mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
eth/protocols/eth: put back fast decoder for hashing
This commit is contained in:
parent
3348638509
commit
98a5a26082
1 changed files with 47 additions and 1 deletions
|
|
@ -90,6 +90,51 @@ func (r *Receipt) bloom(buffer *[6]byte) types.Bloom {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decode assigns the fields of r by decoding the network format.
|
||||||
|
func (r *Receipt) decode(input []byte) error {
|
||||||
|
input, _, err := rlp.SplitList(input)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("inner list: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// txType
|
||||||
|
var txType uint64
|
||||||
|
txType, input, err = rlp.SplitUint64(input)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid txType: %w", err)
|
||||||
|
}
|
||||||
|
if txType > 0x7f {
|
||||||
|
return fmt.Errorf("invalid txType: too large")
|
||||||
|
}
|
||||||
|
r.TxType = byte(txType)
|
||||||
|
|
||||||
|
// status
|
||||||
|
r.PostStateOrStatus, input, err = rlp.SplitString(input)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid postStateOrStatus: %w", err)
|
||||||
|
}
|
||||||
|
if len(r.PostStateOrStatus) > 1 && len(r.PostStateOrStatus) != 32 {
|
||||||
|
return fmt.Errorf("invalid postStateOrStatus length %d", len(r.PostStateOrStatus))
|
||||||
|
}
|
||||||
|
|
||||||
|
// gas
|
||||||
|
r.GasUsed, input, err = rlp.SplitUint64(input)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid gasUsed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// logs
|
||||||
|
_, rest, err := rlp.SplitList(input)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid logs: %w", err)
|
||||||
|
}
|
||||||
|
if len(rest) != 0 {
|
||||||
|
return fmt.Errorf("junk at end of receipt")
|
||||||
|
}
|
||||||
|
r.Logs = input
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ReceiptList is the block receipt list as downloaded by eth/69.
|
// ReceiptList is the block receipt list as downloaded by eth/69.
|
||||||
type ReceiptList struct {
|
type ReceiptList struct {
|
||||||
items rlp.RawList[Receipt]
|
items rlp.RawList[Receipt]
|
||||||
|
|
@ -146,6 +191,7 @@ func (rl *ReceiptList) EncodeRLP(w io.Writer) error {
|
||||||
return rl.items.EncodeRLP(w)
|
return rl.items.EncodeRLP(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Derivable returns a DerivableList, which can be used to decode
|
||||||
func (rl *ReceiptList) Derivable() types.DerivableList {
|
func (rl *ReceiptList) Derivable() types.DerivableList {
|
||||||
var bloomBuf [6]byte
|
var bloomBuf [6]byte
|
||||||
write := writeReceiptForHash(&bloomBuf)
|
write := writeReceiptForHash(&bloomBuf)
|
||||||
|
|
@ -156,7 +202,7 @@ func (rl *ReceiptList) Derivable() types.DerivableList {
|
||||||
func writeReceiptForHash(bloomBuf *[6]byte) func([]byte, *bytes.Buffer) {
|
func writeReceiptForHash(bloomBuf *[6]byte) func([]byte, *bytes.Buffer) {
|
||||||
return func(data []byte, outbuf *bytes.Buffer) {
|
return func(data []byte, outbuf *bytes.Buffer) {
|
||||||
var r Receipt
|
var r Receipt
|
||||||
if rlp.DecodeBytes(data, &r) == nil {
|
if r.decode(data) == nil {
|
||||||
r.encodeForHash(bloomBuf, outbuf)
|
r.encodeForHash(bloomBuf, outbuf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue