Skip to content

Commit

Permalink
fix(withdrawal unlocker): unhandle tx status unknown and rejected
Browse files Browse the repository at this point in the history
Should drop unlock tx and try again
  • Loading branch information
zeroqn authored and jjyr committed Jul 19, 2022
1 parent 459e156 commit 2249a24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
39 changes: 32 additions & 7 deletions crates/block-producer/src/withdrawal_unlocker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ impl FinalizedWithdrawalUnlocker {
bail!("send tx failed {}", err);
}
};

log::info!(
"[unlock withdrawal] try unlock {} withdrawals in tx {}",
to_unlock.len(),
tx_hash.pack()
);

self.unlocked_set.extend(to_unlock.clone());
self.unlock_txs.insert(tx_hash, to_unlock);
}
Expand All @@ -94,15 +101,33 @@ impl FinalizedWithdrawalUnlocker {
log::info!("[unlock withdrawal] dropped unlock tx {}", tx_hash.pack());
drop_txs.push(*tx_hash);
}
Ok(Some(tx_status)) if matches!(tx_status, TxStatus::Committed) => {
log::info!(
"[unlock withdrawal] unlock {} withdrawals in tx {}",
withdrawal_to_unlock.len(),
tx_hash.pack(),
);
Ok(Some(tx_status)) => {
match tx_status {
TxStatus::Pending | TxStatus::Proposed => continue, // Wait
TxStatus::Committed => {
log::info!(
"[unlock withdrawal] unlock {} withdrawals in tx {}",
withdrawal_to_unlock.len(),
tx_hash.pack(),
);
}
TxStatus::Unknown | TxStatus::Rejected => {
log::debug!(
"[unlock withdrawal] unlock withdrawals tx {} status {:?}, drop it",
tx_hash.pack(),
tx_status
);
}
_ => {
log::warn!(
"[unlock withdrawal] unhandled unlock withdrawals tx {} status {:?}, drop it",
tx_hash.pack(),
tx_status
)
}
}
drop_txs.push(*tx_hash);
}
Ok(Some(_)) => (), // Wait
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/types/src/offchain/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct WithdrawalsAmount {
}

#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum TxStatus {
/// Status "pending". The transaction is in the pool, and not proposed yet.
Pending,
Expand Down

0 comments on commit 2249a24

Please sign in to comment.