Skip to content

Commit

Permalink
Merge branch '2.0' into infallible-output-id
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 27, 2023
2 parents dfa695f + 13cf460 commit 6fbaf93
Show file tree
Hide file tree
Showing 56 changed files with 647 additions and 241 deletions.
7 changes: 3 additions & 4 deletions .github/actions/private-tangle/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ runs:
- name: Wait for tangle 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:8050/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"
- 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:8088/health -- echo "Faucet is up"
15 changes: 10 additions & 5 deletions bindings/python/iota_sdk/types/node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StorageScoreParameters:
factor_data: Defines the factor to be used for data only fields.
offset_output_overhead: Defines the offset to be applied to all outputs for the overhead of handling them in storage.
offset_ed25519_block_issuer_key: Defines the offset to be used for block issuer feature public keys.
offset_staking_feature: Defines the offset to be used for staking feature.
offset_staking_feature: Defines the offset to be used for staking feature.
offset_delegation: Defines the offset to be used for delegation output.
"""
storage_cost: int
Expand Down Expand Up @@ -225,20 +225,23 @@ class ProtocolParameters:
storage_score_parameters: The storage score parameters used by given node/network.
work_score_parameters: Work Score Parameters lists the work score of each type, it is used to denote the computation costs of processing an object.
token_supply: Current supply of the base token. Plain string encoded number.
genesis_slot: Defines the slot of the genesis.
genesis_unix_timestamp: The genesis timestamp at which the slots start to count.
slot_duration_in_seconds: The duration of a slot, in seconds.
slots_per_epoch_exponent: The number of slots in an epoch expressed as an exponent of 2.
mana_parameters: ManaParameters defines the parameters used by mana calculation.
staking_unbonding_period: The unbonding period in epochs before an account can stop staking.
validation_blocks_per_slot: Validation Blocks Per Slot is the number of validation blocks that each validator should issue each slot.
punishment_epochs: The number of epochs worth of Mana that a node is punished with for each additional validation block it issues.
liveness_threshold: Determine if a block is eligible by evaluating issuing_time and commitments in its past cone to ATT and last_committed_slot respectively.
liveness_threshold_lower_bound: Used by tip-selection to determine if a block is eligible by evaluating issuing times.
liveness_threshold_upper_bound: Used by tip-selection to determine if a block is eligible by evaluating issuing times.
min_committable_age: Min_committable_age is the minimum age relative to the accepted tangle time slot index that a slot can be committed.
max_committable_age: Max_committable_age is the maximum age for a slot commitment to be included in a block relative to the slot index of the block issuing time.
epoch_nearing_threshold: Determine the slot that should trigger a new committee selection for the next and upcoming epoch.
congestion_control_parameters: Congestion Control Parameters defines the parameters used to calculate the Reference Mana Cost (RMC).
version_signaling_parameters: The version signaling parameters.
rewards_parameters: Rewards Parameters defines the parameters that are used to calculate Mana rewards.
target_committee_size: Defines the target size of the committee. If there's fewer candidates the actual committee size could be smaller in a given epoch.
"""
type: int
version: int
Expand All @@ -249,6 +252,7 @@ class ProtocolParameters:
token_supply: int = field(metadata=config(
encoder=str
))
genesis_slot: int
genesis_unix_timestamp: int = field(metadata=config(
encoder=str
))
Expand All @@ -260,7 +264,8 @@ class ProtocolParameters:
))
validation_blocks_per_slot: int
punishment_epochs: int
liveness_threshold: int
liveness_threshold_lower_bound: int
liveness_threshold_upper_bound: int
min_committable_age: int = field(metadata=config(
encoder=str
))
Expand All @@ -273,6 +278,7 @@ class ProtocolParameters:
congestion_control_parameters: CongestionControlParameters
version_signaling_parameters: VersionSignalingParameters
rewards_parameters: RewardsParameters
target_committee_size: int


@json
Expand All @@ -288,6 +294,7 @@ class ProtocolParametersResponse:
parameters: ProtocolParameters


@json
@dataclass
class NodeInfoBaseToken:
"""The base coin info.
Expand All @@ -298,13 +305,11 @@ class NodeInfoBaseToken:
unit: The primary unit of the token.
subunit: The name of the smallest possible denomination of the primary unit. subunit * 10^decimals = unit.
decimals: Number of decimals the primary unit is divisible up to.
use_metric_prefix: Whether to use metric prefixes for displaying unit.
"""
name: str
ticker_symbol: str
unit: str
decimals: int
use_metric_prefix: bool
subunit: Optional[str] = None


Expand Down
4 changes: 3 additions & 1 deletion sdk/src/client/api/block_builder/input_selection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ impl InputSelection {
Output::Basic(_) => {
// TODO https://github.com/iotaledger/iota-sdk/issues/1664
}
_ => panic!("unreachable: \"input_accounts\" only contains account outputs and implicit account (basic) outputs")
_ => panic!(
"unreachable: \"input_accounts\" only contains account outputs and implicit account (basic) outputs"
),
}
}
Output::Foundry(foundry_output) => {
Expand Down
1 change: 0 additions & 1 deletion sdk/src/client/secret/ledger_nano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ impl SecretManage for LedgerSecretManager {
) -> Result<Vec<ed25519::PublicKey>, Self::Error> {
// need an update on the ledger C lib
todo!();
//
// let options = options.into().unwrap_or_default();
// let bip32_account = account_index.harden().into();

Expand Down
10 changes: 6 additions & 4 deletions sdk/src/client/stronghold/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,12 @@ mod tests {
stronghold_adapter.clear_key().await;

// Address generation returns an error when the key is cleared.
assert!(stronghold_adapter
.generate_ed25519_addresses(IOTA_COIN_TYPE, 0, 0..1, None,)
.await
.is_err());
assert!(
stronghold_adapter
.generate_ed25519_addresses(IOTA_COIN_TYPE, 0, 0..1, None)
.await
.is_err()
);

stronghold_adapter.set_password("drowssap".to_owned()).await.unwrap();

Expand Down
3 changes: 3 additions & 0 deletions sdk/src/types/block/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ impl Address {
return Err(TransactionFailureReason::InvalidInputUnlock);
}
}
(Self::Restricted(restricted_address), _) => {
return restricted_address.address().unlock(unlock, context);
}
_ => return Err(TransactionFailureReason::InvalidInputUnlock),
}

Expand Down
11 changes: 10 additions & 1 deletion sdk/src/types/block/context_input/block_issuance_credit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

use derive_more::{Display, From};

use crate::types::block::output::AccountId;
use crate::types::block::{
output::AccountId,
protocol::{WorkScore, WorkScoreParameters},
};

/// A Block Issuance Credit (BIC) Context Input provides the VM with context for the value of
/// the BIC vector of a specific slot.
Expand All @@ -25,6 +28,12 @@ impl BlockIssuanceCreditContextInput {
}
}

impl WorkScore for BlockIssuanceCreditContextInput {
fn work_score(&self, params: WorkScoreParameters) -> u32 {
params.context_input()
}
}

#[cfg(feature = "serde")]
mod dto {
use serde::{Deserialize, Serialize};
Expand Down
11 changes: 10 additions & 1 deletion sdk/src/types/block/context_input/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

use derive_more::{Display, From};

use crate::types::block::slot::SlotCommitmentId;
use crate::types::block::{
protocol::{WorkScore, WorkScoreParameters},
slot::SlotCommitmentId,
};

/// A Commitment Context Input references a commitment to a certain slot.
#[derive(Clone, Copy, Display, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, From, packable::Packable)]
Expand All @@ -24,6 +27,12 @@ impl CommitmentContextInput {
}
}

impl WorkScore for CommitmentContextInput {
fn work_score(&self, params: WorkScoreParameters) -> u32 {
params.context_input()
}
}

#[cfg(feature = "serde")]
mod dto {
use serde::{Deserialize, Serialize};
Expand Down
35 changes: 24 additions & 11 deletions sdk/src/types/block/context_input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ pub use self::{
block_issuance_credit::BlockIssuanceCreditContextInput, commitment::CommitmentContextInput,
reward::RewardContextInput,
};
use crate::types::block::Error;
use crate::types::block::{
protocol::{WorkScore, WorkScoreParameters},
Error,
};

/// The maximum number of context inputs of a transaction.
pub const CONTEXT_INPUT_COUNT_MAX: u16 = 128;
Expand All @@ -39,16 +42,6 @@ pub enum ContextInput {
Reward(RewardContextInput),
}

impl core::fmt::Debug for ContextInput {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Commitment(input) => input.fmt(f),
Self::BlockIssuanceCredit(input) => input.fmt(f),
Self::Reward(input) => input.fmt(f),
}
}
}

impl ContextInput {
/// Returns the context input kind of a `ContextInput`.
pub fn kind(&self) -> u8 {
Expand All @@ -62,6 +55,26 @@ impl ContextInput {
crate::def_is_as_opt!(ContextInput: Commitment, BlockIssuanceCredit, Reward);
}

impl WorkScore for ContextInput {
fn work_score(&self, params: WorkScoreParameters) -> u32 {
match self {
Self::Commitment(commitment) => commitment.work_score(params),
Self::BlockIssuanceCredit(bic) => bic.work_score(params),
Self::Reward(reward) => reward.work_score(params),
}
}
}

impl core::fmt::Debug for ContextInput {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Commitment(input) => input.fmt(f),
Self::BlockIssuanceCredit(input) => input.fmt(f),
Self::Reward(input) => input.fmt(f),
}
}
}

#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
Expand Down
11 changes: 10 additions & 1 deletion sdk/src/types/block/context_input/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
use packable::bounded::BoundedU16;

use super::CONTEXT_INPUT_COUNT_RANGE;
use crate::types::block::Error;
use crate::types::block::{
protocol::{WorkScore, WorkScoreParameters},
Error,
};

pub(crate) type RewardContextInputIndex =
BoundedU16<{ *CONTEXT_INPUT_COUNT_RANGE.start() }, { *CONTEXT_INPUT_COUNT_RANGE.end() }>;
Expand All @@ -29,6 +32,12 @@ impl RewardContextInput {
}
}

impl WorkScore for RewardContextInput {
fn work_score(&self, params: WorkScoreParameters) -> u32 {
params.context_input()
}
}

impl core::fmt::Display for RewardContextInput {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "RewardContextInput({})", self.index())
Expand Down
13 changes: 12 additions & 1 deletion sdk/src/types/block/core/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use packable::Packable;
use crate::types::block::{
core::{parent::verify_parents_sets, BlockBody, Parents},
payload::{OptionalPayload, Payload},
protocol::ProtocolParameters,
protocol::{ProtocolParameters, WorkScore, WorkScoreParameters},
Error,
};

Expand Down Expand Up @@ -154,6 +154,17 @@ impl BasicBlockBody {
}
}

impl WorkScore for BasicBlockBody {
fn work_score(&self, params: WorkScoreParameters) -> u32 {
params.block()
+ self
.payload
.as_ref()
.map(|payload| payload.work_score(params))
.unwrap_or(0)
}
}

fn verify_basic_block_body<const VERIFY: bool>(
basic_block_body: &BasicBlockBody,
_: &ProtocolParameters,
Expand Down
10 changes: 9 additions & 1 deletion sdk/src/types/block/core/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::types::block::{
block_id::{BlockHash, BlockId},
core::{BasicBlockBody, ValidationBlockBody},
output::AccountId,
protocol::ProtocolParameters,
protocol::{ProtocolParameters, WorkScore, WorkScoreParameters},
signature::Signature,
slot::{SlotCommitmentId, SlotIndex},
BlockBody, Error,
Expand Down Expand Up @@ -110,6 +110,8 @@ impl BlockHeader {
}
}

impl WorkScore for BlockHeader {}

impl Packable for BlockHeader {
type UnpackError = Error;
type UnpackVisitor = ProtocolParameters;
Expand Down Expand Up @@ -291,6 +293,12 @@ impl Block {
}
}

impl WorkScore for Block {
fn work_score(&self, params: WorkScoreParameters) -> u32 {
self.header.work_score(params) + self.body.work_score(params) + self.signature.work_score(params)
}
}

impl Packable for Block {
type UnpackError = Error;
type UnpackVisitor = ProtocolParameters;
Expand Down
11 changes: 10 additions & 1 deletion sdk/src/types/block/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use self::{
validation::{ValidationBlockBody, ValidationBlockBodyBuilder},
};
use crate::types::block::{
protocol::{ProtocolParameters, ProtocolParametersHash},
protocol::{ProtocolParameters, ProtocolParametersHash, WorkScore, WorkScoreParameters},
Error,
};

Expand Down Expand Up @@ -102,6 +102,15 @@ impl BlockBody {
}
}

impl WorkScore for BlockBody {
fn work_score(&self, params: WorkScoreParameters) -> u32 {
match self {
Self::Basic(basic) => basic.work_score(params),
Self::Validation(validation) => validation.work_score(params),
}
}
}

#[cfg(feature = "serde")]
pub(crate) mod dto {
use alloc::format;
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/types/block/core/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use packable::Packable;

use crate::types::block::{
core::{parent::verify_parents_sets, BlockBody, Parents},
protocol::{ProtocolParameters, ProtocolParametersHash},
protocol::{ProtocolParameters, ProtocolParametersHash, WorkScore},
Error,
};

Expand Down Expand Up @@ -160,6 +160,8 @@ impl ValidationBlockBody {
}
}

impl WorkScore for ValidationBlockBody {}

fn verify_protocol_parameters_hash<const VERIFY: bool>(
hash: &ProtocolParametersHash,
params: &ProtocolParameters,
Expand Down
5 changes: 4 additions & 1 deletion sdk/src/types/block/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use crate::types::block::{
unlock_condition::UnlockConditionCount,
AccountId, AnchorId, ChainId, MetadataFeatureLength, NativeTokenCount, NftId, OutputIndex, TagFeatureLength,
},
payload::{ContextInputCount, InputCount, OutputCount, TagLength, TaggedDataLength},
payload::{
tagged_data::{TagLength, TaggedDataLength},
ContextInputCount, InputCount, OutputCount,
},
protocol::ProtocolParametersHash,
unlock::{UnlockCount, UnlockIndex, UnlocksCount},
};
Expand Down
Loading

0 comments on commit 6fbaf93

Please sign in to comment.