-
Notifications
You must be signed in to change notification settings - Fork 14
Add nonce-aware transaction pool #971
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
Open
vishalchangrani
wants to merge
19
commits into
main
Choose a base branch
from
vishal/nonce-aware-mini-pool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9d1f22c
docs: add nonce-aware tx pool implementation plan
vishalchangrani ea8fa9d
feat(config): add nonce-aware tx pool flags and validation
vishalchangrani 7745740
style(cmd): align nonce-aware validation error messages with house style
vishalchangrani 7e1abcc
feat(requester): add NonceProvider for local index nonce lookups
vishalchangrani 690170c
feat(requester): add nonce selection helpers for nonce-aware pool
vishalchangrani a74f178
feat(errors): add ErrInFlightNonce for in-flight nonce dedup
vishalchangrani c6320f6
feat(requester): add NonceAwareTxPool with fast path, gap handling an…
vishalchangrani 45b8bb9
fix(requester): reconcile in-flight state on failed flush; single ind…
vishalchangrani 5967088
feat(bootstrap): wire NonceAwareTxPool behind tx-nonce-aware-mode flag
vishalchangrani 17bbdb8
test(requester): add e2e tests for nonce-aware tx pool
vishalchangrani 2127a6f
chore: drop implementation plan doc and a vacuous test assertion befo…
vishalchangrani 8e5e010
Update config/config.go
vishalchangrani 7bf5129
fix(requester): address correctness review feedback in nonce-aware pool
vishalchangrani 82aec02
fix(requester): treat local-index nonce read failures as exceptions
vishalchangrani b43115b
feat(metrics): add tx pool size gauges; stop dropped metric on prune
vishalchangrani 9278c55
refactor(requester): rename NonceAwareTxPool to TxMemPool
vishalchangrani 1060813
refactor(requester): reject early in Add; document TTL; add e2e tests
vishalchangrani 57c79c4
refactor(requester): rename lastSentNonce to lastSubmittedNonce
vishalchangrani 8f50460
refactor(requester): simplify in-flight handling per round-2 review
vishalchangrani 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
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
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,68 @@ | ||
| package requester | ||
|
|
||
| import ( | ||
| gethCommon "github.com/ethereum/go-ethereum/common" | ||
| "github.com/onflow/flow-go/fvm/evm" | ||
| "github.com/onflow/flow-go/fvm/evm/offchain/query" | ||
| flowGo "github.com/onflow/flow-go/model/flow" | ||
|
|
||
| "github.com/onflow/flow-evm-gateway/storage" | ||
| "github.com/onflow/flow-evm-gateway/storage/pebble" | ||
| ) | ||
|
|
||
| // NonceProvider returns the current nonce of the given EOA address. | ||
| // The transaction mempool uses it to determine the expected next nonce. | ||
| type NonceProvider interface { | ||
| // GetNonce returns the current nonce of the given EOA address. | ||
| // | ||
| // A non-nil error represents an EXCEPTION, not an expected condition: | ||
| // the underlying read is a local state-index lookup that should not | ||
| // fail under normal operation. Callers must therefore treat an error | ||
| // as a hard failure (reject the transaction / abort the operation) | ||
| // rather than a routine, recoverable condition to swallow. | ||
| GetNonce(address gethCommon.Address) (uint64, error) | ||
| } | ||
|
|
||
| // LocalNonceProvider reads the EOA nonce from the latest height of the | ||
| // local state index. | ||
| type LocalNonceProvider struct { | ||
| chainID flowGo.ChainID | ||
| registerStore *pebble.RegisterStorage | ||
| blocks storage.BlockIndexer | ||
| } | ||
|
|
||
| var _ NonceProvider = &LocalNonceProvider{} | ||
|
|
||
| func NewLocalNonceProvider( | ||
| chainID flowGo.ChainID, | ||
| registerStore *pebble.RegisterStorage, | ||
| blocks storage.BlockIndexer, | ||
| ) *LocalNonceProvider { | ||
| return &LocalNonceProvider{ | ||
| chainID: chainID, | ||
| registerStore: registerStore, | ||
| blocks: blocks, | ||
| } | ||
| } | ||
|
|
||
| func (p *LocalNonceProvider) GetNonce(address gethCommon.Address) (uint64, error) { | ||
| height, err := p.blocks.LatestEVMHeight() | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
||
| viewProvider := query.NewViewProvider( | ||
| p.chainID, | ||
| evm.StorageAccountAddress(p.chainID), | ||
| p.registerStore, | ||
| NewOverridableBlocksProvider(p.blocks, p.chainID, nil), | ||
| blockGasLimit, | ||
| ) | ||
|
|
||
| view, err := viewProvider.GetBlockView(height) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
||
| return view.GetNonce(address) | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the failure is not visible to the end-user, only to the COA of the node operator. It would show up as a Cadence transaction that errored out. Still, this is a good metric which can help us measure how well the tx mempool behaves.