Skip to content

Commit

Permalink
feat(validtor-bot): review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
madhurMongia committed Nov 26, 2024
1 parent b233445 commit 9c12102
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions validator-cli/src/ArbToEth/watcherArbToGnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,15 @@ const watch = async () => {

const veaEpochOutboxClaimableNowOld = veaEpochOutboxClaimableNow;
veaEpochOutboxClaimableNow = Math.floor(timeGnosis / epochPeriod) - 1;
// TODO: sometimes veaEpochOutboxClaimableNow is 1 epoch behind veaEpochOutboxClaimableNowOld
const veaEpochsOutboxClaimableNew: number[] = new Array(veaEpochOutboxClaimableNow - veaEpochOutboxClaimableNowOld)
.fill(veaEpochOutboxClaimableNowOld + 1)
.map((el, i) => el + i);

veaEpochOutboxCheckClaimsRangeArray.concat(veaEpochsOutboxClaimableNew);
if (veaEpochOutboxClaimableNow > veaEpochOutboxClaimableNowOld) {
const veaEpochsOutboxClaimableNew: number[] = new Array(
veaEpochOutboxClaimableNow - veaEpochOutboxClaimableNowOld
)
.fill(veaEpochOutboxClaimableNowOld + 1)
.map((el, i) => el + i);
veaEpochOutboxCheckClaimsRangeArray.push(...veaEpochsOutboxClaimableNew);
}

if (veaEpochOutboxCheckClaimsRangeArray.length == 0) {
console.log("no claims to check");
Expand Down Expand Up @@ -248,7 +251,7 @@ const watch = async () => {
);
veaEpochOutboxCheckClaimsRangeArray.splice(index, 1);
index--;
if (challenges.has(index)) challenges.delete(index);
if (challenges.has(veaEpochOutboxCheck)) challenges.delete(veaEpochOutboxCheck);
continue;
} else {
console.log(
Expand Down Expand Up @@ -320,7 +323,7 @@ const watch = async () => {
continue;
}
console.log(veaEpochOutboxCheck, "claim found ", { claim });
const previousProgress = challenges.get(index) || ({} as any);
const previousProgress = challenges.get(veaEpochOutboxCheck) || ({} as any);
let challengeProgress = await reconstructChallengeProgress(
veaEpochOutboxCheck,
veaOutbox,
Expand All @@ -333,7 +336,7 @@ const watch = async () => {
amb,
previousProgress
);
challenges.set(index, challengeProgress);
challenges.set(veaEpochOutboxCheck, challengeProgress);
console.log(
"challenge progess for epoch " + veaEpochOutboxCheck + " is " + JSON.stringify(challengeProgress)
);
Expand All @@ -347,6 +350,14 @@ const watch = async () => {
10
)) as ContractTransaction;
console.log("Epoch " + veaEpochOutboxCheck + " challenged with txn " + txnChallenge.hash);
challengeProgress.challenge = {
status: "pending",
txHash: txnChallenge.hash,
timestamp: 0,
finalized: false,
};
challengeProgress.status = "ChallengePending";
challenges.set(veaEpochOutboxCheck, challengeProgress);
continue;
}
if (claim?.challenger === watcherAddress) {
Expand All @@ -359,6 +370,14 @@ const watch = async () => {
10
)) as ContractTransaction;
console.log("Epoch " + veaEpochOutboxCheck + " sendSnapshot called with txn " + txnSendSnapshot.hash);
challengeProgress.snapshot = {
status: "pending",
txHash: txnSendSnapshot.hash,
timestamp: 0,
finalized: false,
};
challengeProgress.status = "SnapshotPending";
challenges.set(veaEpochOutboxCheck, challengeProgress);
}
}
if (
Expand Down Expand Up @@ -389,7 +408,7 @@ const watch = async () => {
finalized: false,
};
challengeProgress.status = "WithdrawalPending";
challenges.set(index, challengeProgress);
challenges.set(veaEpochOutboxCheck, challengeProgress);
}
}
}
Expand Down Expand Up @@ -567,7 +586,9 @@ const ArbBlockToL1Block = async (
let latestL2BlockNumberOnEth: number;
let result = (await nodeInterface.functions
.findBatchContainingBlock(L2Block.number, { blockTag: "latest" })
.catch((e) => {})) as [BigNumber] & { batch: BigNumber };
.catch((e) => {
console.error("Error finding batch containing block:", JSON.parse(JSON.stringify(e)).error.body);
})) as [BigNumber] & { batch: BigNumber };

if (!result) {
if (!fallbackLatest) {
Expand Down Expand Up @@ -676,7 +697,7 @@ async function getClaimForEpoch(
challenger: constants.AddressZero,
};
let other = {} as any;
let calculatedHash = await retryOperation(() => veaOutbox.hashClaim(claim), 1000, 10);
let calculatedHash = hashClaim(claim);
if (calculatedHash == claimHash) return claim;

// Check for Challenged event
Expand All @@ -698,7 +719,7 @@ async function getClaimForEpoch(
other.challengeBlock = challengedEvents[0].blockNumber;
}

calculatedHash = await retryOperation(() => veaOutbox.hashClaim(claim), 1000, 10);
calculatedHash = hashClaim(claim);
if (calculatedHash == claimHash) return claim;

// Check for VerificationStarted event
Expand All @@ -724,13 +745,11 @@ async function getClaimForEpoch(
claim.challenger = constants.AddressZero;
}

calculatedHash = await retryOperation(() => veaOutbox.hashClaim(claim), 1000, 10);
calculatedHash = hashClaim(claim);
if (calculatedHash == claimHash) return claim;

const [claimBridgerHonest, claimChallengerHonest] = await Promise.all([
retryOperation(() => veaOutbox.hashClaim({ ...claim, honest: 1 }), 1000, 10) as any,
retryOperation(() => veaOutbox.hashClaim({ ...claim, honest: 2 }), 1000, 10) as any,
]);
const claimBridgerHonest = hashClaim({ ...claim, honest: 1 });
const claimChallengerHonest = hashClaim({ ...claim, honest: 2 });

if (claimBridgerHonest === claimHash) return { ...claim, honest: 1 };
if (claimChallengerHonest === claimHash) return { ...claim, honest: 2 };
Expand Down Expand Up @@ -1093,6 +1112,21 @@ async function reconstructChallengeProgress(
return challengeProgress;
}

const hashClaim = (claim) => {
return ethers.utils.solidityKeccak256(
["bytes32", "address", "uint32", "uint32", "uint32", "uint8", "address"],
[
claim.stateRoot,
claim.claimer,
claim.timestampClaimed,
claim.timestampVerification,
claim.blocknumberVerification,
claim.honest,
claim.challenger,
]
);
};

(async () => {
retryOperation(() => watch(), 1000, 10);
})();
Expand Down

0 comments on commit 9c12102

Please sign in to comment.