-
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
Conversation
b5ff8a8
to
0f4c82e
Compare
baseapp/baseapp.go
Outdated
|
||
"github.com/cosmos/cosmos-sdk/types/mempool" | ||
"github.com/cosmos/gogoproto/proto" | ||
|
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.
"github.com/cosmos/cosmos-sdk/types/mempool" | |
"github.com/cosmos/gogoproto/proto" | |
"github.com/cosmos/gogoproto/proto" | |
"github.com/cosmos/cosmos-sdk/types/mempool" |
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:
"gopls": {
"local": "github.com/cosmos/cosmos-sdk"
}
I'm sure there is one equivalent for vim or whatever
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #13645 +/- ##
==========================================
+ Coverage 54.69% 54.85% +0.15%
==========================================
Files 645 655 +10
Lines 55745 56239 +494
==========================================
+ Hits 30491 30851 +360
- Misses 22764 22866 +102
- Partials 2490 2522 +32
|
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.
Left a few comments, but otherwise LGTM!
baseapp/baseapp.go
Outdated
|
||
"github.com/cosmos/cosmos-sdk/types/mempool" | ||
"github.com/cosmos/gogoproto/proto" | ||
|
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:
"gopls": {
"local": "github.com/cosmos/cosmos-sdk"
}
I'm sure there is one equivalent for vim or whatever
types/mempool/mempool.go
Outdated
|
||
type Factory func() Mempool | ||
|
||
func IsEmpty(mempool Mempool) error { |
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.
rather than type cast. I would just define NumTxs()
on the mempool
interface.
x/auth/tx/builder.go
Outdated
@@ -1,6 +1,7 @@ | |||
package tx | |||
|
|||
import ( | |||
"github.com/cosmos/cosmos-sdk/types/mempool" |
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.
nit: formatting
// are prioritized. Transactions with the same nonce are prioritized by sender address. Fee/gas based | ||
// prioritization is not supported. | ||
type nonceMempool struct { | ||
txQueue *huandu.SkipList |
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.
Just want to point out that using a skip list this for this type of implementation might be overkill. You could just use a sorted []Tx
array, or a wrapper around Tx
so you don't have to do anything extra to get the sender and nonce, etc..
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.
You could just use a sorted []Tx array
I think this is an efficient way to maintain a sorted list. Using an array we'd still need to sort on insert, what are you proposing for maintaining the sort?
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.
Yeah, its the same semantically. With an array, sort on insert. Both are logarithmic. Not blocking though. Just pointing it out.
types/mempool/nonce.go
Outdated
selectedTxs = append(selectedTxs, mempoolTx) | ||
if txBytes += mempoolTx.Size(); txBytes >= maxBytes { | ||
return selectedTxs, nil | ||
} |
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.
I think you need to re-write this slightly. You only want to add the current tx s.t. if when added remains under or equal to maxBytes
. I.e. txBytes + mempoolTx.Size() <= maxBytes { // append }
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.
🎉
nice work!
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.
LGTM, added some very very silly nits (sorry)
types/mempool/mempool_test.go
Outdated
func (t testPubKey) Reset() { panic("implement me") } | ||
|
||
func (t testPubKey) String() string { panic("implement me") } | ||
|
||
func (t testPubKey) ProtoMessage() { panic("implement me") } | ||
|
||
func (t testPubKey) Address() cryptotypes.Address { return t.address.Bytes() } | ||
|
||
func (t testPubKey) Bytes() []byte { panic("implement me") } | ||
|
||
func (t testPubKey) VerifySignature(msg []byte, sig []byte) bool { panic("implement me") } | ||
|
||
func (t testPubKey) Equals(key cryptotypes.PubKey) bool { panic("implement me") } | ||
|
||
func (t testPubKey) Type() string { panic("implement me") } |
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.
nit:
func (t testPubKey) Reset() { panic("implement me") } | |
func (t testPubKey) String() string { panic("implement me") } | |
func (t testPubKey) ProtoMessage() { panic("implement me") } | |
func (t testPubKey) Address() cryptotypes.Address { return t.address.Bytes() } | |
func (t testPubKey) Bytes() []byte { panic("implement me") } | |
func (t testPubKey) VerifySignature(msg []byte, sig []byte) bool { panic("implement me") } | |
func (t testPubKey) Equals(key cryptotypes.PubKey) bool { panic("implement me") } | |
func (t testPubKey) Type() string { panic("implement me") } | |
func (t testPubKey) Reset() { panic("not implemented") } | |
func (t testPubKey) String() string { panic("not implemented") } | |
func (t testPubKey) ProtoMessage() { panic("not implemented") } | |
func (t testPubKey) Address() cryptotypes.Address { return t.address.Bytes() } | |
func (t testPubKey) Bytes() []byte { panic("not implemented") } | |
func (t testPubKey) VerifySignature(msg []byte, sig []byte) bool { panic("not implemented") } | |
func (t testPubKey) Equals(key cryptotypes.PubKey) bool { panic("not implemented") } | |
func (t testPubKey) Type() string { panic("not implemented") } |
types/mempool/mempool_test.go
Outdated
func (tx testTx) GetSigners() []sdk.AccAddress { panic("implement me") } | ||
|
||
func (tx testTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("GetPubKeys not implemented") } |
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.
consistency nit:
func (tx testTx) GetSigners() []sdk.AccAddress { panic("implement me") } | |
func (tx testTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("GetPubKeys not implemented") } | |
func (tx testTx) GetSigners() []sdk.AccAddress { panic("not implemented") } | |
func (tx testTx) GetPubKeys() ([]cryptotypes.PubKey, error) { panic("not implemented") } |
types/mempool/mempool_test.go
Outdated
require.NoError(t, err) | ||
} | ||
|
||
//mempool.DebugPrintKeys(pool) |
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.
//mempool.DebugPrintKeys(pool) |
types/mempool/nonce.go
Outdated
// nonceMempool is a mempool that keeps transactions sorted by nonce. Transactions with the lowest nonce globally | ||
// are prioritized. Transactions with the same nonce are prioritized by sender address. Fee/gas based | ||
// prioritization is not supported. |
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.
// nonceMempool is a mempool that keeps transactions sorted by nonce. Transactions with the lowest nonce globally | |
// are prioritized. Transactions with the same nonce are prioritized by sender address. Fee/gas based | |
// prioritization is not supported. | |
// nonceMempool is a mempool that keeps transactions sorted by nonce. Transactions with the lowest nonce globally | |
// are prioritized. Transactions with the same nonce are prioritized by sender address. Fee/gas based | |
// prioritization is not supported. |
types/mempool/nonce.go
Outdated
return sp | ||
} | ||
|
||
// Insert adds a tx to the mempool. It returns an error if the tx does not have at least one signer. |
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.
// Insert adds a tx to the mempool. It returns an error if the tx does not have at least one signer. | |
// Insert adds a tx to the mempool. It returns an error if the tx does not have at least one signer. |
types/mempool/nonce.go
Outdated
return nil | ||
} | ||
|
||
// Select returns txs from the mempool with the lowest nonce globally first. A sender's txs will always be returned |
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.
// Select returns txs from the mempool with the lowest nonce globally first. A sender's txs will always be returned | |
// Select returns txs from the mempool with the lowest nonce globally first. A sender's txs will always be returned |
types/mempool/nonce.go
Outdated
return sp.txQueue.Len() | ||
} | ||
|
||
// Remove removes a tx from the mempool. It returns an error if the tx does not have at least one signer or the tx |
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.
// Remove removes a tx from the mempool. It returns an error if the tx does not have at least one signer or the tx | |
// Remove removes a tx from the mempool. It returns an error if the tx does not have at least one signer or the tx |
simple default mempool implementation Co-authored-by: Jeancarlo <jeancarlobarrios@gmail.com>
Description
Closes: #13276
This simple mempool implementation keeps transactions sorted by nonce (sequence number). Transactions with the lowest nonce globally are prioritized. Transactions from different senders with the same nonce are prioritized by sender address. Fee/gas based prioritization is not supported.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change