mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-04-04 15:55:23 +00:00
Compare commits
5 Commits
d4066b6a3d
...
a0426c63f7
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a0426c63f7 | ||
![]() |
a32dad8373 | ||
![]() |
4f53e59af7 | ||
![]() |
8ecfda7bd2 | ||
![]() |
bbd02215f7 |
@ -265,40 +265,46 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
|
|||||||
}
|
}
|
||||||
|
|
||||||
remaing := gasPriceSuggestionBlockNum * int64(maxBlockGas)
|
remaing := gasPriceSuggestionBlockNum * int64(maxBlockGas)
|
||||||
for len(txnInfoMap) > 0 && remaing > 0 {
|
var lastProcessedTx *txnInfo
|
||||||
|
|
||||||
// pop each sender's first continuous decreasing subsequence
|
for remaing > 0 && len(txnInfoMap) > 0 {
|
||||||
txnCnt := 0
|
// Find the highest gas price among the first transaction of each account
|
||||||
senderNonceSortedSliceGroup := make([][]*txnInfo, 0, senderCnt)
|
var highestGasPrice *big.Int
|
||||||
for sender := range txnInfoMap {
|
var selectedSender string
|
||||||
endIndex := findFirstContinuousDecreasingSubsequence(txnInfoMap[sender])
|
|
||||||
appendSlice := txnInfoMap[sender][:endIndex]
|
// Compare first transaction (lowest nonce) from each account
|
||||||
senderNonceSortedSliceGroup = append(senderNonceSortedSliceGroup, appendSlice)
|
for sender, txns := range txnInfoMap {
|
||||||
txnCnt += len(appendSlice)
|
if len(txns) == 0 {
|
||||||
txnInfoMap[sender] = txnInfoMap[sender][endIndex:]
|
|
||||||
if len(txnInfoMap[sender]) == 0 {
|
|
||||||
delete(txnInfoMap, sender)
|
delete(txnInfoMap, sender)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// First tx has lowest nonce due to earlier sorting
|
||||||
|
if highestGasPrice == nil || txns[0].gasPrice.Cmp(highestGasPrice) > 0 {
|
||||||
|
highestGasPrice = txns[0].gasPrice
|
||||||
|
selectedSender = sender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var gasPriceSortedSlice []*txnInfo
|
if selectedSender == "" {
|
||||||
if len(senderNonceSortedSliceGroup) > 0 {
|
|
||||||
gasPriceSortedSlice = make([]*txnInfo, 0, len(senderNonceSortedSliceGroup[0]))
|
|
||||||
for i := range senderNonceSortedSliceGroup {
|
|
||||||
gasPriceSortedSlice = mergeSort(len(gasPriceSortedSlice)+len(senderNonceSortedSliceGroup[i]), gasPriceSortedSlice, senderNonceSortedSliceGroup[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range gasPriceSortedSlice {
|
|
||||||
remaing -= int64(gasPriceSortedSlice[i].gasLimit)
|
|
||||||
if remaing <= 0 {
|
|
||||||
h.feemarketKeeper.SetSuggestionGasPrice(ctx, gasPriceSortedSlice[i].gasPrice)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process the selected transaction
|
||||||
|
selectedTx := txnInfoMap[selectedSender][0]
|
||||||
|
remaing -= int64(selectedTx.gasLimit)
|
||||||
|
lastProcessedTx = selectedTx
|
||||||
|
|
||||||
|
// Remove processed transaction
|
||||||
|
txnInfoMap[selectedSender] = txnInfoMap[selectedSender][1:]
|
||||||
|
if len(txnInfoMap[selectedSender]) == 0 {
|
||||||
|
delete(txnInfoMap, selectedSender)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if remaing > 0 {
|
if lastProcessedTx != nil && remaing <= 0 {
|
||||||
|
h.feemarketKeeper.SetSuggestionGasPrice(ctx, lastProcessedTx.gasPrice)
|
||||||
|
} else {
|
||||||
h.feemarketKeeper.SetSuggestionGasPrice(ctx, big.NewInt(0))
|
h.feemarketKeeper.SetSuggestionGasPrice(ctx, big.NewInt(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,45 +466,3 @@ func utilCosmosDemonGasPriceToEvmDemonGasPrice(gasGroup sdk.Coins) (*big.Int, er
|
|||||||
func utilCosmosDemonGasLimitToEvmDemonGasLimit(gasLimit uint64) uint64 {
|
func utilCosmosDemonGasLimitToEvmDemonGasLimit(gasLimit uint64) uint64 {
|
||||||
return gasLimit * chaincfg.GasDenomConversionMultiplier
|
return gasLimit * chaincfg.GasDenomConversionMultiplier
|
||||||
}
|
}
|
||||||
|
|
||||||
func findFirstContinuousDecreasingSubsequence(data []*txnInfo) int {
|
|
||||||
ll := len(data)
|
|
||||||
if ll < 2 {
|
|
||||||
return ll
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < ll-1; i++ {
|
|
||||||
if data[i].gasPrice.Cmp(data[i+1].gasPrice) >= 0 {
|
|
||||||
end := i + 1
|
|
||||||
for ; end < ll && data[end-1].gasPrice.Cmp(data[end].gasPrice) > 0; end++ {
|
|
||||||
}
|
|
||||||
if end == ll || data[end-1].gasPrice.Cmp(data[end].gasPrice) <= 0 {
|
|
||||||
return end
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return i + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ll
|
|
||||||
}
|
|
||||||
|
|
||||||
func mergeSort(size int, left, right []*txnInfo) []*txnInfo {
|
|
||||||
result := make([]*txnInfo, 0, size)
|
|
||||||
i, j := 0, 0
|
|
||||||
|
|
||||||
for i < len(left) && j < len(right) {
|
|
||||||
if left[i].gasPrice.Cmp(right[j].gasPrice) > 0 {
|
|
||||||
result = append(result, left[i])
|
|
||||||
i++
|
|
||||||
} else {
|
|
||||||
result = append(result, right[j])
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = append(result, left[i:]...)
|
|
||||||
result = append(result, right[j:]...)
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
2
go.mod
2
go.mod
@ -250,7 +250,7 @@ replace (
|
|||||||
// TODO: Tag before release
|
// TODO: Tag before release
|
||||||
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2
|
github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2
|
||||||
// Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support
|
// Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support
|
||||||
github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v3.1.9
|
github.com/evmos/ethermint => github.com/0glabs/ethermint v0.21.0-0g.v3.1.10
|
||||||
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
|
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320
|
||||||
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
|
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
|
||||||
// Downgraded to avoid bugs in following commits which causes "version does not exist" errors
|
// Downgraded to avoid bugs in following commits which causes "version does not exist" errors
|
||||||
|
4
go.sum
4
go.sum
@ -213,8 +213,8 @@ github.com/0glabs/cometbft v0.37.9-0glabs.1 h1:KQJG17Y21suKP3QNICLto4b5Ak73XbSmK
|
|||||||
github.com/0glabs/cometbft v0.37.9-0glabs.1/go.mod h1:j0Q3RqrCd+cztWCugs3obbzC4NyHGBPZZjtm/fWV00I=
|
github.com/0glabs/cometbft v0.37.9-0glabs.1/go.mod h1:j0Q3RqrCd+cztWCugs3obbzC4NyHGBPZZjtm/fWV00I=
|
||||||
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10 h1:NJp0RwczHBO4EvrQdDxxftHOgUDBtNh7M/vpaG7wFtQ=
|
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10 h1:NJp0RwczHBO4EvrQdDxxftHOgUDBtNh7M/vpaG7wFtQ=
|
||||||
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10/go.mod h1:KskIVnhXTFqrw7CDccMvx7To5KzUsOomIsQV7sPGOog=
|
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.10/go.mod h1:KskIVnhXTFqrw7CDccMvx7To5KzUsOomIsQV7sPGOog=
|
||||||
github.com/0glabs/ethermint v0.21.0-0g.v3.1.9 h1:oTHp7tSAqoML7D/+RXsBzA9DsbZ80MX93VJYjR/Akh4=
|
github.com/0glabs/ethermint v0.21.0-0g.v3.1.10 h1:DE8hK2OJp9rKYdT2Y0G259/6nAFcOQi383l2e7/VFnE=
|
||||||
github.com/0glabs/ethermint v0.21.0-0g.v3.1.9/go.mod h1:6e/gOcDLhvlDWK3JLJVBgki0gD6H4E1eG7l9byocgWA=
|
github.com/0glabs/ethermint v0.21.0-0g.v3.1.10/go.mod h1:6e/gOcDLhvlDWK3JLJVBgki0gD6H4E1eG7l9byocgWA=
|
||||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
|
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
|
||||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
|
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
|
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
|
||||||
|
Loading…
Reference in New Issue
Block a user