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: detect reverted withdrawal transactions #287

Merged
3 changes: 3 additions & 0 deletions finalizer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub enum Error {

#[error("middleware error {0}")]
Middleware(String),

#[error("withdrawal transaction was reverted")]
WithdrawalTransactionReverted,
}

impl<M: Middleware> From<ContractError<M>> for Error {
Expand Down
13 changes: 13 additions & 0 deletions finalizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ where
tx.tx.clone(),
self.tx_retry_timeout,
nonce,
self.batch_finalization_gas_limit,
)
.await;

Expand All @@ -232,6 +233,18 @@ where
let withdrawals = withdrawals.into_iter().map(|w| w.key()).collect::<Vec<_>>();

match tx {
Ok(Some(tx)) if tx.status.expect("EIP-658 is enabled; qed").is_zero() => {
tracing::error!(
"withdrawal transaction {:?} was reverted",
tx.transaction_hash
);

FINALIZER_METRICS.reverted_withdrawal_transactions.inc();

storage::inc_unsuccessful_finalization_attempts(&self.pgpool, &withdrawals).await?;

return Err(Error::WithdrawalTransactionReverted);
}
Ok(Some(tx)) => {
tracing::info!(
"withdrawal transaction {:?} successfully mined",
Expand Down
3 changes: 3 additions & 0 deletions finalizer/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub(super) struct FinalizerMetrics {

/// Number of withdrawals failed to fetch withdrawal parameters for.
pub failed_to_fetch_withdrawal_params: Counter,

/// Number of withdrawal transactions that were reverted.
pub reverted_withdrawal_transactions: Counter,
}

#[vise::register]
Expand Down
42 changes: 34 additions & 8 deletions tx-sender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub async fn send_tx_adjust_gas<M, T>(
tx: T,
retry_timeout: Duration,
nonce: U256,
gas_limit: U256,
) -> Result<Option<TransactionReceipt>, <M as Middleware>::Error>
where
M: Middleware,
Expand All @@ -103,6 +104,7 @@ where
let mut submit_tx = tx.into();
m.fill_transaction(&mut submit_tx, None).await?;
submit_tx.set_nonce(nonce);
submit_tx.set_gas(gas_limit);

for retry_num in 0..usize::MAX {
if retry_num > 0 {
Expand Down Expand Up @@ -174,9 +176,15 @@ mod tests {
.gas_price(gas_price);

tokio::time::timeout(Duration::from_secs(3), async {
send_tx_adjust_gas(provider.clone(), tx, Duration::from_secs(1), 0.into())
.await
.unwrap_err()
send_tx_adjust_gas(
provider.clone(),
tx,
Duration::from_secs(1),
0.into(),
6000000.into(),
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
)
.await
.unwrap_err()
})
.await
.ok();
Expand Down Expand Up @@ -238,8 +246,20 @@ mod tests {

tokio::time::timeout(Duration::from_secs(3), async {
let (first, second) = tokio::join!(
send_tx_adjust_gas(provider.clone(), tx_1, Duration::from_secs(1), 0.into()),
send_tx_adjust_gas(provider.clone(), tx_2, Duration::from_secs(1), 1.into())
send_tx_adjust_gas(
provider.clone(),
tx_1,
Duration::from_secs(1),
0.into(),
6000000.into()
),
send_tx_adjust_gas(
provider.clone(),
tx_2,
Duration::from_secs(1),
1.into(),
6000000.into()
)
);
first.unwrap();
second.unwrap();
Expand Down Expand Up @@ -377,9 +397,15 @@ mod tests {
.from(from);

tokio::time::timeout(Duration::from_secs(3), async {
send_tx_adjust_gas(provider.clone(), tx, Duration::from_secs(1), 0.into())
.await
.unwrap()
send_tx_adjust_gas(
provider.clone(),
tx,
Duration::from_secs(1),
0.into(),
6000000.into(),
)
.await
.unwrap()
})
.await
.ok();
Expand Down
Loading