Skip to content

Commit

Permalink
Fix for possible race for new block post consensus job.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozen committed May 27, 2024
1 parent ae849c4 commit cfc5bb2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions consensus/post_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,31 @@ func (consensus *Consensus) postConsensusProcessing(newBlock *types.Block) error

if h := consensus.registry.GetNodeConfig().WebHooks.Hooks; h != nil {
if h.Availability != nil {
for _, addr := range node.GetAddresses(newBlock.Epoch()) {
wrapper, err := node.Beaconchain().ReadValidatorInformation(addr)
shardState, err := consensus.Blockchain().ReadShardState(newBlock.Epoch())
if err != nil {
utils.Logger().Error().Err(err).
Int64("epoch", newBlock.Epoch().Int64()).
Uint32("shard-id", consensus.ShardID).
Msg("failed to read shard state")
return err
}
for _, addr := range consensus.Registry().GetAddressToBLSKey().GetAddresses(consensus.getPublicKeys(), shardState, newBlock.Epoch()) {
wrapper, err := consensus.Beaconchain().ReadValidatorInformation(addr)
if err != nil {
utils.Logger().Err(err).Str("addr", addr.Hex()).Msg("failed reaching validator info")
return nil
}
snapshot, err := node.Beaconchain().ReadValidatorSnapshot(addr)
snapshot, err := consensus.Beaconchain().ReadValidatorSnapshot(addr)
if err != nil {
utils.Logger().Err(err).Str("addr", addr.Hex()).Msg("failed reaching validator snapshot")
return nil
}
computed := availability.ComputeCurrentSigning(
snapshot.Validator, wrapper,
)
lastBlockOfEpoch := shard.Schedule.EpochLastBlock(node.Beaconchain().CurrentBlock().Header().Epoch().Uint64())
lastBlockOfEpoch := shard.Schedule.EpochLastBlock(consensus.Beaconchain().CurrentBlock().Header().Epoch().Uint64())

computed.BlocksLeftInEpoch = lastBlockOfEpoch - node.Beaconchain().CurrentBlock().Header().Number().Uint64()
computed.BlocksLeftInEpoch = lastBlockOfEpoch - consensus.Beaconchain().CurrentBlock().Header().Number().Uint64()

if err != nil && computed.IsBelowThreshold {
url := h.Availability.OnDroppedBelowThreshold
Expand Down

0 comments on commit cfc5bb2

Please sign in to comment.