-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(fd): start at beginning of challenge period #2629
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@eth-optimism/fault-detector': patch | ||
| --- | ||
|
|
||
| Smarter starting height for fault-detector |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { HardhatUserConfig } from 'hardhat/types' | ||
|
|
||
| // Hardhat plugins | ||
| import '@nomiclabs/hardhat-ethers' | ||
| import '@nomiclabs/hardhat-waffle' | ||
|
|
||
| const config: HardhatUserConfig = { | ||
| mocha: { | ||
| timeout: 50000, | ||
| }, | ||
| } | ||
|
|
||
| export default config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { Contract, ethers } from 'ethers' | ||
|
|
||
| /** | ||
| * Finds the Event that corresponds to a given state batch by index. | ||
| * | ||
| * @param scc StateCommitmentChain contract. | ||
| * @param index State batch index to search for. | ||
| * @returns Event corresponding to the batch. | ||
| */ | ||
| export const findEventForStateBatch = async ( | ||
| scc: Contract, | ||
| index: number | ||
| ): Promise<ethers.Event> => { | ||
| const events = await scc.queryFilter(scc.filters.StateBatchAppended(index)) | ||
|
|
||
| // Only happens if the batch with the given index does not exist yet. | ||
| if (events.length === 0) { | ||
| throw new Error(`unable to find event for batch`) | ||
| } | ||
|
|
||
| // Should never happen. | ||
| if (events.length > 1) { | ||
| throw new Error(`found too many events for batch`) | ||
| } | ||
|
|
||
| return events[0] | ||
| } | ||
|
|
||
| /** | ||
| * Finds the first state batch index that has not yet passed the fault proof window. | ||
| * | ||
| * @param scc StateCommitmentChain contract. | ||
| * @returns Starting state root batch index. | ||
| */ | ||
| export const findFirstUnfinalizedStateBatchIndex = async ( | ||
| scc: Contract | ||
| ): Promise<number> => { | ||
| const fpw = (await scc.FRAUD_PROOF_WINDOW()).toNumber() | ||
| const latestBlock = await scc.provider.getBlock('latest') | ||
| const totalBatches = (await scc.getTotalBatches()).toNumber() | ||
|
|
||
| // Perform a binary search to find the next batch that will pass the challenge period. | ||
| let lo = 0 | ||
| let hi = totalBatches | ||
| while (lo !== hi) { | ||
| const mid = Math.floor((lo + hi) / 2) | ||
| const event = await findEventForStateBatch(scc, mid) | ||
| const block = await event.getBlock() | ||
|
|
||
| if (block.timestamp + fpw < latestBlock.timestamp) { | ||
| lo = mid + 1 | ||
| } else { | ||
| hi = mid | ||
| } | ||
| } | ||
|
|
||
| // Result will be zero if the chain is less than FPW seconds old. Only returns undefined in the | ||
| // case that no batches have been submitted for an entire challenge period. | ||
| if (lo === totalBatches) { | ||
| return undefined | ||
| } else { | ||
| return lo | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './service' | ||
| export * from './helpers' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.