Skip to content

Commit

Permalink
Check p2p hash for pre 0.13.2 blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Nov 19, 2024
1 parent 5ab5002 commit 706f1ba
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 706f1ba

Please sign in to comment.