Skip to content
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: Sepolia support #169

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/magi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl Cli {
let chain = match self.network.as_str() {
"optimism" => ChainConfig::optimism(),
"optimism-goerli" => ChainConfig::optimism_goerli(),
"optimism-sepolia" => ChainConfig::optimism_sepolia(),
"base" => ChainConfig::base(),
"base-goerli" => ChainConfig::base_goerli(),
file if file.ends_with(".json") => ChainConfig::from_json(file),
Expand Down
2 changes: 1 addition & 1 deletion docker/.env.default
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# L1 network option: can be either `optimism`, `optimism-goerli` or `base-goerli`
# L1 network option: can be either `optimism`, `optimism-goerli`, `optimism-sepolia` or `base-goerli`
NETWORK=optimism

# The HTTP RPC endpoint of an L1 node
Expand Down
8 changes: 8 additions & 0 deletions docker/start-op-geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ then
wget "https://datadirs.optimism.io/goerli-bedrock.tar.zst" -P $DATADIR
zstd -cd $DATADIR/goerli-bedrock.tar.zst | tar xvf - -C $DATADIR
fi
elif [ "$NETWORK" = "optimism-sepolia" ]
then
CHAIN_ID=11155420
if [ ! -d "$DATADIR" ]
then
wget "https://storage.googleapis.com/oplabs-network-data/Sepolia/genesis.json" -O ./genesis-l2.json
geth init --datadir=$DATADIR ./genesis-l2.json
fi
elif [ $NETWORK = "base-goerli" ]
then
CHAIN_ID=84531
Expand Down
37 changes: 37 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,43 @@ impl ChainConfig {
blocktime: 2,
}
}
pub fn optimism_sepolia() -> Self {
Self {
network: "optimism-sepolia".to_string(),
l1_chain_id: 11155111,
l2_chain_id: 11155420,
l1_start_epoch: Epoch {
hash: hash("0x48f520cf4ddaf34c8336e6e490632ea3cf1e5e93b0b2bc6e917557e31845371b"),
number: 4071408,
timestamp: 1691802540,
},
l2_genesis: BlockInfo {
hash: hash("0x102de6ffb001480cc9b8b548fd05c34cd4f46ae4aa91759393db90ea0409887d"),
number: 0,
parent_hash: hash(
"0x0000000000000000000000000000000000000000000000000000000000000000",
),
timestamp: 1691802540,
},
system_config: SystemConfig {
batch_sender: addr("0x8F23BB38F531600e5d8FDDaAEC41F13FaB46E98c"),
gas_limit: U256::from(30_000_000),
l1_fee_overhead: U256::from(188),
l1_fee_scalar: U256::from(684000),
unsafe_block_signer: addr("0x0000000000000000000000000000000000000000"),
},
system_config_contract: addr("0x034edd2a225f7f429a63e0f1d2084b9e0a93b538"),
batch_inbox: addr("0xff00000000000000000000000000000011155420"),
deposit_contract: addr("0x16fc5058f25648194471939df75cf27a2fdc48bc"),
l2_to_l1_message_passer: addr("0x4200000000000000000000000000000000000016"),
max_channel_size: 100_000_000,
channel_timeout: 300,
seq_window_size: 3600,
max_seq_drift: 600,
regolith_time: 0,
blocktime: 2,
}
}

pub fn base() -> Self {
Self {
Expand Down
4 changes: 0 additions & 4 deletions src/derive/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ impl State {
})
}

pub fn is_full(&self) -> bool {
self.current_epoch_num > self.safe_epoch.number + 1000
}

pub fn update_l1_info(&mut self, l1_info: L1Info) {
self.current_epoch_num = l1_info.block_info.number;

Expand Down
93 changes: 45 additions & 48 deletions src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ impl<E: Engine> Driver<E> {
let new_safe_head = self.engine_driver.safe_head;
let new_safe_epoch = self.engine_driver.safe_epoch;

self.state
.write()
.map_err(|_| eyre::eyre!("lock poisoned"))?
.update_safe_head(new_safe_head, new_safe_epoch);

let unfinalized_entry = (
new_safe_head,
new_safe_epoch,
Expand Down Expand Up @@ -252,54 +257,46 @@ impl<E: Engine> Driver<E> {

/// Ingests the next update from the block update channel
async fn handle_next_block_update(&mut self) -> Result<()> {
let is_state_full = self
.state
.read()
.map_err(|_| eyre::eyre!("lock poisoned"))?
.is_full();

if !is_state_full {
let next = self.chain_watcher.block_update_receiver.try_recv();

if let Ok(update) = next {
match update {
BlockUpdate::NewBlock(l1_info) => {
let num = l1_info.block_info.number;

self.unsafe_block_signer_sender
.send(l1_info.system_config.unsafe_block_signer)?;

self.pipeline
.push_batcher_transactions(l1_info.batcher_transactions.clone(), num)?;

self.state
.write()
.map_err(|_| eyre::eyre!("lock poisoned"))?
.update_l1_info(*l1_info);
}
BlockUpdate::Reorg => {
tracing::warn!("reorg detected, purging pipeline");

self.unfinalized_blocks.clear();
self.chain_watcher.restart(
self.engine_driver.finalized_epoch.number - self.channel_timeout,
self.engine_driver.finalized_head.number,
)?;

self.state
.write()
.map_err(|_| eyre::eyre!("lock poisoned"))?
.purge(
self.engine_driver.finalized_head,
self.engine_driver.finalized_epoch,
);

self.pipeline.purge()?;
self.engine_driver.reorg();
}
BlockUpdate::FinalityUpdate(num) => {
self.finalized_l1_block_number = num;
}
let next = self.chain_watcher.block_update_receiver.try_recv();

if let Ok(update) = next {
match update {
BlockUpdate::NewBlock(l1_info) => {
let num = l1_info.block_info.number;

self.unsafe_block_signer_sender
.send(l1_info.system_config.unsafe_block_signer)?;

self.pipeline
.push_batcher_transactions(l1_info.batcher_transactions.clone(), num)?;

self.state
.write()
.map_err(|_| eyre::eyre!("lock poisoned"))?
.update_l1_info(*l1_info);
}
BlockUpdate::Reorg => {
tracing::warn!("reorg detected, purging pipeline");

self.unfinalized_blocks.clear();
self.chain_watcher.restart(
self.engine_driver.finalized_epoch.number - self.channel_timeout,
self.engine_driver.finalized_head.number,
)?;

self.state
.write()
.map_err(|_| eyre::eyre!("lock poisoned"))?
.purge(
self.engine_driver.finalized_head,
self.engine_driver.finalized_epoch,
);

self.pipeline.purge()?;
self.engine_driver.reorg();
}
BlockUpdate::FinalityUpdate(num) => {
self.finalized_l1_block_number = num;
}
}
}
Expand Down
Loading