From 706f1bad3524934e68f6cc640900650638746549 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Tue, 19 Nov 2024 17:38:04 +0700 Subject: [PATCH] Check p2p hash for pre 0.13.2 blocks --- p2p/sync.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/p2p/sync.go b/p2p/sync.go index 8016d11419..e437df1fe5 100644 --- a/p2p/sync.go +++ b/p2p/sync.go @@ -366,25 +366,23 @@ func (s *syncService) adaptAndSanityCheckBlock(ctx context.Context, header *spec } if blockVer.LessThan(core.Ver0_13_2) { + p2pHash, err := s.blockchain.BlockP2PHashByNumber(coreBlock.Number) + if err != nil { + bodyCh <- blockBody{err: fmt.Errorf("failed to get p2p hash: %w", err)} + return + } + expectedHash, _, err := core.Post0132Hash(coreBlock, stateDiff) if err != nil { bodyCh <- blockBody{err: fmt.Errorf("failed to compute p2p hash: %w", err)} return } - if !coreBlock.Hash.Equal(expectedHash) { + if !p2pHash.Equal(expectedHash) { err = fmt.Errorf("received p2p hash %v doesn't match expected %v", coreBlock.Hash, expectedHash) bodyCh <- blockBody{err: err} return } - - // once we verified p2p hash with received one above - // we need to overwrite it with old scheme hash - coreBlock.Hash, err = core.BlockHash(coreBlock) - if err != nil { - bodyCh <- blockBody{err: fmt.Errorf("failed to generate block hash: %w", err)} - return - } } stateUpdate := &core.StateUpdate{