-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/bridger-cli #370
feat/bridger-cli #370
Changes from 1 commit
d29ae84
cabab3f
310184a
2bfba2d
f779e6b
84b65d6
2416bcb
9dd90cc
382681d
1f0ab5f
97d6777
64427bb
4690526
8e81840
2d8a218
590f6ff
7a6aee7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require("dotenv").config(); | ||
import { JsonRpcProvider } from "@ethersproject/providers"; | ||
import { ethers } from "ethers"; | ||
import { EventEmitter } from "events"; | ||
import { getLastClaimedEpoch } from "./utils/graphQueries"; | ||
|
@@ -20,12 +21,13 @@ export const watch = async ( | |
emitter.emit(BotEvents.STARTED); | ||
const chainId = Number(process.env.VEAOUTBOX_CHAIN_ID); | ||
const veaInboxAddress = process.env.VEAINBOX_ADDRESS; | ||
const veaInboxProviderURL = process.env.VEAINBOX_PROVIDER; | ||
const veaOutboxAddress = process.env.VEAOUTBOX_ADDRESS; | ||
const veaOutboxProviderURL = process.env.VEAOUTBOX_PROVIDER; | ||
const PRIVATE_KEY = process.env.PRIVATE_KEY; | ||
const veaInbox = getVeaInbox(veaInboxAddress, PRIVATE_KEY, veaInboxProviderURL, chainId); | ||
const veaOutbox = getVeaOutbox(veaOutboxAddress, PRIVATE_KEY, veaOutboxProviderURL, chainId); | ||
const veaInboxRPC = process.env.VEAINBOX_PROVIDER; | ||
const veaOutboxRPC = process.env.VEAOUTBOX_PROVIDER; | ||
const veaInbox = getVeaInbox(veaInboxAddress, PRIVATE_KEY, veaInboxRPC, chainId); | ||
const veaOutbox = getVeaOutbox(veaOutboxAddress, PRIVATE_KEY, veaOutboxRPC, chainId); | ||
const veaOutboxProvider = new JsonRpcProvider(veaOutboxRPC); | ||
const epochs = await setEpochRange(veaOutbox, startEpoch); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From this line I understand that if the bot shuts down it will start from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no mechanism to handle bot shutting down yet. The |
||
let verifiableEpoch = epochs[epochs.length - 1] - 1; | ||
|
||
|
@@ -38,27 +40,20 @@ export const watch = async ( | |
emitter.emit(BotEvents.CHECKING, activeEpoch); | ||
let claimableEpochHash = await veaOutbox.claimHashes(activeEpoch); | ||
let outboxStateRoot = await veaOutbox.stateRoot(); | ||
const finalizedOutboxBlock = await veaOutbox.provider.getBlock("finalized"); | ||
const finalizedOutboxBlock = await veaOutboxProvider.getBlock("finalized"); | ||
|
||
if (claimableEpochHash == ethers.constants.HashZero && activeEpoch == verifiableEpoch) { | ||
if (claimableEpochHash == ethers.ZeroAddress && activeEpoch == verifiableEpoch) { | ||
// Claim can be made | ||
const savedSnapshot = await veaInbox.snapshots(activeEpoch); | ||
if (savedSnapshot != outboxStateRoot && savedSnapshot != ethers.constants.HashZero) { | ||
if (savedSnapshot != outboxStateRoot && savedSnapshot != ethers.ZeroHash) { | ||
// Its possible that a claim was made for previous epoch but its not verified yet | ||
// Making claim if there are new messages or last claim was challenged. | ||
const claimData = await getLastClaimedEpoch(); | ||
|
||
if (claimData.challenged || claimData.stateroot != savedSnapshot) { | ||
// Making claim as either last claim was challenged or there are new messages | ||
if (!transactionHandlers[activeEpoch]) { | ||
transactionHandlers[activeEpoch] = new TransactionHandler( | ||
chainId, | ||
activeEpoch, | ||
veaOutbox, | ||
null, | ||
null, | ||
emitter | ||
); | ||
transactionHandlers[activeEpoch] = new TransactionHandler(chainId, activeEpoch, veaOutbox, null, emitter); | ||
} | ||
await transactionHandlers[activeEpoch].makeClaim(savedSnapshot); | ||
} else { | ||
|
@@ -68,25 +63,18 @@ export const watch = async ( | |
continue; | ||
} | ||
} else { | ||
if (savedSnapshot == ethers.constants.HashZero) { | ||
if (savedSnapshot == ethers.ZeroHash) { | ||
emitter.emit(BotEvents.NO_SNAPSHOT); | ||
} else { | ||
emitter.emit(BotEvents.NO_NEW_MESSAGES); | ||
} | ||
epochs.splice(i, 1); | ||
i--; | ||
} | ||
} else if (claimableEpochHash != ethers.constants.HashZero) { | ||
} else if (claimableEpochHash != ethers.ZeroHash) { | ||
const claim = await fetchClaim(veaOutbox, activeEpoch); | ||
if (!transactionHandlers[activeEpoch]) { | ||
transactionHandlers[activeEpoch] = new TransactionHandler( | ||
chainId, | ||
activeEpoch, | ||
veaOutbox, | ||
claim, | ||
null, | ||
emitter | ||
); | ||
transactionHandlers[activeEpoch] = new TransactionHandler(chainId, activeEpoch, veaOutbox, claim, emitter); | ||
} else { | ||
transactionHandlers[activeEpoch].claim = claim; | ||
} | ||
|
@@ -107,7 +95,7 @@ export const watch = async ( | |
epochs.splice(i, 1); | ||
i--; | ||
} | ||
} else if (claim.challenger == ethers.constants.AddressZero) { | ||
} else if (claim.challenger == ethers.ZeroAddress) { | ||
// No verification started yet, check if we can start it | ||
await transactionHandler.startVerification(finalizedOutboxBlock.timestamp); | ||
} else { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliantly resolved. I left a few comments but I am utterly happy with the job you did
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the help 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a type mismatch issue for tests which include
value : deposit
used for mocking, the bot itself works. I wasn't able to solve it for now will raise an issue and fix later.