mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30:44 +00:00
fix error
This commit is contained in:
parent
b2ac1c8d8c
commit
0d34003a40
3 changed files with 21 additions and 8 deletions
|
|
@ -17,6 +17,7 @@
|
||||||
package downloader
|
package downloader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -40,6 +41,16 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type receiptHashList struct {
|
||||||
|
items []eth.Receipt
|
||||||
|
bloomBuf [6]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *receiptHashList) Len() int { return len(l.items) }
|
||||||
|
func (l *receiptHashList) EncodeIndex(i int, buf *bytes.Buffer) {
|
||||||
|
l.items[i].EncodeForHash(&l.bloomBuf, buf)
|
||||||
|
}
|
||||||
|
|
||||||
// downloadTester is a test simulator for mocking out local block chain.
|
// downloadTester is a test simulator for mocking out local block chain.
|
||||||
type downloadTester struct {
|
type downloadTester struct {
|
||||||
chain *core.BlockChain
|
chain *core.BlockChain
|
||||||
|
|
@ -264,13 +275,15 @@ func (dlp *downloadTesterPeer) RequestReceipts(hashes []common.Hash, sink chan *
|
||||||
blobs := eth.ServiceGetReceiptsQuery(dlp.chain, hashes)
|
blobs := eth.ServiceGetReceiptsQuery(dlp.chain, hashes)
|
||||||
|
|
||||||
receipts := make([]types.Receipts, len(blobs))
|
receipts := make([]types.Receipts, len(blobs))
|
||||||
|
|
||||||
|
hashes = make([]common.Hash, len(blobs))
|
||||||
|
hasher := trie.NewStackTrie(nil)
|
||||||
for i, blob := range blobs {
|
for i, blob := range blobs {
|
||||||
rlp.DecodeBytes(blob, &receipts[i])
|
rlp.DecodeBytes(blob, &receipts[i])
|
||||||
}
|
|
||||||
hasher := trie.NewStackTrie(nil)
|
var items []eth.Receipt
|
||||||
hashes = make([]common.Hash, len(receipts))
|
rlp.DecodeBytes(blob, &items)
|
||||||
for i, receipt := range receipts {
|
hashes[i] = types.DeriveSha(&receiptHashList{items: items}, hasher)
|
||||||
hashes[i] = types.DeriveSha(receipt, hasher)
|
|
||||||
}
|
}
|
||||||
req := ð.Request{
|
req := ð.Request{
|
||||||
Peer: dlp.id,
|
Peer: dlp.id,
|
||||||
|
|
|
||||||
|
|
@ -440,7 +440,7 @@ 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 rlp.DecodeBytes(data, &r) == nil {
|
||||||
r.encodeForHash(bloomBuf, outbuf)
|
r.EncodeForHash(bloomBuf, outbuf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ func newReceipt(tr *types.Receipt) Receipt {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// encodeForHash encodes a receipt for the block receiptsRoot derivation.
|
// EncodeForHash encodes a receipt for the block receiptsRoot derivation.
|
||||||
func (r *Receipt) encodeForHash(bloomBuf *[6]byte, out *bytes.Buffer) {
|
func (r *Receipt) EncodeForHash(bloomBuf *[6]byte, out *bytes.Buffer) {
|
||||||
// For typed receipts, add the tx type.
|
// For typed receipts, add the tx type.
|
||||||
if r.TxType != 0 {
|
if r.TxType != 0 {
|
||||||
out.WriteByte(r.TxType)
|
out.WriteByte(r.TxType)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue