Skip to content

[feature]: implement producer-consumer pattern for block subscription #7952

@yyforyongyu

Description

@yyforyongyu

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.

Metadata

Metadata

Assignees

Labels

P4low prioadvancedIssues suitable for very experienced developersenhancementImprovements to existing features / behavioursecurityGeneral label for issues/PRs related to the security of the software

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions