Skip to content

Commit

Permalink
mana cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jan 15, 2024
1 parent 4697561 commit 877183e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 30 deletions.
4 changes: 3 additions & 1 deletion sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ impl Output {
protocol_parameters.generate_mana_with_decay(generation_amount, creation_index, target_index)?;
let stored_mana = protocol_parameters.mana_with_decay(mana, creation_index, target_index)?;

Ok(potential_mana + stored_mana)
Ok(potential_mana
.checked_add(stored_mana)
.ok_or(Error::ConsumedManaOverflow)?)
}

/// Returns the unlock conditions of an [`Output`], if any.
Expand Down
35 changes: 6 additions & 29 deletions sdk/src/types/block/semantic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ pub use self::{
};
use crate::types::block::{
address::Address,
output::{
AccountId, AnchorOutput, ChainId, FoundryId, MinimumOutputAmount, NativeTokens, Output, OutputId, TokenId,
},
output::{AccountId, AnchorOutput, ChainId, FoundryId, NativeTokens, Output, OutputId, TokenId},
payload::signed_transaction::{Transaction, TransactionCapabilityFlag, TransactionSigningHash},
protocol::ProtocolParameters,
unlock::Unlock,
Expand Down Expand Up @@ -162,34 +160,13 @@ impl<'a> SemanticValidationContext<'a> {
.checked_add(amount)
.ok_or(Error::ConsumedAmountOverflow)?;

let potential_mana = {
// Deposit amount doesn't generate mana
let min_deposit = consumed_output.minimum_amount(self.protocol_parameters.storage_score_parameters());
let generation_amount = consumed_output.amount().saturating_sub(min_deposit);

self.protocol_parameters.generate_mana_with_decay(
generation_amount,
output_id.transaction_id().slot_index(),
self.transaction.creation_slot(),
)
}?;

// Add potential mana
self.input_mana = self
.input_mana
.checked_add(potential_mana)
.ok_or(Error::ConsumedManaOverflow)?;

let stored_mana = self.protocol_parameters.mana_with_decay(
mana,
output_id.transaction_id().slot_index(),
self.transaction.creation_slot(),
)?;

// Add stored mana
self.input_mana = self
.input_mana
.checked_add(stored_mana)
.checked_add(consumed_output.all_mana(
&self.protocol_parameters,
output_id.transaction_id().slot_index(),
self.transaction.creation_slot(),
)?)
.ok_or(Error::ConsumedManaOverflow)?;

// TODO: Add reward mana https://github.com/iotaledger/iota-sdk/issues/1310
Expand Down

0 comments on commit 877183e

Please sign in to comment.