From 3e7e98aad9eb6e4b84eec7def28e5c9a99e44cd8 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 12 Feb 2024 21:54:04 +0100 Subject: [PATCH 1/2] Remove NativeTokens::COUNT_MAX --- .../input_selection/requirement/amount.rs | 25 +++---------------- sdk/src/types/block/output/native_token.rs | 5 +--- sdk/src/types/block/semantic/mod.rs | 12 +-------- 3 files changed, 6 insertions(+), 36 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..8099ece58a 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, }, @@ -162,13 +162,8 @@ impl AmountSelection { 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; - } + // Update selected with NTs from this output. + self.selected_native_tokens = selected_native_tokens; } self.inputs_sum += input.output.amount(); @@ -341,19 +336,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. From 2a58625a2c0aad52414e632d68ec5b4cd335b50a Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 13 Feb 2024 09:34:49 +0100 Subject: [PATCH 2/2] Nit --- .../api/block_builder/input_selection/requirement/amount.rs | 6 +----- 1 file changed, 1 insertion(+), 5 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 8099ece58a..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 @@ -159,11 +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()); - // 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();