Skip to content

Commit

Permalink
fix: nil pointer ref priority nonce mempool iterator (#17668)
Browse files Browse the repository at this point in the history
(cherry picked from commit cc7b117)

# Conflicts:
#	types/mempool/priority_nonce.go
  • Loading branch information
0xmuralik authored and mergify[bot] committed Sep 11, 2023
1 parent c79964c commit d62c8e0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* (config) [#17649](https://github.com/cosmos/cosmos-sdk/pull/17649) Fix `mempool.max-txs` configuration is invalid in `app.config`.
* (mempool) [#17668](https://github.com/cosmos/cosmos-sdk/pull/17668) Fix: `PriorityNonceIterator.Next()` nil pointer ref for min priority at the end of iteration.

## [v0.47.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.5) - 2023-09-01

Expand Down
4 changes: 4 additions & 0 deletions types/mempool/priority_nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ func (i *PriorityNonceIterator) Next() Iterator {
// priority in the pool.
if key.priority < i.nextPriority {
return i.iteratePriority()
<<<<<<< HEAD

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expecting }

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected statement, found '<<' (typecheck)

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '<<'

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expecting }

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expecting }

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expecting }

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expecting }

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expecting }

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expecting }

Check failure on line 286 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expecting }
} else if key.priority == i.nextPriority {

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected else after top level declaration

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected else after top level declaration

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected else after top level declaration

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected else after top level declaration

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected else after top level declaration

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected else after top level declaration

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected else after top level declaration

Check failure on line 287 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected else after top level declaration
=======

Check failure on line 288 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected statement, found '==' (typecheck)

Check failure on line 288 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '=='
} else if i.priorityNode.Next() != nil && i.mempool.cfg.TxPriority.Compare(key.priority, i.nextPriority) == 0 {
>>>>>>> cc7b1178e (fix: nil pointer ref priority nonce mempool iterator (#17668))

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#' (typecheck)

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected statement, found '>>' (typecheck)

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '>>'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 290 in types/mempool/priority_nonce.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
// Weight is incorporated into the priority index key only (not sender index)
// so we must fetch it here from the scores map.
weight := i.mempool.scores[txMeta{nonce: key.nonce, sender: key.sender}].weight
Expand Down
56 changes: 56 additions & 0 deletions types/mempool/priority_nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,62 @@ func (s *MempoolTestSuite) TestPriorityNonceTxOrder() {
}
}

func (s *MempoolTestSuite) TestIterator() {
t := s.T()
ctx := sdk.NewContext(nil, false, log.NewNopLogger())
accounts := simtypes.RandomAccounts(rand.New(rand.NewSource(0)), 2)
sa := accounts[0].Address
sb := accounts[1].Address

tests := []struct {
txs []txSpec
fail bool
}{
{
txs: []txSpec{
{p: 20, n: 1, a: sa},
{p: 15, n: 1, a: sb},
{p: 6, n: 2, a: sa},
{p: 21, n: 4, a: sa},
{p: 8, n: 2, a: sb},
},
},
{
txs: []txSpec{
{p: 20, n: 1, a: sa},
{p: 15, n: 1, a: sb},
{p: 6, n: 2, a: sa},
{p: 21, n: 4, a: sa},
{p: math.MinInt64, n: 2, a: sb},
},
},
}

for i, tt := range tests {
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
pool := mempool.DefaultPriorityMempool()

// 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}
c := ctx.WithPriority(tx.priority)
err := pool.Insert(c, tx)
require.NoError(t, err)
}

// iterate through txs
iterator := pool.Select(ctx, nil)
for iterator != nil {
tx := iterator.Tx().(testTx)
require.Equal(t, tt.txs[tx.id].p, int(tx.priority))
require.Equal(t, tt.txs[tx.id].n, int(tx.nonce))
require.Equal(t, tt.txs[tx.id].a, tx.address)
iterator = iterator.Next()
}
})
}
}

func (s *MempoolTestSuite) TestPriorityTies() {
ctx := sdk.NewContext(nil, cmtproto.Header{}, false, log.NewNopLogger())
accounts := simtypes.RandomAccounts(rand.New(rand.NewSource(0)), 3)
Expand Down

0 comments on commit d62c8e0

Please sign in to comment.