Skip to content

Commit

Permalink
Add and use Epoch- and SlotIndex (#1347)
Browse files Browse the repository at this point in the history
* Add and use Epoch- and SlotIndex

* Change more fields

* Fix

* Change more things, that aren't actually an Epoch- or SlotIndex
  • Loading branch information
Thoralf-M authored Sep 29, 2023
1 parent cb0659f commit 61a0e83
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
2 changes: 2 additions & 0 deletions bindings/python/iota_sdk/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from dataclasses_json import DataClassJsonMixin, dataclass_json, LetterCase, Undefined

HexStr = NewType("HexStr", str)
EpochIndex = NewType("EpochIndex", int)
SlotIndex = NewType("SlotIndex", int)


def json(cls):
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/iota_sdk/types/essence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dataclasses import dataclass, field

from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import HexStr, json, SlotIndex
from iota_sdk.types.mana import ManaAllotment
# TODO: Add missing output types in #1174
# pylint: disable=no-name-in-module
Expand Down Expand Up @@ -54,11 +54,11 @@ class RegularTransactionEssence(TransactionEssence):
payload: An optional tagged data payload
"""
network_id: str
# TODO: Replace with a proper SlotIndex type
creation_slot: HexStr
creation_slot: SlotIndex
inputs: List[UtxoInput]
inputs_commitment: HexStr
outputs: List[Union[BasicOutput, AccountOutput, FoundryOutput, NftOutput, DelegationOutput]]
outputs: List[Union[BasicOutput, AccountOutput,
FoundryOutput, NftOutput, DelegationOutput]]
context_inputs: Optional[List[Union[CommitmentContextInput,
BlockIssuanceCreditContextInput, RewardContextInput]]] = None
allotments: Optional[List[ManaAllotment]] = None
Expand Down
11 changes: 4 additions & 7 deletions bindings/python/iota_sdk/types/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass, field

from iota_sdk.types.address import Ed25519Address, AccountAddress, NFTAddress
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import EpochIndex, HexStr, json, SlotIndex


class FeatureType(IntEnum):
Expand Down Expand Up @@ -97,8 +97,7 @@ class BlockIssuer(Feature):
expiry_slot: The slot index at which the Block Issuer Feature expires and can be removed.
public_keys: The Block Issuer Keys.
"""
# TODO Replace with a proper SlotIndex type
expiry_slot: str
expiry_slot: SlotIndex
# TODO Replace with a list of PublicKey types
public_keys: List[HexStr]
type: int = field(
Expand All @@ -119,10 +118,8 @@ class StakingFeature(Feature):
"""
staked_amount: str
fixed_cost: str
# TODO Replace with an EpochIndex type
start_epoch: HexStr
# TODO Replace with an EpochIndex type
end_epoch: HexStr
start_epoch: EpochIndex
end_epoch: EpochIndex
type: int = field(
default_factory=lambda: int(
FeatureType.Staking),
Expand Down
22 changes: 8 additions & 14 deletions bindings/python/iota_sdk/types/node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import List, Optional
from iota_sdk.types.common import HexStr, json
from iota_sdk.types.common import EpochIndex, HexStr, json, SlotIndex


@json
Expand All @@ -22,22 +22,18 @@ class NodeInfoStatus:
latest_finalized_slot: The index of the latest finalized slot.
latest_accepted_block_slot: The slot index of the latest accepted block.
latest_confirmed_block_slot: The slot index of the latest confirmed block.
pruning_epoch: The index of the slot before which the tangle history is pruned.
pruning_epoch: The index of the epoch before which the tangle history is pruned.
"""
is_healthy: bool
accepted_tangle_time: str
relative_accepted_tangle_time: str
confirmed_tangle_time: str
relative_confirmed_tangle_time: str
latest_commitment_id: HexStr
# TODO Replace with a proper SlotIndex type
latest_finalized_slot: str
# TODO Replace with a proper SlotIndex type
latest_accepted_block_slot: str
# TODO Replace with a proper SlotIndex type
latest_confirmed_block_slot: str
# TODO Replace with a proper SlotIndex type
pruning_epoch: str
latest_finalized_slot: SlotIndex
latest_accepted_block_slot: SlotIndex
latest_confirmed_block_slot: SlotIndex
pruning_epoch: EpochIndex


@json
Expand Down Expand Up @@ -217,11 +213,9 @@ class ProtocolParameters:
staking_unbonding_period: str
validation_blocks_per_slot: int
punishment_epochs: str
staking_unbonding_period: str
liveness_threshold: str
min_committable_age: str
max_committable_age: str
# TODO Replace with a proper SlotIndex type
epoch_nearing_threshold: str
congestion_control_parameters: CongestionControlParameters
version_signaling: VersionSignaling
Expand All @@ -236,7 +230,7 @@ class ProtocolParametersResponse:
start_epoch: The start epoch of the set of protocol parameters.
parameters: The protocol parameters.
"""
start_epoch: str
start_epoch: EpochIndex
parameters: ProtocolParameters


Expand All @@ -255,9 +249,9 @@ class NodeInfoBaseToken:
name: str
ticker_symbol: str
unit: str
subunit: Optional[str] = None
decimals: int
use_metric_prefix: bool
subunit: Optional[str] = None


@json
Expand Down
37 changes: 21 additions & 16 deletions sdk/src/types/block/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use packable::{prefix::StringPrefix, Packable, PackableExt};
use super::{
address::Hrp,
mana::{ManaStructure, RewardsParameters},
slot::{EpochIndex, SlotIndex},
slot::SlotIndex,
};
use crate::types::block::{helper::network_name_to_id, output::RentStructure, ConvertTo, Error, PROTOCOL_VERSION};

Expand Down Expand Up @@ -55,23 +55,28 @@ pub struct ProtocolParameters {
#[getset(skip)]
pub(crate) mana_structure: ManaStructure,
/// The unbonding period in epochs before an account can stop staking.
pub(crate) staking_unbonding_period: EpochIndex,
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub(crate) staking_unbonding_period: u64,
/// The number of validation blocks that each validator should issue each slot.
pub(crate) validation_blocks_per_slot: u16,
/// The number of epochs worth of Mana that a node is punished with for each additional validation block it issues.
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub(crate) punishment_epochs: u64,
/// The slot index used by tip-selection to determine if a block is eligible by evaluating issuing times
/// and commitments in its past-cone against accepted tangle time and last committed slot respectively.
pub(crate) liveness_threshold: SlotIndex,
/// Liveness Threshold is used by tip-selection to determine if a block is eligible by evaluating issuingTimes and
/// commitments in its past-cone to Accepted Tangle Time and lastCommittedSlot respectively.
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub(crate) liveness_threshold: u64,
/// Minimum age relative to the accepted tangle time slot index that a slot can be committed.
pub(crate) min_committable_age: SlotIndex,
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub(crate) min_committable_age: u64,
/// Maximum age for a slot commitment to be included in a block relative to the slot index of the block issuing
/// time.
pub(crate) max_committable_age: SlotIndex,
/// The slot index used by the epoch orchestrator to detect the slot that should trigger a new
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub(crate) max_committable_age: u64,
/// Epoch Nearing Threshold is used by the epoch orchestrator to detect the slot that should trigger a new
/// committee selection for the next and upcoming epoch.
pub(crate) epoch_nearing_threshold: SlotIndex,
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub(crate) epoch_nearing_threshold: u64,
/// Parameters used to calculate the Reference Mana Cost (RMC).
pub(crate) congestion_control_parameters: CongestionControlParameters,
/// Defines the parameters used to signal a protocol parameters upgrade.
Expand Down Expand Up @@ -100,15 +105,15 @@ impl Default for ProtocolParameters {
token_supply: 1_813_620_509_061_365,
genesis_unix_timestamp: 1582328545,
slot_duration_in_seconds: 10,
epoch_nearing_threshold: 20.into(),
epoch_nearing_threshold: 20,
slots_per_epoch_exponent: Default::default(),
mana_structure: Default::default(),
staking_unbonding_period: 10.into(),
staking_unbonding_period: 10,
validation_blocks_per_slot: 10,
punishment_epochs: 9,
liveness_threshold: 5.into(),
min_committable_age: 10.into(),
max_committable_age: 20.into(),
liveness_threshold: 5,
min_committable_age: 10,
max_committable_age: 20,
congestion_control_parameters: Default::default(),
version_signaling: Default::default(),
rewards_parameters: Default::default(),
Expand All @@ -127,7 +132,7 @@ impl ProtocolParameters {
token_supply: u64,
genesis_unix_timestamp: u64,
slot_duration_in_seconds: u8,
epoch_nearing_threshold: impl Into<SlotIndex>,
epoch_nearing_threshold: u64,
) -> Result<Self, Error> {
Ok(Self {
version,
Expand All @@ -137,7 +142,7 @@ impl ProtocolParameters {
token_supply,
genesis_unix_timestamp,
slot_duration_in_seconds,
epoch_nearing_threshold: epoch_nearing_threshold.into(),
epoch_nearing_threshold,
..Default::default()
})
}
Expand Down

0 comments on commit 61a0e83

Please sign in to comment.