diff --git a/txpool/packets.go b/txpool/packets.go index b22bf98b4..d03f6751e 100644 --- a/txpool/packets.go +++ b/txpool/packets.go @@ -181,8 +181,8 @@ func ParsePooledTransactions65(payload []byte, pos int, ctx *TxParseContext, txS return 0, err } - for i := 0; pos != len(payload); i++ { - txSlots.Growth(i) + for i := 0; pos < len(payload); i++ { + txSlots.Growth(i + 1) pos, err = ctx.ParseTransaction(payload, pos, txSlots.txs[i], txSlots.senders.At(i)) if err != nil { return 0, err @@ -205,8 +205,8 @@ func ParsePooledTransactions66(payload []byte, pos int, ctx *TxParseContext, txS return requestID, 0, err } - for i := 0; pos != len(payload); i++ { - txSlots.Growth(i) + for i := 0; pos < len(payload); i++ { + txSlots.Growth(i + 1) pos, err = ctx.ParseTransaction(payload, pos, txSlots.txs[i], txSlots.senders.At(i)) if err != nil { return requestID, 0, err diff --git a/txpool/packets_test.go b/txpool/packets_test.go index 6b093415d..38733d11f 100644 --- a/txpool/packets_test.go +++ b/txpool/packets_test.go @@ -133,6 +133,15 @@ func TestPooledTransactionsPacket66(t *testing.T) { encodeBuf = EncodePooledTransactions66(tt.txs, tt.requestId, encodeBuf) require.Equal(tt.expectedErr, err != nil) require.Equal(tt.encoded, fmt.Sprintf("%x", encodeBuf)) + + ctx := NewTxParseContext() + slots := &TxSlots{} + requestId, _, err := ParsePooledTransactions66(encodeBuf, 0, ctx, slots) + require.NoError(err) + require.Equal(tt.requestId, requestId) + require.Equal(len(tt.txs), len(slots.txs)) + require.Equal(fmt.Sprintf("%x", tt.txs[0]), fmt.Sprintf("%x", slots.txs[0].rlp)) + require.Equal(fmt.Sprintf("%x", tt.txs[1]), fmt.Sprintf("%x", slots.txs[1].rlp)) }) } } diff --git a/txpool/types.go b/txpool/types.go index e39eb6f77..d9d47cb63 100644 --- a/txpool/types.go +++ b/txpool/types.go @@ -144,16 +144,12 @@ func (ctx *TxParseContext) ParseTransaction(payload []byte, pos int, slot *TxSlo // to validate whether they fit into the pool or not. txMaxSize = 4 * txSlotSize // 128KB ) - if len(payload) > txMaxSize { - return 0, fmt.Errorf("%s: too large tx.size=%dKb", ParseTransactionErrorPrefix, len(payload)/1024) - } if len(payload) == 0 { return 0, fmt.Errorf("%s: empty rlp", ParseTransactionErrorPrefix) } if len(sender) != 20 { return 0, fmt.Errorf("%s: expect sender buffer of len 20", ParseTransactionErrorPrefix) } - slot.rlp = payload // Compute transaction hash ctx.keccak1.Reset() ctx.keccak2.Reset() @@ -163,9 +159,14 @@ func (ctx *TxParseContext) ParseTransaction(payload []byte, pos int, slot *TxSlo if err != nil { return 0, fmt.Errorf("%s: size Prefix: %v", ParseTransactionErrorPrefix, err) } - if dataPos+dataLen != len(payload) { - return 0, fmt.Errorf("%s: transaction must be either 1 list or 1 string", ParseTransactionErrorPrefix) + if dataLen > txMaxSize { + return 0, fmt.Errorf("%s: too large tx.size=%dKb", ParseTransactionErrorPrefix, len(payload)/1024) } + slot.rlp = payload[pos : dataPos+dataLen] + + //if dataPos+dataLen != len(payload) { + // return 0, fmt.Errorf("%s: transaction must be either 1 list or 1 string", ParseTransactionErrorPrefix) + //} p = dataPos var txType int