Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update private tangle setup #1106

Merged
merged 9 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions .github/actions/private-tangle/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
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

# 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
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
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"
6 changes: 1 addition & 5 deletions .github/actions/private-tangle/tear-down/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ 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
working-directory: iota-core/tools/docker-network
41 changes: 22 additions & 19 deletions .github/workflows/private-tangle-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/models/info/node-info-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct StatusResponse {
pub latest_finalized_slot: SlotIndex,
pub latest_accepted_block_slot: Option<SlotIndex>,
pub latest_confirmed_block_slot: Option<SlotIndex>,
pub pruning_slot: SlotIndex,
pub pruning_epoch: EpochIndex,
}

/// Returned in [`InfoResponse`].
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/feature/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, MetadataFeatureLength>>,
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/feature/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, TagFeatureLength>>,
}

Expand Down
1 change: 1 addition & 0 deletions sdk/src/types/block/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
#[getset(skip)]
/// A lookup table of epoch index diff to mana decay factor.
pub(crate) mana_decay_factors: BoxedSlicePrefix<u32, u16>,
Expand Down
38 changes: 34 additions & 4 deletions sdk/src/utils/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<Cow<'a, BoxedSlicePrefix<u8, B>>, D::Error>
where
Expand All @@ -174,7 +174,37 @@ pub mod cow_boxed_slice_prefix {
Box<[u8]>: FromHexPrefixed,
<B as TryFrom<usize>>::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 {
use alloc::vec::Vec;

use packable::{bounded::Bounded, prefix::BoxedSlicePrefix};
use serde::{de, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer};

pub fn serialize<S, T, B: Bounded>(value: &BoxedSlicePrefix<T, B>, serializer: S) -> Result<S::Ok, S::Error>
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<BoxedSlicePrefix<T, B>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de>,
<B as TryFrom<usize>>::Error: core::fmt::Display,
{
BoxedSlicePrefix::try_from(Vec::<T>::deserialize(deserializer)?.into_boxed_slice()).map_err(de::Error::custom)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/client/common/constants.rs
Original file line number Diff line number Diff line change
@@ -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";