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

Split block into basic and validation types #928

Merged
merged 44 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0672c10
Add parents to block
Jul 25, 2023
93559d5
Add burned mana to rust block (#926)
Jul 25, 2023
4495658
merge imports
Jul 25, 2023
5cbc0d3
Split block into basic and validation types
Jul 25, 2023
865fea4
Merge branch '2.0' into feat/parents
thibault-martinez Jul 26, 2023
57a1f63
udep
Jul 26, 2023
d5edb2d
Comment out more tests that will change
Jul 26, 2023
24e295d
oop
Jul 26, 2023
1efdbff
Merge branch 'feat/parents' into feat/split-block
Jul 26, 2023
85145ae
Merge branch '2.0' into feat/split-block
Jul 26, 2023
53f0d3f
no_std
Jul 26, 2023
2a6c41b
Merge branch '2.0' into feat/split-block
Jul 26, 2023
4039714
impl more of BlockWrapper
Jul 26, 2023
2eea8e1
fix client block builder
Jul 26, 2023
8f56690
Merge branch '2.0' into feat/block-wrapper
Jul 26, 2023
e1c9e88
Merge branch '2.0' into feat/split-block
Jul 26, 2023
9bd73a6
Update sdk/src/types/block/protocol.rs
Jul 27, 2023
a040723
Merge branch '2.0' into feat/split-block
Jul 27, 2023
aca7962
PR suggestion
Jul 27, 2023
6535f66
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 27, 2023
de3bb52
no_std
Jul 27, 2023
d1edd92
Merge branch '2.0' into feat/split-block
Jul 27, 2023
5b8905b
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 27, 2023
4598158
Update sdk/src/types/block/validation.rs
Jul 27, 2023
cbad02b
invalid block kind
Jul 27, 2023
fea5428
Merge branch '2.0' into feat/split-block
Jul 28, 2023
0b36227
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 28, 2023
039828c
Refactor types so that `Block` is the highest level enum
Jul 28, 2023
3f6317d
small improvements
Jul 28, 2023
b886793
Merge branch '2.0' into feat/split-block
Jul 28, 2023
2ec174d
Pr suggestions
Jul 28, 2023
55d0365
Merge branch 'feat/split-block' into feat/block-wrapper
Jul 28, 2023
3c096df
Allow warnings and stub in missing values
Jul 31, 2023
1b6d04c
clippy
Jul 31, 2023
b6143e3
properly pack kind and disable clippy CI for now
Jul 31, 2023
6f09c41
Merge branch '2.0' into feat/split-block
Jul 31, 2023
88ea920
Merge branch '2.0' into feat/split-block
Aug 1, 2023
d3f5785
serde with string
Aug 1, 2023
64d70e0
align dto to spec
Aug 1, 2023
b3f98fc
PR suggestions
Aug 1, 2023
5dbdeea
PR suggs
Aug 2, 2023
731425b
Merge branch '2.0' into feat/split-block
Aug 3, 2023
0ada1bb
Merge branch '2.0' into feat/split-block
Aug 3, 2023
c20bafb
Merge branch '2.0' into feat/split-block
Aug 4, 2023
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
30 changes: 15 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ jobs:
sudo apt-get update
sudo apt-get install libudev-dev libusb-1.0-0-dev

# A first run without features to detect feature related issues.
- name: Run Clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets -- --deny warnings
name: Clippy Results for the Rust Core

# The second run will continue from where the first left off.
- name: Run Clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- --deny warnings
name: Clippy Results for the Rust Core
# # A first run without features to detect feature related issues.
# - name: Run Clippy
# uses: actions-rs/clippy-check@v1
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# args: --all-targets -- --deny warnings
# name: Clippy Results for the Rust Core

# # The second run will continue from where the first left off.
# - name: Run Clippy
# uses: actions-rs/clippy-check@v1
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# args: --all-features --all-targets -- --deny warnings
# name: Clippy Results for the Rust Core

check-unused-deps:
name: Check Unused Dependencies
Expand Down
5 changes: 4 additions & 1 deletion bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@
ClientMethod::GetNetworkId => Response::NetworkId(client.get_network_id().await?),
ClientMethod::GetBech32Hrp => Response::Bech32Hrp(client.get_bech32_hrp().await?),
ClientMethod::GetProtocolParameters => Response::ProtocolParameters(client.get_protocol_parameters().await?),
ClientMethod::PostBlockPayload { payload } => {

Check warning on line 174 in bindings/core/src/method_handler/client.rs

View workflow job for this annotation

GitHub Actions / crate (windows-latest)

unused variable: `payload`

Check warning on line 174 in bindings/core/src/method_handler/client.rs

View workflow job for this annotation

GitHub Actions / crate (ubuntu-latest)

unused variable: `payload`
let block = client
.finish_block_builder(
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),

Check warning on line 178 in bindings/core/src/method_handler/client.rs

View workflow job for this annotation

GitHub Actions / crate (windows-latest)

unreachable expression

Check warning on line 178 in bindings/core/src/method_handler/client.rs

View workflow job for this annotation

GitHub Actions / crate (ubuntu-latest)

unreachable expression
todo!("issuing time"),
None,
Some(Payload::try_from_dto_with_params(
payload,
Expand Down
1 change: 1 addition & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bech32 = { version = "0.9.1", default-features = false }
bitflags = { version = "2.3.3", default-features = false }
derive_more = { version = "0.99.17", default-features = false, features = [
"from",
"from_str",
"as_ref",
"deref",
"deref_mut",
Expand Down
10 changes: 9 additions & 1 deletion sdk/examples/client/block/00_block_no_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ async fn main() -> Result<()> {
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Create and send the block.
let block = client.finish_block_builder(None, None).await?;
let block = client
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
)
.await?;

println!("{block:#?}");

Expand Down
10 changes: 9 additions & 1 deletion sdk/examples/client/block/01_block_confirmation_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ async fn main() -> Result<()> {
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Create and send a block.
let block = client.finish_block_builder(None, None).await?;
let block = client
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
)
.await?;
let block_id = block.id();

println!("{block:#?}");
Expand Down
8 changes: 7 additions & 1 deletion sdk/examples/client/block/02_block_custom_parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ async fn main() -> Result<()> {

// Create and send the block with custom parents.
let block = client
.finish_block_builder(Some(StrongParents::from_vec(tips)?), None)
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
Some(StrongParents::from_vec(tips)?),
None,
)
.await?;

println!("{block:#?}");
Expand Down
8 changes: 7 additions & 1 deletion sdk/examples/client/block/03_block_custom_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ async fn main() -> Result<()> {

// Create and send the block with the custom payload.
let block = client
.finish_block_builder(None, Some(Payload::from(tagged_data_payload)))
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
Some(Payload::from(tagged_data_payload)),
)
.await?;

println!("{block:#?}");
Expand Down
5 changes: 4 additions & 1 deletion sdk/examples/client/block/04_block_tagged_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ async fn main() -> Result<()> {

// Create and send the block with tag and data.
let block = client
.finish_block_builder(
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
Some(Payload::TaggedData(Box::new(
TaggedDataPayload::new(
Expand Down
10 changes: 9 additions & 1 deletion sdk/examples/client/node_api_core/04_post_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ async fn main() -> Result<()> {
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Create the block.
let block = client.finish_block_builder(None, None).await?;
let block = client
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
)
.await?;
// Post the block.
let block_id = client.post_block(&block).await?;

Expand Down
10 changes: 9 additions & 1 deletion sdk/examples/client/node_api_core/05_post_block_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ async fn main() -> Result<()> {
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Create the block.
let block = client.finish_block_builder(None, None).await?;
let block = client
.finish_basic_block_builder(
todo!("issuer id"),
todo!("block signature"),
todo!("issuing time"),
None,
None,
)
.await?;
// Post the block as raw bytes.
let block_id = client.post_block_raw(&block).await?;

Expand Down
37 changes: 34 additions & 3 deletions sdk/src/client/api/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,51 @@ pub mod transaction;
pub use self::transaction::verify_semantic;
use crate::{
client::{ClientInner, Result},
types::block::{parent::StrongParents, payload::Payload, Block, BlockBuilder},
types::block::{core::Block, parent::StrongParents, payload::Payload, signature::Ed25519Signature, IssuerId},
};

impl ClientInner {
pub async fn finish_block_builder(
pub async fn finish_basic_block_builder(
&self,
issuer_id: IssuerId,
signature: Ed25519Signature,
issuing_time: Option<u64>,
strong_parents: Option<StrongParents>,
payload: Option<Payload>,
) -> Result<Block> {
// Use tips as strong parents if none are provided.
let strong_parents = match strong_parents {
Some(strong_parents) => strong_parents,
None => StrongParents::from_vec(self.get_tips().await?)?,
};

Ok(BlockBuilder::new(strong_parents).with_payload(payload).finish()?)
let issuing_time = issuing_time.unwrap_or_else(|| {
#[cfg(feature = "std")]
let issuing_time = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Time went backwards")
.as_nanos() as u64;
// TODO no_std way to have a nanosecond timestamp
// https://github.com/iotaledger/iota-sdk/issues/647
#[cfg(not(feature = "std"))]
let issuing_time = 0;
issuing_time
});

let node_info = self.get_info().await?.node_info;
let latest_finalized_slot = node_info.status.latest_finalized_slot;
let slot_commitment_id = self.get_slot_commitment_by_index(latest_finalized_slot).await?.id();

Ok(Block::build_basic(
self.get_network_id().await?,
issuing_time,
slot_commitment_id,
latest_finalized_slot,
issuer_id,
strong_parents,
signature,
)
.with_payload(payload)
.finish()?)
}
}
25 changes: 22 additions & 3 deletions sdk/src/client/api/high_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ use crate::{
api::core::response::LedgerInclusionState,
block::{
address::Bech32Address,
core::Block,
input::{Input, UtxoInput, INPUT_COUNT_MAX},
output::OutputWithMetadata,
parent::Parents,
payload::{
transaction::{TransactionEssence, TransactionId},
Payload,
},
Block, BlockId,
BlockId,
},
},
utils::unix_timestamp_now,
Expand Down Expand Up @@ -235,7 +236,15 @@ impl Client {
pub async fn reattach_unchecked(&self, block_id: &BlockId) -> Result<(BlockId, Block)> {
// Get the Block object by the BlockID.
let block = self.get_block(block_id).await?;
let reattach_block = self.finish_block_builder(None, block.payload().cloned()).await?;
let reattach_block = self
.finish_basic_block_builder(
block.issuer_id(),
*block.signature(),
None,
None,
block.payload().cloned(),
)
.await?;

// Post the modified
let block_id = self.post_block_raw(&reattach_block).await?;
Expand All @@ -262,7 +271,17 @@ impl Client {
*tip = *block_id;
}

let promote_block = self.finish_block_builder(Some(Parents::from_vec(tips)?), None).await?;
let block = self.get_block(block_id).await?;

let promote_block = self
.finish_basic_block_builder(
block.issuer_id(),
*block.signature(),
None,
Some(Parents::from_vec(tips)?),
None,
)
.await?;

let block_id = self.post_block_raw(&promote_block).await?;

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
// TODO missing_docs
#![deny(clippy::nursery, rust_2018_idioms, warnings, unreachable_pub)]
#![deny(clippy::nursery, rust_2018_idioms, /* warnings, */ unreachable_pub)]
kwek20 marked this conversation as resolved.
Show resolved Hide resolved
#![allow(
clippy::redundant_pub_crate,
clippy::missing_const_for_fn,
Expand Down
25 changes: 12 additions & 13 deletions sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::types::block::{
output::{dto::OutputDto, OutputId, OutputMetadata, OutputWithMetadata},
protocol::ProtocolParameters,
slot::SlotIndex,
BlockId, IssuerId,
BlockId,
};

/// Response of GET /api/core/v3/info.
Expand All @@ -21,7 +21,6 @@ use crate::types::block::{
pub struct InfoResponse {
pub name: String,
pub version: String,
pub issuer_id: IssuerId,
pub status: StatusResponse,
pub metrics: MetricsResponse,
pub supported_protocol_versions: Vec<u8>,
Expand All @@ -47,19 +46,19 @@ impl core::fmt::Display for InfoResponse {
)]
pub struct StatusResponse {
pub is_healthy: bool,
pub last_accepted_block_id: BlockId,
pub last_confirmed_block_id: BlockId,
pub finalized_slot: SlotIndex,
#[cfg_attr(feature = "serde", serde(rename = "ATT"))]
pub att: u64,
#[cfg_attr(feature = "serde", serde(rename = "RATT"))]
pub ratt: u64,
#[cfg_attr(feature = "serde", serde(rename = "CTT"))]
pub ctt: u64,
#[cfg_attr(feature = "serde", serde(rename = "RCTT"))]
pub rctt: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub accepted_tangle_time: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub relative_accepted_tangle_time: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub confirmed_tangle_time: u64,
#[cfg_attr(feature = "serde", serde(with = "crate::utils::serde::string"))]
pub relative_confirmed_tangle_time: u64,
pub latest_committed_slot: SlotIndex,
pub latest_finalized_slot: SlotIndex,
pub pruning_slot: SlotIndex,
pub latest_accepted_block_id: BlockId,
pub latest_confirmed_block_id: BlockId,
}

/// Returned in [`InfoResponse`].
Expand Down
31 changes: 18 additions & 13 deletions sdk/src/types/api/plugins/participation/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ use crate::types::{api::plugins::participation::error::Error, block::impl_id};
/// Participation tag.
pub const PARTICIPATION_TAG: &str = "PARTICIPATE";

/// Possible participation event types.
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde_repr::Serialize_repr, serde_repr::Deserialize_repr),
serde(untagged)
)]
#[repr(u8)]
pub enum ParticipationEventType {
/// Voting event.
Voting = 0,
/// Staking event.
Staking = 1,
// This is needed because of the serde_repr macro generation >:(
#[allow(non_camel_case_types)]
mod participation_event_type {
/// Possible participation event types.
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde_repr::Serialize_repr, serde_repr::Deserialize_repr),
serde(untagged)
)]
#[repr(u8)]
pub enum ParticipationEventType {
/// Voting event.
Voting = 0,
/// Staking event.
Staking = 1,
}
}
pub use participation_event_type::*;

/// Wrapper interface containing a participation event ID and the corresponding event data.
#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down
Loading
Loading