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