@@ -43,14 +43,10 @@ type validBlockResult = result<blockDataWithTimestamp, validBlockError>
4343module LastBlockScannedHashes : {
4444 type t
4545 /**Instantiat t with existing data*/
46- let makeWithData : (
47- array <blockData >,
48- ~confirmedBlockThreshold : int ,
49- ~detectedReorgBlock : blockData = ?,
50- ) => t
46+ let makeWithData : (array <blockData >, ~maxReorgDepth : int , ~detectedReorgBlock : blockData = ?) => t
5147
5248 /**Instantiat empty t with no block data*/
53- let empty : (~confirmedBlockThreshold : int ) => t
49+ let empty : (~maxReorgDepth : int ) => t
5450
5551 /** Registers a new reorg guard, prunes unneeded data, and returns the updated state.
5652 * Resets internal state if shouldRollbackOnReorg is false (detect-only mode)
@@ -82,7 +78,7 @@ module LastBlockScannedHashes: {
8278 // as a threshold for reorgs. If for eg. this is 200,
8379 // it means we are accounting for reorgs up to 200 blocks
8480 // behind the head
85- confirmedBlockThreshold : int ,
81+ maxReorgDepth : int ,
8682 // A hash map of recent blockdata by block number to make comparison checks
8783 // for reorgs.
8884 dataByBlockNumber : dict <blockData >,
@@ -93,33 +89,33 @@ module LastBlockScannedHashes: {
9389 detectedReorgBlock : option <blockData >,
9490 }
9591
96- let makeWithData = (blocks , ~confirmedBlockThreshold , ~detectedReorgBlock = ?) => {
92+ let makeWithData = (blocks , ~maxReorgDepth , ~detectedReorgBlock = ?) => {
9793 let dataByBlockNumber = Js .Dict .empty ()
9894
9995 blocks -> Belt .Array .forEach (block => {
10096 dataByBlockNumber -> Js .Dict .set (block .blockNumber -> Js .Int .toString , block )
10197 })
10298
10399 {
104- confirmedBlockThreshold ,
100+ maxReorgDepth ,
105101 dataByBlockNumber ,
106102 detectedReorgBlock ,
107103 }
108104 }
109105 //Instantiates empty LastBlockHashes
110- let empty = (~confirmedBlockThreshold ) => {
111- confirmedBlockThreshold ,
106+ let empty = (~maxReorgDepth ) => {
107+ maxReorgDepth ,
112108 dataByBlockNumber : Js .Dict .empty (),
113109 detectedReorgBlock : None ,
114110 }
115111
116112 let getDataByBlockNumberCopyInThreshold = (
117- {dataByBlockNumber , confirmedBlockThreshold }: t ,
113+ {dataByBlockNumber , maxReorgDepth }: t ,
118114 ~currentBlockHeight ,
119115 ) => {
120116 // Js engine automatically orders numeric object keys
121117 let ascBlockNumberKeys = dataByBlockNumber -> Js .Dict .keys
122- let thresholdBlockNumber = currentBlockHeight - confirmedBlockThreshold
118+ let thresholdBlockNumber = currentBlockHeight - maxReorgDepth
123119
124120 let copy = Js .Dict .empty ()
125121
@@ -136,7 +132,7 @@ module LastBlockScannedHashes: {
136132 }
137133
138134 let registerReorgGuard = (
139- {confirmedBlockThreshold } as self : t ,
135+ {maxReorgDepth } as self : t ,
140136 ~reorgGuard : reorgGuard ,
141137 ~currentBlockHeight ,
142138 ~shouldRollbackOnReorg ,
@@ -180,7 +176,7 @@ module LastBlockScannedHashes: {
180176 ... self ,
181177 detectedReorgBlock : Some (reorgDetected .scannedBlock ),
182178 }
183- : empty (~confirmedBlockThreshold ),
179+ : empty (~maxReorgDepth ),
184180 ReorgDetected (reorgDetected ),
185181 )
186182 | None => {
@@ -199,7 +195,7 @@ module LastBlockScannedHashes: {
199195
200196 (
201197 {
202- confirmedBlockThreshold ,
198+ maxReorgDepth ,
203199 dataByBlockNumber : dataByBlockNumberCopyInThreshold ,
204200 detectedReorgBlock : None ,
205201 },
@@ -289,10 +285,7 @@ module LastBlockScannedHashes: {
289285 Return a BlockNumbersAndHashes.t rolled back to where blockData is less
290286 than the provided blockNumber
291287 */
292- let rollbackToValidBlockNumber = (
293- {dataByBlockNumber , confirmedBlockThreshold }: t ,
294- ~blockNumber : int ,
295- ) => {
288+ let rollbackToValidBlockNumber = ({dataByBlockNumber , maxReorgDepth }: t , ~blockNumber : int ) => {
296289 // Js engine automatically orders numeric object keys
297290 let ascBlockNumberKeys = dataByBlockNumber -> Js .Dict .keys
298291
@@ -316,7 +309,7 @@ module LastBlockScannedHashes: {
316309 loop (0 )
317310
318311 {
319- confirmedBlockThreshold ,
312+ maxReorgDepth ,
320313 dataByBlockNumber : newDataByBlockNumber ,
321314 detectedReorgBlock : None ,
322315 }
0 commit comments