Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: incarnation cache not enabled #498

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* (evm) [#414](https://github.com/crypto-org-chain/ethermint/pull/414) Integrate go-block-stm for parallel tx execution.
* (block-stm) [#498](https://github.com/crypto-org-chain/ethermint/pull/498) Enable incarnation cache for block-stm executor.

### State Machine Breaking

Expand Down
12 changes: 11 additions & 1 deletion app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

const EthSigVerificationResultCacheKey = "ante:EthSigVerificationResult"

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper, EVM Keeper and Fee Market Keeper.
type HandlerOptions struct {
Expand Down Expand Up @@ -111,7 +113,15 @@
return ctx, err
}

if err := VerifyEthSig(tx, ethSigner); err != nil {
if v, ok := ctx.GetIncarnationCache(EthSigVerificationResultCacheKey); ok {
if v != nil {
err = v.(error)

Check warning on line 118 in app/ante/handler_options.go

View check run for this annotation

Codecov / codecov/patch

app/ante/handler_options.go#L117-L118

Added lines #L117 - L118 were not covered by tests
}
} else {
err = VerifyEthSig(tx, ethSigner)
ctx.SetIncarnationCache(EthSigVerificationResultCacheKey, err)
}
if err != nil {
return ctx, err
}

Expand Down
27 changes: 23 additions & 4 deletions app/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"
"io"
"sync/atomic"

"cosmossdk.io/store/cachemulti"
storetypes "cosmossdk.io/store/types"
Expand All @@ -17,11 +18,11 @@
func DefaultTxExecutor(_ context.Context,
blockSize int,
ms storetypes.MultiStore,
deliverTxWithMultiStore func(int, storetypes.MultiStore) *abci.ExecTxResult,
deliverTxWithMultiStore func(int, storetypes.MultiStore, map[string]any) *abci.ExecTxResult,
) ([]*abci.ExecTxResult, error) {
results := make([]*abci.ExecTxResult, blockSize)
for i := 0; i < blockSize; i++ {
results[i] = deliverTxWithMultiStore(i, ms)
results[i] = deliverTxWithMultiStore(i, ms, nil)

Check warning on line 25 in app/executor.go

View check run for this annotation

Codecov / codecov/patch

app/executor.go#L25

Added line #L25 was not covered by tests
}
return evmtypes.PatchTxResponses(results), nil
}
Expand All @@ -35,21 +36,39 @@
ctx context.Context,
blockSize int,
ms storetypes.MultiStore,
deliverTxWithMultiStore func(int, storetypes.MultiStore) *abci.ExecTxResult,
deliverTxWithMultiStore func(int, storetypes.MultiStore, map[string]any) *abci.ExecTxResult,

Check warning on line 39 in app/executor.go

View check run for this annotation

Codecov / codecov/patch

app/executor.go#L39

Added line #L39 was not covered by tests
) ([]*abci.ExecTxResult, error) {
if blockSize == 0 {
return nil, nil
}
results := make([]*abci.ExecTxResult, blockSize)
incarnationCache := make([]atomic.Pointer[map[string]any], blockSize)
for i := 0; i < blockSize; i++ {
m := make(map[string]any)
incarnationCache[i].Store(&m)

Check warning on line 48 in app/executor.go

View check run for this annotation

Codecov / codecov/patch

app/executor.go#L45-L48

Added lines #L45 - L48 were not covered by tests
}
if err := blockstm.ExecuteBlock(
ctx,
blockSize,
index,
stmMultiStoreWrapper{ms},
workers,
func(txn blockstm.TxnIndex, ms blockstm.MultiStore) {
result := deliverTxWithMultiStore(int(txn), msWrapper{ms})
var cache map[string]any

Check warning on line 57 in app/executor.go

View check run for this annotation

Codecov / codecov/patch

app/executor.go#L57

Added line #L57 was not covered by tests

// 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)
if v != nil {
cache = *v

Check warning on line 63 in app/executor.go

View check run for this annotation

Codecov / codecov/patch

app/executor.go#L61-L63

Added lines #L61 - L63 were not covered by tests
}

result := deliverTxWithMultiStore(int(txn), msWrapper{ms}, cache)

Check warning on line 66 in app/executor.go

View check run for this annotation

Codecov / codecov/patch

app/executor.go#L66

Added line #L66 was not covered by tests
results[txn] = result

if v != nil {
incarnationCache[txn].Store(v)

Check warning on line 70 in app/executor.go

View check run for this annotation

Codecov / codecov/patch

app/executor.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}
},
); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ replace (
cosmossdk.io/client/v2 => github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240626040048-36295f051595
cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240626040048-36295f051595
cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240626040048-36295f051595
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.0.0-20240626040048-36295f051595
github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240715031529-5a1594f17924
)

replace (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,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.0.0-20240626040048-36295f051595 h1:qiUv1Y+OE8ZgB5mfXFti8R9bjq8zmfuoe2m2g3Iq41c=
github.com/crypto-org-chain/cosmos-sdk v0.0.0-20240626040048-36295f051595/go.mod h1:bIUzWfqXnCF2WTFb2uN+FjzMIG3BsOk+P2QmvMtm4ic=
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240715031529-5a1594f17924 h1:rTiEYiXC8AxKeKsOTz4QODkX9fvMAnlAj8R2gOACoxU=
github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240715031529-5a1594f17924/go.mod h1:bIUzWfqXnCF2WTFb2uN+FjzMIG3BsOk+P2QmvMtm4ic=
github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240626040048-36295f051595 h1:xfrVLBZgV2DXjQXTSlaWHcG/s6Fdeme8tczaN4TTERw=
github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240626040048-36295f051595/go.mod h1:W5sR4asmVDUhJpEmuXTUBkk/yEefKlXTjVWcNciVSR0=
github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240626040048-36295f051595 h1:gHBOTNAuuGeD9HXGkTE04x3zee+00bXcVd8Jb3WG0nY=
Expand Down
4 changes: 2 additions & 2 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ schema = 3
version = "v1.0.0-beta.5"
hash = "sha256-Fy/PbsOsd6iq0Njy3DVWK6HqWsogI+MkE8QslHGWyVg="
[mod."github.com/cosmos/cosmos-sdk"]
version = "v0.0.0-20240626040048-36295f051595"
hash = "sha256-rwGLcCHeeq74zLoqZ/yCSB6WdHmdwFiz/xRw1SIiBYQ="
version = "v0.50.6-0.20240715031529-5a1594f17924"
hash = "sha256-1oX4RDHti4eGTkHIdqUZfCYUXpw5Ao7oBZDfZclF1Mk="
replaced = "github.com/crypto-org-chain/cosmos-sdk"
[mod."github.com/cosmos/go-bip39"]
version = "v1.0.0"
Expand Down
Loading