From aa0d554af0002b16c3ac0b4946f68b537c1ba3a3 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Mon, 11 Sep 2023 11:42:59 +0200 Subject: [PATCH 1/6] Python: BlockIssuer feature (#1181) * BlockIssuer feature * added todos --------- Co-authored-by: Thibault Martinez --- bindings/python/iota_sdk/types/feature.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index 52be6bbe97..043c1faf2f 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -17,11 +17,13 @@ class FeatureType(IntEnum): Issuer (1): The issuer feature. Metadata (2): The metadata feature. Tag (3): The tag feature. + BlockIssuer (4): The block issuer feature. """ Sender = 0 Issuer = 1 Metadata = 2 Tag = 3 + BlockIssuer = 4 @json @@ -83,3 +85,18 @@ class TagFeature(Feature): """ tag: HexStr type: int = field(default_factory=lambda: int(FeatureType.Tag), init=False) + + +@json +@dataclass +class BlockIssuer(Feature): + """Block issuer feature. + Attributes: + 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 + # TODO Replace with a list of PublicKey types + public_keys: List[HexStr] + type: int = field(default_factory=lambda: int(FeatureType.BlockIssuer), init=False) From e0af5a582733cfee1e1005145cab8f6fbf260dc3 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 11 Sep 2023 14:22:13 +0200 Subject: [PATCH 2/6] Add validationBlocksPerSlot to ProtocolParameters (#1189) * Add validationBlocksPerSlot to ProtocolParameters * Fix block ID test --- sdk/src/types/block/protocol.rs | 3 +++ sdk/tests/types/block_id.rs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sdk/src/types/block/protocol.rs b/sdk/src/types/block/protocol.rs index fa16ad6fe7..7c1a5cbfc3 100644 --- a/sdk/src/types/block/protocol.rs +++ b/sdk/src/types/block/protocol.rs @@ -53,6 +53,8 @@ pub struct ProtocolParameters { pub(crate) mana_structure: ManaStructure, /// The unbonding period in epochs before an account can stop staking. pub(crate) staking_unbonding_period: EpochIndex, + /// The number of validation blocks that each validator should issue each slot. + pub(crate) validation_blocks_per_slot: u16, /// 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, @@ -93,6 +95,7 @@ impl Default for ProtocolParameters { slots_per_epoch_exponent: Default::default(), mana_structure: Default::default(), staking_unbonding_period: 10.into(), + validation_blocks_per_slot: 10, liveness_threshold: 5.into(), min_committable_age: 10.into(), max_committable_age: 20.into(), diff --git a/sdk/tests/types/block_id.rs b/sdk/tests/types/block_id.rs index 5a380bba05..c4e9ef024a 100644 --- a/sdk/tests/types/block_id.rs +++ b/sdk/tests/types/block_id.rs @@ -102,11 +102,11 @@ fn compute() { // TODO: Independently verify this value assert_eq!( block_id.to_string(), - "0x5e3d8befccbd36860a589cf9427efa108bcc781f630ebfdf6f57cef7eed8b5bb0b00000000000000" + "0x7ac622307277e700e4161d805d22dfb03f89904657a6353f985bd6e78ed267550b00000000000000" ); assert_eq!( block_id.hash().to_string(), - "0x5e3d8befccbd36860a589cf9427efa108bcc781f630ebfdf6f57cef7eed8b5bb" + "0x7ac622307277e700e4161d805d22dfb03f89904657a6353f985bd6e78ed26755" ); assert_eq!(block_id.slot_index(), slot_index); } From e39e3bc3dcfc04d0a6073182e5bc0af0339f4a68 Mon Sep 17 00:00:00 2001 From: Thoralf-M <46689931+Thoralf-M@users.noreply.github.com> Date: Mon, 11 Sep 2023 14:23:27 +0200 Subject: [PATCH 3/6] Python: add BlockIssuanceCreditContextInput (#1193) * Python: add BlockIssuanceCreditInput, fixes * Add ContextInput base class --- bindings/python/iota_sdk/__init__.py | 1 + .../python/iota_sdk/client/_high_level_api.py | 1 + .../python/iota_sdk/types/context_input.py | 34 +++++++++++++++++++ bindings/python/iota_sdk/types/feature.py | 6 +++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 bindings/python/iota_sdk/types/context_input.py diff --git a/bindings/python/iota_sdk/__init__.py b/bindings/python/iota_sdk/__init__.py index d59e9e0a47..2c6aaf12de 100644 --- a/bindings/python/iota_sdk/__init__.py +++ b/bindings/python/iota_sdk/__init__.py @@ -17,6 +17,7 @@ from .types.burn import * from .types.client_options import * from .types.common import * +from .types.context_input import * from .types.event import * from .types.feature import * from .types.filter_options import * diff --git a/bindings/python/iota_sdk/client/_high_level_api.py b/bindings/python/iota_sdk/client/_high_level_api.py index 77f16c4a0b..931cbb5cfb 100644 --- a/bindings/python/iota_sdk/client/_high_level_api.py +++ b/bindings/python/iota_sdk/client/_high_level_api.py @@ -3,6 +3,7 @@ from typing import List, Optional from dataclasses import dataclass +from iota_sdk.types.block import Block from iota_sdk.types.common import HexStr, json from iota_sdk.types.output import OutputWithMetadata from iota_sdk.types.output_id import OutputId diff --git a/bindings/python/iota_sdk/types/context_input.py b/bindings/python/iota_sdk/types/context_input.py new file mode 100644 index 0000000000..ac7b57efea --- /dev/null +++ b/bindings/python/iota_sdk/types/context_input.py @@ -0,0 +1,34 @@ +# Copyright 2023 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations +from dataclasses import dataclass, field +from enum import IntEnum +from iota_sdk.types.common import HexStr, json + + +class ContextInputType(IntEnum): + """Context input types. + """ + BlockIssuanceCredit = 1 + + +@json +@dataclass +class ContextInput(): + """Base class for context inputs. + """ + type: int + + +@json +@dataclass +class BlockIssuanceCreditContextInput(ContextInput): + """A Block Issuance Credit (BIC) Context Input provides the VM with context for the value of + the BIC vector of a specific slot. + """ + account_id: HexStr + type: int = field( + default_factory=lambda: int( + ContextInputType.BlockIssuanceCredit), + init=False) diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index 043c1faf2f..24a9cc56ef 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -4,6 +4,7 @@ from enum import IntEnum from dataclasses import dataclass, field +from typing import List from iota_sdk.types.address import Ed25519Address, AccountAddress, NFTAddress from iota_sdk.types.common import HexStr, json @@ -99,4 +100,7 @@ class BlockIssuer(Feature): expiry_slot: str # TODO Replace with a list of PublicKey types public_keys: List[HexStr] - type: int = field(default_factory=lambda: int(FeatureType.BlockIssuer), init=False) + type: int = field( + default_factory=lambda: int( + FeatureType.BlockIssuer), + init=False) From ba7439c4f87f9de8c3ff21f1fb2f856120b39d02 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 11 Sep 2023 15:36:49 +0200 Subject: [PATCH 4/6] Optional ValidatorsResponse cursor (#1165) --- sdk/src/types/api/core/response.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/src/types/api/core/response.rs b/sdk/src/types/api/core/response.rs index f9a9904888..1a832b4c02 100644 --- a/sdk/src/types/api/core/response.rs +++ b/sdk/src/types/api/core/response.rs @@ -180,7 +180,8 @@ pub struct ValidatorsResponse { page_size: u32, /// The cursor that needs to be provided as cursor query parameter to request the next page. If empty, this was the /// last page. - cursor: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + cursor: Option, } /// Response of GET /api/core/v3/rewards/{outputId}. From 4789f3f54b74fbed86075592fccb21e947241d4d Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 11 Sep 2023 16:11:54 +0200 Subject: [PATCH 5/6] Update BlockFailureReason (#1194) --- sdk/src/types/api/core/response.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sdk/src/types/api/core/response.rs b/sdk/src/types/api/core/response.rs index 1a832b4c02..43ef4ea3b3 100644 --- a/sdk/src/types/api/core/response.rs +++ b/sdk/src/types/api/core/response.rs @@ -336,14 +336,16 @@ pub enum TransactionState { pub enum BlockFailureReason { /// The block is too old to issue. TooOldToIssue = 1, - /// The block's parents are too old. - ParentsTooOld = 2, - /// The block failed at the booker. - FailedAtBooker = 3, + /// One of the block's parents is too old. + ParentTooOld = 2, + /// One of the block's parents does not exist. + ParentDoesNotExist = 3, + /// One of the block's parents is invalid. + ParentInvalid = 4, /// The block is dropped due to congestion. - DroppedDueToCongestion = 4, + DroppedDueToCongestion = 5, /// The block is invalid. - Invalid = 5, + Invalid = 6, } /// Response of GET /api/core/v3/blocks/{blockId}/metadata. From 7d98236c907e80ea19e2cf1036189a87933e50e8 Mon Sep 17 00:00:00 2001 From: Brord van Wierst Date: Mon, 11 Sep 2023 16:13:34 +0200 Subject: [PATCH 6/6] Python/staking feature (#1196) * staking feature in python * fix * amount to str type * fmt --------- Co-authored-by: Thibault Martinez --- bindings/python/iota_sdk/types/feature.py | 34 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/bindings/python/iota_sdk/types/feature.py b/bindings/python/iota_sdk/types/feature.py index 24a9cc56ef..842c012837 100644 --- a/bindings/python/iota_sdk/types/feature.py +++ b/bindings/python/iota_sdk/types/feature.py @@ -19,12 +19,14 @@ class FeatureType(IntEnum): Metadata (2): The metadata feature. Tag (3): The tag feature. BlockIssuer (4): The block issuer feature. + Staking (5): The staking feature. """ Sender = 0 Issuer = 1 Metadata = 2 Tag = 3 BlockIssuer = 4 + Staking = 5 @json @@ -38,7 +40,7 @@ class Feature(): @json @dataclass class SenderFeature(Feature): - """Sender feature. + """Identifies the validated sender of an output. Attributes: address: A given sender address. """ @@ -52,7 +54,7 @@ class SenderFeature(Feature): @json @dataclass class IssuerFeature(Feature): - """Issuer feature. + """Identifies the validated issuer of the UTXO state machine. Attributes: address: A given issuer address. """ @@ -66,7 +68,7 @@ class IssuerFeature(Feature): @json @dataclass class MetadataFeature(Feature): - """Metadata feature. + """Defines metadata, arbitrary binary data, that will be stored in the output. Attributes: data: Some hex encoded metadata. """ @@ -80,7 +82,7 @@ class MetadataFeature(Feature): @json @dataclass class TagFeature(Feature): - """Tag feature. + """Makes it possible to tag outputs with an index, so they can be retrieved through an indexer API. Attributes: tag: A hex encoded tag used to index the output. """ @@ -91,7 +93,7 @@ class TagFeature(Feature): @json @dataclass class BlockIssuer(Feature): - """Block issuer feature. + """Contains the public keys to verify block signatures and allows for unbonding the issuer deposit. Attributes: expiry_slot: The slot index at which the Block Issuer Feature expires and can be removed. public_keys: The Block Issuer Keys. @@ -104,3 +106,25 @@ class BlockIssuer(Feature): default_factory=lambda: int( FeatureType.BlockIssuer), init=False) + + +@json +@dataclass +class StakingFeature(Feature): + """Stakes IOTA coins to become eligible for committee selection, validate the network and receive Mana rewards. + Attributes: + staked_amount: The amount of IOTA coins that are locked and staked in the containing account. + fixed_cost: The fixed cost of the validator, which it receives as part of its Mana rewards. + start_epoch: The epoch index in which the staking started. + end_epoch: The epoch index in which the staking ends. + """ + staked_amount: str + fixed_cost: str + # TODO Replace with an EpochIndex type + start_epoch: HexStr + # TODO Replace with an EpochIndex type + end_epoch: HexStr + type: int = field( + default_factory=lambda: int( + FeatureType.Staking), + init=False)