Make empty but non-nil Withdrawals arrays decode as empty but non-nil. (#6291)

This commit is contained in:
Roberto Bayardo 2022-12-15 00:52:14 -08:00 committed by GitHub
parent 863e1ed07b
commit cf6173d042
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -728,6 +728,7 @@ func (rb *RawBody) DecodeRLP(s *rlp.Stream) error {
}
return fmt.Errorf("read Withdrawals: %w", err)
}
rb.Withdrawals = []*Withdrawal{}
for err == nil {
var withdrawal Withdrawal
if err = withdrawal.DecodeRLP(s); err != nil {
@ -909,6 +910,7 @@ func (bb *Body) DecodeRLP(s *rlp.Stream) error {
}
return fmt.Errorf("read Withdrawals: %w", err)
}
bb.Withdrawals = []*Withdrawal{}
for err == nil {
var withdrawal Withdrawal
if err = withdrawal.DecodeRLP(s); err != nil {
@ -1083,6 +1085,7 @@ func (bb *Block) DecodeRLP(s *rlp.Stream) error {
}
return fmt.Errorf("read Withdrawals: %w", err)
}
bb.withdrawals = []*Withdrawal{}
for err == nil {
var withdrawal Withdrawal
if err = withdrawal.DecodeRLP(s); err != nil {

View File

@ -425,4 +425,16 @@ func TestWithdrawalsEncoding(t *testing.T) {
require.NoError(t, rlp.DecodeBytes(encoded, &decoded))
assert.Equal(t, block, &decoded)
// Now test with empty withdrawals
block2 := NewBlock(&header, nil, nil, nil, []*Withdrawal{})
_ = block2.Size()
encoded2, err := rlp.EncodeToBytes(block2)
require.NoError(t, err)
var decoded2 Block
require.NoError(t, rlp.DecodeBytes(encoded2, &decoded2))
assert.Equal(t, block2, &decoded2)
}