From 010d70a083ba98b6c3f5469c09d72a3a247b5586 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Wed, 15 Nov 2023 09:37:46 +0100 Subject: [PATCH 1/4] Remove verify_output_amount_packable (#1618) --- sdk/src/types/block/output/account.rs | 7 ++----- sdk/src/types/block/output/anchor.rs | 7 ++----- sdk/src/types/block/output/basic.rs | 7 +++---- sdk/src/types/block/output/delegation.rs | 5 ++--- sdk/src/types/block/output/foundry.rs | 7 ++----- sdk/src/types/block/output/mod.rs | 10 ---------- sdk/src/types/block/output/nft.rs | 7 ++----- 7 files changed, 13 insertions(+), 37 deletions(-) diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 1a65c4f833..ddb2ec9501 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -16,9 +16,8 @@ use crate::types::block::{ output::{ feature::{verify_allowed_features, Feature, FeatureFlags, Features}, unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, - verify_output_amount_packable, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore, - StorageScoreParameters, + ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId, + StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters, }, payload::signed_transaction::TransactionCapabilityFlag, protocol::ProtocolParameters, @@ -555,8 +554,6 @@ impl Packable for AccountOutput { ) -> Result> { let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; - verify_output_amount_packable::(&amount, visitor).map_err(UnpackError::Packable)?; - let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?; diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index 3646ea4e32..60ae4bada5 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -18,9 +18,8 @@ use crate::types::block::{ output::{ feature::{verify_allowed_features, Feature, FeatureFlags, Features}, unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, - verify_output_amount_packable, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore, - StorageScoreParameters, + ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId, + StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters, }, payload::signed_transaction::TransactionCapabilityFlag, protocol::ProtocolParameters, @@ -622,8 +621,6 @@ impl Packable for AnchorOutput { ) -> Result> { let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; - verify_output_amount_packable::(&amount, visitor).map_err(UnpackError::Packable)?; - let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?; diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index 6290dbd9e4..4407b942d7 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -13,8 +13,8 @@ use crate::types::block::{ verify_allowed_unlock_conditions, AddressUnlockCondition, StorageDepositReturnUnlockCondition, UnlockCondition, UnlockConditionFlags, UnlockConditions, }, - verify_output_amount_packable, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, - OutputId, StorageScore, StorageScoreParameters, + MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId, StorageScore, + StorageScoreParameters, }, protocol::ProtocolParameters, semantic::{SemanticValidationContext, TransactionFailureReason}, @@ -252,7 +252,6 @@ impl From<&BasicOutput> for BasicOutputBuilder { #[packable(unpack_visitor = ProtocolParameters)] pub struct BasicOutput { /// Amount of IOTA coins to deposit with this output. - #[packable(verify_with = verify_output_amount_packable)] amount: u64, /// Amount of stored Mana held by this output. mana: u64, @@ -261,8 +260,8 @@ pub struct BasicOutput { /// Define how the output can be unlocked in a transaction. #[packable(verify_with = verify_unlock_conditions_packable)] unlock_conditions: UnlockConditions, - #[packable(verify_with = verify_features_packable)] /// Features of the output. + #[packable(verify_with = verify_features_packable)] features: Features, } diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index ad3c765150..b4683aa063 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -10,8 +10,8 @@ use crate::types::block::{ output::{ chain_id::ChainId, unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, - verify_output_amount_packable, MinimumOutputAmount, Output, OutputBuilderAmount, OutputId, - StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters, + MinimumOutputAmount, Output, OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, + StorageScore, StorageScoreParameters, }, protocol::ProtocolParameters, semantic::{SemanticValidationContext, TransactionFailureReason}, @@ -217,7 +217,6 @@ impl From<&DelegationOutput> for DelegationOutputBuilder { #[packable(unpack_visitor = ProtocolParameters)] pub struct DelegationOutput { /// Amount of IOTA coins to deposit with this output. - #[packable(verify_with = verify_output_amount_packable)] amount: u64, /// Amount of delegated IOTA coins. delegated_amount: u64, diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index da514eb580..cc4f9b59d9 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -18,9 +18,8 @@ use crate::types::block::{ account::AccountId, feature::{verify_allowed_features, Feature, FeatureFlags, Features}, unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions}, - verify_output_amount_packable, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, - OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore, - StorageScoreParameters, TokenId, TokenScheme, + ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, OutputId, + StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters, TokenId, TokenScheme, }, payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag}, protocol::ProtocolParameters, @@ -624,8 +623,6 @@ impl Packable for FoundryOutput { ) -> Result> { let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; - verify_output_amount_packable::(&amount, visitor).map_err(UnpackError::Packable)?; - let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?; let serial_number = u32::unpack::<_, VERIFY>(unpacker, &()).coerce()?; let token_scheme = TokenScheme::unpack::<_, VERIFY>(unpacker, &())?; diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index a44416d268..53095f9ee5 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -460,16 +460,6 @@ pub(crate) fn verify_output_amount(amount: u64, token_supply: u64) -> Result<(), verify_output_amount_supply(amount, token_supply) } -pub(crate) fn verify_output_amount_packable( - amount: &u64, - protocol_parameters: &ProtocolParameters, -) -> Result<(), Error> { - if VERIFY { - verify_output_amount(*amount, protocol_parameters.token_supply())?; - } - Ok(()) -} - /// A trait that is shared by all output types, which is used to calculate the minimum amount the output /// must contain to satisfy its storage cost. pub trait MinimumOutputAmount: StorageScore { diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 1a1656df4f..11b758d456 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -18,9 +18,8 @@ use crate::types::block::{ verify_allowed_unlock_conditions, AddressUnlockCondition, StorageDepositReturnUnlockCondition, UnlockCondition, UnlockConditionFlags, UnlockConditions, }, - verify_output_amount_packable, BasicOutputBuilder, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, - Output, OutputBuilderAmount, OutputId, StateTransitionError, StateTransitionVerifier, StorageScore, - StorageScoreParameters, + BasicOutputBuilder, ChainId, MinimumOutputAmount, NativeToken, NativeTokens, Output, OutputBuilderAmount, + OutputId, StateTransitionError, StateTransitionVerifier, StorageScore, StorageScoreParameters, }, payload::signed_transaction::TransactionCapabilityFlag, protocol::ProtocolParameters, @@ -541,8 +540,6 @@ impl Packable for NftOutput { ) -> Result> { let amount = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; - verify_output_amount_packable::(&amount, visitor).map_err(UnpackError::Packable)?; - let mana = u64::unpack::<_, VERIFY>(unpacker, &()).coerce()?; let native_tokens = NativeTokens::unpack::<_, VERIFY>(unpacker, &())?; From a557b9d07bcdbd32afed76b0729e768c7467edb4 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 16 Nov 2023 09:25:01 +0100 Subject: [PATCH 2/4] Add genesis_slot to ProtocolParameters (#1625) --- sdk/src/types/block/protocol.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index ffefe16550..4577a31b94 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -52,6 +52,8 @@ pub struct ProtocolParameters { /// TokenSupply defines the current token supply on the network. #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] pub(crate) token_supply: u64, + /// Defines the slot of the genesis. + pub(crate) genesis_slot: u32, /// Genesis timestamp at which the slots start to count. #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))] pub(crate) genesis_unix_timestamp: u64, @@ -106,6 +108,7 @@ impl Default for ProtocolParameters { storage_score_parameters: Default::default(), work_score_parameters: Default::default(), token_supply: 1_813_620_509_061_365, + genesis_slot: 0, genesis_unix_timestamp: 1582328545, slot_duration_in_seconds: 10, epoch_nearing_threshold: 20, From 1a2af398c6f9bcaa4064aee58b804021424f8b1c Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 16 Nov 2023 09:25:31 +0100 Subject: [PATCH 3/4] Harmonize macro usage (#1623) --- sdk/src/types/api/plugins/participation/types.rs | 4 ++-- sdk/src/types/block/macro.rs | 2 -- sdk/src/types/block/output/feature/mod.rs | 3 +-- sdk/src/types/block/output/unlock_condition/mod.rs | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sdk/src/types/api/plugins/participation/types.rs b/sdk/src/types/api/plugins/participation/types.rs index 88c9f35a84..cfab17c7c3 100644 --- a/sdk/src/types/api/plugins/participation/types.rs +++ b/sdk/src/types/api/plugins/participation/types.rs @@ -12,7 +12,7 @@ use getset::Getters; use hashbrown::HashMap; use packable::PackableExt; -use crate::types::{api::plugins::participation::error::Error, block::impl_id}; +use crate::types::api::plugins::participation::error::Error; /// Participation tag. pub const PARTICIPATION_TAG: &str = "PARTICIPATE"; @@ -51,7 +51,7 @@ pub struct ParticipationEvent { pub data: ParticipationEventData, } -impl_id!( +crate::impl_id!( /// A participation event id. pub ParticipationEventId { pub const LENGTH: usize = 32; diff --git a/sdk/src/types/block/macro.rs b/sdk/src/types/block/macro.rs index b7a5b6695a..74b74a6ec8 100644 --- a/sdk/src/types/block/macro.rs +++ b/sdk/src/types/block/macro.rs @@ -229,7 +229,6 @@ macro_rules! impl_id { )? }; } -pub(crate) use impl_id; /// Convenience macro to serialize types to string via serde. #[cfg(feature = "serde")] @@ -297,7 +296,6 @@ macro_rules! create_bitflags { } }; } -pub(crate) use create_bitflags; #[macro_export] macro_rules! impl_serde_typed_dto { diff --git a/sdk/src/types/block/output/feature/mod.rs b/sdk/src/types/block/output/feature/mod.rs index e3d0e49982..ef936e372b 100644 --- a/sdk/src/types/block/output/feature/mod.rs +++ b/sdk/src/types/block/output/feature/mod.rs @@ -29,7 +29,6 @@ pub use self::{ tag::TagFeature, }; use crate::types::block::{ - create_bitflags, output::{StorageScore, StorageScoreParameters}, Error, }; @@ -126,7 +125,7 @@ impl Feature { crate::def_is_as_opt!(Feature: Sender, Issuer, Metadata, Tag, BlockIssuer, Staking); } -create_bitflags!( +crate::create_bitflags!( /// A bitflags-based representation of the set of active [`Feature`]s. pub FeatureFlags, u16, diff --git a/sdk/src/types/block/output/unlock_condition/mod.rs b/sdk/src/types/block/output/unlock_condition/mod.rs index 6a6c9688f2..030fd5be67 100644 --- a/sdk/src/types/block/output/unlock_condition/mod.rs +++ b/sdk/src/types/block/output/unlock_condition/mod.rs @@ -32,7 +32,6 @@ pub use self::{ }; use crate::types::block::{ address::Address, - create_bitflags, output::{StorageScore, StorageScoreParameters}, protocol::ProtocolParameters, slot::SlotIndex, @@ -135,7 +134,7 @@ impl UnlockCondition { ); } -create_bitflags!( +crate::create_bitflags!( /// A bitflags-based representation of the set of active [`UnlockCondition`]s. pub UnlockConditionFlags, u16, From 967b45f8de2a0dfb01f83da5489c4bd2d9696279 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 16 Nov 2023 09:26:49 +0100 Subject: [PATCH 4/4] Fix private tangle action (#1617) --- .github/actions/private-tangle/setup/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/private-tangle/setup/action.yml b/.github/actions/private-tangle/setup/action.yml index 31d5797112..f0b7c4b08d 100644 --- a/.github/actions/private-tangle/setup/action.yml +++ b/.github/actions/private-tangle/setup/action.yml @@ -18,13 +18,13 @@ runs: # remove the last 5 lines and add docker compose with `-d` to run it in the background sed -i -n -e :a -e '1,5!{P;N;D;};N;ba' run.sh - echo "docker compose -f \$DOCKER_COMPOSE_FILE up -d" >> run.sh + echo "docker compose -f docker-compose.yml up -d" >> run.sh working-directory: iota-core/tools/docker-network # Copied from https://github.com/iotaledger/iota-core/blob/926bf11b5fb6dc46b25482770e0ccf1e048b97c9/.github/workflows/unit-test.yml#L16-L19 - uses: actions/setup-go@v4 with: - go-version-file: 'iota-core/go.mod' + go-version-file: "iota-core/go.mod" cache: false - name: Setup private tangle @@ -40,5 +40,5 @@ runs: run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8080/health -- echo "Tangle is up" # TODO enable, maybe need another URL # - name: Wait for faucet to start - # shell: bash - # run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8081/api/info -- echo "Faucet is up" + # shell: bash + # run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8081/api/info -- echo "Faucet is up"