Compare commits

...

5 Commits

Author SHA1 Message Date
Solovyov1796
a0426c63f7 set suggetsion gas price as 0 if not found 2025-02-10 23:27:22 +08:00
Solovyov1796
a32dad8373 remove useless code 2025-02-10 23:13:10 +08:00
Solovyov1796
4f53e59af7
Merge pull request #108 from 0g-wh/suggestion_gas_price
update txn selection algo
2025-02-10 22:47:43 +08:00
Solovyov1796
8ecfda7bd2 update ethermint version 2025-02-10 22:23:46 +08:00
0g-wh
bbd02215f7 update txn selection algo 2025-02-10 14:23:18 +00:00
3 changed files with 33 additions and 69 deletions

View File

@ -265,40 +265,46 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
}
remaing := gasPriceSuggestionBlockNum * int64(maxBlockGas)
for len(txnInfoMap) > 0 && remaing > 0 {
var lastProcessedTx *txnInfo
// pop each sender's first continuous decreasing subsequence
txnCnt := 0
senderNonceSortedSliceGroup := make([][]*txnInfo, 0, senderCnt)
for sender := range txnInfoMap {
endIndex := findFirstContinuousDecreasingSubsequence(txnInfoMap[sender])
appendSlice := txnInfoMap[sender][:endIndex]
senderNonceSortedSliceGroup = append(senderNonceSortedSliceGroup, appendSlice)
txnCnt += len(appendSlice)
txnInfoMap[sender] = txnInfoMap[sender][endIndex:]
if len(txnInfoMap[sender]) == 0 {
for remaing > 0 && len(txnInfoMap) > 0 {
// Find the highest gas price among the first transaction of each account
var highestGasPrice *big.Int
var selectedSender string
// Compare first transaction (lowest nonce) from each account
for sender, txns := range txnInfoMap {
if len(txns) == 0 {
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 len(senderNonceSortedSliceGroup) > 0 {
gasPriceSortedSlice = make([]*txnInfo, 0, len(senderNonceSortedSliceGroup[0]))
for i := range senderNonceSortedSliceGroup {
gasPriceSortedSlice = mergeSort(len(gasPriceSortedSlice)+len(senderNonceSortedSliceGroup[i]), gasPriceSortedSlice, senderNonceSortedSliceGroup[i])
}
if selectedSender == "" {
break
}
for i := range gasPriceSortedSlice {
remaing -= int64(gasPriceSortedSlice[i].gasLimit)
if remaing <= 0 {
h.feemarketKeeper.SetSuggestionGasPrice(ctx, gasPriceSortedSlice[i].gasPrice)
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))
}
}
@ -460,45 +466,3 @@ func utilCosmosDemonGasPriceToEvmDemonGasPrice(gasGroup sdk.Coins) (*big.Int, er
func utilCosmosDemonGasLimitToEvmDemonGasLimit(gasLimit uint64) uint64 {
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
View File

@ -250,7 +250,7 @@ replace (
// TODO: Tag before release
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
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
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

4
go.sum
View File

@ -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/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/ethermint v0.21.0-0g.v3.1.9 h1:oTHp7tSAqoML7D/+RXsBzA9DsbZ80MX93VJYjR/Akh4=
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 h1:DE8hK2OJp9rKYdT2Y0G259/6nAFcOQi383l2e7/VFnE=
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/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=