mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
fix: change the decode type
This commit is contained in:
parent
59ea5c7f15
commit
bbf46450ba
4 changed files with 28 additions and 20 deletions
|
|
@ -1049,7 +1049,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state
|
||||||
receipts := make([]rlp.RawValue, len(results))
|
receipts := make([]rlp.RawValue, len(results))
|
||||||
for i, result := range results {
|
for i, result := range results {
|
||||||
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body())
|
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.body())
|
||||||
receipts[i] = result.Receipts
|
receipts[i] = types.EncodeBlockReceiptLists([]types.Receipts{result.Receipts})[0]
|
||||||
}
|
}
|
||||||
if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil {
|
if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil {
|
||||||
log.Debug("Downloaded item processing failed", "number", results[index].Header.Number, "hash", results[index].Header.Hash(), "err", err)
|
log.Debug("Downloaded item processing failed", "number", results[index].Header.Number, "hash", results[index].Header.Hash(), "err", err)
|
||||||
|
|
@ -1063,7 +1063,7 @@ func (d *Downloader) commitPivotBlock(result *fetchResult) error {
|
||||||
log.Debug("Committing snap sync pivot as new head", "number", block.Number(), "hash", block.Hash())
|
log.Debug("Committing snap sync pivot as new head", "number", block.Number(), "hash", block.Hash())
|
||||||
|
|
||||||
// Commit the pivot block as the new head, will require full sync from here on
|
// Commit the pivot block as the new head, will require full sync from here on
|
||||||
if _, err := d.blockchain.InsertReceiptChain([]*types.Block{block}, []rlp.RawValue{result.Receipts}, d.ancientLimit); err != nil {
|
if _, err := d.blockchain.InsertReceiptChain([]*types.Block{block}, types.EncodeBlockReceiptLists([]types.Receipts{result.Receipts}), d.ancientLimit); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := d.blockchain.SnapSyncCommitHead(block.Hash()); err != nil {
|
if err := d.blockchain.SnapSyncCommitHead(block.Hash()); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -95,12 +95,15 @@ func (q *receiptQueue) deliver(peer *peerConnection, packet *eth.Response) (int,
|
||||||
|
|
||||||
receipts := make([][]*types.Receipt, len(receiptsRLP))
|
receipts := make([][]*types.Receipt, len(receiptsRLP))
|
||||||
for i, rc := range receiptsRLP {
|
for i, rc := range receiptsRLP {
|
||||||
var r []*types.Receipt
|
var rcStorage []*types.ReceiptForStorage
|
||||||
if err := rlp.DecodeBytes(rc, &r); err != nil {
|
if err := rlp.DecodeBytes(rc, &rcStorage); err != nil {
|
||||||
peer.log.Debug("Failed to decode retreived receipts")
|
peer.log.Error("Failed to decode retreived receipts", "err", err)
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
receipts[i] = r
|
receipts[i] = make([]*types.Receipt, len(rcStorage))
|
||||||
|
for j := range rcStorage {
|
||||||
|
receipts[i][j] = (*types.Receipt)(rcStorage[j])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accepted, err := q.queue.DeliverReceipts(peer.id, receipts, hashes, false)
|
accepted, err := q.queue.DeliverReceipts(peer.id, receipts, hashes, false)
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ type fetchResult struct {
|
||||||
Header *types.Header
|
Header *types.Header
|
||||||
Uncles []*types.Header
|
Uncles []*types.Header
|
||||||
Transactions types.Transactions
|
Transactions types.Transactions
|
||||||
Receipts [][]*types.Receipt
|
Receipts types.Receipts
|
||||||
Withdrawals types.Withdrawals
|
Withdrawals types.Withdrawals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ func newFetchResult(header *types.Header, snapSync bool) *fetchResult {
|
||||||
if snapSync {
|
if snapSync {
|
||||||
if header.EmptyReceipts() {
|
if header.EmptyReceipts() {
|
||||||
// Ensure the receipts list is valid even if it isn't actively fetched.
|
// Ensure the receipts list is valid even if it isn't actively fetched.
|
||||||
item.Receipts = [][]*types.Receipt{}
|
item.Receipts = []*types.Receipt{}
|
||||||
} else {
|
} else {
|
||||||
item.pending.Store(item.pending.Load() | (1 << receiptType))
|
item.pending.Store(item.pending.Load() | (1 << receiptType))
|
||||||
}
|
}
|
||||||
|
|
@ -647,11 +647,11 @@ func (q *queue) DeliverReceipts(id string, receiptList [][]*types.Receipt, recei
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
reconstruct := func(index int, result *fetchResult) int {
|
reconstruct := func(index int, result *fetchResult) int {
|
||||||
result.Receipts = append(result.Receipts, receiptList[index])
|
result.Receipts = append(result.Receipts, receiptList[index]...)
|
||||||
if index == len(receiptList) && lastBlockIncomplete {
|
if lastBlockIncomplete && index == len(receiptList) {
|
||||||
// 1. Verify the total number of tx delivered
|
// 1. Verify the total number of tx delivered
|
||||||
if uint64(len(receiptList[index])) > result.Header.GasUsed/21_000 {
|
if uint64(len(receiptList[index])) > result.Header.GasUsed/21_000 {
|
||||||
result.Receipts = [][]*types.Receipt{}
|
result.Receipts = []*types.Receipt{}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
// 2. Verify the size of each receipt against the gas limit of the corresponding transaction
|
// 2. Verify the size of each receipt against the gas limit of the corresponding transaction
|
||||||
|
|
@ -661,14 +661,14 @@ func (q *queue) DeliverReceipts(id string, receiptList [][]*types.Receipt, recei
|
||||||
logSize += uint64(len(log.Data))
|
logSize += uint64(len(log.Data))
|
||||||
}
|
}
|
||||||
if logSize > params.MaxTxGas/params.LogDataGas {
|
if logSize > params.MaxTxGas/params.LogDataGas {
|
||||||
result.Receipts = [][]*types.Receipt{}
|
result.Receipts = []*types.Receipt{}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
result.receiptSize += logSize
|
result.receiptSize += logSize
|
||||||
}
|
}
|
||||||
// 3. Verify the total download receipt size is no longer than allowed by the block gas limit
|
// 3. Verify the total download receipt size is no longer than allowed by the block gas limit
|
||||||
if result.receiptSize > result.Header.GasLimit/params.LogDataGas {
|
if result.receiptSize > result.Header.GasLimit/params.LogDataGas {
|
||||||
result.Receipts = [][]*types.Receipt{}
|
result.Receipts = []*types.Receipt{}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return len(result.Receipts)
|
return len(result.Receipts)
|
||||||
|
|
@ -730,13 +730,9 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, header := range request.Headers[:i] {
|
for _, header := range request.Headers[:i] {
|
||||||
|
resume := -1
|
||||||
if res, stale, err := q.resultCache.GetDeliverySlot(header.Number.Uint64()); err == nil && !stale {
|
if res, stale, err := q.resultCache.GetDeliverySlot(header.Number.Uint64()); err == nil && !stale {
|
||||||
resume := reconstruct(accepted, res)
|
resume = reconstruct(accepted, res)
|
||||||
if resume >= 0 {
|
|
||||||
// TODO: add receipt index in TaskPool
|
|
||||||
taskPool[header.Hash()] = header
|
|
||||||
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// else: between here and above, some other peer filled this result,
|
// else: between here and above, some other peer filled this result,
|
||||||
// or it was indeed a no-op. This should not happen, but if it does it's
|
// or it was indeed a no-op. This should not happen, but if it does it's
|
||||||
|
|
@ -746,6 +742,11 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
|
||||||
}
|
}
|
||||||
// Clean up a successful fetch
|
// Clean up a successful fetch
|
||||||
delete(taskPool, hashes[accepted])
|
delete(taskPool, hashes[accepted])
|
||||||
|
if resume >= 0 {
|
||||||
|
// TODO: add receipt index in TaskPool
|
||||||
|
taskPool[header.Hash()] = header
|
||||||
|
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||||
|
}
|
||||||
accepted++
|
accepted++
|
||||||
}
|
}
|
||||||
resDropMeter.Mark(int64(results - accepted))
|
resDropMeter.Mark(int64(results - accepted))
|
||||||
|
|
|
||||||
|
|
@ -367,7 +367,11 @@ func XTestDelivery(t *testing.T) {
|
||||||
for i, receipt := range rcs {
|
for i, receipt := range rcs {
|
||||||
hashes[i] = types.DeriveSha(receipt, hasher)
|
hashes[i] = types.DeriveSha(receipt, hasher)
|
||||||
}
|
}
|
||||||
_, err := q.DeliverReceipts(peer.id, types.EncodeBlockReceiptLists(rcs), hashes)
|
receiptSets := make([][]*types.Receipt, len(rcs))
|
||||||
|
for i := range rcs {
|
||||||
|
receiptSets[i] = rcs[i]
|
||||||
|
}
|
||||||
|
_, err := q.DeliverReceipts(peer.id, receiptSets, hashes, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("delivered %d receipts %v\n", len(rcs), err)
|
fmt.Printf("delivered %d receipts %v\n", len(rcs), err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue