As of today, subsystems in lnd subscribe to new blocks via RegisterBlockEpochNtfn and process them independently. Since the speed of processing varies in subsystems, they may end up having a different view of the current best block, causing undefined behaviors. This happens more in itest than in reality, as block production is generally slow. To make sure every subsystem shares the same view, we could introduce a new service, blockbeat, that handles producing new blocks, and other subsystems will consume the block and signal the consumption, in specific,
blockbeat will be the only service that calls RegisterBlockEpochNtfn. Upon receiving a new block, the service will send it to all its subscribers.
- the subscribers will then consume the block, and signal back when the consumption is done.
blockbeat will refuse to move ahead without receiving the done signals from all its subscribers, hence making sure all subsystems are sharing the same best block.
blockbeat can further handle reorg events, thus making all other subsystems handle it.
blockbeat will behave as the heartbeat of lnd, monitoring the subsystems to properly handle the blocks in a time-sensitive manner.
As of today, subsystems in
lndsubscribe to new blocks viaRegisterBlockEpochNtfnand process them independently. Since the speed of processing varies in subsystems, they may end up having a different view of the current best block, causing undefined behaviors. This happens more in itest than in reality, as block production is generally slow. To make sure every subsystem shares the same view, we could introduce a new service,blockbeat, that handles producing new blocks, and other subsystems will consume the block and signal the consumption, in specific,blockbeatwill be the only service that callsRegisterBlockEpochNtfn. Upon receiving a new block, the service will send it to all its subscribers.blockbeatwill refuse to move ahead without receiving the done signals from all its subscribers, hence making sure all subsystems are sharing the same best block.blockbeatcan further handle reorg events, thus making all other subsystems handle it.blockbeatwill behave as the heartbeat oflnd, monitoring the subsystems to properly handle the blocks in a time-sensitive manner.