From 289889fdb01a22c1105ac9d7a32fd87327d773d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Thu, 31 Aug 2023 09:42:29 +0200 Subject: [PATCH 1/8] Update private tangle setup --- .../actions/private-tangle/setup/action.yml | 55 ++++++++----------- .../private-tangle/tear-down/action.yml | 8 +-- .github/workflows/private-tangle-tests.yml | 41 +++++++------- sdk/src/client/node_api/core/routes.rs | 27 ++++----- sdk/tests/client/common/constants.rs | 2 +- 5 files changed, 62 insertions(+), 71 deletions(-) diff --git a/.github/actions/private-tangle/setup/action.yml b/.github/actions/private-tangle/setup/action.yml index 5061735206..6383c08f47 100644 --- a/.github/actions/private-tangle/setup/action.yml +++ b/.github/actions/private-tangle/setup/action.yml @@ -1,47 +1,36 @@ -name: 'private-tangle-setup' -description: 'Setup a private tangle' +name: "private-tangle-setup" +description: "Setup a private tangle" runs: using: "composite" steps: - name: Clone private tangle files uses: actions/checkout@v3 with: - repository: iotaledger/hornet - path: hornet + repository: iotaledger/iota-core + path: iota-core + + - name: Prepare files for start and stop + shell: bash + run: | + echo "docker compose down -v" >> cleanup.sh + echo "rm *.snapshot" >> cleanup.sh + chmod +x cleanup.sh + + 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 + working-directory: iota-core/tools/docker-network - name: Setup private tangle shell: bash run: | - # TODO: use next lines when a working hornet release is published - # # Download the private_tangle setup from the hornet repo. - # mkdir private_tangle - # cd private_tangle - # # Use the output of https://api.github.com/repos/iotaledger/hornet/releases/latest once there's a 2.0 Hornet release. - # DOWNLOAD_URL=$(curl "https://api.github.com/repos/iotaledger/hornet/releases" | jq -r '.[0].assets[] | select(.name | contains("private_tangle")) | .browser_download_url') - # echo "Downloading private tangle from $DOWNLOAD_URL" - # curl -L -o private_tangle.tar.gz $DOWNLOAD_URL - # tar -xf private_tangle.tar.gz - # TODO: remove next lines when a working hornet release is published - # Set protocol_parameters to the same values as in the shimmer network - jq '.tokenSupply="1813620509061365" | .rentStructure.vByteCost=100 | .bech32HRP="rms"' protocol_parameters.json > tmp.json && mv tmp.json protocol_parameters.json - jq --color-output . protocol_parameters.json - - # Reduce milestone interval to 1 second - yq eval '.services.inx-coordinator.command += "--coordinator.interval=1s"' docker-compose.yml > tmp.yml && mv tmp.yml docker-compose.yml - jq --color-output . config_private_tangle.json # Start Tangle - sudo ./cleanup.sh - sudo ./bootstrap.sh - sudo ./run.sh -d --quiet-pull - working-directory: hornet/private_tangle + sudo ./run.sh + working-directory: iota-core/tools/docker-network - name: Wait for tangle to start shell: bash - run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- -t 60 http://localhost:14265/health -- echo "Tangle is up" - env: - WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3 - - name: Wait for faucet to start - shell: bash - run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- -t 60 http://localhost:8091/api/info -- echo "Faucet is up" - env: - WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3 + 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" diff --git a/.github/actions/private-tangle/tear-down/action.yml b/.github/actions/private-tangle/tear-down/action.yml index cf46081319..3598506ce9 100644 --- a/.github/actions/private-tangle/tear-down/action.yml +++ b/.github/actions/private-tangle/tear-down/action.yml @@ -6,9 +6,7 @@ runs: - name: Tear down private tangle shell: bash run: | - # TODO: use next line when a working hornet release is published - #cd private_tangle - - # TODO: remove next line when a working hornet release is published sudo ./cleanup.sh - working-directory: hornet/private_tangle + # sudo docker compose kill + # sudo docker compose down + working-directory: iota-core/tools/docker-network diff --git a/.github/workflows/private-tangle-tests.yml b/.github/workflows/private-tangle-tests.yml index 726307049f..0c042fb369 100644 --- a/.github/workflows/private-tangle-tests.yml +++ b/.github/workflows/private-tangle-tests.yml @@ -42,29 +42,32 @@ jobs: steps: - uses: actions/checkout@v3 - # - name: Install toolchain - # uses: dtolnay/rust-toolchain@stable + - name: Install toolchain + uses: dtolnay/rust-toolchain@stable - # - name: Install required packages - # run: | - # sudo apt-get update - # sudo apt-get install libudev-dev libusb-1.0-0-dev + - name: Install required packages + run: | + sudo apt-get update + sudo apt-get install libudev-dev libusb-1.0-0-dev - # - name: Install Nextest - # uses: taiki-e/install-action@nextest + - name: Install Nextest + uses: taiki-e/install-action@nextest - # - name: Cache dependencies - # uses: Swatinem/rust-cache@v2 + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 - # - name: Start private tangle - # uses: "./.github/actions/private-tangle/setup" + - name: Start private tangle + uses: "./.github/actions/private-tangle/setup" - # - name: Start ledger nano - # uses: "./.github/actions/ledger-nano" + - name: Start ledger nano + uses: "./.github/actions/ledger-nano" - # - name: Run tests - # run: cargo nextest run --tests --all-features --run-ignored ignored-only --profile ci --cargo-profile ci -p iota-sdk -p iota-sdk-bindings-core + - name: Run nodeinfo test + run: | + cargo nextest run test_get_info --all-features --run-ignored ignored-only --profile ci --cargo-profile ci -p iota-sdk -p iota-sdk-bindings-core --no-capture + # TODO: change in the future to run all tests and not only test_get_info + # cargo nextest run --tests --all-features --run-ignored ignored-only --profile ci --cargo-profile ci -p iota-sdk -p iota-sdk-bindings-core - # - name: Tear down private tangle - # if: always() - # uses: "./.github/actions/private-tangle/tear-down" + - name: Tear down private tangle + if: always() + uses: "./.github/actions/private-tangle/tear-down" diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 1962a482ce..03e62670b3 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -432,19 +432,20 @@ impl Client { } url.set_path(INFO_PATH); - let resp: InfoResponse = - crate::client::node_manager::http_client::HttpClient::new(DEFAULT_USER_AGENT.to_string()) - .get( - Node { - url, - auth, - disabled: false, - }, - DEFAULT_API_TIMEOUT, - ) - .await? - .into_json() - .await?; + let resp = crate::client::node_manager::http_client::HttpClient::new(DEFAULT_USER_AGENT.to_string()) + .get( + Node { + url, + auth, + disabled: false, + }, + DEFAULT_API_TIMEOUT, + ) + .await?; + // TODO: don't convert into_text(), but use into_json() directly, only for testing of the private tangle now + let node_info = resp.into_text().await?; + println!("info response {node_info}"); + let resp: InfoResponse = serde_json::from_str(&node_info)?; Ok(resp) } diff --git a/sdk/tests/client/common/constants.rs b/sdk/tests/client/common/constants.rs index 73f3acba5a..c55f5c5e6f 100644 --- a/sdk/tests/client/common/constants.rs +++ b/sdk/tests/client/common/constants.rs @@ -1,6 +1,6 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -pub static NODE_LOCAL: &str = "http://localhost:14265"; +pub static NODE_LOCAL: &str = "http://localhost:8080"; pub static FAUCET_URL: &str = "http://localhost:8091/api/enqueue"; From 718a7bc7635266c9758e3235f3602d5710bc95cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Mon, 4 Sep 2023 11:39:14 +0200 Subject: [PATCH 2/8] pruning_slot -> pruning_epoch --- bindings/nodejs/lib/types/models/info/node-info-status.ts | 4 ++-- sdk/src/types/api/core/response.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/nodejs/lib/types/models/info/node-info-status.ts b/bindings/nodejs/lib/types/models/info/node-info-status.ts index 51f0854dd9..ee4d1ca608 100644 --- a/bindings/nodejs/lib/types/models/info/node-info-status.ts +++ b/bindings/nodejs/lib/types/models/info/node-info-status.ts @@ -42,7 +42,7 @@ export interface INodeInfoStatus { */ latestConfirmedBlockSlot?: string; /** - * The index of the slot before which the tangle history is pruned. + * The index of the epoch before which the tangle history is pruned. */ - pruningSlot: string; + pruningEpoch: string; } diff --git a/sdk/src/types/api/core/response.rs b/sdk/src/types/api/core/response.rs index 3d94c17c62..6d088605f4 100644 --- a/sdk/src/types/api/core/response.rs +++ b/sdk/src/types/api/core/response.rs @@ -66,7 +66,7 @@ pub struct StatusResponse { pub latest_finalized_slot: SlotIndex, pub latest_accepted_block_slot: Option, pub latest_confirmed_block_slot: Option, - pub pruning_slot: SlotIndex, + pub pruning_epoch: EpochIndex, } /// Returned in [`InfoResponse`]. From f5b348bac84b7cf05c9f22fad1ec085bd0f11b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Mon, 4 Sep 2023 13:04:32 +0200 Subject: [PATCH 3/8] boxed_slice_prefix_serde --- sdk/src/types/block/protocol.rs | 1 + sdk/src/utils/serde.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index df6813fc45..95f0f3aec2 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -55,6 +55,7 @@ pub struct ProtocolParameters { /// The scaling of `mana_generation_rate` expressed as an exponent of 2. pub(crate) mana_generation_rate_exponent: u8, #[packable(unpack_error_with = |_| Error::InvalidManaDecayFactors)] + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::boxed_slice_prefix_serde"))] #[getset(skip)] /// A lookup table of epoch index diff to mana decay factor. pub(crate) mana_decay_factors: BoxedSlicePrefix, diff --git a/sdk/src/utils/serde.rs b/sdk/src/utils/serde.rs index b6363fef80..a315f85824 100644 --- a/sdk/src/utils/serde.rs +++ b/sdk/src/utils/serde.rs @@ -178,6 +178,35 @@ pub mod cow_boxed_slice_prefix { } } +pub mod boxed_slice_prefix_serde { + + use alloc::vec::Vec; + + use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; + use serde::{de, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer}; + + pub fn serialize(value: &BoxedSlicePrefix, serializer: S) -> Result + where + S: Serializer, + T: Serialize, + { + let mut seq = serializer.serialize_seq(Some(value.len()))?; + for e in value.into_iter() { + seq.serialize_element(e)?; + } + seq.end() + } + + pub fn deserialize<'de, D, T, B: Bounded>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + T: Deserialize<'de>, + >::Error: core::fmt::Display, + { + BoxedSlicePrefix::try_from(Vec::::deserialize(deserializer)?.into_boxed_slice()).map_err(de::Error::custom) + } +} + #[cfg(feature = "client")] pub mod bip44 { use crypto::keys::bip44::Bip44; From 74a41a4965ba542930524edb1b11792c63237b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Mon, 4 Sep 2023 15:13:24 +0200 Subject: [PATCH 4/8] Revert --- sdk/src/client/node_api/core/routes.rs | 27 +++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 03e62670b3..1962a482ce 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -432,20 +432,19 @@ impl Client { } url.set_path(INFO_PATH); - let resp = crate::client::node_manager::http_client::HttpClient::new(DEFAULT_USER_AGENT.to_string()) - .get( - Node { - url, - auth, - disabled: false, - }, - DEFAULT_API_TIMEOUT, - ) - .await?; - // TODO: don't convert into_text(), but use into_json() directly, only for testing of the private tangle now - let node_info = resp.into_text().await?; - println!("info response {node_info}"); - let resp: InfoResponse = serde_json::from_str(&node_info)?; + let resp: InfoResponse = + crate::client::node_manager::http_client::HttpClient::new(DEFAULT_USER_AGENT.to_string()) + .get( + Node { + url, + auth, + disabled: false, + }, + DEFAULT_API_TIMEOUT, + ) + .await? + .into_json() + .await?; Ok(resp) } From ec3d31df1cf6092306120d85849bd7e071bea677 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Mon, 4 Sep 2023 20:19:29 +0200 Subject: [PATCH 5/8] Update sdk/src/utils/serde.rs Co-authored-by: Thibault Martinez --- sdk/src/utils/serde.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/src/utils/serde.rs b/sdk/src/utils/serde.rs index a315f85824..4e383b0b96 100644 --- a/sdk/src/utils/serde.rs +++ b/sdk/src/utils/serde.rs @@ -179,7 +179,6 @@ pub mod cow_boxed_slice_prefix { } pub mod boxed_slice_prefix_serde { - use alloc::vec::Vec; use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; From 1a01898d20d4668254ce615c085e5fedb1be961e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Mon, 4 Sep 2023 20:20:22 +0200 Subject: [PATCH 6/8] Remove commented part --- .github/actions/private-tangle/tear-down/action.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/actions/private-tangle/tear-down/action.yml b/.github/actions/private-tangle/tear-down/action.yml index 3598506ce9..cf3e7dc4c5 100644 --- a/.github/actions/private-tangle/tear-down/action.yml +++ b/.github/actions/private-tangle/tear-down/action.yml @@ -7,6 +7,4 @@ runs: shell: bash run: | sudo ./cleanup.sh - # sudo docker compose kill - # sudo docker compose down working-directory: iota-core/tools/docker-network From d0126d7566689425d4a56aff571932e5c41677d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Mon, 4 Sep 2023 20:27:49 +0200 Subject: [PATCH 7/8] Rename --- sdk/src/types/block/output/feature/metadata.rs | 4 ++-- sdk/src/types/block/output/feature/tag.rs | 4 ++-- sdk/src/types/block/protocol.rs | 2 +- sdk/src/utils/serde.rs | 12 +++++++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sdk/src/types/block/output/feature/metadata.rs b/sdk/src/types/block/output/feature/metadata.rs index 293257261f..aa768e0e9d 100644 --- a/sdk/src/types/block/output/feature/metadata.rs +++ b/sdk/src/types/block/output/feature/metadata.rs @@ -81,13 +81,13 @@ pub(crate) mod dto { use serde::{Deserialize, Serialize}; use super::*; - use crate::utils::serde::cow_boxed_slice_prefix; + use crate::utils::serde::cow_boxed_slice_prefix_hex_bytes; #[derive(Serialize, Deserialize)] struct MetadataFeatureDto<'a> { #[serde(rename = "type")] kind: u8, - #[serde(with = "cow_boxed_slice_prefix")] + #[serde(with = "cow_boxed_slice_prefix_hex_bytes")] data: Cow<'a, BoxedSlicePrefix>, } diff --git a/sdk/src/types/block/output/feature/tag.rs b/sdk/src/types/block/output/feature/tag.rs index f7b8cc2961..aa9ae7130f 100644 --- a/sdk/src/types/block/output/feature/tag.rs +++ b/sdk/src/types/block/output/feature/tag.rs @@ -73,13 +73,13 @@ pub(crate) mod dto { use serde::{Deserialize, Serialize}; use super::*; - use crate::utils::serde::cow_boxed_slice_prefix; + use crate::utils::serde::cow_boxed_slice_prefix_hex_bytes; #[derive(Serialize, Deserialize)] struct TagFeatureDto<'a> { #[serde(rename = "type")] kind: u8, - #[serde(with = "cow_boxed_slice_prefix")] + #[serde(with = "cow_boxed_slice_prefix_hex_bytes")] tag: Cow<'a, BoxedSlicePrefix>, } diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index 95f0f3aec2..5533921db2 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -55,7 +55,7 @@ pub struct ProtocolParameters { /// The scaling of `mana_generation_rate` expressed as an exponent of 2. pub(crate) mana_generation_rate_exponent: u8, #[packable(unpack_error_with = |_| Error::InvalidManaDecayFactors)] - #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::boxed_slice_prefix_serde"))] + #[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::boxed_slice_prefix"))] #[getset(skip)] /// A lookup table of epoch index diff to mana decay factor. pub(crate) mana_decay_factors: BoxedSlicePrefix, diff --git a/sdk/src/utils/serde.rs b/sdk/src/utils/serde.rs index 4e383b0b96..cb7de80138 100644 --- a/sdk/src/utils/serde.rs +++ b/sdk/src/utils/serde.rs @@ -131,7 +131,7 @@ pub mod string_prefix { } } -pub mod boxed_slice_prefix { +pub mod boxed_slice_prefix_hex_bytes { use alloc::boxed::Box; use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; @@ -158,14 +158,14 @@ pub mod boxed_slice_prefix { } } -pub mod cow_boxed_slice_prefix { +pub mod cow_boxed_slice_prefix_hex_bytes { use alloc::{borrow::Cow, boxed::Box}; use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; use prefix_hex::FromHexPrefixed; use serde::Deserializer; - pub use super::boxed_slice_prefix::serialize; + pub use super::boxed_slice_prefix_hex_bytes::serialize; pub fn deserialize<'de, 'a, D, B>(deserializer: D) -> Result>, D::Error> where @@ -174,11 +174,13 @@ pub mod cow_boxed_slice_prefix { Box<[u8]>: FromHexPrefixed, >::Error: core::fmt::Display, { - Ok(Cow::Owned(super::boxed_slice_prefix::deserialize(deserializer)?)) + Ok(Cow::Owned(super::boxed_slice_prefix_hex_bytes::deserialize( + deserializer, + )?)) } } -pub mod boxed_slice_prefix_serde { +pub mod boxed_slice_prefix { use alloc::vec::Vec; use packable::{bounded::Bounded, prefix::BoxedSlicePrefix}; From 63d9437fed2d4f9071bd0ce0bf7cb5b24da1b5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 5 Sep 2023 10:43:16 +0200 Subject: [PATCH 8/8] Add comment --- .github/actions/private-tangle/setup/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/private-tangle/setup/action.yml b/.github/actions/private-tangle/setup/action.yml index 6383c08f47..be937278b9 100644 --- a/.github/actions/private-tangle/setup/action.yml +++ b/.github/actions/private-tangle/setup/action.yml @@ -16,6 +16,7 @@ runs: echo "rm *.snapshot" >> cleanup.sh chmod +x cleanup.sh + # 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 working-directory: iota-core/tools/docker-network