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

feat: sender mempool impl #13888

Merged
merged 60 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0cb8ad1
draft sender mempool impl
JeancarloBarrios Nov 16, 2022
b967d56
select
JeancarloBarrios Nov 16, 2022
353378c
nit
JeancarloBarrios Nov 16, 2022
20fbacb
random sender update
JeancarloBarrios Nov 16, 2022
c8ea169
nit
JeancarloBarrios Nov 16, 2022
1a89940
prevent memory leak
JeancarloBarrios Nov 16, 2022
28c6cfc
fix nil return
JeancarloBarrios Nov 17, 2022
faecdda
small fixes
JeancarloBarrios Nov 17, 2022
164bded
added tests
JeancarloBarrios Nov 17, 2022
87c221f
change count
JeancarloBarrios Nov 17, 2022
94334f5
finish tx order test removed the three address test due to make the t…
JeancarloBarrios Nov 17, 2022
24ebefe
remove unsued variable
JeancarloBarrios Nov 17, 2022
584bc51
nit
JeancarloBarrios Nov 17, 2022
fe3fbf8
fix
JeancarloBarrios Nov 17, 2022
2a18e81
temoral commit braking
JeancarloBarrios Nov 18, 2022
7784594
nit most
JeancarloBarrios Nov 18, 2022
d34cd88
nit most
JeancarloBarrios Nov 18, 2022
5a385cb
final
JeancarloBarrios Nov 18, 2022
9e02590
comments
JeancarloBarrios Nov 18, 2022
11ceaa7
t
JeancarloBarrios Nov 18, 2022
6703390
comments
JeancarloBarrios Nov 18, 2022
36b42cf
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
JeancarloBarrios Nov 18, 2022
7556b9f
test
JeancarloBarrios Nov 20, 2022
6f1a08b
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
kocubinski Nov 21, 2022
d388bc4
add nolint
kocubinski Nov 21, 2022
9ff7528
Fix comment
kocubinski Nov 21, 2022
ec50ee6
golint comment
kocubinski Nov 21, 2022
bc851a9
golint
kocubinski Nov 21, 2022
1c938bf
improve format?
kocubinski Nov 21, 2022
8800e71
more gosec disable
kocubinski Nov 21, 2022
ed8a268
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
kocubinski Nov 21, 2022
beee298
Fix ctr usage
kocubinski Nov 21, 2022
1dcc89c
use #nosec
kocubinski Nov 21, 2022
99aff01
Update types/mempool/sender_nonce.go
kocubinski Nov 21, 2022
b5960c5
Kocubinski/random sender nonce (#13956)
kocubinski Nov 21, 2022
a3bdcb9
import fixes
kocubinski Nov 21, 2022
da63465
derive order randomness from seed only
kocubinski Nov 21, 2022
ea54e18
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
kocubinski Nov 21, 2022
c306fca
gosec fix
kocubinski Nov 21, 2022
a93c950
ignore gosec again
kocubinski Nov 21, 2022
578046a
comments
kocubinski Nov 21, 2022
695ed48
property based
JeancarloBarrios Nov 21, 2022
99b6536
minor fixes
JeancarloBarrios Nov 21, 2022
bf64e22
added property test
JeancarloBarrios Nov 21, 2022
5785fe7
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
JeancarloBarrios Nov 21, 2022
ca1c17f
comment
JeancarloBarrios Nov 21, 2022
09cac5d
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
JeancarloBarrios Nov 22, 2022
745d50d
fix imports
JeancarloBarrios Nov 22, 2022
c841351
Merge branch 'JeancarloBarrios/random-sender-nonce-ordering' of githu…
JeancarloBarrios Nov 22, 2022
77ea978
comment
JeancarloBarrios Nov 22, 2022
3078d65
Update types/mempool/sender_nonce_property_test.go
JeancarloBarrios Nov 22, 2022
e7c2e2f
remove unesessary loop
JeancarloBarrios Nov 22, 2022
d056a8a
improve function name
JeancarloBarrios Nov 22, 2022
9073aaf
Update types/mempool/sender_nonce.go
JeancarloBarrios Nov 22, 2022
69f3bc5
change import name
JeancarloBarrios Nov 22, 2022
73453ea
change validation to be preemvtive
JeancarloBarrios Nov 22, 2022
847bcf5
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
JeancarloBarrios Nov 22, 2022
278adb0
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
JeancarloBarrios Nov 23, 2022
560e747
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
JeancarloBarrios Nov 23, 2022
cb6121e
Merge branch 'main' into JeancarloBarrios/random-sender-nonce-ordering
JeancarloBarrios Nov 23, 2022
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
3 changes: 2 additions & 1 deletion types/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (s *MempoolTestSuite) TestDefaultMempool() {
for i := 0; i < txCount; i++ {
acc := accounts[i%len(accounts)]
tx := testTx{
nonce: 0,
address: acc.Address,
priority: rand.Int63(),
}
Expand Down Expand Up @@ -201,7 +202,7 @@ type MempoolTestSuite struct {

func (s *MempoolTestSuite) resetMempool() {
s.iterations = 0
s.mempool = mempool.NewNonceMempool()
s.mempool = mempool.NewSenderNonceMempool()
}

func (s *MempoolTestSuite) SetupTest() {
Expand Down
145 changes: 50 additions & 95 deletions types/mempool/nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mempool_test

import (
"fmt"
"github.com/cosmos/cosmos-sdk/types/mempool"
"math/rand"
"testing"

Expand All @@ -19,12 +20,13 @@ func (s *MempoolTestSuite) TestTxOrder() {
accounts := simtypes.RandomAccounts(rand.New(rand.NewSource(0)), 5)
sa := accounts[0].Address
sb := accounts[1].Address
sc := accounts[2].Address
//sc := accounts[2].Address

tests := []struct {
txs []txSpec
order []int
order [][]int
fail bool
seed int64
}{
{
txs: []txSpec{
Expand All @@ -34,7 +36,12 @@ func (s *MempoolTestSuite) TestTxOrder() {
{p: 15, n: 1, a: sb},
{p: 20, n: 1, a: sa},
},
order: []int{3, 4, 2, 1, 0},
order: [][]int{
{4, 2, 3, 1, 0},
{3, 4, 2, 1, 0},
},
// Index order base on seed 0: 0 0 1 0 1 0 0
seed: 0,
},
{
txs: []txSpec{
Expand All @@ -45,15 +52,25 @@ func (s *MempoolTestSuite) TestTxOrder() {
{p: 5, n: 1, a: sb},
{p: 8, n: 2, a: sb},
},
order: []int{3, 0, 4, 1, 5, 2},
order: [][]int{
{0, 1, 3, 2, 4, 5},
{3, 4, 0, 5, 1, 2},
},
// Index order base on seed 0: 0 0 1 0 1 0 0
seed: 0,
},
{
txs: []txSpec{
{p: 21, n: 4, a: sa},
{p: 15, n: 1, a: sb},
{p: 20, n: 1, a: sa},
},
order: []int{1, 2, 0},
order: [][]int{
{2, 0, 1},
{1, 2, 0},
},
// Index order base on seed 0: 0 0 1 0 1 0 0
seed: 0,
},
{
txs: []txSpec{
Expand All @@ -63,7 +80,12 @@ func (s *MempoolTestSuite) TestTxOrder() {
{p: 15, n: 1, a: sb},
{p: 21, n: 2, a: sb},
},
order: []int{3, 2, 4, 1, 0},
order: [][]int{
{2, 1, 3, 0, 4},
{3, 4, 2, 1, 0},
},
// Index order base on seed 0: 0 0 1 0 1 0 0
seed: 0,
},
{
txs: []txSpec{
Expand All @@ -73,7 +95,12 @@ func (s *MempoolTestSuite) TestTxOrder() {
{p: 15, n: 1, a: sb},
{p: 8, n: 2, a: sb},
},
order: []int{3, 2, 4, 1, 0},
order: [][]int{
{2, 1, 3, 0, 4},
{3, 4, 2, 1, 0},
},
// Index order base on seed 0: 0 0 1 0 1 0 0
seed: 0,
},
{
txs: []txSpec{
Expand All @@ -85,21 +112,12 @@ func (s *MempoolTestSuite) TestTxOrder() {
{p: 6, a: sa, n: 3},
{p: 4, a: sb, n: 3},
},
order: []int{4, 3, 1, 2, 0, 6, 5},
},
{
txs: []txSpec{
{p: 30, n: 2, a: sa},
{p: 20, a: sb, n: 1},
{p: 15, a: sa, n: 1},
{p: 10, a: sa, n: 0},
{p: 8, a: sb, n: 0},
{p: 6, a: sa, n: 3},
{p: 4, a: sb, n: 3},
{p: 2, a: sc, n: 0},
{p: 7, a: sc, n: 3},
order: [][]int{
{3, 2, 4, 0, 1, 5, 6},
{4, 1, 3, 6, 2, 0, 5},
},
order: []int{4, 3, 7, 1, 2, 0, 6, 5, 8},
// Index order base on seed 0: 0 0 1 0 1 0 1 1 0
seed: 0,
},
{
txs: []txSpec{
Expand All @@ -108,83 +126,17 @@ func (s *MempoolTestSuite) TestTxOrder() {
{p: 5, n: 1, a: sb},
{p: 99, n: 2, a: sb},
},
order: []int{2, 0, 3, 1},
},
{
// if all txs have the same priority they will be ordered lexically sender address, and nonce with the
// sender.
txs: []txSpec{
{p: 10, n: 7, a: sc},
{p: 10, n: 8, a: sc},
{p: 10, n: 9, a: sc},
{p: 10, n: 1, a: sa},
{p: 10, n: 2, a: sa},
{p: 10, n: 3, a: sa},
{p: 10, n: 4, a: sb},
{p: 10, n: 5, a: sb},
{p: 10, n: 6, a: sb},
order: [][]int{
{0, 1, 2, 3},
{2, 3, 0, 1},
},
order: []int{3, 4, 5, 6, 7, 8, 0, 1, 2},
},
/*
The next 4 tests are different permutations of the same set:

{p: 5, n: 1, a: sa},
{p: 10, n: 2, a: sa},
{p: 20, n: 2, a: sb},
{p: 5, n: 1, a: sb},
{p: 99, n: 2, a: sc},
{p: 5, n: 1, a: sc},

which exercises the actions required to resolve priority ties.
*/
{
txs: []txSpec{
{p: 5, n: 1, a: sa},
{p: 10, n: 2, a: sa},
{p: 5, n: 1, a: sb},
{p: 99, n: 2, a: sb},
},
order: []int{2, 0, 3, 1},
},
{
txs: []txSpec{
{p: 5, n: 1, a: sa},
{p: 10, n: 2, a: sa},
{p: 20, n: 2, a: sb},
{p: 5, n: 1, a: sb},
{p: 99, n: 2, a: sc},
{p: 5, n: 1, a: sc},
},
order: []int{3, 0, 5, 2, 1, 4},
},
{
txs: []txSpec{
{p: 5, n: 1, a: sa},
{p: 10, n: 2, a: sa},
{p: 5, n: 1, a: sb},
{p: 20, n: 2, a: sb},
{p: 5, n: 1, a: sc},
{p: 99, n: 2, a: sc},
},
order: []int{2, 0, 4, 3, 1, 5},
},
{
txs: []txSpec{
{p: 5, n: 1, a: sa},
{p: 10, n: 2, a: sa},
{p: 5, n: 1, a: sc},
{p: 20, n: 2, a: sc},
{p: 5, n: 1, a: sb},
{p: 99, n: 2, a: sb},
},
order: []int{4, 0, 2, 5, 1, 3},
// Index order base on seed 0: 0 0 1 0 1 0 1 1 0
seed: 0,
},
}
for i, tt := range tests {
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
pool := s.mempool

pool := mempool.NewSenderNonceMempoolWithSeed(tt.seed)
// create test txs and insert into mempool
for i, ts := range tt.txs {
tx := testTx{id: i, priority: int64(ts.p), nonce: uint64(ts.n), address: ts.a}
Expand All @@ -202,9 +154,12 @@ func (s *MempoolTestSuite) TestTxOrder() {
for _, tx := range orderedTxs {
require.NoError(t, pool.Remove(tx))
}

require.Equal(t, tt.order, txOrder)
require.Contains(t, fmt.Sprintf("%v", tt.order), fmt.Sprintf("%v", txOrder))
require.Equal(t, 0, pool.CountTx())
})
}
}

func (s *MempoolTestSuite) TestNormalDistributionTxSelection() {

}
Loading