Skip to content

Commit 9c12102

Browse files
committed
feat(validtor-bot): review fixes
1 parent b233445 commit 9c12102

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

Diff for: validator-cli/src/ArbToEth/watcherArbToGnosis.ts

+51-17
Original file line numberDiff line numberDiff line change
@@ -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) {
@@ -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
@@ -724,13 +745,11 @@ async function getClaimForEpoch(
724745
claim.challenger = constants.AddressZero;
725746
}
726747

727-
calculatedHash = await retryOperation(() => veaOutbox.hashClaim(claim), 1000, 10);
748+
calculatedHash = hashClaim(claim);
728749
if (calculatedHash == claimHash) return claim;
729750

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-
]);
751+
const claimBridgerHonest = hashClaim({ ...claim, honest: 1 });
752+
const claimChallengerHonest = hashClaim({ ...claim, honest: 2 });
734753

735754
if (claimBridgerHonest === claimHash) return { ...claim, honest: 1 };
736755
if (claimChallengerHonest === claimHash) return { ...claim, honest: 2 };
@@ -1093,6 +1112,21 @@ async function reconstructChallengeProgress(
10931112
return challengeProgress;
10941113
}
10951114

1115+
const hashClaim = (claim) => {
1116+
return ethers.utils.solidityKeccak256(
1117+
["bytes32", "address", "uint32", "uint32", "uint32", "uint8", "address"],
1118+
[
1119+
claim.stateRoot,
1120+
claim.claimer,
1121+
claim.timestampClaimed,
1122+
claim.timestampVerification,
1123+
claim.blocknumberVerification,
1124+
claim.honest,
1125+
claim.challenger,
1126+
]
1127+
);
1128+
};
1129+
10961130
(async () => {
10971131
retryOperation(() => watch(), 1000, 10);
10981132
})();

0 commit comments

Comments
 (0)