Skip to content

Commit cff1d59

Browse files
chore: add defensive checks
1 parent 9dc7a53 commit cff1d59

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

finalizer/src/actor.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,14 @@ impl<
12381238

12391239
for (key, balance, withdrawal_credentials) in validators_to_process {
12401240
if balance < self.canonical_state.get_minimum_stake() {
1241+
// Nothing to withdraw and nothing in the committee to
1242+
// remove. Setting has_pending_withdrawal here would never
1243+
// get cleared because the zero-balance_deduction
1244+
// completion path is a refund-style short-circuit.
1245+
// Node: this is a defensive check and not strictly necessary.
1246+
if balance == 0 {
1247+
continue;
1248+
}
12411249
// Remove the validator from the committee and withdraw the full balance
12421250
// Update account first: move balance to pending_withdrawal_amount
12431251
if let Some(mut account) = self.canonical_state.get_account(&key).cloned() {
@@ -1966,12 +1974,24 @@ async fn process_execution_requests<
19661974
assert_eq!(pending_withdrawal.inner, *withdrawal);
19671975

19681976
// If balance_deduction is 0, this is an immediate refund of a rejected deposit.
1969-
// No account modifications needed - the money was never part of the account.
1977+
// No balance changes are needed the money was never part of the account.
19701978
// Note: if a deposit request with an invalid amount (below minimum or above maximum stake) was submitted,
19711979
// a withdrawal request will be initiated immediately, without creating a validator account.
19721980
// These are the cases where we process a withdrawal request without having a validator account
19731981
// stored in the consensus state.
19741982
if pending_withdrawal.balance_deduction == 0 {
1983+
// If a validator account still exists and is carrying a
1984+
// has_pending_withdrawal flag from an earlier stake-bound
1985+
// force-removal that incorrectly enqueued a zero-amount
1986+
// withdrawal, clear the flag so the validator isn't permanently
1987+
// blocked from future deposit/withdrawal requests.
1988+
// Node: this is a defensive check and not strictly necessary.
1989+
if let Some(mut account) = state.get_account(&pending_withdrawal.pubkey).cloned()
1990+
&& account.has_pending_withdrawal
1991+
{
1992+
account.has_pending_withdrawal = false;
1993+
state.set_account(pending_withdrawal.pubkey, account);
1994+
}
19751995
continue;
19761996
}
19771997

0 commit comments

Comments
 (0)