Skip to content

Commit

Permalink
Fix staking amount (#2238)
Browse files Browse the repository at this point in the history
Co-authored-by: Thibault Martinez <thibault@iota.org>
  • Loading branch information
Thoralf-M and thibault-martinez authored Apr 29, 2024
1 parent e5e80d3 commit 1a231ee
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ impl TransactionBuilder {
.cloned()
.collect::<Vec<_>>();

let mut new_amount = None;

if let Some(change) = self.transitions.as_ref().and_then(|t| t.accounts.get(&account_id)) {
match change {
AccountChange::BeginStaking {
Expand All @@ -83,6 +85,7 @@ impl TransactionBuilder {
self.protocol_parameters
.past_bounded_slot(self.latest_slot_commitment_id),
);
new_amount = Some(*staked_amount);
features.push(
StakingFeature::new(
*staked_amount,
Expand All @@ -101,6 +104,7 @@ impl TransactionBuilder {
.protocol_parameters
.future_bounded_epoch(self.latest_slot_commitment_id);
let staking_feature = feature.as_staking();
new_amount = Some(staking_feature.staked_amount());
// Just extend the end epoch if it's still possible
if future_bounded_epoch <= staking_feature.end_epoch() {
*feature = StakingFeature::new(
Expand Down Expand Up @@ -162,11 +166,14 @@ impl TransactionBuilder {
}

let mut builder = AccountOutputBuilder::from(input)
.with_minimum_amount(self.protocol_parameters.storage_score_parameters())
.with_mana(0)
.with_account_id(account_id)
.with_foundry_counter(u32::max(highest_foundry_serial_number, input.foundry_counter()))
.with_features(features);
match new_amount {
Some(amount) => builder = builder.with_amount(amount),
None => builder = builder.with_minimum_amount(self.protocol_parameters.storage_score_parameters()),
}

// Block issuers cannot move their mana elsewhere.
if input.is_block_issuer() {
Expand Down

0 comments on commit 1a231ee

Please sign in to comment.