From 42a6fd3054eb3d0d80750d35b7d8425e48af037b Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 13 Feb 2024 10:59:11 +0100 Subject: [PATCH] Remove NativeTokens::COUNT_MAX (#1984) * Remove NativeTokens::COUNT_MAX * Nit --- .../input_selection/requirement/amount.rs | 27 +++---------------- sdk/src/types/block/output/native_token.rs | 5 +--- sdk/src/types/block/semantic/mod.rs | 12 +-------- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs b/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs index db43ee7646..30fd2357e9 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs +++ b/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs @@ -11,7 +11,7 @@ use crate::{ input::INPUT_COUNT_MAX, output::{ unlock_condition::StorageDepositReturnUnlockCondition, AccountOutputBuilder, FoundryOutputBuilder, - MinimumOutputAmount, NativeTokens, NftOutputBuilder, Output, OutputId, StorageScoreParameters, TokenId, + MinimumOutputAmount, NftOutputBuilder, Output, OutputId, StorageScoreParameters, TokenId, }, slot::SlotIndex, }, @@ -159,16 +159,7 @@ impl AmountSelection { } if let Some(nt) = input.output.native_token() { - let mut selected_native_tokens = self.selected_native_tokens.clone(); - - selected_native_tokens.insert(*nt.token_id()); - // Don't select input if the tx would end up with more than allowed native tokens. - if selected_native_tokens.len() > NativeTokens::COUNT_MAX.into() { - continue; - } else { - // Update selected with NTs from this output. - self.selected_native_tokens = selected_native_tokens; - } + self.selected_native_tokens.insert(*nt.token_id()); } self.inputs_sum += input.output.amount(); @@ -341,19 +332,7 @@ impl InputSelection { return Ok(r); } - // If the available inputs have more NTs than are allowed in a single tx, we might not be able to find inputs - // without exceeding the threshold, so in this case we also try again with the outputs ordered the other way - // around. - let potentially_too_many_native_tokens = self - .available_inputs - .iter() - .filter_map(|i| i.output.native_token()) - .count() - > NativeTokens::COUNT_MAX.into(); - - if self.selected_inputs.len() + amount_selection.newly_selected_inputs.len() > INPUT_COUNT_MAX.into() - || potentially_too_many_native_tokens - { + if self.selected_inputs.len() + amount_selection.newly_selected_inputs.len() > INPUT_COUNT_MAX.into() { // Clear before trying with reversed ordering. log::debug!("Clearing amount selection"); amount_selection = AmountSelection::new(self)?; diff --git a/sdk/src/types/block/output/native_token.rs b/sdk/src/types/block/output/native_token.rs index 6e48df309b..20084d4c46 100644 --- a/sdk/src/types/block/output/native_token.rs +++ b/sdk/src/types/block/output/native_token.rs @@ -173,7 +173,7 @@ impl From for NativeTokensBuilder { } } -pub(crate) type NativeTokenCount = BoundedU8<0, { NativeTokens::COUNT_MAX }>; +pub(crate) type NativeTokenCount = BoundedU8<0, 255>; /// #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deref, Packable)] @@ -211,9 +211,6 @@ impl IntoIterator for NativeTokens { } impl NativeTokens { - /// Maximum number of different native tokens that can be referenced in one transaction. - pub const COUNT_MAX: u8 = 64; - /// Creates a new [`NativeTokens`] from a vec. pub fn from_vec(native_tokens: Vec) -> Result { let mut native_tokens = diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index ac30255a8e..0c76927a0b 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -14,7 +14,7 @@ pub use self::{error::TransactionFailureReason, state_transition::StateTransitio use crate::types::block::{ address::Address, context_input::{BlockIssuanceCreditContextInput, CommitmentContextInput, RewardContextInput}, - output::{AccountId, AnchorOutput, ChainId, FoundryId, NativeTokens, Output, OutputId, TokenId}, + output::{AccountId, AnchorOutput, ChainId, FoundryId, Output, OutputId, TokenId}, payload::signed_transaction::{Transaction, TransactionCapabilityFlag, TransactionSigningHash}, protocol::ProtocolParameters, unlock::Unlock, @@ -308,9 +308,6 @@ impl<'a> SemanticValidationContext<'a> { } } - // Validation of input native tokens. - let mut native_token_ids = self.input_native_tokens.keys().collect::>(); - // Validation of output native tokens. for (token_id, output_amount) in self.output_native_tokens.iter() { let input_amount = self.input_native_tokens.get(token_id).copied().unwrap_or_default(); @@ -322,13 +319,6 @@ impl<'a> SemanticValidationContext<'a> { { return Ok(Some(TransactionFailureReason::NativeTokenSumUnbalanced)); } - - native_token_ids.insert(token_id); - } - - if native_token_ids.len() > NativeTokens::COUNT_MAX as usize { - // TODO https://github.com/iotaledger/iota-sdk/issues/1954 - return Ok(Some(TransactionFailureReason::SemanticValidationFailed)); } // Validation of state transitions and destructions.