From 06b761b6f92e4f7845c1c0420eefaeb5c259ddc0 Mon Sep 17 00:00:00 2001 From: Sujong Lee Date: Wed, 6 Nov 2024 17:28:25 +0900 Subject: [PATCH] feat: Apply b-harvest/cosmos-sdk (#27) * chore: Update go.mod * chore: Update go.mod * chore: Update go.mod * chore: Expose NewEhtAnteHandler * chore: Revert toolchain comment * test: Add tx execute counter for stm tx executor * chore: Update go.mod * chore: allow unlimited block gas limit * chore: Update go.mod for custom go-ethereum * chore: Update go.mod for custom cosmos-sdk --------- Co-authored-by: Kyuhyeon Choi --- app/ante/handler_options.go | 4 ++++ app/executor.go | 14 ++++++++++++++ go.mod | 9 ++++----- go.sum | 16 ++++++++-------- types/block.go | 19 ++++++++++++++++++- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index ccf446a88a..84665bf931 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -76,6 +76,10 @@ func (options HandlerOptions) validate() error { return nil } +func NewEthAnteHandler(options HandlerOptions) sdk.AnteHandler { + return newEthAnteHandler(options) +} + func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { blockCfg, err := options.EvmKeeper.EVMBlockConfig(ctx, options.EvmKeeper.ChainID()) diff --git a/app/executor.go b/app/executor.go index 1cff225d61..1241dbe567 100644 --- a/app/executor.go +++ b/app/executor.go @@ -24,6 +24,12 @@ import ( const MinimalParallelPreEstimate = 16 +var ( + TESTMODE = false + + TxExecuteCounter []atomic.Int32 +) + func DefaultTxExecutor(_ context.Context, txs [][]byte, ms storetypes.MultiStore, @@ -86,6 +92,10 @@ func STMTxExecutor( memTxs, estimates = preEstimates(txs, workers, authStore, bankStore, evmDenom, txDecoder) } + if TESTMODE { + TxExecuteCounter = make([]atomic.Int32, blockSize) + } + if err := blockstm.ExecuteBlockWithEstimates( ctx, blockSize, @@ -96,6 +106,10 @@ func STMTxExecutor( func(txn blockstm.TxnIndex, ms blockstm.MultiStore) { var cache map[string]any + if TESTMODE { + TxExecuteCounter[txn].Add(1) + } + // only one of the concurrent incarnations gets the cache if there are any, otherwise execute without // cache, concurrent incarnations should be rare. v := incarnationCache[txn].Swap(nil) diff --git a/go.mod b/go.mod index af84c95e75..eb9f849993 100644 --- a/go.mod +++ b/go.mod @@ -244,17 +244,16 @@ require ( ) replace ( - // release/v0.50.x - cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240930015419-f4ea363b3fdf - cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240930015419-f4ea363b3fdf - github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240930015419-f4ea363b3fdf + cosmossdk.io/store => github.com/b-harvest/cosmos-sdk/store v0.0.0-20241106072527-a25eb3a65854 + cosmossdk.io/x/tx => github.com/b-harvest/cosmos-sdk/x/tx v0.0.0-20241106072513-3f9b5f9442bd + github.com/cosmos/cosmos-sdk => github.com/b-harvest/cosmos-sdk v0.0.0-20241106082343-55e55e63db3a + github.com/ethereum/go-ethereum => github.com/b-harvest/go-ethereum v0.0.0-20241106045451-23c79ab53226 ) replace ( // use cosmos keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // release/v1.11.x - github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240926023215-d2275b4afb9a // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 diff --git a/go.sum b/go.sum index 26744c4247..b129f21a61 100644 --- a/go.sum +++ b/go.sum @@ -265,6 +265,14 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX github.com/aws/aws-sdk-go v1.44.224 h1:09CiaaF35nRmxrzWZ2uRq5v6Ghg/d2RiPjZnSgtt+RQ= github.com/aws/aws-sdk-go v1.44.224/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= +github.com/b-harvest/cosmos-sdk v0.0.0-20241106082343-55e55e63db3a h1:9TcRQHfsXFGcjSJNHt/458YdC+H7FFwJ7Ak80OO21ck= +github.com/b-harvest/cosmos-sdk v0.0.0-20241106082343-55e55e63db3a/go.mod h1:D3Z0eQDB3wcIeRVPD2e7xGPbS5Cx+GGcKLh3w/BvI3I= +github.com/b-harvest/cosmos-sdk/store v0.0.0-20241106072527-a25eb3a65854 h1:KcAh4n5qOx36uh9hN8nQDdLKHT+Uz8dT6nWN5AW7yi8= +github.com/b-harvest/cosmos-sdk/store v0.0.0-20241106072527-a25eb3a65854/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng= +github.com/b-harvest/cosmos-sdk/x/tx v0.0.0-20241106072513-3f9b5f9442bd h1:yshPrVv7tqs/KREIbcfG6xAp9yp3eTpDkzXz/Rt8cJ8= +github.com/b-harvest/cosmos-sdk/x/tx v0.0.0-20241106072513-3f9b5f9442bd/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= +github.com/b-harvest/go-ethereum v0.0.0-20241106045451-23c79ab53226 h1:TUw0xOKTEKSqWPmCcFO8Gci49mvxHKWJ8NwERwD1o5I= +github.com/b-harvest/go-ethereum v0.0.0-20241106045451-23c79ab53226/go.mod h1:A249HEl6XyiV5zSnKM9j9RF3szMghMNONMyNvYuqQIw= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -412,16 +420,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c h1:MOgfS4+FBB8cMkDE2j2VBVsbY+HCkPIu0YsJ/9bbGeQ= github.com/crypto-org-chain/btree v0.0.0-20240406140148-2687063b042c/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= -github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240930015419-f4ea363b3fdf h1:QNQ9uB3DEfJqSMwERDSaYQMofgfzfcSp49iDt7B2jvc= -github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240930015419-f4ea363b3fdf/go.mod h1:iJLknPnyzlcQGdgfIp9d8QCuqt8g1RjJeh8pJ/p5wj4= -github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240930015419-f4ea363b3fdf h1:vGFA8f1EbNLgabbSBBnT1bArLnrl4ETk4PUTJLb01Pc= -github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240930015419-f4ea363b3fdf/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM= -github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240930015419-f4ea363b3fdf h1:u6BY+dtlmhuQYfPDnpGhDBF2uiCA0HvrIk22L67nB6Q= -github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240930015419-f4ea363b3fdf/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= github.com/crypto-org-chain/go-block-stm v0.0.0-20240919080136-6c49aef68716 h1:OvD5Rm0B6LHUJk6z858UgwdP72jU2DuUdXeclRyKpDI= github.com/crypto-org-chain/go-block-stm v0.0.0-20240919080136-6c49aef68716/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE= -github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240926023215-d2275b4afb9a h1:IUPD+dg1YQl8cLocxQ/Mbx/ObTgAgcrZlcBhFjsLO40= -github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240926023215-d2275b4afb9a/go.mod h1:A249HEl6XyiV5zSnKM9j9RF3szMghMNONMyNvYuqQIw= github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/types/block.go b/types/block.go index 6c5558cbd3..9d3d41794d 100644 --- a/types/block.go +++ b/types/block.go @@ -15,12 +15,23 @@ // along with the Ethermint library. If not, see https://github.com/evmos/ethermint/blob/main/LICENSE package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + math "math" + + sdk "github.com/cosmos/cosmos-sdk/types" +) // BlockGasLimit returns the max gas (limit) defined in the block gas meter. If the meter is not // set, it returns the max gas from the application consensus params. // NOTE: see https://github.com/cosmos/cosmos-sdk/issues/9514 for full reference func BlockGasLimit(ctx sdk.Context) uint64 { + blockGasMeter := ctx.BlockGasMeter() + + // Get the limit from the gas meter only if its not null and not an InfiniteGasMeter + if blockGasMeter != nil && blockGasMeter.Limit() != 0 { + return blockGasMeter.Limit() + } + // Otherwise get from the consensus parameters cp := ctx.ConsensusParams() if cp.Block == nil { @@ -28,6 +39,12 @@ func BlockGasLimit(ctx sdk.Context) uint64 { } maxGas := cp.Block.MaxGas + + // Setting maxGas to -1 means that block gas is unlimited + if maxGas == -1 { + return math.MaxUint64 + } + if maxGas > 0 { return uint64(maxGas) }