Skip to content

Commit

Permalink
be stricter with boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
montekki committed Oct 5, 2023
1 parent 80ee74e commit 5d454db
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
6 changes: 2 additions & 4 deletions bin/withdrawal-finalizer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ async fn main() -> Result<()> {

let zksync_contract = IZkSync::new(config.diamond_proxy_addr, client_l1.clone());

let first_block_today = client::get_first_block_today(None, &client_l2)
.await?
.unwrap();
let first_block_today = client::get_first_block_today(None, &client_l2).await?;

let watcher = Watcher::new(client_l2.clone(), pgpool.clone(), first_block_today).await?;

Expand Down Expand Up @@ -271,7 +269,7 @@ async fn main() -> Result<()> {
config.one_withdrawal_gas_limit,
config.batch_finalization_gas_limit,
);
vlog::info!("first L2 miniblock mined today is {first_block_today}");
vlog::info!("first L2 miniblock mined today is {first_block_today:?}");

let finalizer = finalizer::Finalizer::new(
pgpool,
Expand Down
20 changes: 14 additions & 6 deletions finalizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,26 @@ where
l1_bridge: IL1Bridge<M>,
tx_retry_timeout: usize,
account_address: Address,
first_block_today: U64,
first_block_today: Option<U64>,
) -> Result<Self> {
let max_finalized_today =
storage::max_finalized_l2_miniblock_since_block(&pgpool, first_block_today.as_u64())
.await?
.unwrap_or(first_block_today.as_u64());
let max_finalized_today = match first_block_today {
Some(first_block_today) => {
storage::max_finalized_l2_miniblock_since_block(&pgpool, first_block_today.as_u64())
.await?
}
None => None,
};

let historic_interval = match (first_block_today, max_finalized_today) {
(None, None) | (None, Some(_)) | (Some(_), None) => None,
(Some(from), Some(to)) => Some((from, to.into())),
};

// we need to tell the meter to meter only finalized withdrawls
let withdrawals_meterer = withdrawals_meterer::WithdrawalsMeter::new(
pgpool.clone(),
"era_withdrawal_finalizer_meter",
Some((first_block_today, max_finalized_today.into())),
historic_interval,
)
.await;
let tx_fee_limit = ethers::utils::parse_ether(TX_FEE_LIMIT)
Expand Down
17 changes: 12 additions & 5 deletions watcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,22 @@ where
<M2 as Middleware>::Provider: JsonRpcClient,
{
#[allow(clippy::too_many_arguments)]
pub async fn new(l2_provider: Arc<M2>, pgpool: PgPool, first_block_today: U64) -> Result<Self> {
let max_l2_miniblock = storage::max_l2_miniblock(&pgpool)
.await?
.unwrap_or(first_block_today.as_u64());
pub async fn new(
l2_provider: Arc<M2>,
pgpool: PgPool,
first_block_today: Option<U64>,
) -> Result<Self> {
let max_l2_miniblock = storage::max_l2_miniblock(&pgpool).await?;

let historic_interval = match (first_block_today, max_l2_miniblock) {
(None, None) | (None, Some(_)) | (Some(_), None) => None,
(Some(from), Some(to)) => Some((from, to.into())),
};

let withdrawals_meterer = withdrawals_meterer::WithdrawalsMeter::new(
pgpool.clone(),
"era_withdrawal_finalizer_watcher_meter",
Some((first_block_today, max_l2_miniblock.into())),
historic_interval,
)
.await;

Expand Down

0 comments on commit 5d454db

Please sign in to comment.