diff --git a/txpool/packets.go b/txpool/packets.go index fc1a7f6ba..b22bf98b4 100644 --- a/txpool/packets.go +++ b/txpool/packets.go @@ -181,11 +181,6 @@ func ParsePooledTransactions65(payload []byte, pos int, ctx *TxParseContext, txS return 0, err } - for i := range txSlots.txs { - if txSlots.txs[i] == nil { - txSlots.txs[i] = &TxSlot{} - } - } for i := 0; pos != len(payload); i++ { txSlots.Growth(i) pos, err = ctx.ParseTransaction(payload, pos, txSlots.txs[i], txSlots.senders.At(i)) @@ -210,11 +205,6 @@ func ParsePooledTransactions66(payload []byte, pos int, ctx *TxParseContext, txS return requestID, 0, err } - for i := range txSlots.txs { - if txSlots.txs[i] == nil { - txSlots.txs[i] = &TxSlot{} - } - } for i := 0; pos != len(payload); i++ { txSlots.Growth(i) pos, err = ctx.ParseTransaction(payload, pos, txSlots.txs[i], txSlots.senders.At(i)) diff --git a/txpool/types.go b/txpool/types.go index 9ca5d40d2..e39eb6f77 100644 --- a/txpool/types.go +++ b/txpool/types.go @@ -115,6 +115,9 @@ func (s *TxSlots) Growth(targetSize int) { for s.senders.Len() < targetSize { s.senders = append(s.senders, addressesGrowth...) } + for i := len(s.txs) - 1; i >= 0 && s.txs[i] == nil; i-- { + s.txs[i] = &TxSlot{} + } } const ( diff --git a/txpool/types_test.go b/txpool/types_test.go index 549e90099..0c7336fe3 100644 --- a/txpool/types_test.go +++ b/txpool/types_test.go @@ -97,15 +97,19 @@ func TestTxSlotsGrowth(t *testing.T) { s.Growth(11) assert.Equal(11, len(s.txs)) assert.Equal(11, s.senders.Len()) + assert.NotNil(s.txs[0]) s.Growth(23) assert.Equal(23, len(s.txs)) assert.Equal(23, s.senders.Len()) + assert.NotNil(s.txs[12]) s = &TxSlots{txs: make([]*TxSlot, 20), senders: make(Addresses, 20*20)} s.Growth(20) assert.Equal(20, len(s.txs)) assert.Equal(20, s.senders.Len()) + assert.NotNil(s.txs[0]) s.Growth(23) assert.Equal(23, len(s.txs)) assert.Equal(23, s.senders.Len()) + assert.NotNil(s.txs[21]) }