Skip to content

Commit

Permalink
Remove p2p hash calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Nov 18, 2024
1 parent f0a860f commit ff4fbc8
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *syncService) processSpecBlockParts(
return orderedBlockBodiesCh
}

//nolint:gocyclo,funlen
//nolint:gocyclo
func (s *syncService) adaptAndSanityCheckBlock(ctx context.Context, header *spec.SignedBlockHeader, contractDiffs []*spec.ContractDiff,
classes []*spec.Class, txs []*spec.Transaction, receipts []*spec.Receipt, events []*spec.Event, prevBlockRoot *felt.Felt,
) <-chan blockBody {
Expand Down Expand Up @@ -359,40 +359,6 @@ func (s *syncService) adaptAndSanityCheckBlock(ctx context.Context, header *spec

stateDiff := p2p2core.AdaptStateDiff(stateReader, contractDiffs, classes)

blockVer, err := core.ParseBlockVersion(coreBlock.ProtocolVersion)
if err != nil {
bodyCh <- blockBody{err: fmt.Errorf("failed to parse block version: %w", err)}
return
}

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 !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{
BlockHash: coreBlock.Hash,
NewRoot: coreBlock.GlobalStateRoot,
Expand Down

0 comments on commit ff4fbc8

Please sign in to comment.