-
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
tests: replica syncing #981
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7cbd4f4
[wip] add l2_dtl and replica images
annieke 5a92acb
passing basic dummy tx test
annieke 352b964
add erc20 test
annieke f8b3953
remove comments and lint check
annieke ffed8c7
remove l2_dtl from docker-compose
annieke 601cc99
cleanup logs and l2_dtl references
annieke bd51308
fix verifier config and order sync tests for ci
annieke 4fb229e
add sync test to ci
annieke 31f2a24
fix: wait for sequencer
annieke f53e81e
remove duplicated field and add build step before sync test
annieke 68cf25f
debug: separate yarn build and yarn test
annieke dcbc83a
poll provider instead of docker logs
annieke 8b5b116
add missing build step
annieke b7c0eab
Merge branch 'develop' into annie/replica-sync-test
tynes 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 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,6 @@ | ||
--- | ||
'@eth-optimism/integration-tests': patch | ||
'@eth-optimism/data-transport-layer': patch | ||
--- | ||
|
||
Add replica sync test to integration tests; handle 0 L2 blocks in DTL |
This file contains 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 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 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,119 @@ | ||
import chai, { expect } from 'chai' | ||
import { Wallet, Contract, ContractFactory, providers } from 'ethers' | ||
import { ethers } from 'hardhat' | ||
import { injectL2Context } from '@eth-optimism/core-utils' | ||
|
||
import { | ||
sleep, | ||
l2Provider, | ||
replicaProvider, | ||
waitForL2Geth, | ||
} from '../test/shared/utils' | ||
import { OptimismEnv } from '../test/shared/env' | ||
import { DockerComposeNetwork } from '../test/shared/docker-compose' | ||
|
||
describe('Syncing a replica', () => { | ||
let env: OptimismEnv | ||
let wallet: Wallet | ||
let replica: DockerComposeNetwork | ||
let provider: providers.JsonRpcProvider | ||
|
||
const sequencerProvider = injectL2Context(l2Provider) | ||
|
||
/* Helper functions */ | ||
|
||
const startReplica = async () => { | ||
// Bring up new replica | ||
replica = new DockerComposeNetwork(['replica']) | ||
await replica.up({ | ||
commandOptions: ['--scale', 'replica=1'], | ||
}) | ||
|
||
provider = await waitForL2Geth(replicaProvider) | ||
} | ||
|
||
const syncReplica = async (sequencerBlockNumber: number) => { | ||
// Wait until replica has caught up to the sequencer | ||
let latestReplicaBlock = (await provider.getBlock('latest')) as any | ||
while (latestReplicaBlock.number < sequencerBlockNumber) { | ||
await sleep(500) | ||
latestReplicaBlock = (await provider.getBlock('latest')) as any | ||
} | ||
|
||
return provider.getBlock(sequencerBlockNumber) | ||
} | ||
|
||
before(async () => { | ||
env = await OptimismEnv.new() | ||
wallet = env.l2Wallet | ||
}) | ||
|
||
after(async () => { | ||
await replica.stop('replica') | ||
await replica.rm() | ||
}) | ||
|
||
describe('Basic transactions and ERC20s', () => { | ||
const initialAmount = 1000 | ||
const tokenName = 'OVM Test' | ||
const tokenDecimals = 8 | ||
const TokenSymbol = 'OVM' | ||
|
||
let other: Wallet | ||
let Factory__ERC20: ContractFactory | ||
let ERC20: Contract | ||
|
||
before(async () => { | ||
other = Wallet.createRandom().connect(ethers.provider) | ||
Factory__ERC20 = await ethers.getContractFactory('ERC20', wallet) | ||
}) | ||
|
||
it('should sync dummy transaction', async () => { | ||
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 latestSequencerBlock = (await sequencerProvider.getBlock( | ||
'latest' | ||
)) as any | ||
|
||
await startReplica() | ||
|
||
const matchingReplicaBlock = (await syncReplica( | ||
latestSequencerBlock.number | ||
)) as any | ||
|
||
expect(matchingReplicaBlock.stateRoot).to.eq( | ||
latestSequencerBlock.stateRoot | ||
) | ||
}) | ||
|
||
it('should sync ERC20 deployment and transfer', async () => { | ||
ERC20 = await Factory__ERC20.deploy( | ||
initialAmount, | ||
tokenName, | ||
tokenDecimals, | ||
TokenSymbol | ||
) | ||
|
||
const transfer = await ERC20.transfer(other.address, 100) | ||
await transfer.wait() | ||
|
||
const latestSequencerBlock = (await provider.getBlock('latest')) as any | ||
|
||
const matchingReplicaBlock = (await syncReplica( | ||
latestSequencerBlock.number | ||
)) as any | ||
|
||
expect(matchingReplicaBlock.stateRoot).to.eq( | ||
latestSequencerBlock.stateRoot | ||
) | ||
}) | ||
}) | ||
}) |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -62,6 +62,7 @@ services: | |
# connect to the 2 layers | ||
DATA_TRANSPORT_LAYER__L1_RPC_ENDPOINT: http://l1_chain:8545 | ||
DATA_TRANSPORT_LAYER__L2_RPC_ENDPOINT: http://l2geth:8545 | ||
DATA_TRANSPORT_LAYER__SYNC_FROM_L2: 'true' | ||
annieke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DATA_TRANSPORT_LAYER__L2_CHAIN_ID: 420 | ||
ports: | ||
- ${DTL_PORT:-7878}:7878 | ||
|
@@ -141,23 +142,46 @@ services: | |
build: | ||
context: .. | ||
dockerfile: ./ops/docker/Dockerfile.geth | ||
# override with the geth script and the env vars required for it | ||
entrypoint: sh ./geth.sh | ||
env_file: | ||
- ./envs/geth.env | ||
environment: | ||
ETH1_HTTP: http://l1_chain:8545 | ||
ROLLUP_STATE_DUMP_PATH: http://deployer:8081/state-dump.latest.json | ||
# used for getting the addresses | ||
URL: http://deployer:8081/addresses.json | ||
# connecting to the DTL | ||
ROLLUP_CLIENT_HTTP: http://dtl:7878 | ||
ROLLUP_BACKEND: 'l1' | ||
ETH1_CTC_DEPLOYMENT_HEIGHT: 8 | ||
RETRIES: 60 | ||
IS_VERIFIER: "true" | ||
ROLLUP_VERIFIER_ENABLE: 'true' | ||
ports: | ||
- ${VERIFIER_HTTP_PORT:-8547}:8545 | ||
- ${VERIFIER_WS_PORT:-8548}:8546 | ||
|
||
replica: | ||
depends_on: | ||
- dtl | ||
image: ethereumoptimism/l2geth | ||
deploy: | ||
replicas: 0 | ||
build: | ||
context: .. | ||
dockerfile: ./ops/docker/Dockerfile.geth | ||
entrypoint: sh ./geth.sh | ||
env_file: | ||
- ./envs/geth.env | ||
environment: | ||
ETH1_HTTP: http://l1_chain:8545 | ||
ROLLUP_STATE_DUMP_PATH: http://deployer:8081/state-dump.latest.json | ||
URL: http://deployer:8081/addresses.json | ||
ROLLUP_CLIENT_HTTP: http://dtl:7878 | ||
ROLLUP_BACKEND: 'l2' | ||
ROLLUP_VERIFIER_ENABLE: 'true' | ||
ETH1_CTC_DEPLOYMENT_HEIGHT: 8 | ||
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 doesn't seem to be any reason for us to be supplying this parameter. It just happens to be that the CTC is deployed at block 8 right now. Let's make an issue for this. |
||
RETRIES: 60 | ||
ports: | ||
- ${L2GETH_HTTP_PORT:-8549}:8545 | ||
- ${L2GETH_WS_PORT:-8550}:8546 | ||
|
||
integration_tests: | ||
image: ethereumoptimism/integration-tests | ||
|
This file contains 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
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.
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.
This function is basically the same as
startVerifier
- it should be possible to have a common file where both the verifier and replica can use that deduplicates the codeThere 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.
^agreed, will refactor this!
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.
@tynes i switched both to poll the endpoint instead of waiting for docker logs! as a long term vision when both verifier and replicas are stable, i think these tests can go for a larger refactor in which they share the same test suite of transactions and we just use a
verifier
orreplica
switch to run each.as of now though, the replica has matching state roots for pretty much everything but the verifier is the opposite, so i'm keeping them as separate files (also not in the
test
folder for now) so we could buff up the replica tests before uniswap launch.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.
Ok! Thats a good idea!