mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-01 00:31:21 +00:00
parse
This commit is contained in:
parent
a892707c19
commit
cf43882226
@ -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
|
||||
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user