@@ -26,9 +26,6 @@ const SYNC_MIN_HEIGHT = getRequiredEnvNumber("SYNC_MIN_HEIGHT");
2626const SYNC_FETCH_INTERVAL_IN_BLOCKS = getRequiredEnvNumber (
2727 "SYNC_FETCH_INTERVAL_IN_BLOCKS" ,
2828) ;
29- const SYNC_TIME_BETWEEN_REQUESTS_IN_MS = getRequiredEnvNumber (
30- "SYNC_TIME_BETWEEN_REQUESTS_IN_MS" ,
31- ) ;
3229
3330const shutdownSignal = createSignal ( ) ;
3431
@@ -118,79 +115,6 @@ export async function processKeys(
118115 return totalKeysProcessed ;
119116}
120117
121- /**
122- * Initiates the process of synchronizing blockchain data from a specific point, either from the latest block cut or from the
123- * last recorded synchronization status for each chain.
124- *
125- * The synchronization process involves the following steps:
126- * 1. Fetching the latest cut from the Chainweb network to determine the current highest block heights across all chains.
127- * 2. Retrieving the last synchronization status for all chains to identify the starting point of the fill process.
128- * If no previous synchronization status is found for a chain, the process starts from the height provided by the latest cut.
129- * 3. Processing each chain individually in a round-robin fashion, fetching headers and their corresponding payloads from
130- * the last height down to a specified minimum height. This ensures that the load is evenly distributed across all chains and
131- * that the system remains responsive during the synchronization process.
132- * 4. For each chain, headers and payloads are fetched in descending order (from higher blocks to lower blocks), allowing for
133- * efficient catch-up to the current state of the blockchain.
134- * 5. The process continues iteratively, moving through each chain in turn, until all chains have reached the minimum required block height.
135- *
136- * @param {string } network - The identifier of the Chainweb network from which to synchronize data (e.g., 'mainnet01').
137- */
138- export async function startBackFill (
139- network : string ,
140- chainId = 0 ,
141- ) : Promise < void > {
142- try {
143- console . log ( "Starting filling..." ) ;
144- const chains = await getLastSync ( network ) ;
145- const chain = chains . find ( ( c ) => c . chainId === chainId ) ;
146- if ( ! chain ) {
147- throw new Error ( "Chain not found in the list of chains." ) ;
148- }
149- console . info (
150- "Starting backfill process for chain: " ,
151- chain ,
152- SYNC_MIN_HEIGHT ,
153- ) ;
154- while ( chain . currentHeight > SYNC_MIN_HEIGHT ) {
155- console . info ( `Processing chain:` , {
156- chainId : chain . chainId ,
157- currentHeight : chain . currentHeight ,
158- } ) ;
159-
160- let nextHeight = Math . max (
161- chain . currentHeight - SYNC_FETCH_INTERVAL_IN_BLOCKS ,
162- SYNC_MIN_HEIGHT + 1 ,
163- ) ;
164-
165- const start = new Date ( ) . getTime ( ) ;
166-
167- const counters = await fetchHeadersWithRetry (
168- network ,
169- chain . chainId ,
170- nextHeight ,
171- chain . currentHeight ,
172- ) ;
173-
174- chain . currentHeight = nextHeight - 1 ;
175-
176- const end = new Date ( ) . getTime ( ) ;
177- const time = end - start ;
178- console . log (
179- {
180- chainId : chain . chainId ,
181- currentHeight : chain . currentHeight ,
182- } ,
183- `processed in ${ time / 1000 } s.` ,
184- ) ;
185- console . log ( "Counters: " , counters ) ;
186- }
187-
188- console . log ( "All chains have been processed to the minimum height." ) ;
189- } catch ( error ) {
190- console . error ( "Error during backfilling: " , error ) ;
191- }
192- }
193-
194118/**
195119 * Retrieves the last synchronization status for each chain in a given network.
196120 * It fetches the latest cut (highest block heights) from the network and combines
0 commit comments