-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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[integration-tests]: add verifier sync test #913
Changes from all commits
f97a2e6
6ec2172
47413c4
c91b64c
d47414c
9aaa850
30c5e8b
7535aa2
2f6f7a1
d466412
a9869f6
36349e5
a86814b
ebe7e3a
a1db034
4d0b61f
473f525
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@eth-optimism/integration-tests': patch | ||
--- | ||
|
||
Add verifier sync test and extra docker-compose functions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import chai, { expect } from 'chai' | ||
import { Wallet, BigNumber, providers } from 'ethers' | ||
import { injectL2Context } from '@eth-optimism/core-utils' | ||
|
||
import { sleep, l2Provider, verifierProvider } from '../test/shared/utils' | ||
import { OptimismEnv } from '../test/shared/env' | ||
import { DockerComposeNetwork } from '../test/shared/docker-compose' | ||
|
||
describe('Syncing a verifier', () => { | ||
let env: OptimismEnv | ||
let wallet: Wallet | ||
let verifier: DockerComposeNetwork | ||
let provider: providers.JsonRpcProvider | ||
|
||
const sequencerProvider = injectL2Context(l2Provider) | ||
|
||
/* Helper functions */ | ||
|
||
const waitForBatchSubmission = async ( | ||
totalElementsBefore: BigNumber | ||
): Promise<BigNumber> => { | ||
// Wait for batch submission to happen by watching the CTC | ||
let totalElementsAfter = (await env.ctc.getTotalElements()) as BigNumber | ||
while (totalElementsBefore.eq(totalElementsAfter)) { | ||
await sleep(500) | ||
totalElementsAfter = (await env.ctc.getTotalElements()) as BigNumber | ||
} | ||
return totalElementsAfter | ||
} | ||
|
||
const startVerifier = async () => { | ||
// Bring up new verifier | ||
verifier = new DockerComposeNetwork(['verifier']) | ||
await verifier.up({ commandOptions: ['--scale', 'verifier=1'] }) | ||
|
||
// Wait for verifier to be looping | ||
let logs = await verifier.logs() | ||
while (!logs.out.includes('Starting Sequencer Loop')) { | ||
await sleep(500) | ||
logs = await verifier.logs() | ||
} | ||
|
||
provider = injectL2Context(verifierProvider) | ||
} | ||
|
||
const syncVerifier = async (sequencerBlockNumber: number) => { | ||
// Wait until verifier has caught up to the sequencer | ||
let latestVerifierBlock = (await provider.getBlock('latest')) as any | ||
while (latestVerifierBlock.number < sequencerBlockNumber) { | ||
await sleep(500) | ||
latestVerifierBlock = (await provider.getBlock('latest')) as any | ||
} | ||
|
||
return provider.getBlock(sequencerBlockNumber) | ||
} | ||
|
||
before(async () => { | ||
env = await OptimismEnv.new() | ||
wallet = env.l2Wallet | ||
}) | ||
|
||
describe('Basic transactions', () => { | ||
afterEach(async () => { | ||
await verifier.stop('verifier') | ||
await verifier.rm() | ||
}) | ||
|
||
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. Why does 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. i followed the structure described in #604 which specified spinning up the verifier after making transactions. i haven't looked into distinctions between the two approaches yet, just imagined this test as "starting with a fresh copy of what's syncing every test" |
||
it('should sync dummy transaction', async () => { | ||
const totalElementsBefore = (await env.ctc.getTotalElements()) as BigNumber | ||
|
||
const tx = { | ||
to: '0x' + '1234'.repeat(10), | ||
gasLimit: 4000000, | ||
gasPrice: 0, | ||
data: '0x', | ||
value: 0, | ||
} | ||
const result = await wallet.sendTransaction(tx) | ||
await result.wait() | ||
|
||
const totalElementsAfter = await waitForBatchSubmission( | ||
totalElementsBefore | ||
) | ||
expect(totalElementsAfter.gt(totalElementsAfter)) | ||
|
||
const latestSequencerBlock = (await sequencerProvider.getBlock( | ||
'latest' | ||
)) as any | ||
|
||
await startVerifier() | ||
|
||
const matchingVerifierBlock = (await syncVerifier( | ||
latestSequencerBlock.number | ||
)) as any | ||
|
||
expect(matchingVerifierBlock.stateRoot).to.eq( | ||
latestSequencerBlock.stateRoot | ||
) | ||
}) | ||
}) | ||
}) |
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.
I feel like we need sync tests that have a dummy db that is passed to geth (upstream geth in L1 mode because hardhat doesn't allow for this) and then we sync from that deterministically. Perhaps we can call these verifier tests? We need to do the exact same logic for replicas so maybe network tests? Since its a network of nodes?
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.
^can rename to network tests!
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.
I don't think we necessarily need a pre-instantiated db as things are reasonably deterministic in our current envs? Think PR is fine rn otherwise
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.
That was more of a longer term comment, sorry for the confusion. In the long term we need sync tests that basically sync thousands of blocks where we can observe things like performance and state
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.
^opted to rename those later since sync is clearer for this context :)