Skip to content

Commit

Permalink
Fix: check auth changes before processing block
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Nov 21, 2024
1 parent 22a34e6 commit e9a96e7
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions dot/sync/block_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,7 @@ func (b *blockImporter) importBlock(bd *types.BlockData, origin BlockOrigin) (im
// or the index of the block data that errored on failure.
func (b *blockImporter) processBlockData(blockData types.BlockData, origin BlockOrigin) error {
if blockData.Header != nil {
var (
hasJustification = blockData.Justification != nil && len(*blockData.Justification) > 0
round uint64
setID uint64
)

if hasJustification {
var err error
round, setID, err = b.finalityGadget.VerifyBlockJustification(
blockData.Header.Hash(), blockData.Header.Number, *blockData.Justification)
if err != nil {
return fmt.Errorf("verifying justification: %w", err)
}
}
header := blockData.Header

if blockData.Body != nil {
err := b.processBlockDataWithHeaderAndBody(blockData, origin)
Expand All @@ -126,18 +113,22 @@ func (b *blockImporter) processBlockData(blockData types.BlockData, origin Block
}
}

if hasJustification {
header := blockData.Header
err := b.blockState.SetFinalisedHash(header.Hash(), round, setID)
if blockData.Justification != nil && len(*blockData.Justification) > 0 {
round, setID, err := b.finalityGadget.VerifyBlockJustification(
header.Hash(), header.Number, *blockData.Justification)
if err != nil {
return fmt.Errorf("verifying justification for block %s: %w", header.Hash().String(), err)
}

err = b.blockState.SetFinalisedHash(header.Hash(), round, setID)
if err != nil {
return fmt.Errorf("setting finalised hash: %w", err)
}

err = b.blockState.SetJustification(header.Hash(), *blockData.Justification)
if err != nil {
return fmt.Errorf("setting justification for block number %d: %w", header.Number, err)
}

return nil
}
}
err := b.blockState.CompareAndSetBlockData(&blockData)
Expand Down

0 comments on commit e9a96e7

Please sign in to comment.