-
Notifications
You must be signed in to change notification settings - Fork 887
Add context cancellation to SS DB layer #3940
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
740a933
Add context cancellation to SS DB layer
yzang2019 bee64c4
Address AI comment
yzang2019 8b6955d
Address comments
yzang2019 ea2b220
Merge branch 'main' into yzang/fix-trace-timeout
yzang2019 9c37151
Address blocker comments for beginblock
yzang2019 f910384
Merge branch 'main' into yzang/fix-trace-timeout
yzang2019 0f90826
Merge branch 'main' into yzang/fix-trace-timeout
yzang2019 fc1a430
Fix for trace_profile.go
yzang2019 10cfae5
Merge branch 'main' into yzang/fix-trace-timeout
yzang2019 d9981da
Address comment using t.context
yzang2019 ee8aeff
Merge branch 'main' into yzang/fix-trace-timeout
yzang2019 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| package evmrpc | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/trie" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/app/legacyabci" | ||
| sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types" | ||
| abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types" | ||
| "github.com/sei-protocol/sei-chain/sei-tendermint/rpc/coretypes" | ||
| tmtypes "github.com/sei-protocol/sei-chain/sei-tendermint/types" | ||
| ) | ||
|
|
||
| func TestReleaseOnContextPanic(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var released int | ||
| release := func() { released++ } | ||
|
|
||
| err := releaseOnContextPanic(release, context.Canceled) | ||
| require.ErrorIs(t, err, context.Canceled) | ||
| require.Equal(t, 1, released) | ||
|
|
||
| err = releaseOnContextPanic(release, context.DeadlineExceeded) | ||
| require.ErrorIs(t, err, context.DeadlineExceeded) | ||
| require.Equal(t, 2, released) | ||
|
|
||
| err = releaseOnContextPanic(release, fmt.Errorf("skip: %w", context.DeadlineExceeded)) | ||
| require.ErrorIs(t, err, context.DeadlineExceeded) | ||
| require.Equal(t, 3, released) | ||
|
|
||
| require.Panics(t, func() { | ||
| _ = releaseOnContextPanic(release, errors.New("pebble seek failed")) | ||
| }) | ||
| require.Equal(t, 4, released) | ||
|
|
||
| require.Panics(t, func() { | ||
| _ = releaseOnContextPanic(release, "not an error") | ||
| }) | ||
| require.Equal(t, 5, released) | ||
| } | ||
|
|
||
| func TestInitializeBlockReleasesLeaseOnBeginBlockDeadline(t *testing.T) { | ||
| orig := runTraceBeginBlock | ||
| t.Cleanup(func() { runTraceBeginBlock = orig }) | ||
| runTraceBeginBlock = func(sdk.Context, int64, []abci.VoteInfo, []abci.Misbehavior, legacyabci.BeginBlockKeepers) { | ||
| panic(context.DeadlineExceeded) | ||
| } | ||
|
|
||
| var released int | ||
| backend, block := newInitializeBlockTestBackend(t) | ||
| _, _, release, err := backend.initializeBlock(t.Context(), block, func(int64) (sdk.Context, func()) { | ||
| return sdk.Context{}, func() { released++ } | ||
| }) | ||
| require.ErrorIs(t, err, context.DeadlineExceeded) | ||
| require.Equal(t, 1, released, "base snapshot lease must be released on BeginBlock abort") | ||
| release() | ||
| require.Equal(t, 1, released, "returned release must be a no-op after recover") | ||
| } | ||
|
|
||
| func TestInitializeBlockReleasesLeaseOnUnrelatedBeginBlockPanic(t *testing.T) { | ||
| orig := runTraceBeginBlock | ||
| t.Cleanup(func() { runTraceBeginBlock = orig }) | ||
| runTraceBeginBlock = func(sdk.Context, int64, []abci.VoteInfo, []abci.Misbehavior, legacyabci.BeginBlockKeepers) { | ||
| panic("boom") | ||
| } | ||
|
|
||
| var released int | ||
| backend, block := newInitializeBlockTestBackend(t) | ||
| require.Panics(t, func() { | ||
| _, _, _, _ = backend.initializeBlock(t.Context(), block, func(int64) (sdk.Context, func()) { | ||
| return sdk.Context{}, func() { released++ } | ||
| }) | ||
| }) | ||
| require.Equal(t, 1, released) | ||
| } | ||
|
|
||
| func newInitializeBlockTestBackend(t *testing.T) (*Backend, *ethtypes.Block) { | ||
| t.Helper() | ||
| tm := &fakeTMClient{ | ||
| status: &coretypes.ResultStatus{SyncInfo: coretypes.SyncInfo{LatestBlockHeight: 10, EarliestBlockHeight: 1}}, | ||
| blocksByHeight: map[int64]*coretypes.ResultBlock{ | ||
| 8: { | ||
| Block: &tmtypes.Block{ | ||
| Header: tmtypes.Header{Height: 8}, | ||
| LastCommit: &tmtypes.Commit{}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| return &Backend{ | ||
| tmClient: tm, | ||
| watermarks: newTestWatermarkManager(tm, 10, nil, 10), | ||
| }, ethtypes.NewBlock( | ||
| ðtypes.Header{Number: big.NewInt(8), Time: 1, Difficulty: big.NewInt(0)}, | ||
| ðtypes.Body{}, | ||
| nil, | ||
| trie.NewStackTrie(nil), | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package evmrpc | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestResultUnlessExpiredReportsTheDeadline(t *testing.T) { | ||
| live := t.Context() | ||
|
|
||
| traced := map[string]string{"gas": "0x1"} | ||
| result, err := resultUnlessExpired(live, traced, nil) | ||
| require.NoError(t, err) | ||
| require.Equal(t, traced, result) | ||
|
|
||
| underlying := errors.New("tracer failed") | ||
| result, err = resultUnlessExpired(live, nil, underlying) | ||
| require.ErrorIs(t, err, underlying) | ||
| require.Nil(t, result) | ||
|
|
||
| expired, cancelExpired := context.WithCancel(t.Context()) | ||
| cancelExpired() | ||
| result, err = resultUnlessExpired(expired, map[string]string{"error": "store access cancelled"}, nil) | ||
| require.ErrorIs(t, err, context.Canceled) | ||
| require.Nil(t, result) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.