1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-17 04:30:03 +02:00

Merge branch 'rollback'

This commit is contained in:
Henrik Hautakoski 2024-01-09 15:49:48 +01:00
commit d32b463e12
3 changed files with 19 additions and 0 deletions

View file

@ -45,6 +45,7 @@ func (c Channel) Is(other Channel) bool {
var (
TransactionChannel = Channel{"transactions"}
HeartbeatChannel = Channel{"heartbeat"}
RollbackChannel = Channel{"rollback"}
)
// Action Channel

View file

@ -80,3 +80,8 @@ func (act ActionTrace) GetData() (map[string]any, error) {
}
return nil, errors.New("failed to convert data to map")
}
type RollbackMessage struct {
OldBlockNum uint32 `json:"old_block" msgpack:"old_block"`
NewBlockNum uint32 `json:"new_block" msgpack:"new_block"`
}

View file

@ -135,6 +135,19 @@ func (processor *ShipProcessor) GetCurrentBlock() uint32 {
// Callback function called by shipclient.Stream when a new block arrives.
func (processor *ShipProcessor) processBlock(block *ship.GetBlocksResultV0) {
// Check to see if we have a microfork and post a message to
// the rollback channel in that case.
if processor.state.CurrentBlock > 0 && block.ThisBlock.BlockNum < processor.state.CurrentBlock {
log.WithField("old_block", processor.state.CurrentBlock).
WithField("new_block", block.ThisBlock.BlockNum).
Warn("Fork detected, old_block is greater than new_block")
processor.encodeQueue(api.RollbackChannel, message.RollbackMessage{
OldBlockNum: processor.state.CurrentBlock,
NewBlockNum: block.ThisBlock.BlockNum,
})
}
processor.state.CurrentBlock = block.ThisBlock.BlockNum
if block.ThisBlock.BlockNum%100 == 0 {