Skip to content

Commit 706f1ba

Browse files
Check p2p hash for pre 0.13.2 blocks
1 parent 5ab5002 commit 706f1ba

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

p2p/sync.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -366,25 +366,23 @@ func (s *syncService) adaptAndSanityCheckBlock(ctx context.Context, header *spec
366366
}
367367

368368
if blockVer.LessThan(core.Ver0_13_2) {
369+
p2pHash, err := s.blockchain.BlockP2PHashByNumber(coreBlock.Number)
370+
if err != nil {
371+
bodyCh <- blockBody{err: fmt.Errorf("failed to get p2p hash: %w", err)}
372+
return
373+
}
374+
369375
expectedHash, _, err := core.Post0132Hash(coreBlock, stateDiff)
370376
if err != nil {
371377
bodyCh <- blockBody{err: fmt.Errorf("failed to compute p2p hash: %w", err)}
372378
return
373379
}
374380

375-
if !coreBlock.Hash.Equal(expectedHash) {
381+
if !p2pHash.Equal(expectedHash) {
376382
err = fmt.Errorf("received p2p hash %v doesn't match expected %v", coreBlock.Hash, expectedHash)
377383
bodyCh <- blockBody{err: err}
378384
return
379385
}
380-
381-
// once we verified p2p hash with received one above
382-
// we need to overwrite it with old scheme hash
383-
coreBlock.Hash, err = core.BlockHash(coreBlock)
384-
if err != nil {
385-
bodyCh <- blockBody{err: fmt.Errorf("failed to generate block hash: %w", err)}
386-
return
387-
}
388386
}
389387

390388
stateUpdate := &core.StateUpdate{

0 commit comments

Comments
 (0)