Skip to content

Commit c3e9e93

Browse files
committed
feat(validations): guard "unstake-it-all" rule behind V2_1 guard
1 parent 4a84eff commit c3e9e93

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

node/src/actors/chain_manager/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5189,7 +5189,7 @@ mod tests {
51895189
// Unstake all for validator 2
51905190
process_unstake_transactions(
51915191
&mut stakes,
5192-
[unstake_txn_1.clone()],
5192+
[unstake_txn_1.clone()].iter(),
51935193
block_epoch,
51945194
10_000_000_000_000,
51955195
)
@@ -5254,7 +5254,7 @@ mod tests {
52545254
// Unstake all again for validator 2
52555255
process_unstake_transactions(
52565256
&mut stakes,
5257-
[unstake_txn_2],
5257+
[unstake_txn_2].iter(),
52585258
block_epoch,
52595259
10_000_000_000_000,
52605260
)

validations/src/validations.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,9 @@ pub fn validate_unstake_transaction<'a>(
14651465
min_stake_nanowits: u64,
14661466
unstake_delay: u64,
14671467
) -> Result<(u64, u32, Vec<&'a ValueTransferOutput>), anyhow::Error> {
1468-
if get_protocol_version(Some(epoch)) <= ProtocolVersion::V1_8 {
1468+
let protocol_version = get_protocol_version(Some(epoch));
1469+
1470+
if protocol_version <= ProtocolVersion::V1_8 {
14691471
return Err(TransactionError::NoUnstakeTransactionsAllowed.into());
14701472
}
14711473

@@ -1514,10 +1516,11 @@ pub fn validate_unstake_transaction<'a>(
15141516
.into());
15151517
}
15161518
};
1517-
1519+
1520+
// Introduced in V2_1:
15181521
// Apply a protocol-level "rule of convenience", where an amount to unstake of u64::MAX actually
15191522
// means "unstake all my stake".
1520-
if amount_to_unstake == u64::MAX {
1523+
if protocol_version >= ProtocolVersion::V2_1 && amount_to_unstake == u64::MAX {
15211524
amount_to_unstake = staked_amount;
15221525
}
15231526

0 commit comments

Comments
 (0)