mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
les: fixed receipts encoding
This commit is contained in:
parent
9fd76e33af
commit
e63427abb8
3 changed files with 24 additions and 11 deletions
|
|
@ -644,14 +644,18 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
break
|
||||
}
|
||||
// Retrieve the requested block's receipts, skipping if unknown to us
|
||||
results := core.GetBlockReceipts(pm.chainDb, hash, core.GetBlockNumber(pm.chainDb, hash))
|
||||
if results == nil {
|
||||
blockReceipts := core.GetBlockReceipts(pm.chainDb, hash, core.GetBlockNumber(pm.chainDb, hash))
|
||||
if blockReceipts == nil {
|
||||
if header := pm.blockchain.GetHeaderByHash(hash); header == nil || header.ReceiptHash != types.EmptyRootHash {
|
||||
continue
|
||||
}
|
||||
}
|
||||
// If known, encode and queue for response packet
|
||||
if encoded, err := rlp.EncodeToBytes(results); err != nil {
|
||||
storageReceipts := make([]*types.ReceiptForStorage, len(blockReceipts))
|
||||
for i, receipt := range blockReceipts {
|
||||
storageReceipts[i] = (*types.ReceiptForStorage)(receipt)
|
||||
}
|
||||
if encoded, err := rlp.EncodeToBytes(storageReceipts); err != nil {
|
||||
log.Error("Failed to encode receipt", "err", err)
|
||||
} else {
|
||||
receipts = append(receipts, encoded)
|
||||
|
|
@ -671,7 +675,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
// A batch of receipts arrived to one of our previous requests
|
||||
var resp struct {
|
||||
ReqID, BV uint64
|
||||
Receipts []types.Receipts
|
||||
Receipts [][]*types.ReceiptForStorage
|
||||
}
|
||||
if err := msg.Decode(&resp); err != nil {
|
||||
return errResp(ErrDecode, "msg %v: %v", msg, err)
|
||||
|
|
|
|||
|
|
@ -299,12 +299,17 @@ func testGetReceipt(t *testing.T, protocol int) {
|
|||
defer peer.close()
|
||||
|
||||
// Collect the hashes to request, and the response to expect
|
||||
hashes, receipts := []common.Hash{}, []types.Receipts{}
|
||||
hashes, receipts := []common.Hash{}, [][]*types.ReceiptForStorage{}
|
||||
for i := uint64(0); i <= bc.CurrentBlock().NumberU64(); i++ {
|
||||
block := bc.GetBlockByNumber(i)
|
||||
|
||||
hashes = append(hashes, block.Hash())
|
||||
receipts = append(receipts, core.GetBlockReceipts(db, block.Hash(), block.NumberU64()))
|
||||
blockReceipts := core.GetBlockReceipts(db, block.Hash(), block.NumberU64())
|
||||
storageReceipts := make([]*types.ReceiptForStorage, len(blockReceipts))
|
||||
for i, receipt := range blockReceipts {
|
||||
storageReceipts[i] = (*types.ReceiptForStorage)(receipt)
|
||||
}
|
||||
receipts = append(receipts, storageReceipts)
|
||||
}
|
||||
// Send the hash request and verify the response
|
||||
cost := peer.GetRequestCost(GetReceiptsMsg, len(hashes))
|
||||
|
|
|
|||
|
|
@ -159,22 +159,26 @@ func (r *ReceiptsRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
if msg.MsgType != MsgReceipts {
|
||||
return errInvalidMessageType
|
||||
}
|
||||
receipts := msg.Obj.([]types.Receipts)
|
||||
if len(receipts) != 1 {
|
||||
receiptsList := msg.Obj.([][]*types.ReceiptForStorage)
|
||||
if len(receiptsList) != 1 {
|
||||
return errInvalidEntryCount
|
||||
}
|
||||
receipt := receipts[0]
|
||||
storageReceipts := receiptsList[0]
|
||||
receipts := make(types.Receipts, len(storageReceipts))
|
||||
for i, receipt := range storageReceipts {
|
||||
receipts[i] = (*types.Receipt)(receipt)
|
||||
}
|
||||
|
||||
// Retrieve our stored header and validate receipt content against it
|
||||
header := core.GetHeader(db, r.Hash, r.Number)
|
||||
if header == nil {
|
||||
return errHeaderUnavailable
|
||||
}
|
||||
if header.ReceiptHash != types.DeriveSha(receipt) {
|
||||
if header.ReceiptHash != types.DeriveSha(receipts) {
|
||||
return errReceiptHashMismatch
|
||||
}
|
||||
// Validations passed, store and return
|
||||
r.Receipts = receipt
|
||||
r.Receipts = receipts
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue