From dc611f10939259bba1d83d6d7a9e7a9a9c02c8aa Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 13:35:09 +0530 Subject: [PATCH 01/13] added mock client and consensus state --- Cargo.toml | 2 +- .../programs/solana-ibc/src/client_state.rs | 103 +++++++++++++++++- .../solana-ibc/src/consensus_state.rs | 51 ++++++++- .../solana-ibc/programs/solana-ibc/src/lib.rs | 8 +- .../solana-ibc/src/validation_context.rs | 3 + 5 files changed, 162 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8689dbfc..8a221838 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ base64 = { version = "0.21", default-features = false, features = ["alloc"] } bincode = "1.3.3" borsh = { version = "0.10.3", default-features = false } derive_more = "0.99.17" -ibc = { version = "0.45.0", default-features = false, features = ["serde"] } +ibc = { version = "0.45.0", default-features = false, features = ["serde", "mocks", "std"] } ibc-proto = { version = "0.35.0", default-features = false, features = ["serde"] } pretty_assertions = "1.4.0" rand = { version = "0.8.5" } diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index 617a4865..44d4bbe2 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -11,8 +11,12 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ics24_host::path::{ClientConsensusStatePath, Path}; use ibc::core::timestamp::Timestamp; use ibc::core::{ContextError, ValidationContext}; +use ibc::mock::client_state::{ + MockClientContext, MockClientState, MOCK_CLIENT_STATE_TYPE_URL, +}; use ibc::{Any, Height}; use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState; +use ibc_proto::ibc::mock::ClientState as RawMockClientState; use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; @@ -25,6 +29,7 @@ const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum AnyClientState { Tendermint(TmClientState), + Mock(MockClientState), } impl Protobuf for AnyClientState {} @@ -41,6 +46,12 @@ impl TryFrom for AnyClientState { }, )?, )), + MOCK_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::Mock( + Protobuf::::decode_vec(&raw.value) + .map_err(|e| ClientError::ClientSpecific { + description: e.to_string(), + })?, + )), _ => Err(ClientError::UnknownClientStateType { client_state_type: raw.type_url, }), @@ -55,6 +66,12 @@ impl From for Any { type_url: TENDERMINT_CLIENT_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec(&client_state), }, + AnyClientState::Mock(mock_client_state) => Any { + type_url: MOCK_CLIENT_STATE_TYPE_URL.to_string(), + value: Protobuf::::encode_vec( + &mock_client_state, + ), + }, } } } @@ -75,6 +92,13 @@ impl ClientStateValidation for AnyClientState { client_message, update_kind, ), + AnyClientState::Mock(mock_client_state) => mock_client_state + .verify_client_message( + ctx, + client_id, + client_message, + update_kind, + ), } } @@ -93,6 +117,13 @@ impl ClientStateValidation for AnyClientState { client_message, update_kind, ), + AnyClientState::Mock(mock_client_state) => mock_client_state + .check_for_misbehaviour( + ctx, + client_id, + client_message, + update_kind, + ), } } @@ -115,6 +146,9 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.verify_consensus_state(consensus_state) } + AnyClientState::Mock(mock_client_state) => { + mock_client_state.verify_consensus_state(consensus_state) + } } } @@ -123,6 +157,9 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.client_type() } + AnyClientState::Mock(mock_client_state) => { + mock_client_state.client_type() + } } } @@ -131,6 +168,9 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.latest_height() } + AnyClientState::Mock(mock_client_state) => { + mock_client_state.latest_height() + } } } @@ -142,6 +182,9 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.validate_proof_height(proof_height) } + AnyClientState::Mock(client_state) => { + client_state.validate_proof_height(proof_height) + } } } @@ -162,6 +205,14 @@ impl ClientStateCommon for AnyClientState { proof_upgrade_consensus_state, root, ), + AnyClientState::Mock(client_state) => client_state + .verify_upgrade_client( + upgraded_client_state, + upgraded_consensus_state, + proof_upgrade_client, + proof_upgrade_consensus_state, + root, + ), } } @@ -177,6 +228,9 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.verify_membership(prefix, proof, root, path, value) } + AnyClientState::Mock(client_state) => { + client_state.verify_membership(prefix, proof, root, path, value) + } } } @@ -191,12 +245,23 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.verify_non_membership(prefix, proof, root, path) } + AnyClientState::Mock(client_state) => { + client_state.verify_non_membership(prefix, proof, root, path) + } } } } impl From for AnyClientState { - fn from(value: TmClientState) -> Self { AnyClientState::Tendermint(value) } + fn from(value: TmClientState) -> Self { + AnyClientState::Tendermint(value) + } +} + +impl From for AnyClientState { + fn from(value: MockClientState) -> Self { + AnyClientState::Mock(value) + } } impl ClientStateExecution for AnyClientState { @@ -210,6 +275,9 @@ impl ClientStateExecution for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.initialise(ctx, client_id, consensus_state) } + AnyClientState::Mock(client_state) => { + client_state.initialise(ctx, client_id, consensus_state) + } } } @@ -223,6 +291,9 @@ impl ClientStateExecution for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.update_state(ctx, client_id, header) } + AnyClientState::Mock(client_state) => { + client_state.update_state(ctx, client_id, header) + } } } @@ -241,6 +312,13 @@ impl ClientStateExecution for AnyClientState { client_message, update_kind, ), + AnyClientState::Mock(client_state) => client_state + .update_state_on_misbehaviour( + ctx, + client_id, + client_message, + update_kind, + ), } } @@ -259,6 +337,13 @@ impl ClientStateExecution for AnyClientState { upgraded_client_state, upgraded_consensus_state, ), + AnyClientState::Mock(client_state) => client_state + .update_state_on_upgrade( + ctx, + client_id, + upgraded_client_state, + upgraded_consensus_state, + ), } } } @@ -276,6 +361,22 @@ impl ibc::clients::ics07_tendermint::CommonContext for SolanaIbcStorage { } } +impl MockClientContext for SolanaIbcStorage { + type ConversionError = ClientError; + type AnyConsensusState = AnyConsensusState; + + fn consensus_state( + &self, + client_cons_state_path: &ClientConsensusStatePath, + ) -> Result { + ValidationContext::consensus_state(self, client_cons_state_path) + } + + fn host_timestamp(&self) -> Result { + ValidationContext::host_timestamp(self) + } +} + impl ibc::clients::ics07_tendermint::ValidationContext for SolanaIbcStorage { fn host_timestamp(&self) -> Result { ValidationContext::host_timestamp(self) diff --git a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs index 4ef0f862..acaa5a17 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs @@ -1,4 +1,5 @@ -use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; +use ibc::mock::consensus_state::MOCK_CONSENSUS_STATE_TYPE_URL; +use ibc::{clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState, mock::consensus_state::MockConsensusState}; use ibc::core::ics02_client::consensus_state::ConsensusState; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics23_commitment::commitment::CommitmentRoot; @@ -7,6 +8,7 @@ use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState; use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; +use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState; const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ConsensusState"; @@ -15,6 +17,7 @@ const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = #[serde(tag = "type")] pub enum AnyConsensusState { Tendermint(TmConsensusState), + Mock(MockConsensusState) } impl Protobuf for AnyConsensusState {} @@ -32,6 +35,14 @@ impl TryFrom for AnyConsensusState { })?, )) } + MOCK_CONSENSUS_STATE_TYPE_URL => { + Ok(AnyConsensusState::Mock( + Protobuf::::decode_vec(&value.value) + .map_err(|e| ClientError::ClientSpecific { + description: e.to_string(), + })?, + )) + } _ => Err(ClientError::UnknownConsensusStateType { consensus_state_type: value.type_url.clone(), }), @@ -46,6 +57,10 @@ impl From for Any { type_url: TENDERMINT_CONSENSUS_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec(&value), }, + AnyConsensusState::Mock(value) => Any { + type_url: MOCK_CONSENSUS_STATE_TYPE_URL.to_string(), + value: Protobuf::::encode_vec(&value), + }, } } } @@ -56,16 +71,24 @@ impl From for AnyConsensusState { } } +impl From for AnyConsensusState { + fn from(value: MockConsensusState) -> Self { + AnyConsensusState::Mock(value) + } +} + impl ConsensusState for AnyConsensusState { fn root(&self) -> &CommitmentRoot { match self { AnyConsensusState::Tendermint(value) => value.root(), + AnyConsensusState::Mock(value) => value.root(), } } fn timestamp(&self) -> Timestamp { match self { AnyConsensusState::Tendermint(value) => value.timestamp(), + AnyConsensusState::Mock(value) => value.timestamp(), } } @@ -73,6 +96,9 @@ impl ConsensusState for AnyConsensusState { match self { AnyConsensusState::Tendermint(value) => { ibc::core::ics02_client::consensus_state::ConsensusState::encode_vec(value) + }, + AnyConsensusState::Mock(value) => { + ibc::core::ics02_client::consensus_state::ConsensusState::encode_vec(value) } } } @@ -91,6 +117,29 @@ impl TryInto > { match self { AnyConsensusState::Tendermint(value) => Ok(value), + AnyConsensusState::Mock(_) => Err(ClientError::Other { + description: "Cannot convert mock consensus state to tendermint".to_string(), + }), } } } + +impl TryInto + for AnyConsensusState +{ + type Error = ClientError; + + fn try_into( + self, + ) -> Result< + ibc::mock::consensus_state::MockConsensusState, + Self::Error, + > { + match self { + AnyConsensusState::Mock(value) => Ok(value), + AnyConsensusState::Tendermint(_) => Err(ClientError::Other { + description: "Cannot convert tendermint consensus state to mock".to_string(), + }), + } + } +} \ No newline at end of file diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index b69daee9..59ff1e83 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -45,7 +45,9 @@ pub mod solana_ibc { }) .collect::>(); - let _errors = + msg!("These are messages {:?}", all_messages); + + let errors = all_messages.into_iter().fold(vec![], |mut errors, msg| { match ibc::core::MsgEnvelope::try_from(msg) { Ok(msg) => { @@ -63,6 +65,8 @@ pub mod solana_ibc { errors }); + msg!("These are errors {:?}", errors); + Ok(()) } } @@ -71,7 +75,7 @@ pub mod solana_ibc { pub struct Deliver<'info> { #[account(mut)] pub sender: Signer<'info>, - #[account(init, payer = sender, seeds = [SOLANA_IBC_STORAGE_SEED],bump, space = 10000)] + #[account(init_if_needed, payer = sender, seeds = [SOLANA_IBC_STORAGE_SEED],bump, space = 10000)] pub storage: Account<'info, SolanaIbcStorage>, pub system_program: Program<'info, System>, } diff --git a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs index a19c95c6..d4f34e9f 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -93,6 +93,9 @@ impl ValidationContext for SolanaIbcStorage { AnyConsensusState::Tendermint(consensus_state) => { Ok(consensus_state.timestamp.into()) } + AnyConsensusState::Mock(mock_consensus_state) => { + Ok(mock_consensus_state.timestamp().into()) + } } } From 9c30411fa5d3be43ffbaf2088873c4437a6a9370 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 15:21:37 +0530 Subject: [PATCH 02/13] added tendermint patch and updated program id --- Anchor.toml | 4 ++-- Cargo.toml | 1 + solana/solana-ibc/programs/solana-ibc/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Anchor.toml b/Anchor.toml index 56e4887f..f32d2c57 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -2,9 +2,9 @@ seeds = false skip-lint = false [programs.localnet] -solana_ibc = "7MEuaEwNMsjVCJy9N31ZgvQf1dFkRNXYFREaAjMsoE5g" +solana_ibc = "EnfDJsAK7BGgetnmKzBx86CsgC5kfSPcsktFCQ4YLC81" [programs.devnet] -solana_ibc = "7MEuaEwNMsjVCJy9N31ZgvQf1dFkRNXYFREaAjMsoE5g" +solana_ibc = "EnfDJsAK7BGgetnmKzBx86CsgC5kfSPcsktFCQ4YLC81" [registry] url = "https://api.apr.dev" diff --git a/Cargo.toml b/Cargo.toml index 8a221838..83f96716 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,3 +51,4 @@ anyhow = "1.0.32" [patch.crates-io] curve25519-dalek = { git = "https://github.com/dhruvja/curve25519-dalek", branch = "master" } aes-gcm-siv = { git = "https://github.com/dhruvja/AEADs", branch = "main-aes-gcm-siv-v0.10.3" } +tendermint = { git = "https://github.com/mina86/tendermint-rs.git", branch = "33.2-sans-eyre" } diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 59ff1e83..58588453 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -12,7 +12,7 @@ use module_holder::ModuleHolder; const SOLANA_IBC_STORAGE_SEED: &[u8] = b"solana_ibc_storage"; -declare_id!("7MEuaEwNMsjVCJy9N31ZgvQf1dFkRNXYFREaAjMsoE5g"); +declare_id!("EnfDJsAK7BGgetnmKzBx86CsgC5kfSPcsktFCQ4YLC81"); mod client_state; mod consensus_state; From 0a5209c3145d4bbe257a9098a02fafde56b6f44e Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 15:23:45 +0530 Subject: [PATCH 03/13] fix code format --- common/blockchain/src/block.rs | 4 +- common/blockchain/src/candidates.rs | 4 +- common/blockchain/src/candidates/tests.rs | 24 ++++++------ common/blockchain/src/epoch.rs | 8 +++- common/blockchain/src/height.rs | 20 +++++++--- common/blockchain/src/validators.rs | 8 +++- common/lib/src/hash.rs | 24 +++++++++--- common/lib/src/varint.rs | 26 ++++++++----- common/memory/src/lib.rs | 12 ++++-- common/sealable-trie/src/bits.rs | 26 ++++++++----- common/sealable-trie/src/nodes.rs | 33 ++++++++++++----- common/sealable-trie/src/proof.rs | 32 ++++++++++++---- .../sealable-trie/src/proof/serialisation.rs | 8 ++-- common/sealable-trie/src/trie.rs | 13 +++++-- common/sealable-trie/src/trie/tests.rs | 12 ++++-- .../solana-ibc/src/consensus_state.rs | 37 ++++++++++--------- .../solana-ibc/src/execution_context.rs | 4 +- .../solana-ibc/programs/solana-ibc/src/lib.rs | 4 +- .../programs/solana-ibc/src/module_holder.rs | 4 +- .../solana-ibc/src/validation_context.rs | 4 +- solana/trie-example/src/lib.rs | 1 - solana/trie-example/src/trie.rs | 11 +++--- 22 files changed, 211 insertions(+), 108 deletions(-) diff --git a/common/blockchain/src/block.rs b/common/blockchain/src/block.rs index 2b11aa48..394454f3 100644 --- a/common/blockchain/src/block.rs +++ b/common/blockchain/src/block.rs @@ -60,8 +60,8 @@ pub enum GenerateError { impl Block { /// Returns whether the block is a valid genesis block. pub fn is_genesis(&self) -> bool { - self.prev_block_hash == CryptoHash::DEFAULT && - self.epoch_id == CryptoHash::DEFAULT + self.prev_block_hash == CryptoHash::DEFAULT + && self.epoch_id == CryptoHash::DEFAULT } /// Calculates hash of the block. diff --git a/common/blockchain/src/candidates.rs b/common/blockchain/src/candidates.rs index 830916bd..c032cd6d 100644 --- a/common/blockchain/src/candidates.rs +++ b/common/blockchain/src/candidates.rs @@ -160,7 +160,9 @@ impl Candidates { Ok(()) } - fn max_validators(&self) -> usize { usize::from(self.max_validators.get()) } + fn max_validators(&self) -> usize { + usize::from(self.max_validators.get()) + } /// Adds a new candidate at given position. /// diff --git a/common/blockchain/src/candidates/tests.rs b/common/blockchain/src/candidates/tests.rs index 7078781c..a89f3b0e 100644 --- a/common/blockchain/src/candidates/tests.rs +++ b/common/blockchain/src/candidates/tests.rs @@ -109,7 +109,9 @@ fn test_candidates_0() { use candidate as c; use UpdateCandidateError::*; - fn pk(pubkey: char) -> MockPubKey { MockPubKey(pubkey as u32) } + fn pk(pubkey: char) -> MockPubKey { + MockPubKey(pubkey as u32) + } // Create candidates set let mut candidates = Candidates::from_candidates( @@ -239,8 +241,8 @@ impl TestCtx { /// configuration file. fn check(&self) { assert!( - self.candidates.candidates.len() >= - self.config.min_validators.get().into(), + self.candidates.candidates.len() + >= self.config.min_validators.get().into(), "Violated min validators constraint: {} < {}", self.candidates.candidates.len(), self.config.min_validators.get(), @@ -280,14 +282,14 @@ impl TestCtx { .get(usize::from(self.config.max_validators.get())) .map_or(0, |c: &Candidate<_>| c.stake.get()); assert!( - head_stake - old_stake + new_stake < - self.config.min_total_stake.get() + head_stake - old_stake + new_stake + < self.config.min_total_stake.get() ); } NotEnoughValidators => { assert!( - self.candidates.candidates.len() <= - self.config.min_validators.get().into() + self.candidates.candidates.len() + <= self.config.min_validators.get().into() ); } } @@ -359,8 +361,8 @@ impl TestCtx { .candidates .get(usize::from(self.config.max_validators.get())); let kicked_out = last.clone().map_or(false, |candidiate| { - candidiate < - &Candidate { + candidiate + < &Candidate { pubkey, stake: NonZeroU128::new(new_stake).unwrap(), } @@ -370,8 +372,8 @@ impl TestCtx { if kicked_out { last.unwrap().stake.get() } else { new_stake }; assert!( - self.candidates.head_stake - old_stake + new_stake < - self.config.min_total_stake.get() + self.candidates.head_stake - old_stake + new_stake + < self.config.min_total_stake.get() ); } diff --git a/common/blockchain/src/epoch.rs b/common/blockchain/src/epoch.rs index 97dae879..74366e1a 100644 --- a/common/blockchain/src/epoch.rs +++ b/common/blockchain/src/epoch.rs @@ -82,10 +82,14 @@ impl Epoch { } /// Returns list of all validators in the epoch. - pub fn validators(&self) -> &[Validator] { self.validators.as_slice() } + pub fn validators(&self) -> &[Validator] { + self.validators.as_slice() + } /// Returns stake needed to reach quorum. - pub fn quorum_stake(&self) -> NonZeroU128 { self.quorum_stake } + pub fn quorum_stake(&self) -> NonZeroU128 { + self.quorum_stake + } /// Finds a validator by their public key. pub fn validator(&self, pk: &PK) -> Option<&Validator> diff --git a/common/blockchain/src/height.rs b/common/blockchain/src/height.rs index 20f5f1dc..3985871f 100644 --- a/common/blockchain/src/height.rs +++ b/common/blockchain/src/height.rs @@ -53,7 +53,9 @@ pub type BlockDelta = Delta; impl Height { /// Returns the next height, i.e. `self + 1`. - pub fn next(self) -> Self { Self(self.0.checked_add(1).unwrap(), self.1) } + pub fn next(self) -> Self { + Self(self.0.checked_add(1).unwrap(), self.1) + } /// Checks whether delta between two heights is at least `min`. /// @@ -64,19 +66,27 @@ impl Height { } impl From for Height { - fn from(value: u64) -> Self { Self(value, Default::default()) } + fn from(value: u64) -> Self { + Self(value, Default::default()) + } } impl From for Delta { - fn from(value: u64) -> Self { Self(value, Default::default()) } + fn from(value: u64) -> Self { + Self(value, Default::default()) + } } impl From> for u64 { - fn from(value: Height) -> u64 { value.0 } + fn from(value: Height) -> u64 { + value.0 + } } impl From> for u64 { - fn from(value: Delta) -> u64 { value.0 } + fn from(value: Delta) -> u64 { + value.0 + } } impl core::fmt::Display for Height { diff --git a/common/blockchain/src/validators.rs b/common/blockchain/src/validators.rs index d6624159..2507e100 100644 --- a/common/blockchain/src/validators.rs +++ b/common/blockchain/src/validators.rs @@ -50,9 +50,13 @@ impl Validator { Self { version: crate::common::VersionZero, pubkey, stake } } - pub fn pubkey(&self) -> &PK { &self.pubkey } + pub fn pubkey(&self) -> &PK { + &self.pubkey + } - pub fn stake(&self) -> NonZeroU128 { self.stake } + pub fn stake(&self) -> NonZeroU128 { + self.stake + } } #[cfg(test)] diff --git a/common/lib/src/hash.rs b/common/lib/src/hash.rs index 8e375f4d..5461bf06 100644 --- a/common/lib/src/hash.rs +++ b/common/lib/src/hash.rs @@ -38,7 +38,9 @@ impl CryptoHash { /// Returns a builder which can be used to construct cryptographic hash by /// digesting bytes. #[inline] - pub fn builder() -> Builder { Builder::default() } + pub fn builder() -> Builder { + Builder::default() + } /// Returns hash of given bytes. #[inline] @@ -87,7 +89,9 @@ impl CryptoHash { /// Returns a shared reference to the hash as slice of bytes. #[inline] - pub fn as_slice(&self) -> &[u8] { &self.0[..] } + pub fn as_slice(&self) -> &[u8] { + &self.0[..] + } } impl core::fmt::Display for CryptoHash { @@ -119,7 +123,9 @@ impl<'a> From<&'a [u8; CryptoHash::LENGTH]> for CryptoHash { impl From<&'_ CryptoHash> for [u8; CryptoHash::LENGTH] { #[inline] - fn from(hash: &'_ CryptoHash) -> Self { hash.0 } + fn from(hash: &'_ CryptoHash) -> Self { + hash.0 + } } impl<'a> From<&'a [u8; CryptoHash::LENGTH]> for &'a CryptoHash { @@ -184,11 +190,15 @@ pub struct Builder(sha2::Sha256); impl Builder { /// Process data, updating the internal state of the digest. #[inline] - pub fn update(&mut self, bytes: &[u8]) { self.0.update(bytes) } + pub fn update(&mut self, bytes: &[u8]) { + self.0.update(bytes) + } /// Finalises the digest and returns the cryptographic hash. #[inline] - pub fn build(self) -> CryptoHash { CryptoHash(self.0.finalize().into()) } + pub fn build(self) -> CryptoHash { + CryptoHash(self.0.finalize().into()) + } } #[cfg(feature = "borsh")] @@ -202,7 +212,9 @@ impl io::Write for Builder { Ok(self.update(buf)) } - fn flush(&mut self) -> io::Result<()> { Ok(()) } + fn flush(&mut self) -> io::Result<()> { + Ok(()) + } } #[test] diff --git a/common/lib/src/varint.rs b/common/lib/src/varint.rs index 63f6b4bd..57dd298e 100644 --- a/common/lib/src/varint.rs +++ b/common/lib/src/varint.rs @@ -104,16 +104,18 @@ impl borsh::BorshDeserialize for VarInt { #[inline] fn deserialize_reader(reader: &mut R) -> io::Result { read_u32(|| u8::deserialize_reader(reader)).map(Self).map_err(|err| { - io::Error::new(io::ErrorKind::InvalidData, match err { - ReadError::ReaderError(err) => return err, - ReadError::Overlong => "overlong", - ReadError::Overflow => "overflow", - }) + io::Error::new( + io::ErrorKind::InvalidData, + match err { + ReadError::ReaderError(err) => return err, + ReadError::Overlong => "overlong", + ReadError::Overflow => "overflow", + }, + ) }) } } - /// Small on-stack buffer. /// /// # Example @@ -135,7 +137,9 @@ pub struct Buffer { } impl Buffer { - fn new() -> Self { Self { len: 0, data: [0; N] } } + fn new() -> Self { + Self { len: 0, data: [0; N] } + } fn push_or_panic(&mut self, byte: u8) { self.data[usize::from(self.len)] = byte; @@ -152,12 +156,16 @@ impl Buffer { impl core::ops::Deref for Buffer { type Target = [u8]; #[inline] - fn deref(&self) -> &[u8] { self.as_slice() } + fn deref(&self) -> &[u8] { + self.as_slice() + } } impl core::convert::AsRef<[u8]> for Buffer { #[inline] - fn as_ref(&self) -> &[u8] { self.as_slice() } + fn as_ref(&self) -> &[u8] { + self.as_slice() + } } #[cfg(test)] diff --git a/common/memory/src/lib.rs b/common/memory/src/lib.rs index b4b1e9bc..a8698df7 100644 --- a/common/memory/src/lib.rs +++ b/common/memory/src/lib.rs @@ -192,7 +192,9 @@ impl<'a, A: Allocator> WriteLog<'a, A> { } /// Returns underlying allocator. - pub fn allocator(&self) -> &A { &*self.alloc } + pub fn allocator(&self) -> &A { + &*self.alloc + } pub fn alloc(&mut self, value: A::Value) -> Result { let ptr = self.alloc.alloc(value)?; @@ -204,7 +206,9 @@ impl<'a, A: Allocator> WriteLog<'a, A> { self.write_log.push((ptr, value)) } - pub fn free(&mut self, ptr: Ptr) { self.freed.push(ptr); } + pub fn free(&mut self, ptr: Ptr) { + self.freed.push(ptr); + } } impl<'a, A: Allocator> core::ops::Drop for WriteLog<'a, A> { @@ -235,7 +239,9 @@ pub mod test_utils { Self { count: 0, pool, free_list: Default::default() } } - pub fn count(&self) -> usize { self.count } + pub fn count(&self) -> usize { + self.count + } /// Gets index in the memory pool for the given pointer. /// diff --git a/common/sealable-trie/src/bits.rs b/common/sealable-trie/src/bits.rs index 2a965d64..5d3327fe 100644 --- a/common/sealable-trie/src/bits.rs +++ b/common/sealable-trie/src/bits.rs @@ -88,11 +88,15 @@ impl<'a> Slice<'a> { /// Returns length of the slice in bits. #[inline] - pub fn len(&self) -> u16 { self.length } + pub fn len(&self) -> u16 { + self.length + } /// Returns whether the slice is empty. #[inline] - pub fn is_empty(&self) -> bool { self.length == 0 } + pub fn is_empty(&self) -> bool { + self.length == 0 + } /// Returns the first bit in the slice advances the slice by one position. /// @@ -210,7 +214,9 @@ impl<'a> Slice<'a> { /// may be shorter than 272 bits (i.e. 34 * 8) however it will span full 34 /// bytes. #[inline] - pub fn chunks(&self) -> Chunks<'a> { Chunks(*self) } + pub fn chunks(&self) -> Chunks<'a> { + Chunks(*self) + } /// Splits slice into two at given index. /// @@ -372,10 +378,10 @@ impl<'a> Slice<'a> { fn check_bytes(bytes: &[u8], offset: u8, length: u16) -> bool { let (front, back) = Self::masks(offset, length); let bytes_len = (usize::from(offset) + usize::from(length) + 7) / 8; - bytes_len <= bytes.len() && - (bytes[0] & !front) == 0 && - (bytes[bytes_len - 1] & !back) == 0 && - bytes[bytes_len..].iter().all(|&b| b == 0) + bytes_len <= bytes.len() + && (bytes[0] & !front) == 0 + && (bytes[bytes_len - 1] & !back) == 0 + && bytes[bytes_len..].iter().all(|&b| b == 0) } /// Returns total number of underlying bits, i.e. bits in the slice plus the @@ -529,9 +535,9 @@ impl core::cmp::PartialEq for Slice<'_> { if len == 1 { ((lhs[0] ^ rhs[0]) & front & back) == 0 } else { - ((lhs[0] ^ rhs[0]) & front) == 0 && - ((lhs[len - 1] ^ rhs[len - 1]) & back) == 0 && - lhs[1..len - 1] == rhs[1..len - 1] + ((lhs[0] ^ rhs[0]) & front) == 0 + && ((lhs[len - 1] ^ rhs[len - 1]) & back) == 0 + && lhs[1..len - 1] == rhs[1..len - 1] } } } diff --git a/common/sealable-trie/src/nodes.rs b/common/sealable-trie/src/nodes.rs index e714f9fd..8d76d269 100644 --- a/common/sealable-trie/src/nodes.rs +++ b/common/sealable-trie/src/nodes.rs @@ -196,8 +196,8 @@ impl<'a, P, S> Node<'a, P, S> { Node::Branch { children: [left, right] } => { // tag = 0b0000_00xy where x and y indicate whether left and // right children respectively are value references. - let tag = (u8::from(left.is_value()) << 1) | - u8::from(right.is_value()); + let tag = (u8::from(left.is_value()) << 1) + | u8::from(right.is_value()); tag_hash_hash(&mut buf, tag, left.hash(), right.hash()) } Node::Value { value, child } => { @@ -339,10 +339,14 @@ impl RawNode { } /// Returns the first byte in the raw representation. - fn first(&self) -> u8 { self.0[0] } + fn first(&self) -> u8 { + self.0[0] + } /// Splits the raw byte representation in two halfs. - fn halfs(&self) -> (&[u8; 36], &[u8; 36]) { stdx::split_array_ref(&self.0) } + fn halfs(&self) -> (&[u8; 36], &[u8; 36]) { + stdx::split_array_ref(&self.0) + } /// Splits the raw byte representation in two halfs. fn halfs_mut(&mut self) -> (&mut [u8; 36], &mut [u8; 36]) { @@ -352,10 +356,14 @@ impl RawNode { impl<'a, P, S> Reference<'a, P, S> { /// Returns whether the reference is to a node. - pub fn is_node(&self) -> bool { matches!(self, Self::Node(_)) } + pub fn is_node(&self) -> bool { + matches!(self, Self::Node(_)) + } /// Returns whether the reference is to a value. - pub fn is_value(&self) -> bool { matches!(self, Self::Value(_)) } + pub fn is_value(&self) -> bool { + matches!(self, Self::Value(_)) + } /// Returns node’s or value’s hash depending on type of reference. /// @@ -460,13 +468,17 @@ impl<'a> Reference<'a, (), ()> { impl<'a, P> NodeRef<'a, P> { /// Constructs a new node reference. #[inline] - pub fn new(ptr: P, hash: &'a CryptoHash) -> Self { Self { ptr, hash } } + pub fn new(ptr: P, hash: &'a CryptoHash) -> Self { + Self { ptr, hash } + } } impl<'a> NodeRef<'a, Option> { /// Returns sealed version of the reference. The hash remains unchanged. #[inline] - pub fn sealed(self) -> Self { Self { ptr: None, hash: self.hash } } + pub fn sealed(self) -> Self { + Self { ptr: None, hash: self.hash } + } } impl<'a, S> ValueRef<'a, S> { @@ -480,10 +492,11 @@ impl<'a, S> ValueRef<'a, S> { impl<'a> ValueRef<'a, bool> { /// Returns sealed version of the reference. The hash remains unchanged. #[inline] - pub fn sealed(self) -> Self { Self { is_sealed: true, hash: self.hash } } + pub fn sealed(self) -> Self { + Self { is_sealed: true, hash: self.hash } + } } - // ============================================================================= // Conversions diff --git a/common/sealable-trie/src/proof.rs b/common/sealable-trie/src/proof.rs index 06413f53..1cb66a67 100644 --- a/common/sealable-trie/src/proof.rs +++ b/common/sealable-trie/src/proof.rs @@ -99,7 +99,9 @@ impl Proof { } /// Creates a builder which allows creation of proofs. - pub(crate) fn builder() -> Builder { Builder(Vec::new()) } + pub(crate) fn builder() -> Builder { + Builder(Vec::new()) + } } impl Membership { @@ -254,7 +256,9 @@ impl Item { impl Builder { /// Adds a new item to the proof. - pub fn push(&mut self, item: Item) { self.0.push(item); } + pub fn push(&mut self, item: Item) { + self.0.push(item); + } /// Reverses order of items in the builder. /// @@ -268,7 +272,9 @@ impl Builder { } /// Constructs a new membership proof from added items. - pub fn build>(self) -> T { T::from(Membership(self.0)) } + pub fn build>(self) -> T { + T::from(Membership(self.0)) + } /// Constructs a new non-membership proof from added items and given /// ‘actual’ entry. @@ -332,11 +338,17 @@ impl Builder { impl OwnedRef { /// Creates a reference pointing at node with given hash. - fn node(hash: CryptoHash) -> Self { Self { is_value: false, hash } } + fn node(hash: CryptoHash) -> Self { + Self { is_value: false, hash } + } /// Creates a reference pointing at value with given hash. - fn value(hash: CryptoHash) -> Self { Self { is_value: true, hash } } + fn value(hash: CryptoHash) -> Self { + Self { is_value: true, hash } + } /// Creates a reference pointing at given node. - fn to(node: Node) -> Self { Self::node(node.hash()) } + fn to(node: Node) -> Self { + Self::node(node.hash()) + } #[cfg(test)] #[allow(dead_code)] @@ -356,11 +368,15 @@ impl<'a, P, S> From<&'a Reference<'a, P, S>> for OwnedRef { } impl<'a, P, S> From> for OwnedRef { - fn from(rf: Reference<'a, P, S>) -> OwnedRef { Self::from(&rf) } + fn from(rf: Reference<'a, P, S>) -> OwnedRef { + Self::from(&rf) + } } impl<'a> From<&'a OwnedRef> for Reference<'a, (), ()> { - fn from(rf: &'a OwnedRef) -> Self { Self::new(rf.is_value, &rf.hash) } + fn from(rf: &'a OwnedRef) -> Self { + Self::new(rf.is_value, &rf.hash) + } } #[test] diff --git a/common/sealable-trie/src/proof/serialisation.rs b/common/sealable-trie/src/proof/serialisation.rs index ebc393d7..67885839 100644 --- a/common/sealable-trie/src/proof/serialisation.rs +++ b/common/sealable-trie/src/proof/serialisation.rs @@ -281,7 +281,6 @@ fn invalid_data(msg: String) -> io::Error { io::Error::new(io::ErrorKind::InvalidData, msg) } - #[test] fn test_item_borsh() { #[track_caller] @@ -466,9 +465,10 @@ fn test_proof_borsh() { &[4, 32, 42, 32, 42], ); test(Proof::Negative(super::NonMembership(None, vec![])), &[1]); - test(Proof::Negative(super::NonMembership(None, vec![item.clone()])), &[ - 3, 32, 42, - ]); + test( + Proof::Negative(super::NonMembership(None, vec![item.clone()])), + &[3, 32, 42], + ); test( Proof::Negative(super::NonMembership( Some(actual.clone().into()), diff --git a/common/sealable-trie/src/trie.rs b/common/sealable-trie/src/trie.rs index 2257bc5b..d1aca515 100644 --- a/common/sealable-trie/src/trie.rs +++ b/common/sealable-trie/src/trie.rs @@ -87,7 +87,9 @@ pub enum Error { } impl From for Error { - fn from(_: memory::OutOfMemory) -> Self { Self::OutOfMemory } + fn from(_: memory::OutOfMemory) -> Self { + Self::OutOfMemory + } } type Result = ::core::result::Result; @@ -112,10 +114,14 @@ impl> Trie { } /// Returns hash of the root node. - pub fn hash(&self) -> &CryptoHash { &self.root_hash } + pub fn hash(&self) -> &CryptoHash { + &self.root_hash + } /// Returns whether the trie is empty. - pub fn is_empty(&self) -> bool { self.root_hash == EMPTY_TRIE_ROOT } + pub fn is_empty(&self) -> bool { + self.root_hash == EMPTY_TRIE_ROOT + } /// Deconstructs the object into the individual parts — allocator, root /// pointer and root hash. @@ -328,7 +334,6 @@ impl> Trie { } } - #[cfg(test)] impl Trie> { /// Creates a test trie using a TestAllocator with given capacity. diff --git a/common/sealable-trie/src/trie/tests.rs b/common/sealable-trie/src/trie/tests.rs index 06299cb0..f780299a 100644 --- a/common/sealable-trie/src/trie/tests.rs +++ b/common/sealable-trie/src/trie/tests.rs @@ -19,7 +19,9 @@ fn do_test_inserts<'a>( } #[test] -fn test_msb_difference() { do_test_inserts([&[0][..], &[0x80][..]], true); } +fn test_msb_difference() { + do_test_inserts([&[0][..], &[0x80][..]], true); +} #[test] fn test_sequence() { @@ -86,11 +88,15 @@ struct Key { } impl Key { - fn as_bytes(&self) -> &[u8] { &self.buf[..usize::from(self.len)] } + fn as_bytes(&self) -> &[u8] { + &self.buf[..usize::from(self.len)] + } } impl core::cmp::PartialEq for Key { - fn eq(&self, other: &Self) -> bool { self.as_bytes() == other.as_bytes() } + fn eq(&self, other: &Self) -> bool { + self.as_bytes() == other.as_bytes() + } } impl core::cmp::PartialOrd for Key { diff --git a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs index acaa5a17..1cd6a6f4 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs @@ -1,14 +1,17 @@ -use ibc::mock::consensus_state::MOCK_CONSENSUS_STATE_TYPE_URL; -use ibc::{clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState, mock::consensus_state::MockConsensusState}; use ibc::core::ics02_client::consensus_state::ConsensusState; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics23_commitment::commitment::CommitmentRoot; use ibc::core::timestamp::Timestamp; +use ibc::mock::consensus_state::MOCK_CONSENSUS_STATE_TYPE_URL; +use ibc::{ + clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState, + mock::consensus_state::MockConsensusState, +}; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState; +use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState; use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; -use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState; const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ConsensusState"; @@ -17,7 +20,7 @@ const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = #[serde(tag = "type")] pub enum AnyConsensusState { Tendermint(TmConsensusState), - Mock(MockConsensusState) + Mock(MockConsensusState), } impl Protobuf for AnyConsensusState {} @@ -35,14 +38,12 @@ impl TryFrom for AnyConsensusState { })?, )) } - MOCK_CONSENSUS_STATE_TYPE_URL => { - Ok(AnyConsensusState::Mock( - Protobuf::::decode_vec(&value.value) - .map_err(|e| ClientError::ClientSpecific { + MOCK_CONSENSUS_STATE_TYPE_URL => Ok(AnyConsensusState::Mock( + Protobuf::::decode_vec(&value.value) + .map_err(|e| ClientError::ClientSpecific { description: e.to_string(), })?, - )) - } + )), _ => Err(ClientError::UnknownConsensusStateType { consensus_state_type: value.type_url.clone(), }), @@ -118,7 +119,9 @@ impl TryInto match self { AnyConsensusState::Tendermint(value) => Ok(value), AnyConsensusState::Mock(_) => Err(ClientError::Other { - description: "Cannot convert mock consensus state to tendermint".to_string(), + description: + "Cannot convert mock consensus state to tendermint" + .to_string(), }), } } @@ -131,15 +134,15 @@ impl TryInto fn try_into( self, - ) -> Result< - ibc::mock::consensus_state::MockConsensusState, - Self::Error, - > { + ) -> Result + { match self { AnyConsensusState::Mock(value) => Ok(value), AnyConsensusState::Tendermint(_) => Err(ClientError::Other { - description: "Cannot convert tendermint consensus state to mock".to_string(), + description: + "Cannot convert tendermint consensus state to mock" + .to_string(), }), } } -} \ No newline at end of file +} diff --git a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs index cfb56b9c..9ad08f5e 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -370,7 +370,9 @@ impl ExecutionContext for SolanaIbcStorage { Ok(()) } - fn get_client_execution_context(&mut self) -> &mut Self::E { self } + fn get_client_execution_context(&mut self) -> &mut Self::E { + self + } } fn record_packet_sequence( diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 58588453..29bfa9be 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -201,7 +201,9 @@ pub trait SolanaIbcStorageHost { todo!() } /// - fn set_solana_ibc_store(_store: &SolanaIbcStorage) { todo!() } + fn set_solana_ibc_store(_store: &SolanaIbcStorage) { + todo!() + } } impl Router for SolanaIbcStorage { diff --git a/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs b/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs index 391c42a5..b2aab8b2 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs @@ -9,7 +9,9 @@ pub struct ModuleHolder { } impl ModuleHolder { - pub fn new(account: Pubkey) -> Self { Self { account } } + pub fn new(account: Pubkey) -> Self { + Self { account } + } /// pub fn get_module_id(&self, port_id: &PortId) -> Option { match port_id.as_str() { diff --git a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs index d4f34e9f..17511f9c 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -402,7 +402,7 @@ fn calculate_block_delay( if max_expected_time_per_block.is_zero() { return 0; } - let delay = delay_period_time.as_secs_f64() / - max_expected_time_per_block.as_secs_f64(); + let delay = delay_period_time.as_secs_f64() + / max_expected_time_per_block.as_secs_f64(); delay.ceil() as u64 } diff --git a/solana/trie-example/src/lib.rs b/solana/trie-example/src/lib.rs index c28564d8..ce808e9d 100644 --- a/solana/trie-example/src/lib.rs +++ b/solana/trie-example/src/lib.rs @@ -72,7 +72,6 @@ impl TrieResultExt for Result { } } - /// Instruction to execute. pub(crate) enum Instruction<'a> { // Encoding: diff --git a/solana/trie-example/src/trie.rs b/solana/trie-example/src/trie.rs index 6456879c..ff7e6557 100644 --- a/solana/trie-example/src/trie.rs +++ b/solana/trie-example/src/trie.rs @@ -211,15 +211,17 @@ impl<'a, 'b> memory::Allocator for Allocator<'a, 'b> { } } - - impl<'a, 'b> core::ops::Deref for AccountTrie<'a, 'b> { type Target = sealable_trie::Trie>; - fn deref(&self) -> &Self::Target { &self.0 } + fn deref(&self) -> &Self::Target { + &self.0 + } } impl<'a, 'b> core::ops::DerefMut for AccountTrie<'a, 'b> { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } } /// Reads fixed-width value from start of the buffer and returns the value and @@ -249,7 +251,6 @@ fn write( right } - #[test] fn test_header_encoding() { const ONE: CryptoHash = CryptoHash([1; 32]); From 08c7dfe9375fae092aa09a06e075ca3db94af6a2 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 17:13:07 +0530 Subject: [PATCH 04/13] fix issues in contract --- .../programs/solana-ibc/src/client_state.rs | 12 ++++++++++-- .../programs/solana-ibc/src/execution_context.rs | 3 ++- solana/solana-ibc/programs/solana-ibc/src/lib.rs | 11 ++++++----- solana/solana-ibc/programs/solana-ibc/src/tests.rs | 4 +++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index 44d4bbe2..f325e5d4 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -1,3 +1,4 @@ +use anchor_lang::solana_program::msg; use ibc::clients::ics07_tendermint::client_state::ClientState as TmClientState; use ibc::core::ics02_client::client_state::{ ClientStateCommon, ClientStateExecution, ClientStateValidation, UpdateKind, @@ -164,14 +165,21 @@ impl ClientStateCommon for AnyClientState { } fn latest_height(&self) -> Height { - match self { + msg!("Fetching the height"); + let height = match self { AnyClientState::Tendermint(client_state) => { client_state.latest_height() } AnyClientState::Mock(mock_client_state) => { + msg!( + "This is latest height {:?}", + mock_client_state.latest_height() + ); mock_client_state.latest_height() } - } + }; + msg!("This was the height {}", height); + height } fn validate_proof_height( diff --git a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs index 9ad08f5e..7d6b2669 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -44,7 +44,7 @@ impl ClientExecutionContext for SolanaIbcStorage { msg!( "store_client_state - path: {}, client_state: {:?}", client_state_path, - client_state + client_state, ); let client_state_key = client_state_path.0.to_string(); let serialized_client_state = @@ -84,6 +84,7 @@ impl ExecutionContext for SolanaIbcStorage { height: Height, timestamp: Timestamp, ) -> Result { + msg!("I am here inside update time"); msg!( "store_update_time - client_id: {}, height: {}, timestamp: {}", client_id, diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 29bfa9be..6b60ff19 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -46,16 +46,16 @@ pub mod solana_ibc { .collect::>(); msg!("These are messages {:?}", all_messages); + solana_ibc_store.channel_counter = + solana_ibc_store.channel_counter.checked_add(10).unwrap(); + let router = &mut solana_ibc_store.clone(); let errors = all_messages.into_iter().fold(vec![], |mut errors, msg| { match ibc::core::MsgEnvelope::try_from(msg) { Ok(msg) => { - match ibc::core::dispatch( - &mut solana_ibc_store.clone(), - solana_ibc_store, - msg, - ) { + match ibc::core::dispatch(solana_ibc_store, router, msg) + { Ok(()) => (), Err(e) => errors.push(e), } @@ -66,6 +66,7 @@ pub mod solana_ibc { }); msg!("These are errors {:?}", errors); + msg!("This is final structure {:?}", solana_ibc_store); Ok(()) } diff --git a/solana/solana-ibc/programs/solana-ibc/src/tests.rs b/solana/solana-ibc/programs/solana-ibc/src/tests.rs index 780047a7..f5f25b18 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/tests.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/tests.rs @@ -93,9 +93,11 @@ fn anchor_test_deliver() -> Result<()> { println!("demo sig: {sig}"); // Retrieve and validate state - let _solana_ibc_storage_account: SolanaIbcStorage = + let solana_ibc_storage_account: SolanaIbcStorage = program.account(solana_ibc_storage).unwrap(); + println!("This is solana storage account {:?}", solana_ibc_storage_account); + Ok(()) } From aa14b29c915174a1c69b415e6bc200ac97295243 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Fri, 13 Oct 2023 13:45:58 +0200 Subject: [PATCH 05/13] cargo +nightly fmt --- common/blockchain/src/block.rs | 4 +-- common/blockchain/src/candidates.rs | 4 +-- common/blockchain/src/candidates/tests.rs | 24 +++++++------- common/blockchain/src/epoch.rs | 8 ++--- common/blockchain/src/height.rs | 20 +++--------- common/blockchain/src/validators.rs | 8 ++--- common/lib/src/hash.rs | 24 ++++---------- common/lib/src/varint.rs | 25 +++++---------- common/memory/src/lib.rs | 12 ++----- common/sealable-trie/src/bits.rs | 26 ++++++--------- common/sealable-trie/src/nodes.rs | 32 ++++++------------- common/sealable-trie/src/proof.rs | 32 +++++-------------- .../sealable-trie/src/proof/serialisation.rs | 7 ++-- common/sealable-trie/src/trie.rs | 12 ++----- common/sealable-trie/src/trie/tests.rs | 12 ++----- .../programs/solana-ibc/src/client_state.rs | 8 ++--- .../solana-ibc/src/consensus_state.rs | 19 ++++++----- .../solana-ibc/src/execution_context.rs | 4 +-- .../solana-ibc/programs/solana-ibc/src/lib.rs | 4 +-- .../programs/solana-ibc/src/module_holder.rs | 4 +-- .../solana-ibc/src/validation_context.rs | 4 +-- solana/trie-example/src/trie.rs | 8 ++--- 22 files changed, 94 insertions(+), 207 deletions(-) diff --git a/common/blockchain/src/block.rs b/common/blockchain/src/block.rs index 394454f3..2b11aa48 100644 --- a/common/blockchain/src/block.rs +++ b/common/blockchain/src/block.rs @@ -60,8 +60,8 @@ pub enum GenerateError { impl Block { /// Returns whether the block is a valid genesis block. pub fn is_genesis(&self) -> bool { - self.prev_block_hash == CryptoHash::DEFAULT - && self.epoch_id == CryptoHash::DEFAULT + self.prev_block_hash == CryptoHash::DEFAULT && + self.epoch_id == CryptoHash::DEFAULT } /// Calculates hash of the block. diff --git a/common/blockchain/src/candidates.rs b/common/blockchain/src/candidates.rs index c032cd6d..830916bd 100644 --- a/common/blockchain/src/candidates.rs +++ b/common/blockchain/src/candidates.rs @@ -160,9 +160,7 @@ impl Candidates { Ok(()) } - fn max_validators(&self) -> usize { - usize::from(self.max_validators.get()) - } + fn max_validators(&self) -> usize { usize::from(self.max_validators.get()) } /// Adds a new candidate at given position. /// diff --git a/common/blockchain/src/candidates/tests.rs b/common/blockchain/src/candidates/tests.rs index a89f3b0e..7078781c 100644 --- a/common/blockchain/src/candidates/tests.rs +++ b/common/blockchain/src/candidates/tests.rs @@ -109,9 +109,7 @@ fn test_candidates_0() { use candidate as c; use UpdateCandidateError::*; - fn pk(pubkey: char) -> MockPubKey { - MockPubKey(pubkey as u32) - } + fn pk(pubkey: char) -> MockPubKey { MockPubKey(pubkey as u32) } // Create candidates set let mut candidates = Candidates::from_candidates( @@ -241,8 +239,8 @@ impl TestCtx { /// configuration file. fn check(&self) { assert!( - self.candidates.candidates.len() - >= self.config.min_validators.get().into(), + self.candidates.candidates.len() >= + self.config.min_validators.get().into(), "Violated min validators constraint: {} < {}", self.candidates.candidates.len(), self.config.min_validators.get(), @@ -282,14 +280,14 @@ impl TestCtx { .get(usize::from(self.config.max_validators.get())) .map_or(0, |c: &Candidate<_>| c.stake.get()); assert!( - head_stake - old_stake + new_stake - < self.config.min_total_stake.get() + head_stake - old_stake + new_stake < + self.config.min_total_stake.get() ); } NotEnoughValidators => { assert!( - self.candidates.candidates.len() - <= self.config.min_validators.get().into() + self.candidates.candidates.len() <= + self.config.min_validators.get().into() ); } } @@ -361,8 +359,8 @@ impl TestCtx { .candidates .get(usize::from(self.config.max_validators.get())); let kicked_out = last.clone().map_or(false, |candidiate| { - candidiate - < &Candidate { + candidiate < + &Candidate { pubkey, stake: NonZeroU128::new(new_stake).unwrap(), } @@ -372,8 +370,8 @@ impl TestCtx { if kicked_out { last.unwrap().stake.get() } else { new_stake }; assert!( - self.candidates.head_stake - old_stake + new_stake - < self.config.min_total_stake.get() + self.candidates.head_stake - old_stake + new_stake < + self.config.min_total_stake.get() ); } diff --git a/common/blockchain/src/epoch.rs b/common/blockchain/src/epoch.rs index 74366e1a..97dae879 100644 --- a/common/blockchain/src/epoch.rs +++ b/common/blockchain/src/epoch.rs @@ -82,14 +82,10 @@ impl Epoch { } /// Returns list of all validators in the epoch. - pub fn validators(&self) -> &[Validator] { - self.validators.as_slice() - } + pub fn validators(&self) -> &[Validator] { self.validators.as_slice() } /// Returns stake needed to reach quorum. - pub fn quorum_stake(&self) -> NonZeroU128 { - self.quorum_stake - } + pub fn quorum_stake(&self) -> NonZeroU128 { self.quorum_stake } /// Finds a validator by their public key. pub fn validator(&self, pk: &PK) -> Option<&Validator> diff --git a/common/blockchain/src/height.rs b/common/blockchain/src/height.rs index 3985871f..20f5f1dc 100644 --- a/common/blockchain/src/height.rs +++ b/common/blockchain/src/height.rs @@ -53,9 +53,7 @@ pub type BlockDelta = Delta; impl Height { /// Returns the next height, i.e. `self + 1`. - pub fn next(self) -> Self { - Self(self.0.checked_add(1).unwrap(), self.1) - } + pub fn next(self) -> Self { Self(self.0.checked_add(1).unwrap(), self.1) } /// Checks whether delta between two heights is at least `min`. /// @@ -66,27 +64,19 @@ impl Height { } impl From for Height { - fn from(value: u64) -> Self { - Self(value, Default::default()) - } + fn from(value: u64) -> Self { Self(value, Default::default()) } } impl From for Delta { - fn from(value: u64) -> Self { - Self(value, Default::default()) - } + fn from(value: u64) -> Self { Self(value, Default::default()) } } impl From> for u64 { - fn from(value: Height) -> u64 { - value.0 - } + fn from(value: Height) -> u64 { value.0 } } impl From> for u64 { - fn from(value: Delta) -> u64 { - value.0 - } + fn from(value: Delta) -> u64 { value.0 } } impl core::fmt::Display for Height { diff --git a/common/blockchain/src/validators.rs b/common/blockchain/src/validators.rs index 2507e100..d6624159 100644 --- a/common/blockchain/src/validators.rs +++ b/common/blockchain/src/validators.rs @@ -50,13 +50,9 @@ impl Validator { Self { version: crate::common::VersionZero, pubkey, stake } } - pub fn pubkey(&self) -> &PK { - &self.pubkey - } + pub fn pubkey(&self) -> &PK { &self.pubkey } - pub fn stake(&self) -> NonZeroU128 { - self.stake - } + pub fn stake(&self) -> NonZeroU128 { self.stake } } #[cfg(test)] diff --git a/common/lib/src/hash.rs b/common/lib/src/hash.rs index 5461bf06..8e375f4d 100644 --- a/common/lib/src/hash.rs +++ b/common/lib/src/hash.rs @@ -38,9 +38,7 @@ impl CryptoHash { /// Returns a builder which can be used to construct cryptographic hash by /// digesting bytes. #[inline] - pub fn builder() -> Builder { - Builder::default() - } + pub fn builder() -> Builder { Builder::default() } /// Returns hash of given bytes. #[inline] @@ -89,9 +87,7 @@ impl CryptoHash { /// Returns a shared reference to the hash as slice of bytes. #[inline] - pub fn as_slice(&self) -> &[u8] { - &self.0[..] - } + pub fn as_slice(&self) -> &[u8] { &self.0[..] } } impl core::fmt::Display for CryptoHash { @@ -123,9 +119,7 @@ impl<'a> From<&'a [u8; CryptoHash::LENGTH]> for CryptoHash { impl From<&'_ CryptoHash> for [u8; CryptoHash::LENGTH] { #[inline] - fn from(hash: &'_ CryptoHash) -> Self { - hash.0 - } + fn from(hash: &'_ CryptoHash) -> Self { hash.0 } } impl<'a> From<&'a [u8; CryptoHash::LENGTH]> for &'a CryptoHash { @@ -190,15 +184,11 @@ pub struct Builder(sha2::Sha256); impl Builder { /// Process data, updating the internal state of the digest. #[inline] - pub fn update(&mut self, bytes: &[u8]) { - self.0.update(bytes) - } + pub fn update(&mut self, bytes: &[u8]) { self.0.update(bytes) } /// Finalises the digest and returns the cryptographic hash. #[inline] - pub fn build(self) -> CryptoHash { - CryptoHash(self.0.finalize().into()) - } + pub fn build(self) -> CryptoHash { CryptoHash(self.0.finalize().into()) } } #[cfg(feature = "borsh")] @@ -212,9 +202,7 @@ impl io::Write for Builder { Ok(self.update(buf)) } - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } #[test] diff --git a/common/lib/src/varint.rs b/common/lib/src/varint.rs index 57dd298e..aa76a235 100644 --- a/common/lib/src/varint.rs +++ b/common/lib/src/varint.rs @@ -104,14 +104,11 @@ impl borsh::BorshDeserialize for VarInt { #[inline] fn deserialize_reader(reader: &mut R) -> io::Result { read_u32(|| u8::deserialize_reader(reader)).map(Self).map_err(|err| { - io::Error::new( - io::ErrorKind::InvalidData, - match err { - ReadError::ReaderError(err) => return err, - ReadError::Overlong => "overlong", - ReadError::Overflow => "overflow", - }, - ) + io::Error::new(io::ErrorKind::InvalidData, match err { + ReadError::ReaderError(err) => return err, + ReadError::Overlong => "overlong", + ReadError::Overflow => "overflow", + }) }) } } @@ -137,9 +134,7 @@ pub struct Buffer { } impl Buffer { - fn new() -> Self { - Self { len: 0, data: [0; N] } - } + fn new() -> Self { Self { len: 0, data: [0; N] } } fn push_or_panic(&mut self, byte: u8) { self.data[usize::from(self.len)] = byte; @@ -156,16 +151,12 @@ impl Buffer { impl core::ops::Deref for Buffer { type Target = [u8]; #[inline] - fn deref(&self) -> &[u8] { - self.as_slice() - } + fn deref(&self) -> &[u8] { self.as_slice() } } impl core::convert::AsRef<[u8]> for Buffer { #[inline] - fn as_ref(&self) -> &[u8] { - self.as_slice() - } + fn as_ref(&self) -> &[u8] { self.as_slice() } } #[cfg(test)] diff --git a/common/memory/src/lib.rs b/common/memory/src/lib.rs index a8698df7..b4b1e9bc 100644 --- a/common/memory/src/lib.rs +++ b/common/memory/src/lib.rs @@ -192,9 +192,7 @@ impl<'a, A: Allocator> WriteLog<'a, A> { } /// Returns underlying allocator. - pub fn allocator(&self) -> &A { - &*self.alloc - } + pub fn allocator(&self) -> &A { &*self.alloc } pub fn alloc(&mut self, value: A::Value) -> Result { let ptr = self.alloc.alloc(value)?; @@ -206,9 +204,7 @@ impl<'a, A: Allocator> WriteLog<'a, A> { self.write_log.push((ptr, value)) } - pub fn free(&mut self, ptr: Ptr) { - self.freed.push(ptr); - } + pub fn free(&mut self, ptr: Ptr) { self.freed.push(ptr); } } impl<'a, A: Allocator> core::ops::Drop for WriteLog<'a, A> { @@ -239,9 +235,7 @@ pub mod test_utils { Self { count: 0, pool, free_list: Default::default() } } - pub fn count(&self) -> usize { - self.count - } + pub fn count(&self) -> usize { self.count } /// Gets index in the memory pool for the given pointer. /// diff --git a/common/sealable-trie/src/bits.rs b/common/sealable-trie/src/bits.rs index 5d3327fe..2a965d64 100644 --- a/common/sealable-trie/src/bits.rs +++ b/common/sealable-trie/src/bits.rs @@ -88,15 +88,11 @@ impl<'a> Slice<'a> { /// Returns length of the slice in bits. #[inline] - pub fn len(&self) -> u16 { - self.length - } + pub fn len(&self) -> u16 { self.length } /// Returns whether the slice is empty. #[inline] - pub fn is_empty(&self) -> bool { - self.length == 0 - } + pub fn is_empty(&self) -> bool { self.length == 0 } /// Returns the first bit in the slice advances the slice by one position. /// @@ -214,9 +210,7 @@ impl<'a> Slice<'a> { /// may be shorter than 272 bits (i.e. 34 * 8) however it will span full 34 /// bytes. #[inline] - pub fn chunks(&self) -> Chunks<'a> { - Chunks(*self) - } + pub fn chunks(&self) -> Chunks<'a> { Chunks(*self) } /// Splits slice into two at given index. /// @@ -378,10 +372,10 @@ impl<'a> Slice<'a> { fn check_bytes(bytes: &[u8], offset: u8, length: u16) -> bool { let (front, back) = Self::masks(offset, length); let bytes_len = (usize::from(offset) + usize::from(length) + 7) / 8; - bytes_len <= bytes.len() - && (bytes[0] & !front) == 0 - && (bytes[bytes_len - 1] & !back) == 0 - && bytes[bytes_len..].iter().all(|&b| b == 0) + bytes_len <= bytes.len() && + (bytes[0] & !front) == 0 && + (bytes[bytes_len - 1] & !back) == 0 && + bytes[bytes_len..].iter().all(|&b| b == 0) } /// Returns total number of underlying bits, i.e. bits in the slice plus the @@ -535,9 +529,9 @@ impl core::cmp::PartialEq for Slice<'_> { if len == 1 { ((lhs[0] ^ rhs[0]) & front & back) == 0 } else { - ((lhs[0] ^ rhs[0]) & front) == 0 - && ((lhs[len - 1] ^ rhs[len - 1]) & back) == 0 - && lhs[1..len - 1] == rhs[1..len - 1] + ((lhs[0] ^ rhs[0]) & front) == 0 && + ((lhs[len - 1] ^ rhs[len - 1]) & back) == 0 && + lhs[1..len - 1] == rhs[1..len - 1] } } } diff --git a/common/sealable-trie/src/nodes.rs b/common/sealable-trie/src/nodes.rs index 8d76d269..c2396512 100644 --- a/common/sealable-trie/src/nodes.rs +++ b/common/sealable-trie/src/nodes.rs @@ -196,8 +196,8 @@ impl<'a, P, S> Node<'a, P, S> { Node::Branch { children: [left, right] } => { // tag = 0b0000_00xy where x and y indicate whether left and // right children respectively are value references. - let tag = (u8::from(left.is_value()) << 1) - | u8::from(right.is_value()); + let tag = (u8::from(left.is_value()) << 1) | + u8::from(right.is_value()); tag_hash_hash(&mut buf, tag, left.hash(), right.hash()) } Node::Value { value, child } => { @@ -339,14 +339,10 @@ impl RawNode { } /// Returns the first byte in the raw representation. - fn first(&self) -> u8 { - self.0[0] - } + fn first(&self) -> u8 { self.0[0] } /// Splits the raw byte representation in two halfs. - fn halfs(&self) -> (&[u8; 36], &[u8; 36]) { - stdx::split_array_ref(&self.0) - } + fn halfs(&self) -> (&[u8; 36], &[u8; 36]) { stdx::split_array_ref(&self.0) } /// Splits the raw byte representation in two halfs. fn halfs_mut(&mut self) -> (&mut [u8; 36], &mut [u8; 36]) { @@ -356,14 +352,10 @@ impl RawNode { impl<'a, P, S> Reference<'a, P, S> { /// Returns whether the reference is to a node. - pub fn is_node(&self) -> bool { - matches!(self, Self::Node(_)) - } + pub fn is_node(&self) -> bool { matches!(self, Self::Node(_)) } /// Returns whether the reference is to a value. - pub fn is_value(&self) -> bool { - matches!(self, Self::Value(_)) - } + pub fn is_value(&self) -> bool { matches!(self, Self::Value(_)) } /// Returns node’s or value’s hash depending on type of reference. /// @@ -468,17 +460,13 @@ impl<'a> Reference<'a, (), ()> { impl<'a, P> NodeRef<'a, P> { /// Constructs a new node reference. #[inline] - pub fn new(ptr: P, hash: &'a CryptoHash) -> Self { - Self { ptr, hash } - } + pub fn new(ptr: P, hash: &'a CryptoHash) -> Self { Self { ptr, hash } } } impl<'a> NodeRef<'a, Option> { /// Returns sealed version of the reference. The hash remains unchanged. #[inline] - pub fn sealed(self) -> Self { - Self { ptr: None, hash: self.hash } - } + pub fn sealed(self) -> Self { Self { ptr: None, hash: self.hash } } } impl<'a, S> ValueRef<'a, S> { @@ -492,9 +480,7 @@ impl<'a, S> ValueRef<'a, S> { impl<'a> ValueRef<'a, bool> { /// Returns sealed version of the reference. The hash remains unchanged. #[inline] - pub fn sealed(self) -> Self { - Self { is_sealed: true, hash: self.hash } - } + pub fn sealed(self) -> Self { Self { is_sealed: true, hash: self.hash } } } // ============================================================================= diff --git a/common/sealable-trie/src/proof.rs b/common/sealable-trie/src/proof.rs index 1cb66a67..06413f53 100644 --- a/common/sealable-trie/src/proof.rs +++ b/common/sealable-trie/src/proof.rs @@ -99,9 +99,7 @@ impl Proof { } /// Creates a builder which allows creation of proofs. - pub(crate) fn builder() -> Builder { - Builder(Vec::new()) - } + pub(crate) fn builder() -> Builder { Builder(Vec::new()) } } impl Membership { @@ -256,9 +254,7 @@ impl Item { impl Builder { /// Adds a new item to the proof. - pub fn push(&mut self, item: Item) { - self.0.push(item); - } + pub fn push(&mut self, item: Item) { self.0.push(item); } /// Reverses order of items in the builder. /// @@ -272,9 +268,7 @@ impl Builder { } /// Constructs a new membership proof from added items. - pub fn build>(self) -> T { - T::from(Membership(self.0)) - } + pub fn build>(self) -> T { T::from(Membership(self.0)) } /// Constructs a new non-membership proof from added items and given /// ‘actual’ entry. @@ -338,17 +332,11 @@ impl Builder { impl OwnedRef { /// Creates a reference pointing at node with given hash. - fn node(hash: CryptoHash) -> Self { - Self { is_value: false, hash } - } + fn node(hash: CryptoHash) -> Self { Self { is_value: false, hash } } /// Creates a reference pointing at value with given hash. - fn value(hash: CryptoHash) -> Self { - Self { is_value: true, hash } - } + fn value(hash: CryptoHash) -> Self { Self { is_value: true, hash } } /// Creates a reference pointing at given node. - fn to(node: Node) -> Self { - Self::node(node.hash()) - } + fn to(node: Node) -> Self { Self::node(node.hash()) } #[cfg(test)] #[allow(dead_code)] @@ -368,15 +356,11 @@ impl<'a, P, S> From<&'a Reference<'a, P, S>> for OwnedRef { } impl<'a, P, S> From> for OwnedRef { - fn from(rf: Reference<'a, P, S>) -> OwnedRef { - Self::from(&rf) - } + fn from(rf: Reference<'a, P, S>) -> OwnedRef { Self::from(&rf) } } impl<'a> From<&'a OwnedRef> for Reference<'a, (), ()> { - fn from(rf: &'a OwnedRef) -> Self { - Self::new(rf.is_value, &rf.hash) - } + fn from(rf: &'a OwnedRef) -> Self { Self::new(rf.is_value, &rf.hash) } } #[test] diff --git a/common/sealable-trie/src/proof/serialisation.rs b/common/sealable-trie/src/proof/serialisation.rs index 67885839..21776a53 100644 --- a/common/sealable-trie/src/proof/serialisation.rs +++ b/common/sealable-trie/src/proof/serialisation.rs @@ -465,10 +465,9 @@ fn test_proof_borsh() { &[4, 32, 42, 32, 42], ); test(Proof::Negative(super::NonMembership(None, vec![])), &[1]); - test( - Proof::Negative(super::NonMembership(None, vec![item.clone()])), - &[3, 32, 42], - ); + test(Proof::Negative(super::NonMembership(None, vec![item.clone()])), &[ + 3, 32, 42, + ]); test( Proof::Negative(super::NonMembership( Some(actual.clone().into()), diff --git a/common/sealable-trie/src/trie.rs b/common/sealable-trie/src/trie.rs index d1aca515..1e3fc246 100644 --- a/common/sealable-trie/src/trie.rs +++ b/common/sealable-trie/src/trie.rs @@ -87,9 +87,7 @@ pub enum Error { } impl From for Error { - fn from(_: memory::OutOfMemory) -> Self { - Self::OutOfMemory - } + fn from(_: memory::OutOfMemory) -> Self { Self::OutOfMemory } } type Result = ::core::result::Result; @@ -114,14 +112,10 @@ impl> Trie { } /// Returns hash of the root node. - pub fn hash(&self) -> &CryptoHash { - &self.root_hash - } + pub fn hash(&self) -> &CryptoHash { &self.root_hash } /// Returns whether the trie is empty. - pub fn is_empty(&self) -> bool { - self.root_hash == EMPTY_TRIE_ROOT - } + pub fn is_empty(&self) -> bool { self.root_hash == EMPTY_TRIE_ROOT } /// Deconstructs the object into the individual parts — allocator, root /// pointer and root hash. diff --git a/common/sealable-trie/src/trie/tests.rs b/common/sealable-trie/src/trie/tests.rs index f780299a..06299cb0 100644 --- a/common/sealable-trie/src/trie/tests.rs +++ b/common/sealable-trie/src/trie/tests.rs @@ -19,9 +19,7 @@ fn do_test_inserts<'a>( } #[test] -fn test_msb_difference() { - do_test_inserts([&[0][..], &[0x80][..]], true); -} +fn test_msb_difference() { do_test_inserts([&[0][..], &[0x80][..]], true); } #[test] fn test_sequence() { @@ -88,15 +86,11 @@ struct Key { } impl Key { - fn as_bytes(&self) -> &[u8] { - &self.buf[..usize::from(self.len)] - } + fn as_bytes(&self) -> &[u8] { &self.buf[..usize::from(self.len)] } } impl core::cmp::PartialEq for Key { - fn eq(&self, other: &Self) -> bool { - self.as_bytes() == other.as_bytes() - } + fn eq(&self, other: &Self) -> bool { self.as_bytes() == other.as_bytes() } } impl core::cmp::PartialOrd for Key { diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index f325e5d4..53f04b59 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -261,15 +261,11 @@ impl ClientStateCommon for AnyClientState { } impl From for AnyClientState { - fn from(value: TmClientState) -> Self { - AnyClientState::Tendermint(value) - } + fn from(value: TmClientState) -> Self { AnyClientState::Tendermint(value) } } impl From for AnyClientState { - fn from(value: MockClientState) -> Self { - AnyClientState::Mock(value) - } + fn from(value: MockClientState) -> Self { AnyClientState::Mock(value) } } impl ClientStateExecution for AnyClientState { diff --git a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs index 1cd6a6f4..06d1d59c 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs @@ -1,11 +1,10 @@ +use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use ibc::core::ics02_client::consensus_state::ConsensusState; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics23_commitment::commitment::CommitmentRoot; use ibc::core::timestamp::Timestamp; -use ibc::mock::consensus_state::MOCK_CONSENSUS_STATE_TYPE_URL; -use ibc::{ - clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState, - mock::consensus_state::MockConsensusState, +use ibc::mock::consensus_state::{ + MockConsensusState, MOCK_CONSENSUS_STATE_TYPE_URL, }; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState; @@ -119,9 +118,9 @@ impl TryInto match self { AnyConsensusState::Tendermint(value) => Ok(value), AnyConsensusState::Mock(_) => Err(ClientError::Other { - description: - "Cannot convert mock consensus state to tendermint" - .to_string(), + description: "Cannot convert mock consensus state to \ + tendermint" + .to_string(), }), } } @@ -139,9 +138,9 @@ impl TryInto match self { AnyConsensusState::Mock(value) => Ok(value), AnyConsensusState::Tendermint(_) => Err(ClientError::Other { - description: - "Cannot convert tendermint consensus state to mock" - .to_string(), + description: "Cannot convert tendermint consensus state to \ + mock" + .to_string(), }), } } diff --git a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs index 7d6b2669..4ef621dd 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -371,9 +371,7 @@ impl ExecutionContext for SolanaIbcStorage { Ok(()) } - fn get_client_execution_context(&mut self) -> &mut Self::E { - self - } + fn get_client_execution_context(&mut self) -> &mut Self::E { self } } fn record_packet_sequence( diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 6b60ff19..5ce4561b 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -202,9 +202,7 @@ pub trait SolanaIbcStorageHost { todo!() } /// - fn set_solana_ibc_store(_store: &SolanaIbcStorage) { - todo!() - } + fn set_solana_ibc_store(_store: &SolanaIbcStorage) { todo!() } } impl Router for SolanaIbcStorage { diff --git a/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs b/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs index b2aab8b2..391c42a5 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs @@ -9,9 +9,7 @@ pub struct ModuleHolder { } impl ModuleHolder { - pub fn new(account: Pubkey) -> Self { - Self { account } - } + pub fn new(account: Pubkey) -> Self { Self { account } } /// pub fn get_module_id(&self, port_id: &PortId) -> Option { match port_id.as_str() { diff --git a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs index 17511f9c..d4f34e9f 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -402,7 +402,7 @@ fn calculate_block_delay( if max_expected_time_per_block.is_zero() { return 0; } - let delay = delay_period_time.as_secs_f64() - / max_expected_time_per_block.as_secs_f64(); + let delay = delay_period_time.as_secs_f64() / + max_expected_time_per_block.as_secs_f64(); delay.ceil() as u64 } diff --git a/solana/trie-example/src/trie.rs b/solana/trie-example/src/trie.rs index ff7e6557..57a83a5d 100644 --- a/solana/trie-example/src/trie.rs +++ b/solana/trie-example/src/trie.rs @@ -213,15 +213,11 @@ impl<'a, 'b> memory::Allocator for Allocator<'a, 'b> { impl<'a, 'b> core::ops::Deref for AccountTrie<'a, 'b> { type Target = sealable_trie::Trie>; - fn deref(&self) -> &Self::Target { - &self.0 - } + fn deref(&self) -> &Self::Target { &self.0 } } impl<'a, 'b> core::ops::DerefMut for AccountTrie<'a, 'b> { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } /// Reads fixed-width value from start of the buffer and returns the value and From 429b10d14175958830db2a3bd8f795d9d20156f8 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 17:16:08 +0530 Subject: [PATCH 06/13] fix formatting --- common/blockchain/src/block.rs | 4 +-- common/blockchain/src/candidates.rs | 4 +-- common/blockchain/src/candidates/tests.rs | 24 +++++++------- common/blockchain/src/epoch.rs | 8 ++--- common/blockchain/src/height.rs | 20 +++--------- common/blockchain/src/validators.rs | 8 ++--- common/lib/src/hash.rs | 24 ++++---------- common/lib/src/varint.rs | 25 +++++---------- common/memory/src/lib.rs | 12 ++----- common/sealable-trie/src/bits.rs | 26 ++++++--------- common/sealable-trie/src/nodes.rs | 32 ++++++------------- common/sealable-trie/src/proof.rs | 32 +++++-------------- .../sealable-trie/src/proof/serialisation.rs | 7 ++-- common/sealable-trie/src/trie.rs | 12 ++----- common/sealable-trie/src/trie/tests.rs | 12 ++----- .../programs/solana-ibc/src/client_state.rs | 8 ++--- .../solana-ibc/src/consensus_state.rs | 19 ++++++----- .../solana-ibc/src/execution_context.rs | 4 +-- .../solana-ibc/programs/solana-ibc/src/lib.rs | 4 +-- .../programs/solana-ibc/src/module_holder.rs | 4 +-- .../solana-ibc/src/validation_context.rs | 4 +-- solana/trie-example/src/trie.rs | 8 ++--- 22 files changed, 94 insertions(+), 207 deletions(-) diff --git a/common/blockchain/src/block.rs b/common/blockchain/src/block.rs index 394454f3..2b11aa48 100644 --- a/common/blockchain/src/block.rs +++ b/common/blockchain/src/block.rs @@ -60,8 +60,8 @@ pub enum GenerateError { impl Block { /// Returns whether the block is a valid genesis block. pub fn is_genesis(&self) -> bool { - self.prev_block_hash == CryptoHash::DEFAULT - && self.epoch_id == CryptoHash::DEFAULT + self.prev_block_hash == CryptoHash::DEFAULT && + self.epoch_id == CryptoHash::DEFAULT } /// Calculates hash of the block. diff --git a/common/blockchain/src/candidates.rs b/common/blockchain/src/candidates.rs index c032cd6d..830916bd 100644 --- a/common/blockchain/src/candidates.rs +++ b/common/blockchain/src/candidates.rs @@ -160,9 +160,7 @@ impl Candidates { Ok(()) } - fn max_validators(&self) -> usize { - usize::from(self.max_validators.get()) - } + fn max_validators(&self) -> usize { usize::from(self.max_validators.get()) } /// Adds a new candidate at given position. /// diff --git a/common/blockchain/src/candidates/tests.rs b/common/blockchain/src/candidates/tests.rs index a89f3b0e..7078781c 100644 --- a/common/blockchain/src/candidates/tests.rs +++ b/common/blockchain/src/candidates/tests.rs @@ -109,9 +109,7 @@ fn test_candidates_0() { use candidate as c; use UpdateCandidateError::*; - fn pk(pubkey: char) -> MockPubKey { - MockPubKey(pubkey as u32) - } + fn pk(pubkey: char) -> MockPubKey { MockPubKey(pubkey as u32) } // Create candidates set let mut candidates = Candidates::from_candidates( @@ -241,8 +239,8 @@ impl TestCtx { /// configuration file. fn check(&self) { assert!( - self.candidates.candidates.len() - >= self.config.min_validators.get().into(), + self.candidates.candidates.len() >= + self.config.min_validators.get().into(), "Violated min validators constraint: {} < {}", self.candidates.candidates.len(), self.config.min_validators.get(), @@ -282,14 +280,14 @@ impl TestCtx { .get(usize::from(self.config.max_validators.get())) .map_or(0, |c: &Candidate<_>| c.stake.get()); assert!( - head_stake - old_stake + new_stake - < self.config.min_total_stake.get() + head_stake - old_stake + new_stake < + self.config.min_total_stake.get() ); } NotEnoughValidators => { assert!( - self.candidates.candidates.len() - <= self.config.min_validators.get().into() + self.candidates.candidates.len() <= + self.config.min_validators.get().into() ); } } @@ -361,8 +359,8 @@ impl TestCtx { .candidates .get(usize::from(self.config.max_validators.get())); let kicked_out = last.clone().map_or(false, |candidiate| { - candidiate - < &Candidate { + candidiate < + &Candidate { pubkey, stake: NonZeroU128::new(new_stake).unwrap(), } @@ -372,8 +370,8 @@ impl TestCtx { if kicked_out { last.unwrap().stake.get() } else { new_stake }; assert!( - self.candidates.head_stake - old_stake + new_stake - < self.config.min_total_stake.get() + self.candidates.head_stake - old_stake + new_stake < + self.config.min_total_stake.get() ); } diff --git a/common/blockchain/src/epoch.rs b/common/blockchain/src/epoch.rs index 74366e1a..97dae879 100644 --- a/common/blockchain/src/epoch.rs +++ b/common/blockchain/src/epoch.rs @@ -82,14 +82,10 @@ impl Epoch { } /// Returns list of all validators in the epoch. - pub fn validators(&self) -> &[Validator] { - self.validators.as_slice() - } + pub fn validators(&self) -> &[Validator] { self.validators.as_slice() } /// Returns stake needed to reach quorum. - pub fn quorum_stake(&self) -> NonZeroU128 { - self.quorum_stake - } + pub fn quorum_stake(&self) -> NonZeroU128 { self.quorum_stake } /// Finds a validator by their public key. pub fn validator(&self, pk: &PK) -> Option<&Validator> diff --git a/common/blockchain/src/height.rs b/common/blockchain/src/height.rs index 3985871f..20f5f1dc 100644 --- a/common/blockchain/src/height.rs +++ b/common/blockchain/src/height.rs @@ -53,9 +53,7 @@ pub type BlockDelta = Delta; impl Height { /// Returns the next height, i.e. `self + 1`. - pub fn next(self) -> Self { - Self(self.0.checked_add(1).unwrap(), self.1) - } + pub fn next(self) -> Self { Self(self.0.checked_add(1).unwrap(), self.1) } /// Checks whether delta between two heights is at least `min`. /// @@ -66,27 +64,19 @@ impl Height { } impl From for Height { - fn from(value: u64) -> Self { - Self(value, Default::default()) - } + fn from(value: u64) -> Self { Self(value, Default::default()) } } impl From for Delta { - fn from(value: u64) -> Self { - Self(value, Default::default()) - } + fn from(value: u64) -> Self { Self(value, Default::default()) } } impl From> for u64 { - fn from(value: Height) -> u64 { - value.0 - } + fn from(value: Height) -> u64 { value.0 } } impl From> for u64 { - fn from(value: Delta) -> u64 { - value.0 - } + fn from(value: Delta) -> u64 { value.0 } } impl core::fmt::Display for Height { diff --git a/common/blockchain/src/validators.rs b/common/blockchain/src/validators.rs index 2507e100..d6624159 100644 --- a/common/blockchain/src/validators.rs +++ b/common/blockchain/src/validators.rs @@ -50,13 +50,9 @@ impl Validator { Self { version: crate::common::VersionZero, pubkey, stake } } - pub fn pubkey(&self) -> &PK { - &self.pubkey - } + pub fn pubkey(&self) -> &PK { &self.pubkey } - pub fn stake(&self) -> NonZeroU128 { - self.stake - } + pub fn stake(&self) -> NonZeroU128 { self.stake } } #[cfg(test)] diff --git a/common/lib/src/hash.rs b/common/lib/src/hash.rs index 5461bf06..8e375f4d 100644 --- a/common/lib/src/hash.rs +++ b/common/lib/src/hash.rs @@ -38,9 +38,7 @@ impl CryptoHash { /// Returns a builder which can be used to construct cryptographic hash by /// digesting bytes. #[inline] - pub fn builder() -> Builder { - Builder::default() - } + pub fn builder() -> Builder { Builder::default() } /// Returns hash of given bytes. #[inline] @@ -89,9 +87,7 @@ impl CryptoHash { /// Returns a shared reference to the hash as slice of bytes. #[inline] - pub fn as_slice(&self) -> &[u8] { - &self.0[..] - } + pub fn as_slice(&self) -> &[u8] { &self.0[..] } } impl core::fmt::Display for CryptoHash { @@ -123,9 +119,7 @@ impl<'a> From<&'a [u8; CryptoHash::LENGTH]> for CryptoHash { impl From<&'_ CryptoHash> for [u8; CryptoHash::LENGTH] { #[inline] - fn from(hash: &'_ CryptoHash) -> Self { - hash.0 - } + fn from(hash: &'_ CryptoHash) -> Self { hash.0 } } impl<'a> From<&'a [u8; CryptoHash::LENGTH]> for &'a CryptoHash { @@ -190,15 +184,11 @@ pub struct Builder(sha2::Sha256); impl Builder { /// Process data, updating the internal state of the digest. #[inline] - pub fn update(&mut self, bytes: &[u8]) { - self.0.update(bytes) - } + pub fn update(&mut self, bytes: &[u8]) { self.0.update(bytes) } /// Finalises the digest and returns the cryptographic hash. #[inline] - pub fn build(self) -> CryptoHash { - CryptoHash(self.0.finalize().into()) - } + pub fn build(self) -> CryptoHash { CryptoHash(self.0.finalize().into()) } } #[cfg(feature = "borsh")] @@ -212,9 +202,7 @@ impl io::Write for Builder { Ok(self.update(buf)) } - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } #[test] diff --git a/common/lib/src/varint.rs b/common/lib/src/varint.rs index 57dd298e..aa76a235 100644 --- a/common/lib/src/varint.rs +++ b/common/lib/src/varint.rs @@ -104,14 +104,11 @@ impl borsh::BorshDeserialize for VarInt { #[inline] fn deserialize_reader(reader: &mut R) -> io::Result { read_u32(|| u8::deserialize_reader(reader)).map(Self).map_err(|err| { - io::Error::new( - io::ErrorKind::InvalidData, - match err { - ReadError::ReaderError(err) => return err, - ReadError::Overlong => "overlong", - ReadError::Overflow => "overflow", - }, - ) + io::Error::new(io::ErrorKind::InvalidData, match err { + ReadError::ReaderError(err) => return err, + ReadError::Overlong => "overlong", + ReadError::Overflow => "overflow", + }) }) } } @@ -137,9 +134,7 @@ pub struct Buffer { } impl Buffer { - fn new() -> Self { - Self { len: 0, data: [0; N] } - } + fn new() -> Self { Self { len: 0, data: [0; N] } } fn push_or_panic(&mut self, byte: u8) { self.data[usize::from(self.len)] = byte; @@ -156,16 +151,12 @@ impl Buffer { impl core::ops::Deref for Buffer { type Target = [u8]; #[inline] - fn deref(&self) -> &[u8] { - self.as_slice() - } + fn deref(&self) -> &[u8] { self.as_slice() } } impl core::convert::AsRef<[u8]> for Buffer { #[inline] - fn as_ref(&self) -> &[u8] { - self.as_slice() - } + fn as_ref(&self) -> &[u8] { self.as_slice() } } #[cfg(test)] diff --git a/common/memory/src/lib.rs b/common/memory/src/lib.rs index a8698df7..b4b1e9bc 100644 --- a/common/memory/src/lib.rs +++ b/common/memory/src/lib.rs @@ -192,9 +192,7 @@ impl<'a, A: Allocator> WriteLog<'a, A> { } /// Returns underlying allocator. - pub fn allocator(&self) -> &A { - &*self.alloc - } + pub fn allocator(&self) -> &A { &*self.alloc } pub fn alloc(&mut self, value: A::Value) -> Result { let ptr = self.alloc.alloc(value)?; @@ -206,9 +204,7 @@ impl<'a, A: Allocator> WriteLog<'a, A> { self.write_log.push((ptr, value)) } - pub fn free(&mut self, ptr: Ptr) { - self.freed.push(ptr); - } + pub fn free(&mut self, ptr: Ptr) { self.freed.push(ptr); } } impl<'a, A: Allocator> core::ops::Drop for WriteLog<'a, A> { @@ -239,9 +235,7 @@ pub mod test_utils { Self { count: 0, pool, free_list: Default::default() } } - pub fn count(&self) -> usize { - self.count - } + pub fn count(&self) -> usize { self.count } /// Gets index in the memory pool for the given pointer. /// diff --git a/common/sealable-trie/src/bits.rs b/common/sealable-trie/src/bits.rs index 5d3327fe..2a965d64 100644 --- a/common/sealable-trie/src/bits.rs +++ b/common/sealable-trie/src/bits.rs @@ -88,15 +88,11 @@ impl<'a> Slice<'a> { /// Returns length of the slice in bits. #[inline] - pub fn len(&self) -> u16 { - self.length - } + pub fn len(&self) -> u16 { self.length } /// Returns whether the slice is empty. #[inline] - pub fn is_empty(&self) -> bool { - self.length == 0 - } + pub fn is_empty(&self) -> bool { self.length == 0 } /// Returns the first bit in the slice advances the slice by one position. /// @@ -214,9 +210,7 @@ impl<'a> Slice<'a> { /// may be shorter than 272 bits (i.e. 34 * 8) however it will span full 34 /// bytes. #[inline] - pub fn chunks(&self) -> Chunks<'a> { - Chunks(*self) - } + pub fn chunks(&self) -> Chunks<'a> { Chunks(*self) } /// Splits slice into two at given index. /// @@ -378,10 +372,10 @@ impl<'a> Slice<'a> { fn check_bytes(bytes: &[u8], offset: u8, length: u16) -> bool { let (front, back) = Self::masks(offset, length); let bytes_len = (usize::from(offset) + usize::from(length) + 7) / 8; - bytes_len <= bytes.len() - && (bytes[0] & !front) == 0 - && (bytes[bytes_len - 1] & !back) == 0 - && bytes[bytes_len..].iter().all(|&b| b == 0) + bytes_len <= bytes.len() && + (bytes[0] & !front) == 0 && + (bytes[bytes_len - 1] & !back) == 0 && + bytes[bytes_len..].iter().all(|&b| b == 0) } /// Returns total number of underlying bits, i.e. bits in the slice plus the @@ -535,9 +529,9 @@ impl core::cmp::PartialEq for Slice<'_> { if len == 1 { ((lhs[0] ^ rhs[0]) & front & back) == 0 } else { - ((lhs[0] ^ rhs[0]) & front) == 0 - && ((lhs[len - 1] ^ rhs[len - 1]) & back) == 0 - && lhs[1..len - 1] == rhs[1..len - 1] + ((lhs[0] ^ rhs[0]) & front) == 0 && + ((lhs[len - 1] ^ rhs[len - 1]) & back) == 0 && + lhs[1..len - 1] == rhs[1..len - 1] } } } diff --git a/common/sealable-trie/src/nodes.rs b/common/sealable-trie/src/nodes.rs index 8d76d269..c2396512 100644 --- a/common/sealable-trie/src/nodes.rs +++ b/common/sealable-trie/src/nodes.rs @@ -196,8 +196,8 @@ impl<'a, P, S> Node<'a, P, S> { Node::Branch { children: [left, right] } => { // tag = 0b0000_00xy where x and y indicate whether left and // right children respectively are value references. - let tag = (u8::from(left.is_value()) << 1) - | u8::from(right.is_value()); + let tag = (u8::from(left.is_value()) << 1) | + u8::from(right.is_value()); tag_hash_hash(&mut buf, tag, left.hash(), right.hash()) } Node::Value { value, child } => { @@ -339,14 +339,10 @@ impl RawNode { } /// Returns the first byte in the raw representation. - fn first(&self) -> u8 { - self.0[0] - } + fn first(&self) -> u8 { self.0[0] } /// Splits the raw byte representation in two halfs. - fn halfs(&self) -> (&[u8; 36], &[u8; 36]) { - stdx::split_array_ref(&self.0) - } + fn halfs(&self) -> (&[u8; 36], &[u8; 36]) { stdx::split_array_ref(&self.0) } /// Splits the raw byte representation in two halfs. fn halfs_mut(&mut self) -> (&mut [u8; 36], &mut [u8; 36]) { @@ -356,14 +352,10 @@ impl RawNode { impl<'a, P, S> Reference<'a, P, S> { /// Returns whether the reference is to a node. - pub fn is_node(&self) -> bool { - matches!(self, Self::Node(_)) - } + pub fn is_node(&self) -> bool { matches!(self, Self::Node(_)) } /// Returns whether the reference is to a value. - pub fn is_value(&self) -> bool { - matches!(self, Self::Value(_)) - } + pub fn is_value(&self) -> bool { matches!(self, Self::Value(_)) } /// Returns node’s or value’s hash depending on type of reference. /// @@ -468,17 +460,13 @@ impl<'a> Reference<'a, (), ()> { impl<'a, P> NodeRef<'a, P> { /// Constructs a new node reference. #[inline] - pub fn new(ptr: P, hash: &'a CryptoHash) -> Self { - Self { ptr, hash } - } + pub fn new(ptr: P, hash: &'a CryptoHash) -> Self { Self { ptr, hash } } } impl<'a> NodeRef<'a, Option> { /// Returns sealed version of the reference. The hash remains unchanged. #[inline] - pub fn sealed(self) -> Self { - Self { ptr: None, hash: self.hash } - } + pub fn sealed(self) -> Self { Self { ptr: None, hash: self.hash } } } impl<'a, S> ValueRef<'a, S> { @@ -492,9 +480,7 @@ impl<'a, S> ValueRef<'a, S> { impl<'a> ValueRef<'a, bool> { /// Returns sealed version of the reference. The hash remains unchanged. #[inline] - pub fn sealed(self) -> Self { - Self { is_sealed: true, hash: self.hash } - } + pub fn sealed(self) -> Self { Self { is_sealed: true, hash: self.hash } } } // ============================================================================= diff --git a/common/sealable-trie/src/proof.rs b/common/sealable-trie/src/proof.rs index 1cb66a67..06413f53 100644 --- a/common/sealable-trie/src/proof.rs +++ b/common/sealable-trie/src/proof.rs @@ -99,9 +99,7 @@ impl Proof { } /// Creates a builder which allows creation of proofs. - pub(crate) fn builder() -> Builder { - Builder(Vec::new()) - } + pub(crate) fn builder() -> Builder { Builder(Vec::new()) } } impl Membership { @@ -256,9 +254,7 @@ impl Item { impl Builder { /// Adds a new item to the proof. - pub fn push(&mut self, item: Item) { - self.0.push(item); - } + pub fn push(&mut self, item: Item) { self.0.push(item); } /// Reverses order of items in the builder. /// @@ -272,9 +268,7 @@ impl Builder { } /// Constructs a new membership proof from added items. - pub fn build>(self) -> T { - T::from(Membership(self.0)) - } + pub fn build>(self) -> T { T::from(Membership(self.0)) } /// Constructs a new non-membership proof from added items and given /// ‘actual’ entry. @@ -338,17 +332,11 @@ impl Builder { impl OwnedRef { /// Creates a reference pointing at node with given hash. - fn node(hash: CryptoHash) -> Self { - Self { is_value: false, hash } - } + fn node(hash: CryptoHash) -> Self { Self { is_value: false, hash } } /// Creates a reference pointing at value with given hash. - fn value(hash: CryptoHash) -> Self { - Self { is_value: true, hash } - } + fn value(hash: CryptoHash) -> Self { Self { is_value: true, hash } } /// Creates a reference pointing at given node. - fn to(node: Node) -> Self { - Self::node(node.hash()) - } + fn to(node: Node) -> Self { Self::node(node.hash()) } #[cfg(test)] #[allow(dead_code)] @@ -368,15 +356,11 @@ impl<'a, P, S> From<&'a Reference<'a, P, S>> for OwnedRef { } impl<'a, P, S> From> for OwnedRef { - fn from(rf: Reference<'a, P, S>) -> OwnedRef { - Self::from(&rf) - } + fn from(rf: Reference<'a, P, S>) -> OwnedRef { Self::from(&rf) } } impl<'a> From<&'a OwnedRef> for Reference<'a, (), ()> { - fn from(rf: &'a OwnedRef) -> Self { - Self::new(rf.is_value, &rf.hash) - } + fn from(rf: &'a OwnedRef) -> Self { Self::new(rf.is_value, &rf.hash) } } #[test] diff --git a/common/sealable-trie/src/proof/serialisation.rs b/common/sealable-trie/src/proof/serialisation.rs index 67885839..21776a53 100644 --- a/common/sealable-trie/src/proof/serialisation.rs +++ b/common/sealable-trie/src/proof/serialisation.rs @@ -465,10 +465,9 @@ fn test_proof_borsh() { &[4, 32, 42, 32, 42], ); test(Proof::Negative(super::NonMembership(None, vec![])), &[1]); - test( - Proof::Negative(super::NonMembership(None, vec![item.clone()])), - &[3, 32, 42], - ); + test(Proof::Negative(super::NonMembership(None, vec![item.clone()])), &[ + 3, 32, 42, + ]); test( Proof::Negative(super::NonMembership( Some(actual.clone().into()), diff --git a/common/sealable-trie/src/trie.rs b/common/sealable-trie/src/trie.rs index d1aca515..1e3fc246 100644 --- a/common/sealable-trie/src/trie.rs +++ b/common/sealable-trie/src/trie.rs @@ -87,9 +87,7 @@ pub enum Error { } impl From for Error { - fn from(_: memory::OutOfMemory) -> Self { - Self::OutOfMemory - } + fn from(_: memory::OutOfMemory) -> Self { Self::OutOfMemory } } type Result = ::core::result::Result; @@ -114,14 +112,10 @@ impl> Trie { } /// Returns hash of the root node. - pub fn hash(&self) -> &CryptoHash { - &self.root_hash - } + pub fn hash(&self) -> &CryptoHash { &self.root_hash } /// Returns whether the trie is empty. - pub fn is_empty(&self) -> bool { - self.root_hash == EMPTY_TRIE_ROOT - } + pub fn is_empty(&self) -> bool { self.root_hash == EMPTY_TRIE_ROOT } /// Deconstructs the object into the individual parts — allocator, root /// pointer and root hash. diff --git a/common/sealable-trie/src/trie/tests.rs b/common/sealable-trie/src/trie/tests.rs index f780299a..06299cb0 100644 --- a/common/sealable-trie/src/trie/tests.rs +++ b/common/sealable-trie/src/trie/tests.rs @@ -19,9 +19,7 @@ fn do_test_inserts<'a>( } #[test] -fn test_msb_difference() { - do_test_inserts([&[0][..], &[0x80][..]], true); -} +fn test_msb_difference() { do_test_inserts([&[0][..], &[0x80][..]], true); } #[test] fn test_sequence() { @@ -88,15 +86,11 @@ struct Key { } impl Key { - fn as_bytes(&self) -> &[u8] { - &self.buf[..usize::from(self.len)] - } + fn as_bytes(&self) -> &[u8] { &self.buf[..usize::from(self.len)] } } impl core::cmp::PartialEq for Key { - fn eq(&self, other: &Self) -> bool { - self.as_bytes() == other.as_bytes() - } + fn eq(&self, other: &Self) -> bool { self.as_bytes() == other.as_bytes() } } impl core::cmp::PartialOrd for Key { diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index f325e5d4..53f04b59 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -261,15 +261,11 @@ impl ClientStateCommon for AnyClientState { } impl From for AnyClientState { - fn from(value: TmClientState) -> Self { - AnyClientState::Tendermint(value) - } + fn from(value: TmClientState) -> Self { AnyClientState::Tendermint(value) } } impl From for AnyClientState { - fn from(value: MockClientState) -> Self { - AnyClientState::Mock(value) - } + fn from(value: MockClientState) -> Self { AnyClientState::Mock(value) } } impl ClientStateExecution for AnyClientState { diff --git a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs index 1cd6a6f4..06d1d59c 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs @@ -1,11 +1,10 @@ +use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState; use ibc::core::ics02_client::consensus_state::ConsensusState; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics23_commitment::commitment::CommitmentRoot; use ibc::core::timestamp::Timestamp; -use ibc::mock::consensus_state::MOCK_CONSENSUS_STATE_TYPE_URL; -use ibc::{ - clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState, - mock::consensus_state::MockConsensusState, +use ibc::mock::consensus_state::{ + MockConsensusState, MOCK_CONSENSUS_STATE_TYPE_URL, }; use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState; @@ -119,9 +118,9 @@ impl TryInto match self { AnyConsensusState::Tendermint(value) => Ok(value), AnyConsensusState::Mock(_) => Err(ClientError::Other { - description: - "Cannot convert mock consensus state to tendermint" - .to_string(), + description: "Cannot convert mock consensus state to \ + tendermint" + .to_string(), }), } } @@ -139,9 +138,9 @@ impl TryInto match self { AnyConsensusState::Mock(value) => Ok(value), AnyConsensusState::Tendermint(_) => Err(ClientError::Other { - description: - "Cannot convert tendermint consensus state to mock" - .to_string(), + description: "Cannot convert tendermint consensus state to \ + mock" + .to_string(), }), } } diff --git a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs index 7d6b2669..4ef621dd 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -371,9 +371,7 @@ impl ExecutionContext for SolanaIbcStorage { Ok(()) } - fn get_client_execution_context(&mut self) -> &mut Self::E { - self - } + fn get_client_execution_context(&mut self) -> &mut Self::E { self } } fn record_packet_sequence( diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 6b60ff19..5ce4561b 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -202,9 +202,7 @@ pub trait SolanaIbcStorageHost { todo!() } /// - fn set_solana_ibc_store(_store: &SolanaIbcStorage) { - todo!() - } + fn set_solana_ibc_store(_store: &SolanaIbcStorage) { todo!() } } impl Router for SolanaIbcStorage { diff --git a/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs b/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs index b2aab8b2..391c42a5 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/module_holder.rs @@ -9,9 +9,7 @@ pub struct ModuleHolder { } impl ModuleHolder { - pub fn new(account: Pubkey) -> Self { - Self { account } - } + pub fn new(account: Pubkey) -> Self { Self { account } } /// pub fn get_module_id(&self, port_id: &PortId) -> Option { match port_id.as_str() { diff --git a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs index 17511f9c..d4f34e9f 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -402,7 +402,7 @@ fn calculate_block_delay( if max_expected_time_per_block.is_zero() { return 0; } - let delay = delay_period_time.as_secs_f64() - / max_expected_time_per_block.as_secs_f64(); + let delay = delay_period_time.as_secs_f64() / + max_expected_time_per_block.as_secs_f64(); delay.ceil() as u64 } diff --git a/solana/trie-example/src/trie.rs b/solana/trie-example/src/trie.rs index ff7e6557..57a83a5d 100644 --- a/solana/trie-example/src/trie.rs +++ b/solana/trie-example/src/trie.rs @@ -213,15 +213,11 @@ impl<'a, 'b> memory::Allocator for Allocator<'a, 'b> { impl<'a, 'b> core::ops::Deref for AccountTrie<'a, 'b> { type Target = sealable_trie::Trie>; - fn deref(&self) -> &Self::Target { - &self.0 - } + fn deref(&self) -> &Self::Target { &self.0 } } impl<'a, 'b> core::ops::DerefMut for AccountTrie<'a, 'b> { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } /// Reads fixed-width value from start of the buffer and returns the value and From 4631aaa07743ea402dfdd279284369e3c2424fc2 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Fri, 13 Oct 2023 13:49:57 +0200 Subject: [PATCH 07/13] reduce diff noise --- common/sealable-trie/src/nodes.rs | 1 + common/sealable-trie/src/proof/serialisation.rs | 1 + common/sealable-trie/src/trie.rs | 1 + solana/trie-example/src/lib.rs | 1 + solana/trie-example/src/trie.rs | 3 +++ 5 files changed, 7 insertions(+) diff --git a/common/sealable-trie/src/nodes.rs b/common/sealable-trie/src/nodes.rs index c2396512..e714f9fd 100644 --- a/common/sealable-trie/src/nodes.rs +++ b/common/sealable-trie/src/nodes.rs @@ -483,6 +483,7 @@ impl<'a> ValueRef<'a, bool> { pub fn sealed(self) -> Self { Self { is_sealed: true, hash: self.hash } } } + // ============================================================================= // Conversions diff --git a/common/sealable-trie/src/proof/serialisation.rs b/common/sealable-trie/src/proof/serialisation.rs index 21776a53..ebc393d7 100644 --- a/common/sealable-trie/src/proof/serialisation.rs +++ b/common/sealable-trie/src/proof/serialisation.rs @@ -281,6 +281,7 @@ fn invalid_data(msg: String) -> io::Error { io::Error::new(io::ErrorKind::InvalidData, msg) } + #[test] fn test_item_borsh() { #[track_caller] diff --git a/common/sealable-trie/src/trie.rs b/common/sealable-trie/src/trie.rs index 1e3fc246..2257bc5b 100644 --- a/common/sealable-trie/src/trie.rs +++ b/common/sealable-trie/src/trie.rs @@ -328,6 +328,7 @@ impl> Trie { } } + #[cfg(test)] impl Trie> { /// Creates a test trie using a TestAllocator with given capacity. diff --git a/solana/trie-example/src/lib.rs b/solana/trie-example/src/lib.rs index ce808e9d..c28564d8 100644 --- a/solana/trie-example/src/lib.rs +++ b/solana/trie-example/src/lib.rs @@ -72,6 +72,7 @@ impl TrieResultExt for Result { } } + /// Instruction to execute. pub(crate) enum Instruction<'a> { // Encoding: diff --git a/solana/trie-example/src/trie.rs b/solana/trie-example/src/trie.rs index 57a83a5d..6456879c 100644 --- a/solana/trie-example/src/trie.rs +++ b/solana/trie-example/src/trie.rs @@ -211,6 +211,8 @@ impl<'a, 'b> memory::Allocator for Allocator<'a, 'b> { } } + + impl<'a, 'b> core::ops::Deref for AccountTrie<'a, 'b> { type Target = sealable_trie::Trie>; fn deref(&self) -> &Self::Target { &self.0 } @@ -247,6 +249,7 @@ fn write( right } + #[test] fn test_header_encoding() { const ONE: CryptoHash = CryptoHash([1; 32]); From 07167b902925dbce509437fd8c355af5996a081e Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 19:14:00 +0530 Subject: [PATCH 08/13] storing height while storing consensus state and returning current timestamp when host_timestamp is called --- .gitignore | 3 ++- Cargo.toml | 3 ++- .../programs/solana-ibc/src/execution_context.rs | 4 +++- solana/solana-ibc/programs/solana-ibc/src/tests.rs | 6 +++++- .../programs/solana-ibc/src/validation_context.rs | 14 ++++---------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index ea93e8e7..3e181d7f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ Cargo.lock node_modules package-lock.json target -test-ledger \ No newline at end of file +test-ledger +local-ibc \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 83f96716..7a4799ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,8 @@ base64 = { version = "0.21", default-features = false, features = ["alloc"] } bincode = "1.3.3" borsh = { version = "0.10.3", default-features = false } derive_more = "0.99.17" -ibc = { version = "0.45.0", default-features = false, features = ["serde", "mocks", "std"] } +ibc = { path = "local-ibc", features = ["serde", "mocks", "std"] } +# ibc = { version = "0.45.0", default-features = false, features = ["serde", "mocks", "std"] } ibc-proto = { version = "0.35.0", default-features = false, features = ["serde"] } pretty_assertions = "1.4.0" rand = { version = "0.8.5" } diff --git a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs index 4ef621dd..c46704b3 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -58,7 +58,7 @@ impl ClientExecutionContext for SolanaIbcStorage { consensus_state_path: ClientConsensusStatePath, consensus_state: Self::AnyConsensusState, ) -> Result { - msg!("{}-{}", consensus_state_path.epoch, consensus_state_path.height); + msg!("store_consensus_state - path: {}, consensus_state: {:?}", consensus_state_path, consensus_state); let consensus_state_key = ( consensus_state_path.client_id.to_string(), (consensus_state_path.epoch, consensus_state_path.height), @@ -67,6 +67,8 @@ impl ClientExecutionContext for SolanaIbcStorage { serde_json::to_string(&consensus_state).unwrap(); self.consensus_states .insert(consensus_state_key, serialized_consensus_state); + self.height.0 = consensus_state_path.epoch; + self.height.1 = consensus_state_path.height; Ok(()) } } diff --git a/solana/solana-ibc/programs/solana-ibc/src/tests.rs b/solana/solana-ibc/programs/solana-ibc/src/tests.rs index f5f25b18..8051b7b8 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/tests.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/tests.rs @@ -4,6 +4,7 @@ use std::time::Duration; use anchor_client::anchor_lang::system_program; use anchor_client::solana_client::rpc_client::RpcClient; +use anchor_client::solana_client::rpc_config::RpcSendTransactionConfig; use anchor_client::solana_sdk::commitment_config::CommitmentConfig; use anchor_client::solana_sdk::pubkey::Pubkey; use anchor_client::solana_sdk::signature::{Keypair, Signature, Signer}; @@ -88,7 +89,10 @@ fn anchor_test_deliver() -> Result<()> { .args(instruction::Deliver { messages: all_messages }) .payer(authority.clone()) .signer(&*authority) - .send()?; // ? gives us the log messages on the why the tx did fail ( better than unwrap ) + .send_with_spinner_and_config(RpcSendTransactionConfig{ + skip_preflight: true, + ..RpcSendTransactionConfig::default() + })?; // ? gives us the log messages on the why the tx did fail ( better than unwrap ) println!("demo sig: {sig}"); diff --git a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs index d4f34e9f..0f014eaf 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use std::time::Duration; -use anchor_lang::prelude::Pubkey; +use anchor_lang::prelude::{Pubkey, Clock, SolanaSysvar}; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics03_connection::connection::ConnectionEnd; use ibc::core::ics03_connection::error::ConnectionError; @@ -88,15 +88,9 @@ impl ValidationContext for SolanaIbcStorage { } fn host_timestamp(&self) -> std::result::Result { - let host_height = self.host_height()?; - match self.host_consensus_state(&host_height)? { - AnyConsensusState::Tendermint(consensus_state) => { - Ok(consensus_state.timestamp.into()) - } - AnyConsensusState::Mock(mock_consensus_state) => { - Ok(mock_consensus_state.timestamp().into()) - } - } + let clock = Clock::get().unwrap(); + let current_timestamp = clock.unix_timestamp as u64; + Ok(Timestamp::from_nanoseconds(current_timestamp).unwrap()) } fn host_consensus_state( From 8fcea3776ebc4a201f2e2f427b1054e93671df15 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 19:38:24 +0530 Subject: [PATCH 09/13] rm channel counter update --- solana/solana-ibc/programs/solana-ibc/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 5ce4561b..b2d86651 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -46,8 +46,6 @@ pub mod solana_ibc { .collect::>(); msg!("These are messages {:?}", all_messages); - solana_ibc_store.channel_counter = - solana_ibc_store.channel_counter.checked_add(10).unwrap(); let router = &mut solana_ibc_store.clone(); let errors = From c733f27b27784c02e1c8083fb8cbbc9a25e8d1b6 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 19:46:20 +0530 Subject: [PATCH 10/13] remove local ibc crate --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea529c9c..88318e68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,7 @@ base64 = { version = "0.21", default-features = false, features = ["alloc"] } bincode = "1.3.3" borsh = { version = "0.10.3", default-features = false } derive_more = "0.99.17" -ibc = { path = "local-ibc", features = ["serde", "mocks", "std"] } -# ibc = { version = "0.45.0", default-features = false, features = ["serde", "mocks", "std"] } +ibc = { version = "0.45.0", default-features = false, features = ["serde", "mocks", "std"] } ibc-proto = { version = "0.35.0", default-features = false, features = ["serde"] } pretty_assertions = "1.4.0" rand = { version = "0.8.5" } From a2ab39707701748ed2f3f6dd62c48e761664eff3 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 22:38:14 +0530 Subject: [PATCH 11/13] added mocks feature --- .../solana-ibc/programs/solana-ibc/Cargo.toml | 1 + .../programs/solana-ibc/src/client_state.rs | 30 ++++++++++++++++--- .../solana-ibc/src/consensus_state.rs | 22 +++++++++++--- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/solana/solana-ibc/programs/solana-ibc/Cargo.toml b/solana/solana-ibc/programs/solana-ibc/Cargo.toml index 6714b97d..bb4690d7 100644 --- a/solana/solana-ibc/programs/solana-ibc/Cargo.toml +++ b/solana/solana-ibc/programs/solana-ibc/Cargo.toml @@ -13,6 +13,7 @@ no-entrypoint = [] no-idl = [] no-log-ix-name = [] cpi = ["no-entrypoint"] +mocks = [] [dependencies] anchor-lang.workspace = true diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index 53f04b59..b1e42bc6 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -12,24 +12,29 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ics24_host::path::{ClientConsensusStatePath, Path}; use ibc::core::timestamp::Timestamp; use ibc::core::{ContextError, ValidationContext}; -use ibc::mock::client_state::{ - MockClientContext, MockClientState, MOCK_CLIENT_STATE_TYPE_URL, -}; + use ibc::{Any, Height}; use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState; -use ibc_proto::ibc::mock::ClientState as RawMockClientState; use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; use super::consensus_state::AnyConsensusState; use crate::SolanaIbcStorage; +#[cfg(any(test, feature = "mocks"))] +use ibc_proto::ibc::mock::ClientState as RawMockClientState; +#[cfg(any(test, feature = "mocks"))] +use ibc::mock::client_state::{ + MockClientContext, MockClientState, MOCK_CLIENT_STATE_TYPE_URL, +}; + const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState"; #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub enum AnyClientState { Tendermint(TmClientState), + #[cfg(any(test, feature = "mocks"))] Mock(MockClientState), } @@ -47,6 +52,7 @@ impl TryFrom for AnyClientState { }, )?, )), + #[cfg(any(test, feature = "mocks"))] MOCK_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::Mock( Protobuf::::decode_vec(&raw.value) .map_err(|e| ClientError::ClientSpecific { @@ -67,6 +73,7 @@ impl From for Any { type_url: TENDERMINT_CLIENT_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec(&client_state), }, + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(mock_client_state) => Any { type_url: MOCK_CLIENT_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec( @@ -93,6 +100,7 @@ impl ClientStateValidation for AnyClientState { client_message, update_kind, ), + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(mock_client_state) => mock_client_state .verify_client_message( ctx, @@ -118,6 +126,7 @@ impl ClientStateValidation for AnyClientState { client_message, update_kind, ), + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(mock_client_state) => mock_client_state .check_for_misbehaviour( ctx, @@ -147,6 +156,7 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.verify_consensus_state(consensus_state) } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(mock_client_state) => { mock_client_state.verify_consensus_state(consensus_state) } @@ -158,6 +168,7 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.client_type() } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(mock_client_state) => { mock_client_state.client_type() } @@ -170,6 +181,7 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.latest_height() } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(mock_client_state) => { msg!( "This is latest height {:?}", @@ -190,6 +202,7 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.validate_proof_height(proof_height) } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => { client_state.validate_proof_height(proof_height) } @@ -213,6 +226,7 @@ impl ClientStateCommon for AnyClientState { proof_upgrade_consensus_state, root, ), + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => client_state .verify_upgrade_client( upgraded_client_state, @@ -236,6 +250,7 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.verify_membership(prefix, proof, root, path, value) } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => { client_state.verify_membership(prefix, proof, root, path, value) } @@ -253,6 +268,7 @@ impl ClientStateCommon for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.verify_non_membership(prefix, proof, root, path) } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => { client_state.verify_non_membership(prefix, proof, root, path) } @@ -264,6 +280,7 @@ impl From for AnyClientState { fn from(value: TmClientState) -> Self { AnyClientState::Tendermint(value) } } +#[cfg(any(test, feature = "mocks"))] impl From for AnyClientState { fn from(value: MockClientState) -> Self { AnyClientState::Mock(value) } } @@ -279,6 +296,7 @@ impl ClientStateExecution for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.initialise(ctx, client_id, consensus_state) } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => { client_state.initialise(ctx, client_id, consensus_state) } @@ -295,6 +313,7 @@ impl ClientStateExecution for AnyClientState { AnyClientState::Tendermint(client_state) => { client_state.update_state(ctx, client_id, header) } + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => { client_state.update_state(ctx, client_id, header) } @@ -316,6 +335,7 @@ impl ClientStateExecution for AnyClientState { client_message, update_kind, ), + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => client_state .update_state_on_misbehaviour( ctx, @@ -341,6 +361,7 @@ impl ClientStateExecution for AnyClientState { upgraded_client_state, upgraded_consensus_state, ), + #[cfg(any(test, feature = "mocks"))] AnyClientState::Mock(client_state) => client_state .update_state_on_upgrade( ctx, @@ -365,6 +386,7 @@ impl ibc::clients::ics07_tendermint::CommonContext for SolanaIbcStorage { } } +#[cfg(any(test, feature = "mocks"))] impl MockClientContext for SolanaIbcStorage { type ConversionError = ClientError; type AnyConsensusState = AnyConsensusState; diff --git a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs index 06d1d59c..545efbf7 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs @@ -3,15 +3,20 @@ use ibc::core::ics02_client::consensus_state::ConsensusState; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics23_commitment::commitment::CommitmentRoot; use ibc::core::timestamp::Timestamp; -use ibc::mock::consensus_state::{ - MockConsensusState, MOCK_CONSENSUS_STATE_TYPE_URL, -}; + use ibc_proto::google::protobuf::Any; use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState; -use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState; use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; + +#[cfg(any(test, feature = "mocks"))] +use ibc::mock::consensus_state::{ + MockConsensusState, MOCK_CONSENSUS_STATE_TYPE_URL, +}; +#[cfg(any(test, feature = "mocks"))] +use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState; + const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ConsensusState"; @@ -19,6 +24,7 @@ const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = #[serde(tag = "type")] pub enum AnyConsensusState { Tendermint(TmConsensusState), + #[cfg(any(test, feature = "mocks"))] Mock(MockConsensusState), } @@ -37,6 +43,7 @@ impl TryFrom for AnyConsensusState { })?, )) } + #[cfg(any(test, feature = "mocks"))] MOCK_CONSENSUS_STATE_TYPE_URL => Ok(AnyConsensusState::Mock( Protobuf::::decode_vec(&value.value) .map_err(|e| ClientError::ClientSpecific { @@ -57,6 +64,7 @@ impl From for Any { type_url: TENDERMINT_CONSENSUS_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec(&value), }, + #[cfg(any(test, feature = "mocks"))] AnyConsensusState::Mock(value) => Any { type_url: MOCK_CONSENSUS_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec(&value), @@ -71,6 +79,7 @@ impl From for AnyConsensusState { } } +#[cfg(any(test, feature = "mocks"))] impl From for AnyConsensusState { fn from(value: MockConsensusState) -> Self { AnyConsensusState::Mock(value) @@ -81,6 +90,7 @@ impl ConsensusState for AnyConsensusState { fn root(&self) -> &CommitmentRoot { match self { AnyConsensusState::Tendermint(value) => value.root(), + #[cfg(any(test, feature = "mocks"))] AnyConsensusState::Mock(value) => value.root(), } } @@ -88,6 +98,7 @@ impl ConsensusState for AnyConsensusState { fn timestamp(&self) -> Timestamp { match self { AnyConsensusState::Tendermint(value) => value.timestamp(), + #[cfg(any(test, feature = "mocks"))] AnyConsensusState::Mock(value) => value.timestamp(), } } @@ -97,6 +108,7 @@ impl ConsensusState for AnyConsensusState { AnyConsensusState::Tendermint(value) => { ibc::core::ics02_client::consensus_state::ConsensusState::encode_vec(value) }, + #[cfg(any(test, feature = "mocks"))] AnyConsensusState::Mock(value) => { ibc::core::ics02_client::consensus_state::ConsensusState::encode_vec(value) } @@ -117,6 +129,7 @@ impl TryInto > { match self { AnyConsensusState::Tendermint(value) => Ok(value), + #[cfg(any(test, feature = "mocks"))] AnyConsensusState::Mock(_) => Err(ClientError::Other { description: "Cannot convert mock consensus state to \ tendermint" @@ -126,6 +139,7 @@ impl TryInto } } +#[cfg(any(test, feature = "mocks"))] impl TryInto for AnyConsensusState { From 6a38919ce3e693bdbf06fedf401a86d876fa71a6 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Fri, 13 Oct 2023 22:40:53 +0530 Subject: [PATCH 12/13] fix formatting --- common/lib/src/varint.rs | 1 - common/sealable-trie/src/nodes.rs | 1 - common/sealable-trie/src/proof/serialisation.rs | 1 - common/sealable-trie/src/trie.rs | 1 - .../programs/solana-ibc/src/client_state.rs | 14 ++++++-------- .../programs/solana-ibc/src/consensus_state.rs | 11 ++++------- .../programs/solana-ibc/src/execution_context.rs | 6 +++++- solana/solana-ibc/programs/solana-ibc/src/tests.rs | 2 +- .../programs/solana-ibc/src/validation_context.rs | 2 +- solana/trie-example/src/lib.rs | 1 - solana/trie-example/src/trie.rs | 3 --- 11 files changed, 17 insertions(+), 26 deletions(-) diff --git a/common/lib/src/varint.rs b/common/lib/src/varint.rs index 63f6b4bd..aa76a235 100644 --- a/common/lib/src/varint.rs +++ b/common/lib/src/varint.rs @@ -113,7 +113,6 @@ impl borsh::BorshDeserialize for VarInt { } } - /// Small on-stack buffer. /// /// # Example diff --git a/common/sealable-trie/src/nodes.rs b/common/sealable-trie/src/nodes.rs index e714f9fd..c2396512 100644 --- a/common/sealable-trie/src/nodes.rs +++ b/common/sealable-trie/src/nodes.rs @@ -483,7 +483,6 @@ impl<'a> ValueRef<'a, bool> { pub fn sealed(self) -> Self { Self { is_sealed: true, hash: self.hash } } } - // ============================================================================= // Conversions diff --git a/common/sealable-trie/src/proof/serialisation.rs b/common/sealable-trie/src/proof/serialisation.rs index ebc393d7..21776a53 100644 --- a/common/sealable-trie/src/proof/serialisation.rs +++ b/common/sealable-trie/src/proof/serialisation.rs @@ -281,7 +281,6 @@ fn invalid_data(msg: String) -> io::Error { io::Error::new(io::ErrorKind::InvalidData, msg) } - #[test] fn test_item_borsh() { #[track_caller] diff --git a/common/sealable-trie/src/trie.rs b/common/sealable-trie/src/trie.rs index 2257bc5b..1e3fc246 100644 --- a/common/sealable-trie/src/trie.rs +++ b/common/sealable-trie/src/trie.rs @@ -328,7 +328,6 @@ impl> Trie { } } - #[cfg(test)] impl Trie> { /// Creates a test trie using a TestAllocator with given capacity. diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index b1e42bc6..35d855b4 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -12,22 +12,20 @@ use ibc::core::ics24_host::identifier::ClientId; use ibc::core::ics24_host::path::{ClientConsensusStatePath, Path}; use ibc::core::timestamp::Timestamp; use ibc::core::{ContextError, ValidationContext}; - +#[cfg(any(test, feature = "mocks"))] +use ibc::mock::client_state::{ + MockClientContext, MockClientState, MOCK_CLIENT_STATE_TYPE_URL, +}; use ibc::{Any, Height}; use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState; +#[cfg(any(test, feature = "mocks"))] +use ibc_proto::ibc::mock::ClientState as RawMockClientState; use ibc_proto::protobuf::Protobuf; use serde::{Deserialize, Serialize}; use super::consensus_state::AnyConsensusState; use crate::SolanaIbcStorage; -#[cfg(any(test, feature = "mocks"))] -use ibc_proto::ibc::mock::ClientState as RawMockClientState; -#[cfg(any(test, feature = "mocks"))] -use ibc::mock::client_state::{ - MockClientContext, MockClientState, MOCK_CLIENT_STATE_TYPE_URL, -}; - const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState"; diff --git a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs index 545efbf7..36405dd4 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs @@ -3,19 +3,16 @@ use ibc::core::ics02_client::consensus_state::ConsensusState; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics23_commitment::commitment::CommitmentRoot; use ibc::core::timestamp::Timestamp; - -use ibc_proto::google::protobuf::Any; -use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState; -use ibc_proto::protobuf::Protobuf; -use serde::{Deserialize, Serialize}; - - #[cfg(any(test, feature = "mocks"))] use ibc::mock::consensus_state::{ MockConsensusState, MOCK_CONSENSUS_STATE_TYPE_URL, }; +use ibc_proto::google::protobuf::Any; +use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState; #[cfg(any(test, feature = "mocks"))] use ibc_proto::ibc::mock::ConsensusState as RawMockConsensusState; +use ibc_proto::protobuf::Protobuf; +use serde::{Deserialize, Serialize}; const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ConsensusState"; diff --git a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs index c46704b3..bdfb21a4 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/execution_context.rs @@ -58,7 +58,11 @@ impl ClientExecutionContext for SolanaIbcStorage { consensus_state_path: ClientConsensusStatePath, consensus_state: Self::AnyConsensusState, ) -> Result { - msg!("store_consensus_state - path: {}, consensus_state: {:?}", consensus_state_path, consensus_state); + msg!( + "store_consensus_state - path: {}, consensus_state: {:?}", + consensus_state_path, + consensus_state + ); let consensus_state_key = ( consensus_state_path.client_id.to_string(), (consensus_state_path.epoch, consensus_state_path.height), diff --git a/solana/solana-ibc/programs/solana-ibc/src/tests.rs b/solana/solana-ibc/programs/solana-ibc/src/tests.rs index 8051b7b8..16ce4cff 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/tests.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/tests.rs @@ -89,7 +89,7 @@ fn anchor_test_deliver() -> Result<()> { .args(instruction::Deliver { messages: all_messages }) .payer(authority.clone()) .signer(&*authority) - .send_with_spinner_and_config(RpcSendTransactionConfig{ + .send_with_spinner_and_config(RpcSendTransactionConfig { skip_preflight: true, ..RpcSendTransactionConfig::default() })?; // ? gives us the log messages on the why the tx did fail ( better than unwrap ) diff --git a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs index 0f014eaf..db2e48ee 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/validation_context.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use std::time::Duration; -use anchor_lang::prelude::{Pubkey, Clock, SolanaSysvar}; +use anchor_lang::prelude::{Clock, Pubkey, SolanaSysvar}; use ibc::core::ics02_client::error::ClientError; use ibc::core::ics03_connection::connection::ConnectionEnd; use ibc::core::ics03_connection::error::ConnectionError; diff --git a/solana/trie-example/src/lib.rs b/solana/trie-example/src/lib.rs index c28564d8..ce808e9d 100644 --- a/solana/trie-example/src/lib.rs +++ b/solana/trie-example/src/lib.rs @@ -72,7 +72,6 @@ impl TrieResultExt for Result { } } - /// Instruction to execute. pub(crate) enum Instruction<'a> { // Encoding: diff --git a/solana/trie-example/src/trie.rs b/solana/trie-example/src/trie.rs index 6456879c..57a83a5d 100644 --- a/solana/trie-example/src/trie.rs +++ b/solana/trie-example/src/trie.rs @@ -211,8 +211,6 @@ impl<'a, 'b> memory::Allocator for Allocator<'a, 'b> { } } - - impl<'a, 'b> core::ops::Deref for AccountTrie<'a, 'b> { type Target = sealable_trie::Trie>; fn deref(&self) -> &Self::Target { &self.0 } @@ -249,7 +247,6 @@ fn write( right } - #[test] fn test_header_encoding() { const ONE: CryptoHash = CryptoHash([1; 32]); From d0584b5380492a646bbb4e1097b321137b330679 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Fri, 13 Oct 2023 19:55:44 +0200 Subject: [PATCH 13/13] reduce diff noise --- .gitignore | 8 ++++---- common/lib/src/varint.rs | 1 + common/sealable-trie/src/nodes.rs | 1 + common/sealable-trie/src/proof/serialisation.rs | 1 + common/sealable-trie/src/trie.rs | 1 + solana/trie-example/src/lib.rs | 1 + solana/trie-example/src/trie.rs | 3 +++ 7 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 3e181d7f..695277c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ +*.rs.bk +.DS_Store .anchor -Cargo.lock /dist/ -.DS_Store -*.rs.bk +Cargo.lock +local-ibc node_modules package-lock.json target test-ledger -local-ibc \ No newline at end of file diff --git a/common/lib/src/varint.rs b/common/lib/src/varint.rs index aa76a235..63f6b4bd 100644 --- a/common/lib/src/varint.rs +++ b/common/lib/src/varint.rs @@ -113,6 +113,7 @@ impl borsh::BorshDeserialize for VarInt { } } + /// Small on-stack buffer. /// /// # Example diff --git a/common/sealable-trie/src/nodes.rs b/common/sealable-trie/src/nodes.rs index c2396512..e714f9fd 100644 --- a/common/sealable-trie/src/nodes.rs +++ b/common/sealable-trie/src/nodes.rs @@ -483,6 +483,7 @@ impl<'a> ValueRef<'a, bool> { pub fn sealed(self) -> Self { Self { is_sealed: true, hash: self.hash } } } + // ============================================================================= // Conversions diff --git a/common/sealable-trie/src/proof/serialisation.rs b/common/sealable-trie/src/proof/serialisation.rs index 21776a53..ebc393d7 100644 --- a/common/sealable-trie/src/proof/serialisation.rs +++ b/common/sealable-trie/src/proof/serialisation.rs @@ -281,6 +281,7 @@ fn invalid_data(msg: String) -> io::Error { io::Error::new(io::ErrorKind::InvalidData, msg) } + #[test] fn test_item_borsh() { #[track_caller] diff --git a/common/sealable-trie/src/trie.rs b/common/sealable-trie/src/trie.rs index 1e3fc246..2257bc5b 100644 --- a/common/sealable-trie/src/trie.rs +++ b/common/sealable-trie/src/trie.rs @@ -328,6 +328,7 @@ impl> Trie { } } + #[cfg(test)] impl Trie> { /// Creates a test trie using a TestAllocator with given capacity. diff --git a/solana/trie-example/src/lib.rs b/solana/trie-example/src/lib.rs index ce808e9d..c28564d8 100644 --- a/solana/trie-example/src/lib.rs +++ b/solana/trie-example/src/lib.rs @@ -72,6 +72,7 @@ impl TrieResultExt for Result { } } + /// Instruction to execute. pub(crate) enum Instruction<'a> { // Encoding: diff --git a/solana/trie-example/src/trie.rs b/solana/trie-example/src/trie.rs index 57a83a5d..6456879c 100644 --- a/solana/trie-example/src/trie.rs +++ b/solana/trie-example/src/trie.rs @@ -211,6 +211,8 @@ impl<'a, 'b> memory::Allocator for Allocator<'a, 'b> { } } + + impl<'a, 'b> core::ops::Deref for AccountTrie<'a, 'b> { type Target = sealable_trie::Trie>; fn deref(&self) -> &Self::Target { &self.0 } @@ -247,6 +249,7 @@ fn write( right } + #[test] fn test_header_encoding() { const ONE: CryptoHash = CryptoHash([1; 32]);