Skip to content

Commit

Permalink
Merge branch '2.0' into python-fix-union-deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Sep 27, 2023
2 parents 9877bca + 1e954c4 commit 07c8b3c
Show file tree
Hide file tree
Showing 21 changed files with 324 additions and 170 deletions.
13 changes: 5 additions & 8 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,11 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
.await?;
Response::CustomJson(data)
}
ClientMethod::BlockId { block } => Response::BlockId(
client
.block_id(&BlockWrapper::try_from_dto_with_params(
block,
client.get_protocol_parameters().await?,
)?)
.await?,
),
ClientMethod::BlockId { block } => {
let protocol_parameters = client.get_protocol_parameters().await?;
let block = BlockWrapper::try_from_dto_with_params(block, &protocol_parameters)?;
Response::BlockId(block.id(&protocol_parameters))
}
};
Ok(response)
}
2 changes: 1 addition & 1 deletion bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
block,
protocol_parameters,
} => {
let block = BlockWrapper::try_from_dto_with_params(block, protocol_parameters.clone())?;
let block = BlockWrapper::try_from_dto_with_params(block, &protocol_parameters)?;
Response::BlockId(block.id(&protocol_parameters))
}
UtilsMethod::TransactionId { payload } => {
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class Client {
/**
* Get the token supply.
*/
async getTokenSupply(): Promise<string> {
async getTokenSupply(): Promise<u64> {
return (await this.getProtocolParameters()).tokenSupply;
}

Expand Down
119 changes: 73 additions & 46 deletions bindings/nodejs/lib/types/models/info/node-info-protocol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { u64 } from '../../utils';
import type { RentStructure } from '../rent-structure';

/**
Expand All @@ -21,6 +22,10 @@ export interface ProtocolInfo {
* The Protocol Parameters.
*/
export interface ProtocolParameters {
/**
* Set to value 0 to denote a IOTA 2.0 protocol parameter.
*/
type: number;
/**
* Protocol version used by the network.
*/
Expand All @@ -42,13 +47,13 @@ export interface ProtocolParameters {
*/
workScoreStructure: WorkScoreStructure;
/**
* Current supply of base token. Plain string encoded number.
* Current supply of base token.
*/
tokenSupply: string;
tokenSupply: u64;
/**
* The genesis timestamp at which the slots start to count.
*/
genesisUnixTimestamp: string;
genesisUnixTimestamp: u64;
/**
* The duration of a slot, in seconds.
*/
Expand All @@ -58,59 +63,43 @@ export interface ProtocolParameters {
*/
slotsPerEpochExponent: number;
/**
* The number of bits used to represent Mana expressed as an exponent of 2.
*/
manaBitsExponent: number;
/**
* The amount of potential Mana generated by 1 IOTA in 1 slot.
*/
manaGenerationRate: number;
/**
* The scaling of ManaGenerationRate expressed as an exponent of 2.
*/
manaGenerationRateExponent: number;
/**
* A lookup table of epoch index diff to mana decay factor (slice index 0 = 1 epoch).
*/
manaDecayFactors: number[];
/**
* The scaling of ManaDecayFactors expressed as an exponent of 2.
* The parameters used by mana calculation.
*/
manaDecayFactorsExponent: number;
manaStructure: ManaStructure;
/**
* An integer approximation of the sum of decay over epochs.
* The unbonding period in epochs before an account can stop staking.
*/
manaDecayFactorEpochsSum: number;
stakingUnbondingPeriod: u64;
/**
* The scaling of ManaDecayFactorEpochsSum expressed as an exponent of 2.
* The number of validation blocks that each validator should issue each slot.
*/
manaDecayFactorEpochsSumExponent: number;
validationBlocksPerSlot: number;
/**
* The unbonding period in epochs before an account can stop staking.
* The number of epochs worth of Mana that a node is punished with for each additional validation block it issues.
*/
stakingUnbondingPeriod: string;
punishmentEpochs: u64;
/**
* Determine if a block is eligible by evaluating issuingTime and commitments in its pastcone to ATT and lastCommittedSlot respectively.
*/
livenessThreshold: string;
livenessThreshold: u64;
/**
* MinCommittableAge is the minimum age relative to the accepted tangle time slot index that a slot can be committed.
*/
minCommittableAge: string;
minCommittableAge: u64;
/**
* MaxCommittableAge is the maximum age for a slot commitment to be included in a block relative to the slot index of the block issuing time.
*/
maxCommittableAge: string;
maxCommittableAge: u64;
/**
* Determine the slot that should trigger a new committee selection for the next and upcoming epoch.
*/
epochNearingThreshold: string;
epochNearingThreshold: u64;
/**
* Congestion Control Parameters defines the parameters used to calculate the Reference Mana Cost (RMC).
*/
congestionControlParameters: CongestionControlParameters;
/**
* The version signaling parameters.
* The parameters used by signaling protocol parameters upgrade.
*/
versionSignaling: VersionSignalingParameters;
}
Expand All @@ -120,9 +109,9 @@ export interface ProtocolParameters {
*/
export interface WorkScoreStructure {
/**
* DataKilobyte accounts for the network traffic per kilobyte.
* DataByte accounts for the network traffic per kibibyte.
*/
dataKilobyte: number;
dataByte: number;
/**
* Block accounts for work done to process a block in the node software.
*/
Expand Down Expand Up @@ -169,42 +158,80 @@ export interface WorkScoreStructure {
minStrongParentsThreshold: number;
}

/**
* Mana Structure defines the parameters used by mana calculation.
*/
export interface ManaStructure {
/**
* The number of bits used to represent Mana.
*/
bitsCount: number;
/**
* The amount of potential Mana generated by 1 IOTA in 1 slot.
*/
generationRate: number;
/**
* The scaling of ManaGenerationRate expressed as an exponent of 2.
*/
generationRateExponent: number;
/**
* A lookup table of epoch index diff to mana decay factor (slice index 0 = 1 epoch).
*/
decayFactors: number[];
/**
* The scaling of ManaDecayFactors expressed as an exponent of 2.
*/
decayFactorsExponent: number;
/**
* An integer approximation of the sum of decay over epochs.
*/
decayFactorEpochsSum: number;
/**
* The scaling of ManaDecayFactorEpochsSum expressed as an exponent of 2.
*/
decayFactorEpochsSumExponent: number;
}

/**
* Congestion Control Parameters defines the parameters used to calculate the Reference Mana Cost (RMC).
*/
export interface CongestionControlParameters {
/**
* RMCMin is the minimum value of the reference Mana cost.
* The minimum value of the reference Mana cost.
*/
rmcMin: string;
minReferenceManaCost: u64;
/**
* Increase is the increase step size of the reference Mana cost.
* The increase step size of the reference Mana cost.
*/
increase: string;
increase: u64;
/**
* Decrease is the decrease step size of the reference Mana cost.
* The decrease step size of the reference Mana cost.
*/
decrease: string;
decrease: u64;
/**
* IncreaseThreshold is the threshold for increasing the reference Mana cost.
* The threshold for increasing the reference Mana cost.
*/
increaseThreshold: number;
/**
* DecreaseThreshold is the threshold for decreasing the reference Mana cost.
* The threshold for decreasing the reference Mana cost.
*/
decreaseThreshold: number;
/**
* SchedulerRate is the rate at which the scheduler runs in workscore units per second.
* The rate at which the scheduler runs in workscore units per second.
*/
schedulerRate: number;
/**
* MinMana is the minimum amount of Mana that an account must have to have a block scheduled.
* The minimum amount of Mana that an account must have to have a block scheduled.
*/
minMana: string;
minMana: u64;
/**
* MaxBufferSize is the maximum size of the buffer.
* The maximum size of the buffer.
*/
maxBufferSize: number;
/**
* The maximum number of blocks in the validation buffer.
*/
maxValidationBufferSize: number;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions bindings/nodejs/lib/types/models/rent-structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ export interface RentStructure {
* Defines the factor to be used for staking feature.
*/
vByteFactorStakingFeature: number;
/**
* Defines the factor to be used for delegation output.
*/
vByteFactorDelegation: number;
}
4 changes: 2 additions & 2 deletions sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ pub struct ManaRewardsResponse {
pub struct CommitteeResponse {
/// The epoch index of the committee.
pub epoch_index: EpochIndex,
/// The total amount of delegated and staked IOTA tokens in the selected committee.
/// The total amount of delegated and staked IOTA coins in the selected committee.
#[serde(with = "string")]
pub total_stake: u64,
/// The total amount of staked IOTA tokens in the selected committee.
/// The total amount of staked IOTA coins in the selected committee.
#[serde(with = "string")]
pub total_validator_stake: u64,
/// The validators of the committee.
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/types/block/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub enum Error {
UnsupportedOutputKind(u8),
DuplicateOutputChain(ChainId),
InvalidField(&'static str),
NullDelegationValidatorId,
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -371,6 +372,7 @@ impl fmt::Display for Error {
Self::UnsupportedOutputKind(k) => write!(f, "unsupported output kind: {k}"),
Self::DuplicateOutputChain(chain_id) => write!(f, "duplicate output chain {chain_id}"),
Self::InvalidField(field) => write!(f, "invalid field: {field}"),
Self::NullDelegationValidatorId => write!(f, "null delegation validator ID"),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions sdk/src/types/block/mana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

mod allotment;
mod protocol;
mod rewards;
mod structure;

use alloc::{boxed::Box, collections::BTreeSet, vec::Vec};
use core::ops::RangeInclusive;
Expand All @@ -13,7 +14,7 @@ use packable::{bounded::BoundedU16, prefix::BoxedSlicePrefix, Packable};

#[cfg(feature = "serde")]
pub use self::allotment::dto::ManaAllotmentDto;
pub use self::{allotment::ManaAllotment, protocol::ManaStructure};
pub use self::{allotment::ManaAllotment, rewards::RewardsParameters, structure::ManaStructure};
use super::{output::AccountId, protocol::ProtocolParameters, Error};

pub(crate) type ManaAllotmentCount =
Expand Down
49 changes: 49 additions & 0 deletions sdk/src/types/block/mana/rewards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use getset::CopyGetters;
use packable::Packable;

use crate::types::block::{slot::EpochIndex, Error};

#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Packable, CopyGetters)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
#[packable(unpack_error = Error)]
#[getset(get_copy = "pub")]
pub struct RewardsParameters {
/// The number of validation blocks that should be issued by a selected validator per slot during its epoch duties.
validator_blocks_per_slot: u8,
/// Used for shift operation during calculation of profit margin.
profit_margin_exponent: u8,
/// The length of the bootstrapping phase in epochs.
bootstrapping_duration: EpochIndex,
/// The coefficient used for calculation of initial rewards.
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
mana_share_coefficient: u64,
/// The exponent used for calculation of the initial reward.
decay_balancing_constant_exponent: u8,
/// An integer approximation which is calculated using the `decay_balancing_constant_exponent`.
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
decay_balancing_constant: u64,
/// The exponent used for shifting operation during the pool rewards calculations.
pool_coefficient_exponent: u8,
}

impl Default for RewardsParameters {
fn default() -> Self {
// TODO: use actual values
Self {
validator_blocks_per_slot: Default::default(),
profit_margin_exponent: Default::default(),
bootstrapping_duration: Default::default(),
mana_share_coefficient: Default::default(),
decay_balancing_constant_exponent: Default::default(),
decay_balancing_constant: Default::default(),
pool_coefficient_exponent: Default::default(),
}
}
}
File renamed without changes.
11 changes: 1 addition & 10 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ pub(crate) type StateMetadataLength = BoundedU16<0, { AccountOutput::STATE_METAD
/// Describes an account in the ledger that can be controlled by the state and governance controllers.
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct AccountOutput {
// Amount of IOTA tokens held by the output.
// Amount of IOTA coins held by the output.
amount: u64,
mana: u64,
// Native tokens held by the output.
Expand Down Expand Up @@ -780,29 +780,20 @@ pub(crate) mod dto {
pub struct AccountOutputDto {
#[serde(rename = "type")]
pub kind: u8,
// Amount of IOTA tokens held by the output.
#[serde(with = "string")]
pub amount: u64,
#[serde(with = "string")]
pub mana: u64,
// Native tokens held by the output.
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub native_tokens: Vec<NativeToken>,
// Unique identifier of the account.
pub account_id: AccountId,
// A counter that must increase by 1 every time the account is state transitioned.
pub state_index: u32,
// Metadata that can only be changed by the state controller.
#[serde(skip_serializing_if = "<[_]>::is_empty", default, with = "prefix_hex_bytes")]
pub state_metadata: Box<[u8]>,
// A counter that denotes the number of foundries created by this account.
pub foundry_counter: u32,
//
pub unlock_conditions: Vec<UnlockConditionDto>,
//
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub features: Vec<Feature>,
//
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub immutable_features: Vec<Feature>,
}
Expand Down
Loading

0 comments on commit 07c8b3c

Please sign in to comment.