Skip to content

Commit

Permalink
Added code to call UpdateFinalizedEpoch after the first block is adde…
Browse files Browse the repository at this point in the history
…d in the new epoch
  • Loading branch information
cyyber committed Sep 14, 2022
1 parent 6ce7bca commit 3033017
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,25 @@ func (c *Chain) AddBlock(b *block.Block) bool {
c.lastBlock = lastBlock
}

if b.Hash() == c.lastBlock.Hash() && b.Epoch() != parentBlock.Epoch() {
err = b.UpdateFinalizedEpoch(c.state.DB(), stateContext)
if err != nil {
log.Error("Failed to update finalized epoch")
} else {
finalizedHeaderHash, err := c.GetFinalizedHeaderHash()
if err != nil {
log.Error("Error getting finalized header hash")
} else {
b, err := c.GetBlock(finalizedHeaderHash)
if err != nil {
log.Error("Error getting block for finalized header hash")
} else {
log.Info(fmt.Sprintf("Updated finalized epoch to Epoch %d Slot Number #%d %s ", b.Epoch(), b.SlotNumber(), b.Hash()))
}
}
}
}

log.Info(fmt.Sprintf("Added Block #%d %s", b.SlotNumber(), misc.BytesToHexStr(bHash[:])))
log.Info(fmt.Sprintf("Protocol Txs Count %d | Txs Count %d",
len(b.ProtocolTransactions()), len(b.Transactions())))
Expand Down

0 comments on commit 3033017

Please sign in to comment.