diff --git a/Cargo.lock b/Cargo.lock index dc5cbadfc..a69b80c86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8002,15 +8002,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-byte-array" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63213ee4ed648dbd87db6fa993d4275b46bfb4ddfd95b3756045007c2b28f742" -dependencies = [ - "serde", -] - [[package]] name = "serde-value" version = "0.7.0" @@ -8023,9 +8014,9 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.12" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" dependencies = [ "serde", ] @@ -9808,8 +9799,8 @@ version = "0.3.0" dependencies = [ "newtype-ops", "serde", - "serde-byte-array", "serde_json", + "serde_with", "tari_bor", "tari_template_abi", "tari_template_macros", diff --git a/Cargo.toml b/Cargo.toml index b0a008314..4e8acb65e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,8 +59,8 @@ resolver = "2" # specifying them in a single place and having them applied to all crates # internal dependencies among workspace crates -libp2p-messaging = { path = "networking/libp2p-messaging"} -libp2p-peersync = { path = "networking/libp2p-peersync"} +libp2p-messaging = { path = "networking/libp2p-messaging" } +libp2p-peersync = { path = "networking/libp2p-peersync" } libp2p-substream = { path = "networking/libp2p-substream" } proto_builder = { path = "networking/proto_builder" } sqlite_message_logger = { path = "networking/sqlite_message_logger" } @@ -88,10 +88,10 @@ tari_rpc_framework = { path = "networking/rpc_framework" } tari_rpc_macros = { path = "networking/rpc_macros" } tari_state_store_sqlite = { path = "dan_layer/state_store_sqlite" } tari_swarm = { path = "networking/swarm" } -tari_template_abi = { version="0.3.0", path = "dan_layer/template_abi" } +tari_template_abi = { version = "0.3.0", path = "dan_layer/template_abi" } tari_template_builtin = { path = "dan_layer/template_builtin" } tari_template_lib = { path = "dan_layer/template_lib" } -tari_template_macros = { version="0.3.0", path = "dan_layer/template_macros" } +tari_template_macros = { version = "0.3.0", path = "dan_layer/template_macros" } tari_template_test_tooling = { path = "dan_layer/template_test_tooling" } tari_transaction = { path = "dan_layer/transaction" } tari_transaction_manifest = { path = "dan_layer/transaction_manifest" } @@ -199,7 +199,6 @@ semver = "1.0" serde = { version = "1.0", default-features = false } serde_json = "1.0" serde_with = "2.3" -serde-byte-array = "0.1.2" sha2 = "0.10.8" smallvec = "2.0.0-alpha.1" std-semaphore = "0.1.0" @@ -212,7 +211,7 @@ tokio-stream = "0.1.7" tokio-util = "0.7.10" tonic = "0.6.2" tower = "0.4" -tower-http = { version = "0.3.5", default-features = false} +tower-http = { version = "0.3.5", default-features = false } tower-layer = "0.3" tracing = "0.1.40" url = "2.4.1" diff --git a/applications/tari_validator_node_web_ui/src/routes/Committees/Committees.tsx b/applications/tari_validator_node_web_ui/src/routes/Committees/Committees.tsx index b8aa8340a..899ceb1fd 100644 --- a/applications/tari_validator_node_web_ui/src/routes/Committees/Committees.tsx +++ b/applications/tari_validator_node_web_ui/src/routes/Committees/Committees.tsx @@ -66,9 +66,9 @@ function Committees({ committees, peerId }: { committees: CommitteeShardInfo[] | {committees.map((committee) => ( diff --git a/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesPieChart.tsx b/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesPieChart.tsx index bcc4bf6d7..d33f8cf03 100644 --- a/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesPieChart.tsx +++ b/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesPieChart.tsx @@ -31,17 +31,23 @@ const MyChartComponent = ({ chartData }: MyChartComponentProps) => { useEffect(() => { const mappedTitles = chartData.committees.map((shardInfo) => { - return `${shardInfo.shard_range.start.slice(0, 6)}... - ${shardInfo.shard_range.end.slice(0, 6)}...`; + return `${shardInfo.substate_address_range.start.slice(0, 6)}... - ${shardInfo.substate_address_range.end.slice( + 0, + 6, + )}...`; }); setTitles(mappedTitles); const mappedContent = chartData.committees.reverse().map((shardInfo) => { const data: any = { value: shardInfo.validators.length, - name: `${shardInfo.shard_range.start.slice(0, 6)}... - ${shardInfo.shard_range.end.slice(0, 6)}...`, + name: `${shardInfo.substate_address_range.start.slice(0, 6)}... - ${shardInfo.substate_address_range.end.slice( + 0, + 6, + )}...`, committee: shardInfo.validators, - link: `/committees/${shardInfo.shard_range.start},${shardInfo.shard_range.end}`, - range: `${shardInfo.shard_range.start}
${shardInfo.shard_range.end}`, + link: `/committees/${shardInfo.substate_address_range.start},${shardInfo.substate_address_range.end}`, + range: `${shardInfo.substate_address_range.start}
${shardInfo.substate_address_range.end}`, }; return data; }); diff --git a/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesRadial.tsx b/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesRadial.tsx index e0f89fff8..cbd4e672e 100644 --- a/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesRadial.tsx +++ b/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesRadial.tsx @@ -56,8 +56,8 @@ export default function CommitteesRadial({ committees }: { committees: GetNetwor }; dataset.forEach((data: CommitteeShardInfo) => { - const start = fromHexString(data.shard_range.start)[0]; - const end = fromHexString(data.shard_range.end)[0]; + const start = fromHexString(data.substate_address_range.start)[0]; + const end = fromHexString(data.substate_address_range.end)[0]; switch (true) { case start === end: @@ -86,7 +86,7 @@ export default function CommitteesRadial({ committees }: { committees: GetNetwor } }); setChartData(info); - const newTitles = dataset.map((info) => `Committee ${info.bucket}`); + const newTitles = dataset.map((info) => `Committee ${info.shard}`); setTitles(newTitles); }, [committees]); @@ -95,7 +95,7 @@ export default function CommitteesRadial({ committees }: { committees: GetNetwor const data = committees.committees[dataIndex]; const { validators, - shard_range: { start, end }, + substate_address_range: { start, end }, } = data; const memberList = validators diff --git a/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesWaterfall.tsx b/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesWaterfall.tsx index 31552c080..453cbb72b 100644 --- a/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesWaterfall.tsx +++ b/applications/tari_validator_node_web_ui/src/routes/Committees/CommitteesWaterfall.tsx @@ -23,7 +23,7 @@ import { useState, useEffect } from "react"; import { fromHexString } from "../VN/Components/helpers"; import EChartsReact from "echarts-for-react"; -import { ICommittees, ICommitteeChart, ICommitteeMap } from "../../utils/interfaces"; +import { ICommitteeChart } from "../../utils/interfaces"; import "../../theme/echarts.css"; import { CommitteeShardInfo } from "../../utils/interfaces"; @@ -56,8 +56,8 @@ export default function CommitteesWaterfall({ committees }: { committees: Commit }; committees.forEach((data) => { - const firstValue = fromHexString(data.shard_range.start)[0]; - const secondValue = fromHexString(data.shard_range.end)[0]; + const firstValue = fromHexString(data.substate_address_range.start)[0]; + const secondValue = fromHexString(data.substate_address_range.end)[0]; switch (true) { case firstValue === secondValue: info.activeleft.push(0); @@ -86,15 +86,15 @@ export default function CommitteesWaterfall({ committees }: { committees: Commit }); setChartData(info); setDivHeight(committees.length * 50); - const newTitles = committees.map((data) => `Committee ${data.bucket}`); + const newTitles = committees.map((data) => `Committee ${data.shard}`); setTitles(newTitles); }, [committees]); function tooltipFormatter(params: any) { const dataIndex = params[0].dataIndex; const data = committees[dataIndex]; - const begin = fromHexString(data.shard_range.start)[0]; - const end = fromHexString(data.shard_range.end)[0]; + const begin = fromHexString(data.substate_address_range.start)[0]; + const end = fromHexString(data.substate_address_range.end)[0]; const memberList = data.validators .map((member) => `
  • ${member.address}
  • `) diff --git a/applications/tari_validator_node_web_ui/src/utils/interfaces.tsx b/applications/tari_validator_node_web_ui/src/utils/interfaces.tsx index f6c3be060..eb7618663 100644 --- a/applications/tari_validator_node_web_ui/src/utils/interfaces.tsx +++ b/applications/tari_validator_node_web_ui/src/utils/interfaces.tsx @@ -72,8 +72,8 @@ interface GetNetworkCommitteesResponse { } interface CommitteeShardInfo { - bucket: number; - shard_range: { + shard: number; + substate_address_range: { end: string; start: string; }; diff --git a/dan_layer/template_lib/Cargo.toml b/dan_layer/template_lib/Cargo.toml index 0e4c24aa5..32b511bcd 100644 --- a/dan_layer/template_lib/Cargo.toml +++ b/dan_layer/template_lib/Cargo.toml @@ -13,8 +13,11 @@ tari_template_macros = { workspace = true, optional = true } tari_bor = { workspace = true, default-features = false } newtype-ops = { workspace = true } -serde = { workspace = true, default-features = false, features = ["derive", "alloc"] } -serde-byte-array = { workspace = true } +serde = { workspace = true, default-features = false, features = [ + "derive", + "alloc", +] } +serde_with = { workspace = true } [dev-dependencies] serde_json = { workspace = true } @@ -23,9 +26,3 @@ serde_json = { workspace = true } default = ["macro", "std"] macro = ["tari_template_macros"] std = ["serde/std", "tari_bor/std"] - -[package.metadata.cargo-machete] -ignored = [ - # Used but not detectable by machete - "serde-byte-array", -] diff --git a/dan_layer/template_lib/src/crypto/balance_proof.rs b/dan_layer/template_lib/src/crypto/balance_proof.rs index 22631ae4f..f919f81b4 100644 --- a/dan_layer/template_lib/src/crypto/balance_proof.rs +++ b/dan_layer/template_lib/src/crypto/balance_proof.rs @@ -1,13 +1,15 @@ // Copyright 2023 The Tari Project // SPDX-License-Identifier: BSD-3-Clause use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, Bytes}; use crate::crypto::InvalidByteLengthError; /// The signature of a balance proof, used to validate the authorship of confidential transfers +#[serde_as] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(transparent)] -pub struct BalanceProofSignature(#[serde(with = "serde_byte_array")] [u8; BalanceProofSignature::length()]); +pub struct BalanceProofSignature(#[serde_as(as = "Bytes")] [u8; BalanceProofSignature::length()]); impl BalanceProofSignature { pub const fn length() -> usize { diff --git a/dan_layer/template_lib/src/crypto/commitment.rs b/dan_layer/template_lib/src/crypto/commitment.rs index 72488a4b0..be4b00826 100644 --- a/dan_layer/template_lib/src/crypto/commitment.rs +++ b/dan_layer/template_lib/src/crypto/commitment.rs @@ -2,14 +2,16 @@ // SPDX-License-Identifier: BSD-3-Clause use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, Bytes}; use tari_template_abi::rust::fmt::{Display, Formatter}; use crate::{crypto::InvalidByteLengthError, Hash}; /// A Pederson Commitment byte contents +#[serde_as] #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash, Default, Serialize, Deserialize)] #[serde(transparent)] -pub struct PedersonCommitmentBytes(#[serde(with = "serde_byte_array")] [u8; PedersonCommitmentBytes::length()]); +pub struct PedersonCommitmentBytes(#[serde_as(as = "Bytes")] [u8; PedersonCommitmentBytes::length()]); impl PedersonCommitmentBytes { pub const fn length() -> usize { diff --git a/dan_layer/template_lib/src/crypto/ristretto.rs b/dan_layer/template_lib/src/crypto/ristretto.rs index 1c96b471a..95b5d319d 100644 --- a/dan_layer/template_lib/src/crypto/ristretto.rs +++ b/dan_layer/template_lib/src/crypto/ristretto.rs @@ -2,14 +2,16 @@ // SPDX-License-Identifier: BSD-3-Clause use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, Bytes}; use tari_template_abi::rust::fmt::{Display, Formatter}; use crate::{crypto::InvalidByteLengthError, models::NonFungibleAddress, Hash}; /// A Ristretto public key byte contents +#[serde_as] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] #[serde(transparent)] -pub struct RistrettoPublicKeyBytes(#[serde(with = "serde_byte_array")] [u8; RistrettoPublicKeyBytes::length()]); +pub struct RistrettoPublicKeyBytes(#[serde_as(as = "Bytes")] [u8; RistrettoPublicKeyBytes::length()]); impl RistrettoPublicKeyBytes { pub const fn length() -> usize { diff --git a/dan_layer/template_lib/src/hash.rs b/dan_layer/template_lib/src/hash.rs index 8393915d9..60a513df5 100644 --- a/dan_layer/template_lib/src/hash.rs +++ b/dan_layer/template_lib/src/hash.rs @@ -29,11 +29,13 @@ use std::{ }; use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, Bytes}; /// Representation of a 32-byte hash value +#[serde_as] #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash, Default, Serialize, Deserialize)] #[serde(transparent)] -pub struct Hash([u8; 32]); +pub struct Hash(#[serde_as(as = "Bytes")] [u8; 32]); impl Hash { pub const fn from_array(bytes: [u8; 32]) -> Self { diff --git a/dan_layer/template_lib/src/models/confidential_proof.rs b/dan_layer/template_lib/src/models/confidential_proof.rs index 93afd3082..d49ddacf5 100644 --- a/dan_layer/template_lib/src/models/confidential_proof.rs +++ b/dan_layer/template_lib/src/models/confidential_proof.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, Bytes}; use crate::{ crypto::{BalanceProofSignature, PedersonCommitmentBytes, RistrettoPublicKeyBytes}, @@ -21,9 +22,10 @@ pub struct ConfidentialOutputProof { } /// A zero-knowledge proof that a confidential resource amount is valid +#[serde_as] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct ConfidentialStatement { - #[serde(with = "serde_byte_array")] + #[serde_as(as = "Bytes")] pub commitment: [u8; 32], /// Public nonce (R) that was used to generate the commitment mask // #[cfg_attr(feature = "serde", serde(with = "hex::serde"))] @@ -47,9 +49,10 @@ pub struct ConfidentialWithdrawProof { /// Used by the receiver to determine the value component of the commitment, in both confidential transfers and Minotari /// burns +#[serde_as] #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(transparent)] -pub struct EncryptedData(#[serde(with = "serde_byte_array")] pub [u8; EncryptedData::size()]); +pub struct EncryptedData(#[serde_as(as = "Bytes")] pub [u8; EncryptedData::size()]); impl EncryptedData { pub const fn size() -> usize { diff --git a/dan_layer/template_lib/src/models/non_fungible.rs b/dan_layer/template_lib/src/models/non_fungible.rs index 6468aad94..ee6239b5c 100644 --- a/dan_layer/template_lib/src/models/non_fungible.rs +++ b/dan_layer/template_lib/src/models/non_fungible.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde_with::{serde_as, Bytes}; use tari_bor::BorTag; use tari_template_abi::{ call_engine, @@ -22,9 +23,10 @@ use crate::{ const DELIM: char = ':'; /// The unique identification of a non-fungible token inside it's parent resource +#[serde_as] #[derive(Debug, Clone, Ord, PartialOrd, PartialEq, Eq, Serialize, Deserialize, Hash)] pub enum NonFungibleId { - U256(#[serde(with = "serde_byte_array")] [u8; 32]), + U256(#[serde_as(as = "Bytes")] [u8; 32]), String(String), Uint32(u32), Uint64(u64), diff --git a/integration_tests/tests/features/block_sync.feature b/integration_tests/tests/features/block_sync.feature index 8f860d822..615537c9d 100644 --- a/integration_tests/tests/features/block_sync.feature +++ b/integration_tests/tests/features/block_sync.feature @@ -3,57 +3,56 @@ Feature: Block Sync -# This is flaky, we should fix it -# @serial -# Scenario: New validator node registers and syncs -# # Initialize a base node, wallet, miner and VN -# Given a base node BASE -# Given a wallet WALLET connected to base node BASE -# Given a miner MINER connected to base node BASE and wallet WALLET - -# # Initialize an indexer -# Given an indexer IDX connected to base node BASE - -# # Initialize the wallet daemon -# Given a wallet daemon WALLET_D connected to indexer IDX -# When I create a key named K1 for WALLET_D - -# # Initialize a VN -# Given a seed validator node VN connected to base node BASE and wallet WALLET -# When miner MINER mines 4 new blocks -# When wallet WALLET has at least 5000 T -# When validator node VN sends a registration transaction allowing fee claims from wallet WALLET_D using key K1 -# When miner MINER mines 16 new blocks -# Then VN has scanned to height 17 -# And indexer IDX has scanned to height 17 -# Then the validator node VN is listed as registered - -# When indexer IDX connects to all other validators - -# # Submit a few transactions -# When I create an account ACC1 via the wallet daemon WALLET_D with 10000 free coins -# When I create an account UNUSED1 via the wallet daemon WALLET_D -# When I create an account UNUSED2 via the wallet daemon WALLET_D -# When I create an account UNUSED3 via the wallet daemon WALLET_D - -# When I wait for validator VN has leaf block height of at least 20 - -# # Start a new VN that needs to sync -# Given a validator node VN2 connected to base node BASE and wallet WALLET -# Given validator VN2 nodes connect to all other validators -# When indexer IDX connects to all other validators - -# When validator node VN2 sends a registration transaction allowing fee claims from wallet WALLET_D using key K1 -# When miner MINER mines 20 new blocks -# Then VN has scanned to height 37 -# Then VN2 has scanned to height 37 -# Then the validator node VN2 is listed as registered - -# When I wait for validator VN2 has leaf block height of at least 20 - -# When I create an account UNUSED4 via the wallet daemon WALLET_D -# When I create an account UNUSED5 via the wallet daemon WALLET_D - -# When I wait for validator VN has leaf block height of at least 26 -# When I wait for validator VN2 has leaf block height of at least 26 + @serial + Scenario: New validator node registers and syncs + # Initialize a base node, wallet, miner and VN + Given a base node BASE + Given a wallet WALLET connected to base node BASE + Given a miner MINER connected to base node BASE and wallet WALLET + + # Initialize an indexer + Given an indexer IDX connected to base node BASE + + # Initialize the wallet daemon + Given a wallet daemon WALLET_D connected to indexer IDX + When I create a key named K1 for WALLET_D + + # Initialize a VN + Given a seed validator node VN connected to base node BASE and wallet WALLET + When miner MINER mines 4 new blocks + When wallet WALLET has at least 5000 T + When validator node VN sends a registration transaction allowing fee claims from wallet WALLET_D using key K1 + When miner MINER mines 16 new blocks + Then VN has scanned to height 17 + And indexer IDX has scanned to height 17 + Then the validator node VN is listed as registered + + When indexer IDX connects to all other validators + + # Submit a few transactions + When I create an account ACC1 via the wallet daemon WALLET_D with 10000 free coins + When I create an account UNUSED1 via the wallet daemon WALLET_D + When I create an account UNUSED2 via the wallet daemon WALLET_D + When I create an account UNUSED3 via the wallet daemon WALLET_D + + When I wait for validator VN has leaf block height of at least 20 + + # Start a new VN that needs to sync + Given a validator node VN2 connected to base node BASE and wallet WALLET + Given validator VN2 nodes connect to all other validators + When indexer IDX connects to all other validators + + When validator node VN2 sends a registration transaction allowing fee claims from wallet WALLET_D using key K1 + When miner MINER mines 20 new blocks + Then VN has scanned to height 37 + Then VN2 has scanned to height 37 + Then the validator node VN2 is listed as registered + + When I wait for validator VN2 has leaf block height of at least 20 + + When I create an account UNUSED4 via the wallet daemon WALLET_D + When I create an account UNUSED5 via the wallet daemon WALLET_D + + When I wait for validator VN has leaf block height of at least 26 + When I wait for validator VN2 has leaf block height of at least 26