Skip to content

Commit ff5d65d

Browse files
committed
Updated design doc
Signed-off-by: Nana Essilfie-Conduah <nana@swirldslabs.com>
1 parent 696bf03 commit ff5d65d

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

docs/design/backfill-plugin.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
## Purpose
1717

18-
This plugin purpose is to detect missing gaps in the intended stored block sequence, then autonomously and asynchronously fetch the missing blocks from another source and store them.
18+
This plugin purpose is to detect missing gaps (historica and recent) in the intended stored block sequence, then
19+
autonomously and asynchronously fetch the missing blocks from another source and store them.
1920

2021
## Goals
2122

@@ -34,9 +35,11 @@ This plugin purpose is to detect missing gaps in the intended stored block seque
3435
<dt>Grpc Client</dt>
3536
<dd>A client that connects to another Block Node to fetch missing blocks.</dd>
3637
<dt>BackfilledBlockNotification</dt>
37-
<dd>A new Notification Type that can be published to the Messaging Facility, it is intended to contain a whole block that was fetched from another source and is being backfilled into the system. </dd>
38+
<dd>A new Notification Type that can be published to the Messaging Facility, it is intended to contain a whole block
39+
that was fetched from another source and is being backfilled into the system. </dd>
3840
<dt>NewestBlockKnownToNetwork</dt>
39-
<dd>Notification sent by a plugin, including a "publisher" plugin, to indicate that the BlockNode is behind and must be brought up-to-date. This is often handled by a "backfill" plugin by immediately requesting the missing blocks.</dd>
41+
<dd>Notification sent by a plugin, including a "publisher" plugin, to indicate that the BlockNode is behind and must
42+
be brought up-to-date. This is often handled by a "backfill" plugin by immediately requesting the missing blocks.</dd>
4043
<dt>BlockSource</dt>
4144
<dd>A new Enum that will be added to existing notification types: `VerificationNotification` and `PersistedNotification` to indicate the original source where the block is coming from, currently it will only have two values: `Publisher`, `Backfill`</dd>
4245

@@ -65,16 +68,22 @@ There are two flows for backfilling, Autonomous and On-Demand.
6568

6669
### Autonomous Backfill
6770

68-
The plugin will autonomously detect gaps in the block range and fetch missing blocks from a configured source.
71+
The plugin will autonomously detect gaps in the block range and fetch missing blocks from a configured sources
72+
(via `backfill_sources` config).
6973

7074
1. At start-up a loop is defined that runs every `backfill.scanInterval`
71-
2. At every interval the plugin detects missing gaps in the intended block range against the actual stored blocks using the `HistoricalBlockFacility`.
75+
2. At every interval the plugin detects missing gaps in the intended block range against the actual stored blocks using
76+
the `HistoricalBlockFacility`. It will use a gRPC client to request the serverStatus from configured target block
77+
nodes and determine the available range of recent blocks available.
7278
3. If gaps are found, it initiates the backfill process.
73-
4. The plugin uses a gRPC client to connect to another Block Node (configured via `backfill_sources`) to fetch the missing blocks.
74-
5. Once the blocks are fetched, the plugin creates a `BlockNotification` of type `BackfilledBlockNotification` and sends it to the `MessagingFacility`.
75-
6. The `VerificationPlugin` will then process the `BackfilledBlockNotification` and if the block is valid, it will create a `VerificationNotification` and send it to the `MessagingFacility` for further processing.
79+
4. The plugin uses a gRPC client to connect to other Block Nodes to fetch the missing blocks.
80+
5. Once the blocks are fetched, the plugin creates a `BlockNotification` of type `BackfilledBlockNotification` and sends
81+
it to the `MessagingFacility`.
82+
6. The `VerificationPlugin` will then process the `BackfilledBlockNotification` and if the block is valid, it will
83+
create a `VerificationNotification` and send it to the `MessagingFacility` for further processing.
7684
7. The PersistencePlugin will then store the block in the local storage.
77-
8. The `BackfillPlugin` will receive the `PersistenceNotification` and update its internal state accordingly, marking the backfill process as complete for that block.
85+
8. The `BackfillPlugin` will receive the `PersistenceNotification` and update its internal state accordingly, marking
86+
the backfill process as complete for that block.
7887

7988
## Diagram
8089

@@ -89,7 +98,9 @@ sequenceDiagram
8998
participant PersistencePlugin
9099
91100
loop Every backfill.scanInterval
92-
BackfillPlugin->>HistoricalBlockFacility: detectMissingGaps(firstBlock, lastBlock)
101+
BackfillPlugin->>HistoricalBlockFacility: detectMissingHistoricalGaps(firstBlock, lastBlock)
102+
BackfillPlugin->>+GrpcClient: getServerStatusFromPeerBlockNodes()
103+
BackfillPlugin-->>BackfillPlugin: detectMissingRecentGaps(min(firstBlocks), max(lastBlocks))
93104
alt Gaps found
94105
BackfillPlugin->>+GrpcClient: fetchMissingBlocks(gapRange, batchSize)
95106
GrpcClient-->>-BackfillPlugin: blocks[]
@@ -123,12 +134,18 @@ sequenceDiagram
123134

124135
### On-Demand Backfill
125136

126-
The plugin can also be triggered on-demand to backfill missing blocks when the latest block known to the network is received.
137+
The plugin can also be triggered on-demand to backfill missing blocks when the latest block known to the network is
138+
received and periodically to ensure block node does not fall too far behind.
127139

128-
1. The plugin can also be triggered on-demand by sending a `NewestBlockKnownToNetwork` message to the `MessagingFacility`, usually this would be done by the `PublisherPlugin` or any other plugin that knows the latest block.
129-
2. BackfillPlugin will handle the `NewestBlockKnownToNetwork` message and will check if there are any gaps in the block range available in the local storage.
140+
1. The plugin can also be triggered on-demand by sending a `NewestBlockKnownToNetwork` message to the `MessagingFacility`,
141+
usually this would be done by the `PublisherPlugin` or any other plugin that knows the latest block or wants to
142+
ensure the Block Node is up-to-date.
143+
2. BackfillPlugin will handle the `NewestBlockKnownToNetwork` message and will check if there are any gaps in the block
144+
range available in the local storage. It will also use a gRPC client to request the serverStatus from configured
145+
peer block nodes and determine the available range of recent blocks available.
130146
3. If gaps are found, it will initiate the backfill process as described in the Autonomous Backfill section.
131-
4. The process will be the same as the Autonomous Backfill, but it will be triggered by the `NewestBlockKnownToNetwork` message instead of the periodic scan.
147+
4. The process will be the same as the Autonomous Backfill, but it will be triggered by the `NewestBlockKnownToNetwork`
148+
message instead of the periodic scan.
132149

133150
```mermaid
134151
sequenceDiagram
@@ -145,6 +162,8 @@ sequenceDiagram
145162
%% Dispatch to backfill
146163
MessagingFacility->>BackfillPlugin: NewestBlockKnownToNetwork(latestBlock)
147164
BackfillPlugin->>HistoricalBlockFacility: detectMissingGaps(…, latestBlock)
165+
BackfillPlugin->>+GrpcClient: getServerStatusFromPeerBlockNodes()
166+
BackfillPlugin-->>BackfillPlugin: detectMissingRecentGaps(min(firstBlocks), max(lastBlocks))
148167
149168
alt Gaps found
150169
BackfillPlugin->>GrpcClient: fetchMissingBlocks(gapRange, batchSize)

0 commit comments

Comments
 (0)