-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat: nonce (sequence number) based mempool #13645
Merged
Merged
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cb21a86
mempool sender priority implementation
kocubinski 90fa7cf
Fix tests
kocubinski 0de3547
remove priority impl
kocubinski 1859fd6
fix IsEmpty
kocubinski dc60fef
simplify refactor
kocubinski f735bed
add select godoc
kocubinski 9016e96
tx size
kocubinski e4c7f47
nonce mempool implementation
JeancarloBarrios 55b8b79
one test passing
kocubinski 505dc5f
remove sender priority implementation
kocubinski 30ab950
Fix tests and add godocs
kocubinski 034a85c
formatting
kocubinski 0f4c82e
mod tidy
kocubinski f6df50b
reorder imports
kocubinski 14805d6
txBytes counting
kocubinski 1654d11
Merge branch 'main' into kocubinski/mempool-nonce
kocubinski fe36b38
Merge branch 'main' into kocubinski/mempool-nonce
kocubinski 2db6e6b
Merge branch 'main' into kocubinski/mempool-nonce
kocubinski d1e37ed
minor reformatting
kocubinski 0ae7966
import formatting
kocubinski c0ce7d1
fix import order
kocubinski 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 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 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,54 @@ | ||
package mempool | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// Tx defines an app-side mempool transaction interface that is as | ||
// minimal as possible, only requiring applications to define the size of the | ||
// transaction to be used when inserting, selecting, and deleting the transaction. | ||
// Interface type casting can be used in the actual app-side mempool implementation. | ||
type Tx interface { | ||
types.Tx | ||
|
||
// Size returns the size of the transaction in bytes. | ||
Size() int64 | ||
} | ||
|
||
type Mempool interface { | ||
// Insert attempts to insert a Tx into the app-side mempool returning | ||
// an error upon failure. | ||
Insert(types.Context, Tx) error | ||
|
||
// Select returns the next set of available transactions from the app-side | ||
// mempool, up to maxBytes or until the mempool is empty. The application can | ||
// decide to return transactions from its own mempool, from the incoming | ||
// txs, or some combination of both. | ||
Select(txs [][]byte, maxBytes int64) ([]Tx, error) | ||
|
||
// CountTx returns the number of transactions currently in the mempool. | ||
CountTx() int | ||
|
||
// Remove attempts to remove a transaction from the mempool, returning an error | ||
// upon failure. | ||
Remove(Tx) error | ||
} | ||
|
||
var ErrTxNotFound = errors.New("tx not found in mempool") | ||
|
||
type Factory func() Mempool | ||
|
||
func IsEmpty(mempool Mempool) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than type cast. I would just define |
||
smp, ok := mempool.(*nonceMempool) | ||
if ok { | ||
if smp.txQueue.Len() != 0 { | ||
return fmt.Errorf("mempool is not empty") | ||
} | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("unknown mempool type") | ||
} |
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.
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.
@kocubinski do you use VSCode? If so, you can add the following to your SDK workspace settings:
I'm sure there is one equivalent for vim or whatever