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

fix: block range #267

Merged
merged 1 commit into from
Dec 10, 2024
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
10 changes: 5 additions & 5 deletions configs/2151908/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"genesis": {
"l1": {
"number": 7,
"hash": "0x86ae6225a9dc2477b58f9aed99078498d53bf562dceea949ade8c7d8faae210f"
"hash": "0x60e7e36dc50afbef1eddb5d3168bffb70e3ca52e1358a2930600461d67eda6d3"
},
"l2": {
"number": 0,
"hash": "0x43e7f10deaa02139e39293a9de36a57b71dae823aac51e962ba253443cf151c1"
"hash": "0xc576b2c683017e9a6d27bad4d8de6781919352942d747b10d5081ad7c514fe49"
},
"l2_time": 1733297540,
"l2_time": 1733812906,
"system_config": {
"batcherAddr": "0xd3f2c5afb2d76f5579f326b0cd7da5f5a4126c35",
"overhead": "0x0",
Expand Down Expand Up @@ -43,7 +43,7 @@
"granite_time": 0,
"holocene_time": 0,
"batch_inbox_address": "0x00a4fe4c6aaa0729d7699c387e7f281dd64afa2a",
"deposit_contract_address": "0xadbe3b0c0789e185866359e2502b7a36bd88d907",
"l1_system_config_address": "0xf19ae8506aa195d0997687b1e38f097ada484fb1",
"deposit_contract_address": "0x365f6f26f02f097dbc25b37391fe58b3915961ae",
"l1_system_config_address": "0xe20837f876176234bd118bfc649a90d09b209d97",
"protocol_versions_address": "0x0000000000000000000000000000000000000000"
}
8 changes: 4 additions & 4 deletions contracts/opsuccinctl2ooconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"challenger": "0x0000000000000000000000000000000000000000",
"finalizationPeriod": 0,
"finalizationPeriod": 3600,
"l2BlockTime": 2,
"owner": "0xDEd0000E32f8F40414d3ab3a830f735a3553E18e",
"proposer": "0xDEd0000E32f8F40414d3ab3a830f735a3553E18e",
"rollupConfigHash": "0x0d7101e2acc7eae1fb42cfce5c604d14da561726e4e01b509315e5a9f97a9816",
"startingBlockNumber": 5591859,
"startingOutputRoot": "0xd2c903c40513a87898b2830196d53e0bedabe5dfba09c002b9cc39cb0ba5fe46",
"startingTimestamp": 1733536206,
"startingBlockNumber": 5726082,
"startingOutputRoot": "0x88cf50185686c85146bdfd3aa17c9624b13a7c3ec912f68026c54171735a0be3",
"startingTimestamp": 1733804652,
"submissionInterval": 1200,
"verifier": "0x397A5f7f3dBd538f23DE225B51f532c34448dA9B",
"aggregationVkey": "0x00ea4171dbd0027768055bee7f6d64e17e9cec99b29aad5d18e5d804b967775b",
Expand Down
23 changes: 19 additions & 4 deletions utils/host/src/block_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,36 @@ pub async fn get_validated_block_range(
end: Option<u64>,
default_range: u64,
) -> Result<(u64, u64)> {
let header = data_fetcher.get_l2_header(BlockId::finalized()).await?;
// If safeDB is activated, get the L2 safe head. If not, use the finalized block.
let safe_db_activated = data_fetcher.is_safe_db_activated().await?;
let end_number = if safe_db_activated {
let header = data_fetcher.get_l1_header(BlockId::latest()).await?;
let safe_head_response: SafeHeadResponse = data_fetcher
.fetch_rpc_data_with_mode(
RPCMode::L2Node,
"optimism_safeHeadAtL1Block",
vec![format!("0x{:x}", header.number).into()],
)
.await?;
safe_head_response.safe_head.number
} else {
let header = data_fetcher.get_l2_header(BlockId::finalized()).await?;
header.number
};

// If end block not provided, use latest finalized block
let l2_end_block = match end {
Some(end) => {
if end > header.number {
if end > end_number {
bail!(
"The end block ({}) is greater than the latest finalized block ({})",
end,
header.number
end_number
);
}
end
}
None => header.number,
None => end_number,
};

// If start block not provided, use end block - default_range
Expand Down
25 changes: 16 additions & 9 deletions utils/host/src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ use op_alloy_rpc_types::{OpTransactionReceipt, OutputResponse, SafeHeadResponse}
use op_succinct_client_utils::boot::BootInfoStruct;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::{cmp::Ordering, collections::HashMap, env, fs, path::Path, str::FromStr, sync::Arc};
use std::{
cmp::{min, Ordering},
collections::HashMap,
env, fs,
path::Path,
str::FromStr,
sync::Arc,
};

use alloy_primitives::{keccak256, Bytes, U256, U64};

Expand Down Expand Up @@ -466,7 +473,7 @@ impl OPSuccinctDataFetcher {

// Return the block hash of the closest block after the target timestamp
let block = provider
.get_block((low - 10).into(), BlockTransactionsKind::Hashes)
.get_block(low.into(), BlockTransactionsKind::Hashes)
.await?;
if let Some(block) = block {
Ok((block.header().hash().0.into(), block.header().number()))
Expand Down Expand Up @@ -760,12 +767,7 @@ impl OPSuccinctDataFetcher {
};
let claimed_l2_output_root = keccak256(l2_claim_encoded.abi_encode());

let (_, l1_head_number) = self.get_l1_head(l2_end_block).await?;

// FIXME: Investigate requirement for L1 head offset beyond batch posting block with safe head > L2 end block.
let l1_head_number = l1_head_number + 20;
let header = self.get_l1_header(l1_head_number.into()).await?;
let l1_head_hash = header.hash_slow();
let (l1_head_hash, _) = self.get_l1_head(l2_end_block).await?;

// Get the workspace root, which is where the data directory is.
let data_directory =
Expand Down Expand Up @@ -922,8 +924,13 @@ impl OPSuccinctDataFetcher {

// Get L1 head.
let l2_block_timestamp = self.get_l2_header(l2_end_block.into()).await?.timestamp;
let latest_l1_timestamp = self.get_l1_header(BlockId::latest()).await?.timestamp;

let target_timestamp = l2_block_timestamp + (max_batch_post_delay_minutes * 60);
// Ensure that the target timestamp is not greater than the latest L1 timestamp.
let target_timestamp = min(
l2_block_timestamp + (max_batch_post_delay_minutes * 60),
latest_l1_timestamp,
);
Ok(self.find_l1_block_by_timestamp(target_timestamp).await?)
}
}
Expand Down
Loading