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: delta hardfork #198

Merged
merged 39 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1c1efa8
basic span batch decoding
ncitron Dec 28, 2023
2158fb7
refactor: move span batch type into separate module
ncitron Jan 8, 2024
0130ea5
span batch status checks
ncitron Jan 10, 2024
11f67c8
output BlockInput in batch stage
ncitron Jan 10, 2024
566423b
take BlockInput in attributes stage
ncitron Jan 10, 2024
8cca8a7
fix tests
ncitron Jan 10, 2024
59c8bd5
fix tests
ncitron Jan 10, 2024
f69b8c8
remove unstable code
ncitron Jan 10, 2024
3b63bbf
filter overlapping block inputs
ncitron Jan 11, 2024
bb85a83
clippy
ncitron Jan 11, 2024
cd31c63
cleanup
ncitron Jan 11, 2024
451b3f1
fix clippy in service
ncitron Jan 11, 2024
7b4200e
fix transaction decoding
ncitron Jan 11, 2024
34eabc5
remove empty block creation for testing
ncitron Jan 11, 2024
f7c47dc
revert changes
ncitron Jan 11, 2024
c0dbf3c
debug
ncitron Jan 12, 2024
5c5ff2a
fix batch origin calculation
ncitron Jan 12, 2024
5b3ed1f
better logging
ncitron Jan 12, 2024
f2ba143
logging
ncitron Jan 12, 2024
afffb80
logging
ncitron Jan 12, 2024
f66e8c3
show batch future or undecided
ncitron Jan 12, 2024
4c88464
confrm error
ncitron Jan 12, 2024
6174e38
cleanup for testing
ncitron Jan 12, 2024
8de532f
fix batch origin checks
ncitron Jan 14, 2024
2a44d6a
fix prev l2 block calculation
ncitron Jan 14, 2024
110cc36
fix prev block fetch
ncitron Jan 14, 2024
a1af83b
fix l2_info tracking
ncitron Jan 14, 2024
f7a3eee
fix epoch checks
ncitron Jan 14, 2024
c105fc8
fix
ncitron Jan 14, 2024
676b693
fix overlapped checks
ncitron Jan 14, 2024
72a7d92
fix origin bit handling in block input derivation
ncitron Jan 14, 2024
fd9623d
better logging
ncitron Jan 14, 2024
7913b84
start sync earlier
ncitron Jan 14, 2024
548315d
reorder span batch status checks for better logging
ncitron Jan 14, 2024
09a35d2
prefetch l2 refs
ncitron Jan 14, 2024
4e56ca4
add overlap epoch check
ncitron Jan 14, 2024
6ef35d9
Merge branch 'master' into ncitron/span-batch
ncitron Jan 14, 2024
159d34a
fmt
ncitron Jan 14, 2024
ad0582a
fix batch status check ordering
ncitron Jan 14, 2024
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
29 changes: 24 additions & 5 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl FromStr for SyncMode {
}

/// A system configuration
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Default)]
pub struct Config {
/// The base chain RPC URL
pub l1_rpc_url: String,
Expand Down Expand Up @@ -143,13 +143,21 @@ pub struct ChainConfig {
pub regolith_time: u64,
/// Timestamp of the canyon hardfork
pub canyon_time: u64,
/// Timestamp of the delta hardfork
pub delta_time: u64,
/// Network blocktime
#[serde(default = "default_blocktime")]
pub blocktime: u64,
/// L2 To L1 Message passer address
pub l2_to_l1_message_passer: Address,
}

impl Default for ChainConfig {
fn default() -> Self {
ChainConfig::optimism()
}
}

/// Optimism system config contract values
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct SystemConfig {
Expand Down Expand Up @@ -255,6 +263,7 @@ impl ChainConfig {
blocktime: 2,
regolith_time: 0,
canyon_time: 170499240,
delta_time: u64::MAX,
}
}

Expand Down Expand Up @@ -293,6 +302,7 @@ impl ChainConfig {
max_seq_drift: 600,
regolith_time: 1679079600,
canyon_time: 1699981200,
delta_time: 1703116800,
blocktime: 2,
}
}
Expand Down Expand Up @@ -331,6 +341,7 @@ impl ChainConfig {
max_seq_drift: 600,
regolith_time: 0,
canyon_time: 1699981200,
delta_time: 1703203200,
blocktime: 2,
}
}
Expand Down Expand Up @@ -369,6 +380,7 @@ impl ChainConfig {
blocktime: 2,
regolith_time: 0,
canyon_time: 1704992401,
delta_time: u64::MAX,
}
}

Expand Down Expand Up @@ -405,6 +417,7 @@ impl ChainConfig {
max_seq_drift: 600,
regolith_time: 1683219600,
canyon_time: 1699981200,
delta_time: 1703116800,
blocktime: 2,
}
}
Expand Down Expand Up @@ -442,6 +455,7 @@ impl ChainConfig {
max_seq_drift: 600,
regolith_time: 0,
canyon_time: 1699981200,
delta_time: 1703203200,
blocktime: 2,
}
}
Expand Down Expand Up @@ -485,6 +499,7 @@ pub struct ExternalChainConfig {
l2_chain_id: u64,
regolith_time: u64,
canyon_time: u64,
delta_time: u64,
batch_inbox_address: Address,
deposit_contract_address: Address,
l1_system_config_address: Address,
Expand Down Expand Up @@ -547,6 +562,7 @@ impl From<ExternalChainConfig> for ChainConfig {
max_seq_drift: external.max_sequencer_drift,
regolith_time: external.regolith_time,
canyon_time: external.canyon_time,
delta_time: external.delta_time,
blocktime: external.block_time,
l2_to_l1_message_passer: addr("0x4200000000000000000000000000000000000016"),
}
Expand Down Expand Up @@ -593,6 +609,7 @@ impl From<ChainConfig> for ExternalChainConfig {
l2_chain_id: chain_config.l2_chain_id,
regolith_time: chain_config.regolith_time,
canyon_time: chain_config.canyon_time,
delta_time: chain_config.delta_time,
batch_inbox_address: chain_config.batch_inbox,
deposit_contract_address: chain_config.deposit_contract,
l1_system_config_address: chain_config.system_config_contract,
Expand Down Expand Up @@ -718,8 +735,9 @@ mod test {
"channel_timeout": 120,
"l1_chain_id": 900,
"l2_chain_id": 901,
"regolith_time": 0,
"canyon_time": 0,
"regolith_time": 1,
"canyon_time": 2,
"delta_time": 3,
"batch_inbox_address": "0xff00000000000000000000000000000000000000",
"deposit_contract_address": "0x6900000000000000000000000000000000000001",
"l1_system_config_address": "0x6900000000000000000000000000000000000009"
Expand Down Expand Up @@ -765,8 +783,9 @@ mod test {
assert_eq!(chain.channel_timeout, 120);
assert_eq!(chain.seq_window_size, 200);
assert_eq!(chain.max_seq_drift, 300);
assert_eq!(chain.regolith_time, 0);
assert_eq!(chain.canyon_time, 0);
assert_eq!(chain.regolith_time, 1);
assert_eq!(chain.canyon_time, 2);
assert_eq!(chain.delta_time, 3);
assert_eq!(chain.blocktime, 2);
assert_eq!(
chain.l2_to_l1_message_passer,
Expand Down
15 changes: 10 additions & 5 deletions src/derive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,16 @@ mod tests {

chain_watcher.start().unwrap();

let state = Arc::new(RwLock::new(State::new(
config.chain.l2_genesis,
config.chain.l1_start_epoch,
config.clone(),
)));
let provider = Provider::try_from(env::var("L2_TEST_RPC_URL").unwrap()).unwrap();
let state = Arc::new(RwLock::new(
State::new(
config.chain.l2_genesis,
config.chain.l1_start_epoch,
&provider,
config.clone(),
)
.await,
));

let mut pipeline = Pipeline::new(state.clone(), config.clone(), 0).unwrap();

Expand Down
48 changes: 24 additions & 24 deletions src/derive/stages/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use crate::derive::PurgeableIterator;
use crate::engine::PayloadAttributes;
use crate::l1::L1Info;

use super::batches::Batch;
use super::block_input::BlockInput;

pub struct Attributes {
batch_iter: Box<dyn PurgeableIterator<Item = Batch>>,
block_input_iter: Box<dyn PurgeableIterator<Item = BlockInput<u64>>>,
state: Arc<RwLock<State>>,
sequence_number: u64,
epoch_hash: H256,
Expand All @@ -27,64 +27,60 @@ impl Iterator for Attributes {
type Item = PayloadAttributes;

fn next(&mut self) -> Option<Self::Item> {
self.batch_iter
self.block_input_iter
.next()
.map(|input| input.with_full_epoch(&self.state).unwrap())
.map(|batch| self.derive_attributes(batch))
}
}

impl PurgeableIterator for Attributes {
fn purge(&mut self) {
self.batch_iter.purge();
self.block_input_iter.purge();
self.sequence_number = 0;
self.epoch_hash = self.state.read().unwrap().safe_epoch.hash;
}
}

impl Attributes {
pub fn new(
batch_iter: Box<dyn PurgeableIterator<Item = Batch>>,
block_input_iter: Box<dyn PurgeableIterator<Item = BlockInput<u64>>>,
state: Arc<RwLock<State>>,
config: Arc<Config>,
seq: u64,
) -> Self {
let epoch_hash = state.read().unwrap().safe_epoch.hash;

Self {
batch_iter,
block_input_iter,
state,
sequence_number: seq,
epoch_hash,
config,
}
}

fn derive_attributes(&mut self, batch: Batch) -> PayloadAttributes {
tracing::debug!("attributes derived from block {}", batch.epoch_num);
tracing::debug!("batch epoch hash {:?}", batch.epoch_hash);
fn derive_attributes(&mut self, input: BlockInput<Epoch>) -> PayloadAttributes {
tracing::debug!("attributes derived from block {}", input.epoch.number);
tracing::debug!("batch epoch hash {:?}", input.epoch.hash);

self.update_sequence_number(batch.epoch_hash);
self.update_sequence_number(input.epoch.hash);

let state = self.state.read().unwrap();
let l1_info = state.l1_info_by_hash(batch.epoch_hash).unwrap();
let l1_info = state.l1_info_by_hash(input.epoch.hash).unwrap();

let epoch = Some(Epoch {
number: batch.epoch_num,
hash: batch.epoch_hash,
timestamp: l1_info.block_info.timestamp,
});

let withdrawals = if batch.timestamp >= self.config.chain.canyon_time {
let withdrawals = if input.timestamp >= self.config.chain.canyon_time {
Some(Vec::new())
} else {
None
};

let timestamp = U64([batch.timestamp]);
let l1_inclusion_block = Some(batch.l1_inclusion_block);
let timestamp = U64([input.timestamp]);
let l1_inclusion_block = Some(input.l1_inclusion_block);
let seq_number = Some(self.sequence_number);
let prev_randao = l1_info.block_info.mix_hash;
let transactions = Some(self.derive_transactions(batch, l1_info));
let epoch = Some(input.epoch);
let transactions = Some(self.derive_transactions(input, l1_info));
let suggested_fee_recipient = SystemAccounts::default().fee_vault;

PayloadAttributes {
Expand All @@ -101,18 +97,22 @@ impl Attributes {
}
}

fn derive_transactions(&self, batch: Batch, l1_info: &L1Info) -> Vec<RawTransaction> {
fn derive_transactions(
&self,
input: BlockInput<Epoch>,
l1_info: &L1Info,
) -> Vec<RawTransaction> {
let mut transactions = Vec::new();

let attributes_tx = self.derive_attributes_deposited(l1_info, batch.timestamp);
let attributes_tx = self.derive_attributes_deposited(l1_info, input.timestamp);
transactions.push(attributes_tx);

if self.sequence_number == 0 {
let mut user_deposited_txs = self.derive_user_deposited();
transactions.append(&mut user_deposited_txs);
}

let mut rest = batch.transactions;
let mut rest = input.transactions;
transactions.append(&mut rest);

transactions
Expand Down
Loading
Loading