diff --git a/p2p/sentry/sentry_multi_client/sentry_multi_client.go b/p2p/sentry/sentry_multi_client/sentry_multi_client.go index e9794af9985..9d58b4bfd46 100644 --- a/p2p/sentry/sentry_multi_client/sentry_multi_client.go +++ b/p2p/sentry/sentry_multi_client/sentry_multi_client.go @@ -528,10 +528,10 @@ func (cs *MultiClient) newBlock66(ctx context.Context, inreq *proto_sentry.Inbou return fmt.Errorf("decode 4 NewBlockMsg: %w", err) } if err := request.SanityCheck(); err != nil { - return fmt.Errorf("newBlock66: %w", err) + return fmt.Errorf("newBlock66: %w, PeerID: %s", err, fmt.Sprintf("%x", sentry.ConvertH512ToPeerID(inreq.PeerId))[:8]) } if err := request.Block.HashCheck(); err != nil { - return fmt.Errorf("newBlock66: %w", err) + return fmt.Errorf("newBlock66: %w, PeerID: %s", err, fmt.Sprintf("%x", sentry.ConvertH512ToPeerID(inreq.PeerId))[:8]) } if request.Sidecars != nil && len(request.Sidecars) > 0 { diff --git a/turbo/rpchelper/helper.go b/turbo/rpchelper/helper.go index b076bcfdddb..cc0bb545c64 100644 --- a/turbo/rpchelper/helper.go +++ b/turbo/rpchelper/helper.go @@ -72,7 +72,9 @@ func _GetBlockNumber(requireCanonical bool, blockNrOrHash rpc.BlockNumberOrHash, if fs := parliafinality.GetFinalizationService(); fs != nil { blockHash := fs.GetFinalizeBlockHash() blockNum := rawdb.ReadHeaderNumber(tx, blockHash) - return *blockNum, blockHash, false, nil + if blockNum != nil { + return *blockNum, blockHash, false, nil + } } blockNumber, err = GetFinalizedBlockNumber(tx) if err != nil { @@ -82,7 +84,9 @@ func _GetBlockNumber(requireCanonical bool, blockNrOrHash rpc.BlockNumberOrHash, if fs := parliafinality.GetFinalizationService(); fs != nil { blockHash := fs.GetSafeBlockHash() blockNum := rawdb.ReadHeaderNumber(tx, blockHash) - return *blockNum, blockHash, false, nil + if blockNum != nil { + return *blockNum, blockHash, false, nil + } } blockNumber, err = GetSafeBlockNumber(tx) if err != nil { diff --git a/turbo/stages/bodydownload/body_algos.go b/turbo/stages/bodydownload/body_algos.go index 663b0dfd88d..fe950fe1110 100644 --- a/turbo/stages/bodydownload/body_algos.go +++ b/turbo/stages/bodydownload/body_algos.go @@ -37,7 +37,7 @@ func (bd *BodyDownload) UpdateFromDb(db kv.Tx) (headHeight, headTime uint64, hea bd.maxProgress = headerProgress + 1 // Resetting for requesting a new range of blocks bd.requestedLow = bodyProgress + 1 - bd.requestedMap = make(map[TripleHash]uint64) + bd.requestedMap = make(map[BodyHashes]uint64) bd.delivered.Clear() bd.deliveredCount = 0 bd.wastedCount = 0 @@ -164,15 +164,13 @@ func (bd *BodyDownload) RequestMoreBodies(tx kv.RwTx, blockReader services.FullB } } if request { - var tripleHash TripleHash - copy(tripleHash[:], header.UncleHash.Bytes()) - copy(tripleHash[length.Hash:], header.TxHash.Bytes()) + var bodyHashes BodyHashes + copy(bodyHashes[:], header.UncleHash.Bytes()) + copy(bodyHashes[length.Hash:], header.TxHash.Bytes()) if header.WithdrawalsHash != nil { - copy(tripleHash[2*length.Hash:], header.WithdrawalsHash.Bytes()) - } else { - copy(tripleHash[2*length.Hash:], types.EmptyRootHash.Bytes()) + copy(bodyHashes[2*length.Hash:], header.WithdrawalsHash.Bytes()) } - bd.requestedMap[tripleHash] = blockNum + bd.requestedMap[bodyHashes] = blockNum blockNums = append(blockNums, blockNum) hashes = append(hashes, hash) } else { @@ -307,18 +305,19 @@ Loop: txs, uncles, withdrawals, lenOfP2PMessage, sidecars := delivery.txs, delivery.uncles, delivery.withdrawals, delivery.lenOfP2PMessage, delivery.sidecars for i := range txs { + var bodyHashes BodyHashes uncleHash := types.CalcUncleHash(uncles[i]) + copy(bodyHashes[:], uncleHash.Bytes()) txHash := types.DeriveSha(RawTransactions(txs[i])) - withdrawalsHash := types.DeriveSha(withdrawals[i]) - - var tripleHash TripleHash - copy(tripleHash[:], uncleHash.Bytes()) - copy(tripleHash[length.Hash:], txHash.Bytes()) - copy(tripleHash[2*length.Hash:], withdrawalsHash.Bytes()) + copy(bodyHashes[length.Hash:], txHash.Bytes()) + if withdrawals[i] != nil { + withdrawalsHash := types.DeriveSha(withdrawals[i]) + copy(bodyHashes[2*length.Hash:], withdrawalsHash.Bytes()) + } // Block numbers are added to the bd.delivered bitmap here, only for blocks for which the body has been received, and their double hashes are present in the bd.requestedMap // Also, block numbers can be added to bd.delivered for empty blocks, above - blockNum, ok := bd.requestedMap[tripleHash] + blockNum, ok := bd.requestedMap[bodyHashes] if !ok { undelivered++ continue @@ -329,7 +328,7 @@ Loop: toClean[blockNum] = struct{}{} } } - delete(bd.requestedMap, tripleHash) // Delivered, cleaning up + delete(bd.requestedMap, bodyHashes) // Delivered, cleaning up bd.addBodyToCache(blockNum, &types.RawBody{Transactions: txs[i], Uncles: uncles[i], Withdrawals: withdrawals[i], Sidecars: sidecars[i]}) bd.delivered.Add(blockNum) diff --git a/turbo/stages/bodydownload/body_data_struct.go b/turbo/stages/bodydownload/body_data_struct.go index 5234171f411..c49e7c835d2 100644 --- a/turbo/stages/bodydownload/body_data_struct.go +++ b/turbo/stages/bodydownload/body_data_struct.go @@ -12,8 +12,8 @@ import ( "github.com/ledgerwatch/erigon/core/types" ) -// TripleHash is type to be used for the mapping between TxHash, UncleHash, and WithdrawalsHash to the block header -type TripleHash [3 * length.Hash]byte +// BodyHashes is type to be used for the mapping between TxHash, UncleHash, and WithdrawalsHash to the block header +type BodyHashes [3 * length.Hash]byte const MaxBodiesInRequest = 1024 @@ -36,7 +36,7 @@ type BodyTreeItem struct { // BodyDownload represents the state of body downloading process type BodyDownload struct { peerMap map[[64]byte]int - requestedMap map[TripleHash]uint64 + requestedMap map[BodyHashes]uint64 DeliveryNotify chan struct{} deliveryCh chan Delivery Engine consensus.Engine @@ -67,7 +67,7 @@ type BodyRequest struct { // NewBodyDownload create a new body download state object func NewBodyDownload(engine consensus.Engine, blockBufferSize, bodyCacheLimit int, br services.FullBlockReader, logger log.Logger) *BodyDownload { bd := &BodyDownload{ - requestedMap: make(map[TripleHash]uint64), + requestedMap: make(map[BodyHashes]uint64), bodyCacheLimit: bodyCacheLimit, delivered: roaring64.New(), deliveriesH: make(map[uint64]*types.Header),