Skip to content

Commit

Permalink
Revert "all: use rlp.DecodeBytes instead of rlp.Decode where possible (
Browse files Browse the repository at this point in the history
…ethereum#27994)"

This reverts commit dd6f2f9.
  • Loading branch information
devopsbo3 authored Nov 10, 2023
1 parent d853d17 commit 73c4545
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func ReadHeader(db ethdb.Reader, hash common.Hash, number uint64) *types.Header
return nil
}
header := new(types.Header)
if err := rlp.DecodeBytes(data, header); err != nil {
if err := rlp.Decode(bytes.NewReader(data), header); err != nil {
log.Error("Invalid block header RLP", "hash", hash, "err", err)
return nil
}
Expand Down Expand Up @@ -498,7 +498,7 @@ func ReadBody(db ethdb.Reader, hash common.Hash, number uint64) *types.Body {
return nil
}
body := new(types.Body)
if err := rlp.DecodeBytes(data, body); err != nil {
if err := rlp.Decode(bytes.NewReader(data), body); err != nil {
log.Error("Invalid block body RLP", "hash", hash, "err", err)
return nil
}
Expand Down Expand Up @@ -544,7 +544,7 @@ func ReadTd(db ethdb.Reader, hash common.Hash, number uint64) *big.Int {
return nil
}
td := new(big.Int)
if err := rlp.DecodeBytes(data, td); err != nil {
if err := rlp.Decode(bytes.NewReader(data), td); err != nil {
log.Error("Invalid block total difficulty RLP", "hash", hash, "err", err)
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion core/rawdb/accessors_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package rawdb

import (
"bytes"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -51,7 +53,7 @@ func ReadSkeletonHeader(db ethdb.KeyValueReader, number uint64) *types.Header {
return nil
}
header := new(types.Header)
if err := rlp.DecodeBytes(data, header); err != nil {
if err := rlp.Decode(bytes.NewReader(data), header); err != nil {
log.Error("Invalid skeleton header RLP", "number", number, "err", err)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/state/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (it *nodeIterator) step() error {
}
// Otherwise we've reached an account node, initiate data iteration
var account types.StateAccount
if err := rlp.DecodeBytes(it.stateIt.LeafBlob(), &account); err != nil {
if err := rlp.Decode(bytes.NewReader(it.stateIt.LeafBlob()), &account); err != nil {
return err
}
// Lookup the preimage of account hash
Expand Down
4 changes: 3 additions & 1 deletion core/state/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package state

import (
"bytes"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
Expand All @@ -43,7 +45,7 @@ func NewStateSync(root common.Hash, database ethdb.KeyValueReader, onLeaf func(k
}
}
var obj types.StateAccount
if err := rlp.DecodeBytes(leaf, &obj); err != nil {
if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil {
return err
}
syncer.AddSubTrie(obj.Root, path, parent, parentPath, onSlot)
Expand Down
2 changes: 1 addition & 1 deletion core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestEIP2718TransactionEncode(t *testing.T) {

func decodeTx(data []byte) (*Transaction, error) {
var tx Transaction
t, err := &tx, rlp.DecodeBytes(data, &tx)
t, err := &tx, rlp.Decode(bytes.NewReader(data), &tx)
return t, err
}

Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tracers

import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -452,7 +453,7 @@ func (api *API) TraceBlockByHash(ctx context.Context, hash common.Hash, config *
// and returns them as a JSON object.
func (api *API) TraceBlock(ctx context.Context, blob hexutil.Bytes, config *TraceConfig) ([]*txTraceResult, error) {
block := new(types.Block)
if err := rlp.DecodeBytes(blob, block); err != nil {
if err := rlp.Decode(bytes.NewReader(blob), block); err != nil {
return nil, fmt.Errorf("could not decode block: %v", err)
}
return api.traceBlock(ctx, block, config)
Expand Down
3 changes: 2 additions & 1 deletion light/odr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package light

import (
"bytes"
"context"
"errors"
"math/big"
Expand Down Expand Up @@ -125,7 +126,7 @@ func GetBody(ctx context.Context, odr OdrBackend, hash common.Hash, number uint6
return nil, err
}
body := new(types.Body)
if err := rlp.DecodeBytes(data, body); err != nil {
if err := rlp.Decode(bytes.NewReader(data), body); err != nil {
return nil, err
}
return body, nil
Expand Down
2 changes: 0 additions & 2 deletions p2p/discover/v4wire/v4wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ func Decode(input []byte) (Packet, Pubkey, []byte, error) {
default:
return nil, fromKey, hash, fmt.Errorf("unknown type: %d", ptype)
}
// Here we use NewStream to allow for additional data after the first
// RLP object (forward-compatibility).
s := rlp.NewStream(bytes.NewReader(sigdata[1:]), 0)
err = s.Decode(req)
return req, fromKey, hash, err
Expand Down
4 changes: 2 additions & 2 deletions signer/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestSignTx(t *testing.T) {
t.Fatal(err)
}
parsedTx := &types.Transaction{}
rlp.DecodeBytes(res.Raw, parsedTx)
rlp.Decode(bytes.NewReader(res.Raw), parsedTx)

//The tx should NOT be modified by the UI
if parsedTx.Value().Cmp(tx.Value.ToInt()) != 0 {
Expand All @@ -308,7 +308,7 @@ func TestSignTx(t *testing.T) {
t.Fatal(err)
}
parsedTx2 := &types.Transaction{}
rlp.DecodeBytes(res.Raw, parsedTx2)
rlp.Decode(bytes.NewReader(res.Raw), parsedTx2)

//The tx should be modified by the UI
if parsedTx2.Value().Cmp(tx.Value.ToInt()) != 0 {
Expand Down

0 comments on commit 73c4545

Please sign in to comment.