@@ -11,7 +11,7 @@ import { ChildToParentMessageStatus, ChildTransactionReceipt, getArbitrumNetwork
1111import { NODE_INTERFACE_ADDRESS } from "@arbitrum/sdk/dist/lib/dataEntities/constants" ;
1212import { NodeInterface__factory } from "@arbitrum/sdk/dist/lib/abi/factories/NodeInterface__factory" ;
1313import { SequencerInbox__factory } from "@arbitrum/sdk/dist/lib/abi/factories/SequencerInbox__factory" ;
14- import { BigNumber , ContractTransaction , Wallet , constants } from "ethers" ;
14+ import { BigNumber , ContractTransaction , Wallet , constants , ethers } from "ethers" ;
1515import { Block , Log } from "@ethersproject/abstract-provider" ;
1616import { SequencerInbox } from "@arbitrum/sdk/dist/lib/abi/SequencerInbox" ;
1717import { NodeInterface } from "@arbitrum/sdk/dist/lib/abi/NodeInterface" ;
@@ -212,12 +212,15 @@ const watch = async () => {
212212
213213 const veaEpochOutboxClaimableNowOld = veaEpochOutboxClaimableNow ;
214214 veaEpochOutboxClaimableNow = Math . floor ( timeGnosis / epochPeriod ) - 1 ;
215- // TODO: sometimes veaEpochOutboxClaimableNow is 1 epoch behind veaEpochOutboxClaimableNowOld
216- const veaEpochsOutboxClaimableNew : number [ ] = new Array ( veaEpochOutboxClaimableNow - veaEpochOutboxClaimableNowOld )
217- . fill ( veaEpochOutboxClaimableNowOld + 1 )
218- . map ( ( el , i ) => el + i ) ;
219215
220- veaEpochOutboxCheckClaimsRangeArray . concat ( veaEpochsOutboxClaimableNew ) ;
216+ if ( veaEpochOutboxClaimableNow > veaEpochOutboxClaimableNowOld ) {
217+ const veaEpochsOutboxClaimableNew : number [ ] = new Array (
218+ veaEpochOutboxClaimableNow - veaEpochOutboxClaimableNowOld
219+ )
220+ . fill ( veaEpochOutboxClaimableNowOld + 1 )
221+ . map ( ( el , i ) => el + i ) ;
222+ veaEpochOutboxCheckClaimsRangeArray . push ( ...veaEpochsOutboxClaimableNew ) ;
223+ }
221224
222225 if ( veaEpochOutboxCheckClaimsRangeArray . length == 0 ) {
223226 console . log ( "no claims to check" ) ;
@@ -248,7 +251,7 @@ const watch = async () => {
248251 ) ;
249252 veaEpochOutboxCheckClaimsRangeArray . splice ( index , 1 ) ;
250253 index -- ;
251- if ( challenges . has ( index ) ) challenges . delete ( index ) ;
254+ if ( challenges . has ( veaEpochOutboxCheck ) ) challenges . delete ( veaEpochOutboxCheck ) ;
252255 continue ;
253256 } else {
254257 console . log (
@@ -320,7 +323,7 @@ const watch = async () => {
320323 continue ;
321324 }
322325 console . log ( veaEpochOutboxCheck , "claim found " , { claim } ) ;
323- const previousProgress = challenges . get ( index ) || ( { } as any ) ;
326+ const previousProgress = challenges . get ( veaEpochOutboxCheck ) || ( { } as any ) ;
324327 let challengeProgress = await reconstructChallengeProgress (
325328 veaEpochOutboxCheck ,
326329 veaOutbox ,
@@ -333,7 +336,7 @@ const watch = async () => {
333336 amb ,
334337 previousProgress
335338 ) ;
336- challenges . set ( index , challengeProgress ) ;
339+ challenges . set ( veaEpochOutboxCheck , challengeProgress ) ;
337340 console . log (
338341 "challenge progess for epoch " + veaEpochOutboxCheck + " is " + JSON . stringify ( challengeProgress )
339342 ) ;
@@ -347,6 +350,14 @@ const watch = async () => {
347350 10
348351 ) ) as ContractTransaction ;
349352 console . log ( "Epoch " + veaEpochOutboxCheck + " challenged with txn " + txnChallenge . hash ) ;
353+ challengeProgress . challenge = {
354+ status : "pending" ,
355+ txHash : txnChallenge . hash ,
356+ timestamp : 0 ,
357+ finalized : false ,
358+ } ;
359+ challengeProgress . status = "ChallengePending" ;
360+ challenges . set ( veaEpochOutboxCheck , challengeProgress ) ;
350361 continue ;
351362 }
352363 if ( claim ?. challenger === watcherAddress ) {
@@ -359,6 +370,14 @@ const watch = async () => {
359370 10
360371 ) ) as ContractTransaction ;
361372 console . log ( "Epoch " + veaEpochOutboxCheck + " sendSnapshot called with txn " + txnSendSnapshot . hash ) ;
373+ challengeProgress . snapshot = {
374+ status : "pending" ,
375+ txHash : txnSendSnapshot . hash ,
376+ timestamp : 0 ,
377+ finalized : false ,
378+ } ;
379+ challengeProgress . status = "SnapshotPending" ;
380+ challenges . set ( veaEpochOutboxCheck , challengeProgress ) ;
362381 }
363382 }
364383 if (
@@ -389,7 +408,7 @@ const watch = async () => {
389408 finalized : false ,
390409 } ;
391410 challengeProgress . status = "WithdrawalPending" ;
392- challenges . set ( index , challengeProgress ) ;
411+ challenges . set ( veaEpochOutboxCheck , challengeProgress ) ;
393412 }
394413 }
395414 }
@@ -567,7 +586,9 @@ const ArbBlockToL1Block = async (
567586 let latestL2BlockNumberOnEth : number ;
568587 let result = ( await nodeInterface . functions
569588 . findBatchContainingBlock ( L2Block . number , { blockTag : "latest" } )
570- . catch ( ( e ) => { } ) ) as [ BigNumber ] & { batch : BigNumber } ;
589+ . catch ( ( e ) => {
590+ console . error ( "Error finding batch containing block:" , JSON . parse ( JSON . stringify ( e ) ) . error . body ) ;
591+ } ) ) as [ BigNumber ] & { batch : BigNumber } ;
571592
572593 if ( ! result ) {
573594 if ( ! fallbackLatest ) {
@@ -605,7 +626,7 @@ const findLatestL2BatchAndBlock = async (
605626 nodeInterface : NodeInterface ,
606627 fromArbBlock : number ,
607628 latestBlockNumber : number
608- ) : Promise < [ number , number ] > => {
629+ ) : Promise < [ number | undefined , number | undefined ] > => {
609630 let low = fromArbBlock ;
610631 let high = latestBlockNumber ;
611632
@@ -676,7 +697,7 @@ async function getClaimForEpoch(
676697 challenger : constants . AddressZero ,
677698 } ;
678699 let other = { } as any ;
679- let calculatedHash = await retryOperation ( ( ) => veaOutbox . hashClaim ( claim ) , 1000 , 10 ) ;
700+ let calculatedHash = hashClaim ( claim ) ;
680701 if ( calculatedHash == claimHash ) return claim ;
681702
682703 // Check for Challenged event
@@ -698,7 +719,7 @@ async function getClaimForEpoch(
698719 other . challengeBlock = challengedEvents [ 0 ] . blockNumber ;
699720 }
700721
701- calculatedHash = await retryOperation ( ( ) => veaOutbox . hashClaim ( claim ) , 1000 , 10 ) ;
722+ calculatedHash = hashClaim ( claim ) ;
702723 if ( calculatedHash == claimHash ) return claim ;
703724
704725 // Check for VerificationStarted event
@@ -721,16 +742,13 @@ async function getClaimForEpoch(
721742 ) ;
722743 claim . timestampVerification = verificationBlock . timestamp ;
723744 claim . blocknumberVerification = verificationBlock . number ;
724- claim . challenger = constants . AddressZero ;
725745 }
726746
727- calculatedHash = await retryOperation ( ( ) => veaOutbox . hashClaim ( claim ) , 1000 , 10 ) ;
747+ calculatedHash = hashClaim ( claim ) ;
728748 if ( calculatedHash == claimHash ) return claim ;
729749
730- const [ claimBridgerHonest , claimChallengerHonest ] = await Promise . all ( [
731- retryOperation ( ( ) => veaOutbox . hashClaim ( { ...claim , honest : 1 } ) , 1000 , 10 ) as any ,
732- retryOperation ( ( ) => veaOutbox . hashClaim ( { ...claim , honest : 2 } ) , 1000 , 10 ) as any ,
733- ] ) ;
750+ const claimBridgerHonest = hashClaim ( { ...claim , honest : 1 } ) ;
751+ const claimChallengerHonest = hashClaim ( { ...claim , honest : 2 } ) ;
734752
735753 if ( claimBridgerHonest === claimHash ) return { ...claim , honest : 1 } ;
736754 if ( claimChallengerHonest === claimHash ) return { ...claim , honest : 2 } ;
@@ -1093,6 +1111,21 @@ async function reconstructChallengeProgress(
10931111 return challengeProgress ;
10941112}
10951113
1114+ const hashClaim = ( claim ) => {
1115+ return ethers . utils . solidityKeccak256 (
1116+ [ "bytes32" , "address" , "uint32" , "uint32" , "uint32" , "uint8" , "address" ] ,
1117+ [
1118+ claim . stateRoot ,
1119+ claim . claimer ,
1120+ claim . timestampClaimed ,
1121+ claim . timestampVerification ,
1122+ claim . blocknumberVerification ,
1123+ claim . honest ,
1124+ claim . challenger ,
1125+ ]
1126+ ) ;
1127+ } ;
1128+
10961129( async ( ) => {
10971130 retryOperation ( ( ) => watch ( ) , 1000 , 10 ) ;
10981131} ) ( ) ;
0 commit comments