mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
eth/protocols/eth: fix handleReceipts69
This commit is contained in:
parent
1b8422cd73
commit
f213897a41
2 changed files with 17 additions and 51 deletions
|
|
@ -426,10 +426,15 @@ func handleReceipts69(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
}
|
}
|
||||||
return hashes
|
return hashes
|
||||||
}
|
}
|
||||||
|
// TODO this can probably be made 0-alloc.
|
||||||
|
var enc []rlp.RawValue
|
||||||
|
for _, blockReceipts := range res.List {
|
||||||
|
enc = append(enc, blockReceipts.toStorageReceiptsRLP())
|
||||||
|
}
|
||||||
return peer.dispatchResponse(&Response{
|
return peer.dispatchResponse(&Response{
|
||||||
id: res.RequestId,
|
id: res.RequestId,
|
||||||
code: ReceiptsMsg,
|
code: ReceiptsMsg,
|
||||||
Res: &res,
|
Res: &enc,
|
||||||
}, metadata)
|
}, metadata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,57 +150,18 @@ func (rl *ReceiptList69) EncodeIndex(i int, b *bytes.Buffer) {
|
||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeForDatabase
|
func (rl *ReceiptList69) toStorageReceiptsRLP() rlp.RawValue {
|
||||||
func (rl *ReceiptList69) EncodeForDatabase() []byte {
|
var (
|
||||||
if rl.buf == nil {
|
out bytes.Buffer
|
||||||
rl.buf = new(receiptListBuffers)
|
enc = rlp.NewEncoderBuffer(&out)
|
||||||
|
)
|
||||||
|
outer := enc.List()
|
||||||
|
for _, receipts := range rl.items {
|
||||||
|
receipts.EncodeRLP(enc)
|
||||||
}
|
}
|
||||||
// TODO this is probably wrong
|
enc.ListEnd(outer)
|
||||||
var result []byte
|
enc.Flush()
|
||||||
var b = new(bytes.Buffer)
|
return out.Bytes()
|
||||||
for _, r := range rl.items {
|
|
||||||
var (
|
|
||||||
bloom = r.bloom(&rl.buf.bloom)
|
|
||||||
w = &rl.buf.enc
|
|
||||||
)
|
|
||||||
// encode receipt list: [postStateOrStatus, gasUsed, bloom, logs]
|
|
||||||
w.Reset(b)
|
|
||||||
l := w.List()
|
|
||||||
w.WriteBytes(r.PostStateOrStatus)
|
|
||||||
w.WriteUint64(r.GasUsed)
|
|
||||||
w.WriteBytes(bloom[:])
|
|
||||||
w.Write(r.Logs)
|
|
||||||
w.ListEnd(l)
|
|
||||||
if err := w.Flush(); err != nil {
|
|
||||||
return []byte{}
|
|
||||||
}
|
|
||||||
// if this is a legacy transaction receipt, we are done.
|
|
||||||
if r.TxType == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Otherwise it's a typed transaction receipt, which has the type prefix and
|
|
||||||
// the inner list as a byte-array: tx-type || rlp(list).
|
|
||||||
// Since b contains the correct inner list, we can reuse its content.
|
|
||||||
w.Reset(b)
|
|
||||||
w.WriteUint64(uint64(r.TxType))
|
|
||||||
w.WriteBytes(b.Bytes())
|
|
||||||
w.Flush()
|
|
||||||
result = append(result, b.Bytes()...)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *ReceiptList69) toReceipts() []*types.Receipt {
|
|
||||||
list := make([]*types.Receipt, len(rl.items))
|
|
||||||
for i, r := range rl.items {
|
|
||||||
list[i] = &types.Receipt{
|
|
||||||
Type: r.TxType,
|
|
||||||
PostState: r.PostStateOrStatus,
|
|
||||||
CumulativeGasUsed: r.GasUsed,
|
|
||||||
}
|
|
||||||
rlp.DecodeBytes(r.Logs, &list[i].Logs)
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// blockReceiptsToNetwork takes a slice of rlp-encoded receipts, and transactions,
|
// blockReceiptsToNetwork takes a slice of rlp-encoded receipts, and transactions,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue