From 1f06661dc05605de953f9abc0461160fc14b1ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 30 Jan 2024 15:07:34 +0000 Subject: [PATCH 01/19] refactor finalize_block token updates --- Cargo.lock | 2 +- .../lib/node/ledger/shell/finalize_block.rs | 24 +- crates/core/src/event.rs | 207 +++++++++++++++++ crates/core/src/lib.rs | 1 + crates/sdk/src/error.rs | 18 +- crates/sdk/src/events/mod.rs | 217 +----------------- crates/shielded_token/src/conversion.rs | 12 + crates/token/Cargo.toml | 2 +- crates/token/src/lib.rs | 23 +- crates/tx/src/lib.rs | 46 ++++ wasm/Cargo.lock | 2 +- wasm_for_tests/wasm_source/Cargo.lock | 2 +- 12 files changed, 308 insertions(+), 248 deletions(-) create mode 100644 crates/core/src/event.rs diff --git a/Cargo.lock b/Cargo.lock index 9ae92171d8..76c4f3198e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4745,7 +4745,7 @@ version = "0.31.5" dependencies = [ "namada_core", "namada_shielded_token", - "namada_storage", + "namada_state", "namada_trans_token", ] diff --git a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs index a65c2af8e7..5de2ee5d6e 100644 --- a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -17,12 +17,12 @@ use namada::state::write_log::StorageModification; use namada::state::{ ResultExt, StorageRead, StorageWrite, EPOCH_SWITCH_BLOCKS_DELAY, }; -use namada::token::conversion::update_allowed_conversions; use namada::tx::data::protocol::ProtocolTxType; use namada::types::key::tm_raw_hash_to_string; use namada::types::storage::{BlockHash, BlockResults, Epoch, Header}; use namada::vote_ext::ethereum_events::MultiSignedEthEvent; use namada::vote_ext::ethereum_tx_data_variants; +use namada_sdk::tx::new_tx_event; use super::governance::execute_governance_proposals; use super::*; @@ -88,12 +88,16 @@ where .expect("Failed tx hashes finalization") } + token::finalize_block( + &mut self.wl_storage, + &mut response.events, + new_epoch, + )?; + let pos_params = namada_proof_of_stake::storage::read_pos_params(&self.wl_storage)?; if new_epoch { - update_allowed_conversions(&mut self.wl_storage)?; - execute_governance_proposals(self, &mut response)?; // Copy the new_epoch + pipeline_len - 1 validator set into @@ -216,7 +220,7 @@ where { let mut tx_event = match tx.header().tx_type { TxType::Wrapper(_) | TxType::Protocol(_) => { - Event::new_tx_event(&tx, height.0) + new_tx_event(&tx, height.0) } _ => { tracing::error!( @@ -249,7 +253,7 @@ where if ResultCode::from_u32(processed_tx.result.code).unwrap() != ResultCode::Ok { - let mut tx_event = Event::new_tx_event(&tx, height.0); + let mut tx_event = new_tx_event(&tx, height.0); tx_event["code"] = processed_tx.result.code.to_string(); tx_event["info"] = format!("Tx rejected: {}", &processed_tx.result.info); @@ -277,7 +281,7 @@ where ) = match &tx_header.tx_type { TxType::Wrapper(wrapper) => { stats.increment_wrapper_txs(); - let tx_event = Event::new_tx_event(&tx, height.0); + let tx_event = new_tx_event(&tx, height.0); let gas_meter = TxGasMeter::new(wrapper.gas_limit); ( tx_event, @@ -298,7 +302,7 @@ where .tx_queue .pop() .expect("Missing wrapper tx in queue"); - let mut event = Event::new_tx_event(&tx, height.0); + let mut event = new_tx_event(&tx, height.0); match inner { DecryptedTx::Decrypted => { @@ -345,7 +349,7 @@ where | ProtocolTxType::BridgePool | ProtocolTxType::ValSetUpdateVext | ProtocolTxType::ValidatorSetUpdate => ( - Event::new_tx_event(&tx, height.0), + new_tx_event(&tx, height.0), None, TxGasMeter::new_from_sub_limit(0.into()), None, @@ -370,7 +374,7 @@ where } } ( - Event::new_tx_event(&tx, height.0), + new_tx_event(&tx, height.0), None, TxGasMeter::new_from_sub_limit(0.into()), None, @@ -398,7 +402,7 @@ where } } ( - Event::new_tx_event(&tx, height.0), + new_tx_event(&tx, height.0), None, TxGasMeter::new_from_sub_limit(0.into()), None, diff --git a/crates/core/src/event.rs b/crates/core/src/event.rs new file mode 100644 index 0000000000..5db1de6131 --- /dev/null +++ b/crates/core/src/event.rs @@ -0,0 +1,207 @@ +//! Ledger events + +use std::collections::HashMap; +use std::fmt::{self, Display}; +use std::ops::{Index, IndexMut}; +use std::str::FromStr; + +use thiserror::Error; + +use crate::borsh::{BorshDeserialize, BorshSerialize}; +use crate::types::ethereum_structs::{BpTransferStatus, EthBridgeEvent}; +use crate::types::ibc::IbcEvent; + +/// Used in sub-systems that may emit events. +pub trait EmitEvents { + /// Emit an event + fn emit(&mut self, value: Event); +} + +impl EmitEvents for Vec { + fn emit(&mut self, value: Event) { + Vec::push(self, value) + } +} + +/// Indicates if an event is emitted do to +/// an individual Tx or the nature of a finalized block +#[derive(Clone, Debug, Eq, PartialEq, BorshSerialize, BorshDeserialize)] +pub enum EventLevel { + /// Indicates an event is to do with a finalized block. + Block, + /// Indicates an event is to do with an individual transaction. + Tx, +} + +/// Custom events that can be queried from Tendermint +/// using a websocket client +#[derive(Clone, Debug, Eq, PartialEq, BorshSerialize, BorshDeserialize)] +pub struct Event { + /// The type of event. + pub event_type: EventType, + /// The level of the event - whether it relates to a block or an individual + /// transaction. + pub level: EventLevel, + /// Key-value attributes of the event. + pub attributes: HashMap, +} + +/// The two types of custom events we currently use +#[derive(Clone, Debug, Eq, PartialEq, BorshSerialize, BorshDeserialize)] +pub enum EventType { + /// The transaction was accepted to be included in a block + Accepted, + /// The transaction was applied during block finalization + Applied, + /// The IBC transaction was applied during block finalization + Ibc(String), + /// The proposal that has been executed + Proposal, + /// The pgf payment + PgfPayment, + /// Ethereum Bridge event + EthereumBridge, +} + +impl Display for EventType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + EventType::Accepted => write!(f, "accepted"), + EventType::Applied => write!(f, "applied"), + EventType::Ibc(t) => write!(f, "{}", t), + EventType::Proposal => write!(f, "proposal"), + EventType::PgfPayment => write!(f, "pgf_payment"), + EventType::EthereumBridge => write!(f, "ethereum_bridge"), + }?; + Ok(()) + } +} + +impl FromStr for EventType { + type Err = EventError; + + fn from_str(s: &str) -> Result { + match s { + "accepted" => Ok(EventType::Accepted), + "applied" => Ok(EventType::Applied), + "proposal" => Ok(EventType::Proposal), + "pgf_payments" => Ok(EventType::PgfPayment), + // IBC + "update_client" => Ok(EventType::Ibc("update_client".to_string())), + "send_packet" => Ok(EventType::Ibc("send_packet".to_string())), + "write_acknowledgement" => { + Ok(EventType::Ibc("write_acknowledgement".to_string())) + } + "ethereum_bridge" => Ok(EventType::EthereumBridge), + _ => Err(EventError::InvalidEventType), + } + } +} + +/// Errors to do with emitting events. +#[derive(Error, Debug, Clone)] +pub enum EventError { + /// Error when parsing an event type + #[error("Invalid event type")] + InvalidEventType, + /// Error when parsing attributes from an event JSON. + #[error("Json missing `attributes` field")] + MissingAttributes, + /// Missing key in attributes. + #[error("Attributes missing key: {0}")] + MissingKey(String), + /// Missing value in attributes. + #[error("Attributes missing value: {0}")] + MissingValue(String), +} + +impl Event { + /// Check if the events keys contains a given string + pub fn contains_key(&self, key: &str) -> bool { + self.attributes.contains_key(key) + } + + /// Get the value corresponding to a given key, if it exists. + /// Else return None. + pub fn get(&self, key: &str) -> Option<&String> { + self.attributes.get(key) + } +} + +impl From for Event { + #[inline] + fn from(event: EthBridgeEvent) -> Event { + Self::from(&event) + } +} + +impl From<&EthBridgeEvent> for Event { + fn from(event: &EthBridgeEvent) -> Event { + match event { + EthBridgeEvent::BridgePool { tx_hash, status } => Event { + event_type: EventType::EthereumBridge, + level: EventLevel::Tx, + attributes: { + let mut attrs = HashMap::new(); + attrs.insert( + "kind".into(), + match status { + BpTransferStatus::Relayed => "bridge_pool_relayed", + BpTransferStatus::Expired => "bridge_pool_expired", + } + .into(), + ); + attrs.insert("tx_hash".into(), tx_hash.to_string()); + attrs + }, + }, + } + } +} + +impl Index<&str> for Event { + type Output = String; + + fn index(&self, index: &str) -> &Self::Output { + &self.attributes[index] + } +} + +impl IndexMut<&str> for Event { + fn index_mut(&mut self, index: &str) -> &mut Self::Output { + if !self.attributes.contains_key(index) { + self.attributes.insert(String::from(index), String::new()); + } + self.attributes.get_mut(index).unwrap() + } +} + +impl From for Event { + fn from(ibc_event: IbcEvent) -> Self { + Self { + event_type: EventType::Ibc(ibc_event.event_type), + level: EventLevel::Tx, + attributes: ibc_event.attributes, + } + } +} + +/// Convert our custom event into the necessary tendermint proto type +impl From for crate::tendermint_proto::v0_37::abci::Event { + fn from(event: Event) -> Self { + Self { + r#type: event.event_type.to_string(), + attributes: event + .attributes + .into_iter() + .map(|(key, value)| { + crate::tendermint_proto::v0_37::abci::EventAttribute { + key, + value, + index: true, + } + }) + .collect(), + } + } +} diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index c0d837517b..a0401d05a2 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -7,6 +7,7 @@ #![deny(rustdoc::private_intra_doc_links)] pub mod bytes; +pub mod event; pub mod hints; pub mod ledger; pub mod types; diff --git a/crates/sdk/src/error.rs b/crates/sdk/src/error.rs index b04b50da13..a8cb147da4 100644 --- a/crates/sdk/src/error.rs +++ b/crates/sdk/src/error.rs @@ -1,5 +1,6 @@ //! Generic Error Type for all of the Shared Crate +use namada_core::event::EventError; use namada_core::types::address::Address; use namada_core::types::dec::Dec; use namada_core::types::ethereum_events::EthAddress; @@ -60,23 +61,6 @@ pub enum PinnedBalanceError { InvalidViewingKey, } -/// Errors to do with emitting events. -#[derive(Error, Debug, Clone)] -pub enum EventError { - /// Error when parsing an event type - #[error("Invalid event type")] - InvalidEventType, - /// Error when parsing attributes from an event JSON. - #[error("Json missing `attributes` field")] - MissingAttributes, - /// Missing key in attributes. - #[error("Attributes missing key: {0}")] - MissingKey(String), - /// Missing value in attributes. - #[error("Attributes missing value: {0}")] - MissingValue(String), -} - /// Errors that deal with querying some kind of data #[derive(Error, Debug, Clone)] pub enum QueryError { diff --git a/crates/sdk/src/events/mod.rs b/crates/sdk/src/events/mod.rs index 646fd1b8d3..73c33f0a64 100644 --- a/crates/sdk/src/events/mod.rs +++ b/crates/sdk/src/events/mod.rs @@ -3,225 +3,12 @@ pub mod log; use std::collections::HashMap; use std::convert::TryFrom; -use std::fmt::{self, Display}; -use std::ops::{Index, IndexMut}; -use std::str::FromStr; -use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::ethereum_structs::{BpTransferStatus, EthBridgeEvent}; -use namada_core::types::ibc::IbcEvent; -use namada_tx::data::TxType; +pub use namada_core::event::{Event, EventError, EventLevel, EventType}; use serde_json::Value; // use crate::ledger::governance::utils::ProposalEvent; -use crate::error::{EncodingError, Error, EventError}; -use crate::tendermint_proto::v0_37::abci::EventAttribute; - -impl From for Event { - #[inline] - fn from(event: EthBridgeEvent) -> Event { - Self::from(&event) - } -} - -impl From<&EthBridgeEvent> for Event { - fn from(event: &EthBridgeEvent) -> Event { - match event { - EthBridgeEvent::BridgePool { tx_hash, status } => Event { - event_type: EventType::EthereumBridge, - level: EventLevel::Tx, - attributes: { - let mut attrs = HashMap::new(); - attrs.insert( - "kind".into(), - match status { - BpTransferStatus::Relayed => "bridge_pool_relayed", - BpTransferStatus::Expired => "bridge_pool_expired", - } - .into(), - ); - attrs.insert("tx_hash".into(), tx_hash.to_string()); - attrs - }, - }, - } - } -} - -/// Indicates if an event is emitted do to -/// an individual Tx or the nature of a finalized block -#[derive(Clone, Debug, Eq, PartialEq, BorshSerialize, BorshDeserialize)] -pub enum EventLevel { - /// Indicates an event is to do with a finalized block. - Block, - /// Indicates an event is to do with an individual transaction. - Tx, -} - -/// Custom events that can be queried from Tendermint -/// using a websocket client -#[derive(Clone, Debug, Eq, PartialEq, BorshSerialize, BorshDeserialize)] -pub struct Event { - /// The type of event. - pub event_type: EventType, - /// The level of the event - whether it relates to a block or an individual - /// transaction. - pub level: EventLevel, - /// Key-value attributes of the event. - pub attributes: HashMap, -} - -/// The two types of custom events we currently use -#[derive(Clone, Debug, Eq, PartialEq, BorshSerialize, BorshDeserialize)] -pub enum EventType { - /// The transaction was accepted to be included in a block - Accepted, - /// The transaction was applied during block finalization - Applied, - /// The IBC transaction was applied during block finalization - Ibc(String), - /// The proposal that has been executed - Proposal, - /// The pgf payment - PgfPayment, - /// Ethereum Bridge event - EthereumBridge, -} - -impl Display for EventType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - EventType::Accepted => write!(f, "accepted"), - EventType::Applied => write!(f, "applied"), - EventType::Ibc(t) => write!(f, "{}", t), - EventType::Proposal => write!(f, "proposal"), - EventType::PgfPayment => write!(f, "pgf_payment"), - EventType::EthereumBridge => write!(f, "ethereum_bridge"), - }?; - Ok(()) - } -} - -impl FromStr for EventType { - type Err = EventError; - - fn from_str(s: &str) -> Result { - match s { - "accepted" => Ok(EventType::Accepted), - "applied" => Ok(EventType::Applied), - "proposal" => Ok(EventType::Proposal), - "pgf_payments" => Ok(EventType::PgfPayment), - // IBC - "update_client" => Ok(EventType::Ibc("update_client".to_string())), - "send_packet" => Ok(EventType::Ibc("send_packet".to_string())), - "write_acknowledgement" => { - Ok(EventType::Ibc("write_acknowledgement".to_string())) - } - "ethereum_bridge" => Ok(EventType::EthereumBridge), - _ => Err(EventError::InvalidEventType), - } - } -} - -impl Event { - /// Creates a new event with the hash and height of the transaction - /// already filled in - pub fn new_tx_event(tx: &namada_tx::Tx, height: u64) -> Self { - let mut event = match tx.header().tx_type { - TxType::Wrapper(_) => { - let mut event = Event { - event_type: EventType::Accepted, - level: EventLevel::Tx, - attributes: HashMap::new(), - }; - event["hash"] = tx.header_hash().to_string(); - event - } - TxType::Decrypted(_) => { - let mut event = Event { - event_type: EventType::Applied, - level: EventLevel::Tx, - attributes: HashMap::new(), - }; - event["hash"] = tx - .clone() - .update_header(TxType::Raw) - .header_hash() - .to_string(); - event - } - TxType::Protocol(_) => { - let mut event = Event { - event_type: EventType::Applied, - level: EventLevel::Tx, - attributes: HashMap::new(), - }; - event["hash"] = tx.header_hash().to_string(); - event - } - _ => unreachable!(), - }; - event["height"] = height.to_string(); - event["log"] = "".to_string(); - event - } - - /// Check if the events keys contains a given string - pub fn contains_key(&self, key: &str) -> bool { - self.attributes.contains_key(key) - } - - /// Get the value corresponding to a given key, if it exists. - /// Else return None. - pub fn get(&self, key: &str) -> Option<&String> { - self.attributes.get(key) - } -} - -impl Index<&str> for Event { - type Output = String; - - fn index(&self, index: &str) -> &Self::Output { - &self.attributes[index] - } -} - -impl IndexMut<&str> for Event { - fn index_mut(&mut self, index: &str) -> &mut Self::Output { - if !self.attributes.contains_key(index) { - self.attributes.insert(String::from(index), String::new()); - } - self.attributes.get_mut(index).unwrap() - } -} - -impl From for Event { - fn from(ibc_event: IbcEvent) -> Self { - Self { - event_type: EventType::Ibc(ibc_event.event_type), - level: EventLevel::Tx, - attributes: ibc_event.attributes, - } - } -} - -/// Convert our custom event into the necessary tendermint proto type -impl From for crate::tendermint_proto::v0_37::abci::Event { - fn from(event: Event) -> Self { - Self { - r#type: event.event_type.to_string(), - attributes: event - .attributes - .into_iter() - .map(|(key, value)| EventAttribute { - key, - value, - index: true, - }) - .collect(), - } - } -} +use crate::error::{EncodingError, Error}; /// A thin wrapper around a HashMap for parsing event JSONs /// returned in tendermint subscription responses. diff --git a/crates/shielded_token/src/conversion.rs b/crates/shielded_token/src/conversion.rs index 23db438d42..06f25246c5 100644 --- a/crates/shielded_token/src/conversion.rs +++ b/crates/shielded_token/src/conversion.rs @@ -182,6 +182,18 @@ where } // This is only enabled when "wasm-runtime" is on, because we're using rayon +#[cfg(not(any(feature = "multicore", test)))] +/// Update the MASP's allowed conversions +pub fn update_allowed_conversions( + _wl_storage: &mut WlStorage, +) -> namada_storage::Result<()> +where + D: 'static + DB + for<'iter> DBIter<'iter>, + H: 'static + StorageHasher, +{ + Ok(()) +} + #[cfg(any(feature = "multicore", test))] /// Update the MASP's allowed conversions pub fn update_allowed_conversions( diff --git a/crates/token/Cargo.toml b/crates/token/Cargo.toml index 1029be2b38..942a45eb4b 100644 --- a/crates/token/Cargo.toml +++ b/crates/token/Cargo.toml @@ -19,5 +19,5 @@ multicore = ["namada_shielded_token/multicore"] [dependencies] namada_core = { path = "../core" } namada_shielded_token = { path = "../shielded_token" } -namada_storage = { path = "../storage" } +namada_state = { path = "../state" } namada_trans_token = { path = "../trans_token" } diff --git a/crates/token/src/lib.rs b/crates/token/src/lib.rs index 9a97c4f89f..deb4b71170 100644 --- a/crates/token/src/lib.rs +++ b/crates/token/src/lib.rs @@ -9,8 +9,12 @@ pub mod storage_key { pub use namada_trans_token::storage_key::*; } +use namada_core::event::EmitEvents; use namada_core::types::address::Address; -use namada_storage::{Result, StorageRead, StorageWrite}; +use namada_state::{ + DBIter, StorageHasher, StorageRead, StorageResult, StorageWrite, WlStorage, + DB, +}; /// Initialize parameters for the token in storage during the genesis block. pub fn write_params( @@ -18,7 +22,7 @@ pub fn write_params( storage: &mut S, address: &Address, denom: &Denomination, -) -> Result<()> +) -> StorageResult<()> where S: StorageRead + StorageWrite, { @@ -28,3 +32,18 @@ where } Ok(()) } + +pub fn finalize_block( + wl_storage: &mut WlStorage, + _events: &mut impl EmitEvents, + is_new_epoch: bool, +) -> StorageResult<()> +where + D: 'static + DB + for<'iter> DBIter<'iter>, + H: 'static + StorageHasher, +{ + if is_new_epoch { + conversion::update_allowed_conversions(wl_storage)?; + } + Ok(()) +} diff --git a/crates/tx/src/lib.rs b/crates/tx/src/lib.rs index 6c69d1f45c..61e7a9040d 100644 --- a/crates/tx/src/lib.rs +++ b/crates/tx/src/lib.rs @@ -4,6 +4,10 @@ pub mod data; pub mod proto; mod types; +use std::collections::HashMap; + +use data::TxType; +use namada_core::event::{Event, EventLevel, EventType}; pub use namada_core::types::key::SignableEthMessage; pub use namada_core::types::sign::SignatureIndex; pub use types::{ @@ -12,6 +16,48 @@ pub use types::{ Signature, Signed, Signer, Tx, TxError, VerifySigError, }; +/// Creates a new event with the hash and height of the transaction +/// already filled in +pub fn new_tx_event(tx: &Tx, height: u64) -> Event { + let mut event = match tx.header().tx_type { + TxType::Wrapper(_) => { + let mut event = Event { + event_type: EventType::Accepted, + level: EventLevel::Tx, + attributes: HashMap::new(), + }; + event["hash"] = tx.header_hash().to_string(); + event + } + TxType::Decrypted(_) => { + let mut event = Event { + event_type: EventType::Applied, + level: EventLevel::Tx, + attributes: HashMap::new(), + }; + event["hash"] = tx + .clone() + .update_header(TxType::Raw) + .header_hash() + .to_string(); + event + } + TxType::Protocol(_) => { + let mut event = Event { + event_type: EventType::Applied, + level: EventLevel::Tx, + attributes: HashMap::new(), + }; + event["hash"] = tx.header_hash().to_string(); + event + } + _ => unreachable!(), + }; + event["height"] = height.to_string(); + event["log"] = "".to_string(); + event +} + #[cfg(test)] mod tests { use data_encoding::HEXLOWER; diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 5b910eaebf..60a54bfa7a 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3737,7 +3737,7 @@ version = "0.31.5" dependencies = [ "namada_core", "namada_shielded_token", - "namada_storage", + "namada_state", "namada_trans_token", ] diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index d55a150fdc..1ecac8bcfd 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3737,7 +3737,7 @@ version = "0.31.5" dependencies = [ "namada_core", "namada_shielded_token", - "namada_storage", + "namada_state", "namada_trans_token", ] From b57211c5a66d5c6b7a854b1d80b274de9ba02fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 30 Jan 2024 15:15:55 +0000 Subject: [PATCH 02/19] refactor finalize_block governance updates --- .../lib/node/ledger/shell/finalize_block.rs | 13 ++++------ .../src/lib/node/ledger/shell/governance.rs | 26 +++++++++++++++---- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs index 5de2ee5d6e..01c13ca737 100644 --- a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -24,7 +24,6 @@ use namada::vote_ext::ethereum_events::MultiSignedEthEvent; use namada::vote_ext::ethereum_tx_data_variants; use namada_sdk::tx::new_tx_event; -use super::governance::execute_governance_proposals; use super::*; use crate::facade::tendermint::abci::types::{Misbehavior, VoteInfo}; use crate::node::ledger::shell::stats::InternalStats; @@ -88,18 +87,16 @@ where .expect("Failed tx hashes finalization") } - token::finalize_block( - &mut self.wl_storage, - &mut response.events, - new_epoch, - )?; + let emit_events = &mut response.events; + + token::finalize_block(&mut self.wl_storage, emit_events, new_epoch)?; + + governance::finalize_block(self, emit_events, new_epoch)?; let pos_params = namada_proof_of_stake::storage::read_pos_params(&self.wl_storage)?; if new_epoch { - execute_governance_proposals(self, &mut response)?; - // Copy the new_epoch + pipeline_len - 1 validator set into // new_epoch + pipeline_len namada_proof_of_stake::validator_set_update::copy_validator_sets_and_positions( diff --git a/crates/apps/src/lib/node/ledger/shell/governance.rs b/crates/apps/src/lib/node/ledger/shell/governance.rs index 119bc789b2..4865f714f5 100644 --- a/crates/apps/src/lib/node/ledger/shell/governance.rs +++ b/crates/apps/src/lib/node/ledger/shell/governance.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use namada::core::event::EmitEvents; use namada::governance::pgf::storage::keys as pgf_storage; use namada::governance::pgf::storage::steward::StewardDetail; use namada::governance::pgf::{storage as pgf, ADDRESS}; @@ -29,15 +30,30 @@ use namada_sdk::proof_of_stake::storage::read_validator_stake; use super::utils::force_read; use super::*; +pub fn finalize_block( + shell: &mut Shell, + events: &mut impl EmitEvents, + is_new_epoch: bool, +) -> Result<()> +where + D: 'static + DB + for<'iter> DBIter<'iter> + Sync, + H: 'static + StorageHasher + Sync, +{ + if is_new_epoch { + execute_governance_proposals(shell, events)?; + } + Ok(()) +} + #[derive(Default)] pub struct ProposalsResult { passed: Vec, rejected: Vec, } -pub fn execute_governance_proposals( +fn execute_governance_proposals( shell: &mut Shell, - response: &mut shim::response::FinalizeBlock, + events: &mut impl EmitEvents, ) -> Result where D: DB + for<'iter> DBIter<'iter> + Sync + 'static, @@ -151,14 +167,14 @@ where .get_last_block_height() + 1; event["height"] = height.to_string(); - response.events.push(event); + events.emit(event); } ProposalEvent::pgf_payments_proposal_event(id, result) .into() } }; - response.events.push(proposal_event); + events.emit(proposal_event); proposals_result.passed.push(id); gov_api::get_proposal_author(&shell.wl_storage, id)? @@ -183,7 +199,7 @@ where } let proposal_event = ProposalEvent::rejected_proposal_event(id).into(); - response.events.push(proposal_event); + events.emit(proposal_event); proposals_result.rejected.push(id); tracing::info!( From 000ae70bafa7c8d332f48a78d3a34ef4e24d46e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 31 Jan 2024 11:30:40 +0000 Subject: [PATCH 03/19] refactor finalize_block PoS updates --- .../lib/node/ledger/shell/finalize_block.rs | 151 ++--------- crates/apps/src/lib/node/ledger/shell/mod.rs | 133 +--------- crates/proof_of_stake/src/lib.rs | 250 +++++++++++++++++- 3 files changed, 269 insertions(+), 265 deletions(-) diff --git a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs index 01c13ca737..725f6913e4 100644 --- a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -8,9 +8,9 @@ use namada::ledger::events::EventType; use namada::ledger::gas::{GasMetering, TxGasMeter}; use namada::ledger::pos::namada_proof_of_stake; use namada::ledger::protocol::{self, WrapperArgs}; +use namada::proof_of_stake; use namada::proof_of_stake::storage::{ - find_validator_by_raw_hash, read_last_block_proposer_address, - write_last_block_proposer_address, + find_validator_by_raw_hash, write_last_block_proposer_address, }; use namada::state::wl_storage::WriteLogAndStorage; use namada::state::write_log::StorageModification; @@ -25,7 +25,7 @@ use namada::vote_ext::ethereum_tx_data_variants; use namada_sdk::tx::new_tx_event; use super::*; -use crate::facade::tendermint::abci::types::{Misbehavior, VoteInfo}; +use crate::facade::tendermint::abci::types::VoteInfo; use crate::node::ledger::shell::stats::InternalStats; impl Shell @@ -60,8 +60,7 @@ where let mut response = shim::response::FinalizeBlock::default(); // Begin the new block and check if a new epoch has begun - let (height, new_epoch) = - self.update_state(req.header, req.hash, req.byzantine_validators); + let (height, new_epoch) = self.update_state(req.header, req.hash); let (current_epoch, _gas) = self.wl_storage.storage.get_current_epoch(); let update_for_tendermint = matches!( @@ -88,99 +87,30 @@ where } let emit_events = &mut response.events; - - token::finalize_block(&mut self.wl_storage, emit_events, new_epoch)?; - - governance::finalize_block(self, emit_events, new_epoch)?; - - let pos_params = - namada_proof_of_stake::storage::read_pos_params(&self.wl_storage)?; - - if new_epoch { - // Copy the new_epoch + pipeline_len - 1 validator set into - // new_epoch + pipeline_len - namada_proof_of_stake::validator_set_update::copy_validator_sets_and_positions( - &mut self.wl_storage, - &pos_params, - current_epoch, - current_epoch + pos_params.pipeline_len, - )?; - - // Compute the total stake of the consensus validator set and record - // it in storage - namada_proof_of_stake::compute_and_store_total_consensus_stake( - &mut self.wl_storage, - current_epoch, - )?; - } - // Get the actual votes from cometBFT in the preferred format let votes = pos_votes_from_abci(&self.wl_storage, &req.votes); - - // Invariant: Has to be applied before `record_slashes_from_evidence` - // because it potentially needs to be able to read validator state from - // previous epoch and jailing validator removes the historical state - if !votes.is_empty() { - self.log_block_rewards( - votes.clone(), - height, - current_epoch, - new_epoch, - )?; - } - - // Invariant: This has to be applied after - // `copy_validator_sets_and_positions` and before `self.update_epoch`. - self.record_slashes_from_evidence(); - // Invariant: This has to be applied after - // `copy_validator_sets_and_positions` if we're starting a new epoch - if new_epoch { - // Invariant: Process slashes before inflation as they may affect - // the rewards in the current epoch. - self.process_slashes(); - self.apply_inflation(current_epoch, &mut response)?; - } - - // Consensus set liveness check - if !votes.is_empty() { - let vote_height = height.prev_height(); - let epoch_of_votes = self - .wl_storage - .storage - .block - .pred_epochs - .get_epoch(vote_height) - .expect( - "Should always find an epoch when looking up the vote \ - height before recording liveness data.", - ); - namada_proof_of_stake::record_liveness_data( - &mut self.wl_storage, - &votes, - epoch_of_votes, - vote_height, - &pos_params, - )?; - } - let validator_set_update_epoch = self.get_validator_set_update_epoch(current_epoch); - // Jail validators for inactivity - namada_proof_of_stake::jail_for_liveness( + // Sub-system updates: + // - Token + token::finalize_block(&mut self.wl_storage, emit_events, new_epoch)?; + // - Governance + governance::finalize_block(self, emit_events, new_epoch)?; + // - PoS + // - Must be applied after governance in case it changes PoS params + proof_of_stake::finalize_block( &mut self.wl_storage, - &pos_params, - current_epoch, + emit_events, + new_epoch, validator_set_update_epoch, + votes, + req.byzantine_validators, )?; if new_epoch { - // Prune liveness data from validators that are no longer in the - // consensus set - namada_proof_of_stake::prune_liveness_data( - &mut self.wl_storage, - current_epoch, - )?; + // Apply PoS and PGF inflation + self.apply_inflation(current_epoch, &mut response)?; } let mut stats = InternalStats::default(); @@ -640,7 +570,6 @@ where &mut self, header: Header, hash: BlockHash, - byzantine_validators: Vec, ) -> (BlockHeight, bool) { let height = self.wl_storage.storage.get_last_block_height() + 1; @@ -655,8 +584,6 @@ where .set_header(header) .expect("Setting a header shouldn't fail"); - self.byzantine_validators = byzantine_validators; - let new_epoch = self .wl_storage .update_epoch(height, header_time) @@ -728,47 +655,6 @@ where Ok(()) } - // Process the proposer and votes in the block to assign their PoS rewards. - fn log_block_rewards( - &mut self, - votes: Vec, - height: BlockHeight, - current_epoch: Epoch, - new_epoch: bool, - ) -> Result<()> { - // Read the block proposer of the previously committed block in storage - // (n-1 if we are in the process of finalizing n right now). - match read_last_block_proposer_address(&self.wl_storage)? { - Some(proposer_address) => { - tracing::debug!( - "Found last block proposer: {proposer_address}" - ); - namada_proof_of_stake::rewards::log_block_rewards( - &mut self.wl_storage, - if new_epoch { - current_epoch.prev() - } else { - current_epoch - }, - &proposer_address, - votes, - )?; - } - None => { - if height > BlockHeight::default().next_height() { - tracing::error!( - "Can't find the last block proposer at height {height}" - ); - } else { - tracing::debug!( - "No last block proposer at height {height}" - ); - } - } - } - Ok(()) - } - // Write the inner tx hash to storage and remove the corresponding wrapper // hash since it's redundant (we check the inner tx hash too when validating // the wrapper). Requires the wrapper transaction as argument to recover @@ -903,6 +789,7 @@ mod test_finalize_block { liveness_missed_votes_handle, liveness_sum_missed_votes_handle, read_consensus_validator_set_addresses, }; + use namada_sdk::tendermint::abci::types::MisbehaviorKind; use namada_test_utils::tx_data::TxWriteData; use namada_test_utils::TestWasms; use test_log::test; diff --git a/crates/apps/src/lib/node/ledger/shell/mod.rs b/crates/apps/src/lib/node/ledger/shell/mod.rs index 28a2cc006a..eadf54dd23 100644 --- a/crates/apps/src/lib/node/ledger/shell/mod.rs +++ b/crates/apps/src/lib/node/ledger/shell/mod.rs @@ -23,7 +23,6 @@ mod vote_extensions; use std::collections::{BTreeSet, HashSet}; use std::convert::{TryFrom, TryInto}; -use std::mem; use std::path::{Path, PathBuf}; #[allow(unused_imports)] use std::rc::Rc; @@ -45,11 +44,9 @@ use namada::ledger::protocol::{ apply_wasm_tx, get_fee_unshielding_transaction, get_transfer_hash_from_storage, ShellParams, }; -use namada::ledger::{parameters, pos, protocol}; +use namada::ledger::{parameters, protocol}; use namada::parameters::validate_tx_bytes; -use namada::proof_of_stake::slashing::{process_slashes, slash}; use namada::proof_of_stake::storage::read_pos_params; -use namada::proof_of_stake::{self}; use namada::state::tx_queue::{ExpiredTx, TxInQueue}; use namada::state::wl_storage::WriteLogAndStorage; use namada::state::write_log::WriteLog; @@ -78,7 +75,6 @@ use tokio::sync::mpsc::{Receiver, UnboundedSender}; use super::ethereum_oracle::{self as oracle, last_processed_block}; use crate::config::{self, genesis, TendermintMode, ValidatorLocalConfig}; -use crate::facade::tendermint::abci::types::{Misbehavior, MisbehaviorKind}; use crate::facade::tendermint::v0_37::abci::{request, response}; use crate::facade::tendermint::{self, validator}; use crate::facade::tendermint_proto::v0_37::crypto::public_key; @@ -337,9 +333,6 @@ where pub chain_id: ChainId, /// The persistent storage with write log pub wl_storage: WlStorage, - /// Byzantine validators given from ABCI++ `prepare_proposal` are stored in - /// this field. They will be slashed when we finalize the block. - byzantine_validators: Vec, /// Path to the base directory with DB data and configs #[allow(dead_code)] pub(crate) base_dir: PathBuf, @@ -520,7 +513,6 @@ where let mut shell = Self { chain_id, wl_storage, - byzantine_validators: vec![], base_dir, wasm_dir, mode, @@ -620,115 +612,6 @@ where } } - /// Apply PoS slashes from the evidence - fn record_slashes_from_evidence(&mut self) { - if !self.byzantine_validators.is_empty() { - let byzantine_validators = - mem::take(&mut self.byzantine_validators); - // TODO: resolve this unwrap() better - let pos_params = read_pos_params(&self.wl_storage).unwrap(); - let current_epoch = self.wl_storage.storage.block.epoch; - for evidence in byzantine_validators { - // dbg!(&evidence); - tracing::info!("Processing evidence {evidence:?}."); - let evidence_height = match u64::try_from(evidence.height) { - Ok(height) => height, - Err(err) => { - tracing::error!( - "Unexpected evidence block height {}", - err - ); - continue; - } - }; - let evidence_epoch = match self - .wl_storage - .storage - .block - .pred_epochs - .get_epoch(BlockHeight(evidence_height)) - { - Some(epoch) => epoch, - None => { - tracing::error!( - "Couldn't find epoch for evidence block height {}", - evidence_height - ); - continue; - } - }; - // Disregard evidences that should have already been processed - // at this time - if evidence_epoch + pos_params.slash_processing_epoch_offset() - - pos_params.cubic_slashing_window_length - <= current_epoch - { - tracing::info!( - "Skipping outdated evidence from epoch \ - {evidence_epoch}" - ); - continue; - } - let slash_type = match evidence.kind { - MisbehaviorKind::DuplicateVote => { - pos::types::SlashType::DuplicateVote - } - MisbehaviorKind::LightClientAttack => { - pos::types::SlashType::LightClientAttack - } - MisbehaviorKind::Unknown => { - tracing::error!("Unknown evidence: {:#?}", evidence); - continue; - } - }; - let validator_raw_hash = - tm_raw_hash_to_string(evidence.validator.address); - let validator = - match proof_of_stake::storage::find_validator_by_raw_hash( - &self.wl_storage, - &validator_raw_hash, - ) - .expect("Must be able to read storage") - { - Some(validator) => validator, - None => { - tracing::error!( - "Cannot find validator's address from raw \ - hash {}", - validator_raw_hash - ); - continue; - } - }; - // Check if we're gonna switch to a new epoch after a delay - let validator_set_update_epoch = - self.get_validator_set_update_epoch(current_epoch); - tracing::info!( - "Slashing {} for {} in epoch {}, block height {} (current \ - epoch = {}, validator set update epoch = \ - {validator_set_update_epoch})", - validator, - slash_type, - evidence_epoch, - evidence_height, - current_epoch - ); - if let Err(err) = slash( - &mut self.wl_storage, - &pos_params, - current_epoch, - evidence_epoch, - evidence_height, - slash_type, - &validator, - validator_set_update_epoch, - ) { - tracing::error!("Error in slashing: {}", err); - } - } - } - } - /// Get the next epoch for which we can request validator set changed pub fn get_validator_set_update_epoch( &self, @@ -751,20 +634,6 @@ where } } - /// Process and apply slashes that have already been recorded for the - /// current epoch - fn process_slashes(&mut self) { - let current_epoch = self.wl_storage.storage.block.epoch; - if let Err(err) = process_slashes(&mut self.wl_storage, current_epoch) { - tracing::error!( - "Error while processing slashes queued for epoch {}: {}", - current_epoch, - err - ); - panic!("Error while processing slashes"); - } - } - /// Commit a block. Persist the application state and return the Merkle root /// hash. pub fn commit(&mut self) -> response::Commit { diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 6fb618db4f..0d5341689b 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -27,9 +27,11 @@ use std::cmp::{self}; use std::collections::{BTreeMap, BTreeSet, HashSet}; pub use error::*; +use namada_core::event::EmitEvents; +use namada_core::tendermint::abci::types::{Misbehavior, MisbehaviorKind}; use namada_core::types::address::{Address, InternalAddress}; use namada_core::types::dec::Dec; -use namada_core::types::key::common; +use namada_core::types::key::{common, tm_raw_hash_to_string}; use namada_core::types::storage::BlockHeight; pub use namada_core::types::storage::{Epoch, Key, KeySeg}; use namada_storage::collections::lazy_map::{self, Collectable, LazyMap}; @@ -2768,3 +2770,249 @@ where } Ok(()) } + +/// Apply PoS updates for a block +pub fn finalize_block( + storage: &mut S, + _events: &mut impl EmitEvents, + is_new_epoch: bool, + validator_set_update_epoch: Epoch, + votes: Vec, + byzantine_validators: Vec, +) -> namada_storage::Result<()> +where + S: StorageWrite + StorageRead, +{ + let height = storage.get_block_height()?; + let current_epoch = storage.get_block_epoch()?; + let pos_params = storage::read_pos_params(storage)?; + + if is_new_epoch { + // Copy the new_epoch + pipeline_len - 1 validator set into + // new_epoch + pipeline_len + validator_set_update::copy_validator_sets_and_positions( + storage, + &pos_params, + current_epoch, + current_epoch + pos_params.pipeline_len, + )?; + + // Compute the total stake of the consensus validator set and record + // it in storage + compute_and_store_total_consensus_stake(storage, current_epoch)?; + } + + // Invariant: Has to be applied before `record_slashes_from_evidence` + // because it potentially needs to be able to read validator state from + // previous epoch and jailing validator removes the historical state + if !votes.is_empty() { + log_block_rewards( + storage, + votes.clone(), + height, + current_epoch, + is_new_epoch, + )?; + } + + // Invariant: This has to be applied after + // `copy_validator_sets_and_positions` and before `self.update_epoch`. + record_slashes_from_evidence( + storage, + byzantine_validators, + &pos_params, + current_epoch, + validator_set_update_epoch, + )?; + + // Invariant: This has to be applied after + // `copy_validator_sets_and_positions` if we're starting a new epoch + if is_new_epoch { + // Invariant: Process slashes before inflation as they may affect + // the rewards in the current epoch. + + // Process and apply slashes that have already been recorded for the + // current epoch + if let Err(err) = slashing::process_slashes(storage, current_epoch) { + tracing::error!( + "Error while processing slashes queued for epoch {}: {}", + current_epoch, + err + ); + panic!("Error while processing slashes"); + } + } + + // Consensus set liveness check + if !votes.is_empty() { + let vote_height = height.prev_height(); + let epoch_of_votes = + storage.get_pred_epochs()?.get_epoch(vote_height).expect( + "Should always find an epoch when looking up the vote height \ + before recording liveness data.", + ); + record_liveness_data( + storage, + &votes, + epoch_of_votes, + vote_height, + &pos_params, + )?; + } + + // Jail validators for inactivity + jail_for_liveness( + storage, + &pos_params, + current_epoch, + validator_set_update_epoch, + )?; + + if is_new_epoch { + // Prune liveness data from validators that are no longer in the + // consensus set + prune_liveness_data(storage, current_epoch)?; + } + + Ok(()) +} + +// Process the proposer and votes in the block to assign their PoS rewards. +fn log_block_rewards( + storage: &mut S, + votes: Vec, + height: BlockHeight, + current_epoch: Epoch, + new_epoch: bool, +) -> namada_storage::Result<()> +where + S: StorageWrite + StorageRead, +{ + // Read the block proposer of the previously committed block in storage + // (n-1 if we are in the process of finalizing n right now). + match storage::read_last_block_proposer_address(storage)? { + Some(proposer_address) => { + tracing::debug!("Found last block proposer: {proposer_address}"); + rewards::log_block_rewards( + storage, + if new_epoch { + current_epoch.prev() + } else { + current_epoch + }, + &proposer_address, + votes, + )?; + } + None => { + if height > BlockHeight::default().next_height() { + tracing::error!( + "Can't find the last block proposer at height {height}" + ); + } else { + tracing::debug!("No last block proposer at height {height}"); + } + } + } + Ok(()) +} + +/// Apply PoS slashes from the evidence +fn record_slashes_from_evidence( + storage: &mut S, + byzantine_validators: Vec, + pos_params: &PosParams, + current_epoch: Epoch, + validator_set_update_epoch: Epoch, +) -> namada_storage::Result<()> +where + S: StorageWrite + StorageRead, +{ + if !byzantine_validators.is_empty() { + let pred_epochs = storage.get_pred_epochs()?; + for evidence in byzantine_validators { + // dbg!(&evidence); + tracing::info!("Processing evidence {evidence:?}."); + let evidence_height = match u64::try_from(evidence.height) { + Ok(height) => height, + Err(err) => { + tracing::error!("Unexpected evidence block height {}", err); + continue; + } + }; + let evidence_epoch = + match pred_epochs.get_epoch(BlockHeight(evidence_height)) { + Some(epoch) => epoch, + None => { + tracing::error!( + "Couldn't find epoch for evidence block height {}", + evidence_height + ); + continue; + } + }; + // Disregard evidences that should have already been processed + // at this time + if evidence_epoch + pos_params.slash_processing_epoch_offset() + - pos_params.cubic_slashing_window_length + <= current_epoch + { + tracing::info!( + "Skipping outdated evidence from epoch {evidence_epoch}" + ); + continue; + } + let slash_type = match evidence.kind { + MisbehaviorKind::DuplicateVote => { + types::SlashType::DuplicateVote + } + MisbehaviorKind::LightClientAttack => { + types::SlashType::LightClientAttack + } + MisbehaviorKind::Unknown => { + tracing::error!("Unknown evidence: {:#?}", evidence); + continue; + } + }; + let validator_raw_hash = + tm_raw_hash_to_string(evidence.validator.address); + let validator = match storage::find_validator_by_raw_hash( + storage, + &validator_raw_hash, + )? { + Some(validator) => validator, + None => { + tracing::error!( + "Cannot find validator's address from raw hash {}", + validator_raw_hash + ); + continue; + } + }; + // Check if we're gonna switch to a new epoch after a delay + tracing::info!( + "Slashing {} for {} in epoch {}, block height {} (current \ + epoch = {}, validator set update epoch = \ + {validator_set_update_epoch})", + validator, + slash_type, + evidence_epoch, + evidence_height, + current_epoch + ); + if let Err(err) = slashing::slash( + storage, + pos_params, + current_epoch, + evidence_epoch, + evidence_height, + slash_type, + &validator, + validator_set_update_epoch, + ) { + tracing::error!("Error in slashing: {}", err); + } + } + } + Ok(()) +} From fdafaa685f3cc0da98dc84a443a93314feffea7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 31 Jan 2024 13:19:43 +0000 Subject: [PATCH 04/19] changelog: add #2482 --- .../unreleased/improvements/2482-refactor-finalize-block.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/2482-refactor-finalize-block.md diff --git a/.changelog/unreleased/improvements/2482-refactor-finalize-block.md b/.changelog/unreleased/improvements/2482-refactor-finalize-block.md new file mode 100644 index 0000000000..79150d5a8e --- /dev/null +++ b/.changelog/unreleased/improvements/2482-refactor-finalize-block.md @@ -0,0 +1,2 @@ +- Refactored sub-systems integration in the ABCI FinalizeBlock request handler. + ([\#2482](https://github.com/anoma/namada/pull/2482)) \ No newline at end of file From 4476583e04d52cd2ec27949bc0b22300720fc248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 31 Jan 2024 13:56:43 +0000 Subject: [PATCH 05/19] replace namada_state usage with namada_storage in token crates --- Cargo.lock | 3 +- .../src/lib/node/ledger/storage/rocksdb.rs | 2 +- crates/core/src/lib.rs | 2 +- crates/core/src/types/token.rs | 29 +--- crates/shielded_token/Cargo.toml | 3 +- crates/shielded_token/src/conversion.rs | 162 +++++++++--------- crates/shielded_token/src/lib.rs | 3 + crates/state/src/lib.rs | 2 +- crates/state/src/wl_storage.rs | 15 ++ crates/storage/src/conversion_state.rs | 43 +++++ crates/storage/src/db.rs | 2 +- crates/storage/src/lib.rs | 14 ++ crates/storage/src/mockdb.rs | 2 +- crates/token/Cargo.toml | 2 +- crates/token/src/lib.rs | 18 +- wasm/Cargo.lock | 3 +- wasm_for_tests/wasm_source/Cargo.lock | 3 +- 17 files changed, 170 insertions(+), 138 deletions(-) create mode 100644 crates/storage/src/conversion_state.rs diff --git a/Cargo.lock b/Cargo.lock index 76c4f3198e..7191371a93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4629,7 +4629,6 @@ dependencies = [ "masp_primitives", "namada_core", "namada_parameters", - "namada_state", "namada_storage", "namada_trans_token", "proptest", @@ -4745,7 +4744,7 @@ version = "0.31.5" dependencies = [ "namada_core", "namada_shielded_token", - "namada_state", + "namada_storage", "namada_trans_token", ] diff --git a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs index c708605ad7..54bf05152a 100644 --- a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs +++ b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs @@ -58,13 +58,13 @@ use namada::state::{ BlockStateRead, BlockStateWrite, DBIter, DBWriteBatch, DbError as Error, DbResult as Result, MerkleTreeStoresRead, StoreType, DB, }; +use namada::token::ConversionState; use namada::types; use namada::types::storage::{ BlockHeight, BlockResults, Epoch, EthEventsQueue, Header, Key, KeySeg, KEY_SEGMENT_SEPARATOR, }; use namada::types::time::DateTimeUtc; -use namada::types::token::ConversionState; use namada::types::{ethereum_events, ethereum_structs}; use rayon::prelude::*; use rocksdb::{ diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index a0401d05a2..d3dd426fb5 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -12,7 +12,7 @@ pub mod hints; pub mod ledger; pub mod types; -pub use {ibc, tendermint, tendermint_proto}; +pub use {ibc, masp_primitives, tendermint, tendermint_proto}; /// Borsh binary encoding (re-exported) from official crate with custom ext. pub mod borsh { pub use borsh::*; diff --git a/crates/core/src/types/token.rs b/crates/core/src/types/token.rs index 02370b9854..4ee2983638 100644 --- a/crates/core/src/types/token.rs +++ b/crates/core/src/types/token.rs @@ -1,7 +1,6 @@ //! A basic fungible token use std::cmp::Ordering; -use std::collections::BTreeMap; use std::fmt::Display; use std::iter::Sum; use std::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign}; @@ -10,10 +9,6 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use data_encoding::BASE32HEX_NOPAD; use ethabi::ethereum_types::U256; -use masp_primitives::asset_type::AssetType; -use masp_primitives::convert::AllowedConversion; -use masp_primitives::merkle_tree::FrozenCommitmentTree; -use masp_primitives::sapling; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -22,31 +17,9 @@ use crate::types::address::Address; use crate::types::dec::{Dec, POS_DECIMAL_PRECISION}; use crate::types::hash::Hash; use crate::types::storage; -use crate::types::storage::{DbKeySeg, Epoch, KeySeg}; +use crate::types::storage::{DbKeySeg, KeySeg}; use crate::types::uint::{self, Uint, I256}; -/// A representation of the conversion state -#[derive(Debug, Default, BorshSerialize, BorshDeserialize)] -pub struct ConversionState { - /// The last amount of the native token distributed - pub normed_inflation: Option, - /// The tree currently containing all the conversions - pub tree: FrozenCommitmentTree, - /// A map from token alias to actual address. - pub tokens: BTreeMap, - /// Map assets to their latest conversion and position in Merkle tree - #[allow(clippy::type_complexity)] - pub assets: BTreeMap< - AssetType, - ( - (Address, Denomination, MaspDigitPos), - Epoch, - AllowedConversion, - usize, - ), - >, -} - /// Amount in micro units. For different granularity another representation /// might be more appropriate. #[derive( diff --git a/crates/shielded_token/Cargo.toml b/crates/shielded_token/Cargo.toml index 87302cd42f..990f46bc1d 100644 --- a/crates/shielded_token/Cargo.toml +++ b/crates/shielded_token/Cargo.toml @@ -20,7 +20,6 @@ testing = ["multicore", "namada_core/testing"] [dependencies] namada_core = { path = "../core" } namada_parameters = { path = "../parameters" } -namada_state = { path = "../state" } namada_storage = { path = "../storage" } namada_trans_token = { path = "../trans_token" } @@ -30,7 +29,7 @@ tracing.workspace = true [dev-dependencies] namada_core = { path = "../core", features = ["testing"] } -namada_state = { path = "../state", features = ["testing"] } +namada_storage = { path = "../storage", features = ["testing"] } proptest.workspace = true rayon.workspace = true diff --git a/crates/shielded_token/src/conversion.rs b/crates/shielded_token/src/conversion.rs index 06f25246c5..839ab42597 100644 --- a/crates/shielded_token/src/conversion.rs +++ b/crates/shielded_token/src/conversion.rs @@ -7,7 +7,6 @@ use namada_core::types::address::{Address, MASP}; use namada_core::types::dec::Dec; use namada_core::types::uint::Uint; use namada_parameters as parameters; -use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_storage::{StorageRead, StorageWrite}; use namada_trans_token::storage_key::{balance_key, minted_balance_key}; use namada_trans_token::{read_denom, Amount, DenominatedAmount, Denomination}; @@ -17,19 +16,19 @@ use crate::storage_key::{ masp_last_locked_amount_key, masp_locked_amount_target_key, masp_max_reward_rate_key, }; +use crate::WithConversionState; /// Compute the precision of MASP rewards for the given token. This function /// must be a non-zero constant for a given token. -pub fn calculate_masp_rewards_precision( - wl_storage: &mut WlStorage, +pub fn calculate_masp_rewards_precision( + storage: &mut S, addr: &Address, ) -> namada_storage::Result<(u128, Denomination)> where - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, + S: StorageWrite + StorageRead, { - let denomination = read_denom(wl_storage, addr)? - .expect("failed to read token denomination"); + let denomination = + read_denom(storage, addr)?.expect("failed to read token denomination"); // Inflation is implicitly denominated by this value. The lower this // figure, the less precise inflation computations are. This is especially // problematic when inflation is coming from a token with much higher @@ -45,58 +44,58 @@ where /// Compute the MASP rewards by applying the PD-controller to the genesis /// parameters and the last inflation and last locked rewards ratio values. -pub fn calculate_masp_rewards( - wl_storage: &mut WlStorage, +pub fn calculate_masp_rewards( + storage: &mut S, token: &Address, ) -> namada_storage::Result<((u128, u128), Denomination)> where - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, + S: StorageWrite + StorageRead, { let (precision, denomination) = - calculate_masp_rewards_precision(wl_storage, token)?; + calculate_masp_rewards_precision(storage, token)?; let masp_addr = MASP; // Query the storage for information ------------------------- + let native_token = storage.get_native_token()?; //// information about the amount of native tokens on the chain - let total_native_tokens: Amount = wl_storage - .read(&minted_balance_key(&wl_storage.storage.native_token))? + let total_native_tokens: Amount = storage + .read(&minted_balance_key(&native_token))? .expect("the total supply key should be here"); // total locked amount in the Shielded pool - let total_tokens_in_masp: Amount = wl_storage + let total_tokens_in_masp: Amount = storage .read(&balance_key(token, &masp_addr))? .unwrap_or_default(); - let epochs_per_year: u64 = wl_storage + let epochs_per_year: u64 = storage .read(¶meters::storage::get_epochs_per_year_key())? .expect("epochs per year should properly decode"); //// Values from the last epoch - let last_inflation: Amount = wl_storage + let last_inflation: Amount = storage .read(&masp_last_inflation_key(token))? .expect("failure to read last inflation"); - let last_locked_amount: Amount = wl_storage + let last_locked_amount: Amount = storage .read(&masp_last_locked_amount_key(token))? .expect("failure to read last inflation"); //// Parameters for each token - let max_reward_rate: Dec = wl_storage + let max_reward_rate: Dec = storage .read(&masp_max_reward_rate_key(token))? .expect("max reward should properly decode"); - let kp_gain_nom: Dec = wl_storage + let kp_gain_nom: Dec = storage .read(&masp_kp_gain_key(token))? .expect("kp_gain_nom reward should properly decode"); - let kd_gain_nom: Dec = wl_storage + let kd_gain_nom: Dec = storage .read(&masp_kd_gain_key(token))? .expect("kd_gain_nom reward should properly decode"); - let target_locked_amount: Amount = wl_storage + let target_locked_amount: Amount = storage .read(&masp_locked_amount_target_key(token))? .expect("locked ratio target should properly decode"); @@ -173,10 +172,9 @@ where // but we should make sure the return value's ratio matches // this new inflation rate in 'update_allowed_conversions', // otherwise we will have an inaccurate view of inflation - wl_storage.write(&masp_last_inflation_key(token), inflation_amount)?; + storage.write(&masp_last_inflation_key(token), inflation_amount)?; - wl_storage - .write(&masp_last_locked_amount_key(token), total_tokens_in_masp)?; + storage.write(&masp_last_locked_amount_key(token), total_tokens_in_masp)?; Ok(((noterized_inflation, precision), denomination)) } @@ -184,24 +182,22 @@ where // This is only enabled when "wasm-runtime" is on, because we're using rayon #[cfg(not(any(feature = "multicore", test)))] /// Update the MASP's allowed conversions -pub fn update_allowed_conversions( - _wl_storage: &mut WlStorage, +pub fn update_allowed_conversions( + _storage: &mut S, ) -> namada_storage::Result<()> where - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, + S: StorageWrite + StorageRead + WithConversionState, { Ok(()) } #[cfg(any(feature = "multicore", test))] /// Update the MASP's allowed conversions -pub fn update_allowed_conversions( - wl_storage: &mut WlStorage, +pub fn update_allowed_conversions( + storage: &mut S, ) -> namada_storage::Result<()> where - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, + S: StorageWrite + StorageRead + WithConversionState, { use std::cmp::Ordering; use std::collections::BTreeMap; @@ -224,9 +220,8 @@ where // The derived conversions will be placed in MASP address space let masp_addr = MASP; - let mut masp_reward_keys: Vec<_> = wl_storage - .storage - .conversion_state + let mut masp_reward_keys: Vec<_> = storage + .conversion_state() .tokens .values() .cloned() @@ -234,7 +229,7 @@ where let mut masp_reward_denoms = BTreeMap::new(); // Put the native rewards first because other inflation computations depend // on it - let native_token = wl_storage.storage.native_token.clone(); + let native_token = storage.get_native_token()?; masp_reward_keys.sort_unstable_by(|x, y| { if (*x == native_token) == (*y == native_token) { Ordering::Equal @@ -288,20 +283,24 @@ where >::new(); // Native token inflation values are always with respect to this let ref_inflation = - calculate_masp_rewards_precision(wl_storage, &native_token)?.0; + calculate_masp_rewards_precision(storage, &native_token)?.0; // Reward all tokens according to above reward rates + let epoch = storage.get_block_epoch()?; + if epoch == Epoch::default() { + return Ok(()); + } + let prev_epoch = epoch.prev(); for token in &masp_reward_keys { - let (reward, denom) = calculate_masp_rewards(wl_storage, token)?; + let (reward, denom) = calculate_masp_rewards(storage, token)?; masp_reward_denoms.insert(token.clone(), denom); // Dispense a transparent reward in parallel to the shielded rewards - let addr_bal: Amount = wl_storage + let addr_bal: Amount = storage .read(&balance_key(token, &masp_addr))? .unwrap_or_default(); // Get the last rewarded amount of the native token - let normed_inflation = wl_storage - .storage - .conversion_state + let normed_inflation = *storage + .conversion_state_mut() .normed_inflation .get_or_insert(ref_inflation); @@ -313,23 +312,19 @@ where token.clone(), denom, digit, - Some(wl_storage.storage.last_epoch), - ) - .into_storage_result()?; - let new_asset = encode_asset_type( - token.clone(), - denom, - digit, - Some(wl_storage.storage.block.epoch), + Some(prev_epoch), ) .into_storage_result()?; + let new_asset = + encode_asset_type(token.clone(), denom, digit, Some(epoch)) + .into_storage_result()?; if *token == native_token { // The amount that will be given of the new native token for // every amount of the native token given in the // previous epoch - let new_normed_inflation = Uint::from(*normed_inflation) + let new_normed_inflation = Uint::from(normed_inflation) .checked_add( - (Uint::from(*normed_inflation) * Uint::from(reward.0)) + (Uint::from(normed_inflation) * Uint::from(reward.0)) / reward.1, ) .and_then(|x| x.try_into().ok()) @@ -340,7 +335,7 @@ where inflation parameters.", token ); - *normed_inflation + normed_inflation }); // The conversion is computed such that if consecutive // conversions are added together, the @@ -350,7 +345,7 @@ where (token.clone(), denom, digit), (MaspAmount::from_pair( old_asset, - -(*normed_inflation as i128), + -(normed_inflation as i128), ) .unwrap() + MaspAmount::from_pair( @@ -365,7 +360,7 @@ where // The reward for each reward.1 units of the current asset // is reward.0 units of the reward token let native_reward = - addr_bal * (new_normed_inflation, *normed_inflation); + addr_bal * (new_normed_inflation, normed_inflation); total_reward += native_reward .0 .checked_add(native_reward.1) @@ -373,7 +368,11 @@ where .checked_sub(addr_bal) .unwrap_or_default(); // Save the new normed inflation - *normed_inflation = new_normed_inflation; + + let _ = storage + .conversion_state_mut() + .normed_inflation + .insert(new_normed_inflation); } } else { // Express the inflation reward in real terms, that is, with @@ -381,7 +380,7 @@ where // epoch let real_reward = ((Uint::from(reward.0) * Uint::from(ref_inflation)) - / *normed_inflation) + / normed_inflation) .try_into() .unwrap_or_else(|_| { tracing::warn!( @@ -416,11 +415,11 @@ where } } // Add a conversion from the previous asset type - wl_storage.storage.conversion_state.assets.insert( + storage.conversion_state_mut().assets.insert( old_asset, ( (token.clone(), denom, digit), - wl_storage.storage.last_epoch, + prev_epoch, MaspAmount::zero().into(), 0, ), @@ -432,9 +431,8 @@ where // multiple cores let num_threads = rayon::current_num_threads(); // Put assets into vector to enable computation batching - let assets: Vec<_> = wl_storage - .storage - .conversion_state + let assets: Vec<_> = storage + .conversion_state_mut() .assets .values_mut() .enumerate() @@ -464,9 +462,9 @@ where // Update the MASP's transparent reward token balance to ensure that it // is sufficiently backed to redeem rewards let reward_key = balance_key(&native_token, &masp_addr); - let addr_bal: Amount = wl_storage.read(&reward_key)?.unwrap_or_default(); + let addr_bal: Amount = storage.read(&reward_key)?.unwrap_or_default(); let new_bal = addr_bal + total_reward; - wl_storage.write(&reward_key, new_bal)?; + storage.write(&reward_key, new_bal)?; // Try to distribute Merkle tree construction as evenly as possible // across multiple cores // Merkle trees must have exactly 2^n leaves to be mergeable @@ -482,16 +480,14 @@ where // Convert conversion vector into tree so that Merkle paths can be // obtained - wl_storage.storage.conversion_state.tree = + storage.conversion_state_mut().tree = FrozenCommitmentTree::merge(&tree_parts); // Update the anchor in storage - wl_storage.write( + storage.write( &crate::storage_key::masp_convert_anchor_key(), namada_core::types::hash::Hash( - bls12_381::Scalar::from( - wl_storage.storage.conversion_state.tree.root(), - ) - .to_bytes(), + bls12_381::Scalar::from(storage.conversion_state().tree.root()) + .to_bytes(), ), )?; @@ -506,20 +502,17 @@ where for digit in MaspDigitPos::iter() { // Add the decoding entry for the new asset type. An uncommitted // node position is used since this is not a conversion. - let new_asset = encode_asset_type( - addr.clone(), - denom, - digit, - Some(wl_storage.storage.block.epoch), - ) - .into_storage_result()?; - wl_storage.storage.conversion_state.assets.insert( + let new_asset = + encode_asset_type(addr.clone(), denom, digit, Some(epoch)) + .into_storage_result()?; + let tree_size = storage.conversion_state().tree.size(); + storage.conversion_state_mut().assets.insert( new_asset, ( (addr.clone(), denom, digit), - wl_storage.storage.block.epoch, + epoch, MaspAmount::zero().into(), - wl_storage.storage.conversion_state.tree.size(), + tree_size, ), ); } @@ -538,7 +531,7 @@ mod tests { use namada_core::types::time::DurationSecs; use namada_core::types::token::testing::arb_amount; use namada_parameters::{EpochDuration, Parameters}; - use namada_state::testing::TestWlStorage; + use namada_storage::testing::TestStorage; use namada_trans_token::{write_denom, Denomination, MaspParams}; use proptest::prelude::*; use proptest::test_runner::Config; @@ -566,7 +559,7 @@ mod tests { ) { const ROUNDS: usize = 10; - let mut s = TestWlStorage::default(); + let mut s = TestStorage::default(); let params = Parameters { max_tx_bytes: 1024 * 1024, epoch_duration: EpochDuration { @@ -621,8 +614,7 @@ mod tests { .unwrap(); // Insert tokens into MASP conversion state - s.storage - .conversion_state + s.conversion_state_mut() .tokens .insert(alias.to_string(), token_addr.clone()); } diff --git a/crates/shielded_token/src/lib.rs b/crates/shielded_token/src/lib.rs index 6e747b14da..60da422716 100644 --- a/crates/shielded_token/src/lib.rs +++ b/crates/shielded_token/src/lib.rs @@ -5,4 +5,7 @@ mod storage; pub mod storage_key; pub mod utils; +pub use namada_storage::conversion_state::{ + ConversionState, WithConversionState, +}; pub use storage::*; diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 8274277158..fa7b0ab116 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -22,7 +22,6 @@ pub use namada_core::types::storage::{ EPOCH_TYPE_LENGTH, }; use namada_core::types::time::DateTimeUtc; -pub use namada_core::types::token::ConversionState; use namada_core::types::{encode, ethereum_structs, storage}; use namada_gas::{ MEMORY_ACCESS_GAS_PER_BYTE, STORAGE_ACCESS_GAS_PER_BYTE, @@ -34,6 +33,7 @@ pub use namada_merkle_tree::{ }; use namada_merkle_tree::{Error as MerkleTreeError, MerkleRoot}; use namada_parameters::{self, EpochDuration, Parameters}; +pub use namada_storage::conversion_state::ConversionState; pub use namada_storage::{Error as StorageError, Result as StorageResult, *}; use thiserror::Error; use tx_queue::{ExpiredTxsQueue, TxQueue}; diff --git a/crates/state/src/wl_storage.rs b/crates/state/src/wl_storage.rs index e971315a99..270a8fc005 100644 --- a/crates/state/src/wl_storage.rs +++ b/crates/state/src/wl_storage.rs @@ -7,6 +7,7 @@ use namada_core::types::hash::{Hash, StorageHasher}; use namada_core::types::storage::{self, BlockHeight, Epochs}; use namada_core::types::time::DateTimeUtc; use namada_parameters::EpochDuration; +use namada_storage::conversion_state::{ConversionState, WithConversionState}; use namada_storage::{ResultExt, StorageRead, StorageWrite}; use super::EPOCH_SWITCH_BLOCKS_DELAY; @@ -572,6 +573,20 @@ macro_rules! impl_storage_traits { impl_storage_traits!(WlStorage); impl_storage_traits!(TempWlStorage<'_, D, H>); +impl WithConversionState for WlStorage +where + D: DB + for<'iter> DBIter<'iter>, + H: StorageHasher, +{ + fn conversion_state(&self) -> &ConversionState { + &self.storage.conversion_state + } + + fn conversion_state_mut(&mut self) -> &mut ConversionState { + &mut self.storage.conversion_state + } +} + #[cfg(test)] mod tests { use std::collections::BTreeMap; diff --git a/crates/storage/src/conversion_state.rs b/crates/storage/src/conversion_state.rs new file mode 100644 index 0000000000..5ef405c4db --- /dev/null +++ b/crates/storage/src/conversion_state.rs @@ -0,0 +1,43 @@ +//! Shielded tokens conversion state + +use std::collections::BTreeMap; + +use namada_core::borsh::{BorshDeserialize, BorshSerialize}; +use namada_core::masp_primitives::asset_type::AssetType; +use namada_core::masp_primitives::convert::AllowedConversion; +use namada_core::masp_primitives::merkle_tree::FrozenCommitmentTree; +use namada_core::masp_primitives::sapling; +use namada_core::types::address::Address; +use namada_core::types::storage::Epoch; +use namada_core::types::token::{Denomination, MaspDigitPos}; + +/// A representation of the conversion state +#[derive(Debug, Default, BorshSerialize, BorshDeserialize)] +pub struct ConversionState { + /// The last amount of the native token distributed + pub normed_inflation: Option, + /// The tree currently containing all the conversions + pub tree: FrozenCommitmentTree, + /// A map from token alias to actual address. + pub tokens: BTreeMap, + /// Map assets to their latest conversion and position in Merkle tree + #[allow(clippy::type_complexity)] + pub assets: BTreeMap< + AssetType, + ( + (Address, Denomination, MaspDigitPos), + Epoch, + AllowedConversion, + usize, + ), + >, +} + +/// Able to borrow mutable conversion state. +pub trait WithConversionState { + /// Borrow immutable conversion state + fn conversion_state(&self) -> &ConversionState; + + /// Borrow mutable conversion state + fn conversion_state_mut(&mut self) -> &mut ConversionState; +} diff --git a/crates/storage/src/db.rs b/crates/storage/src/db.rs index 7eef20b918..34f7f90a15 100644 --- a/crates/storage/src/db.rs +++ b/crates/storage/src/db.rs @@ -7,7 +7,6 @@ use namada_core::types::storage::{ Header, Key, }; use namada_core::types::time::DateTimeUtc; -use namada_core::types::token::ConversionState; use namada_core::types::{ethereum_events, ethereum_structs}; use namada_merkle_tree::{ Error as MerkleTreeError, MerkleTreeStoresRead, MerkleTreeStoresWrite, @@ -15,6 +14,7 @@ use namada_merkle_tree::{ }; use thiserror::Error; +use crate::conversion_state::ConversionState; use crate::tx_queue::TxQueue; #[allow(missing_docs)] diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 334e51e50e..a2ebabb6a2 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -2,6 +2,7 @@ //! and VPs (both native and WASM). pub mod collections; +pub mod conversion_state; mod db; mod error; pub mod mockdb; @@ -310,6 +311,7 @@ pub mod testing { use super::mockdb::MockDB; use super::*; + use crate::conversion_state::{ConversionState, WithConversionState}; /// Storage with a mock DB for testing pub struct TestStorage { @@ -319,6 +321,7 @@ pub mod testing { epoch: Epoch, pred_epochs: Epochs, native_token: Address, + conversion_state: ConversionState, merkle_tree_key_filter: fn(&storage::Key) -> bool, } @@ -336,6 +339,7 @@ pub mod testing { epoch: Epoch::default(), pred_epochs: Epochs::default(), native_token: address::nam(), + conversion_state: ConversionState::default(), merkle_tree_key_filter: merklize_all_keys, } } @@ -427,6 +431,16 @@ pub mod testing { } } + impl WithConversionState for TestStorage { + fn conversion_state(&self) -> &ConversionState { + &self.conversion_state + } + + fn conversion_state_mut(&mut self) -> &mut ConversionState { + &mut self.conversion_state + } + } + /// Prefix iterator for [`TestStorage`]. #[derive(Debug)] pub struct PrefixIter<'iter> { diff --git a/crates/storage/src/mockdb.rs b/crates/storage/src/mockdb.rs index c23801536c..b18162e447 100644 --- a/crates/storage/src/mockdb.rs +++ b/crates/storage/src/mockdb.rs @@ -16,12 +16,12 @@ use namada_core::types::storage::{ KEY_SEGMENT_SEPARATOR, }; use namada_core::types::time::DateTimeUtc; -use namada_core::types::token::ConversionState; use namada_core::types::{ethereum_events, ethereum_structs}; use namada_merkle_tree::{ base_tree_key_prefix, subtree_key_prefix, MerkleTreeStoresRead, StoreType, }; +use crate::conversion_state::ConversionState; use crate::db::{ BlockStateRead, BlockStateWrite, DBIter, DBWriteBatch, Error, Result, DB, }; diff --git a/crates/token/Cargo.toml b/crates/token/Cargo.toml index 942a45eb4b..1029be2b38 100644 --- a/crates/token/Cargo.toml +++ b/crates/token/Cargo.toml @@ -19,5 +19,5 @@ multicore = ["namada_shielded_token/multicore"] [dependencies] namada_core = { path = "../core" } namada_shielded_token = { path = "../shielded_token" } -namada_state = { path = "../state" } +namada_storage = { path = "../storage" } namada_trans_token = { path = "../trans_token" } diff --git a/crates/token/src/lib.rs b/crates/token/src/lib.rs index deb4b71170..89fa8e1f1f 100644 --- a/crates/token/src/lib.rs +++ b/crates/token/src/lib.rs @@ -11,10 +11,7 @@ pub mod storage_key { use namada_core::event::EmitEvents; use namada_core::types::address::Address; -use namada_state::{ - DBIter, StorageHasher, StorageRead, StorageResult, StorageWrite, WlStorage, - DB, -}; +use namada_storage::{Result, StorageRead, StorageWrite}; /// Initialize parameters for the token in storage during the genesis block. pub fn write_params( @@ -22,7 +19,7 @@ pub fn write_params( storage: &mut S, address: &Address, denom: &Denomination, -) -> StorageResult<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -33,17 +30,16 @@ where Ok(()) } -pub fn finalize_block( - wl_storage: &mut WlStorage, +pub fn finalize_block( + storage: &mut S, _events: &mut impl EmitEvents, is_new_epoch: bool, -) -> StorageResult<()> +) -> Result<()> where - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, + S: StorageWrite + StorageRead + WithConversionState, { if is_new_epoch { - conversion::update_allowed_conversions(wl_storage)?; + conversion::update_allowed_conversions(storage)?; } Ok(()) } diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 60a54bfa7a..e9f97c7b87 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3646,7 +3646,6 @@ dependencies = [ "masp_primitives", "namada_core", "namada_parameters", - "namada_state", "namada_storage", "namada_trans_token", "tracing", @@ -3737,7 +3736,7 @@ version = "0.31.5" dependencies = [ "namada_core", "namada_shielded_token", - "namada_state", + "namada_storage", "namada_trans_token", ] diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 1ecac8bcfd..245d44e834 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3646,7 +3646,6 @@ dependencies = [ "masp_primitives", "namada_core", "namada_parameters", - "namada_state", "namada_storage", "namada_trans_token", "tracing", @@ -3737,7 +3736,7 @@ version = "0.31.5" dependencies = [ "namada_core", "namada_shielded_token", - "namada_state", + "namada_storage", "namada_trans_token", ] From 99808f1fd3ce58c68749d7d70418e66c2211b5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 31 Jan 2024 14:02:55 +0000 Subject: [PATCH 06/19] move inflation from core to trans_token --- crates/core/src/ledger/mod.rs | 1 - crates/proof_of_stake/src/rewards.rs | 3 +-- crates/shielded_token/src/conversion.rs | 6 +++--- crates/{core/src/ledger => trans_token/src}/inflation.rs | 4 ++-- crates/trans_token/src/lib.rs | 1 + 5 files changed, 7 insertions(+), 8 deletions(-) rename crates/{core/src/ledger => trans_token/src}/inflation.rs (99%) diff --git a/crates/core/src/ledger/mod.rs b/crates/core/src/ledger/mod.rs index 70c1773bfb..5122eb8b91 100644 --- a/crates/core/src/ledger/mod.rs +++ b/crates/core/src/ledger/mod.rs @@ -1,5 +1,4 @@ //! The ledger modules pub mod eth_bridge; -pub mod inflation; pub mod replay_protection; diff --git a/crates/proof_of_stake/src/rewards.rs b/crates/proof_of_stake/src/rewards.rs index 78e7accdb4..c81a517db4 100644 --- a/crates/proof_of_stake/src/rewards.rs +++ b/crates/proof_of_stake/src/rewards.rs @@ -2,7 +2,6 @@ use std::collections::{HashMap, HashSet}; -use namada_core::ledger::inflation; use namada_core::types::address::{self, Address}; use namada_core::types::dec::Dec; use namada_core::types::storage::Epoch; @@ -19,8 +18,8 @@ use crate::storage::{ rewards_accumulator_handle, validator_commission_rate_handle, validator_rewards_products_handle, validator_state_handle, }; -use crate::token::credit_tokens; use crate::token::storage_key::minted_balance_key; +use crate::token::{credit_tokens, inflation}; use crate::types::{into_tm_voting_power, BondId, ValidatorState, VoteInfo}; use crate::{ bond_amounts_for_rewards, get_total_consensus_stake, staking_token_address, diff --git a/crates/shielded_token/src/conversion.rs b/crates/shielded_token/src/conversion.rs index 839ab42597..22f48de417 100644 --- a/crates/shielded_token/src/conversion.rs +++ b/crates/shielded_token/src/conversion.rs @@ -1,13 +1,13 @@ //! MASP rewards conversions -use namada_core::ledger::inflation::{ - ShieldedRewardsController, ShieldedValsToUpdate, -}; use namada_core::types::address::{Address, MASP}; use namada_core::types::dec::Dec; use namada_core::types::uint::Uint; use namada_parameters as parameters; use namada_storage::{StorageRead, StorageWrite}; +use namada_trans_token::inflation::{ + ShieldedRewardsController, ShieldedValsToUpdate, +}; use namada_trans_token::storage_key::{balance_key, minted_balance_key}; use namada_trans_token::{read_denom, Amount, DenominatedAmount, Denomination}; diff --git a/crates/core/src/ledger/inflation.rs b/crates/trans_token/src/inflation.rs similarity index 99% rename from crates/core/src/ledger/inflation.rs rename to crates/trans_token/src/inflation.rs index d7600a2d5c..545970f8de 100644 --- a/crates/core/src/ledger/inflation.rs +++ b/crates/trans_token/src/inflation.rs @@ -2,8 +2,8 @@ //! proof-of-stake, providing liquity to shielded asset pools, and public goods //! funding. -use crate::types::dec::Dec; -use crate::types::uint::Uint; +use namada_core::types::dec::Dec; +use namada_core::types::uint::Uint; /// Holds the PD controller values that should be updated in storage #[allow(missing_docs)] diff --git a/crates/trans_token/src/lib.rs b/crates/trans_token/src/lib.rs index 2a5af85457..21c8516a7b 100644 --- a/crates/trans_token/src/lib.rs +++ b/crates/trans_token/src/lib.rs @@ -1,5 +1,6 @@ //! Transparent token types, storage functions, and validation. +pub mod inflation; mod storage; pub mod storage_key; From 0c4756ba64fcf059de0c8ad423eafcda2813c990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 31 Jan 2024 16:24:32 +0000 Subject: [PATCH 07/19] move shielded params from core into shielded_token --- Cargo.lock | 2 + crates/apps/src/lib/config/genesis.rs | 5 ++- .../apps/src/lib/config/genesis/templates.rs | 5 ++- crates/core/src/types/token.rs | 38 ---------------- crates/shielded_token/Cargo.toml | 2 + crates/shielded_token/src/conversion.rs | 5 ++- crates/shielded_token/src/lib.rs | 43 +++++++++++++++++++ crates/shielded_token/src/storage.rs | 5 ++- crates/tests/src/integration/setup.rs | 4 +- crates/token/src/lib.rs | 2 +- wasm/Cargo.lock | 2 + wasm_for_tests/wasm_source/Cargo.lock | 2 + 12 files changed, 66 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7191371a93..205f38c6a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4626,6 +4626,7 @@ dependencies = [ name = "namada_shielded_token" version = "0.31.5" dependencies = [ + "borsh", "masp_primitives", "namada_core", "namada_parameters", @@ -4633,6 +4634,7 @@ dependencies = [ "namada_trans_token", "proptest", "rayon", + "serde 1.0.193", "test-log", "tracing", ] diff --git a/crates/apps/src/lib/config/genesis.rs b/crates/apps/src/lib/config/genesis.rs index 82e5f7cdab..2a4377a877 100644 --- a/crates/apps/src/lib/config/genesis.rs +++ b/crates/apps/src/lib/config/genesis.rs @@ -16,13 +16,14 @@ use namada::governance::pgf::parameters::PgfParameters; use namada::ledger::eth_bridge::EthereumBridgeParams; use namada::ledger::parameters::EpochDuration; use namada::ledger::pos::{Dec, GenesisValidator, OwnedPosParams}; +use namada::token; use namada::types::address::{Address, EstablishedAddress}; use namada::types::chain::ProposalBytes; use namada::types::key::*; +use namada::types::storage; use namada::types::string_encoding::StringEncoded; use namada::types::time::{DateTimeUtc, DurationSecs}; use namada::types::token::Denomination; -use namada::types::{storage, token}; use serde::{Deserialize, Serialize}; #[cfg(all(any(test, feature = "benches"), not(feature = "integration")))] @@ -228,7 +229,7 @@ pub struct TokenAccount { #[derivative(PartialOrd = "ignore", Ord = "ignore")] pub balances: HashMap, /// Token parameters - pub masp_params: Option, + pub masp_params: Option, /// Token inflation from the last epoch (read + write for every epoch) pub last_inflation: token::Amount, /// Token shielded ratio from the last epoch (read + write for every epoch) diff --git a/crates/apps/src/lib/config/genesis/templates.rs b/crates/apps/src/lib/config/genesis/templates.rs index 010d33fb16..7ac2d588ff 100644 --- a/crates/apps/src/lib/config/genesis/templates.rs +++ b/crates/apps/src/lib/config/genesis/templates.rs @@ -8,13 +8,14 @@ use borsh::{BorshDeserialize, BorshSerialize}; use namada::eth_bridge::storage::parameters::{ Contracts, Erc20WhitelistEntry, MinimumConfirmations, }; +use namada::token; use namada::types::address::Address; use namada::types::chain::ProposalBytes; use namada::types::dec::Dec; +use namada::types::ethereum_structs; use namada::types::token::{ Amount, DenominatedAmount, Denomination, NATIVE_MAX_DECIMAL_PLACES, }; -use namada::types::{ethereum_structs, token}; use serde::{Deserialize, Serialize}; use super::transactions::{self, Transactions}; @@ -209,7 +210,7 @@ pub struct Tokens { )] pub struct TokenConfig { pub denom: Denomination, - pub masp_params: Option, + pub masp_params: Option, } #[derive( diff --git a/crates/core/src/types/token.rs b/crates/core/src/types/token.rs index 4ee2983638..3d2429c151 100644 --- a/crates/core/src/types/token.rs +++ b/crates/core/src/types/token.rs @@ -975,44 +975,6 @@ impl From for IbcAmount { } } -/// Token parameters for each kind of asset held on chain -#[derive( - Clone, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - BorshSerialize, - BorshDeserialize, - BorshSchema, - Deserialize, - Serialize, -)] -pub struct MaspParams { - /// Maximum reward rate - pub max_reward_rate: Dec, - /// Shielded Pool nominal derivative gain - pub kd_gain_nom: Dec, - /// Shielded Pool nominal proportional gain for the given token - pub kp_gain_nom: Dec, - /// Target amount for the given token that is locked in the shielded pool - /// TODO: should this be a Uint or DenominatedAmount??? - pub locked_amount_target: u64, -} - -impl Default for MaspParams { - fn default() -> Self { - Self { - max_reward_rate: Dec::from_str("0.1").unwrap(), - kp_gain_nom: Dec::from_str("0.25").unwrap(), - kd_gain_nom: Dec::from_str("0.25").unwrap(), - locked_amount_target: 10_000_u64, - } - } -} - /// A simple bilateral token transfer #[derive( Debug, diff --git a/crates/shielded_token/Cargo.toml b/crates/shielded_token/Cargo.toml index 990f46bc1d..6b73901484 100644 --- a/crates/shielded_token/Cargo.toml +++ b/crates/shielded_token/Cargo.toml @@ -23,8 +23,10 @@ namada_parameters = { path = "../parameters" } namada_storage = { path = "../storage" } namada_trans_token = { path = "../trans_token" } +borsh.workspace = true masp_primitives.workspace = true rayon = { workspace = true, optional = true } +serde.workspace = true tracing.workspace = true [dev-dependencies] diff --git a/crates/shielded_token/src/conversion.rs b/crates/shielded_token/src/conversion.rs index 22f48de417..b2a560d3c5 100644 --- a/crates/shielded_token/src/conversion.rs +++ b/crates/shielded_token/src/conversion.rs @@ -532,12 +532,13 @@ mod tests { use namada_core::types::token::testing::arb_amount; use namada_parameters::{EpochDuration, Parameters}; use namada_storage::testing::TestStorage; - use namada_trans_token::{write_denom, Denomination, MaspParams}; + use namada_trans_token::{write_denom, Denomination}; use proptest::prelude::*; use proptest::test_runner::Config; use test_log::test; use super::*; + use crate::ShieldedParams; proptest! { #![proptest_config(Config { @@ -587,7 +588,7 @@ mod tests { namada_parameters::init_storage(¶ms, &mut s).unwrap(); // Tokens - let token_params = MaspParams { + let token_params = ShieldedParams { max_reward_rate: Dec::from_str("0.1").unwrap(), kp_gain_nom: Dec::from_str("0.1").unwrap(), kd_gain_nom: Dec::from_str("0.1").unwrap(), diff --git a/crates/shielded_token/src/lib.rs b/crates/shielded_token/src/lib.rs index 60da422716..b5f0583738 100644 --- a/crates/shielded_token/src/lib.rs +++ b/crates/shielded_token/src/lib.rs @@ -5,7 +5,50 @@ mod storage; pub mod storage_key; pub mod utils; +use std::str::FromStr; + +use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use namada_core::types::dec::Dec; pub use namada_storage::conversion_state::{ ConversionState, WithConversionState, }; +use serde::{Deserialize, Serialize}; pub use storage::*; + +/// Token parameters for each kind of asset held on chain +#[derive( + Clone, + Debug, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + BorshSerialize, + BorshDeserialize, + BorshSchema, + Deserialize, + Serialize, +)] +pub struct ShieldedParams { + /// Maximum reward rate + pub max_reward_rate: Dec, + /// Shielded Pool nominal derivative gain + pub kd_gain_nom: Dec, + /// Shielded Pool nominal proportional gain for the given token + pub kp_gain_nom: Dec, + /// Target amount for the given token that is locked in the shielded pool + /// TODO: should this be a Uint or DenominatedAmount??? + pub locked_amount_target: u64, +} + +impl Default for ShieldedParams { + fn default() -> Self { + Self { + max_reward_rate: Dec::from_str("0.1").unwrap(), + kp_gain_nom: Dec::from_str("0.25").unwrap(), + kd_gain_nom: Dec::from_str("0.25").unwrap(), + locked_amount_target: 10_000_u64, + } + } +} diff --git a/crates/shielded_token/src/storage.rs b/crates/shielded_token/src/storage.rs index 4fe2127aec..05b42c7ab7 100644 --- a/crates/shielded_token/src/storage.rs +++ b/crates/shielded_token/src/storage.rs @@ -7,10 +7,11 @@ use namada_storage::{StorageRead, StorageWrite}; use storage::ResultExt; use crate::storage_key::*; +use crate::ShieldedParams; /// Initialize parameters for the token in storage during the genesis block. pub fn write_params( - params: &token::MaspParams, + params: &ShieldedParams, storage: &mut S, address: &Address, denom: &token::Denomination, @@ -18,7 +19,7 @@ pub fn write_params( where S: StorageRead + StorageWrite, { - let token::MaspParams { + let ShieldedParams { max_reward_rate: max_rate, kd_gain_nom, kp_gain_nom, diff --git a/crates/tests/src/integration/setup.rs b/crates/tests/src/integration/setup.rs index f8c2b0c066..beb9bf1798 100644 --- a/crates/tests/src/integration/setup.rs +++ b/crates/tests/src/integration/setup.rs @@ -5,8 +5,8 @@ use std::str::FromStr; use std::sync::{Arc, Mutex}; use color_eyre::eyre::{eyre, Result}; +use namada::token; use namada::types::dec::Dec; -use namada::types::token; use namada_apps::cli::args; use namada_apps::client::utils::PRE_GENESIS_DIR; use namada_apps::config; @@ -50,7 +50,7 @@ pub fn initialize_genesis() -> Result<(MockNode, MockServicesController)> { let mut templates = templates::All::read_toml_files(&template_dir) .expect("Missing genesis files"); for (_, config) in templates.tokens.token.iter_mut() { - config.masp_params = Some(token::MaspParams { + config.masp_params = Some(token::ShieldedParams { max_reward_rate: Dec::from_str("0.1").unwrap(), kp_gain_nom: Dec::from_str("0.1").unwrap(), kd_gain_nom: Dec::from_str("0.1").unwrap(), diff --git a/crates/token/src/lib.rs b/crates/token/src/lib.rs index 89fa8e1f1f..ceedef5546 100644 --- a/crates/token/src/lib.rs +++ b/crates/token/src/lib.rs @@ -15,7 +15,7 @@ use namada_storage::{Result, StorageRead, StorageWrite}; /// Initialize parameters for the token in storage during the genesis block. pub fn write_params( - params: &Option, + params: &Option, storage: &mut S, address: &Address, denom: &Denomination, diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index e9f97c7b87..579e6969a3 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3643,11 +3643,13 @@ dependencies = [ name = "namada_shielded_token" version = "0.31.5" dependencies = [ + "borsh", "masp_primitives", "namada_core", "namada_parameters", "namada_storage", "namada_trans_token", + "serde", "tracing", ] diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 245d44e834..2c969b120e 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3643,11 +3643,13 @@ dependencies = [ name = "namada_shielded_token" version = "0.31.5" dependencies = [ + "borsh", "masp_primitives", "namada_core", "namada_parameters", "namada_storage", "namada_trans_token", + "serde", "tracing", ] From 5e3036636533f0e6717788abad8d01b3c0136bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 1 Feb 2024 11:07:13 +0000 Subject: [PATCH 08/19] benches: fix the shell to update conversions on new epochs --- crates/apps/src/lib/bench_utils.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/apps/src/lib/bench_utils.rs b/crates/apps/src/lib/bench_utils.rs index ea9e463340..40e3c6d393 100644 --- a/crates/apps/src/lib/bench_utils.rs +++ b/crates/apps/src/lib/bench_utils.rs @@ -414,6 +414,11 @@ impl BenchShell { current_epoch + params.pipeline_len, ) .unwrap(); + + namada::token::conversion::update_allowed_conversions( + &mut self.wl_storage, + ) + .unwrap(); } pub fn init_ibc_client_state(&mut self, addr_key: Key) -> ClientId { @@ -887,7 +892,7 @@ impl Client for BenchShell { impl Default for BenchShieldedCtx { fn default() -> Self { - let mut shell = BenchShell::default(); + let shell = BenchShell::default(); let base_dir = shell.tempdir.as_ref().canonicalize().unwrap(); // Create a global config and an empty wallet in the chain dir - this is @@ -957,10 +962,6 @@ impl Default for BenchShieldedCtx { } crate::wallet::save(&chain_ctx.wallet).unwrap(); - namada::token::conversion::update_allowed_conversions( - &mut shell.wl_storage, - ) - .unwrap(); Self { shielded: ShieldedContext::default(), From 00cddd4c2585829d7e1b4e9bbded892b3b80d2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 1 Feb 2024 11:32:32 +0000 Subject: [PATCH 09/19] changelog: add #2493 --- .changelog/unreleased/improvements/2493-refactor-token.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changelog/unreleased/improvements/2493-refactor-token.md diff --git a/.changelog/unreleased/improvements/2493-refactor-token.md b/.changelog/unreleased/improvements/2493-refactor-token.md new file mode 100644 index 0000000000..3837e5cdc5 --- /dev/null +++ b/.changelog/unreleased/improvements/2493-refactor-token.md @@ -0,0 +1 @@ +- Refactored token crates. ([\#2493](https://github.com/anoma/namada/pull/2493)) \ No newline at end of file From 5cf8d07bea22e2cbff8f5e60e87f390ec0687269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 1 Feb 2024 13:35:28 +0000 Subject: [PATCH 10/19] core: refactor out ledger::eth_bridge mod --- crates/core/src/ledger/eth_bridge/mod.rs | 9 --------- crates/core/src/ledger/mod.rs | 1 - crates/core/src/types/address.rs | 2 ++ crates/ethereum_bridge/src/lib.rs | 2 +- .../src/protocol/transactions/ethereum_events/events.rs | 3 +-- crates/ethereum_bridge/src/storage/mod.rs | 3 ++- crates/ethereum_bridge/src/storage/vote_tallies.rs | 2 +- crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs | 3 ++- crates/ethereum_bridge/src/storage/whitelist.rs | 2 +- crates/sdk/src/eth_bridge/mod.rs | 3 +-- crates/tests/src/e2e/eth_bridge_tests.rs | 3 +-- crates/tx_prelude/src/lib.rs | 1 - wasm/wasm_source/src/tx_bridge_pool.rs | 2 +- 13 files changed, 13 insertions(+), 23 deletions(-) delete mode 100644 crates/core/src/ledger/eth_bridge/mod.rs diff --git a/crates/core/src/ledger/eth_bridge/mod.rs b/crates/core/src/ledger/eth_bridge/mod.rs deleted file mode 100644 index fda8964ff6..0000000000 --- a/crates/core/src/ledger/eth_bridge/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! Ethereum bridge account - -use crate::types::address::{Address, InternalAddress}; - -/// The [`InternalAddress`] of the Ethereum bridge account -pub const INTERNAL_ADDRESS: InternalAddress = InternalAddress::EthBridge; - -/// The [`Address`] of the Ethereum bridge account -pub const ADDRESS: Address = Address::Internal(INTERNAL_ADDRESS); diff --git a/crates/core/src/ledger/mod.rs b/crates/core/src/ledger/mod.rs index 5122eb8b91..0b5f8b8c0e 100644 --- a/crates/core/src/ledger/mod.rs +++ b/crates/core/src/ledger/mod.rs @@ -1,4 +1,3 @@ //! The ledger modules -pub mod eth_bridge; pub mod replay_protection; diff --git a/crates/core/src/types/address.rs b/crates/core/src/types/address.rs index 7626d3c0b6..a0d911e2c3 100644 --- a/crates/core/src/types/address.rs +++ b/crates/core/src/types/address.rs @@ -64,6 +64,8 @@ pub const GOV: Address = Address::Internal(InternalAddress::Governance); pub const MASP: Address = Address::Internal(InternalAddress::Masp); /// Internal Multitoken address pub const MULTITOKEN: Address = Address::Internal(InternalAddress::Multitoken); +/// Internal Eth bridge address +pub const ETH_BRIDGE: Address = Address::Internal(InternalAddress::EthBridge); /// Error from decoding address from string pub type DecodeError = string_encoding::DecodeError; diff --git a/crates/ethereum_bridge/src/lib.rs b/crates/ethereum_bridge/src/lib.rs index 31d9fc1e62..955ba19887 100644 --- a/crates/ethereum_bridge/src/lib.rs +++ b/crates/ethereum_bridge/src/lib.rs @@ -6,5 +6,5 @@ pub mod storage; #[cfg(any(test, feature = "testing"))] pub mod test_utils; -pub use namada_core::ledger::eth_bridge::ADDRESS; +pub use namada_core::types::address::ETH_BRIDGE as ADDRESS; pub use namada_trans_token as token; diff --git a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs index 1cd2144eec..73a228dcea 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs @@ -6,7 +6,6 @@ use std::str::FromStr; use borsh::BorshDeserialize; use eyre::{Result, WrapErr}; use namada_core::hints; -use namada_core::ledger::eth_bridge::ADDRESS as BRIDGE_ADDRESS; use namada_core::types::address::Address; use namada_core::types::eth_abi::Encode; use namada_core::types::eth_bridge_pool::{ @@ -31,7 +30,7 @@ use crate::storage::bridge_pool::{ use crate::storage::eth_bridge_queries::{EthAssetMint, EthBridgeQueries}; use crate::storage::parameters::read_native_erc20_address; use crate::storage::{self as bridge_storage}; -use crate::token; +use crate::{token, ADDRESS as BRIDGE_ADDRESS}; /// Updates storage based on the given confirmed `event`. For example, for a /// confirmed [`EthereumEvent::TransfersToNamada`], mint the corresponding diff --git a/crates/ethereum_bridge/src/storage/mod.rs b/crates/ethereum_bridge/src/storage/mod.rs index 96c2b8dd84..db40a541b0 100644 --- a/crates/ethereum_bridge/src/storage/mod.rs +++ b/crates/ethereum_bridge/src/storage/mod.rs @@ -9,7 +9,6 @@ pub mod vp; pub mod whitelist; pub mod wrapped_erc20s; -use namada_core::ledger::eth_bridge::ADDRESS; use namada_core::types::address::Address; use namada_core::types::storage::{DbKeySeg, Key, KeySeg}; pub use namada_parameters::native_erc20_key; @@ -17,6 +16,8 @@ use namada_parameters::storage::*; use namada_parameters::ADDRESS as PARAM_ADDRESS; use namada_trans_token::storage_key::balance_key; +use crate::ADDRESS; + /// Key prefix for the storage subspace pub fn prefix() -> Key { Key::from(ADDRESS.to_db_key()) diff --git a/crates/ethereum_bridge/src/storage/vote_tallies.rs b/crates/ethereum_bridge/src/storage/vote_tallies.rs index 354edb9958..b597f15e1f 100644 --- a/crates/ethereum_bridge/src/storage/vote_tallies.rs +++ b/crates/ethereum_bridge/src/storage/vote_tallies.rs @@ -4,7 +4,6 @@ use std::io::{Read, Write}; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::ledger::eth_bridge::ADDRESS; use namada_core::types::address::Address; use namada_core::types::ethereum_events::{EthereumEvent, Uint}; use namada_core::types::hash::Hash; @@ -14,6 +13,7 @@ use namada_macros::StorageKeys; use namada_vote_ext::validator_set_update::VotingPowersMap; use crate::storage::proof::{BridgePoolRootProof, EthereumProof}; +use crate::ADDRESS; /// Storage sub-key space reserved to keeping track of the /// voting power assigned to Ethereum events. diff --git a/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs b/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs index 644555548b..f2ede582a1 100644 --- a/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs +++ b/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs @@ -1,10 +1,11 @@ -use namada_core::ledger::eth_bridge::ADDRESS; use namada_core::types::hash::StorageHasher; use namada_state::{DBIter, WlStorage, DB}; use namada_storage::StorageWrite; use namada_trans_token::storage_key::balance_key; use namada_trans_token::Amount; +use crate::ADDRESS; + /// Initialize the storage owned by the Ethereum Bridge VP. /// /// This means that the amount of escrowed Nam is diff --git a/crates/ethereum_bridge/src/storage/whitelist.rs b/crates/ethereum_bridge/src/storage/whitelist.rs index 6abc873dfb..7792f06484 100644 --- a/crates/ethereum_bridge/src/storage/whitelist.rs +++ b/crates/ethereum_bridge/src/storage/whitelist.rs @@ -5,7 +5,6 @@ use std::str::FromStr; -use namada_core::ledger::eth_bridge::ADDRESS as BRIDGE_ADDRESS; use namada_core::types::eth_bridge_pool::erc20_token_address; use namada_core::types::ethereum_events::EthAddress; use namada_core::types::storage; @@ -13,6 +12,7 @@ use namada_core::types::storage::DbKeySeg; use namada_trans_token::storage_key::{denom_key, minted_balance_key}; use super::prefix as ethbridge_key_prefix; +use crate::ADDRESS as BRIDGE_ADDRESS; mod segments { //! Storage key segments under the token whitelist. diff --git a/crates/sdk/src/eth_bridge/mod.rs b/crates/sdk/src/eth_bridge/mod.rs index 9107798938..ecebd05c32 100644 --- a/crates/sdk/src/eth_bridge/mod.rs +++ b/crates/sdk/src/eth_bridge/mod.rs @@ -8,12 +8,11 @@ use std::ops::ControlFlow; pub use ethers; use ethers::providers::Middleware; use itertools::Either; -pub use namada_core::ledger::eth_bridge::{ADDRESS, INTERNAL_ADDRESS}; pub use namada_core::types::ethereum_structs as structs; pub use namada_ethereum_bridge::storage::eth_bridge_queries::*; pub use namada_ethereum_bridge::storage::parameters::*; pub use namada_ethereum_bridge::storage::wrapped_erc20s; -pub use namada_ethereum_bridge::*; +pub use namada_ethereum_bridge::{ADDRESS, *}; use num256::Uint256; use crate::control_flow::time::{ diff --git a/crates/tests/src/e2e/eth_bridge_tests.rs b/crates/tests/src/e2e/eth_bridge_tests.rs index b1ea2636f5..ece8eb2ee0 100644 --- a/crates/tests/src/e2e/eth_bridge_tests.rs +++ b/crates/tests/src/e2e/eth_bridge_tests.rs @@ -20,7 +20,6 @@ use namada::types::ethereum_events::EthAddress; use namada::types::storage::{self, Epoch}; use namada::types::{address, token}; use namada_apps::config::ethereum_bridge; -use namada_core::ledger::eth_bridge::ADDRESS as BRIDGE_ADDRESS; use namada_core::types::address::Address; use namada_core::types::ethereum_events::{ EthereumEvent, TransferToEthereum, TransferToNamada, @@ -49,7 +48,7 @@ use crate::e2e::setup::{Bin, Who}; use crate::strings::{ LEDGER_STARTED, TX_ACCEPTED, TX_APPLIED_SUCCESS, VALIDATOR_NODE, }; -use crate::{run, run_as}; +use crate::{run, run_as, ADDRESS as BRIDGE_ADDRESS}; /// # Examples /// diff --git a/crates/tx_prelude/src/lib.rs b/crates/tx_prelude/src/lib.rs index 4d04314a53..fcb059fdb7 100644 --- a/crates/tx_prelude/src/lib.rs +++ b/crates/tx_prelude/src/lib.rs @@ -20,7 +20,6 @@ use masp_primitives::transaction::Transaction; pub use namada_core::borsh::{ BorshDeserialize, BorshSerialize, BorshSerializeExt, }; -pub use namada_core::ledger::eth_bridge; use namada_core::types::account::AccountPublicKeysMap; pub use namada_core::types::address::Address; use namada_core::types::chain::CHAIN_ID_LENGTH; diff --git a/wasm/wasm_source/src/tx_bridge_pool.rs b/wasm/wasm_source/src/tx_bridge_pool.rs index 47f401f7d9..8d4277a22e 100644 --- a/wasm/wasm_source/src/tx_bridge_pool.rs +++ b/wasm/wasm_source/src/tx_bridge_pool.rs @@ -42,7 +42,7 @@ fn apply_tx(ctx: &mut Ctx, signed: Tx) -> TxResult { token::undenominated_transfer( ctx, sender, - ð_bridge::ADDRESS, + &address::ETH_BRIDGE, &nam_addr, amount, )?; From 2900e3d318ee9701d363bc23d566399eff2046f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 1 Feb 2024 13:39:52 +0000 Subject: [PATCH 11/19] core: factor out the ledger::replay_protection mod into a new crate --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + Makefile | 1 + crates/core/src/ledger/mod.rs | 3 --- crates/core/src/lib.rs | 1 - crates/replay_protection/Cargo.toml | 17 +++++++++++++++++ .../src/lib.rs} | 0 wasm/Cargo.lock | 10 ++++++++++ wasm_for_tests/wasm_source/Cargo.lock | 10 ++++++++++ 9 files changed, 49 insertions(+), 4 deletions(-) delete mode 100644 crates/core/src/ledger/mod.rs create mode 100644 crates/replay_protection/Cargo.toml rename crates/{core/src/ledger/replay_protection.rs => replay_protection/src/lib.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 205f38c6a4..41676f3c52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4154,6 +4154,7 @@ dependencies = [ "namada_ibc", "namada_parameters", "namada_proof_of_stake", + "namada_replay_protection", "namada_sdk", "namada_state", "namada_test_utils", @@ -4558,6 +4559,13 @@ dependencies = [ "yansi", ] +[[package]] +name = "namada_replay_protection" +version = "0.31.1" +dependencies = [ + "namada_core", +] + [[package]] name = "namada_sdk" version = "0.31.5" @@ -4652,6 +4660,7 @@ dependencies = [ "namada_gas", "namada_merkle_tree", "namada_parameters", + "namada_replay_protection", "namada_storage", "namada_trans_token", "namada_tx", @@ -4674,6 +4683,7 @@ dependencies = [ "namada_core", "namada_gas", "namada_merkle_tree", + "namada_replay_protection", "namada_tx", "thiserror", "tracing", diff --git a/Cargo.toml b/Cargo.toml index d05dfb4b39..a5d271c9e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "crates/merkle_tree", "crates/parameters", "crates/proof_of_stake", + "crates/replay_protection", "crates/sdk", "crates/namada", "crates/shielded_token", diff --git a/Makefile b/Makefile index d8b389b5a8..6372c0a0b9 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ crates += namada_macros crates += namada_merkle_tree crates += namada_parameters crates += namada_proof_of_stake +crates += namada_replay_protection crates += namada_sdk crates += namada_shielded_token crates += namada_state diff --git a/crates/core/src/ledger/mod.rs b/crates/core/src/ledger/mod.rs deleted file mode 100644 index 0b5f8b8c0e..0000000000 --- a/crates/core/src/ledger/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! The ledger modules - -pub mod replay_protection; diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index d3dd426fb5..8c635fca3c 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -9,7 +9,6 @@ pub mod bytes; pub mod event; pub mod hints; -pub mod ledger; pub mod types; pub use {ibc, masp_primitives, tendermint, tendermint_proto}; diff --git a/crates/replay_protection/Cargo.toml b/crates/replay_protection/Cargo.toml new file mode 100644 index 0000000000..010020a052 --- /dev/null +++ b/crates/replay_protection/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "namada_replay_protection" +description = "Namada replay protection" +resolver = "2" +authors.workspace = true +edition.workspace = true +documentation.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +version.workspace = true + + +[dependencies] +namada_core = { path = "../core" } diff --git a/crates/core/src/ledger/replay_protection.rs b/crates/replay_protection/src/lib.rs similarity index 100% rename from crates/core/src/ledger/replay_protection.rs rename to crates/replay_protection/src/lib.rs diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 579e6969a3..803639bbd5 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3343,6 +3343,7 @@ dependencies = [ "namada_ibc", "namada_parameters", "namada_proof_of_stake", + "namada_replay_protection", "namada_sdk", "namada_state", "namada_token", @@ -3579,6 +3580,13 @@ dependencies = [ "tracing", ] +[[package]] +name = "namada_replay_protection" +version = "0.31.1" +dependencies = [ + "namada_core", +] + [[package]] name = "namada_sdk" version = "0.31.5" @@ -3664,6 +3672,7 @@ dependencies = [ "namada_gas", "namada_merkle_tree", "namada_parameters", + "namada_replay_protection", "namada_storage", "namada_trans_token", "namada_tx", @@ -3684,6 +3693,7 @@ dependencies = [ "namada_core", "namada_gas", "namada_merkle_tree", + "namada_replay_protection", "namada_tx", "thiserror", "tracing", diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 2c969b120e..83e0dcff85 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3343,6 +3343,7 @@ dependencies = [ "namada_ibc", "namada_parameters", "namada_proof_of_stake", + "namada_replay_protection", "namada_sdk", "namada_state", "namada_token", @@ -3579,6 +3580,13 @@ dependencies = [ "tracing", ] +[[package]] +name = "namada_replay_protection" +version = "0.31.1" +dependencies = [ + "namada_core", +] + [[package]] name = "namada_sdk" version = "0.31.5" @@ -3664,6 +3672,7 @@ dependencies = [ "namada_gas", "namada_merkle_tree", "namada_parameters", + "namada_replay_protection", "namada_storage", "namada_trans_token", "namada_tx", @@ -3684,6 +3693,7 @@ dependencies = [ "namada_core", "namada_gas", "namada_merkle_tree", + "namada_replay_protection", "namada_tx", "thiserror", "tracing", From 45cb6b972d7c9537335633f30ae09f5077322b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 1 Feb 2024 13:44:55 +0000 Subject: [PATCH 12/19] update replay_protection usage --- crates/apps/src/lib/node/ledger/shell/finalize_block.rs | 2 +- crates/apps/src/lib/node/ledger/shell/mod.rs | 3 +-- crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs | 3 +-- crates/apps/src/lib/node/ledger/shell/process_proposal.rs | 3 +-- crates/apps/src/lib/node/ledger/storage/rocksdb.rs | 3 +-- crates/namada/Cargo.toml | 1 + crates/namada/src/ledger/mod.rs | 1 - crates/namada/src/lib.rs | 5 +++-- crates/replay_protection/src/lib.rs | 6 +++--- crates/state/Cargo.toml | 1 + crates/state/src/write_log.rs | 2 +- crates/storage/Cargo.toml | 1 + crates/storage/src/mockdb.rs | 2 +- 13 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs index 725f6913e4..885c531557 100644 --- a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -742,7 +742,6 @@ mod test_finalize_block { use std::str::FromStr; use data_encoding::HEXUPPER; - use namada::core::ledger::replay_protection; use namada::eth_bridge::storage::bridge_pool::{ self, get_key_from_hash, get_nonce_key, get_signed_root_key, }; @@ -769,6 +768,7 @@ mod test_finalize_block { BondId, SlashType, ValidatorState, WeightedValidator, }; use namada::proof_of_stake::{unjail_validator, ADDRESS as pos_address}; + use namada::replay_protection; use namada::state::StorageWrite; use namada::token::{Amount, DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES}; use namada::tx::data::{Fee, WrapperTx}; diff --git a/crates/apps/src/lib/node/ledger/shell/mod.rs b/crates/apps/src/lib/node/ledger/shell/mod.rs index eadf54dd23..cf86242914 100644 --- a/crates/apps/src/lib/node/ledger/shell/mod.rs +++ b/crates/apps/src/lib/node/ledger/shell/mod.rs @@ -2090,7 +2090,6 @@ mod test_utils { #[cfg(test)] mod shell_tests { - use namada::core::ledger::replay_protection; use namada::token::read_denom; use namada::tx::data::protocol::{ProtocolTx, ProtocolTxType}; use namada::tx::data::{Fee, WrapperTx}; @@ -2103,7 +2102,7 @@ mod shell_tests { use namada::vote_ext::{ bridge_pool_roots, ethereum_events, ethereum_tx_data_variants, }; - use namada::{parameters, token}; + use namada::{parameters, replay_protection, token}; use super::*; use crate::node::ledger::shell::test_utils; diff --git a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs index cd3b55cf30..7255789052 100644 --- a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -433,7 +433,6 @@ mod test_prepare_proposal { use borsh_ext::BorshSerializeExt; use namada::ledger::gas::Gas; use namada::ledger::pos::PosQueries; - use namada::ledger::replay_protection; use namada::proof_of_stake::storage::{ consensus_validator_set_handle, read_consensus_validator_set_addresses_with_stake, @@ -441,7 +440,6 @@ mod test_prepare_proposal { use namada::proof_of_stake::types::WeightedValidator; use namada::proof_of_stake::Epoch; use namada::state::collections::lazy_map::{NestedSubKey, SubKey}; - use namada::token; use namada::token::{read_denom, Amount, DenominatedAmount}; use namada::tx::data::{Fee, TxType, WrapperTx}; use namada::tx::{Code, Data, Header, Section, Signature, Signed}; @@ -450,6 +448,7 @@ mod test_prepare_proposal { use namada::types::key::RefTo; use namada::types::storage::{BlockHeight, InnerEthEventsQueue}; use namada::vote_ext::{ethereum_events, ethereum_tx_data_variants}; + use namada::{replay_protection, token}; use super::*; use crate::config::ValidatorLocalConfig; diff --git a/crates/apps/src/lib/node/ledger/shell/process_proposal.rs b/crates/apps/src/lib/node/ledger/shell/process_proposal.rs index db3cdb926c..7146726382 100644 --- a/crates/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/crates/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -667,9 +667,7 @@ where /// are covered by the e2e tests. #[cfg(test)] mod test_process_proposal { - use namada::ledger::replay_protection; use namada::state::StorageWrite; - use namada::token; use namada::token::{read_denom, Amount, DenominatedAmount}; use namada::tx::data::{Fee, WrapperTx}; use namada::tx::{ @@ -682,6 +680,7 @@ mod test_process_proposal { use namada::vote_ext::{ bridge_pool_roots, ethereum_events, EthereumTxData, }; + use namada::{replay_protection, token}; use super::*; use crate::node::ledger::shell::test_utils::{ diff --git a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs index 54bf05152a..97bbb37b3c 100644 --- a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs +++ b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs @@ -50,7 +50,6 @@ use data_encoding::HEXLOWER; use itertools::Either; use namada::eth_bridge::storage::proof::BridgePoolRootProof; use namada::ledger::eth_bridge::storage::bridge_pool; -use namada::ledger::replay_protection; use namada::ledger::storage::tx_queue::TxQueue; use namada::state::merkle_tree::{base_tree_key_prefix, subtree_key_prefix}; use namada::state::types::PrefixIterator; @@ -59,13 +58,13 @@ use namada::state::{ DbResult as Result, MerkleTreeStoresRead, StoreType, DB, }; use namada::token::ConversionState; -use namada::types; use namada::types::storage::{ BlockHeight, BlockResults, Epoch, EthEventsQueue, Header, Key, KeySeg, KEY_SEGMENT_SEPARATOR, }; use namada::types::time::DateTimeUtc; use namada::types::{ethereum_events, ethereum_structs}; +use namada::{replay_protection, types}; use rayon::prelude::*; use rocksdb::{ BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, DBCompactionStyle, diff --git a/crates/namada/Cargo.toml b/crates/namada/Cargo.toml index 3026aff756..b2d9681245 100644 --- a/crates/namada/Cargo.toml +++ b/crates/namada/Cargo.toml @@ -83,6 +83,7 @@ namada_governance = { path = "../governance" } namada_ibc = { path = "../ibc" } namada_parameters = { path = "../parameters" } namada_proof_of_stake = { path = "../proof_of_stake" } +namada_replay_protection = { path = "../replay_protection" } namada_sdk = { path = "../sdk", default-features = false } namada_state = { path = "../state" } namada_token = { path = "../token" } diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index 5f54de80f2..8ca87958f0 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -14,7 +14,6 @@ pub mod vp_host_fns; #[cfg(feature = "wasm-runtime")] pub use dry_run_tx::dry_run_tx; -pub use namada_core::ledger::replay_protection; pub use { namada_gas as gas, namada_parameters as parameters, namada_tx_env as tx_env, namada_vp_env as vp_env, diff --git a/crates/namada/src/lib.rs b/crates/namada/src/lib.rs index a01dba6ebb..63a0ecb7f6 100644 --- a/crates/namada/src/lib.rs +++ b/crates/namada/src/lib.rs @@ -14,8 +14,9 @@ pub use { namada_ethereum_bridge as ethereum_bridge, namada_gas as gas, namada_governance as governance, namada_ibc as ibc, namada_parameters as parameters, namada_proof_of_stake as proof_of_stake, - namada_sdk as sdk, namada_state as state, namada_token as token, - namada_tx as tx, namada_vote_ext as vote_ext, + namada_replay_protection as replay_protection, namada_sdk as sdk, + namada_state as state, namada_token as token, namada_tx as tx, + namada_vote_ext as vote_ext, }; pub mod ledger; diff --git a/crates/replay_protection/src/lib.rs b/crates/replay_protection/src/lib.rs index 5400d1d2d9..7f68314fcd 100644 --- a/crates/replay_protection/src/lib.rs +++ b/crates/replay_protection/src/lib.rs @@ -1,7 +1,7 @@ -//! Replay protection storage +//! Replay protection storage keys -use crate::types::hash::Hash; -use crate::types::storage::Key; +use namada_core::types::hash::Hash; +use namada_core::types::storage::Key; const ERROR_MSG: &str = "Cannot obtain a valid db key"; diff --git a/crates/state/Cargo.toml b/crates/state/Cargo.toml index 48460ae64f..df16bc3d7e 100644 --- a/crates/state/Cargo.toml +++ b/crates/state/Cargo.toml @@ -23,6 +23,7 @@ namada_core = { path = "../core", default-features = false } namada_gas = { path = "../gas" } namada_merkle_tree = { path = "../merkle_tree" } namada_parameters = { path = "../parameters" } +namada_replay_protection = { path = "../replay_protection" } namada_storage = { path = "../storage" } namada_trans_token = { path = "../trans_token" } namada_tx = { path = "../tx" } diff --git a/crates/state/src/write_log.rs b/crates/state/src/write_log.rs index 17de478659..840bf0dd8b 100644 --- a/crates/state/src/write_log.rs +++ b/crates/state/src/write_log.rs @@ -4,7 +4,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use itertools::Itertools; -use namada_core::ledger::replay_protection; use namada_core::types::address::{ Address, EstablishedAddressGen, InternalAddress, }; @@ -12,6 +11,7 @@ use namada_core::types::hash::{Hash, StorageHasher}; use namada_core::types::ibc::IbcEvent; use namada_core::types::storage; use namada_gas::{MEMORY_ACCESS_GAS_PER_BYTE, STORAGE_WRITE_GAS_PER_BYTE}; +use namada_replay_protection as replay_protection; use namada_trans_token::storage_key::{ is_any_minted_balance_key, is_any_minter_key, is_any_token_balance_key, is_any_token_parameter_key, diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index 17ee879e6b..12f75ba063 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -22,6 +22,7 @@ testing = [ namada_core = { path = "../core" } namada_gas = { path = "../gas" } namada_merkle_tree = { path = "../merkle_tree" } +namada_replay_protection = { path = "../replay_protection" } namada_tx = { path = "../tx" } borsh.workspace = true diff --git a/crates/storage/src/mockdb.rs b/crates/storage/src/mockdb.rs index b18162e447..2827bed5d9 100644 --- a/crates/storage/src/mockdb.rs +++ b/crates/storage/src/mockdb.rs @@ -8,7 +8,6 @@ use std::str::FromStr; use itertools::Either; use namada_core::borsh::{BorshDeserialize, BorshSerializeExt}; -use namada_core::ledger::replay_protection; use namada_core::types; use namada_core::types::hash::Hash; use namada_core::types::storage::{ @@ -20,6 +19,7 @@ use namada_core::types::{ethereum_events, ethereum_structs}; use namada_merkle_tree::{ base_tree_key_prefix, subtree_key_prefix, MerkleTreeStoresRead, StoreType, }; +use namada_replay_protection as replay_protection; use crate::conversion_state::ConversionState; use crate::db::{ From c9d2ba9a6258ac5d836f7de81ad02648bb5538dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 1 Feb 2024 14:52:09 +0000 Subject: [PATCH 13/19] core: flatten types mod --- crates/core/src/{types => }/account.rs | 0 crates/core/src/{types => }/address.rs | 0 crates/core/src/{types => }/address/raw.rs | 0 crates/core/src/{types => }/chain.rs | 0 crates/core/src/{types => }/dec.rs | 0 crates/core/src/{types => }/eth_abi.rs | 0 .../core/src/{types => }/eth_bridge_pool.rs | 0 .../core/src/{types => }/ethereum_events.rs | 0 .../core/src/{types => }/ethereum_structs.rs | 0 crates/core/src/{types => }/hash.rs | 0 crates/core/src/{types => }/ibc.rs | 0 crates/core/src/{types => }/internal.rs | 0 crates/core/src/{types => }/keccak.rs | 0 crates/core/src/{types => }/key/common.rs | 0 crates/core/src/{types => }/key/ed25519.rs | 0 crates/core/src/{types => }/key/mod.rs | 0 crates/core/src/{types => }/key/secp256k1.rs | 0 crates/core/src/lib.rs | 53 ++++++++++++++++++- crates/core/src/{types => }/masp.rs | 0 crates/core/src/{types => }/mod.rs | 0 crates/core/src/{types => }/parameters.rs | 0 crates/core/src/{types => }/sign.rs | 0 crates/core/src/{types => }/storage.rs | 0 .../core/src/{types => }/string_encoding.rs | 0 crates/core/src/{types => }/time.rs | 0 crates/core/src/{types => }/token.rs | 0 crates/core/src/{types => }/uint.rs | 0 .../src/{types => }/validity_predicate.rs | 0 crates/core/src/{types => }/voting_power.rs | 0 29 files changed, 52 insertions(+), 1 deletion(-) rename crates/core/src/{types => }/account.rs (100%) rename crates/core/src/{types => }/address.rs (100%) rename crates/core/src/{types => }/address/raw.rs (100%) rename crates/core/src/{types => }/chain.rs (100%) rename crates/core/src/{types => }/dec.rs (100%) rename crates/core/src/{types => }/eth_abi.rs (100%) rename crates/core/src/{types => }/eth_bridge_pool.rs (100%) rename crates/core/src/{types => }/ethereum_events.rs (100%) rename crates/core/src/{types => }/ethereum_structs.rs (100%) rename crates/core/src/{types => }/hash.rs (100%) rename crates/core/src/{types => }/ibc.rs (100%) rename crates/core/src/{types => }/internal.rs (100%) rename crates/core/src/{types => }/keccak.rs (100%) rename crates/core/src/{types => }/key/common.rs (100%) rename crates/core/src/{types => }/key/ed25519.rs (100%) rename crates/core/src/{types => }/key/mod.rs (100%) rename crates/core/src/{types => }/key/secp256k1.rs (100%) rename crates/core/src/{types => }/masp.rs (100%) rename crates/core/src/{types => }/mod.rs (100%) rename crates/core/src/{types => }/parameters.rs (100%) rename crates/core/src/{types => }/sign.rs (100%) rename crates/core/src/{types => }/storage.rs (100%) rename crates/core/src/{types => }/string_encoding.rs (100%) rename crates/core/src/{types => }/time.rs (100%) rename crates/core/src/{types => }/token.rs (100%) rename crates/core/src/{types => }/uint.rs (100%) rename crates/core/src/{types => }/validity_predicate.rs (100%) rename crates/core/src/{types => }/voting_power.rs (100%) diff --git a/crates/core/src/types/account.rs b/crates/core/src/account.rs similarity index 100% rename from crates/core/src/types/account.rs rename to crates/core/src/account.rs diff --git a/crates/core/src/types/address.rs b/crates/core/src/address.rs similarity index 100% rename from crates/core/src/types/address.rs rename to crates/core/src/address.rs diff --git a/crates/core/src/types/address/raw.rs b/crates/core/src/address/raw.rs similarity index 100% rename from crates/core/src/types/address/raw.rs rename to crates/core/src/address/raw.rs diff --git a/crates/core/src/types/chain.rs b/crates/core/src/chain.rs similarity index 100% rename from crates/core/src/types/chain.rs rename to crates/core/src/chain.rs diff --git a/crates/core/src/types/dec.rs b/crates/core/src/dec.rs similarity index 100% rename from crates/core/src/types/dec.rs rename to crates/core/src/dec.rs diff --git a/crates/core/src/types/eth_abi.rs b/crates/core/src/eth_abi.rs similarity index 100% rename from crates/core/src/types/eth_abi.rs rename to crates/core/src/eth_abi.rs diff --git a/crates/core/src/types/eth_bridge_pool.rs b/crates/core/src/eth_bridge_pool.rs similarity index 100% rename from crates/core/src/types/eth_bridge_pool.rs rename to crates/core/src/eth_bridge_pool.rs diff --git a/crates/core/src/types/ethereum_events.rs b/crates/core/src/ethereum_events.rs similarity index 100% rename from crates/core/src/types/ethereum_events.rs rename to crates/core/src/ethereum_events.rs diff --git a/crates/core/src/types/ethereum_structs.rs b/crates/core/src/ethereum_structs.rs similarity index 100% rename from crates/core/src/types/ethereum_structs.rs rename to crates/core/src/ethereum_structs.rs diff --git a/crates/core/src/types/hash.rs b/crates/core/src/hash.rs similarity index 100% rename from crates/core/src/types/hash.rs rename to crates/core/src/hash.rs diff --git a/crates/core/src/types/ibc.rs b/crates/core/src/ibc.rs similarity index 100% rename from crates/core/src/types/ibc.rs rename to crates/core/src/ibc.rs diff --git a/crates/core/src/types/internal.rs b/crates/core/src/internal.rs similarity index 100% rename from crates/core/src/types/internal.rs rename to crates/core/src/internal.rs diff --git a/crates/core/src/types/keccak.rs b/crates/core/src/keccak.rs similarity index 100% rename from crates/core/src/types/keccak.rs rename to crates/core/src/keccak.rs diff --git a/crates/core/src/types/key/common.rs b/crates/core/src/key/common.rs similarity index 100% rename from crates/core/src/types/key/common.rs rename to crates/core/src/key/common.rs diff --git a/crates/core/src/types/key/ed25519.rs b/crates/core/src/key/ed25519.rs similarity index 100% rename from crates/core/src/types/key/ed25519.rs rename to crates/core/src/key/ed25519.rs diff --git a/crates/core/src/types/key/mod.rs b/crates/core/src/key/mod.rs similarity index 100% rename from crates/core/src/types/key/mod.rs rename to crates/core/src/key/mod.rs diff --git a/crates/core/src/types/key/secp256k1.rs b/crates/core/src/key/secp256k1.rs similarity index 100% rename from crates/core/src/types/key/secp256k1.rs rename to crates/core/src/key/secp256k1.rs diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 8c635fca3c..c7580895ea 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -9,7 +9,6 @@ pub mod bytes; pub mod event; pub mod hints; -pub mod types; pub use {ibc, masp_primitives, tendermint, tendermint_proto}; /// Borsh binary encoding (re-exported) from official crate with custom ext. @@ -17,3 +16,55 @@ pub mod borsh { pub use borsh::*; pub use borsh_ext::*; } + +pub mod account; +pub mod address; +pub mod chain; +pub mod dec; +pub mod eth_abi; +pub mod eth_bridge_pool; +pub mod ethereum_events; +pub mod ethereum_structs; +pub mod hash; +pub mod ibc; +pub mod internal; +pub mod keccak; +pub mod key; +pub mod masp; +pub mod parameters; +pub mod sign; +pub mod storage; +pub mod string_encoding; +pub mod time; +pub mod token; +pub mod uint; +pub mod validity_predicate; +pub mod voting_power; + +use borsh_ext::BorshSerializeExt; +use thiserror::Error; + +use crate::borsh::{BorshDeserialize, BorshSerialize}; + +#[allow(missing_docs)] +#[derive(Error, Debug)] +pub enum DecodeError { + #[error("Deserialization error: {0}")] + DeserializationError(std::io::Error), +} + +/// Encode a value with borsh +pub fn encode(value: &T) -> Vec +where + T: BorshSerialize, +{ + value.serialize_to_vec() +} + +/// Decode a value with borsh +pub fn decode(bytes: impl AsRef<[u8]>) -> Result +where + T: BorshDeserialize, +{ + T::try_from_slice(bytes.as_ref()).map_err(DecodeError::DeserializationError) +} diff --git a/crates/core/src/types/masp.rs b/crates/core/src/masp.rs similarity index 100% rename from crates/core/src/types/masp.rs rename to crates/core/src/masp.rs diff --git a/crates/core/src/types/mod.rs b/crates/core/src/mod.rs similarity index 100% rename from crates/core/src/types/mod.rs rename to crates/core/src/mod.rs diff --git a/crates/core/src/types/parameters.rs b/crates/core/src/parameters.rs similarity index 100% rename from crates/core/src/types/parameters.rs rename to crates/core/src/parameters.rs diff --git a/crates/core/src/types/sign.rs b/crates/core/src/sign.rs similarity index 100% rename from crates/core/src/types/sign.rs rename to crates/core/src/sign.rs diff --git a/crates/core/src/types/storage.rs b/crates/core/src/storage.rs similarity index 100% rename from crates/core/src/types/storage.rs rename to crates/core/src/storage.rs diff --git a/crates/core/src/types/string_encoding.rs b/crates/core/src/string_encoding.rs similarity index 100% rename from crates/core/src/types/string_encoding.rs rename to crates/core/src/string_encoding.rs diff --git a/crates/core/src/types/time.rs b/crates/core/src/time.rs similarity index 100% rename from crates/core/src/types/time.rs rename to crates/core/src/time.rs diff --git a/crates/core/src/types/token.rs b/crates/core/src/token.rs similarity index 100% rename from crates/core/src/types/token.rs rename to crates/core/src/token.rs diff --git a/crates/core/src/types/uint.rs b/crates/core/src/uint.rs similarity index 100% rename from crates/core/src/types/uint.rs rename to crates/core/src/uint.rs diff --git a/crates/core/src/types/validity_predicate.rs b/crates/core/src/validity_predicate.rs similarity index 100% rename from crates/core/src/types/validity_predicate.rs rename to crates/core/src/validity_predicate.rs diff --git a/crates/core/src/types/voting_power.rs b/crates/core/src/voting_power.rs similarity index 100% rename from crates/core/src/types/voting_power.rs rename to crates/core/src/voting_power.rs From d7aedead6663ab2ca615111f7b0d7652951802e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 1 Feb 2024 15:57:57 +0000 Subject: [PATCH 14/19] update all core types usages --- Cargo.lock | 4 +- crates/account/src/lib.rs | 6 +- crates/account/src/storage.rs | 6 +- crates/account/src/storage_key.rs | 6 +- crates/account/src/types.rs | 12 +- crates/apps/src/bin/namada-node/cli.rs | 2 +- crates/apps/src/lib/bench_utils.rs | 24 ++-- crates/apps/src/lib/cli.rs | 24 ++-- crates/apps/src/lib/cli/api.rs | 2 +- crates/apps/src/lib/cli/client.rs | 2 +- crates/apps/src/lib/cli/context.rs | 14 +- crates/apps/src/lib/cli/relayer.rs | 2 +- crates/apps/src/lib/cli/wallet.rs | 8 +- crates/apps/src/lib/client/rpc.rs | 22 +-- crates/apps/src/lib/client/tx.rs | 8 +- crates/apps/src/lib/client/utils.rs | 12 +- .../src/lib/config/ethereum_bridge/ledger.rs | 2 +- crates/apps/src/lib/config/genesis.rs | 26 ++-- crates/apps/src/lib/config/genesis/chain.rs | 22 +-- .../apps/src/lib/config/genesis/templates.rs | 20 +-- .../src/lib/config/genesis/transactions.rs | 20 +-- crates/apps/src/lib/config/genesis/utils.rs | 2 +- crates/apps/src/lib/config/global.rs | 2 +- crates/apps/src/lib/config/mod.rs | 8 +- crates/apps/src/lib/node/ledger/abortable.rs | 2 +- .../apps/src/lib/node/ledger/broadcaster.rs | 4 +- .../lib/node/ledger/ethereum_oracle/events.rs | 14 +- .../lib/node/ledger/ethereum_oracle/mod.rs | 15 +- .../test_tools/events_endpoint.rs | 2 +- .../ledger/ethereum_oracle/test_tools/mod.rs | 4 +- crates/apps/src/lib/node/ledger/mod.rs | 6 +- .../lib/node/ledger/shell/finalize_block.rs | 26 ++-- .../src/lib/node/ledger/shell/governance.rs | 6 +- .../src/lib/node/ledger/shell/init_chain.rs | 12 +- crates/apps/src/lib/node/ledger/shell/mod.rs | 47 +++--- .../lib/node/ledger/shell/prepare_proposal.rs | 18 +-- .../lib/node/ledger/shell/process_proposal.rs | 10 +- .../apps/src/lib/node/ledger/shell/queries.rs | 4 +- .../lib/node/ledger/shell/testing/client.rs | 2 +- .../src/lib/node/ledger/shell/testing/node.rs | 14 +- .../lib/node/ledger/shell/testing/utils.rs | 2 +- .../apps/src/lib/node/ledger/shell/utils.rs | 2 +- .../shell/vote_extensions/bridge_pool_vext.rs | 10 +- .../shell/vote_extensions/eth_events.rs | 16 +-- .../shell/vote_extensions/val_set_update.rs | 2 +- .../src/lib/node/ledger/shims/abcipp_shim.rs | 9 +- .../node/ledger/shims/abcipp_shim_types.rs | 6 +- .../apps/src/lib/node/ledger/storage/mod.rs | 59 ++++---- .../src/lib/node/ledger/storage/rocksdb.rs | 134 +++++++----------- .../src/lib/node/ledger/tendermint_node.rs | 8 +- crates/apps/src/lib/wallet/defaults.rs | 8 +- crates/apps/src/lib/wallet/mod.rs | 2 +- crates/apps/src/lib/wallet/pre_genesis.rs | 2 +- crates/apps/src/lib/wallet/store.rs | 4 +- crates/benches/README.md | 2 +- crates/benches/host_env.rs | 12 +- crates/benches/native_vps.rs | 102 ++++++------- crates/benches/process_wrapper.rs | 8 +- crates/benches/txs.rs | 36 ++--- crates/benches/vps.rs | 13 +- crates/core/Cargo.toml | 2 - crates/core/src/address.rs | 22 ++- crates/core/src/dec.rs | 8 +- crates/core/src/eth_abi.rs | 6 +- crates/core/src/eth_bridge_pool.rs | 22 +-- crates/core/src/ethereum_events.rs | 22 +-- crates/core/src/ethereum_structs.rs | 2 +- crates/core/src/event.rs | 4 +- crates/core/src/ibc.rs | 7 +- crates/core/src/keccak.rs | 4 +- crates/core/src/key/common.rs | 11 +- crates/core/src/key/ed25519.rs | 2 +- crates/core/src/key/mod.rs | 16 +-- crates/core/src/key/secp256k1.rs | 6 +- crates/core/src/lib.rs | 2 +- crates/core/src/masp.rs | 8 +- crates/core/src/storage.rs | 21 ++- crates/core/src/string_encoding.rs | 10 +- crates/core/src/token.rs | 14 +- crates/core/src/uint.rs | 4 +- crates/core/src/voting_power.rs | 4 +- crates/encoding_spec/src/main.rs | 8 +- crates/ethereum_bridge/src/lib.rs | 2 +- crates/ethereum_bridge/src/oracle/config.rs | 4 +- .../transactions/bridge_pool_roots.rs | 20 +-- .../transactions/ethereum_events/eth_msgs.rs | 8 +- .../transactions/ethereum_events/events.rs | 28 ++-- .../transactions/ethereum_events/mod.rs | 22 ++- .../src/protocol/transactions/mod.rs | 2 +- .../src/protocol/transactions/read.rs | 8 +- .../src/protocol/transactions/update.rs | 8 +- .../src/protocol/transactions/utils.rs | 12 +- .../transactions/validator_set_update/mod.rs | 12 +- .../src/protocol/transactions/votes.rs | 12 +- .../protocol/transactions/votes/storage.rs | 6 +- .../src/protocol/transactions/votes/update.rs | 12 +- .../protocol/validation/bridge_pool_roots.rs | 4 +- .../protocol/validation/ethereum_events.rs | 2 +- .../validation/validator_set_update.rs | 6 +- .../src/storage/bridge_pool.rs | 6 +- .../src/storage/eth_bridge_queries.rs | 19 ++- crates/ethereum_bridge/src/storage/mod.rs | 10 +- .../ethereum_bridge/src/storage/parameters.rs | 10 +- crates/ethereum_bridge/src/storage/proof.rs | 16 +-- .../src/storage/vote_tallies.rs | 10 +- .../src/storage/vp/bridge_pool.rs | 2 +- .../src/storage/vp/ethereum_bridge.rs | 2 +- .../ethereum_bridge/src/storage/whitelist.rs | 12 +- .../src/storage/wrapped_erc20s.rs | 14 +- crates/ethereum_bridge/src/test_utils.rs | 14 +- crates/governance/src/cli/offline.rs | 12 +- crates/governance/src/cli/onchain.rs | 6 +- crates/governance/src/cli/validation.rs | 6 +- crates/governance/src/lib.rs | 2 +- crates/governance/src/parameters.rs | 2 +- crates/governance/src/pgf/cli/steward.rs | 4 +- crates/governance/src/pgf/inflation.rs | 4 +- crates/governance/src/pgf/mod.rs | 2 +- crates/governance/src/pgf/parameters.rs | 4 +- crates/governance/src/pgf/storage/keys.rs | 4 +- crates/governance/src/pgf/storage/mod.rs | 4 +- crates/governance/src/pgf/storage/steward.rs | 4 +- crates/governance/src/storage/keys.rs | 4 +- crates/governance/src/storage/mod.rs | 4 +- crates/governance/src/storage/proposal.rs | 14 +- crates/governance/src/utils.rs | 10 +- crates/ibc/src/actions.rs | 12 +- crates/ibc/src/context/common.rs | 4 +- crates/ibc/src/context/storage.rs | 6 +- crates/ibc/src/context/token_transfer.rs | 6 +- crates/ibc/src/lib.rs | 8 +- crates/ibc/src/storage.rs | 10 +- .../src/reading/asynchronous/account.rs | 2 +- .../light_sdk/src/reading/asynchronous/mod.rs | 6 +- .../light_sdk/src/reading/asynchronous/pos.rs | 6 +- .../light_sdk/src/reading/blocking/account.rs | 2 +- crates/light_sdk/src/reading/blocking/mod.rs | 6 +- crates/light_sdk/src/reading/blocking/pos.rs | 6 +- crates/light_sdk/src/transaction/account.rs | 10 +- crates/light_sdk/src/transaction/bridge.rs | 17 +-- .../light_sdk/src/transaction/governance.rs | 10 +- crates/light_sdk/src/transaction/ibc.rs | 12 +- crates/light_sdk/src/transaction/mod.rs | 14 +- crates/light_sdk/src/transaction/pgf.rs | 12 +- crates/light_sdk/src/transaction/pos.rs | 14 +- crates/light_sdk/src/transaction/transfer.rs | 12 +- crates/light_sdk/src/transaction/wrapper.rs | 6 +- crates/macros/src/lib.rs | 98 ++++++------- crates/merkle_tree/src/eth_bridge_pool.rs | 20 +-- crates/merkle_tree/src/ics23_specs.rs | 2 +- crates/merkle_tree/src/lib.rs | 28 ++-- crates/namada/src/ledger/governance/mod.rs | 4 +- crates/namada/src/ledger/mod.rs | 13 +- .../ethereum_bridge/bridge_pool_vp.rs | 24 ++-- .../ledger/native_vp/ethereum_bridge/nut.rs | 10 +- .../ledger/native_vp/ethereum_bridge/vp.rs | 16 +-- .../src/ledger/native_vp/ibc/context.rs | 13 +- crates/namada/src/ledger/native_vp/ibc/mod.rs | 34 ++--- crates/namada/src/ledger/native_vp/masp.rs | 17 ++- crates/namada/src/ledger/native_vp/mod.rs | 16 +-- .../namada/src/ledger/native_vp/multitoken.rs | 14 +- .../namada/src/ledger/native_vp/parameters.rs | 4 +- crates/namada/src/ledger/pgf/mod.rs | 4 +- crates/namada/src/ledger/pgf/utils.rs | 2 +- crates/namada/src/ledger/pos/mod.rs | 8 +- crates/namada/src/ledger/pos/vp.rs | 4 +- crates/namada/src/ledger/protocol/mod.rs | 26 ++-- crates/namada/src/ledger/vp_host_fns.rs | 12 +- crates/namada/src/lib.rs | 11 +- crates/namada/src/types/ibc/mod.rs | 3 - crates/namada/src/types/key/mod.rs | 3 - crates/namada/src/types/mod.rs | 12 -- crates/namada/src/vm/host_env.rs | 28 ++-- crates/namada/src/vm/types.rs | 4 +- .../src/vm/wasm/compilation_cache/common.rs | 4 +- crates/namada/src/vm/wasm/host_env.rs | 2 +- crates/namada/src/vm/wasm/run.rs | 12 +- crates/parameters/src/lib.rs | 18 +-- crates/parameters/src/storage.rs | 4 +- crates/parameters/src/wasm_allowlist.rs | 4 +- crates/proof_of_stake/src/epoched.rs | 8 +- crates/proof_of_stake/src/error.rs | 6 +- crates/proof_of_stake/src/lib.rs | 16 +-- crates/proof_of_stake/src/parameters.rs | 10 +- crates/proof_of_stake/src/pos_queries.rs | 8 +- crates/proof_of_stake/src/queries.rs | 8 +- crates/proof_of_stake/src/rewards.rs | 10 +- crates/proof_of_stake/src/slashing.rs | 8 +- crates/proof_of_stake/src/storage.rs | 34 ++--- crates/proof_of_stake/src/storage_key.rs | 4 +- crates/proof_of_stake/src/tests/helpers.rs | 14 +- .../proof_of_stake/src/tests/state_machine.rs | 12 +- .../src/tests/state_machine_v2.rs | 12 +- .../src/tests/test_helper_fns.rs | 10 +- crates/proof_of_stake/src/tests/test_pos.rs | 14 +- .../src/tests/test_slash_and_redel.rs | 8 +- .../src/tests/test_validator.rs | 14 +- crates/proof_of_stake/src/types/mod.rs | 16 +-- crates/proof_of_stake/src/types/rev_order.rs | 8 +- .../src/validator_set_update.rs | 8 +- crates/replay_protection/src/lib.rs | 4 +- crates/sdk/Cargo.toml | 2 + crates/sdk/src/args.rs | 32 ++--- crates/sdk/src/error.rs | 10 +- crates/sdk/src/eth_bridge/bridge_pool.rs | 36 +++-- crates/sdk/src/eth_bridge/mod.rs | 2 +- crates/sdk/src/eth_bridge/validator_set.rs | 8 +- crates/sdk/src/events/log.rs | 2 +- crates/sdk/src/events/log/dumb_queries.rs | 4 +- crates/sdk/src/lib.rs | 37 +++-- crates/sdk/src/masp.rs | 34 ++--- crates/sdk/src/queries/mod.rs | 9 +- crates/sdk/src/queries/router.rs | 18 +-- crates/sdk/src/queries/shell.rs | 14 +- crates/sdk/src/queries/shell/eth_bridge.rs | 41 +++--- crates/sdk/src/queries/types.rs | 2 +- crates/sdk/src/queries/vp/pgf.rs | 2 +- crates/sdk/src/queries/vp/pos.rs | 8 +- crates/sdk/src/queries/vp/token.rs | 8 +- crates/sdk/src/rpc.rs | 12 +- crates/sdk/src/signing.rs | 26 ++-- crates/sdk/src/tx.rs | 18 +-- crates/sdk/src/wallet/alias.rs | 2 +- crates/sdk/src/wallet/derivation_path.rs | 4 +- crates/sdk/src/wallet/mod.rs | 6 +- crates/sdk/src/wallet/pre_genesis.rs | 2 +- crates/sdk/src/wallet/store.rs | 6 +- crates/shielded_token/src/conversion.rs | 20 +-- crates/shielded_token/src/lib.rs | 2 +- crates/shielded_token/src/storage.rs | 8 +- crates/shielded_token/src/storage_key.rs | 6 +- crates/shielded_token/src/utils.rs | 2 +- crates/state/src/lib.rs | 34 +++-- crates/state/src/wl_storage.rs | 12 +- crates/state/src/write_log.rs | 20 ++- crates/storage/src/collections/lazy_map.rs | 4 +- crates/storage/src/collections/lazy_set.rs | 4 +- crates/storage/src/collections/lazy_vec.rs | 4 +- crates/storage/src/collections/mod.rs | 2 +- crates/storage/src/conversion_state.rs | 6 +- crates/storage/src/db.rs | 14 +- crates/storage/src/lib.rs | 92 +++++------- crates/storage/src/mockdb.rs | 116 ++++++--------- crates/storage/src/tx_queue.rs | 2 +- crates/test_utils/src/tx_data.rs | 6 +- crates/tests/src/e2e/eth_bridge_tests.rs | 18 +-- .../tests/src/e2e/eth_bridge_tests/helpers.rs | 8 +- crates/tests/src/e2e/helpers.rs | 8 +- crates/tests/src/e2e/ibc_tests.rs | 10 +- crates/tests/src/e2e/ledger_tests.rs | 12 +- .../tests/src/e2e/multitoken_tests/helpers.rs | 6 +- crates/tests/src/e2e/setup.rs | 10 +- crates/tests/src/integration/masp.rs | 2 +- crates/tests/src/integration/setup.rs | 4 +- crates/tests/src/native_vp/eth_bridge_pool.rs | 18 +-- crates/tests/src/native_vp/mod.rs | 4 +- crates/tests/src/native_vp/pos.rs | 18 +-- crates/tests/src/storage.rs | 2 +- .../src/storage_api/collections/lazy_map.rs | 4 +- .../src/storage_api/collections/lazy_set.rs | 4 +- .../src/storage_api/collections/lazy_vec.rs | 4 +- .../collections/nested_lazy_map.rs | 4 +- crates/tests/src/vm_host_env/ibc.rs | 14 +- crates/tests/src/vm_host_env/mod.rs | 10 +- crates/tests/src/vm_host_env/tx.rs | 12 +- crates/tests/src/vm_host_env/vp.rs | 6 +- crates/token/src/lib.rs | 2 +- crates/trans_token/src/inflation.rs | 4 +- crates/trans_token/src/lib.rs | 2 +- crates/trans_token/src/storage.rs | 6 +- crates/trans_token/src/storage_key.rs | 6 +- crates/tx/src/data/eval_vp.rs | 2 +- crates/tx/src/data/mod.rs | 22 +-- crates/tx/src/data/pgf.rs | 8 +- crates/tx/src/data/pos.rs | 16 +-- crates/tx/src/data/protocol.rs | 2 +- crates/tx/src/data/wrapper.rs | 12 +- crates/tx/src/lib.rs | 4 +- crates/tx/src/types.rs | 92 ++++++------ crates/tx_env/src/lib.rs | 6 +- crates/tx_prelude/src/ibc.rs | 6 +- crates/tx_prelude/src/key.rs | 2 +- crates/tx_prelude/src/lib.rs | 33 ++--- crates/tx_prelude/src/proof_of_stake.rs | 6 +- crates/tx_prelude/src/token.rs | 2 +- crates/vm_env/src/lib.rs | 2 +- crates/vote_ext/src/bridge_pool_roots.rs | 8 +- crates/vote_ext/src/ethereum_events.rs | 16 +-- crates/vote_ext/src/lib.rs | 4 +- crates/vote_ext/src/validator_set_update.rs | 28 ++-- .../src/collection_validation/lazy_map.rs | 2 +- .../src/collection_validation/lazy_set.rs | 2 +- .../src/collection_validation/lazy_vec.rs | 2 +- .../vp_env/src/collection_validation/mod.rs | 2 +- crates/vp_env/src/lib.rs | 10 +- crates/vp_prelude/src/lib.rs | 16 +-- wasm/Cargo.lock | 4 +- wasm/wasm_source/src/tx_bond.rs | 4 +- .../src/tx_change_validator_commission.rs | 4 +- wasm/wasm_source/src/tx_redelegate.rs | 4 +- wasm/wasm_source/src/tx_unbond.rs | 4 +- wasm/wasm_source/src/tx_withdraw.rs | 4 +- wasm/wasm_source/src/vp_implicit.rs | 4 +- wasm/wasm_source/src/vp_user.rs | 4 +- wasm_for_tests/wasm_source/Cargo.lock | 4 +- 305 files changed, 1703 insertions(+), 1875 deletions(-) delete mode 100644 crates/namada/src/types/ibc/mod.rs delete mode 100644 crates/namada/src/types/key/mod.rs delete mode 100644 crates/namada/src/types/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 41676f3c52..70279d8475 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4342,7 +4342,6 @@ dependencies = [ "k256", "masp_primitives", "namada_macros", - "num-derive", "num-integer", "num-rational 0.4.1", "num-traits 0.2.17", @@ -4351,7 +4350,6 @@ dependencies = [ "pretty_assertions", "primitive-types", "proptest", - "prost 0.12.3", "prost-types 0.12.3", "rand 0.8.5", "rand_core 0.6.4", @@ -4561,7 +4559,7 @@ dependencies = [ [[package]] name = "namada_replay_protection" -version = "0.31.1" +version = "0.31.5" dependencies = [ "namada_core", ] diff --git a/crates/account/src/lib.rs b/crates/account/src/lib.rs index e7f79a3e55..890cf942a0 100644 --- a/crates/account/src/lib.rs +++ b/crates/account/src/lib.rs @@ -7,9 +7,9 @@ mod storage_key; mod types; use borsh::{BorshDeserialize, BorshSerialize}; -pub use namada_core::types::account::AccountPublicKeysMap; -use namada_core::types::address::Address; -use namada_core::types::key::common; +pub use namada_core::account::AccountPublicKeysMap; +use namada_core::address::Address; +use namada_core::key::common; use serde::{Deserialize, Serialize}; pub use storage::*; pub use storage_key::*; diff --git a/crates/account/src/storage.rs b/crates/account/src/storage.rs index 50b56e7808..357922b6ea 100644 --- a/crates/account/src/storage.rs +++ b/crates/account/src/storage.rs @@ -1,8 +1,8 @@ //! Cryptographic signature keys storage API -use namada_core::types::address::Address; -use namada_core::types::key::common; -use namada_core::types::storage; +use namada_core::address::Address; +use namada_core::key::common; +use namada_core::storage; use namada_storage::{Result, StorageRead, StorageWrite}; use super::*; diff --git a/crates/account/src/storage_key.rs b/crates/account/src/storage_key.rs index 20e02906b8..baec1fba86 100644 --- a/crates/account/src/storage_key.rs +++ b/crates/account/src/storage_key.rs @@ -1,6 +1,6 @@ -use namada_core::types::address::Address; -use namada_core::types::key::common; -use namada_core::types::storage::{self, DbKeySeg}; +use namada_core::address::Address; +use namada_core::key::common; +use namada_core::storage::{self, DbKeySeg}; use namada_macros::StorageKeys; use namada_storage::collections::lazy_map::LazyMap; use namada_storage::collections::{lazy_map, LazyCollection}; diff --git a/crates/account/src/types.rs b/crates/account/src/types.rs index 606cf4c63c..332c3e8764 100644 --- a/crates/account/src/types.rs +++ b/crates/account/src/types.rs @@ -1,7 +1,7 @@ +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::hash::Hash; -use namada_core::types::key::common; +use namada_core::hash::Hash; +use namada_core::key::common; use serde::{Deserialize, Serialize}; /// A tx data type to initialize a new established account @@ -53,9 +53,9 @@ pub struct UpdateAccount { #[cfg(any(test, feature = "testing"))] /// Tests and strategies for accounts pub mod tests { - use namada_core::types::address::testing::arb_non_internal_address; - use namada_core::types::hash::testing::arb_hash; - use namada_core::types::key::testing::arb_common_pk; + use namada_core::address::testing::arb_non_internal_address; + use namada_core::hash::testing::arb_hash; + use namada_core::key::testing::arb_common_pk; use proptest::prelude::Just; use proptest::{collection, option, prop_compose}; diff --git a/crates/apps/src/bin/namada-node/cli.rs b/crates/apps/src/bin/namada-node/cli.rs index 7477d3d6af..a0d00d48dc 100644 --- a/crates/apps/src/bin/namada-node/cli.rs +++ b/crates/apps/src/bin/namada-node/cli.rs @@ -1,7 +1,7 @@ //! Namada node CLI. use eyre::{Context, Result}; -use namada::types::time::{DateTimeUtc, Utc}; +use namada::core::time::{DateTimeUtc, Utc}; use namada_apps::cli::{self, cmds}; use namada_apps::config::ValidatorLocalConfig; use namada_apps::node::ledger; diff --git a/crates/apps/src/lib/bench_utils.rs b/crates/apps/src/lib/bench_utils.rs index 40e3c6d393..1db7a07411 100644 --- a/crates/apps/src/lib/bench_utils.rs +++ b/crates/apps/src/lib/bench_utils.rs @@ -14,6 +14,16 @@ use borsh_ext::BorshSerializeExt; use masp_primitives::transaction::Transaction; use masp_primitives::zip32::ExtendedFullViewingKey; use masp_proofs::prover::LocalTxProver; +use namada::core::address::{self, Address, InternalAddress}; +use namada::core::chain::ChainId; +use namada::core::hash::Hash; +use namada::core::key::common::SecretKey; +use namada::core::masp::{ + ExtendedViewingKey, PaymentAddress, TransferSource, TransferTarget, +}; +use namada::core::storage::{BlockHeight, Epoch, Key, KeySeg, TxIndex}; +use namada::core::time::DateTimeUtc; +use namada::core::token::{Amount, DenominatedAmount, Transfer}; use namada::governance::storage::proposal::ProposalType; use namada::governance::InitProposalData; use namada::ibc::apps::transfer::types::msgs::transfer::MsgTransfer; @@ -50,6 +60,7 @@ use namada::ibc::core::host::types::path::{ use namada::ibc::primitives::proto::{Any, Protobuf}; use namada::ibc::primitives::{Msg, Timestamp as IbcTimestamp}; use namada::ibc::storage::port_key; +use namada::io::StdIo; use namada::ledger::dry_run_tx; use namada::ledger::gas::TxGasMeter; use namada::ledger::ibc::storage::{channel_key, connection_key}; @@ -62,17 +73,6 @@ use namada::tendermint_rpc::{self}; use namada::tx::data::pos::Bond; use namada::tx::data::{TxResult, VpsResult}; use namada::tx::{Code, Data, Section, Signature, Tx}; -use namada::types::address::{self, Address, InternalAddress}; -use namada::types::chain::ChainId; -use namada::types::hash::Hash; -use namada::types::io::StdIo; -use namada::types::key::common::SecretKey; -use namada::types::masp::{ - ExtendedViewingKey, PaymentAddress, TransferSource, TransferTarget, -}; -use namada::types::storage::{BlockHeight, Epoch, Key, KeySeg, TxIndex}; -use namada::types::time::DateTimeUtc; -use namada::types::token::{Amount, DenominatedAmount, Transfer}; use namada::vm::wasm::run; use namada::{proof_of_stake, tendermint}; use namada_sdk::masp::{ @@ -1021,7 +1021,7 @@ impl BenchShieldedCtx { let mut hasher = Sha256::new(); let shielded_section_hash = shielded.clone().map(|transaction| { - namada::types::hash::Hash( + namada::core::hash::Hash( Section::MaspTx(transaction) .hash(&mut hasher) .finalize_reset() diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 3e84538f0f..45d75fc7d5 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -15,7 +15,7 @@ pub mod wallet; use clap::{ArgGroup, ArgMatches, ColorChoice}; use color_eyre::eyre::Result; -use namada::types::io::StdIo; +use namada::io::StdIo; use utils::*; pub use utils::{safe_exit, Cmd}; @@ -2849,19 +2849,19 @@ pub mod args { use std::path::PathBuf; use std::str::FromStr; + use namada::core::address::{Address, EstablishedAddress}; + use namada::core::chain::{ChainId, ChainIdPrefix}; + use namada::core::dec::Dec; + use namada::core::ethereum_events::EthAddress; + use namada::core::keccak::KeccakHash; + use namada::core::key::*; + use namada::core::masp::PaymentAddress; + use namada::core::storage::{self, BlockHeight, Epoch}; + use namada::core::time::DateTimeUtc; + use namada::core::token; + use namada::core::token::NATIVE_MAX_DECIMAL_PLACES; use namada::ibc::core::host::types::identifiers::{ChannelId, PortId}; use namada::tx::data::GasLimit; - use namada::types::address::{Address, EstablishedAddress}; - use namada::types::chain::{ChainId, ChainIdPrefix}; - use namada::types::dec::Dec; - use namada::types::ethereum_events::EthAddress; - use namada::types::keccak::KeccakHash; - use namada::types::key::*; - use namada::types::masp::PaymentAddress; - use namada::types::storage::{self, BlockHeight, Epoch}; - use namada::types::time::DateTimeUtc; - use namada::types::token; - use namada::types::token::NATIVE_MAX_DECIMAL_PLACES; pub use namada_sdk::args::*; pub use namada_sdk::tx::{ TX_BECOME_VALIDATOR_WASM, TX_BOND_WASM, TX_BRIDGE_POOL_WASM, diff --git a/crates/apps/src/lib/cli/api.rs b/crates/apps/src/lib/cli/api.rs index 3a5db7d33e..0d83273598 100644 --- a/crates/apps/src/lib/cli/api.rs +++ b/crates/apps/src/lib/cli/api.rs @@ -1,5 +1,5 @@ +use namada::io::Io; use namada::tendermint_rpc::HttpClient; -use namada::types::io::Io; use namada_sdk::error::Error; use namada_sdk::queries::Client; use namada_sdk::rpc::wait_until_node_is_synched; diff --git a/crates/apps/src/lib/cli/client.rs b/crates/apps/src/lib/cli/client.rs index a8df86db19..64b7c4f7e4 100644 --- a/crates/apps/src/lib/cli/client.rs +++ b/crates/apps/src/lib/cli/client.rs @@ -1,5 +1,5 @@ use color_eyre::eyre::Result; -use namada::types::io::Io; +use namada::io::Io; use namada_sdk::{Namada, NamadaImpl}; use crate::cli; diff --git a/crates/apps/src/lib/cli/context.rs b/crates/apps/src/lib/cli/context.rs index b9653e9fb2..aafe04d069 100644 --- a/crates/apps/src/lib/cli/context.rs +++ b/crates/apps/src/lib/cli/context.rs @@ -6,14 +6,14 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use color_eyre::eyre::Result; +use namada::core::address::{Address, InternalAddress}; +use namada::core::chain::ChainId; +use namada::core::ethereum_events::EthAddress; +use namada::core::ibc::is_ibc_denom; +use namada::core::key::*; +use namada::core::masp::*; +use namada::io::Io; use namada::ledger::ibc::storage::ibc_token; -use namada::types::address::{Address, InternalAddress}; -use namada::types::chain::ChainId; -use namada::types::ethereum_events::EthAddress; -use namada::types::ibc::is_ibc_denom; -use namada::types::io::Io; -use namada::types::key::*; -use namada::types::masp::*; use namada_sdk::masp::fs::FsShieldedUtils; use namada_sdk::masp::ShieldedContext; use namada_sdk::wallet::Wallet; diff --git a/crates/apps/src/lib/cli/relayer.rs b/crates/apps/src/lib/cli/relayer.rs index e46f568023..37f0cada62 100644 --- a/crates/apps/src/lib/cli/relayer.rs +++ b/crates/apps/src/lib/cli/relayer.rs @@ -1,5 +1,5 @@ use color_eyre::eyre::Result; -use namada::types::io::Io; +use namada::io::Io; use namada_sdk::eth_bridge::{bridge_pool, validator_set}; use crate::cli; diff --git a/crates/apps/src/lib/cli/wallet.rs b/crates/apps/src/lib/cli/wallet.rs index d47f34cf23..53ea2b6631 100644 --- a/crates/apps/src/lib/cli/wallet.rs +++ b/crates/apps/src/lib/cli/wallet.rs @@ -12,10 +12,10 @@ use ledger_namada_rs::{BIP44Path, NamadaApp}; use ledger_transport_hid::hidapi::HidApi; use ledger_transport_hid::TransportNativeHID; use masp_primitives::zip32::ExtendedFullViewingKey; -use namada::types::address::{Address, DecodeError}; -use namada::types::io::Io; -use namada::types::key::*; -use namada::types::masp::{ExtendedSpendingKey, MaspValue, PaymentAddress}; +use namada::core::address::{Address, DecodeError}; +use namada::core::key::*; +use namada::core::masp::{ExtendedSpendingKey, MaspValue, PaymentAddress}; +use namada::io::Io; use namada_sdk::masp::find_valid_diversifier; use namada_sdk::wallet::{ DecryptionError, DerivationPath, DerivationPathError, FindKeyError, Wallet, diff --git a/crates/apps/src/lib/client/rpc.rs b/crates/apps/src/lib/client/rpc.rs index ec1df0f420..53f9323dae 100644 --- a/crates/apps/src/lib/client/rpc.rs +++ b/crates/apps/src/lib/client/rpc.rs @@ -15,6 +15,15 @@ use masp_primitives::merkle_tree::MerklePath; use masp_primitives::sapling::{Node, ViewingKey}; use masp_primitives::transaction::components::I128Sum; use masp_primitives::zip32::ExtendedFullViewingKey; +use namada::core::address::{Address, InternalAddress, MASP}; +use namada::core::hash::Hash; +use namada::core::ibc::{is_ibc_denom, IbcTokenHash}; +use namada::core::key::*; +use namada::core::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress}; +use namada::core::storage::{ + BlockHeight, BlockResults, Epoch, IndexedTx, Key, KeySeg, +}; +use namada::core::token::{Change, MaspDigitPos}; use namada::governance::cli::offline::{ find_offline_proposal, find_offline_votes, read_offline_files, OfflineSignedProposal, OfflineVote, @@ -29,6 +38,7 @@ use namada::governance::storage::proposal::{ use namada::governance::utils::{ compute_proposal_result, ProposalVotes, TallyType, TallyVote, VotePower, }; +use namada::io::Io; use namada::ledger::events::Event; use namada::ledger::ibc::storage::{ ibc_denom_key, ibc_denom_key_prefix, is_ibc_denom_key, @@ -38,16 +48,6 @@ use namada::ledger::pos::types::{CommissionPair, Slash}; use namada::ledger::pos::PosParams; use namada::ledger::queries::RPC; use namada::proof_of_stake::types::{ValidatorState, WeightedValidator}; -use namada::types::address::{Address, InternalAddress, MASP}; -use namada::types::hash::Hash; -use namada::types::ibc::{is_ibc_denom, IbcTokenHash}; -use namada::types::io::Io; -use namada::types::key::*; -use namada::types::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress}; -use namada::types::storage::{ - BlockHeight, BlockResults, Epoch, IndexedTx, Key, KeySeg, -}; -use namada::types::token::{Change, MaspDigitPos}; use namada::{state as storage, token}; use namada_sdk::error::{ is_pinned_error, Error, PinnedBalanceError, QueryError, @@ -348,7 +348,7 @@ pub async fn query_transparent_balance( args: args::QueryBalance, ) { let prefix = Key::from( - Address::Internal(namada::types::address::InternalAddress::Multitoken) + Address::Internal(namada::core::address::InternalAddress::Multitoken) .to_db_key(), ); match (args.token, args.owner) { diff --git a/crates/apps/src/lib/client/tx.rs b/crates/apps/src/lib/client/tx.rs index eb9a01804b..eb0cadb98d 100644 --- a/crates/apps/src/lib/client/tx.rs +++ b/crates/apps/src/lib/client/tx.rs @@ -7,6 +7,9 @@ use borsh_ext::BorshSerializeExt; use ledger_namada_rs::{BIP44Path, NamadaApp}; use ledger_transport_hid::hidapi::HidApi; use ledger_transport_hid::TransportNativeHID; +use namada::core::address::{Address, ImplicitAddress}; +use namada::core::dec::Dec; +use namada::core::key::{self, *}; use namada::governance::cli::offline::{ OfflineProposal, OfflineSignedProposal, OfflineVote, }; @@ -15,13 +18,10 @@ use namada::governance::cli::onchain::{ }; use namada::governance::ProposalVote; use namada::ibc::apps::transfer::types::Memo; +use namada::io::Io; use namada::state::EPOCH_SWITCH_BLOCKS_DELAY; use namada::tx::data::pos::{BecomeValidator, ConsensusKeyChange}; use namada::tx::{CompressedSignature, Section, Signer, Tx}; -use namada::types::address::{Address, ImplicitAddress}; -use namada::types::dec::Dec; -use namada::types::io::Io; -use namada::types::key::{self, *}; use namada_sdk::rpc::{InnerTxResult, TxBroadcastData, TxResponse}; use namada_sdk::wallet::alias::validator_consensus_key; use namada_sdk::wallet::{Wallet, WalletIo}; diff --git a/crates/apps/src/lib/client/utils.rs b/crates/apps/src/lib/client/utils.rs index a2d5115654..07643104f1 100644 --- a/crates/apps/src/lib/client/utils.rs +++ b/crates/apps/src/lib/client/utils.rs @@ -10,12 +10,12 @@ use flate2::read::GzDecoder; use flate2::write::GzEncoder; use flate2::Compression; use itertools::Either; -use namada::types::chain::ChainId; -use namada::types::dec::Dec; -use namada::types::key::*; -use namada::types::string_encoding::StringEncoded; -use namada::types::token; -use namada::types::uint::Uint; +use namada::core::chain::ChainId; +use namada::core::dec::Dec; +use namada::core::key::*; +use namada::core::string_encoding::StringEncoded; +use namada::core::token; +use namada::core::uint::Uint; use namada::vm::validate_untrusted_wasm; use namada_sdk::wallet::{alias, Wallet}; use prost::bytes::Bytes; diff --git a/crates/apps/src/lib/config/ethereum_bridge/ledger.rs b/crates/apps/src/lib/config/ethereum_bridge/ledger.rs index 55694439b5..c1117c44b5 100644 --- a/crates/apps/src/lib/config/ethereum_bridge/ledger.rs +++ b/crates/apps/src/lib/config/ethereum_bridge/ledger.rs @@ -1,6 +1,6 @@ //! Runtime configuration for a validator node. #[allow(unused_imports)] -use namada::types::ethereum_events::EthereumEvent; +use namada::core::ethereum_events::EthereumEvent; use serde::{Deserialize, Serialize}; /// Default [Ethereum JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/) endpoint used by the oracle diff --git a/crates/apps/src/lib/config/genesis.rs b/crates/apps/src/lib/config/genesis.rs index 2a4377a877..074d17966a 100644 --- a/crates/apps/src/lib/config/genesis.rs +++ b/crates/apps/src/lib/config/genesis.rs @@ -11,19 +11,19 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use derivative::Derivative; +use namada::core::address::{Address, EstablishedAddress}; +use namada::core::chain::ProposalBytes; +use namada::core::key::*; +use namada::core::storage; +use namada::core::string_encoding::StringEncoded; +use namada::core::time::{DateTimeUtc, DurationSecs}; +use namada::core::token::Denomination; use namada::governance::parameters::GovernanceParameters; use namada::governance::pgf::parameters::PgfParameters; use namada::ledger::eth_bridge::EthereumBridgeParams; use namada::ledger::parameters::EpochDuration; use namada::ledger::pos::{Dec, GenesisValidator, OwnedPosParams}; use namada::token; -use namada::types::address::{Address, EstablishedAddress}; -use namada::types::chain::ProposalBytes; -use namada::types::key::*; -use namada::types::storage; -use namada::types::string_encoding::StringEncoded; -use namada::types::time::{DateTimeUtc, DurationSecs}; -use namada::types::token::Denomination; use serde::{Deserialize, Serialize}; #[cfg(all(any(test, feature = "benches"), not(feature = "integration")))] @@ -313,13 +313,13 @@ pub fn make_dev_genesis( use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::time::Duration; + use namada::core::address::wnam; + use namada::core::chain::ChainIdPrefix; + use namada::core::ethereum_events::EthAddress; + use namada::core::key::*; use namada::ledger::eth_bridge::{Contracts, UpgradeableContract}; use namada::ledger::pos::types::ValidatorMetaData; use namada::tx::standalone_signature; - use namada::types::address::wnam; - use namada::types::chain::ChainIdPrefix; - use namada::types::ethereum_events::EthAddress; - use namada::types::key::*; use namada_sdk::wallet::alias::Alias; use crate::config::genesis::chain::{finalize, DeriveEstablishedAddress}; @@ -554,8 +554,8 @@ pub fn make_dev_genesis( #[cfg(test)] pub mod tests { use borsh_ext::BorshSerializeExt; - use namada::types::address::testing::gen_established_address; - use namada::types::key::*; + use namada::core::address::testing::gen_established_address; + use namada::core::key::*; use rand::prelude::ThreadRng; use rand::thread_rng; diff --git a/crates/apps/src/lib/config/genesis/chain.rs b/crates/apps/src/lib/config/genesis/chain.rs index 88a95ec9f5..d440bab5f4 100644 --- a/crates/apps/src/lib/config/genesis/chain.rs +++ b/crates/apps/src/lib/config/genesis/chain.rs @@ -4,17 +4,17 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use borsh_ext::BorshSerializeExt; -use namada::ledger::parameters::EpochDuration; -use namada::types::address::{ +use namada::address::InternalAddress; +use namada::core::address::{ Address, EstablishedAddress, EstablishedAddressGen, }; -use namada::types::chain::{ChainId, ChainIdPrefix}; -use namada::types::dec::Dec; -use namada::types::hash::Hash; -use namada::types::key::{common, RefTo}; -use namada::types::time::{DateTimeUtc, DurationNanos, Rfc3339String}; -use namada::types::token::Amount; -use namada_sdk::types::address::InternalAddress; +use namada::core::chain::{ChainId, ChainIdPrefix}; +use namada::core::dec::Dec; +use namada::core::hash::Hash; +use namada::core::key::{common, RefTo}; +use namada::core::time::{DateTimeUtc, DurationNanos, Rfc3339String}; +use namada::core::token::Amount; +use namada::ledger::parameters::EpochDuration; use namada_sdk::wallet::store::AddressVpType; use namada_sdk::wallet::{pre_genesis, Wallet}; use serde::{Deserialize, Serialize}; @@ -310,11 +310,11 @@ impl Finalized { let min_duration: i64 = 60 * 60 * 24 * 365 / (epochs_per_year as i64); let epoch_duration = EpochDuration { min_num_of_blocks, - min_duration: namada::types::time::Duration::seconds(min_duration) + min_duration: namada::core::time::Duration::seconds(min_duration) .into(), }; let max_expected_time_per_block = - namada::types::time::Duration::seconds(max_expected_time_per_block) + namada::core::time::Duration::seconds(max_expected_time_per_block) .into(); let vp_allowlist = vp_allowlist.unwrap_or_default(); let tx_allowlist = tx_allowlist.unwrap_or_default(); diff --git a/crates/apps/src/lib/config/genesis/templates.rs b/crates/apps/src/lib/config/genesis/templates.rs index 7ac2d588ff..696880552a 100644 --- a/crates/apps/src/lib/config/genesis/templates.rs +++ b/crates/apps/src/lib/config/genesis/templates.rs @@ -5,17 +5,17 @@ use std::marker::PhantomData; use std::path::Path; use borsh::{BorshDeserialize, BorshSerialize}; +use namada::core::address::Address; +use namada::core::chain::ProposalBytes; +use namada::core::dec::Dec; +use namada::core::ethereum_structs; +use namada::core::token::{ + Amount, DenominatedAmount, Denomination, NATIVE_MAX_DECIMAL_PLACES, +}; use namada::eth_bridge::storage::parameters::{ Contracts, Erc20WhitelistEntry, MinimumConfirmations, }; use namada::token; -use namada::types::address::Address; -use namada::types::chain::ProposalBytes; -use namada::types::dec::Dec; -use namada::types::ethereum_structs; -use namada::types::token::{ - Amount, DenominatedAmount, Denomination, NATIVE_MAX_DECIMAL_PLACES, -}; use serde::{Deserialize, Serialize}; use super::transactions::{self, Transactions}; @@ -948,9 +948,9 @@ mod tests { use std::fs; use std::path::PathBuf; - use namada::types::key; - use namada::types::key::RefTo; - use namada::types::string_encoding::StringEncoded; + use namada::core::key; + use namada::core::key::RefTo; + use namada::core::string_encoding::StringEncoded; use tempfile::tempdir; use super::*; diff --git a/crates/apps/src/lib/config/genesis/transactions.rs b/crates/apps/src/lib/config/genesis/transactions.rs index 68a3040eb8..8d3e6facfc 100644 --- a/crates/apps/src/lib/config/genesis/transactions.rs +++ b/crates/apps/src/lib/config/genesis/transactions.rs @@ -11,22 +11,22 @@ use ledger_namada_rs::NamadaApp; use ledger_transport_hid::hidapi::HidApi; use ledger_transport_hid::TransportNativeHID; use namada::account::AccountPublicKeysMap; +use namada::core::address::{nam, Address, EstablishedAddress}; +use namada::core::chain::ChainId; +use namada::core::dec::Dec; +use namada::core::key::{ + common, ed25519, RefTo, SerializeWithBorsh, SigScheme, +}; +use namada::core::string_encoding::StringEncoded; +use namada::core::time::DateTimeUtc; +use namada::core::token; +use namada::core::token::{DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES}; use namada::ledger::pos::common::PublicKey; use namada::ledger::pos::types::ValidatorMetaData; use namada::tx::data::{pos, Fee, TxType}; use namada::tx::{ verify_standalone_sig, Code, Commitment, Data, Section, SignatureIndex, Tx, }; -use namada::types::address::{nam, Address, EstablishedAddress}; -use namada::types::chain::ChainId; -use namada::types::dec::Dec; -use namada::types::key::{ - common, ed25519, RefTo, SerializeWithBorsh, SigScheme, -}; -use namada::types::string_encoding::StringEncoded; -use namada::types::time::DateTimeUtc; -use namada::types::token; -use namada::types::token::{DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES}; use namada_sdk::args::Tx as TxArgs; use namada_sdk::signing::{sign_tx, SigningTxData}; use namada_sdk::tx::{TX_BECOME_VALIDATOR_WASM, TX_BOND_WASM}; diff --git a/crates/apps/src/lib/config/genesis/utils.rs b/crates/apps/src/lib/config/genesis/utils.rs index a17f09843d..a67f259db0 100644 --- a/crates/apps/src/lib/config/genesis/utils.rs +++ b/crates/apps/src/lib/config/genesis/utils.rs @@ -4,8 +4,8 @@ use std::path::Path; use eyre::Context; use ledger_namada_rs::NamadaApp; use ledger_transport_hid::TransportNativeHID; +use namada::core::key::common; use namada::tx::Tx; -use namada::types::key::common; use namada_sdk::wallet::Wallet; use namada_sdk::{error, signing}; use serde::de::DeserializeOwned; diff --git a/crates/apps/src/lib/config/global.rs b/crates/apps/src/lib/config/global.rs index 1dc1380635..f6d917c770 100644 --- a/crates/apps/src/lib/config/global.rs +++ b/crates/apps/src/lib/config/global.rs @@ -4,7 +4,7 @@ use std::fs::{create_dir_all, File}; use std::io::Write; use std::path::{Path, PathBuf}; -use namada::types::chain::ChainId; +use namada::core::chain::ChainId; use serde::{Deserialize, Serialize}; use thiserror::Error; diff --git a/crates/apps/src/lib/config/mod.rs b/crates/apps/src/lib/config/mod.rs index 6d18586408..782ffee77d 100644 --- a/crates/apps/src/lib/config/mod.rs +++ b/crates/apps/src/lib/config/mod.rs @@ -11,9 +11,9 @@ use std::io::Write; use std::path::{Path, PathBuf}; use directories::ProjectDirs; -use namada::types::chain::ChainId; -use namada::types::storage::BlockHeight; -use namada::types::time::Rfc3339String; +use namada::core::chain::ChainId; +use namada::core::storage::BlockHeight; +use namada::core::time::Rfc3339String; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -45,7 +45,7 @@ pub struct Config { #[derive(Debug, Serialize, Deserialize)] pub struct ValidatorLocalConfig { pub accepted_gas_tokens: - HashMap, + HashMap, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] diff --git a/crates/apps/src/lib/node/ledger/abortable.rs b/crates/apps/src/lib/node/ledger/abortable.rs index ceb4a4c892..5a5bf11e58 100644 --- a/crates/apps/src/lib/node/ledger/abortable.rs +++ b/crates/apps/src/lib/node/ledger/abortable.rs @@ -1,7 +1,7 @@ use std::future::Future; use std::pin::Pin; -use namada::types::control_flow::{install_shutdown_signal, ShutdownSignal}; +use namada::control_flow::{install_shutdown_signal, ShutdownSignal}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::task::JoinHandle; diff --git a/crates/apps/src/lib/node/ledger/broadcaster.rs b/crates/apps/src/lib/node/ledger/broadcaster.rs index 6a0d9bf149..7c257d172a 100644 --- a/crates/apps/src/lib/node/ledger/broadcaster.rs +++ b/crates/apps/src/lib/node/ledger/broadcaster.rs @@ -1,8 +1,8 @@ use std::net::SocketAddr; use std::ops::ControlFlow; -use namada::types::control_flow::time; -use namada::types::time::{DateTimeUtc, Utc}; +use namada::control_flow::time; +use namada::time::{DateTimeUtc, Utc}; use tokio::sync::mpsc::UnboundedReceiver; use crate::facade::tendermint_rpc::{Client, HttpClient}; diff --git a/crates/apps/src/lib/node/ledger/ethereum_oracle/events.rs b/crates/apps/src/lib/node/ledger/ethereum_oracle/events.rs index a750ffbc15..d804e85d91 100644 --- a/crates/apps/src/lib/node/ledger/ethereum_oracle/events.rs +++ b/crates/apps/src/lib/node/ledger/ethereum_oracle/events.rs @@ -7,14 +7,14 @@ pub mod eth_events { ValidatorSetUpdateFilter, }; use ethbridge_events::{DynEventCodec, Events as RawEvents}; - use namada::types::address::Address; - use namada::types::ethereum_events::{ + use namada::core::address::Address; + use namada::core::ethereum_events::{ EthAddress, EthereumEvent, TransferToEthereum, TransferToNamada, Uint, }; - use namada::types::ethereum_structs; - use namada::types::hash::Hash; - use namada::types::keccak::KeccakHash; - use namada::types::token::Amount; + use namada::core::ethereum_structs; + use namada::core::hash::Hash; + use namada::core::keccak::KeccakHash; + use namada::core::token::Amount; use num256::Uint256; use thiserror::Error; @@ -176,7 +176,7 @@ pub mod eth_events { impl Parse for ethabi::Uint { fn parse_amount(self) -> Result { let uint = { - use namada::types::uint::Uint as NamadaUint; + use namada::core::uint::Uint as NamadaUint; let mut num_buf = [0; 32]; self.to_little_endian(&mut num_buf); NamadaUint::from_little_endian(&num_buf) diff --git a/crates/apps/src/lib/node/ledger/ethereum_oracle/mod.rs b/crates/apps/src/lib/node/ledger/ethereum_oracle/mod.rs index b0488226f3..777d133769 100644 --- a/crates/apps/src/lib/node/ledger/ethereum_oracle/mod.rs +++ b/crates/apps/src/lib/node/ledger/ethereum_oracle/mod.rs @@ -8,13 +8,12 @@ use async_trait::async_trait; use ethabi::Address; use ethbridge_events::{event_codecs, EventKind}; use itertools::Either; -use namada::core::hints; +use namada::control_flow::time::{Constant, Duration, Instant, Sleep}; +use namada::core::ethereum_events::EthereumEvent; +use namada::core::{ethereum_structs, hints}; use namada::eth_bridge::ethers; use namada::eth_bridge::ethers::providers::{Http, Middleware, Provider}; use namada::eth_bridge::oracle::config::Config; -use namada::types::control_flow::time::{Constant, Duration, Instant, Sleep}; -use namada::types::ethereum_events::EthereumEvent; -use namada::types::ethereum_structs; use namada_sdk::eth_bridge::{eth_syncing_status_timeout, SyncStatus}; use num256::Uint256; use thiserror::Error; @@ -602,7 +601,7 @@ fn process_queue( pub mod last_processed_block { //! Functionality to do with publishing which blocks we have processed. - use namada::types::ethereum_structs; + use namada::core::ethereum_structs; use tokio::sync::watch; pub type Sender = watch::Sender>; @@ -621,11 +620,11 @@ mod test_oracle { use std::num::NonZeroU64; use ethbridge_bridge_events::{TransferToChainFilter, TransferToErcFilter}; + use namada::core::address::testing::gen_established_address; + use namada::core::ethereum_events::{EthAddress, TransferToEthereum}; + use namada::core::hash::Hash; use namada::eth_bridge::ethers::types::H160; use namada::eth_bridge::structs::Erc20Transfer; - use namada::types::address::testing::gen_established_address; - use namada::types::ethereum_events::{EthAddress, TransferToEthereum}; - use namada::types::hash::Hash; use tokio::sync::oneshot::channel; use tokio::time::timeout; diff --git a/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/events_endpoint.rs b/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/events_endpoint.rs index 650a0ad279..2826bc8dbd 100644 --- a/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/events_endpoint.rs +++ b/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/events_endpoint.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use borsh::BorshDeserialize; -use namada::types::ethereum_events::EthereumEvent; +use namada::core::ethereum_events::EthereumEvent; use tokio::sync::mpsc::Sender as BoundedSender; use tokio::sync::oneshot::{Receiver, Sender}; use warp::reply::WithStatus; diff --git a/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/mod.rs b/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/mod.rs index 460e651df5..4d853a9515 100644 --- a/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/mod.rs +++ b/crates/apps/src/lib/node/ledger/ethereum_oracle/test_tools/mod.rs @@ -67,8 +67,8 @@ pub mod mock_web3_client { use async_trait::async_trait; use ethabi::Address; use ethbridge_events::EventCodec; - use namada::types::control_flow::time::{Duration, Instant}; - use namada::types::ethereum_structs::BlockHeight; + use namada::control_flow::time::{Duration, Instant}; + use namada::core::ethereum_structs::BlockHeight; use num256::Uint256; use tokio::sync::mpsc::{ unbounded_channel, UnboundedReceiver, UnboundedSender, diff --git a/crates/apps/src/lib/node/ledger/mod.rs b/crates/apps/src/lib/node/ledger/mod.rs index 8075081c45..5b531aa11a 100644 --- a/crates/apps/src/lib/node/ledger/mod.rs +++ b/crates/apps/src/lib/node/ledger/mod.rs @@ -14,10 +14,10 @@ use std::thread; use byte_unit::Byte; use futures::future::TryFutureExt; +use namada::core::storage::Key; +use namada::core::time::DateTimeUtc; use namada::eth_bridge::ethers::providers::{Http, Provider}; use namada::governance::storage::keys as governance_storage; -use namada::types::storage::Key; -use namada::types::time::DateTimeUtc; use namada_sdk::tendermint::abci::request::CheckTxKind; use once_cell::unsync::Lazy; use sysinfo::{RefreshKind, System, SystemExt}; @@ -753,8 +753,8 @@ pub fn test_genesis_files( genesis: config::genesis::chain::Finalized, wasm_dir: PathBuf, ) { + use namada::core::hash::Sha256Hasher; use namada::state::mockdb::MockDB; - use namada::types::hash::Sha256Hasher; // Channels for validators to send protocol txs to be broadcast to the // broadcaster service diff --git a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs index 885c531557..8fc12578ea 100644 --- a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -3,6 +3,8 @@ use data_encoding::HEXUPPER; use masp_primitives::merkle_tree::CommitmentTree; use masp_primitives::sapling::Node; +use namada::core::key::tm_raw_hash_to_string; +use namada::core::storage::{BlockHash, BlockResults, Epoch, Header}; use namada::governance::pgf::inflation as pgf_inflation; use namada::ledger::events::EventType; use namada::ledger::gas::{GasMetering, TxGasMeter}; @@ -18,8 +20,6 @@ use namada::state::{ ResultExt, StorageRead, StorageWrite, EPOCH_SWITCH_BLOCKS_DELAY, }; use namada::tx::data::protocol::ProtocolTxType; -use namada::types::key::tm_raw_hash_to_string; -use namada::types::storage::{BlockHash, BlockResults, Epoch, Header}; use namada::vote_ext::ethereum_events::MultiSignedEthEvent; use namada::vote_ext::ethereum_tx_data_variants; use namada_sdk::tx::new_tx_event; @@ -742,6 +742,15 @@ mod test_finalize_block { use std::str::FromStr; use data_encoding::HEXUPPER; + use namada::core::dec::{Dec, POS_DECIMAL_PRECISION}; + use namada::core::ethereum_events::{EthAddress, Uint as ethUint}; + use namada::core::hash::Hash; + use namada::core::keccak::KeccakHash; + use namada::core::key::testing::common_sk_from_simple_seed; + use namada::core::key::tm_consensus_key_raw_hash; + use namada::core::storage::{Epoch, KeySeg}; + use namada::core::time::{DateTimeUtc, DurationSecs}; + use namada::core::uint::Uint; use namada::eth_bridge::storage::bridge_pool::{ self, get_key_from_hash, get_nonce_key, get_signed_root_key, }; @@ -773,15 +782,6 @@ mod test_finalize_block { use namada::token::{Amount, DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES}; use namada::tx::data::{Fee, WrapperTx}; use namada::tx::{Code, Data, Section, Signature}; - use namada::types::dec::{Dec, POS_DECIMAL_PRECISION}; - use namada::types::ethereum_events::{EthAddress, Uint as ethUint}; - use namada::types::hash::Hash; - use namada::types::keccak::KeccakHash; - use namada::types::key::testing::common_sk_from_simple_seed; - use namada::types::key::tm_consensus_key_raw_hash; - use namada::types::storage::{Epoch, KeySeg}; - use namada::types::time::{DateTimeUtc, DurationSecs}; - use namada::types::uint::Uint; use namada::vote_ext::{ethereum_events, EthereumTxData}; use namada_sdk::eth_bridge::MinimumConfirmations; use namada_sdk::governance::ProposalVote; @@ -1431,7 +1431,7 @@ mod test_finalize_block { } // write transfer to storage let transfer = { - use namada::types::eth_bridge_pool::{ + use namada::core::eth_bridge_pool::{ GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, }; @@ -5008,7 +5008,7 @@ mod test_finalize_block { // we advance forward to the next epoch let mut req = FinalizeBlock::default(); - req.header.time = namada::types::time::DateTimeUtc::now(); + req.header.time = namada::core::time::DateTimeUtc::now(); let current_decision_height = shell.get_current_decision_height(); if let Some(b) = shell.wl_storage.storage.last_block.as_mut() { b.height = current_decision_height + 11; diff --git a/crates/apps/src/lib/node/ledger/shell/governance.rs b/crates/apps/src/lib/node/ledger/shell/governance.rs index 4865f714f5..36ff6e7cf4 100644 --- a/crates/apps/src/lib/node/ledger/shell/governance.rs +++ b/crates/apps/src/lib/node/ledger/shell/governance.rs @@ -1,6 +1,9 @@ use std::collections::HashMap; +use namada::core::address::Address; +use namada::core::encode; use namada::core::event::EmitEvents; +use namada::core::storage::Epoch; use namada::governance::pgf::storage::keys as pgf_storage; use namada::governance::pgf::storage::steward::StewardDetail; use namada::governance::pgf::{storage as pgf, ADDRESS}; @@ -21,9 +24,6 @@ use namada::proof_of_stake::parameters::PosParams; use namada::proof_of_stake::storage::read_total_stake; use namada::state::{DBIter, StorageHasher, StorageWrite, DB}; use namada::tx::{Code, Data}; -use namada::types::address::Address; -use namada::types::encode; -use namada::types::storage::Epoch; use namada::{ibc, token}; use namada_sdk::proof_of_stake::storage::read_validator_stake; diff --git a/crates/apps/src/lib/node/ledger/shell/init_chain.rs b/crates/apps/src/lib/node/ledger/shell/init_chain.rs index a881171b51..6da33496db 100644 --- a/crates/apps/src/lib/node/ledger/shell/init_chain.rs +++ b/crates/apps/src/lib/node/ledger/shell/init_chain.rs @@ -6,14 +6,14 @@ use masp_primitives::merkle_tree::CommitmentTree; use masp_primitives::sapling::Node; use masp_proofs::bls12_381; use namada::account::protocol_pk_key; +use namada::core::address::Address; +use namada::core::hash::Hash as CodeHash; +use namada::core::time::{DateTimeUtc, TimeZone, Utc}; use namada::ledger::parameters::Parameters; use namada::ledger::{ibc, pos}; use namada::proof_of_stake::BecomeValidator; use namada::state::{DBIter, StorageHasher, StorageWrite, DB}; use namada::token::{credit_tokens, write_denom}; -use namada::types::address::Address; -use namada::types::hash::Hash as CodeHash; -use namada::types::time::{DateTimeUtc, TimeZone, Utc}; use namada::vm::validate_untrusted_wasm; use namada_sdk::eth_bridge::EthBridgeStatus; use namada_sdk::proof_of_stake::PosParams; @@ -153,7 +153,7 @@ where let convert_anchor_key = token::storage_key::masp_convert_anchor_key(); self.wl_storage.write( &convert_anchor_key, - namada::types::hash::Hash( + namada::core::hash::Hash( bls12_381::Scalar::from( self.wl_storage.storage.conversion_state.tree.root(), ) @@ -554,7 +554,7 @@ where genesis: &genesis::chain::Finalized, vp_cache: &mut HashMap>, params: &PosParams, - current_epoch: namada::types::storage::Epoch, + current_epoch: namada::core::storage::Epoch, ) -> ControlFlow<()> { if let Some(txs) = genesis.transactions.validator_account.as_ref() { for FinalizedValidatorAccountTx { @@ -939,8 +939,8 @@ mod test { use std::collections::BTreeMap; use std::str::FromStr; + use namada::core::string_encoding::StringEncoded; use namada::state::DBIter; - use namada::types::string_encoding::StringEncoded; use namada_sdk::wallet::alias::Alias; use super::*; diff --git a/crates/apps/src/lib/node/ledger/shell/mod.rs b/crates/apps/src/lib/node/ledger/shell/mod.rs index cf86242914..977387b280 100644 --- a/crates/apps/src/lib/node/ledger/shell/mod.rs +++ b/crates/apps/src/lib/node/ledger/shell/mod.rs @@ -30,7 +30,13 @@ use std::rc::Rc; use borsh::BorshDeserialize; use borsh_ext::BorshSerializeExt; use masp_primitives::transaction::Transaction; -use namada::core::hints; +use namada::core::address::Address; +use namada::core::chain::ChainId; +use namada::core::ethereum_events::EthereumEvent; +use namada::core::key::*; +use namada::core::storage::{BlockHeight, Key, TxIndex}; +use namada::core::time::DateTimeUtc; +use namada::core::{address, hints}; use namada::ethereum_bridge::protocol::validation::bridge_pool_roots::validate_bp_roots_vext; use namada::ethereum_bridge::protocol::validation::ethereum_events::validate_eth_events_vext; use namada::ethereum_bridge::protocol::validation::validator_set_update::validate_valset_upd_vext; @@ -58,13 +64,6 @@ use namada::token; pub use namada::tx::data::ResultCode; use namada::tx::data::{DecryptedTx, TxType, WrapperTx, WrapperTxErr}; use namada::tx::{Section, Tx}; -use namada::types::address; -use namada::types::address::Address; -use namada::types::chain::ChainId; -use namada::types::ethereum_events::EthereumEvent; -use namada::types::key::*; -use namada::types::storage::{BlockHeight, Key, TxIndex}; -use namada::types::time::DateTimeUtc; use namada::vm::wasm::{TxCache, VpCache}; use namada::vm::{WasmCacheAccess, WasmCacheRwAccess}; use namada::vote_ext::EthereumTxData; @@ -357,7 +356,7 @@ where /// Merkle tree storage key filter. Return `false` for keys that shouldn't be /// merklized. -pub fn is_merklized_storage_key(key: &namada_sdk::types::storage::Key) -> bool { +pub fn is_merklized_storage_key(key: &namada_sdk::storage::Key) -> bool { !token::storage_key::is_masp_key(key) && !namada::ibc::storage::is_ibc_counter_key(key) } @@ -615,8 +614,8 @@ where /// Get the next epoch for which we can request validator set changed pub fn get_validator_set_update_epoch( &self, - current_epoch: namada_sdk::types::storage::Epoch, - ) -> namada_sdk::types::storage::Epoch { + current_epoch: namada_sdk::storage::Epoch, + ) -> namada_sdk::storage::Epoch { if let Some(delay) = self.wl_storage.storage.update_epoch_blocks_delay { if delay == EPOCH_SWITCH_BLOCKS_DELAY { // If we're about to update validator sets for the @@ -1416,6 +1415,14 @@ mod test_utils { use std::path::PathBuf; use data_encoding::HEXUPPER; + use namada::core::address; + use namada::core::chain::ChainId; + use namada::core::ethereum_events::Uint; + use namada::core::hash::Hash; + use namada::core::keccak::KeccakHash; + use namada::core::key::*; + use namada::core::storage::{BlockHash, Epoch, Header}; + use namada::core::time::{DateTimeUtc, DurationSecs}; use namada::ledger::parameters::{EpochDuration, Parameters}; use namada::proof_of_stake::parameters::PosParams; use namada::proof_of_stake::storage::validator_consensus_key_handle; @@ -1427,14 +1434,6 @@ mod test_utils { use namada::token::conversion::update_allowed_conversions; use namada::tx::data::{Fee, TxType, WrapperTx}; use namada::tx::{Code, Data}; - use namada::types::address; - use namada::types::chain::ChainId; - use namada::types::ethereum_events::Uint; - use namada::types::hash::Hash; - use namada::types::keccak::KeccakHash; - use namada::types::key::*; - use namada::types::storage::{BlockHash, Epoch, Header}; - use namada::types::time::{DateTimeUtc, DurationSecs}; use tempfile::tempdir; use tokio::sync::mpsc::{Sender, UnboundedReceiver}; @@ -1530,7 +1529,7 @@ mod test_utils { /// Get the default bridge pool vext bytes to be signed. pub fn get_bp_bytes_to_sign() -> KeccakHash { - use namada::types::keccak::{Hasher, Keccak}; + use namada::core::keccak::{Hasher, Keccak}; let root = [0; 32]; let nonce = Uint::from(0).to_bytes(); @@ -2090,15 +2089,15 @@ mod test_utils { #[cfg(test)] mod shell_tests { + use namada::core::ethereum_events::EthereumEvent; + use namada::core::key::RefTo; + use namada::core::storage::{BlockHeight, Epoch}; use namada::token::read_denom; use namada::tx::data::protocol::{ProtocolTx, ProtocolTxType}; use namada::tx::data::{Fee, WrapperTx}; use namada::tx::{ Code, Data, Section, SignableEthMessage, Signature, Signed, Tx, }; - use namada::types::ethereum_events::EthereumEvent; - use namada::types::key::RefTo; - use namada::types::storage::{BlockHeight, Epoch}; use namada::vote_ext::{ bridge_pool_roots, ethereum_events, ethereum_tx_data_variants, }; @@ -2197,7 +2196,7 @@ mod shell_tests { /// not validated by `CheckTx`. #[test] fn test_outdated_nonce_mempool_validate() { - use namada::types::storage::InnerEthEventsQueue; + use namada::core::storage::InnerEthEventsQueue; const LAST_HEIGHT: BlockHeight = BlockHeight(3); diff --git a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs index 7255789052..9b56878f16 100644 --- a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -1,7 +1,10 @@ //! Implementation of the [`RequestPrepareProposal`] ABCI++ method for the Shell use masp_primitives::transaction::Transaction; +use namada::core::address::Address; use namada::core::hints; +use namada::core::key::tm_raw_hash_to_string; +use namada::core::time::DateTimeUtc; use namada::gas::TxGasMeter; use namada::ledger::protocol; use namada::ledger::storage::tx_queue::TxInQueue; @@ -9,9 +12,6 @@ use namada::proof_of_stake::storage::find_validator_by_raw_hash; use namada::state::{DBIter, StorageHasher, TempWlStorage, DB}; use namada::tx::data::{DecryptedTx, TxType, WrapperTx}; use namada::tx::Tx; -use namada::types::address::Address; -use namada::types::key::tm_raw_hash_to_string; -use namada::types::time::DateTimeUtc; use namada::vm::wasm::{TxCache, VpCache}; use namada::vm::WasmCacheAccess; @@ -431,6 +431,10 @@ mod test_prepare_proposal { use std::collections::BTreeSet; use borsh_ext::BorshSerializeExt; + use namada::core::address::{self, Address}; + use namada::core::ethereum_events::EthereumEvent; + use namada::core::key::RefTo; + use namada::core::storage::{BlockHeight, InnerEthEventsQueue}; use namada::ledger::gas::Gas; use namada::ledger::pos::PosQueries; use namada::proof_of_stake::storage::{ @@ -443,10 +447,6 @@ mod test_prepare_proposal { use namada::token::{read_denom, Amount, DenominatedAmount}; use namada::tx::data::{Fee, TxType, WrapperTx}; use namada::tx::{Code, Data, Header, Section, Signature, Signed}; - use namada::types::address::{self, Address}; - use namada::types::ethereum_events::EthereumEvent; - use namada::types::key::RefTo; - use namada::types::storage::{BlockHeight, InnerEthEventsQueue}; use namada::vote_ext::{ethereum_events, ethereum_tx_data_variants}; use namada::{replay_protection, token}; @@ -1183,7 +1183,7 @@ mod test_prepare_proposal { // Remove the allowed btc *local_config = Some(ValidatorLocalConfig { accepted_gas_tokens: std::collections::HashMap::from([( - namada::types::address::nam(), + namada::core::address::nam(), Amount::from(1), )]), }); @@ -1289,7 +1289,7 @@ mod test_prepare_proposal { // Remove btc and increase minimum for nam *local_config = Some(ValidatorLocalConfig { accepted_gas_tokens: std::collections::HashMap::from([( - namada::types::address::nam(), + namada::core::address::nam(), Amount::from(100), )]), }); diff --git a/crates/apps/src/lib/node/ledger/shell/process_proposal.rs b/crates/apps/src/lib/node/ledger/shell/process_proposal.rs index 7146726382..4f4e3eb132 100644 --- a/crates/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/crates/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -667,16 +667,16 @@ where /// are covered by the e2e tests. #[cfg(test)] mod test_process_proposal { + use namada::core::ethereum_events::EthereumEvent; + use namada::core::key::*; + use namada::core::storage::Epoch; + use namada::core::time::DateTimeUtc; use namada::state::StorageWrite; use namada::token::{read_denom, Amount, DenominatedAmount}; use namada::tx::data::{Fee, WrapperTx}; use namada::tx::{ Code, Data, Section, SignableEthMessage, Signature, Signed, }; - use namada::types::ethereum_events::EthereumEvent; - use namada::types::key::*; - use namada::types::storage::Epoch; - use namada::types::time::DateTimeUtc; use namada::vote_ext::{ bridge_pool_roots, ethereum_events, EthereumTxData, }; @@ -2176,7 +2176,7 @@ mod test_process_proposal { /// not validated by `ProcessProposal`. #[test] fn test_outdated_nonce_process_proposal() { - use namada::types::storage::InnerEthEventsQueue; + use namada::core::storage::InnerEthEventsQueue; const LAST_HEIGHT: BlockHeight = BlockHeight(3); diff --git a/crates/apps/src/lib/node/ledger/shell/queries.rs b/crates/apps/src/lib/node/ledger/shell/queries.rs index 721fd14621..b4cc45b069 100644 --- a/crates/apps/src/lib/node/ledger/shell/queries.rs +++ b/crates/apps/src/lib/node/ledger/shell/queries.rs @@ -1,9 +1,9 @@ //! Shell methods for querying state +use namada::core::address::Address; use namada::ledger::dry_run_tx; use namada::ledger::queries::{RequestCtx, ResponseQuery}; use namada::token; -use namada::types::address::Address; use super::*; use crate::node::ledger::response; @@ -66,12 +66,12 @@ where // access to the `Shell` there #[cfg(test)] mod test_queries { + use namada::core::storage::{BlockHash, Epoch}; use namada::ledger::pos::PosQueries; use namada::proof_of_stake::storage::read_consensus_validator_set_addresses_with_stake; use namada::proof_of_stake::types::WeightedValidator; use namada::state::EPOCH_SWITCH_BLOCKS_DELAY; use namada::tendermint::abci::types::VoteInfo; - use namada::types::storage::{BlockHash, Epoch}; use namada_sdk::eth_bridge::{EthBridgeQueries, SendValsetUpd}; use super::*; diff --git a/crates/apps/src/lib/node/ledger/shell/testing/client.rs b/crates/apps/src/lib/node/ledger/shell/testing/client.rs index 6f34737f22..310a4ce860 100644 --- a/crates/apps/src/lib/node/ledger/shell/testing/client.rs +++ b/crates/apps/src/lib/node/ledger/shell/testing/client.rs @@ -1,6 +1,6 @@ use clap::Command as App; use eyre::Report; -use namada::types::io::Io; +use namada::io::Io; use namada_sdk::error::Error as SdkError; use tendermint_config::net::Address as TendermintAddress; diff --git a/crates/apps/src/lib/node/ledger/shell/testing/node.rs b/crates/apps/src/lib/node/ledger/shell/testing/node.rs index a3ab32dcb6..18f61463e1 100644 --- a/crates/apps/src/lib/node/ledger/shell/testing/node.rs +++ b/crates/apps/src/lib/node/ledger/shell/testing/node.rs @@ -10,6 +10,13 @@ use color_eyre::eyre::{Report, Result}; use data_encoding::HEXUPPER; use itertools::Either; use lazy_static::lazy_static; +use namada::control_flow::time::Duration; +use namada::core::ethereum_events::EthereumEvent; +use namada::core::ethereum_structs; +use namada::core::hash::Hash; +use namada::core::key::tm_consensus_key_raw_hash; +use namada::core::storage::{BlockHash, BlockHeight, Epoch, Header}; +use namada::core::time::DateTimeUtc; use namada::eth_bridge::oracle::config::Config as OracleConfig; use namada::ledger::dry_run_tx; use namada::ledger::events::log::dumb_queries; @@ -26,13 +33,6 @@ use namada::state::{LastBlock, Sha256Hasher, EPOCH_SWITCH_BLOCKS_DELAY}; use namada::tendermint::abci::response::Info; use namada::tendermint::abci::types::VoteInfo; use namada::tendermint_rpc::SimpleRequest; -use namada::types::control_flow::time::Duration; -use namada::types::ethereum_events::EthereumEvent; -use namada::types::ethereum_structs; -use namada::types::hash::Hash; -use namada::types::key::tm_consensus_key_raw_hash; -use namada::types::storage::{BlockHash, BlockHeight, Epoch, Header}; -use namada::types::time::DateTimeUtc; use namada_sdk::queries::Client; use namada_sdk::tendermint_proto::google::protobuf::Timestamp; use namada_sdk::tx::data::ResultCode; diff --git a/crates/apps/src/lib/node/ledger/shell/testing/utils.rs b/crates/apps/src/lib/node/ledger/shell/testing/utils.rs index 451e20c2df..c742559b84 100644 --- a/crates/apps/src/lib/node/ledger/shell/testing/utils.rs +++ b/crates/apps/src/lib/node/ledger/shell/testing/utils.rs @@ -4,7 +4,7 @@ use std::pin::Pin; use std::task::{Context, Poll}; use lazy_static::lazy_static; -use namada::types::io::{prompt_aux, read_aux, Io}; +use namada::io::{prompt_aux, read_aux, Io}; use tempfile::tempdir; use tokio::io::{AsyncRead, ReadBuf}; diff --git a/crates/apps/src/lib/node/ledger/shell/utils.rs b/crates/apps/src/lib/node/ledger/shell/utils.rs index 3a9142cdb8..e34009956d 100644 --- a/crates/apps/src/lib/node/ledger/shell/utils.rs +++ b/crates/apps/src/lib/node/ledger/shell/utils.rs @@ -1,6 +1,6 @@ use borsh::BorshDeserialize; +use namada::core::storage::Key; use namada::state::{self, StorageRead}; -use namada::types::storage::Key; pub(super) fn force_read( storage: &S, diff --git a/crates/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs b/crates/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs index f6f9f10308..6e2b6db25a 100644 --- a/crates/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs +++ b/crates/apps/src/lib/node/ledger/shell/vote_extensions/bridge_pool_vext.rs @@ -56,6 +56,11 @@ where #[cfg(test)] mod test_bp_vote_extensions { + use namada::core::ethereum_events::Uint; + use namada::core::keccak::{keccak_hash, KeccakHash}; + use namada::core::key::*; + use namada::core::storage::BlockHeight; + use namada::core::token; use namada::ethereum_bridge::protocol::validation::bridge_pool_roots::validate_bp_roots_vext; use namada::ethereum_bridge::storage::bridge_pool::get_key_from_hash; use namada::ethereum_bridge::storage::eth_bridge_queries::EthBridgeQueries; @@ -71,11 +76,6 @@ mod test_bp_vote_extensions { use namada::state::StorageWrite; use namada::tendermint::abci::types::VoteInfo; use namada::tx::{SignableEthMessage, Signed}; - use namada::types::ethereum_events::Uint; - use namada::types::keccak::{keccak_hash, KeccakHash}; - use namada::types::key::*; - use namada::types::storage::BlockHeight; - use namada::types::token; use namada::vote_ext::bridge_pool_roots; use crate::node::ledger::shell::test_utils::*; diff --git a/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs b/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs index 8ef538bbcb..3954404203 100644 --- a/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs +++ b/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs @@ -2,9 +2,9 @@ use std::collections::{BTreeMap, HashMap}; +use namada::core::ethereum_events::EthereumEvent; use namada::state::{DBIter, StorageHasher, DB}; use namada::tx::Signed; -use namada::types::ethereum_events::EthereumEvent; use namada::vote_ext::ethereum_events::{self, MultiSignedEthEvent}; use namada_sdk::eth_bridge::EthBridgeQueries; @@ -143,6 +143,13 @@ mod test_vote_extensions { use std::convert::TryInto; use borsh_ext::BorshSerializeExt; + use namada::core::address::testing::gen_established_address; + use namada::core::ethereum_events::{ + EthAddress, EthereumEvent, TransferToEthereum, Uint, + }; + use namada::core::hash::Hash; + use namada::core::key::*; + use namada::core::storage::{Epoch, InnerEthEventsQueue}; use namada::eth_bridge::storage::bridge_pool; use namada::ledger::eth_bridge::EthBridgeQueries; use namada::ledger::pos::PosQueries; @@ -153,13 +160,6 @@ mod test_vote_extensions { use namada::proof_of_stake::types::WeightedValidator; use namada::state::collections::lazy_map::{NestedSubKey, SubKey}; use namada::tendermint::abci::types::VoteInfo; - use namada::types::address::testing::gen_established_address; - use namada::types::ethereum_events::{ - EthAddress, EthereumEvent, TransferToEthereum, Uint, - }; - use namada::types::hash::Hash; - use namada::types::key::*; - use namada::types::storage::{Epoch, InnerEthEventsQueue}; use namada::vote_ext::ethereum_events; use super::validate_eth_events_vext; diff --git a/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs b/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs index 67eb2a0a88..5f76445c7a 100644 --- a/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs +++ b/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs @@ -113,6 +113,7 @@ where #[cfg(test)] mod test_vote_extensions { + use namada::core::key::RefTo; use namada::ledger::pos::PosQueries; use namada::proof_of_stake::storage::{ consensus_validator_set_handle, @@ -122,7 +123,6 @@ mod test_vote_extensions { use namada::proof_of_stake::Epoch; use namada::state::collections::lazy_map::{NestedSubKey, SubKey}; use namada::tendermint::abci::types::VoteInfo; - use namada::types::key::RefTo; use namada::vote_ext::validator_set_update; use namada_sdk::eth_bridge::EthBridgeQueries; diff --git a/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs b/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs index 1b8b7343fd..b86073834c 100644 --- a/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs +++ b/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs @@ -5,14 +5,13 @@ use std::pin::Pin; use std::task::{Context, Poll}; use futures::future::FutureExt; +use namada::core::hash::Hash; +use namada::core::key::tm_raw_hash_to_string; +use namada::core::storage::{BlockHash, BlockHeight}; use namada::proof_of_stake::storage::find_validator_by_raw_hash; +use namada::time::{DateTimeUtc, Utc}; use namada::tx::data::hash_tx; use namada::tx::Tx; -use namada::types::hash::Hash; -use namada::types::key::tm_raw_hash_to_string; -use namada::types::storage::{BlockHash, BlockHeight}; -use namada::types::time::Utc; -use namada_sdk::types::time::DateTimeUtc; use tokio::sync::broadcast; use tokio::sync::mpsc::UnboundedSender; use tower::Service; diff --git a/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs b/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs index 5b0a553f55..81151f45ef 100644 --- a/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs +++ b/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs @@ -153,9 +153,9 @@ pub mod shim { pub mod request { use std::convert::TryFrom; - use namada::types::hash::Hash; - use namada::types::storage::{BlockHash, Header}; - use namada::types::time::DateTimeUtc; + use namada::core::hash::Hash; + use namada::core::storage::{BlockHash, Header}; + use namada::core::time::DateTimeUtc; use super::VoteInfo; use crate::facade::tendermint::abci::types::Misbehavior; diff --git a/crates/apps/src/lib/node/ledger/storage/mod.rs b/crates/apps/src/lib/node/ledger/storage/mod.rs index 385405fed1..8f9aef8476 100644 --- a/crates/apps/src/lib/node/ledger/storage/mod.rs +++ b/crates/apps/src/lib/node/ledger/storage/mod.rs @@ -54,6 +54,13 @@ mod tests { use borsh::BorshDeserialize; use itertools::Itertools; + use namada::core::chain::ChainId; + use namada::core::ethereum_events::Uint; + use namada::core::hash::Hash; + use namada::core::keccak::KeccakHash; + use namada::core::storage::{BlockHash, BlockHeight, Key}; + use namada::core::time::DurationSecs; + use namada::core::{address, storage}; use namada::eth_bridge::storage::proof::BridgePoolRootProof; use namada::ledger::eth_bridge::storage::bridge_pool; use namada::ledger::gas::STORAGE_ACCESS_GAS_PER_BYTE; @@ -64,14 +71,7 @@ mod tests { self, StorageRead, StorageWrite, StoreType, WlStorage, DB, }; use namada::token::conversion::update_allowed_conversions; - use namada::types::chain::ChainId; - use namada::types::ethereum_events::Uint; - use namada::types::hash::Hash; - use namada::types::keccak::KeccakHash; - use namada::types::storage::{BlockHash, BlockHeight, Key}; - use namada::types::time::DurationSecs; - use namada::types::{address, storage}; - use namada::{parameters, types}; + use namada::{decode, encode, parameters}; use proptest::collection::vec; use proptest::prelude::*; use proptest::test_runner::Config; @@ -94,7 +94,7 @@ mod tests { ); let key = Key::parse("key").expect("cannot parse the key string"); let value: u64 = 1; - let value_bytes = types::encode(&value); + let value_bytes = encode(&value); let value_bytes_len = value_bytes.len(); // before insertion @@ -113,9 +113,8 @@ mod tests { assert!(result); assert_eq!(gas, key.len() as u64 * STORAGE_ACCESS_GAS_PER_BYTE); let (result, gas) = storage.read(&key).expect("read failed"); - let read_value: u64 = - types::decode(result.expect("value doesn't exist")) - .expect("decoding failed"); + let read_value: u64 = decode(result.expect("value doesn't exist")) + .expect("decoding failed"); assert_eq!(read_value, value); assert_eq!( gas, @@ -150,7 +149,7 @@ mod tests { .expect("begin_block failed"); let key = Key::parse("key").expect("cannot parse the key string"); let value: u64 = 1; - let value_bytes = types::encode(&value); + let value_bytes = encode(&value); let mut wl_storage = WlStorage::new(WriteLog::default(), storage); // initialize parameter storage let params = Parameters { @@ -242,7 +241,7 @@ mod tests { let key = prefix .push(&format!("{}", i)) .expect("cannot push the key segment"); - let value_bytes = types::encode(&(i as u64)); + let value_bytes = encode(&(i as u64)); // insert storage .write(&key, value_bytes.clone()) @@ -373,7 +372,7 @@ mod tests { ); if write_value { - let value_bytes = types::encode(&storage.block.height); + let value_bytes = encode(&storage.block.height); storage.write(&key, value_bytes)?; } else { storage.delete(&key)?; @@ -391,11 +390,10 @@ mod tests { let value_bytes = value_bytes.unwrap_or_else(|| { panic!("Couldn't read from height {height}") }); - let value: BlockHeight = types::decode(value_bytes).unwrap(); + let value: BlockHeight = decode(value_bytes).unwrap(); assert_eq!(value, height); } else if value_bytes.is_some() { - let value: BlockHeight = - types::decode(value_bytes.unwrap()).unwrap(); + let value: BlockHeight = decode(value_bytes.unwrap()).unwrap(); panic!("Expected no value at height {height}, got {}", value,); } } @@ -415,11 +413,10 @@ mod tests { if is_last_write { let value_bytes = value_bytes.expect("Should have been written"); - let value: BlockHeight = types::decode(value_bytes).unwrap(); + let value: BlockHeight = decode(value_bytes).unwrap(); assert_eq!(value, storage.get_last_block_height()); } else if value_bytes.is_some() { - let value: BlockHeight = - types::decode(value_bytes.unwrap()).unwrap(); + let value: BlockHeight = decode(value_bytes.unwrap()).unwrap(); panic!("Expected no value at height {height}, got {}", value,); } } @@ -458,13 +455,13 @@ mod tests { // write values at Height 0 like init_storage for i in 0..num_keys { let key = ibc_key(format!("key{}", i)).unwrap(); - let value_bytes = types::encode(&storage.block.height); + let value_bytes = encode(&storage.block.height); storage.write(&key, value_bytes)?; } let key = bridge_pool::get_signed_root_key(); let root_proof = BridgePoolRootProof::new((KeccakHash::default(), Uint::default())); - let bytes = types::encode(&root_proof); + let bytes = encode(&root_proof); storage.write(&key, bytes)?; // Update and commit @@ -497,14 +494,14 @@ mod tests { storage.delete(&key)?; } 2 => { - let value_bytes = types::encode(&storage.block.height); + let value_bytes = encode(&storage.block.height); storage.write(&key, value_bytes)?; } 3 => { storage.batch_delete_subspace_val(&mut batch, &key)?; } _ => { - let value_bytes = types::encode(&storage.block.height); + let value_bytes = encode(&storage.block.height); storage.batch_write_subspace_val( &mut batch, &key, @@ -571,9 +568,7 @@ mod tests { let key = ibc_key("key").unwrap(); let value: u64 = 1; - storage - .write(&key, types::encode(&value)) - .expect("write failed"); + storage.write(&key, encode(&value)).expect("write failed"); storage.block.pred_epochs.new_epoch(new_epoch_start); let batch = PersistentStorage::batch(); @@ -586,9 +581,7 @@ mod tests { let key = ibc_key("key2").unwrap(); let value: u64 = 2; - storage - .write(&key, types::encode(&value)) - .expect("write failed"); + storage.write(&key, encode(&value)).expect("write failed"); // the second nonce isn't written for a test skipping pruning let nonce = nonce + 1; @@ -609,7 +602,7 @@ mod tests { let nonce = nonce + 1; let root_proof = BridgePoolRootProof::new((KeccakHash::default(), nonce)); - let bytes = types::encode(&root_proof); + let bytes = encode(&root_proof); storage.write(&signed_root_key, bytes).unwrap(); storage.block.epoch = storage.block.epoch.next(); @@ -637,7 +630,7 @@ mod tests { let nonce = nonce + 1; let root_proof = BridgePoolRootProof::new((KeccakHash::default(), nonce)); - let bytes = types::encode(&root_proof); + let bytes = encode(&root_proof); storage.write(&signed_root_key, bytes).unwrap(); storage.block.epoch = storage.block.epoch.next(); storage.block.pred_epochs.new_epoch(BlockHeight(12)); diff --git a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs index 97bbb37b3c..dca0c44cad 100644 --- a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs +++ b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs @@ -48,9 +48,16 @@ use borsh::BorshDeserialize; use borsh_ext::BorshSerializeExt; use data_encoding::HEXLOWER; use itertools::Either; +use namada::core::storage::{ + BlockHeight, BlockResults, Epoch, EthEventsQueue, Header, Key, KeySeg, + KEY_SEGMENT_SEPARATOR, +}; +use namada::core::time::DateTimeUtc; +use namada::core::{decode, encode, ethereum_events, ethereum_structs}; use namada::eth_bridge::storage::proof::BridgePoolRootProof; use namada::ledger::eth_bridge::storage::bridge_pool; use namada::ledger::storage::tx_queue::TxQueue; +use namada::replay_protection; use namada::state::merkle_tree::{base_tree_key_prefix, subtree_key_prefix}; use namada::state::types::PrefixIterator; use namada::state::{ @@ -58,13 +65,6 @@ use namada::state::{ DbResult as Result, MerkleTreeStoresRead, StoreType, DB, }; use namada::token::ConversionState; -use namada::types::storage::{ - BlockHeight, BlockResults, Epoch, EthEventsQueue, Header, Key, KeySeg, - KEY_SEGMENT_SEPARATOR, -}; -use namada::types::time::DateTimeUtc; -use namada::types::{ethereum_events, ethereum_structs}; -use namada::{replay_protection, types}; use rayon::prelude::*; use rocksdb::{ BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, DBCompactionStyle, @@ -338,7 +338,7 @@ impl RocksDB { .get_column_family(STATE_CF) .expect("State column family should exist"); - let last_height: BlockHeight = types::decode( + let last_height: BlockHeight = decode( self.0 .get_cf(state_cf, "height") .expect("Unable to read DB") @@ -512,7 +512,7 @@ impl RocksDB { // three keys in storage we can only perform one rollback before // restarting the chain tracing::info!("Reverting non-height-prepended metadata keys"); - batch.put_cf(state_cf, "height", types::encode(&previous_height)); + batch.put_cf(state_cf, "height", encode(&previous_height)); for metadata_key in [ "next_epoch_min_start_height", "next_epoch_min_start_time", @@ -664,7 +664,7 @@ impl DB for RocksDB { Some(bytes) => { // TODO if there's an issue decoding this height, should we try // load its predecessor instead? - types::decode(bytes).map_err(Error::CodingError)? + decode(bytes).map_err(Error::CodingError)? } None => return Ok(None), }; @@ -677,7 +677,7 @@ impl DB for RocksDB { .get_cf(block_cf, results_path) .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; @@ -687,7 +687,7 @@ impl DB for RocksDB { .get_cf(state_cf, "next_epoch_min_start_height") .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => { tracing::error!( "Couldn't load next epoch start height from the DB" @@ -700,7 +700,7 @@ impl DB for RocksDB { .get_cf(state_cf, "next_epoch_min_start_time") .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => { tracing::error!( "Couldn't load next epoch start time from the DB" @@ -713,7 +713,7 @@ impl DB for RocksDB { .get_cf(state_cf, "update_epoch_blocks_delay") .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => { tracing::error!( "Couldn't load epoch update block delay from the DB" @@ -726,7 +726,7 @@ impl DB for RocksDB { .get_cf(state_cf, "conversion_state") .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => { tracing::error!("Couldn't load conversion state from the DB"); return Ok(None); @@ -737,7 +737,7 @@ impl DB for RocksDB { .get_cf(state_cf, "tx_queue") .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => { tracing::error!("Couldn't load tx queue from the DB"); return Ok(None); @@ -749,7 +749,7 @@ impl DB for RocksDB { .get_cf(state_cf, "ethereum_height") .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => { tracing::error!("Couldn't load ethereum height from the DB"); return Ok(None); @@ -761,7 +761,7 @@ impl DB for RocksDB { .get_cf(state_cf, "eth_events_queue") .map_err(|e| Error::DBError(e.into_string()))? { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => { tracing::error!( "Couldn't load the eth events queue from the DB" @@ -810,7 +810,7 @@ impl DB for RocksDB { match segments.get(3) { Some(&"root") => merkle_tree_stores.set_root( &st, - types::decode(bytes) + decode(bytes) .map_err(Error::CodingError)?, ), Some(&"store") => merkle_tree_stores @@ -824,29 +824,21 @@ impl DB for RocksDB { // the block header doesn't have to be restored } "hash" => { - hash = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + hash = Some(decode(bytes).map_err(Error::CodingError)?) } "time" => { - time = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + time = Some(decode(bytes).map_err(Error::CodingError)?) } "epoch" => { - epoch = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + epoch = Some(decode(bytes).map_err(Error::CodingError)?) } "pred_epochs" => { - pred_epochs = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + pred_epochs = + Some(decode(bytes).map_err(Error::CodingError)?) } "address_gen" => { - address_gen = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ); + address_gen = + Some(decode(bytes).map_err(Error::CodingError)?); } _ => unknown_key_error(path)?, }, @@ -866,7 +858,7 @@ impl DB for RocksDB { { merkle_tree_stores.set_root( st, - types::decode(bytes).map_err(Error::CodingError)?, + decode(bytes).map_err(Error::CodingError)?, ); } let store_key = key_prefix.with_segment("store".to_owned()); @@ -952,7 +944,7 @@ impl DB for RocksDB { batch.0.put_cf( state_cf, "next_epoch_min_start_height", - types::encode(&next_epoch_min_start_height), + encode(&next_epoch_min_start_height), ); if let Some(current_value) = self @@ -970,7 +962,7 @@ impl DB for RocksDB { batch.0.put_cf( state_cf, "next_epoch_min_start_time", - types::encode(&next_epoch_min_start_time), + encode(&next_epoch_min_start_time), ); if let Some(current_value) = self .0 @@ -987,7 +979,7 @@ impl DB for RocksDB { batch.0.put_cf( state_cf, "update_epoch_blocks_delay", - types::encode(&update_epoch_blocks_delay), + encode(&update_epoch_blocks_delay), ); // Save the conversion state when the epoch is updated @@ -1007,7 +999,7 @@ impl DB for RocksDB { batch.0.put_cf( state_cf, "conversion_state", - types::encode(conversion_state), + encode(conversion_state), ); } @@ -1020,19 +1012,13 @@ impl DB for RocksDB { // Write the predecessor value for rollback batch.0.put_cf(state_cf, "pred/tx_queue", pred_tx_queue); } + batch.0.put_cf(state_cf, "tx_queue", encode(&tx_queue)); batch .0 - .put_cf(state_cf, "tx_queue", types::encode(&tx_queue)); - batch.0.put_cf( - state_cf, - "ethereum_height", - types::encode(ðereum_height), - ); - batch.0.put_cf( - state_cf, - "eth_events_queue", - types::encode(ð_events_queue), - ); + .put_cf(state_cf, "ethereum_height", encode(ðereum_height)); + batch + .0 + .put_cf(state_cf, "eth_events_queue", encode(ð_events_queue)); let block_cf = self.get_column_family(BLOCK_CF)?; let prefix_key = Key::from(height.to_db_key()); @@ -1050,7 +1036,7 @@ impl DB for RocksDB { batch.0.put_cf( block_cf, root_key.to_string(), - types::encode(merkle_tree_stores.root(st)), + encode(merkle_tree_stores.root(st)), ); let store_key = key_prefix.with_segment("store".to_owned()); batch.0.put_cf( @@ -1077,60 +1063,48 @@ impl DB for RocksDB { let key = prefix_key .push(&"hash".to_owned()) .map_err(Error::KeyError)?; - batch - .0 - .put_cf(block_cf, key.to_string(), types::encode(&hash)); + batch.0.put_cf(block_cf, key.to_string(), encode(&hash)); } // Block time { let key = prefix_key .push(&"time".to_owned()) .map_err(Error::KeyError)?; - batch - .0 - .put_cf(block_cf, key.to_string(), types::encode(&time)); + batch.0.put_cf(block_cf, key.to_string(), encode(&time)); } // Block epoch { let key = prefix_key .push(&"epoch".to_owned()) .map_err(Error::KeyError)?; - batch - .0 - .put_cf(block_cf, key.to_string(), types::encode(&epoch)); + batch.0.put_cf(block_cf, key.to_string(), encode(&epoch)); } // Block results { let results_path = format!("results/{}", height.raw()); - batch - .0 - .put_cf(block_cf, results_path, types::encode(&results)); + batch.0.put_cf(block_cf, results_path, encode(&results)); } // Predecessor block epochs { let key = prefix_key .push(&"pred_epochs".to_owned()) .map_err(Error::KeyError)?; - batch.0.put_cf( - block_cf, - key.to_string(), - types::encode(&pred_epochs), - ); + batch + .0 + .put_cf(block_cf, key.to_string(), encode(&pred_epochs)); } // Address gen { let key = prefix_key .push(&"address_gen".to_owned()) .map_err(Error::KeyError)?; - batch.0.put_cf( - block_cf, - key.to_string(), - types::encode(&address_gen), - ); + batch + .0 + .put_cf(block_cf, key.to_string(), encode(&address_gen)); } // Block height - batch.0.put_cf(state_cf, "height", types::encode(&height)); + batch.0.put_cf(state_cf, "height", encode(&height)); Ok(()) } @@ -1180,7 +1154,7 @@ impl DB for RocksDB { .map_err(|e| Error::DBError(e.into_string()))?; match bytes { Some(b) => { - let root = types::decode(b).map_err(Error::CodingError)?; + let root = decode(b).map_err(Error::CodingError)?; merkle_tree_stores.set_root(st, root); } None => return Ok(None), @@ -1203,7 +1177,7 @@ impl DB for RocksDB { fn has_replay_protection_entry( &self, - hash: &namada::types::hash::Hash, + hash: &namada::core::hash::Hash, ) -> Result { let replay_protection_cf = self.get_column_family(REPLAY_PROTECTION_CF)?; @@ -1813,11 +1787,11 @@ mod imp { #[cfg(test)] mod test { - use namada::state::{MerkleTree, Sha256Hasher}; - use namada::types::address::{ + use namada::core::address::{ gen_established_address, EstablishedAddressGen, }; - use namada::types::storage::{BlockHash, Epoch, Epochs}; + use namada::core::storage::{BlockHash, Epoch, Epochs}; + use namada::state::{MerkleTree, Sha256Hasher}; use tempfile::tempdir; use test_log::test; @@ -2120,7 +2094,7 @@ mod test { db.0.get_cf(state_cf, "conversion_state".as_bytes()) .unwrap() .unwrap(); - assert_eq!(conversion_state, types::encode(&conversion_state_0)); + assert_eq!(conversion_state, encode(&conversion_state_0)); } #[test] diff --git a/crates/apps/src/lib/node/ledger/tendermint_node.rs b/crates/apps/src/lib/node/ledger/tendermint_node.rs index 87616d9df2..5f58df7c2f 100644 --- a/crates/apps/src/lib/node/ledger/tendermint_node.rs +++ b/crates/apps/src/lib/node/ledger/tendermint_node.rs @@ -4,10 +4,10 @@ use std::process::Stdio; use std::str::FromStr; use borsh_ext::BorshSerializeExt; -use namada::types::chain::ChainId; -use namada::types::key::*; -use namada::types::storage::BlockHeight; -use namada::types::time::DateTimeUtc; +use namada::core::chain::ChainId; +use namada::core::key::*; +use namada::core::storage::BlockHeight; +use namada::core::time::DateTimeUtc; use serde_json::json; use sha2::{Digest, Sha256}; use thiserror::Error; diff --git a/crates/apps/src/lib/wallet/defaults.rs b/crates/apps/src/lib/wallet/defaults.rs index 6b53ee5545..3b06bdfb13 100644 --- a/crates/apps/src/lib/wallet/defaults.rs +++ b/crates/apps/src/lib/wallet/defaults.rs @@ -13,11 +13,11 @@ mod dev { use std::collections::HashMap; use lazy_static::lazy_static; - use namada::ledger::{governance, pgf, pos}; - use namada::types::address::{ + use namada::core::address::{ apfel, btc, dot, eth, kartoffel, nam, schnitzel, Address, }; - use namada::types::key::*; + use namada::core::key::*; + use namada::ledger::{governance, pgf, pos}; use namada_sdk::wallet::alias::Alias; use namada_sdk::wallet::pre_genesis::ValidatorWallet; use namada_sdk::wallet::Wallet; @@ -78,7 +78,7 @@ mod dev { ("christel".into(), christel_address()), ("daewon".into(), daewon_address()), ("ester".into(), ester_address()), - ("masp".into(), namada::types::address::MASP), + ("masp".into(), namada::core::address::MASP), ] .into_iter() .collect(); diff --git a/crates/apps/src/lib/wallet/mod.rs b/crates/apps/src/lib/wallet/mod.rs index 3ed2969742..d157afdf83 100644 --- a/crates/apps/src/lib/wallet/mod.rs +++ b/crates/apps/src/lib/wallet/mod.rs @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf}; use std::{env, fs}; use namada::bip39::{Language, Mnemonic}; -use namada::types::key::*; +use namada::core::key::*; pub use namada_sdk::wallet::alias::Alias; use namada_sdk::wallet::fs::FsWalletStorage; use namada_sdk::wallet::store::Store; diff --git a/crates/apps/src/lib/wallet/pre_genesis.rs b/crates/apps/src/lib/wallet/pre_genesis.rs index 12f88ed99a..a39a8358f6 100644 --- a/crates/apps/src/lib/wallet/pre_genesis.rs +++ b/crates/apps/src/lib/wallet/pre_genesis.rs @@ -3,7 +3,7 @@ use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use fd_lock::RwLock; -use namada::types::key::SchemeType; +use namada::core::key::SchemeType; use namada_sdk::wallet::pre_genesis::{ ReadError, ValidatorStore, ValidatorWallet, }; diff --git a/crates/apps/src/lib/wallet/store.rs b/crates/apps/src/lib/wallet/store.rs index c721b02d9c..20021765a5 100644 --- a/crates/apps/src/lib/wallet/store.rs +++ b/crates/apps/src/lib/wallet/store.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use namada::types::key::*; +use namada::core::key::*; use namada_sdk::wallet::{ gen_secret_key, LoadStoreError, Store, ValidatorKeys, }; @@ -59,7 +59,7 @@ pub fn gen_validator_keys( #[cfg(test)] mod test_wallet { - use namada::types::address::Address; + use namada::core::address::Address; use super::*; diff --git a/crates/benches/README.md b/crates/benches/README.md index 9f73d2c15b..62980150ac 100644 --- a/crates/benches/README.md +++ b/crates/benches/README.md @@ -6,7 +6,7 @@ Measurements are taken on the elapsed wall-time. The benchmarks only focus on successful transactions and vps: in case of failure, the bench function shall panic to avoid timing incomplete execution paths. -In addition, this crate also contains benchmarks for `WrapperTx` (`namada::core::types::transaction::wrapper::WrapperTx`) validation and `host_env` (`namada::vm::host_env`) exposed functions that define the gas constants of `gas` (`namada::core::ledger::gas`). +In addition, this crate also contains benchmarks for `WrapperTx` (`namada::core::transaction::wrapper::WrapperTx`) validation and `host_env` (`namada::vm::host_env`) exposed functions that define the gas constants of `gas` (`namada::core::ledger::gas`). For more realistic results these benchmarks should be run on all the combination of supported OS/architecture. diff --git a/crates/benches/host_env.rs b/crates/benches/host_env.rs index 36a79cea05..a659e7aa51 100644 --- a/crates/benches/host_env.rs +++ b/crates/benches/host_env.rs @@ -1,8 +1,8 @@ use std::collections::{HashMap, HashSet}; use criterion::{criterion_group, criterion_main, Criterion}; -use namada::core::types::account::AccountPublicKeysMap; -use namada::core::types::address; +use namada::core::account::AccountPublicKeysMap; +use namada::core::address; use namada::ledger::storage::DB; use namada::token::{Amount, Transfer}; use namada::tx::Signature; @@ -183,7 +183,7 @@ fn write_log_read(c: &mut Criterion) { let mut shell = BenchShell::default(); for (key, value_len) in generate_random_keys_sized() { - let key = namada::core::types::storage::Key::parse(key).unwrap(); + let key = namada::core::storage::Key::parse(key).unwrap(); // Extract the throughput, together with the wall-time, so that we can // than invert it to calculate the desired metric (time/byte) // NOTE: criterion states that the throughput is measured on the @@ -214,7 +214,7 @@ fn storage_read(c: &mut Criterion) { let mut shell = BenchShell::default(); for (key, value_len) in generate_random_keys_sized() { - let key = namada::core::types::storage::Key::parse(key).unwrap(); + let key = namada::core::storage::Key::parse(key).unwrap(); // Extract the throughput, together with the wall-time, so that we can // than invert it to calculate the desired metric (time/byte) // NOTE: criterion states that the throughput is measured on the @@ -254,7 +254,7 @@ fn write_log_write(c: &mut Criterion) { let mut shell = BenchShell::default(); for (key, value_len) in generate_random_keys_sized() { - let key = namada::core::types::storage::Key::parse(key).unwrap(); + let key = namada::core::storage::Key::parse(key).unwrap(); // Extract the throughput, together with the wall-time, so that we can // than invert it to calculate the desired metric (time/byte) // NOTE: criterion states that the throughput is measured on the @@ -289,7 +289,7 @@ fn storage_write(c: &mut Criterion) { let mut shell = BenchShell::default(); for (key, value_len) in generate_random_keys_sized() { - let key = namada::core::types::storage::Key::parse(key).unwrap(); + let key = namada::core::storage::Key::parse(key).unwrap(); // Extract the throughput, together with the wall-time, so that we can // than invert it to calculate the desired metric (time/byte) // NOTE: criterion states that the throughput is measured on the diff --git a/crates/benches/native_vps.rs b/crates/benches/native_vps.rs index 5f0524699b..e4d94d764f 100644 --- a/crates/benches/native_vps.rs +++ b/crates/benches/native_vps.rs @@ -5,7 +5,9 @@ use std::str::FromStr; use criterion::{criterion_group, criterion_main, Criterion}; use masp_primitives::sapling::Node; -use namada::core::types::address::{self, Address}; +use namada::core::address::{self, Address, InternalAddress}; +use namada::core::eth_bridge_pool::{GasFee, PendingTransfer}; +use namada::core::masp::{TransferSource, TransferTarget}; use namada::eth_bridge::storage::whitelist; use namada::governance::pgf::storage::steward::StewardDetail; use namada::governance::storage::proposal::ProposalType; @@ -44,9 +46,6 @@ use namada::sdk::masp_primitives::transaction::Transaction; use namada::state::{Epoch, StorageRead, StorageWrite, TxIndex}; use namada::token::{Amount, Transfer}; use namada::tx::{Code, Section, Tx}; -use namada::types::address::InternalAddress; -use namada::types::eth_bridge_pool::{GasFee, PendingTransfer}; -use namada::types::masp::{TransferSource, TransferTarget}; use namada_apps::bench_utils::{ generate_foreign_key_tx, BenchShell, BenchShieldedCtx, ALBERT_PAYMENT_ADDRESS, ALBERT_SPENDING_KEY, BERTHA_PAYMENT_ADDRESS, @@ -353,7 +352,7 @@ fn ibc(c: &mut Criterion) { match bench_name { "open_connection" => { let _ = shell.init_ibc_client_state( - namada::core::types::storage::Key::from( + namada::core::storage::Key::from( Address::Internal(InternalAddress::Ibc).to_db_key(), ), ); @@ -648,7 +647,7 @@ fn pgf(c: &mut Criterion) { steward: defaults::albert_address(), commission: HashMap::from([( defaults::albert_address(), - namada::types::dec::Dec::zero(), + namada::core::dec::Dec::zero(), )]), }; shell.generate_tx( @@ -709,20 +708,21 @@ fn eth_bridge_nut(c: &mut Criterion) { read_native_erc20_address(&shell.wl_storage).unwrap(); let signed_tx = { - let data = PendingTransfer{ - transfer: namada::types::eth_bridge_pool::TransferToEthereum { - kind: namada::types::eth_bridge_pool::TransferToEthereumKind::Erc20, - asset: native_erc20_addres, - recipient: namada::types::ethereum_events::EthAddress([1u8; 20]), - sender: defaults::albert_address(), - amount: Amount::from(1), - }, - gas_fee: GasFee{ - amount: Amount::from(100), - payer: defaults::albert_address(), - token: shell.wl_storage.storage.native_token.clone(), - }, - }; + let data = PendingTransfer { + transfer: namada::core::eth_bridge_pool::TransferToEthereum { + kind: + namada::core::eth_bridge_pool::TransferToEthereumKind::Erc20, + asset: native_erc20_addres, + recipient: namada::core::ethereum_events::EthAddress([1u8; 20]), + sender: defaults::albert_address(), + amount: Amount::from(1), + }, + gas_fee: GasFee { + amount: Amount::from(100), + payer: defaults::albert_address(), + token: shell.wl_storage.storage.native_token.clone(), + }, + }; shell.generate_tx( TX_BRIDGE_POOL_WASM, data, @@ -778,20 +778,21 @@ fn eth_bridge(c: &mut Criterion) { read_native_erc20_address(&shell.wl_storage).unwrap(); let signed_tx = { - let data = PendingTransfer{ - transfer: namada::types::eth_bridge_pool::TransferToEthereum { - kind: namada::types::eth_bridge_pool::TransferToEthereumKind::Erc20, - asset: native_erc20_addres, - recipient: namada::types::ethereum_events::EthAddress([1u8; 20]), - sender: defaults::albert_address(), - amount: Amount::from(1), - }, - gas_fee: GasFee{ - amount: Amount::from(100), - payer: defaults::albert_address(), - token: shell.wl_storage.storage.native_token.clone(), - }, - }; + let data = PendingTransfer { + transfer: namada::core::eth_bridge_pool::TransferToEthereum { + kind: + namada::core::eth_bridge_pool::TransferToEthereumKind::Erc20, + asset: native_erc20_addres, + recipient: namada::core::ethereum_events::EthAddress([1u8; 20]), + sender: defaults::albert_address(), + amount: Amount::from(1), + }, + gas_fee: GasFee { + amount: Amount::from(100), + payer: defaults::albert_address(), + token: shell.wl_storage.storage.native_token.clone(), + }, + }; shell.generate_tx( TX_BRIDGE_POOL_WASM, data, @@ -875,20 +876,21 @@ fn eth_bridge_pool(c: &mut Criterion) { shell.wl_storage.write(&denom_key, 0).unwrap(); let signed_tx = { - let data = PendingTransfer{ - transfer: namada::types::eth_bridge_pool::TransferToEthereum { - kind: namada::types::eth_bridge_pool::TransferToEthereumKind::Erc20, - asset: native_erc20_addres, - recipient: namada::types::ethereum_events::EthAddress([1u8; 20]), - sender: defaults::albert_address(), - amount: Amount::from(1), - }, - gas_fee: GasFee{ - amount: Amount::from(100), - payer: defaults::albert_address(), - token: shell.wl_storage.storage.native_token.clone(), - }, - }; + let data = PendingTransfer { + transfer: namada::core::eth_bridge_pool::TransferToEthereum { + kind: + namada::core::eth_bridge_pool::TransferToEthereumKind::Erc20, + asset: native_erc20_addres, + recipient: namada::core::ethereum_events::EthAddress([1u8; 20]), + sender: defaults::albert_address(), + amount: Amount::from(1), + }, + gas_fee: GasFee { + amount: Amount::from(100), + payer: defaults::albert_address(), + token: shell.wl_storage.storage.native_token.clone(), + }, + }; shell.generate_tx( TX_BRIDGE_POOL_WASM, data, @@ -1137,7 +1139,7 @@ fn ibc_vp_validate_action(c: &mut Criterion) { match bench_name { "open_connection" => { let _ = shell.init_ibc_client_state( - namada::core::types::storage::Key::from( + namada::core::storage::Key::from( Address::Internal(InternalAddress::Ibc).to_db_key(), ), ); @@ -1235,7 +1237,7 @@ fn ibc_vp_execute_action(c: &mut Criterion) { match bench_name { "open_connection" => { let _ = shell.init_ibc_client_state( - namada::core::types::storage::Key::from( + namada::core::storage::Key::from( Address::Internal(InternalAddress::Ibc).to_db_key(), ), ); diff --git a/crates/benches/process_wrapper.rs b/crates/benches/process_wrapper.rs index 4a12b34836..4264748e53 100644 --- a/crates/benches/process_wrapper.rs +++ b/crates/benches/process_wrapper.rs @@ -1,12 +1,12 @@ use criterion::{criterion_group, criterion_main, Criterion}; -use namada::core::types::address; +use namada::core::address; +use namada::core::key::RefTo; +use namada::core::storage::BlockHeight; +use namada::core::time::DateTimeUtc; use namada::ledger::storage::TempWlStorage; use namada::token::{Amount, DenominatedAmount, Transfer}; use namada::tx::data::{Fee, WrapperTx}; use namada::tx::Signature; -use namada::types::key::RefTo; -use namada::types::storage::BlockHeight; -use namada::types::time::DateTimeUtc; use namada_apps::bench_utils::{BenchShell, TX_TRANSFER_WASM}; use namada_apps::node::ledger::shell::process_proposal::ValidationMeta; use namada_apps::wallet::defaults; diff --git a/crates/benches/txs.rs b/crates/benches/txs.rs index 44749908c3..22119c3c5c 100644 --- a/crates/benches/txs.rs +++ b/crates/benches/txs.rs @@ -3,9 +3,15 @@ use std::str::FromStr; use criterion::{criterion_group, criterion_main, Criterion}; use namada::account::{InitAccount, UpdateAccount}; -use namada::core::types::key::{ - common, SecretKey as SecretKeyInterface, SigScheme, +use namada::core::address::{self, Address}; +use namada::core::eth_bridge_pool::{GasFee, PendingTransfer}; +use namada::core::hash::Hash; +use namada::core::key::{ + common, ed25519, secp256k1, PublicKey, RefTo, + SecretKey as SecretKeyInterface, SigScheme, }; +use namada::core::masp::{TransferSource, TransferTarget}; +use namada::core::storage::Key; use namada::governance::pgf::storage::steward::StewardDetail; use namada::governance::storage::proposal::ProposalType; use namada::governance::storage::vote::ProposalVote; @@ -31,12 +37,6 @@ use namada::tx::data::pos::{ MetaDataChange, Redelegation, Withdraw, }; use namada::tx::{Code, Section}; -use namada::types::address::{self, Address}; -use namada::types::eth_bridge_pool::{GasFee, PendingTransfer}; -use namada::types::hash::Hash; -use namada::types::key::{ed25519, secp256k1, PublicKey, RefTo}; -use namada::types::masp::{TransferSource, TransferTarget}; -use namada::types::storage::Key; use namada_apps::bench_utils::{ BenchShell, BenchShieldedCtx, ALBERT_PAYMENT_ADDRESS, ALBERT_SPENDING_KEY, BERTHA_PAYMENT_ADDRESS, TX_BECOME_VALIDATOR_WASM, TX_BOND_WASM, @@ -617,8 +617,8 @@ fn become_validator(c: &mut Criterion) { eth_cold_key, eth_hot_key, protocol_key, - commission_rate: namada::types::dec::Dec::default(), - max_commission_rate_change: namada::types::dec::Dec::default(), + commission_rate: namada::core::dec::Dec::default(), + max_commission_rate_change: namada::core::dec::Dec::default(), email: "null@null.net".to_string(), description: None, website: None, @@ -647,7 +647,7 @@ fn become_validator(c: &mut Criterion) { shell .wl_storage .write_bytes( - &namada::types::storage::Key::validity_predicate( + &namada::core::storage::Key::validity_predicate( &address, ), vec![], @@ -667,7 +667,7 @@ fn change_validator_commission(c: &mut Criterion) { TX_CHANGE_VALIDATOR_COMMISSION_WASM, CommissionChange { validator: defaults::validator_address(), - new_rate: namada::types::dec::Dec::new(6, 2).unwrap(), + new_rate: namada::core::dec::Dec::new(6, 2).unwrap(), }, None, None, @@ -794,8 +794,8 @@ fn ibc(c: &mut Criterion) { match bench_name { "open_connection" => { let _ = shell.init_ibc_client_state( - namada::core::types::storage::Key::from( - Address::Internal(namada::types::address::InternalAddress::Ibc).to_db_key(), + namada::core::storage::Key::from( + Address::Internal(namada::core::address::InternalAddress::Ibc).to_db_key(), ), ); } @@ -866,10 +866,10 @@ fn tx_bridge_pool(c: &mut Criterion) { let shell = BenchShell::default(); let data = PendingTransfer { - transfer: namada::types::eth_bridge_pool::TransferToEthereum { - kind: namada::types::eth_bridge_pool::TransferToEthereumKind::Erc20, + transfer: namada::core::eth_bridge_pool::TransferToEthereum { + kind: namada::core::eth_bridge_pool::TransferToEthereumKind::Erc20, asset: read_native_erc20_address(&shell.wl_storage).unwrap(), - recipient: namada::types::ethereum_events::EthAddress([1u8; 20]), + recipient: namada::core::ethereum_events::EthAddress([1u8; 20]), sender: defaults::albert_address(), amount: Amount::from(1), }, @@ -941,7 +941,7 @@ fn update_steward_commission(c: &mut Criterion) { steward: defaults::albert_address(), commission: HashMap::from([( defaults::albert_address(), - namada::types::dec::Dec::zero(), + namada::core::dec::Dec::zero(), )]), }; let tx = shell.generate_tx( diff --git a/crates/benches/vps.rs b/crates/benches/vps.rs index 35dc7ca219..352fe39f25 100644 --- a/crates/benches/vps.rs +++ b/crates/benches/vps.rs @@ -2,19 +2,18 @@ use std::collections::BTreeSet; use criterion::{criterion_group, criterion_main, Criterion}; use namada::account::UpdateAccount; -use namada::core::types::address::{self, Address}; -use namada::core::types::key::{ - common, SecretKey as SecretKeyInterface, SigScheme, +use namada::core::address::{self, Address}; +use namada::core::hash::Hash; +use namada::core::key::{ + common, ed25519, SecretKey as SecretKeyInterface, SigScheme, }; +use namada::core::storage::{Key, TxIndex}; use namada::governance::storage::vote::ProposalVote; use namada::governance::VoteProposalData; use namada::ledger::gas::{TxGasMeter, VpGasMeter}; use namada::token::{Amount, Transfer}; use namada::tx::data::pos::{Bond, CommissionChange}; use namada::tx::{Code, Section}; -use namada::types::hash::Hash; -use namada::types::key::ed25519; -use namada::types::storage::{Key, TxIndex}; use namada::vm::wasm::run; use namada_apps::bench_utils::{ generate_foreign_key_tx, BenchShell, TX_BOND_WASM, @@ -383,7 +382,7 @@ fn vp_validator(c: &mut Criterion) { TX_CHANGE_VALIDATOR_COMMISSION_WASM, CommissionChange { validator: defaults::validator_address(), - new_rate: namada::types::dec::Dec::new(6, 2).unwrap(), + new_rate: namada::core::dec::Dec::new(6, 2).unwrap(), }, None, None, diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 67271d6728..bb4437f87d 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -46,14 +46,12 @@ index-set.workspace = true k256.workspace = true masp_primitives.workspace = true num256.workspace = true -num-derive.workspace = true num_enum = "0.7.0" num-integer = "0.1.45" num-rational.workspace = true num-traits.workspace = true primitive-types.workspace = true proptest = {workspace = true, optional = true} -prost.workspace = true prost-types.workspace = true rand = {version = "0.8", optional = true} rand_core = {version = "0.6", optional = true} diff --git a/crates/core/src/address.rs b/crates/core/src/address.rs index a0d911e2c3..9cd8f3c64d 100644 --- a/crates/core/src/address.rs +++ b/crates/core/src/address.rs @@ -14,13 +14,12 @@ use data_encoding::HEXUPPER; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; +use crate::ethereum_events::EthAddress; use crate::ibc::primitives::Signer; -use crate::impl_display_and_from_str_via_format; -use crate::types::ethereum_events::EthAddress; -use crate::types::ibc::IbcTokenHash; -use crate::types::key::PublicKeyHash; -use crate::types::token::Denomination; -use crate::types::{key, string_encoding}; +use crate::ibc::IbcTokenHash; +use crate::key::PublicKeyHash; +use crate::token::Denomination; +use crate::{impl_display_and_from_str_via_format, key, string_encoding}; /// The length of an established [`Address`] encoded with Borsh. pub const ESTABLISHED_ADDRESS_BYTES_LEN: usize = 21; @@ -44,7 +43,7 @@ pub const HASH_LEN: usize = 20; /// use sha2::Digest; /// assert_eq!( /// sha2::Sha256::output_size(), -/// namada_core::types::address::SHA_HASH_LEN +/// namada_core::address::SHA_HASH_LEN /// ); /// ``` pub const SHA_HASH_LEN: usize = 32; @@ -366,8 +365,7 @@ impl TryFrom for Address { // sending a token from a spending key, it has been already // replaced with the MASP address. Address::decode(signer.as_ref()).or( - match crate::types::masp::PaymentAddress::from_str(signer.as_ref()) - { + match crate::masp::PaymentAddress::from_str(signer.as_ref()) { Ok(_) => Ok(MASP), Err(_) => Err(DecodeError::InvalidInnerEncoding(format!( "Invalid address for IBC transfer: {signer}" @@ -750,7 +748,7 @@ pub mod testing { use proptest::prelude::*; use super::*; - use crate::types::key::*; + use crate::key::*; /// Generate a new established address. pub fn gen_established_address() -> Address { @@ -899,13 +897,13 @@ pub mod testing { } fn arb_erc20() -> InternalAddress { - use crate::types::ethereum_events::testing::arbitrary_eth_address; + use crate::ethereum_events::testing::arbitrary_eth_address; // TODO: generate random erc20 addr data InternalAddress::Erc20(arbitrary_eth_address()) } fn arb_nut() -> InternalAddress { - use crate::types::ethereum_events::testing::arbitrary_eth_address; + use crate::ethereum_events::testing::arbitrary_eth_address; // TODO: generate random erc20 addr data InternalAddress::Nut(arbitrary_eth_address()) } diff --git a/crates/core/src/dec.rs b/crates/core/src/dec.rs index 5b32b484e5..c8720e4b8e 100644 --- a/crates/core/src/dec.rs +++ b/crates/core/src/dec.rs @@ -14,8 +14,8 @@ use num_traits::CheckedMul; use serde::{Deserialize, Serialize}; use super::token::NATIVE_MAX_DECIMAL_PLACES; -use crate::types::token::{Amount, Change}; -use crate::types::uint::{Uint, I256}; +use crate::token::{Amount, Change}; +use crate::uint::{Uint, I256}; /// The number of Dec places for PoS rational calculations pub const POS_DECIMAL_PRECISION: u8 = 12; @@ -69,7 +69,7 @@ impl Dec { /// /// Example: /// ``` - /// use namada_core::types::dec::Dec; + /// use namada_core::dec::Dec; /// /// let x = Dec::new(3, 1).unwrap(); // Represents 0.3 /// let y = Dec::new(2, 1).unwrap(); // Represents 0.2 @@ -549,7 +549,7 @@ pub mod testing { #[cfg(test)] mod test_dec { use super::*; - use crate::types::token::{Amount, Change}; + use crate::token::{Amount, Change}; #[derive(Debug, Serialize, Deserialize)] struct SerializerTest { diff --git a/crates/core/src/eth_abi.rs b/crates/core/src/eth_abi.rs index 886b5b9c46..62fe0169fe 100644 --- a/crates/core/src/eth_abi.rs +++ b/crates/core/src/eth_abi.rs @@ -7,8 +7,8 @@ use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; #[doc(inline)] pub use ethabi::token::Token; -use crate::types::keccak::{keccak_hash, KeccakHash}; -use crate::types::key::{Signable, SignableEthMessage}; +use crate::keccak::{keccak_hash, KeccakHash}; +use crate::key::{Signable, SignableEthMessage}; /// A container for data types that are able to be Ethereum ABI-encoded. #[derive(Clone, Debug, BorshSerialize, BorshDeserialize, BorshSchema)] @@ -129,7 +129,7 @@ mod tests { use tiny_keccak::{Hasher, Keccak}; use super::*; - use crate::types::ethereum_events::EthAddress; + use crate::ethereum_events::EthAddress; /// Checks if we get the same result as `abi.encode`, for some given /// input data. diff --git a/crates/core/src/eth_bridge_pool.rs b/crates/core/src/eth_bridge_pool.rs index 83bcef6c6a..b2d9c82986 100644 --- a/crates/core/src/eth_bridge_pool.rs +++ b/crates/core/src/eth_bridge_pool.rs @@ -13,14 +13,14 @@ use super::address::InternalAddress; use super::keccak::KeccakHash; use super::storage::{self, KeySeg}; use crate as namada_core; // This is needed for `StorageKeys` macro -use crate::types::address::Address; -use crate::types::eth_abi::Encode; -use crate::types::ethereum_events::{ +use crate::address::Address; +use crate::eth_abi::Encode; +use crate::ethereum_events::{ EthAddress, TransferToEthereum as TransferToEthereumEvent, }; -use crate::types::hash::Hash as HashDigest; -use crate::types::storage::{DbKeySeg, Key}; -use crate::types::token::Amount; +use crate::hash::Hash as HashDigest; +use crate::storage::{DbKeySeg, Key}; +use crate::token::Amount; /// The main address of the Ethereum bridge pool pub const BRIDGE_POOL_ADDRESS: Address = @@ -364,11 +364,11 @@ pub mod testing { use proptest::strategy::Strategy; use super::*; - use crate::types::address::testing::{ + use crate::address::testing::{ arb_established_address, arb_non_internal_address, }; - use crate::types::ethereum_events::testing::arb_eth_address; - use crate::types::token::testing::arb_amount; + use crate::ethereum_events::testing::arb_eth_address; + use crate::token::testing::arb_amount; prop_compose! { /// Generate an arbitrary pending transfer @@ -434,8 +434,8 @@ pub mod testing { #[cfg(test)] mod test_eth_bridge_pool_types { use super::*; - use crate::types::address::nam; - use crate::types::address::testing::established_address_1; + use crate::address::nam; + use crate::address::testing::established_address_1; /// Test that [`PendingTransfer`] and [`TransferToEthereum`] /// have the same keccak hash, after being ABI encoded. diff --git a/crates/core/src/ethereum_events.rs b/crates/core/src/ethereum_events.rs index 8569b118e4..9e55df2b69 100644 --- a/crates/core/src/ethereum_events.rs +++ b/crates/core/src/ethereum_events.rs @@ -12,13 +12,13 @@ use ethabi::Token; use eyre::{eyre, Context}; use serde::{Deserialize, Serialize}; -use crate::types::address::Address; -use crate::types::eth_abi::Encode; -use crate::types::ethereum_structs::Erc20Transfer; -use crate::types::hash::Hash; -use crate::types::keccak::KeccakHash; -use crate::types::storage::{DbKeySeg, KeySeg}; -use crate::types::token::Amount; +use crate::address::Address; +use crate::eth_abi::Encode; +use crate::ethereum_structs::Erc20Transfer; +use crate::hash::Hash; +use crate::keccak::KeccakHash; +use crate::storage::{DbKeySeg, KeySeg}; +use crate::token::Amount; /// Namada native type to replace the ethabi::Uint type #[derive( @@ -197,9 +197,9 @@ impl From for String { } impl KeySeg for EthAddress { - fn parse(string: String) -> crate::types::storage::Result { + fn parse(string: String) -> crate::storage::Result { Self::from_str(string.as_str()) - .map_err(|_| crate::types::storage::Error::ParseKeySeg(string)) + .map_err(|_| crate::storage::Error::ParseKeySeg(string)) } fn raw(&self) -> String { @@ -373,7 +373,7 @@ impl From for TransferToEthereum { Self { amount: { let uint = { - use crate::types::uint::Uint as NamadaUint; + use crate::uint::Uint as NamadaUint; let mut num_buf = [0; 32]; transfer.amount.to_little_endian(&mut num_buf); NamadaUint::from_little_endian(&num_buf) @@ -450,7 +450,7 @@ pub mod testing { use proptest::prop_compose; use super::*; - use crate::types::token::{self, Amount}; + use crate::token::{self, Amount}; pub const DAI_ERC20_ETH_ADDRESS_CHECKSUMMED: &str = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; diff --git a/crates/core/src/ethereum_structs.rs b/crates/core/src/ethereum_structs.rs index 5b29e0e588..e2bd8a5ce0 100644 --- a/crates/core/src/ethereum_structs.rs +++ b/crates/core/src/ethereum_structs.rs @@ -9,7 +9,7 @@ pub use ethbridge_structs::*; use num256::Uint256; use serde::{Deserialize, Serialize}; -use crate::types::keccak::KeccakHash; +use crate::keccak::KeccakHash; /// Status of some Bridge pool transfer. #[derive( diff --git a/crates/core/src/event.rs b/crates/core/src/event.rs index 5db1de6131..d82121de50 100644 --- a/crates/core/src/event.rs +++ b/crates/core/src/event.rs @@ -8,8 +8,8 @@ use std::str::FromStr; use thiserror::Error; use crate::borsh::{BorshDeserialize, BorshSerialize}; -use crate::types::ethereum_structs::{BpTransferStatus, EthBridgeEvent}; -use crate::types::ibc::IbcEvent; +use crate::ethereum_structs::{BpTransferStatus, EthBridgeEvent}; +use crate::ibc::IbcEvent; /// Used in sub-systems that may emit events. pub trait EmitEvents { diff --git a/crates/core/src/ibc.rs b/crates/core/src/ibc.rs index f517c84363..a60cd1d8ed 100644 --- a/crates/core/src/ibc.rs +++ b/crates/core/src/ibc.rs @@ -7,6 +7,7 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use borsh_ext::BorshSerializeExt; use data_encoding::{DecodePartial, HEXLOWER, HEXLOWER_PERMISSIVE, HEXUPPER}; +pub use ibc::*; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -17,9 +18,9 @@ use crate::ibc::core::handler::types::events::{ Error as IbcEventError, IbcEvent as RawIbcEvent, }; use crate::ibc::primitives::proto::Protobuf; +use crate::masp::PaymentAddress; use crate::tendermint::abci::Event as AbciEvent; -use crate::types::masp::PaymentAddress; -use crate::types::token::Transfer; +use crate::token::Transfer; /// The event type defined in ibc-rs for receiving a token pub const EVENT_TYPE_PACKET: &str = "fungible_token_packet"; @@ -166,7 +167,7 @@ pub enum Error { } /// Conversion functions result -pub type Result = std::result::Result; +type Result = std::result::Result; impl TryFrom for IbcEvent { type Error = Error; diff --git a/crates/core/src/keccak.rs b/crates/core/src/keccak.rs index f6fc15724d..b2e85ebd01 100644 --- a/crates/core/src/keccak.rs +++ b/crates/core/src/keccak.rs @@ -11,8 +11,8 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use thiserror::Error; pub use tiny_keccak::{Hasher, Keccak}; -use crate::types::eth_abi::Encode; -use crate::types::hash::{Hash, HASH_LENGTH}; +use crate::eth_abi::Encode; +use crate::hash::{Hash, HASH_LENGTH}; /// Errors for converting / parsing Keccak hashes #[allow(missing_docs)] diff --git a/crates/core/src/key/common.rs b/crates/core/src/key/common.rs index 7db4641879..05023548a4 100644 --- a/crates/core/src/key/common.rs +++ b/crates/core/src/key/common.rs @@ -17,10 +17,9 @@ use super::{ ParseSignatureError, RefTo, SchemeType, SigScheme as SigSchemeTrait, VerifySigError, }; -use crate::impl_display_and_from_str_via_format; -use crate::types::ethereum_events::EthAddress; -use crate::types::key::{SignableBytes, StorageHasher}; -use crate::types::string_encoding; +use crate::ethereum_events::EthAddress; +use crate::key::{SignableBytes, StorageHasher}; +use crate::{impl_display_and_from_str_via_format, string_encoding}; /// Public key #[derive( @@ -456,14 +455,14 @@ impl super::SigScheme for SigScheme { #[cfg(test)] mod tests { use super::*; - use crate::types::key::ed25519; + use crate::key::ed25519; /// Run `cargo test gen_ed25519_keypair -- --nocapture` to generate a /// new ed25519 keypair wrapped in `common` key types. #[test] fn gen_ed25519_keypair() { let secret_key = - SecretKey::Ed25519(crate::types::key::testing::gen_keypair::< + SecretKey::Ed25519(crate::key::testing::gen_keypair::< ed25519::SigScheme, >()); let public_key = secret_key.to_public(); diff --git a/crates/core/src/key/ed25519.rs b/crates/core/src/key/ed25519.rs index 2e118fe90e..ea7cc46e6f 100644 --- a/crates/core/src/key/ed25519.rs +++ b/crates/core/src/key/ed25519.rs @@ -19,7 +19,7 @@ use super::{ ParsePublicKeyError, ParseSecretKeyError, ParseSignatureError, RefTo, SchemeType, SigScheme as SigSchemeTrait, SignableBytes, VerifySigError, }; -use crate::types::key::StorageHasher; +use crate::key::StorageHasher; const PUBLIC_KEY_LENGTH: usize = 32; const SECRET_KEY_LENGTH: usize = 32; diff --git a/crates/core/src/key/mod.rs b/crates/core/src/key/mod.rs index b07efc0ba4..0c32560682 100644 --- a/crates/core/src/key/mod.rs +++ b/crates/core/src/key/mod.rs @@ -17,9 +17,9 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use thiserror::Error; -use crate::types::address; -use crate::types::hash::{KeccakHasher, Sha256Hasher, StorageHasher}; -use crate::types::keccak::{keccak_hash, KeccakHash}; +use crate::address; +use crate::hash::{KeccakHasher, Sha256Hasher, StorageHasher}; +use crate::keccak::{keccak_hash, KeccakHash}; /// Represents an error in signature verification #[allow(missing_docs)] @@ -458,25 +458,25 @@ impl SignableBytes for &[u8] {} impl SignableBytes for [u8; N] {} impl SignableBytes for &[u8; N] {} -impl SignableBytes for crate::types::hash::Hash { +impl SignableBytes for crate::hash::Hash { fn signable_hash(&self) -> [u8; 32] { self.0 } } -impl SignableBytes for &crate::types::hash::Hash { +impl SignableBytes for &crate::hash::Hash { fn signable_hash(&self) -> [u8; 32] { self.0 } } -impl SignableBytes for crate::types::keccak::KeccakHash { +impl SignableBytes for crate::keccak::KeccakHash { fn signable_hash(&self) -> [u8; 32] { self.0 } } -impl SignableBytes for &crate::types::keccak::KeccakHash { +impl SignableBytes for &crate::keccak::KeccakHash { fn signable_hash(&self) -> [u8; 32] { self.0 } @@ -491,7 +491,7 @@ pub mod testing { use rand::{thread_rng, SeedableRng}; use super::SigScheme; - use crate::types::key::*; + use crate::key::*; /// Generate an arbitrary public key pub fn arb_pk() diff --git a/crates/core/src/key/secp256k1.rs b/crates/core/src/key/secp256k1.rs index 06ae2c4216..65a569b1a9 100644 --- a/crates/core/src/key/secp256k1.rs +++ b/crates/core/src/key/secp256k1.rs @@ -24,9 +24,9 @@ use super::{ ParsePublicKeyError, ParseSecretKeyError, ParseSignatureError, RefTo, SchemeType, SigScheme as SigSchemeTrait, SignableBytes, VerifySigError, }; -use crate::types::eth_abi::Encode; -use crate::types::ethereum_events::EthAddress; -use crate::types::key::StorageHasher; +use crate::eth_abi::Encode; +use crate::ethereum_events::EthAddress; +use crate::key::StorageHasher; /// The provided constant is for a traditional /// signature on this curve. For Ethereum, an extra byte is included diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index c7580895ea..667aae67aa 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -10,7 +10,7 @@ pub mod bytes; pub mod event; pub mod hints; -pub use {ibc, masp_primitives, tendermint, tendermint_proto}; +pub use {masp_primitives, tendermint, tendermint_proto}; /// Borsh binary encoding (re-exported) from official crate with custom ext. pub mod borsh { pub use borsh::*; diff --git a/crates/core/src/masp.rs b/crates/core/src/masp.rs index 61b63dab60..fcee87ac71 100644 --- a/crates/core/src/masp.rs +++ b/crates/core/src/masp.rs @@ -9,14 +9,14 @@ use masp_primitives::asset_type::AssetType; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; +use crate::address::{Address, DecodeError, HASH_HEX_LEN, MASP}; use crate::impl_display_and_from_str_via_format; -use crate::types::address::{Address, DecodeError, HASH_HEX_LEN, MASP}; -use crate::types::storage::Epoch; -use crate::types::string_encoding::{ +use crate::storage::Epoch; +use crate::string_encoding::{ self, MASP_EXT_FULL_VIEWING_KEY_HRP, MASP_EXT_SPENDING_KEY_HRP, MASP_PAYMENT_ADDRESS_HRP, }; -use crate::types::token::{Denomination, MaspDigitPos}; +use crate::token::{Denomination, MaspDigitPos}; /// The plain representation of a MASP aaset #[derive( diff --git a/crates/core/src/storage.rs b/crates/core/src/storage.rs index 1ac99d11b4..8eec976070 100644 --- a/crates/core/src/storage.rs +++ b/crates/core/src/storage.rs @@ -16,13 +16,13 @@ use serde::{Deserialize, Serialize}; use thiserror::Error; use super::key::common; +use crate::address::{self, Address}; use crate::bytes::ByteBuf; +use crate::ethereum_events::{GetEventNonce, TransfersToNamada, Uint}; +use crate::hash::Hash; use crate::hints; -use crate::types::address::{self, Address}; -use crate::types::ethereum_events::{GetEventNonce, TransfersToNamada, Uint}; -use crate::types::hash::Hash; -use crate::types::keccak::{KeccakHash, TryFromError}; -use crate::types::time::DateTimeUtc; +use crate::keccak::{KeccakHash, TryFromError}; +use crate::time::DateTimeUtc; /// The maximum size of an IBC key (in bytes) allowed in merkle-ized storage pub const IBC_KEY_LIMIT: usize = 240; @@ -900,9 +900,8 @@ impl KeySeg for Address { impl KeySeg for Hash { fn parse(seg: String) -> Result { - seg.try_into().map_err(|e: crate::types::hash::Error| { - Error::ParseKeySeg(e.to_string()) - }) + seg.try_into() + .map_err(|e: crate::hash::Error| Error::ParseKeySeg(e.to_string())) } fn raw(&self) -> String { @@ -1477,7 +1476,7 @@ pub mod tests { use proptest::prelude::*; use super::*; - use crate::types::address::testing::arb_address; + use crate::address::testing::arb_address; proptest! { /// Tests that any key that doesn't contain reserved prefixes is valid. @@ -1906,9 +1905,7 @@ pub mod testing { use proptest::prelude::*; use super::*; - use crate::types::address::testing::{ - arb_address, arb_non_internal_address, - }; + use crate::address::testing::{arb_address, arb_non_internal_address}; prop_compose! { /// Generate an arbitrary epoch diff --git a/crates/core/src/string_encoding.rs b/crates/core/src/string_encoding.rs index 47db158d85..1e0c37806f 100644 --- a/crates/core/src/string_encoding.rs +++ b/crates/core/src/string_encoding.rs @@ -112,19 +112,15 @@ macro_rules! impl_display_and_from_str_via_format { ($t:path) => { impl std::fmt::Display for $t { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - $crate::types::string_encoding::Format::encode(self) - ) + write!(f, "{}", $crate::string_encoding::Format::encode(self)) } } impl std::str::FromStr for $t { - type Err = $crate::types::string_encoding::DecodeError; + type Err = $crate::string_encoding::DecodeError; fn from_str(s: &str) -> std::result::Result { - $crate::types::string_encoding::Format::decode(s) + $crate::string_encoding::Format::decode(s) } } }; diff --git a/crates/core/src/token.rs b/crates/core/src/token.rs index 3d2429c151..fb7d781a88 100644 --- a/crates/core/src/token.rs +++ b/crates/core/src/token.rs @@ -12,13 +12,13 @@ use ethabi::ethereum_types::U256; use serde::{Deserialize, Serialize}; use thiserror::Error; +use crate::address::Address; +use crate::dec::{Dec, POS_DECIMAL_PRECISION}; +use crate::hash::Hash; use crate::ibc::apps::transfer::types::Amount as IbcAmount; -use crate::types::address::Address; -use crate::types::dec::{Dec, POS_DECIMAL_PRECISION}; -use crate::types::hash::Hash; -use crate::types::storage; -use crate::types::storage::{DbKeySeg, KeySeg}; -use crate::types::uint::{self, Uint, I256}; +use crate::storage; +use crate::storage::{DbKeySeg, KeySeg}; +use crate::uint::{self, Uint, I256}; /// Amount in micro units. For different granularity another representation /// might be more appropriate. @@ -1020,7 +1020,7 @@ pub mod testing { use proptest::prelude::*; use super::*; - use crate::types::address::testing::{ + use crate::address::testing::{ arb_established_address, arb_non_internal_address, }; diff --git a/crates/core/src/uint.rs b/crates/core/src/uint.rs index e13cb9ce1b..4633720fea 100644 --- a/crates/core/src/uint.rs +++ b/crates/core/src/uint.rs @@ -12,8 +12,8 @@ use num_traits::{CheckedAdd, CheckedMul, CheckedSub}; use uint::construct_uint; use super::dec::{Dec, POS_DECIMAL_PRECISION}; -use crate::types::token; -use crate::types::token::{Amount, AmountParseError, MaspDigitPos}; +use crate::token; +use crate::token::{Amount, AmountParseError, MaspDigitPos}; /// The value zero. pub const ZERO: Uint = Uint::from_u64(0); diff --git a/crates/core/src/voting_power.rs b/crates/core/src/voting_power.rs index 014e0bade9..b4164b58f0 100644 --- a/crates/core/src/voting_power.rs +++ b/crates/core/src/voting_power.rs @@ -14,8 +14,8 @@ use num_traits::ops::checked::CheckedAdd; use serde::de::Visitor; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; -use crate::types::token::Amount; -use crate::types::uint::Uint; +use crate::token::Amount; +use crate::uint::Uint; /// Namada voting power, normalized to the range `0 - 2^32`. #[derive( diff --git a/crates/encoding_spec/src/main.rs b/crates/encoding_spec/src/main.rs index d6bb9df06c..dcd8c13620 100644 --- a/crates/encoding_spec/src/main.rs +++ b/crates/encoding_spec/src/main.rs @@ -25,12 +25,12 @@ use itertools::Itertools; use lazy_static::lazy_static; use madato::types::TableRow; use namada::account; +use namada::core::address::Address; +use namada::core::key::ed25519::{PublicKey, Signature}; +use namada::core::storage::{self, Epoch}; +use namada::core::token; use namada::ledger::parameters::Parameters; use namada::tx::data::{pos, TxType, WrapperTx}; -use namada::types::address::Address; -use namada::types::key::ed25519::{PublicKey, Signature}; -use namada::types::storage::{self, Epoch}; -use namada::types::token; /// This generator will write output into this `docs` file. const OUTPUT_PATH: &str = diff --git a/crates/ethereum_bridge/src/lib.rs b/crates/ethereum_bridge/src/lib.rs index 955ba19887..eef7126bab 100644 --- a/crates/ethereum_bridge/src/lib.rs +++ b/crates/ethereum_bridge/src/lib.rs @@ -6,5 +6,5 @@ pub mod storage; #[cfg(any(test, feature = "testing"))] pub mod test_utils; -pub use namada_core::types::address::ETH_BRIDGE as ADDRESS; +pub use namada_core::address::ETH_BRIDGE as ADDRESS; pub use namada_trans_token as token; diff --git a/crates/ethereum_bridge/src/oracle/config.rs b/crates/ethereum_bridge/src/oracle/config.rs index 33b66a34d7..37e5a94cf9 100644 --- a/crates/ethereum_bridge/src/oracle/config.rs +++ b/crates/ethereum_bridge/src/oracle/config.rs @@ -1,8 +1,8 @@ //! Configuration for an oracle. use std::num::NonZeroU64; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::ethereum_structs; +use namada_core::ethereum_events::EthAddress; +use namada_core::ethereum_structs; /// Configuration for an oracle. #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] diff --git a/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs b/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs index afd307fb87..47679b74da 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs @@ -1,11 +1,11 @@ use std::collections::{HashMap, HashSet}; use eyre::Result; -use namada_core::types::address::Address; -use namada_core::types::keccak::keccak_hash; -use namada_core::types::key::{common, SignableEthMessage}; -use namada_core::types::storage::BlockHeight; -use namada_core::types::token::Amount; +use namada_core::address::Address; +use namada_core::keccak::keccak_hash; +use namada_core::key::{common, SignableEthMessage}; +use namada_core::storage::BlockHeight; +use namada_core::token::Amount; use namada_proof_of_stake::pos_queries::PosQueries; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_storage::{StorageRead, StorageWrite}; @@ -259,11 +259,11 @@ mod test_apply_bp_roots_to_storage { use assert_matches::assert_matches; use borsh::BorshDeserialize; - use namada_core::types::address; - use namada_core::types::ethereum_events::Uint; - use namada_core::types::keccak::{keccak_hash, KeccakHash}; - use namada_core::types::storage::Key; - use namada_core::types::voting_power::FractionalVotingPower; + use namada_core::address; + use namada_core::ethereum_events::Uint; + use namada_core::keccak::{keccak_hash, KeccakHash}; + use namada_core::storage::Key; + use namada_core::voting_power::FractionalVotingPower; use namada_proof_of_stake::parameters::OwnedPosParams; use namada_proof_of_stake::storage::write_pos_params; use namada_state::testing::TestWlStorage; diff --git a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/eth_msgs.rs b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/eth_msgs.rs index 515c793a65..3267912131 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/eth_msgs.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/eth_msgs.rs @@ -1,5 +1,5 @@ use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::ethereum_events::EthereumEvent; +use namada_core::ethereum_events::EthereumEvent; use namada_vote_ext::ethereum_events::MultiSignedEthEvent; use crate::protocol::transactions::votes::{dedupe, Tally, Votes}; @@ -51,11 +51,11 @@ pub struct EthMsg { mod tests { use std::collections::BTreeSet; - use namada_core::types::address; - use namada_core::types::ethereum_events::testing::{ + use namada_core::address; + use namada_core::ethereum_events::testing::{ arbitrary_nonce, arbitrary_single_transfer, }; - use namada_core::types::storage::BlockHeight; + use namada_core::storage::BlockHeight; use super::*; diff --git a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs index 73a228dcea..09980ad331 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs @@ -5,19 +5,19 @@ use std::str::FromStr; use borsh::BorshDeserialize; use eyre::{Result, WrapErr}; -use namada_core::hints; -use namada_core::types::address::Address; -use namada_core::types::eth_abi::Encode; -use namada_core::types::eth_bridge_pool::{ +use namada_core::address::Address; +use namada_core::eth_abi::Encode; +use namada_core::eth_bridge_pool::{ erc20_nut_address, erc20_token_address, PendingTransfer, TransferToEthereumKind, }; -use namada_core::types::ethereum_events::{ +use namada_core::ethereum_events::{ EthAddress, EthereumEvent, TransferToEthereum, TransferToNamada, TransfersToNamada, }; -use namada_core::types::ethereum_structs::EthBridgeEvent; -use namada_core::types::storage::{BlockHeight, Key, KeySeg}; +use namada_core::ethereum_structs::EthBridgeEvent; +use namada_core::hints; +use namada_core::storage::{BlockHeight, Key, KeySeg}; use namada_parameters::read_epoch_duration_parameter; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_storage::{StorageRead, StorageWrite}; @@ -585,16 +585,16 @@ mod tests { use assert_matches::assert_matches; use eyre::Result; + use namada_core::address::testing::gen_implicit_address; + use namada_core::address::{gen_established_address, nam, wnam}; use namada_core::borsh::BorshSerializeExt; - use namada_core::types::address::testing::gen_implicit_address; - use namada_core::types::address::{gen_established_address, nam, wnam}; - use namada_core::types::eth_bridge_pool::GasFee; - use namada_core::types::ethereum_events::testing::{ + use namada_core::eth_bridge_pool::GasFee; + use namada_core::ethereum_events::testing::{ arbitrary_keccak_hash, arbitrary_nonce, DAI_ERC20_ETH_ADDRESS, }; - use namada_core::types::time::DurationSecs; - use namada_core::types::token::Amount; - use namada_core::types::{address, eth_bridge_pool}; + use namada_core::time::DurationSecs; + use namada_core::token::Amount; + use namada_core::{address, eth_bridge_pool}; use namada_parameters::{update_epoch_parameter, EpochDuration}; use namada_state::testing::TestWlStorage; use namada_storage::mockdb::MockDBWriteBatch; diff --git a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs index b9b2fe2731..afd596c8a4 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs @@ -8,12 +8,12 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use borsh::BorshDeserialize; use eth_msgs::EthMsgUpdate; use eyre::Result; -use namada_core::types::address::Address; -use namada_core::types::ethereum_events::EthereumEvent; -use namada_core::types::ethereum_structs::EthBridgeEvent; -use namada_core::types::key::common; -use namada_core::types::storage::{BlockHeight, Epoch, Key}; -use namada_core::types::token::Amount; +use namada_core::address::Address; +use namada_core::ethereum_events::EthereumEvent; +use namada_core::ethereum_structs::EthBridgeEvent; +use namada_core::key::common; +use namada_core::storage::{BlockHeight, Epoch, Key}; +use namada_core::token::Amount; use namada_proof_of_stake::pos_queries::PosQueries; use namada_state::tx_queue::ExpiredTx; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; @@ -337,15 +337,13 @@ mod tests { use std::collections::{BTreeSet, HashMap, HashSet}; use borsh::BorshDeserialize; - use namada_core::types::address; - use namada_core::types::ethereum_events::testing::{ + use namada_core::address; + use namada_core::ethereum_events::testing::{ arbitrary_amount, arbitrary_eth_address, arbitrary_nonce, arbitrary_single_transfer, DAI_ERC20_ETH_ADDRESS, }; - use namada_core::types::ethereum_events::{ - EthereumEvent, TransferToNamada, - }; - use namada_core::types::voting_power::FractionalVotingPower; + use namada_core::ethereum_events::{EthereumEvent, TransferToNamada}; + use namada_core::voting_power::FractionalVotingPower; use namada_state::testing::TestWlStorage; use namada_storage::mockdb::MockDBWriteBatch; use namada_storage::StorageRead; diff --git a/crates/ethereum_bridge/src/protocol/transactions/mod.rs b/crates/ethereum_bridge/src/protocol/transactions/mod.rs index 52833e7790..5b249deb7d 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/mod.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/mod.rs @@ -14,7 +14,7 @@ pub mod votes; use std::collections::BTreeSet; -use namada_core::types::storage; +use namada_core::storage; /// The keys changed while applying a protocol transaction. pub type ChangedKeys = BTreeSet; diff --git a/crates/ethereum_bridge/src/protocol/transactions/read.rs b/crates/ethereum_bridge/src/protocol/transactions/read.rs index c618b0335d..63663a4eb0 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/read.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/read.rs @@ -1,8 +1,8 @@ //! Helpers for reading from storage use borsh::BorshDeserialize; use eyre::{eyre, Result}; -use namada_core::types::storage; -use namada_core::types::token::Amount; +use namada_core::storage; +use namada_core::token::Amount; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_storage::StorageRead; @@ -54,8 +54,8 @@ where #[cfg(test)] mod tests { use assert_matches::assert_matches; - use namada_core::types::storage; - use namada_core::types::token::Amount; + use namada_core::storage; + use namada_core::token::Amount; use namada_state::testing::TestWlStorage; use namada_storage::StorageWrite; diff --git a/crates/ethereum_bridge/src/protocol/transactions/update.rs b/crates/ethereum_bridge/src/protocol/transactions/update.rs index ee258774a2..7d3d5d2e8f 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/update.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/update.rs @@ -1,9 +1,9 @@ //! Helpers for writing to storage use eyre::Result; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::hash::StorageHasher; -use namada_core::types::storage; -use namada_core::types::token::{Amount, AmountError}; +use namada_core::hash::StorageHasher; +use namada_core::storage; +use namada_core::token::{Amount, AmountError}; use namada_state::{DBIter, WlStorage, DB}; use namada_storage::StorageWrite; @@ -43,7 +43,7 @@ where #[cfg(test)] mod tests { use eyre::{eyre, Result}; - use namada_core::types::storage; + use namada_core::storage; use namada_state::testing::TestWlStorage; use namada_storage::{StorageRead, StorageWrite}; diff --git a/crates/ethereum_bridge/src/protocol/transactions/utils.rs b/crates/ethereum_bridge/src/protocol/transactions/utils.rs index 63eaf8530e..6694cd6f27 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/utils.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/utils.rs @@ -2,9 +2,9 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use eyre::eyre; use itertools::Itertools; -use namada_core::types::address::Address; -use namada_core::types::storage::BlockHeight; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::storage::BlockHeight; +use namada_core::token; use namada_proof_of_stake::pos_queries::PosQueries; use namada_proof_of_stake::types::WeightedValidator; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; @@ -123,9 +123,9 @@ mod tests { use std::collections::HashSet; use assert_matches::assert_matches; - use namada_core::types::address; - use namada_core::types::ethereum_events::testing::arbitrary_bonded_stake; - use namada_core::types::voting_power::FractionalVotingPower; + use namada_core::address; + use namada_core::ethereum_events::testing::arbitrary_bonded_stake; + use namada_core::voting_power::FractionalVotingPower; use super::*; diff --git a/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs b/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs index 1adcf3d09b..86ecaf0d88 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs @@ -3,10 +3,10 @@ use std::collections::{HashMap, HashSet}; use eyre::Result; -use namada_core::types::address::Address; -use namada_core::types::key::common; -use namada_core::types::storage::{BlockHeight, Epoch}; -use namada_core::types::token::Amount; +use namada_core::address::Address; +use namada_core::key::common; +use namada_core::storage::{BlockHeight, Epoch}; +use namada_core::token::Amount; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_tx::data::TxResult; use namada_vote_ext::validator_set_update; @@ -233,8 +233,8 @@ where #[cfg(test)] mod test_valset_upd_state_changes { - use namada_core::types::address; - use namada_core::types::voting_power::FractionalVotingPower; + use namada_core::address; + use namada_core::voting_power::FractionalVotingPower; use namada_proof_of_stake::pos_queries::PosQueries; use namada_vote_ext::validator_set_update::VotingPowersMap; diff --git a/crates/ethereum_bridge/src/protocol/transactions/votes.rs b/crates/ethereum_bridge/src/protocol/transactions/votes.rs index 7accb41f66..ef361f6a09 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/votes.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/votes.rs @@ -5,10 +5,10 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use eyre::{eyre, Result}; -use namada_core::types::address::Address; -use namada_core::types::storage::{BlockHeight, Epoch}; -use namada_core::types::token; -use namada_core::types::voting_power::FractionalVotingPower; +use namada_core::address::Address; +use namada_core::storage::{BlockHeight, Epoch}; +use namada_core::token; +use namada_core::voting_power::FractionalVotingPower; use namada_proof_of_stake::pos_queries::PosQueries; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; @@ -187,8 +187,8 @@ pub fn dedupe(signers: BTreeSet<(Address, BlockHeight)>) -> Votes { mod tests { use std::collections::BTreeSet; - use namada_core::types::storage::BlockHeight; - use namada_core::types::{address, token}; + use namada_core::storage::BlockHeight; + use namada_core::{address, token}; use namada_proof_of_stake::parameters::OwnedPosParams; use namada_proof_of_stake::storage::write_pos_params; diff --git a/crates/ethereum_bridge/src/protocol/transactions/votes/storage.rs b/crates/ethereum_bridge/src/protocol/transactions/votes/storage.rs index 8830059b63..494d3da5e7 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/votes/storage.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/votes/storage.rs @@ -1,8 +1,8 @@ use eyre::{Result, WrapErr}; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; use namada_core::hints; -use namada_core::types::storage::Key; -use namada_core::types::voting_power::FractionalVotingPower; +use namada_core::storage::Key; +use namada_core::voting_power::FractionalVotingPower; use namada_state::{DBIter, PrefixIter, StorageHasher, WlStorage, DB}; use namada_storage::{StorageRead, StorageWrite}; @@ -135,7 +135,7 @@ mod tests { use assert_matches::assert_matches; use namada_core::borsh::BorshSerializeExt; - use namada_core::types::ethereum_events::EthereumEvent; + use namada_core::ethereum_events::EthereumEvent; use super::*; use crate::test_utils; diff --git a/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs b/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs index 47027cde41..7f8ff356af 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs @@ -2,9 +2,9 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use borsh::BorshDeserialize; use eyre::{eyre, Result}; -use namada_core::types::address::Address; -use namada_core::types::storage::BlockHeight; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::storage::BlockHeight; +use namada_core::token; use namada_proof_of_stake::pos_queries::PosQueries; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; @@ -209,9 +209,9 @@ fn keys_changed( mod tests { use std::collections::BTreeMap; - use namada_core::types::address; - use namada_core::types::ethereum_events::EthereumEvent; - use namada_core::types::voting_power::FractionalVotingPower; + use namada_core::address; + use namada_core::ethereum_events::EthereumEvent; + use namada_core::voting_power::FractionalVotingPower; use namada_state::testing::TestWlStorage; use self::helpers::{default_event, default_total_stake, TallyParams}; diff --git a/crates/ethereum_bridge/src/protocol/validation/bridge_pool_roots.rs b/crates/ethereum_bridge/src/protocol/validation/bridge_pool_roots.rs index e178a1fa98..74adde0a07 100644 --- a/crates/ethereum_bridge/src/protocol/validation/bridge_pool_roots.rs +++ b/crates/ethereum_bridge/src/protocol/validation/bridge_pool_roots.rs @@ -1,7 +1,7 @@ //! Bridge pool roots validation. -use namada_core::types::keccak::keccak_hash; -use namada_core::types::storage::BlockHeight; +use namada_core::keccak::keccak_hash; +use namada_core::storage::BlockHeight; use namada_proof_of_stake::pos_queries::PosQueries; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_tx::{SignableEthMessage, Signed}; diff --git a/crates/ethereum_bridge/src/protocol/validation/ethereum_events.rs b/crates/ethereum_bridge/src/protocol/validation/ethereum_events.rs index a71d743c35..7c21d4746e 100644 --- a/crates/ethereum_bridge/src/protocol/validation/ethereum_events.rs +++ b/crates/ethereum_bridge/src/protocol/validation/ethereum_events.rs @@ -1,6 +1,6 @@ //! Ethereum events validation. -use namada_core::types::storage::BlockHeight; +use namada_core::storage::BlockHeight; use namada_proof_of_stake::pos_queries::PosQueries; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_tx::Signed; diff --git a/crates/ethereum_bridge/src/protocol/validation/validator_set_update.rs b/crates/ethereum_bridge/src/protocol/validation/validator_set_update.rs index 37cedea65a..508a878910 100644 --- a/crates/ethereum_bridge/src/protocol/validation/validator_set_update.rs +++ b/crates/ethereum_bridge/src/protocol/validation/validator_set_update.rs @@ -1,6 +1,6 @@ //! Validator set update validation. -use namada_core::types::storage::Epoch; +use namada_core::storage::Epoch; use namada_proof_of_stake::pos_queries::PosQueries; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_vote_ext::validator_set_update; @@ -132,8 +132,8 @@ where #[cfg(test)] mod tests { use assert_matches::assert_matches; - use namada_core::types::ethereum_events::EthAddress; - use namada_core::types::key::{common, RefTo}; + use namada_core::ethereum_events::EthAddress; + use namada_core::key::{common, RefTo}; use namada_vote_ext::validator_set_update::{EthAddrBook, VotingPowersMap}; use super::*; diff --git a/crates/ethereum_bridge/src/storage/bridge_pool.rs b/crates/ethereum_bridge/src/storage/bridge_pool.rs index 9fe34e7611..1ef4870df8 100644 --- a/crates/ethereum_bridge/src/storage/bridge_pool.rs +++ b/crates/ethereum_bridge/src/storage/bridge_pool.rs @@ -1,12 +1,12 @@ //! Tools for accessing the storage subspaces of the Ethereum //! bridge pool -use namada_core::types::eth_bridge_pool::Segments; -pub use namada_core::types::eth_bridge_pool::{ +use namada_core::eth_bridge_pool::Segments; +pub use namada_core::eth_bridge_pool::{ get_key_from_hash, get_pending_key, is_pending_transfer_key, BRIDGE_POOL_ADDRESS, }; -use namada_core::types::storage::{DbKeySeg, Key}; +use namada_core::storage::{DbKeySeg, Key}; pub use namada_state::merkle_tree::eth_bridge_pool::BridgePoolTree; /// Get the storage key for the root of the Merkle tree diff --git a/crates/ethereum_bridge/src/storage/eth_bridge_queries.rs b/crates/ethereum_bridge/src/storage/eth_bridge_queries.rs index 44b38a751a..1d4f56f117 100644 --- a/crates/ethereum_bridge/src/storage/eth_bridge_queries.rs +++ b/crates/ethereum_bridge/src/storage/eth_bridge_queries.rs @@ -1,17 +1,14 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::hints; -use namada_core::types::address::Address; -use namada_core::types::eth_abi::Encode; -use namada_core::types::eth_bridge_pool::PendingTransfer; -use namada_core::types::ethereum_events::{ +use namada_core::address::Address; +use namada_core::eth_abi::Encode; +use namada_core::eth_bridge_pool::PendingTransfer; +use namada_core::ethereum_events::{ EthAddress, EthereumEvent, GetEventNonce, TransferToEthereum, Uint, }; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::storage::{BlockHeight, Epoch, Key as StorageKey}; -use namada_core::types::token; -use namada_core::types::voting_power::{ - EthBridgeVotingPower, FractionalVotingPower, -}; +use namada_core::keccak::KeccakHash; +use namada_core::storage::{BlockHeight, Epoch, Key as StorageKey}; +use namada_core::voting_power::{EthBridgeVotingPower, FractionalVotingPower}; +use namada_core::{hints, token}; use namada_proof_of_stake::pos_queries::{ConsensusValidators, PosQueries}; use namada_proof_of_stake::storage::{ validator_eth_cold_key_handle, validator_eth_hot_key_handle, diff --git a/crates/ethereum_bridge/src/storage/mod.rs b/crates/ethereum_bridge/src/storage/mod.rs index db40a541b0..b4e4470944 100644 --- a/crates/ethereum_bridge/src/storage/mod.rs +++ b/crates/ethereum_bridge/src/storage/mod.rs @@ -9,8 +9,8 @@ pub mod vp; pub mod whitelist; pub mod wrapped_erc20s; -use namada_core::types::address::Address; -use namada_core::types::storage::{DbKeySeg, Key, KeySeg}; +use namada_core::address::Address; +use namada_core::storage::{DbKeySeg, Key, KeySeg}; pub use namada_parameters::native_erc20_key; use namada_parameters::storage::*; use namada_parameters::ADDRESS as PARAM_ADDRESS; @@ -68,9 +68,9 @@ pub fn bridge_contract_key() -> Key { #[cfg(test)] mod test { - use namada_core::types::address; - use namada_core::types::address::nam; - use namada_core::types::ethereum_events::testing::arbitrary_eth_address; + use namada_core::address; + use namada_core::address::nam; + use namada_core::ethereum_events::testing::arbitrary_eth_address; use super::*; diff --git a/crates/ethereum_bridge/src/storage/parameters.rs b/crates/ethereum_bridge/src/storage/parameters.rs index ead8b612f4..f075662313 100644 --- a/crates/ethereum_bridge/src/storage/parameters.rs +++ b/crates/ethereum_bridge/src/storage/parameters.rs @@ -3,10 +3,10 @@ use std::num::NonZeroU64; use eyre::{eyre, Result}; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::ethereum_structs; -use namada_core::types::storage::Key; -use namada_core::types::token::{DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES}; +use namada_core::ethereum_events::EthAddress; +use namada_core::ethereum_structs; +use namada_core::storage::Key; +use namada_core::token::{DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES}; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_storage::{StorageRead, StorageWrite}; use serde::{Deserialize, Serialize}; @@ -364,7 +364,7 @@ where #[cfg(test)] mod tests { use eyre::Result; - use namada_core::types::ethereum_events::EthAddress; + use namada_core::ethereum_events::EthAddress; use namada_state::testing::TestWlStorage; use super::*; diff --git a/crates/ethereum_bridge/src/storage/proof.rs b/crates/ethereum_bridge/src/storage/proof.rs index 92b377f70f..2f5895f363 100644 --- a/crates/ethereum_bridge/src/storage/proof.rs +++ b/crates/ethereum_bridge/src/storage/proof.rs @@ -4,12 +4,12 @@ use std::collections::HashMap; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use ethers::abi::Tokenizable; -use namada_core::types::eth_abi::Encode; -use namada_core::types::ethereum_events::Uint; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::key::{common, secp256k1}; -use namada_core::types::storage::Epoch; -use namada_core::types::{eth_abi, ethereum_structs}; +use namada_core::eth_abi::Encode; +use namada_core::ethereum_events::Uint; +use namada_core::keccak::KeccakHash; +use namada_core::key::{common, secp256k1}; +use namada_core::storage::Epoch; +use namada_core::{eth_abi, ethereum_structs}; use namada_vote_ext::validator_set_update::{ valset_upd_toks_to_hashes, EthAddrBook, VotingPowersMap, VotingPowersMapExt, }; @@ -123,8 +123,8 @@ mod test_ethbridge_proofs { //! Test ethereum bridge proofs. use assert_matches::assert_matches; - use namada_core::types::ethereum_events::EthAddress; - use namada_core::types::key; + use namada_core::ethereum_events::EthAddress; + use namada_core::key; use namada_tx::Signed; use super::*; diff --git a/crates/ethereum_bridge/src/storage/vote_tallies.rs b/crates/ethereum_bridge/src/storage/vote_tallies.rs index b597f15e1f..a6a6770253 100644 --- a/crates/ethereum_bridge/src/storage/vote_tallies.rs +++ b/crates/ethereum_bridge/src/storage/vote_tallies.rs @@ -4,11 +4,11 @@ use std::io::{Read, Write}; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::ethereum_events::{EthereumEvent, Uint}; -use namada_core::types::hash::Hash; -use namada_core::types::keccak::{keccak_hash, KeccakHash}; -use namada_core::types::storage::{BlockHeight, DbKeySeg, Epoch, Key}; +use namada_core::address::Address; +use namada_core::ethereum_events::{EthereumEvent, Uint}; +use namada_core::hash::Hash; +use namada_core::keccak::{keccak_hash, KeccakHash}; +use namada_core::storage::{BlockHeight, DbKeySeg, Epoch, Key}; use namada_macros::StorageKeys; use namada_vote_ext::validator_set_update::VotingPowersMap; diff --git a/crates/ethereum_bridge/src/storage/vp/bridge_pool.rs b/crates/ethereum_bridge/src/storage/vp/bridge_pool.rs index ec52cf37db..572ef84590 100644 --- a/crates/ethereum_bridge/src/storage/vp/bridge_pool.rs +++ b/crates/ethereum_bridge/src/storage/vp/bridge_pool.rs @@ -1,4 +1,4 @@ -use namada_core::types::ethereum_events::Uint; +use namada_core::ethereum_events::Uint; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use namada_storage::StorageWrite; use namada_trans_token::storage_key::balance_key; diff --git a/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs b/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs index f2ede582a1..9e79024991 100644 --- a/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs +++ b/crates/ethereum_bridge/src/storage/vp/ethereum_bridge.rs @@ -1,4 +1,4 @@ -use namada_core::types::hash::StorageHasher; +use namada_core::hash::StorageHasher; use namada_state::{DBIter, WlStorage, DB}; use namada_storage::StorageWrite; use namada_trans_token::storage_key::balance_key; diff --git a/crates/ethereum_bridge/src/storage/whitelist.rs b/crates/ethereum_bridge/src/storage/whitelist.rs index 7792f06484..349469a0d0 100644 --- a/crates/ethereum_bridge/src/storage/whitelist.rs +++ b/crates/ethereum_bridge/src/storage/whitelist.rs @@ -5,10 +5,10 @@ use std::str::FromStr; -use namada_core::types::eth_bridge_pool::erc20_token_address; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::storage; -use namada_core::types::storage::DbKeySeg; +use namada_core::eth_bridge_pool::erc20_token_address; +use namada_core::ethereum_events::EthAddress; +use namada_core::storage; +use namada_core::storage::DbKeySeg; use namada_trans_token::storage_key::{denom_key, minted_balance_key}; use super::prefix as ethbridge_key_prefix; @@ -16,7 +16,7 @@ use crate::ADDRESS as BRIDGE_ADDRESS; mod segments { //! Storage key segments under the token whitelist. - use namada_core::types::address::Address; + use namada_core::address::Address; use namada_macros::StorageKeys; /// The name of the main storage segment. @@ -118,7 +118,7 @@ pub fn is_cap_or_whitelisted_key(key: &storage::Key) -> bool { #[cfg(test)] mod tests { - use namada_core::types::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; + use namada_core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; use super::*; diff --git a/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs b/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs index 4976caea8f..551da0a8ad 100644 --- a/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs +++ b/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs @@ -1,12 +1,12 @@ //! Functionality for accessing the multitoken subspace use eyre::eyre; -use namada_core::types::address::{Address, InternalAddress}; -pub use namada_core::types::eth_bridge_pool::{ +use namada_core::address::{Address, InternalAddress}; +pub use namada_core::eth_bridge_pool::{ erc20_nut_address as nut, erc20_token_address as token, }; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::storage::{self, DbKeySeg}; +use namada_core::ethereum_events::EthAddress; +use namada_core::storage::{self, DbKeySeg}; use namada_trans_token::storage_key::{ balance_key, minted_balance_key, MINTED_STORAGE_KEY, }; @@ -110,9 +110,9 @@ mod test { use std::str::FromStr; use assert_matches::assert_matches; - use namada_core::types::address::{nam, Address}; - use namada_core::types::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; - use namada_core::types::storage::DbKeySeg; + use namada_core::address::{nam, Address}; + use namada_core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; + use namada_core::storage::DbKeySeg; use super::*; use crate::token::storage_key::BALANCE_STORAGE_KEY; diff --git a/crates/ethereum_bridge/src/test_utils.rs b/crates/ethereum_bridge/src/test_utils.rs index bc108be1d0..f823cc7f47 100644 --- a/crates/ethereum_bridge/src/test_utils.rs +++ b/crates/ethereum_bridge/src/test_utils.rs @@ -4,13 +4,13 @@ use std::collections::HashMap; use std::num::NonZeroU64; use namada_account::protocol_pk_key; -use namada_core::types::address::{self, wnam, Address}; -use namada_core::types::dec::Dec; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::key::{self, RefTo}; -use namada_core::types::storage::{BlockHeight, Key}; -use namada_core::types::token; +use namada_core::address::{self, wnam, Address}; +use namada_core::dec::Dec; +use namada_core::ethereum_events::EthAddress; +use namada_core::keccak::KeccakHash; +use namada_core::key::{self, RefTo}; +use namada_core::storage::{BlockHeight, Key}; +use namada_core::token; use namada_proof_of_stake::parameters::OwnedPosParams; use namada_proof_of_stake::pos_queries::PosQueries; use namada_proof_of_stake::types::GenesisValidator; diff --git a/crates/governance/src/cli/offline.rs b/crates/governance/src/cli/offline.rs index b89d9afe10..f55a3e0104 100644 --- a/crates/governance/src/cli/offline.rs +++ b/crates/governance/src/cli/offline.rs @@ -2,13 +2,13 @@ use std::collections::{BTreeMap, BTreeSet}; use std::fs::{File, ReadDir}; use std::path::PathBuf; +use namada_core::account::AccountPublicKeysMap; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt}; -use namada_core::types::account::AccountPublicKeysMap; -use namada_core::types::address::Address; -use namada_core::types::hash::Hash; -use namada_core::types::key::{common, RefTo, SigScheme}; -use namada_core::types::sign::SignatureIndex; -use namada_core::types::storage::Epoch; +use namada_core::hash::Hash; +use namada_core::key::{common, RefTo, SigScheme}; +use namada_core::sign::SignatureIndex; +use namada_core::storage::Epoch; use serde::{Deserialize, Serialize}; use super::validation::{is_valid_tally_epoch, ProposalValidation}; diff --git a/crates/governance/src/cli/onchain.rs b/crates/governance/src/cli/onchain.rs index db40a16eb1..a366022584 100644 --- a/crates/governance/src/cli/onchain.rs +++ b/crates/governance/src/cli/onchain.rs @@ -1,9 +1,9 @@ use std::collections::BTreeMap; use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::storage::Epoch; +use namada_core::token; use serde::{Deserialize, Serialize}; use super::validation::{ diff --git a/crates/governance/src/cli/validation.rs b/crates/governance/src/cli/validation.rs index db3222614d..07efc82e93 100644 --- a/crates/governance/src/cli/validation.rs +++ b/crates/governance/src/cli/validation.rs @@ -1,8 +1,8 @@ use std::collections::BTreeMap; -use namada_core::types::address::Address; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::storage::Epoch; +use namada_core::token; use thiserror::Error; use super::onchain::{PgfFunding, StewardsUpdate}; diff --git a/crates/governance/src/lib.rs b/crates/governance/src/lib.rs index 54d23b623b..49d6695a99 100644 --- a/crates/governance/src/lib.rs +++ b/crates/governance/src/lib.rs @@ -1,6 +1,6 @@ //! Governance library code -use namada_core::types::address::{self, Address}; +use namada_core::address::{self, Address}; /// governance CLI structures pub mod cli; diff --git a/crates/governance/src/parameters.rs b/crates/governance/src/parameters.rs index a93eefad43..b1537bf381 100644 --- a/crates/governance/src/parameters.rs +++ b/crates/governance/src/parameters.rs @@ -1,5 +1,5 @@ use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::token; +use namada_core::token; use namada_state::{StorageRead, StorageResult, StorageWrite}; use super::storage::keys as goverance_storage; diff --git a/crates/governance/src/pgf/cli/steward.rs b/crates/governance/src/pgf/cli/steward.rs index 6cfbf61b26..bac7482603 100644 --- a/crates/governance/src/pgf/cli/steward.rs +++ b/crates/governance/src/pgf/cli/steward.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; +use namada_core::address::Address; +use namada_core::dec::Dec; use serde::{Deserialize, Serialize}; use crate::pgf::REWARD_DISTRIBUTION_LIMIT; diff --git a/crates/governance/src/pgf/inflation.rs b/crates/governance/src/pgf/inflation.rs index 30391a622a..a057c8b479 100644 --- a/crates/governance/src/pgf/inflation.rs +++ b/crates/governance/src/pgf/inflation.rs @@ -1,7 +1,7 @@ //! PGF lib code. -use namada_core::types::address::Address; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::token; use namada_parameters::storage as params_storage; use namada_state::{ DBIter, StorageHasher, StorageRead, StorageResult, WlStorage, DB, diff --git a/crates/governance/src/pgf/mod.rs b/crates/governance/src/pgf/mod.rs index 77302b6ebd..22592625cf 100644 --- a/crates/governance/src/pgf/mod.rs +++ b/crates/governance/src/pgf/mod.rs @@ -1,6 +1,6 @@ //! Pgf library code -use namada_core::types::address::{Address, InternalAddress}; +use namada_core::address::{Address, InternalAddress}; /// Pgf CLI pub mod cli; diff --git a/crates/governance/src/pgf/parameters.rs b/crates/governance/src/pgf/parameters.rs index 416cbcb931..5e9bb34f34 100644 --- a/crates/governance/src/pgf/parameters.rs +++ b/crates/governance/src/pgf/parameters.rs @@ -1,8 +1,8 @@ use std::collections::BTreeSet; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; +use namada_core::dec::Dec; use namada_state::{StorageRead, StorageResult, StorageWrite}; use serde::{Deserialize, Serialize}; diff --git a/crates/governance/src/pgf/storage/keys.rs b/crates/governance/src/pgf/storage/keys.rs index 5d581d27a7..3d856f066b 100644 --- a/crates/governance/src/pgf/storage/keys.rs +++ b/crates/governance/src/pgf/storage/keys.rs @@ -1,5 +1,5 @@ -use namada_core::types::address::Address; -use namada_core::types::storage::{DbKeySeg, Key, KeySeg}; +use namada_core::address::Address; +use namada_core::storage::{DbKeySeg, Key, KeySeg}; use namada_macros::StorageKeys; use namada_state::collections::{lazy_map, LazyCollection, LazyMap}; diff --git a/crates/governance/src/pgf/storage/mod.rs b/crates/governance/src/pgf/storage/mod.rs index f965da157d..fd8190dd51 100644 --- a/crates/governance/src/pgf/storage/mod.rs +++ b/crates/governance/src/pgf/storage/mod.rs @@ -7,8 +7,8 @@ pub mod steward; use std::collections::HashMap; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; +use namada_core::address::Address; +use namada_core::dec::Dec; use namada_state::{StorageRead, StorageResult, StorageWrite}; use crate::pgf::parameters::PgfParameters; diff --git a/crates/governance/src/pgf/storage/steward.rs b/crates/governance/src/pgf/storage/steward.rs index ce6855a130..973c33ed78 100644 --- a/crates/governance/src/pgf/storage/steward.rs +++ b/crates/governance/src/pgf/storage/steward.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; +use namada_core::address::Address; +use namada_core::dec::Dec; use crate::pgf::REWARD_DISTRIBUTION_LIMIT; diff --git a/crates/governance/src/storage/keys.rs b/crates/governance/src/storage/keys.rs index 5eed69cbba..ded546af78 100644 --- a/crates/governance/src/storage/keys.rs +++ b/crates/governance/src/storage/keys.rs @@ -1,5 +1,5 @@ -use namada_core::types::address::Address; -use namada_core::types::storage::{DbKeySeg, Key, KeySeg}; +use namada_core::address::Address; +use namada_core::storage::{DbKeySeg, Key, KeySeg}; use namada_macros::StorageKeys; use crate::ADDRESS; diff --git a/crates/governance/src/storage/mod.rs b/crates/governance/src/storage/mod.rs index 4feaeba578..bc8c36a4ea 100644 --- a/crates/governance/src/storage/mod.rs +++ b/crates/governance/src/storage/mod.rs @@ -9,9 +9,9 @@ pub mod vote; use std::collections::BTreeMap; +use namada_core::address::Address; use namada_core::borsh::BorshDeserialize; -use namada_core::types::address::Address; -use namada_core::types::storage::Epoch; +use namada_core::storage::Epoch; use namada_state::{ iter_prefix, StorageError, StorageRead, StorageResult, StorageWrite, }; diff --git a/crates/governance/src/storage/proposal.rs b/crates/governance/src/storage/proposal.rs index f88bf24919..fcc07140bc 100644 --- a/crates/governance/src/storage/proposal.rs +++ b/crates/governance/src/storage/proposal.rs @@ -2,10 +2,10 @@ use std::collections::{BTreeMap, BTreeSet}; use std::fmt::Display; use borsh::{BorshDeserialize, BorshSerialize}; +use namada_core::address::Address; +use namada_core::hash::Hash; use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId}; -use namada_core::types::address::Address; -use namada_core::types::hash::Hash; -use namada_core::types::storage::Epoch; +use namada_core::storage::Epoch; use namada_trans_token::Amount; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -565,10 +565,10 @@ impl Display for StorageProposal { #[cfg(any(test, feature = "testing"))] /// Testing helpers and and strategies for governance proposals pub mod testing { - use namada_core::types::address::testing::arb_non_internal_address; - use namada_core::types::hash::testing::arb_hash; - use namada_core::types::storage::testing::arb_epoch; - use namada_core::types::token::testing::arb_amount; + use namada_core::address::testing::arb_non_internal_address; + use namada_core::hash::testing::arb_hash; + use namada_core::storage::testing::arb_epoch; + use namada_core::token::testing::arb_amount; use proptest::prelude::*; use proptest::{collection, option, prop_compose}; diff --git a/crates/governance/src/utils.rs b/crates/governance/src/utils.rs index cf380fd82f..4619c90473 100644 --- a/crates/governance/src/utils.rs +++ b/crates/governance/src/utils.rs @@ -1,11 +1,11 @@ use std::collections::HashMap; use std::fmt::Display; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::dec::Dec; +use namada_core::storage::Epoch; +use namada_core::token; use super::cli::offline::OfflineVote; use super::storage::proposal::ProposalType; @@ -452,7 +452,7 @@ pub fn is_valid_validator_voting_period( mod test { use std::ops::{Add, Sub}; - use namada_core::types::address; + use namada_core::address; use super::*; diff --git a/crates/ibc/src/actions.rs b/crates/ibc/src/actions.rs index eed8f284ae..9a999e6151 100644 --- a/crates/ibc/src/actions.rs +++ b/crates/ibc/src/actions.rs @@ -3,18 +3,18 @@ use std::cell::RefCell; use std::rc::Rc; +use namada_core::address::{Address, InternalAddress}; +use namada_core::hash::Hash; use namada_core::ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use namada_core::ibc::apps::transfer::types::packet::PacketData; use namada_core::ibc::apps::transfer::types::PrefixedCoin; use namada_core::ibc::core::channel::types::timeout::TimeoutHeight; use namada_core::ibc::primitives::Msg; +use namada_core::ibc::IbcEvent; +use namada_core::storage::Epochs; use namada_core::tendermint::Time as TmTime; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::hash::Hash; -use namada_core::types::ibc::IbcEvent; -use namada_core::types::storage::Epochs; -use namada_core::types::time::DateTimeUtc; -use namada_core::types::token::DenominatedAmount; +use namada_core::time::DateTimeUtc; +use namada_core::token::DenominatedAmount; use namada_governance::storage::proposal::PGFIbcTarget; use namada_parameters::read_epoch_duration_parameter; use namada_state::wl_storage::{PrefixIter, WriteLogAndStorage}; diff --git a/crates/ibc/src/context/common.rs b/crates/ibc/src/context/common.rs index b5b761bd86..9f335c6318 100644 --- a/crates/ibc/src/context/common.rs +++ b/crates/ibc/src/context/common.rs @@ -24,9 +24,9 @@ use namada_core::ibc::core::host::types::identifiers::{ }; use namada_core::ibc::primitives::proto::{Any, Protobuf}; use namada_core::ibc::primitives::Timestamp; +use namada_core::storage::{BlockHeight, Key}; use namada_core::tendermint::Time as TmTime; -use namada_core::types::storage::{BlockHeight, Key}; -use namada_core::types::time::DurationSecs; +use namada_core::time::DurationSecs; use namada_parameters::storage::get_max_expected_time_per_block_key; use prost::Message; use sha2::Digest; diff --git a/crates/ibc/src/context/storage.rs b/crates/ibc/src/context/storage.rs index 05ab8121ef..c9d8218bd1 100644 --- a/crates/ibc/src/context/storage.rs +++ b/crates/ibc/src/context/storage.rs @@ -1,9 +1,9 @@ //! IBC storage context pub use ics23::ProofSpec; -use namada_core::types::address::Address; -use namada_core::types::ibc::IbcEvent; -use namada_core::types::token::DenominatedAmount; +use namada_core::address::Address; +use namada_core::ibc::IbcEvent; +use namada_core::token::DenominatedAmount; use namada_storage::{Error, StorageRead, StorageWrite}; /// IBC context trait to be implemented in integration that can read and write diff --git a/crates/ibc/src/context/token_transfer.rs b/crates/ibc/src/context/token_transfer.rs index 4b3e333ec4..caaa945015 100644 --- a/crates/ibc/src/context/token_transfer.rs +++ b/crates/ibc/src/context/token_transfer.rs @@ -3,6 +3,7 @@ use std::cell::RefCell; use std::rc::Rc; +use namada_core::address::{Address, InternalAddress}; use namada_core::ibc::apps::transfer::context::{ TokenTransferExecutionContext, TokenTransferValidationContext, }; @@ -11,9 +12,8 @@ use namada_core::ibc::apps::transfer::types::{PrefixedCoin, PrefixedDenom}; use namada_core::ibc::core::channel::types::error::ChannelError; use namada_core::ibc::core::handler::types::error::ContextError; use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId}; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::token; -use namada_core::types::uint::Uint; +use namada_core::token; +use namada_core::uint::Uint; use namada_trans_token::read_denom; use super::common::IbcCommonContext; diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index bea1b2ba4a..fe31b7177f 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -18,6 +18,7 @@ pub use context::token_transfer::TokenTransferContext; pub use context::transfer_mod::{ModuleWrapper, TransferModule}; use context::IbcContext; pub use context::ValidationParams; +use namada_core::address::{Address, MASP}; use namada_core::ibc::apps::transfer::handler::{ send_transfer_execute, send_transfer_validate, }; @@ -36,12 +37,7 @@ use namada_core::ibc::core::router::types::error::RouterError; use namada_core::ibc::core::router::types::module::ModuleId; use namada_core::ibc::primitives::proto::Any; pub use namada_core::ibc::*; -use namada_core::types::address::{Address, MASP}; -use namada_core::types::ibc::{ - get_shielded_transfer, is_ibc_denom, MsgShieldedTransfer, - EVENT_TYPE_DENOM_TRACE, EVENT_TYPE_PACKET, -}; -use namada_core::types::masp::PaymentAddress; +use namada_core::masp::PaymentAddress; use prost::Message; use thiserror::Error; diff --git a/crates/ibc/src/storage.rs b/crates/ibc/src/storage.rs index 2137a6e6fa..c4aafc947d 100644 --- a/crates/ibc/src/storage.rs +++ b/crates/ibc/src/storage.rs @@ -2,6 +2,7 @@ use std::str::FromStr; +use namada_core::address::{Address, InternalAddress, HASH_LEN, SHA_HASH_LEN}; use namada_core::ibc::core::client::types::Height; use namada_core::ibc::core::host::types::identifiers::{ ChannelId, ClientId, ConnectionId, PortId, Sequence, @@ -11,11 +12,8 @@ use namada_core::ibc::core::host::types::path::{ ClientStatePath, CommitmentPath, ConnectionPath, Path, PortPath, ReceiptPath, SeqAckPath, SeqRecvPath, SeqSendPath, }; -use namada_core::types::address::{ - Address, InternalAddress, HASH_LEN, SHA_HASH_LEN, -}; -use namada_core::types::ibc::IbcTokenHash; -use namada_core::types::storage::{DbKeySeg, Key, KeySeg}; +use namada_core::ibc::IbcTokenHash; +use namada_core::storage::{DbKeySeg, Key, KeySeg}; use sha2::{Digest, Sha256}; use thiserror::Error; @@ -29,7 +27,7 @@ const DENOM: &str = "ibc_denom"; #[derive(Error, Debug)] pub enum Error { #[error("Storage key error: {0}")] - StorageKey(namada_core::types::storage::Error), + StorageKey(namada_core::storage::Error), #[error("Invalid Key: {0}")] InvalidKey(String), #[error("Port capability error: {0}")] diff --git a/crates/light_sdk/src/reading/asynchronous/account.rs b/crates/light_sdk/src/reading/asynchronous/account.rs index 8648ca7059..24b1c34e13 100644 --- a/crates/light_sdk/src/reading/asynchronous/account.rs +++ b/crates/light_sdk/src/reading/asynchronous/account.rs @@ -1,5 +1,5 @@ use namada_sdk::account::Account; -use namada_sdk::types::key::common; +use namada_sdk::key::common; use super::*; diff --git a/crates/light_sdk/src/reading/asynchronous/mod.rs b/crates/light_sdk/src/reading/asynchronous/mod.rs index 441d88746c..0b40764955 100644 --- a/crates/light_sdk/src/reading/asynchronous/mod.rs +++ b/crates/light_sdk/src/reading/asynchronous/mod.rs @@ -1,13 +1,13 @@ use std::str::FromStr; +use namada_sdk::address::Address; use namada_sdk::error::{EncodingError, Error}; use namada_sdk::io::StdIo; use namada_sdk::queries::RPC; use namada_sdk::rpc; use namada_sdk::state::LastBlock; -use namada_sdk::types::address::Address; -use namada_sdk::types::storage::BlockResults; -use namada_sdk::types::token::{self, DenominatedAmount}; +use namada_sdk::storage::BlockResults; +use namada_sdk::token::{self, DenominatedAmount}; use tendermint_config::net::Address as TendermintAddress; use tendermint_rpc::HttpClient; diff --git a/crates/light_sdk/src/reading/asynchronous/pos.rs b/crates/light_sdk/src/reading/asynchronous/pos.rs index 9c28beb957..0885fdcc39 100644 --- a/crates/light_sdk/src/reading/asynchronous/pos.rs +++ b/crates/light_sdk/src/reading/asynchronous/pos.rs @@ -1,13 +1,13 @@ use std::collections::{BTreeSet, HashMap, HashSet}; +use namada_sdk::address::Address; +use namada_sdk::key::common; use namada_sdk::proof_of_stake::types::{ BondsAndUnbondsDetails, CommissionPair, ValidatorMetaData, ValidatorState, }; use namada_sdk::proof_of_stake::PosParams; use namada_sdk::queries::vp::pos::EnrichedBondsAndUnbondsDetails; -use namada_sdk::types::address::Address; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::{BlockHeight, Epoch}; +use namada_sdk::storage::{BlockHeight, Epoch}; use super::*; diff --git a/crates/light_sdk/src/reading/blocking/account.rs b/crates/light_sdk/src/reading/blocking/account.rs index 321178e62c..eb5bccc21d 100644 --- a/crates/light_sdk/src/reading/blocking/account.rs +++ b/crates/light_sdk/src/reading/blocking/account.rs @@ -1,5 +1,5 @@ use namada_sdk::account::Account; -use namada_sdk::types::key::common; +use namada_sdk::key::common; use super::*; diff --git a/crates/light_sdk/src/reading/blocking/mod.rs b/crates/light_sdk/src/reading/blocking/mod.rs index 5f7e79ca62..a70b4633e4 100644 --- a/crates/light_sdk/src/reading/blocking/mod.rs +++ b/crates/light_sdk/src/reading/blocking/mod.rs @@ -1,13 +1,13 @@ use std::str::FromStr; +use namada_sdk::address::Address; use namada_sdk::error::{EncodingError, Error}; use namada_sdk::io::StdIo; use namada_sdk::queries::RPC; use namada_sdk::rpc; use namada_sdk::state::LastBlock; -use namada_sdk::types::address::Address; -use namada_sdk::types::storage::BlockResults; -use namada_sdk::types::token::{self, DenominatedAmount}; +use namada_sdk::storage::BlockResults; +use namada_sdk::token::{self, DenominatedAmount}; use tendermint_config::net::Address as TendermintAddress; use tendermint_rpc::HttpClient; use tokio::runtime::Runtime; diff --git a/crates/light_sdk/src/reading/blocking/pos.rs b/crates/light_sdk/src/reading/blocking/pos.rs index a03aad078d..4a070d36f8 100644 --- a/crates/light_sdk/src/reading/blocking/pos.rs +++ b/crates/light_sdk/src/reading/blocking/pos.rs @@ -1,13 +1,13 @@ use std::collections::{BTreeSet, HashMap, HashSet}; +use namada_sdk::address::Address; +use namada_sdk::key::common; use namada_sdk::proof_of_stake::types::{ BondsAndUnbondsDetails, CommissionPair, ValidatorMetaData, ValidatorState, }; use namada_sdk::proof_of_stake::PosParams; use namada_sdk::queries::vp::pos::EnrichedBondsAndUnbondsDetails; -use namada_sdk::types::address::Address; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::{BlockHeight, Epoch}; +use namada_sdk::storage::{BlockHeight, Epoch}; use super::*; diff --git a/crates/light_sdk/src/transaction/account.rs b/crates/light_sdk/src/transaction/account.rs index e4d30ece2c..fce8794bb6 100644 --- a/crates/light_sdk/src/transaction/account.rs +++ b/crates/light_sdk/src/transaction/account.rs @@ -1,10 +1,10 @@ +use namada_sdk::address::Address; +use namada_sdk::hash::Hash; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; +use namada_sdk::token::DenominatedAmount; use namada_sdk::tx::data::GasLimit; use namada_sdk::tx::{Signature, Tx, TxError}; -use namada_sdk::types::address::Address; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::token::DenominatedAmount; use super::{attach_fee, attach_fee_signature, GlobalArgs}; use crate::transaction; diff --git a/crates/light_sdk/src/transaction/bridge.rs b/crates/light_sdk/src/transaction/bridge.rs index e365a8ad89..c1e01238c5 100644 --- a/crates/light_sdk/src/transaction/bridge.rs +++ b/crates/light_sdk/src/transaction/bridge.rs @@ -1,11 +1,11 @@ +use namada_sdk::address::Address; +pub use namada_sdk::eth_bridge_pool::{GasFee, TransferToEthereum}; +use namada_sdk::hash::Hash; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; +use namada_sdk::token::DenominatedAmount; use namada_sdk::tx::data::GasLimit; use namada_sdk::tx::{Signature, Tx, TxError}; -use namada_sdk::types::address::Address; -pub use namada_sdk::types::eth_bridge_pool::{GasFee, TransferToEthereum}; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::token::DenominatedAmount; use super::{attach_fee, attach_fee_signature, GlobalArgs}; use crate::transaction; @@ -23,10 +23,7 @@ impl BridgeTransfer { args: GlobalArgs, ) -> Self { let pending_transfer = - namada_sdk::types::eth_bridge_pool::PendingTransfer { - transfer, - gas_fee, - }; + namada_sdk::eth_bridge_pool::PendingTransfer { transfer, gas_fee }; Self(transaction::build_tx( args, diff --git a/crates/light_sdk/src/transaction/governance.rs b/crates/light_sdk/src/transaction/governance.rs index 60ef066e24..a0ac5e96cc 100644 --- a/crates/light_sdk/src/transaction/governance.rs +++ b/crates/light_sdk/src/transaction/governance.rs @@ -1,11 +1,11 @@ +use namada_sdk::address::Address; use namada_sdk::governance::{ProposalType, ProposalVote}; +use namada_sdk::hash::Hash; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; +use namada_sdk::token::DenominatedAmount; use namada_sdk::tx::data::GasLimit; use namada_sdk::tx::{Signature, Tx, TxError}; -use namada_sdk::types::address::Address; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::token::DenominatedAmount; use super::{attach_fee, attach_fee_signature, GlobalArgs}; use crate::transaction; diff --git a/crates/light_sdk/src/transaction/ibc.rs b/crates/light_sdk/src/transaction/ibc.rs index 016817820b..2ecc9b3825 100644 --- a/crates/light_sdk/src/transaction/ibc.rs +++ b/crates/light_sdk/src/transaction/ibc.rs @@ -1,15 +1,15 @@ use std::str::FromStr; +use namada_sdk::address::Address; +use namada_sdk::hash::Hash; pub use namada_sdk::ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use namada_sdk::ibc::primitives::Msg; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; +use namada_sdk::time::DateTimeUtc; +use namada_sdk::token::DenominatedAmount; use namada_sdk::tx::data::GasLimit; use namada_sdk::tx::{Signature, Tx, TxError}; -use namada_sdk::types::address::Address; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::time::DateTimeUtc; -use namada_sdk::types::token::DenominatedAmount; use super::{attach_fee, attach_fee_signature, GlobalArgs}; use crate::transaction; diff --git a/crates/light_sdk/src/transaction/mod.rs b/crates/light_sdk/src/transaction/mod.rs index cf44997e37..598a665381 100644 --- a/crates/light_sdk/src/transaction/mod.rs +++ b/crates/light_sdk/src/transaction/mod.rs @@ -2,15 +2,15 @@ use std::collections::BTreeMap; use std::str::FromStr; use borsh::BorshSerialize; +use namada_sdk::address::Address; +use namada_sdk::chain::ChainId; +use namada_sdk::hash::Hash; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; +use namada_sdk::time::DateTimeUtc; +use namada_sdk::token::DenominatedAmount; use namada_sdk::tx::data::{Fee, GasLimit}; use namada_sdk::tx::{Section, Signature, Signer, Tx}; -use namada_sdk::types::address::Address; -use namada_sdk::types::chain::ChainId; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::time::DateTimeUtc; -use namada_sdk::types::token::DenominatedAmount; pub mod account; pub mod bridge; diff --git a/crates/light_sdk/src/transaction/pgf.rs b/crates/light_sdk/src/transaction/pgf.rs index 572503573d..48afb38a68 100644 --- a/crates/light_sdk/src/transaction/pgf.rs +++ b/crates/light_sdk/src/transaction/pgf.rs @@ -1,13 +1,13 @@ use std::collections::HashMap; +use namada_sdk::address::Address; +use namada_sdk::dec::Dec; +use namada_sdk::hash::Hash; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; +use namada_sdk::token::DenominatedAmount; use namada_sdk::tx::data::GasLimit; use namada_sdk::tx::{Signature, Tx, TxError}; -use namada_sdk::types::address::Address; -use namada_sdk::types::dec::Dec; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::token::DenominatedAmount; use super::{attach_fee, attach_fee_signature, GlobalArgs}; use crate::transaction; diff --git a/crates/light_sdk/src/transaction/pos.rs b/crates/light_sdk/src/transaction/pos.rs index 5b9ed197cb..39ae504c7a 100644 --- a/crates/light_sdk/src/transaction/pos.rs +++ b/crates/light_sdk/src/transaction/pos.rs @@ -1,13 +1,13 @@ +use namada_sdk::address::Address; +use namada_sdk::dec::Dec; +use namada_sdk::hash::Hash; +use namada_sdk::key::{common, secp256k1}; +use namada_sdk::storage::Epoch; +use namada_sdk::token; +use namada_sdk::token::{Amount, DenominatedAmount}; use namada_sdk::tx::data::pos::Redelegation; use namada_sdk::tx::data::GasLimit; use namada_sdk::tx::{Signature, Tx, TxError}; -use namada_sdk::types::address::Address; -use namada_sdk::types::dec::Dec; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::{common, secp256k1}; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::token; -use namada_sdk::types::token::{Amount, DenominatedAmount}; use super::{attach_fee, attach_fee_signature, GlobalArgs}; use crate::transaction; diff --git a/crates/light_sdk/src/transaction/transfer.rs b/crates/light_sdk/src/transaction/transfer.rs index 1c749819e6..b548665086 100644 --- a/crates/light_sdk/src/transaction/transfer.rs +++ b/crates/light_sdk/src/transaction/transfer.rs @@ -1,11 +1,11 @@ use borsh_ext::BorshSerializeExt; +use namada_sdk::address::Address; +use namada_sdk::hash::Hash; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; +use namada_sdk::token::DenominatedAmount; use namada_sdk::tx::data::GasLimit; use namada_sdk::tx::{Signature, Tx, TxError}; -use namada_sdk::types::address::Address; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; -use namada_sdk::types::token::DenominatedAmount; use super::{attach_fee, attach_fee_signature, GlobalArgs}; use crate::transaction; @@ -27,7 +27,7 @@ impl Transfer { shielded: Option, args: GlobalArgs, ) -> Self { - let init_proposal = namada_sdk::types::token::Transfer { + let init_proposal = namada_sdk::token::Transfer { source, target, token, diff --git a/crates/light_sdk/src/transaction/wrapper.rs b/crates/light_sdk/src/transaction/wrapper.rs index 8f396cb144..fbc1ea953e 100644 --- a/crates/light_sdk/src/transaction/wrapper.rs +++ b/crates/light_sdk/src/transaction/wrapper.rs @@ -1,8 +1,8 @@ +use namada_sdk::hash::Hash; +use namada_sdk::key::common; +use namada_sdk::storage::Epoch; use namada_sdk::tx::data::{Fee, GasLimit}; use namada_sdk::tx::{Section, Signature, Signer, Tx, TxError}; -use namada_sdk::types::hash::Hash; -use namada_sdk::types::key::common; -use namada_sdk::types::storage::Epoch; #[allow(missing_docs)] pub struct Wrapper(Tx); diff --git a/crates/macros/src/lib.rs b/crates/macros/src/lib.rs index c3af2fd82f..bb362a422f 100644 --- a/crates/macros/src/lib.rs +++ b/crates/macros/src/lib.rs @@ -269,10 +269,10 @@ fn derive_storage_keys_inner(struct_def: TokenStream2) -> TokenStream2 { let id = syn::Ident::new(&id, ident.span()); quote! { #[allow(missing_docs)] - pub fn #id(key: &namada_core::types::storage::Key, address: &Address) -> bool { + pub fn #id(key: &namada_core::storage::Key, address: &Address) -> bool { matches!(&key.segments[..], [ - namada_core::types::storage::DbKeySeg::AddressSeg(a), - namada_core::types::storage::DbKeySeg::StringSeg(#ident), + namada_core::storage::DbKeySeg::AddressSeg(a), + namada_core::storage::DbKeySeg::StringSeg(#ident), ] if a == address && #ident == #struct_def_ident::VALUES.#ident) } } @@ -282,11 +282,11 @@ fn derive_storage_keys_inner(struct_def: TokenStream2) -> TokenStream2 { let id = syn::Ident::new(&id, ident.span()); quote! { #[allow(missing_docs)] - pub fn #id(address: Address) -> namada_core::types::storage::Key { - namada_core::types::storage::Key { + pub fn #id(address: Address) -> namada_core::storage::Key { + namada_core::storage::Key { segments: vec![ - namada_core::types::storage::DbKeySeg::AddressSeg(address), - namada_core::types::storage::DbKeySeg::StringSeg(#struct_def_ident::VALUES.#ident.to_string()), + namada_core::storage::DbKeySeg::AddressSeg(address), + namada_core::storage::DbKeySeg::StringSeg(#struct_def_ident::VALUES.#ident.to_string()), ], } } @@ -403,66 +403,66 @@ mod test_proc_macros { }; } #[allow(missing_docs)] - pub fn is_bird_key_at_addr(key: &namada_core::types::storage::Key, address: &Address) -> bool { + pub fn is_bird_key_at_addr(key: &namada_core::storage::Key, address: &Address) -> bool { matches!(&key.segments[..], [ - namada_core::types::storage::DbKeySeg::AddressSeg(a), - namada_core::types::storage::DbKeySeg::StringSeg(bird), + namada_core::storage::DbKeySeg::AddressSeg(a), + namada_core::storage::DbKeySeg::StringSeg(bird), ] if a == address && bird == Keys::VALUES.bird) } #[allow(missing_docs)] - pub fn get_bird_key_at_addr(address: Address) -> namada_core::types::storage::Key { - namada_core::types::storage::Key { + pub fn get_bird_key_at_addr(address: Address) -> namada_core::storage::Key { + namada_core::storage::Key { segments: vec![ - namada_core::types::storage::DbKeySeg::AddressSeg(address), - namada_core::types::storage::DbKeySeg::StringSeg(Keys::VALUES.bird.to_string()), + namada_core::storage::DbKeySeg::AddressSeg(address), + namada_core::storage::DbKeySeg::StringSeg(Keys::VALUES.bird.to_string()), ], } } #[allow(missing_docs)] - pub fn is_is_key_at_addr(key: &namada_core::types::storage::Key, address: &Address) -> bool { + pub fn is_is_key_at_addr(key: &namada_core::storage::Key, address: &Address) -> bool { matches!(&key.segments[..], [ - namada_core::types::storage::DbKeySeg::AddressSeg(a), - namada_core::types::storage::DbKeySeg::StringSeg(is), + namada_core::storage::DbKeySeg::AddressSeg(a), + namada_core::storage::DbKeySeg::StringSeg(is), ] if a == address && is == Keys::VALUES.is) } #[allow(missing_docs)] - pub fn get_is_key_at_addr(address: Address) -> namada_core::types::storage::Key { - namada_core::types::storage::Key { + pub fn get_is_key_at_addr(address: Address) -> namada_core::storage::Key { + namada_core::storage::Key { segments: vec![ - namada_core::types::storage::DbKeySeg::AddressSeg(address), - namada_core::types::storage::DbKeySeg::StringSeg(Keys::VALUES.is.to_string()), + namada_core::storage::DbKeySeg::AddressSeg(address), + namada_core::storage::DbKeySeg::StringSeg(Keys::VALUES.is.to_string()), ], } } #[allow(missing_docs)] - pub fn is_the_key_at_addr(key: &namada_core::types::storage::Key, address: &Address) -> bool { + pub fn is_the_key_at_addr(key: &namada_core::storage::Key, address: &Address) -> bool { matches!(&key.segments[..], [ - namada_core::types::storage::DbKeySeg::AddressSeg(a), - namada_core::types::storage::DbKeySeg::StringSeg(the), + namada_core::storage::DbKeySeg::AddressSeg(a), + namada_core::storage::DbKeySeg::StringSeg(the), ] if a == address && the == Keys::VALUES.the) } #[allow(missing_docs)] - pub fn get_the_key_at_addr(address: Address) -> namada_core::types::storage::Key { - namada_core::types::storage::Key { + pub fn get_the_key_at_addr(address: Address) -> namada_core::storage::Key { + namada_core::storage::Key { segments: vec![ - namada_core::types::storage::DbKeySeg::AddressSeg(address), - namada_core::types::storage::DbKeySeg::StringSeg(Keys::VALUES.the.to_string()), + namada_core::storage::DbKeySeg::AddressSeg(address), + namada_core::storage::DbKeySeg::StringSeg(Keys::VALUES.the.to_string()), ], } } #[allow(missing_docs)] - pub fn is_word_key_at_addr(key: &namada_core::types::storage::Key, address: &Address) -> bool { + pub fn is_word_key_at_addr(key: &namada_core::storage::Key, address: &Address) -> bool { matches!(&key.segments[..], [ - namada_core::types::storage::DbKeySeg::AddressSeg(a), - namada_core::types::storage::DbKeySeg::StringSeg(word), + namada_core::storage::DbKeySeg::AddressSeg(a), + namada_core::storage::DbKeySeg::StringSeg(word), ] if a == address && word == Keys::VALUES.word) } #[allow(missing_docs)] - pub fn get_word_key_at_addr(address: Address) -> namada_core::types::storage::Key { - namada_core::types::storage::Key { + pub fn get_word_key_at_addr(address: Address) -> namada_core::storage::Key { + namada_core::storage::Key { segments: vec![ - namada_core::types::storage::DbKeySeg::AddressSeg(address), - namada_core::types::storage::DbKeySeg::StringSeg(Keys::VALUES.word.to_string()), + namada_core::storage::DbKeySeg::AddressSeg(address), + namada_core::storage::DbKeySeg::StringSeg(Keys::VALUES.word.to_string()), ], } } @@ -531,34 +531,34 @@ mod test_proc_macros { }; } #[allow(missing_docs)] - pub fn is_param1_key_at_addr(key: &namada_core::types::storage::Key, address: &Address) -> bool { + pub fn is_param1_key_at_addr(key: &namada_core::storage::Key, address: &Address) -> bool { matches!(&key.segments[..], [ - namada_core::types::storage::DbKeySeg::AddressSeg(a), - namada_core::types::storage::DbKeySeg::StringSeg(param1), + namada_core::storage::DbKeySeg::AddressSeg(a), + namada_core::storage::DbKeySeg::StringSeg(param1), ] if a == address && param1 == Keys::VALUES.param1) } #[allow(missing_docs)] - pub fn get_param1_key_at_addr(address: Address) -> namada_core::types::storage::Key { - namada_core::types::storage::Key { + pub fn get_param1_key_at_addr(address: Address) -> namada_core::storage::Key { + namada_core::storage::Key { segments: vec![ - namada_core::types::storage::DbKeySeg::AddressSeg(address), - namada_core::types::storage::DbKeySeg::StringSeg(Keys::VALUES.param1.to_string()), + namada_core::storage::DbKeySeg::AddressSeg(address), + namada_core::storage::DbKeySeg::StringSeg(Keys::VALUES.param1.to_string()), ], } } #[allow(missing_docs)] - pub fn is_param2_key_at_addr(key: &namada_core::types::storage::Key, address: &Address) -> bool { + pub fn is_param2_key_at_addr(key: &namada_core::storage::Key, address: &Address) -> bool { matches!(&key.segments[..], [ - namada_core::types::storage::DbKeySeg::AddressSeg(a), - namada_core::types::storage::DbKeySeg::StringSeg(param2), + namada_core::storage::DbKeySeg::AddressSeg(a), + namada_core::storage::DbKeySeg::StringSeg(param2), ] if a == address && param2 == Keys::VALUES.param2) } #[allow(missing_docs)] - pub fn get_param2_key_at_addr(address: Address) -> namada_core::types::storage::Key { - namada_core::types::storage::Key { + pub fn get_param2_key_at_addr(address: Address) -> namada_core::storage::Key { + namada_core::storage::Key { segments: vec![ - namada_core::types::storage::DbKeySeg::AddressSeg(address), - namada_core::types::storage::DbKeySeg::StringSeg(Keys::VALUES.param2.to_string()), + namada_core::storage::DbKeySeg::AddressSeg(address), + namada_core::storage::DbKeySeg::StringSeg(Keys::VALUES.param2.to_string()), ], } } diff --git a/crates/merkle_tree/src/eth_bridge_pool.rs b/crates/merkle_tree/src/eth_bridge_pool.rs index b8c30a36aa..32d0f0462c 100644 --- a/crates/merkle_tree/src/eth_bridge_pool.rs +++ b/crates/merkle_tree/src/eth_bridge_pool.rs @@ -4,12 +4,12 @@ use std::collections::{BTreeMap, BTreeSet}; use eyre::eyre; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::eth_abi::{Encode, Token}; -use namada_core::types::eth_bridge_pool::PendingTransfer; -use namada_core::types::hash::Hash; -use namada_core::types::keccak::{keccak_hash, KeccakHash}; -use namada_core::types::storage; -use namada_core::types::storage::{BlockHeight, DbKeySeg}; +use namada_core::eth_abi::{Encode, Token}; +use namada_core::eth_bridge_pool::PendingTransfer; +use namada_core::hash::Hash; +use namada_core::keccak::{keccak_hash, KeccakHash}; +use namada_core::storage; +use namada_core::storage::{BlockHeight, DbKeySeg}; #[derive(thiserror::Error, Debug)] #[error(transparent)] @@ -373,12 +373,12 @@ mod test_bridge_pool_tree { use assert_matches::assert_matches; use itertools::Itertools; - use namada_core::types::address::{nam, Address}; - use namada_core::types::eth_bridge_pool::{ + use namada_core::address::{nam, Address}; + use namada_core::eth_bridge_pool::{ GasFee, TransferToEthereum, TransferToEthereumKind, }; - use namada_core::types::ethereum_events::EthAddress; - use namada_core::types::storage::Key; + use namada_core::ethereum_events::EthAddress; + use namada_core::storage::Key; use proptest::prelude::*; use super::*; diff --git a/crates/merkle_tree/src/ics23_specs.rs b/crates/merkle_tree/src/ics23_specs.rs index 130735d33a..c907b6b71b 100644 --- a/crates/merkle_tree/src/ics23_specs.rs +++ b/crates/merkle_tree/src/ics23_specs.rs @@ -2,7 +2,7 @@ use arse_merkle_tree::H256; use ics23::{HashOp, LeafOp, LengthOp, ProofSpec}; -use namada_core::types::hash::StorageHasher; +use namada_core::hash::StorageHasher; /// Get the leaf spec for the base tree. The key is stored after hashing, /// but the stored value is the subtree's root without hashing. diff --git a/crates/merkle_tree/src/lib.rs b/crates/merkle_tree/src/lib.rs index eb55878a82..cd91fe52b1 100644 --- a/crates/merkle_tree/src/lib.rs +++ b/crates/merkle_tree/src/lib.rs @@ -15,19 +15,17 @@ use eth_bridge_pool::{BridgePoolProof, BridgePoolTree}; use ics23::commitment_proof::Proof as Ics23Proof; use ics23::{CommitmentProof, ExistenceProof, NonExistenceProof}; use ics23_specs::ibc_leaf_spec; +use namada_core::address::{Address, InternalAddress}; use namada_core::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt}; use namada_core::bytes::ByteBuf; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::eth_bridge_pool::{ - is_pending_transfer_key, PendingTransfer, -}; -use namada_core::types::hash::{Hash, StorageHasher}; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::storage::{ +use namada_core::eth_bridge_pool::{is_pending_transfer_key, PendingTransfer}; +use namada_core::hash::{Hash, StorageHasher}; +use namada_core::keccak::KeccakHash; +use namada_core::storage::{ self, BlockHeight, DbKeySeg, Epoch, Error as StorageError, Key, KeySeg, StringKey, TreeBytes, TreeKeyError, IBC_KEY_LIMIT, }; -use namada_core::types::{self, DecodeError}; +use namada_core::{self, decode, DecodeError}; use thiserror::Error; /// Trait for reading from a merkle tree that is a sub-tree @@ -303,11 +301,11 @@ impl StoreType { bytes: T, ) -> std::result::Result { match self { - Self::Base => Ok(Store::Base(types::decode(bytes)?)), - Self::Account => Ok(Store::Account(types::decode(bytes)?)), - Self::Ibc => Ok(Store::Ibc(types::decode(bytes)?)), - Self::PoS => Ok(Store::PoS(types::decode(bytes)?)), - Self::BridgePool => Ok(Store::BridgePool(types::decode(bytes)?)), + Self::Base => Ok(Store::Base(decode(bytes)?)), + Self::Account => Ok(Store::Account(decode(bytes)?)), + Self::Ibc => Ok(Store::Ibc(decode(bytes)?)), + Self::PoS => Ok(Store::PoS(decode(bytes)?)), + Self::BridgePool => Ok(Store::BridgePool(decode(bytes)?)), } } } @@ -1004,8 +1002,8 @@ impl<'a> SubTreeWrite for &'a mut BridgePoolTree { #[cfg(test)] mod test { use ics23::HostFunctionsManager; - use namada_core::types::hash::Sha256Hasher; - use namada_core::types::storage::KeySeg; + use namada_core::hash::Sha256Hasher; + use namada_core::storage::KeySeg; use super::*; use crate::ics23_specs::{ibc_proof_specs, proof_specs}; diff --git a/crates/namada/src/ledger/governance/mod.rs b/crates/namada/src/ledger/governance/mod.rs index ce5b48cbeb..c694f035d4 100644 --- a/crates/namada/src/ledger/governance/mod.rs +++ b/crates/namada/src/ledger/governance/mod.rs @@ -19,11 +19,11 @@ use namada_vp_env::VpEnv; use thiserror::Error; use self::utils::ReadType; +use crate::address::{Address, InternalAddress}; use crate::ledger::native_vp::{Ctx, NativeVp}; use crate::ledger::{native_vp, pos}; +use crate::storage::{Epoch, Key}; use crate::token; -use crate::types::address::{Address, InternalAddress}; -use crate::types::storage::{Epoch, Key}; use crate::vm::WasmCacheAccess; /// for handling Governance NativeVP errors diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index 8ca87958f0..f73b730945 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -46,7 +46,7 @@ mod dry_run_tx { use namada_tx::Tx; use crate::ledger::protocol::ShellParams; - use crate::types::storage::TxIndex; + use crate::storage::TxIndex; let mut tx = Tx::try_from(&request.data[..]).into_storage_result()?; tx.validate_tx().into_storage_result()?; @@ -134,9 +134,9 @@ mod dry_run_tx { mod test { use borsh::BorshDeserialize; use borsh_ext::BorshSerializeExt; - use namada_core::types::address; - use namada_core::types::hash::Hash; - use namada_core::types::storage::{BlockHeight, Key}; + use namada_core::address; + use namada_core::hash::Hash; + use namada_core::storage::{BlockHeight, Key}; use namada_sdk::queries::{ EncodedResponseQuery, RequestCtx, RequestQuery, Router, RPC, }; @@ -191,10 +191,7 @@ mod test { namada_parameters::storage::get_max_block_gas_key(); wl_storage .storage - .write( - &max_block_gas_key, - namada_core::types::encode(&20_000_000_u64), - ) + .write(&max_block_gas_key, namada_core::encode(&20_000_000_u64)) .expect( "Max block gas parameter must be initialized in storage", ); diff --git a/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs b/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs index 19e99a7475..09aef4623d 100644 --- a/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs +++ b/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs @@ -17,8 +17,8 @@ use std::marker::PhantomData; use borsh::BorshDeserialize; use eyre::eyre; +use namada_core::eth_bridge_pool::erc20_token_address; use namada_core::hints; -use namada_core::types::eth_bridge_pool::erc20_token_address; use namada_ethereum_bridge::storage::bridge_pool::{ get_pending_key, is_bridge_pool_key, BRIDGE_POOL_ADDRESS, }; @@ -28,13 +28,13 @@ use namada_ethereum_bridge::ADDRESS as BRIDGE_ADDRESS; use namada_state::{DBIter, StorageHasher, DB}; use namada_tx::Tx; +use crate::address::{Address, InternalAddress}; +use crate::eth_bridge_pool::{PendingTransfer, TransferToEthereumKind}; +use crate::ethereum_events::EthAddress; use crate::ledger::native_vp::{Ctx, NativeVp, StorageReader}; +use crate::storage::Key; use crate::token::storage_key::balance_key; use crate::token::Amount; -use crate::types::address::{Address, InternalAddress}; -use crate::types::eth_bridge_pool::{PendingTransfer, TransferToEthereumKind}; -use crate::types::ethereum_events::EthAddress; -use crate::types::storage::Key; use crate::vm::WasmCacheAccess; #[derive(thiserror::Error, Debug)] @@ -642,8 +642,8 @@ mod test_bridge_pool_vp { use std::env::temp_dir; use borsh::BorshDeserialize; + use namada_core::address; use namada_core::borsh::BorshSerializeExt; - use namada_core::types::address; use namada_ethereum_bridge::storage::bridge_pool::get_signed_root_key; use namada_ethereum_bridge::storage::parameters::{ Contracts, EthereumBridgeParams, UpgradeableContract, @@ -654,15 +654,15 @@ mod test_bridge_pool_vp { use namada_tx::data::TxType; use super::*; + use crate::address::{nam, wnam, InternalAddress}; + use crate::chain::ChainId; + use crate::eth_bridge_pool::{GasFee, TransferToEthereum}; + use crate::hash::Hash; use crate::ledger::gas::VpGasMeter; use crate::state::mockdb::MockDB; use crate::state::write_log::WriteLog; use crate::state::{Sha256Hasher, State, WlStorage}; - use crate::types::address::{nam, wnam, InternalAddress}; - use crate::types::chain::ChainId; - use crate::types::eth_bridge_pool::{GasFee, TransferToEthereum}; - use crate::types::hash::Hash; - use crate::types::storage::TxIndex; + use crate::storage::TxIndex; use crate::vm::wasm::VpCache; use crate::vm::WasmCacheRwAccess; @@ -714,7 +714,7 @@ mod test_bridge_pool_vp { /// An implicit user address for testing & development #[allow(dead_code)] pub fn daewon_address() -> Address { - use crate::types::key::*; + use crate::key::*; pub fn daewon_keypair() -> common::SecretKey { let bytes = [ 235, 250, 15, 1, 145, 250, 172, 218, 247, 27, 63, 212, 60, 47, diff --git a/crates/namada/src/ledger/native_vp/ethereum_bridge/nut.rs b/crates/namada/src/ledger/native_vp/ethereum_bridge/nut.rs index 5acd2927f2..545d549bf8 100644 --- a/crates/namada/src/ledger/native_vp/ethereum_bridge/nut.rs +++ b/crates/namada/src/ledger/native_vp/ethereum_bridge/nut.rs @@ -3,8 +3,8 @@ use std::collections::BTreeSet; use eyre::WrapErr; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::storage::Key; +use namada_core::address::{Address, InternalAddress}; +use namada_core::storage::Key; use namada_state::StorageHasher; use namada_tx::Tx; use namada_vp_env::VpEnv; @@ -121,10 +121,10 @@ mod test_nuts { use std::env::temp_dir; use assert_matches::assert_matches; + use namada_core::address::testing::arb_non_internal_address; use namada_core::borsh::BorshSerializeExt; - use namada_core::types::address::testing::arb_non_internal_address; - use namada_core::types::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; - use namada_core::types::storage::TxIndex; + use namada_core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; + use namada_core::storage::TxIndex; use namada_ethereum_bridge::storage::wrapped_erc20s; use namada_state::testing::TestWlStorage; use namada_state::StorageWrite; diff --git a/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs b/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs index b72fe7d13f..289769eb88 100644 --- a/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs +++ b/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs @@ -2,9 +2,9 @@ use std::collections::{BTreeSet, HashSet}; use eyre::{eyre, Result}; -use namada_core::types::address::Address; -use namada_core::types::hash::StorageHasher; -use namada_core::types::storage::Key; +use namada_core::address::Address; +use namada_core::hash::StorageHasher; +use namada_core::storage::Key; use namada_ethereum_bridge; use namada_ethereum_bridge::storage; use namada_ethereum_bridge::storage::escrow_key; @@ -176,21 +176,21 @@ mod tests { use rand::Rng; use super::*; + use crate::address::testing::established_address_1; + use crate::address::{nam, wnam}; use crate::ethereum_bridge::storage::bridge_pool::BRIDGE_POOL_ADDRESS; use crate::ethereum_bridge::storage::parameters::{ Contracts, EthereumBridgeParams, UpgradeableContract, }; use crate::ethereum_bridge::storage::wrapped_erc20s; + use crate::ethereum_events; + use crate::ethereum_events::EthAddress; use crate::ledger::gas::VpGasMeter; use crate::state::mockdb::MockDB; use crate::state::write_log::WriteLog; use crate::state::{Sha256Hasher, State, WlStorage}; + use crate::storage::TxIndex; use crate::token::storage_key::minted_balance_key; - use crate::types::address::testing::established_address_1; - use crate::types::address::{nam, wnam}; - use crate::types::ethereum_events; - use crate::types::ethereum_events::EthAddress; - use crate::types::storage::TxIndex; use crate::vm::wasm::VpCache; use crate::vm::WasmCacheRwAccess; diff --git a/crates/namada/src/ledger/native_vp/ibc/context.rs b/crates/namada/src/ledger/native_vp/ibc/context.rs index 8581e766ce..3a57ffc126 100644 --- a/crates/namada/src/ledger/native_vp/ibc/context.rs +++ b/crates/namada/src/ledger/native_vp/ibc/context.rs @@ -3,21 +3,18 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use borsh_ext::BorshSerializeExt; -use ledger_storage::ResultExt; -use namada_core::types::storage::Epochs; +use namada_core::storage::Epochs; use namada_ibc::{IbcCommonContext, IbcStorageContext}; use namada_state::{StorageError, StorageRead, StorageWrite}; +use crate::address::{Address, InternalAddress}; +use crate::ibc::IbcEvent; use crate::ledger::ibc::storage::is_ibc_key; use crate::ledger::native_vp::CtxPreStorageRead; use crate::state::write_log::StorageModification; -use crate::state::{self as ledger_storage, StorageHasher}; +use crate::state::{self as ledger_storage, ResultExt, StorageHasher}; +use crate::storage::{BlockHash, BlockHeight, Epoch, Header, Key, TxIndex}; use crate::token::{self as token, Amount, DenominatedAmount}; -use crate::types::address::{Address, InternalAddress}; -use crate::types::ibc::IbcEvent; -use crate::types::storage::{ - BlockHash, BlockHeight, Epoch, Header, Key, TxIndex, -}; use crate::vm::WasmCacheAccess; /// Result of a storage API call. diff --git a/crates/namada/src/ledger/native_vp/ibc/mod.rs b/crates/namada/src/ledger/native_vp/ibc/mod.rs index 7774c41cf1..db0ed077e1 100644 --- a/crates/namada/src/ledger/native_vp/ibc/mod.rs +++ b/crates/namada/src/ledger/native_vp/ibc/mod.rs @@ -8,8 +8,8 @@ use std::rc::Rc; use std::time::Duration; use context::{PseudoExecutionContext, VpValidationContext}; -use namada_core::types::address::Address; -use namada_core::types::storage::Key; +use namada_core::address::Address; +use namada_core::storage::Key; use namada_gas::{IBC_ACTION_EXECUTE_GAS, IBC_ACTION_VALIDATE_GAS}; use namada_ibc::{ Error as ActionError, IbcActions, TransferModule, ValidationParams, @@ -247,12 +247,12 @@ impl From for Error { /// A dummy header used for testing #[cfg(any(test, feature = "testing"))] -pub fn get_dummy_header() -> crate::types::storage::Header { +pub fn get_dummy_header() -> crate::storage::Header { use crate::tendermint::time::Time as TmTime; - crate::types::storage::Header { - hash: crate::types::hash::Hash([0; 32]), + crate::storage::Header { + hash: crate::hash::Hash([0; 32]), time: TmTime::now().try_into().unwrap(), - next_validators_hash: crate::types::hash::Hash([0; 32]), + next_validators_hash: crate::hash::Hash([0; 32]), } } @@ -260,11 +260,11 @@ pub fn get_dummy_header() -> crate::types::storage::Header { #[cfg(any(test, feature = "testing"))] pub fn get_dummy_genesis_validator() -> namada_proof_of_stake::types::GenesisValidator { - use crate::core::types::address::testing::established_address_1; - use crate::core::types::dec::Dec; - use crate::core::types::key::testing::common_sk_from_simple_seed; + use crate::core::address::testing::established_address_1; + use crate::core::dec::Dec; + use crate::core::key::testing::common_sk_from_simple_seed; + use crate::key; use crate::token::Amount; - use crate::types::key; let address = established_address_1(); let tokens = Amount::native_whole(1); @@ -327,11 +327,11 @@ mod tests { use sha2::Digest; use super::*; - use crate::core::types::address::testing::{ + use crate::core::address::testing::{ established_address_1, established_address_2, }; - use crate::core::types::address::{nam, InternalAddress}; - use crate::core::types::storage::Epoch; + use crate::core::address::{nam, InternalAddress}; + use crate::core::storage::Epoch; use crate::ibc::apps::transfer::types::events::{ AckEvent, DenomTraceEvent, RecvEvent, TimeoutEvent, TransferEvent, }; @@ -398,18 +398,18 @@ mod tests { ibc_denom_key, next_sequence_ack_key, next_sequence_recv_key, next_sequence_send_key, receipt_key, }; + use crate::key::testing::keypair_1; use crate::ledger::gas::VpGasMeter; use crate::ledger::parameters::storage::{ get_epoch_duration_storage_key, get_max_expected_time_per_block_key, }; use crate::ledger::parameters::EpochDuration; use crate::ledger::{ibc, pos}; + use crate::storage::{BlockHash, BlockHeight, TxIndex}; use crate::tendermint::time::Time as TmTime; + use crate::time::DurationSecs; use crate::token::storage_key::balance_key; use crate::token::Amount; - use crate::types::key::testing::keypair_1; - use crate::types::storage::{BlockHash, BlockHeight, TxIndex}; - use crate::types::time::DurationSecs; use crate::vm::wasm; const ADDRESS: Address = Address::Internal(InternalAddress::Ibc); @@ -450,7 +450,7 @@ mod tests { let time_key = get_max_expected_time_per_block_key(); wl_storage .write_log - .write(&time_key, namada_core::types::encode(&time)) + .write(&time_key, namada_core::encode(&time)) .expect("write failed"); // set a dummy header wl_storage diff --git a/crates/namada/src/ledger/native_vp/masp.rs b/crates/namada/src/ledger/native_vp/masp.rs index b222aeaf9b..c76b2995b7 100644 --- a/crates/namada/src/ledger/native_vp/masp.rs +++ b/crates/namada/src/ledger/native_vp/masp.rs @@ -9,10 +9,10 @@ use masp_primitives::merkle_tree::CommitmentTree; use masp_primitives::sapling::Node; use masp_primitives::transaction::components::I128Sum; use masp_primitives::transaction::Transaction; -use namada_core::types::address::Address; -use namada_core::types::address::InternalAddress::Masp; -use namada_core::types::masp::encode_asset_type; -use namada_core::types::storage::{IndexedTx, Key}; +use namada_core::address::Address; +use namada_core::address::InternalAddress::Masp; +use namada_core::masp::encode_asset_type; +use namada_core::storage::{IndexedTx, Key}; use namada_gas::MASP_VERIFY_SHIELDED_TX_GAS; use namada_sdk::masp::verify_shielded_tx; use namada_state::{OptionExt, ResultExt}; @@ -34,7 +34,7 @@ use token::Amount; use crate::ledger::native_vp; use crate::ledger::native_vp::{Ctx, NativeVp}; use crate::token; -use crate::types::token::MaspDigitPos; +use crate::token::MaspDigitPos; use crate::vm::WasmCacheAccess; #[allow(missing_docs)] @@ -217,7 +217,7 @@ where let anchor_key = masp_convert_anchor_key(); let expected_anchor = self .ctx - .read_pre::(&anchor_key)? + .read_pre::(&anchor_key)? .ok_or(Error::NativeVpError( native_vp::Error::SimpleMessage("Cannot read storage"), ))?; @@ -225,9 +225,8 @@ where for description in &bundle.shielded_converts { // Check if the provided anchor matches the current // conversion tree's one - if namada_core::types::hash::Hash( - description.anchor.to_bytes(), - ) != expected_anchor + if namada_core::hash::Hash(description.anchor.to_bytes()) + != expected_anchor { tracing::debug!( "Convert description refers to an invalid anchor" diff --git a/crates/namada/src/ledger/native_vp/mod.rs b/crates/namada/src/ledger/native_vp/mod.rs index 6692a514b8..cbfe3b225f 100644 --- a/crates/namada/src/ledger/native_vp/mod.rs +++ b/crates/namada/src/ledger/native_vp/mod.rs @@ -12,24 +12,22 @@ use std::collections::BTreeSet; use borsh::BorshDeserialize; use eyre::WrapErr; -use namada_core::types::storage; -use namada_core::types::storage::Epochs; -use namada_core::types::validity_predicate::VpSentinel; +use namada_core::storage; +use namada_core::storage::Epochs; +use namada_core::validity_predicate::VpSentinel; use namada_gas::GasMetering; use namada_tx::Tx; pub use namada_vp_env::VpEnv; use super::vp_host_fns; +use crate::address::Address; +use crate::hash::Hash; +use crate::ibc::IbcEvent; use crate::ledger::gas::VpGasMeter; use crate::state; use crate::state::write_log::WriteLog; use crate::state::{ResultExt, State, StorageHasher, StorageRead}; -use crate::types::address::Address; -use crate::types::hash::Hash; -use crate::types::ibc::IbcEvent; -use crate::types::storage::{ - BlockHash, BlockHeight, Epoch, Header, Key, TxIndex, -}; +use crate::storage::{BlockHash, BlockHeight, Epoch, Header, Key, TxIndex}; use crate::vm::prefix_iter::PrefixIterators; use crate::vm::WasmCacheAccess; diff --git a/crates/namada/src/ledger/native_vp/multitoken.rs b/crates/namada/src/ledger/native_vp/multitoken.rs index 8999855ece..4a4cdeadf8 100644 --- a/crates/namada/src/ledger/native_vp/multitoken.rs +++ b/crates/namada/src/ledger/native_vp/multitoken.rs @@ -8,14 +8,14 @@ use namada_tx::Tx; use namada_vp_env::VpEnv; use thiserror::Error; +use crate::address::{Address, InternalAddress}; use crate::ledger::native_vp::{self, Ctx, NativeVp}; +use crate::storage::{Key, KeySeg}; use crate::token::storage_key::{ is_any_minted_balance_key, is_any_minter_key, is_any_token_balance_key, minter_key, }; use crate::token::Amount; -use crate::types::address::{Address, InternalAddress}; -use crate::types::storage::{Key, KeySeg}; use crate::vm::WasmCacheAccess; #[allow(missing_docs)] @@ -223,19 +223,19 @@ mod tests { use namada_tx::{Code, Data, Section, Signature, Tx}; use super::*; - use crate::core::types::address::nam; - use crate::core::types::address::testing::{ + use crate::address::{Address, InternalAddress}; + use crate::core::address::nam; + use crate::core::address::testing::{ established_address_1, established_address_2, }; + use crate::key::testing::keypair_1; use crate::ledger::gas::VpGasMeter; use crate::ledger::ibc::storage::ibc_token; + use crate::storage::TxIndex; use crate::token::storage_key::{ balance_key, minted_balance_key, minter_key, }; use crate::token::Amount; - use crate::types::address::{Address, InternalAddress}; - use crate::types::key::testing::keypair_1; - use crate::types::storage::TxIndex; use crate::vm::wasm::compilation_cache::common::testing::cache as wasm_cache; const ADDRESS: Address = Address::Internal(InternalAddress::Multitoken); diff --git a/crates/namada/src/ledger/native_vp/parameters.rs b/crates/namada/src/ledger/native_vp/parameters.rs index b22f56260e..a64667d9f8 100644 --- a/crates/namada/src/ledger/native_vp/parameters.rs +++ b/crates/namada/src/ledger/native_vp/parameters.rs @@ -2,8 +2,8 @@ use std::collections::BTreeSet; -use namada_core::types::address::Address; -use namada_core::types::storage::Key; +use namada_core::address::Address; +use namada_core::storage::Key; use namada_tx::Tx; use thiserror::Error; diff --git a/crates/namada/src/ledger/pgf/mod.rs b/crates/namada/src/ledger/pgf/mod.rs index eb7ec70a98..23ff47903d 100644 --- a/crates/namada/src/ledger/pgf/mod.rs +++ b/crates/namada/src/ledger/pgf/mod.rs @@ -10,10 +10,10 @@ use namada_governance::{is_proposal_accepted, pgf}; use namada_tx::Tx; use thiserror::Error; +use crate::address::{Address, InternalAddress}; use crate::ledger::native_vp; use crate::ledger::native_vp::{Ctx, NativeVp}; -use crate::types::address::{Address, InternalAddress}; -use crate::types::storage::Key; +use crate::storage::Key; use crate::vm::WasmCacheAccess; /// for handling Pgf NativeVP errors diff --git a/crates/namada/src/ledger/pgf/utils.rs b/crates/namada/src/ledger/pgf/utils.rs index 8132de32af..6f6153885e 100644 --- a/crates/namada/src/ledger/pgf/utils.rs +++ b/crates/namada/src/ledger/pgf/utils.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use namada_core::types::address::Address; +use namada_core::address::Address; use crate::ledger::events::EventType; use crate::token; diff --git a/crates/namada/src/ledger/pos/mod.rs b/crates/namada/src/ledger/pos/mod.rs index a7e8fa0d22..c62daccffd 100644 --- a/crates/namada/src/ledger/pos/mod.rs +++ b/crates/namada/src/ledger/pos/mod.rs @@ -4,9 +4,9 @@ pub mod vp; use std::convert::TryFrom; -use namada_core::types::address; -pub use namada_core::types::dec::Dec; -pub use namada_core::types::key::common; +use namada_core::address; +pub use namada_core::dec::Dec; +pub use namada_core::key::common; pub use namada_proof_of_stake::parameters::{OwnedPosParams, PosParams}; pub use namada_proof_of_stake::pos_queries::*; pub use namada_proof_of_stake::storage::*; @@ -16,8 +16,8 @@ pub use namada_proof_of_stake::{staking_token_address, types}; pub use vp::PosVP; pub use {namada_proof_of_stake, namada_state}; +use crate::address::{Address, InternalAddress}; pub use crate::token; -use crate::types::address::{Address, InternalAddress}; /// Address of the PoS account implemented as a native VP pub const ADDRESS: Address = address::POS; diff --git a/crates/namada/src/ledger/pos/vp.rs b/crates/namada/src/ledger/pos/vp.rs index 69ec002654..dfb1c32c25 100644 --- a/crates/namada/src/ledger/pos/vp.rs +++ b/crates/namada/src/ledger/pos/vp.rs @@ -18,9 +18,9 @@ use namada_state::StorageRead; use namada_tx::Tx; use thiserror::Error; +use crate::address::{Address, InternalAddress}; use crate::ledger::native_vp::{self, Ctx, NativeVp}; -use crate::types::address::{Address, InternalAddress}; -use crate::types::storage::{Key, KeySeg}; +use crate::storage::{Key, KeySeg}; use crate::vm::WasmCacheAccess; #[allow(missing_docs)] diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index 9ffa91b6c9..33c930a5c6 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -4,8 +4,8 @@ use std::collections::BTreeSet; use borsh_ext::BorshSerializeExt; use eyre::{eyre, WrapErr}; use masp_primitives::transaction::Transaction; -use namada_core::types::hash::Hash; -use namada_core::types::storage::Key; +use namada_core::hash::Hash; +use namada_core::storage::Key; use namada_gas::TxGasMeter; use namada_sdk::tx::TX_TRANSFER_WASM; use namada_state::wl_storage::WriteLogAndStorage; @@ -19,6 +19,7 @@ use namada_vote_ext::EthereumTxData; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use thiserror::Error; +use crate::address::{Address, InternalAddress}; use crate::ledger::gas::{GasMetering, VpGasMeter}; use crate::ledger::governance::GovernanceVp; use crate::ledger::native_vp::ethereum_bridge::bridge_pool_vp::BridgePoolVp; @@ -33,10 +34,9 @@ use crate::ledger::pgf::PgfVp; use crate::ledger::pos::{self, PosVP}; use crate::state::write_log::WriteLog; use crate::state::{DBIter, State, StorageHasher, WlStorage, DB}; +use crate::storage; +use crate::storage::TxIndex; use crate::token::Amount; -use crate::types::address::{Address, InternalAddress}; -use crate::types::storage; -use crate::types::storage::TxIndex; use crate::vm::wasm::{TxCache, VpCache}; use crate::vm::{self, wasm, WasmCacheAccess}; @@ -1151,15 +1151,13 @@ mod tests { use borsh::BorshDeserialize; use eyre::Result; - use namada_core::types::chain::ChainId; - use namada_core::types::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; - use namada_core::types::ethereum_events::{ - EthereumEvent, TransferToNamada, - }; - use namada_core::types::keccak::keccak_hash; - use namada_core::types::storage::BlockHeight; - use namada_core::types::voting_power::FractionalVotingPower; - use namada_core::types::{address, key}; + use namada_core::chain::ChainId; + use namada_core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; + use namada_core::ethereum_events::{EthereumEvent, TransferToNamada}; + use namada_core::keccak::keccak_hash; + use namada_core::storage::BlockHeight; + use namada_core::voting_power::FractionalVotingPower; + use namada_core::{address, key}; use namada_ethereum_bridge::protocol::transactions::votes::{ EpochedVotingPower, Votes, }; diff --git a/crates/namada/src/ledger/vp_host_fns.rs b/crates/namada/src/ledger/vp_host_fns.rs index 5ebd1a635b..716a49a66a 100644 --- a/crates/namada/src/ledger/vp_host_fns.rs +++ b/crates/namada/src/ledger/vp_host_fns.rs @@ -2,22 +2,22 @@ use std::num::TryFromIntError; -use namada_core::types::address::{Address, ESTABLISHED_ADDRESS_BYTES_LEN}; -use namada_core::types::hash::{Hash, HASH_LENGTH}; -use namada_core::types::storage::{ +use namada_core::address::{Address, ESTABLISHED_ADDRESS_BYTES_LEN}; +use namada_core::hash::{Hash, HASH_LENGTH}; +use namada_core::storage::{ BlockHash, BlockHeight, Epoch, Epochs, Header, Key, TxIndex, TX_INDEX_LENGTH, }; -use namada_core::types::validity_predicate::VpSentinel; +use namada_core::validity_predicate::VpSentinel; use namada_gas::MEMORY_ACCESS_GAS_PER_BYTE; use namada_state::write_log::WriteLog; use namada_state::{write_log, State, StorageHasher}; use namada_tx::{Section, Tx}; use thiserror::Error; +use crate::ibc::IbcEvent; use crate::ledger::gas; use crate::ledger::gas::{GasMetering, VpGasMeter}; -use crate::types::ibc::IbcEvent; /// These runtime errors will abort VP execution immediately #[allow(missing_docs)] @@ -28,7 +28,7 @@ pub enum RuntimeError { #[error("Storage error: {0}")] StorageError(namada_state::Error), #[error("Storage data error: {0}")] - StorageDataError(crate::types::storage::Error), + StorageDataError(crate::storage::Error), #[error("Encoding error: {0}")] EncodingError(std::io::Error), #[error("Numeric conversion error: {0}")] diff --git a/crates/namada/src/lib.rs b/crates/namada/src/lib.rs index 63a0ecb7f6..47f2db3691 100644 --- a/crates/namada/src/lib.rs +++ b/crates/namada/src/lib.rs @@ -6,7 +6,13 @@ #![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::private_intra_doc_links)] -pub use namada_core::{tendermint, tendermint_proto}; +pub use namada_core::{ + address, chain, dec, decode, encode, eth_abi, eth_bridge_pool, + ethereum_events, ethereum_structs, hash, internal, keccak, key, masp, + storage, string_encoding, tendermint, tendermint_proto, time, uint, + validity_predicate, voting_power, +}; +pub use namada_sdk::{control_flow, io}; #[cfg(feature = "tendermint-rpc")] pub use tendermint_rpc; pub use { @@ -21,13 +27,12 @@ pub use { pub mod ledger; pub use namada_tx::proto; -pub mod types; pub mod vm; pub mod eth_bridge { //! Namada Ethereum bridge re-exports. pub use ethers; - pub use namada_core::types::ethereum_structs as structs; + pub use namada_core::ethereum_structs as structs; pub use namada_ethereum_bridge::*; } diff --git a/crates/namada/src/types/ibc/mod.rs b/crates/namada/src/types/ibc/mod.rs deleted file mode 100644 index 3c57da5203..0000000000 --- a/crates/namada/src/types/ibc/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Types that are used in IBC. - -pub use namada_core::types::ibc::*; diff --git a/crates/namada/src/types/key/mod.rs b/crates/namada/src/types/key/mod.rs deleted file mode 100644 index 11a7af5533..0000000000 --- a/crates/namada/src/types/key/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Cryptographic keys - -pub use namada_core::types::key::*; diff --git a/crates/namada/src/types/mod.rs b/crates/namada/src/types/mod.rs deleted file mode 100644 index 3a68fbc779..0000000000 --- a/crates/namada/src/types/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! Types definitions. - -pub use namada_sdk::control_flow; -pub mod ibc; -pub use namada_sdk::io; -pub mod key; - -pub use namada_core::types::{ - address, chain, dec, decode, encode, eth_abi, eth_bridge_pool, - ethereum_events, ethereum_structs, hash, internal, keccak, masp, storage, - string_encoding, time, token, uint, validity_predicate, voting_power, -}; diff --git a/crates/namada/src/vm/host_env.rs b/crates/namada/src/vm/host_env.rs index 21cc2885e8..11acd72987 100644 --- a/crates/namada/src/vm/host_env.rs +++ b/crates/namada/src/vm/host_env.rs @@ -7,10 +7,10 @@ use std::num::TryFromIntError; use borsh::BorshDeserialize; use borsh_ext::BorshSerializeExt; use masp_primitives::transaction::Transaction; -use namada_core::types::address::ESTABLISHED_ADDRESS_BYTES_LEN; -use namada_core::types::internal::KeyVal; -use namada_core::types::storage::{Epochs, TX_INDEX_LENGTH}; -use namada_core::types::validity_predicate::VpSentinel; +use namada_core::address::ESTABLISHED_ADDRESS_BYTES_LEN; +use namada_core::internal::KeyVal; +use namada_core::storage::{Epochs, TX_INDEX_LENGTH}; +use namada_core::validity_predicate::VpSentinel; use namada_gas::{ self as gas, GasMetering, TxGasMeter, VpGasMeter, MEMORY_ACCESS_GAS_PER_BYTE, @@ -27,16 +27,16 @@ use super::wasm::TxCache; #[cfg(feature = "wasm-runtime")] use super::wasm::VpCache; use super::WasmCacheAccess; +use crate::address::{self, Address}; +use crate::hash::Hash; +use crate::ibc::IbcEvent; +use crate::internal::HostEnvResult; use crate::ledger::vp_host_fns; +use crate::storage::{BlockHeight, Epoch, Key, TxIndex}; use crate::token::storage_key::{ balance_key, is_any_minted_balance_key, is_any_minter_key, is_any_token_balance_key, minted_balance_key, minter_key, }; -use crate::types::address::{self, Address}; -use crate::types::hash::Hash; -use crate::types::ibc::IbcEvent; -use crate::types::internal::HostEnvResult; -use crate::types::storage::{BlockHeight, Epoch, Key, TxIndex}; use crate::vm::memory::VmMemory; use crate::vm::prefix_iter::{PrefixIteratorId, PrefixIterators}; use crate::vm::{HostRef, MutHostRef}; @@ -63,7 +63,7 @@ pub enum TxRuntimeError { #[error("Storage error: {0}")] StorageError(#[from] StorageError), #[error("Storage data error: {0}")] - StorageDataError(crate::types::storage::Error), + StorageDataError(crate::storage::Error), #[error("Encoding error: {0}")] EncodingError(std::io::Error), #[error("Address error: {0}")] @@ -1982,7 +1982,7 @@ where .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; vp_host_fns::add_gas(gas_meter, gas, sentinel)?; let public_keys_map = - namada_core::types::account::AccountPublicKeysMap::try_from_slice( + namada_core::account::AccountPublicKeysMap::try_from_slice( &public_keys_map, ) .map_err(vp_host_fns::RuntimeError::EncodingError)?; @@ -2196,7 +2196,7 @@ where .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; tx_charge_gas(env, gas)?; let public_keys_map = - namada_core::types::account::AccountPublicKeysMap::try_from_slice( + namada_core::account::AccountPublicKeysMap::try_from_slice( &public_keys_map, ) .map_err(TxRuntimeError::EncodingError)?; @@ -2367,7 +2367,7 @@ where // Temp. workaround for use namada_state::StorageRead; -use crate::types::storage::BlockHash; +use crate::storage::BlockHash; impl<'a, DB, H, CA> StorageRead for TxCtx<'a, DB, H, CA> where DB: namada_state::DB + for<'iter> namada_state::DBIter<'iter>, @@ -2493,7 +2493,7 @@ where fn get_block_header( &self, height: BlockHeight, - ) -> Result, StorageError> { + ) -> Result, StorageError> { let storage = unsafe { self.storage.get() }; let (header, gas) = storage .get_block_header(Some(height)) diff --git a/crates/namada/src/vm/types.rs b/crates/namada/src/vm/types.rs index 54cc170371..203563ece9 100644 --- a/crates/namada/src/vm/types.rs +++ b/crates/namada/src/vm/types.rs @@ -13,8 +13,8 @@ use std::collections::BTreeSet; use namada_tx::Tx; -use crate::types::address::Address; -use crate::types::storage; +use crate::address::Address; +use crate::storage; /// Input for validity predicate wasm module call pub struct VpInput<'a> { diff --git a/crates/namada/src/vm/wasm/compilation_cache/common.rs b/crates/namada/src/vm/wasm/compilation_cache/common.rs index ce3758678e..cb9291b14a 100644 --- a/crates/namada/src/vm/wasm/compilation_cache/common.rs +++ b/crates/namada/src/vm/wasm/compilation_cache/common.rs @@ -18,8 +18,8 @@ use clru::{CLruCache, CLruCacheConfig, WeightScale}; use wasmer::{Module, Store}; use wasmer_cache::{FileSystemCache, Hash as CacheHash}; -use crate::core::types::hash::Hash; -use crate::types::control_flow::time::{ExponentialBackoff, SleepStrategy}; +use crate::control_flow::time::{ExponentialBackoff, SleepStrategy}; +use crate::core::hash::Hash; use crate::vm::wasm::run::untrusted_wasm_store; use crate::vm::wasm::{self, memory}; use crate::vm::{WasmCacheAccess, WasmCacheRoAccess}; diff --git a/crates/namada/src/vm/wasm/host_env.rs b/crates/namada/src/vm/wasm/host_env.rs index 4ab7ecda35..f6d45e23cb 100644 --- a/crates/namada/src/vm/wasm/host_env.rs +++ b/crates/namada/src/vm/wasm/host_env.rs @@ -3,7 +3,7 @@ //! Here, we expose the host functions into wasm's //! imports, so they can be called from inside the wasm. -use namada_core::types::hash::StorageHasher; +use namada_core::hash::StorageHasher; use wasmer::{ Function, HostEnvInitError, ImportObject, Instance, Memory, Store, WasmerEnv, diff --git a/crates/namada/src/vm/wasm/run.rs b/crates/namada/src/vm/wasm/run.rs index 8d84185135..5c3a3c392d 100644 --- a/crates/namada/src/vm/wasm/run.rs +++ b/crates/namada/src/vm/wasm/run.rs @@ -4,7 +4,7 @@ use std::collections::BTreeSet; use std::marker::PhantomData; use borsh::BorshDeserialize; -use namada_core::types::validity_predicate::VpSentinel; +use namada_core::validity_predicate::VpSentinel; use namada_gas::{GasMetering, TxGasMeter, WASM_MEMORY_PAGE_GAS}; use namada_state::write_log::StorageModification; use namada_state::{State, StorageHasher}; @@ -16,12 +16,12 @@ use wasmer::{BaseTunables, Module, Store}; use super::memory::{Limit, WasmMemory}; use super::TxCache; +use crate::address::Address; +use crate::hash::{Error as TxHashError, Hash}; +use crate::internal::HostEnvResult; use crate::ledger::gas::VpGasMeter; use crate::state::write_log::WriteLog; -use crate::types::address::Address; -use crate::types::hash::{Error as TxHashError, Hash}; -use crate::types::internal::HostEnvResult; -use crate::types::storage::{Key, TxIndex}; +use crate::storage::{Key, TxIndex}; use crate::vm::host_env::{TxVmEnv, VpCtx, VpEvaluator, VpVmEnv}; use crate::vm::prefix_iter::PrefixIterators; use crate::vm::types::VpInput; @@ -641,9 +641,9 @@ mod tests { use wasmer_vm::TrapCode; use super::*; + use crate::hash::Hash; use crate::state::testing::TestStorage; use crate::tx::data::eval_vp::EvalVp; - use crate::types::hash::Hash; use crate::vm::host_env::TxRuntimeError; use crate::vm::wasm; diff --git a/crates/parameters/src/lib.rs b/crates/parameters/src/lib.rs index 8fd77ad58f..e59323e114 100644 --- a/crates/parameters/src/lib.rs +++ b/crates/parameters/src/lib.rs @@ -3,14 +3,14 @@ pub mod storage; mod wasm_allowlist; use std::collections::BTreeMap; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::chain::ProposalBytes; -use namada_core::types::dec::Dec; -use namada_core::types::hash::Hash; -pub use namada_core::types::parameters::*; -use namada_core::types::storage::Key; -use namada_core::types::time::DurationSecs; -use namada_core::types::token; +use namada_core::address::{Address, InternalAddress}; +use namada_core::chain::ProposalBytes; +use namada_core::dec::Dec; +use namada_core::hash::Hash; +pub use namada_core::parameters::*; +use namada_core::storage::Key; +use namada_core::time::DurationSecs; +use namada_core::token; use namada_storage::{self, ResultExt, StorageRead, StorageWrite}; pub use storage::get_max_block_gas; use thiserror::Error; @@ -26,7 +26,7 @@ pub enum ReadError { #[error("Storage error: {0}")] StorageError(namada_storage::Error), #[error("Storage type error: {0}")] - StorageTypeError(namada_core::types::storage::Error), + StorageTypeError(namada_core::storage::Error), #[error("Protocol parameters are missing, they must be always set")] ParametersMissing, } diff --git a/crates/parameters/src/storage.rs b/crates/parameters/src/storage.rs index 7bacb2c6fa..abf3fa743f 100644 --- a/crates/parameters/src/storage.rs +++ b/crates/parameters/src/storage.rs @@ -1,7 +1,7 @@ //! Parameters storage -use namada_core::types::address::Address; -use namada_core::types::storage::{DbKeySeg, Key}; +use namada_core::address::Address; +use namada_core::storage::{DbKeySeg, Key}; use namada_macros::StorageKeys; use namada_storage::StorageRead; diff --git a/crates/parameters/src/wasm_allowlist.rs b/crates/parameters/src/wasm_allowlist.rs index e75b9b292b..c22b4b6fc1 100644 --- a/crates/parameters/src/wasm_allowlist.rs +++ b/crates/parameters/src/wasm_allowlist.rs @@ -1,5 +1,5 @@ -use namada_core::types::hash::Hash; -use namada_core::types::storage; +use namada_core::hash::Hash; +use namada_core::storage; use namada_storage::{Result, StorageRead}; use crate::storage::{ diff --git a/crates/proof_of_stake/src/epoched.rs b/crates/proof_of_stake/src/epoched.rs index 5db83af399..a1767f0318 100644 --- a/crates/proof_of_stake/src/epoched.rs +++ b/crates/proof_of_stake/src/epoched.rs @@ -7,7 +7,7 @@ use std::marker::PhantomData; use std::{cmp, ops}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::storage::{self, Epoch}; +use namada_core::storage::{self, Epoch}; use namada_storage; use namada_storage::collections::lazy_map::{LazyMap, NestedMap}; use namada_storage::collections::{self, LazyCollection}; @@ -1085,9 +1085,9 @@ pub trait EpochOffset: #[cfg(test)] mod test { - use namada_core::types::address::testing::established_address_1; - use namada_core::types::dec::Dec; - use namada_core::types::{key, token}; + use namada_core::address::testing::established_address_1; + use namada_core::dec::Dec; + use namada_core::{key, token}; use namada_state::testing::TestWlStorage; use test_log::test; diff --git a/crates/proof_of_stake/src/error.rs b/crates/proof_of_stake/src/error.rs index 6516809575..c692e0decf 100644 --- a/crates/proof_of_stake/src/error.rs +++ b/crates/proof_of_stake/src/error.rs @@ -1,9 +1,9 @@ /// Custom error types use std::num::TryFromIntError; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::storage::Epoch; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::storage::Epoch; use thiserror::Error; use crate::rewards; diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 0d5341689b..01e4d94636 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -27,13 +27,13 @@ use std::cmp::{self}; use std::collections::{BTreeMap, BTreeSet, HashSet}; pub use error::*; +use namada_core::address::{Address, InternalAddress}; +use namada_core::dec::Dec; use namada_core::event::EmitEvents; +use namada_core::key::{common, tm_raw_hash_to_string}; +use namada_core::storage::BlockHeight; +pub use namada_core::storage::{Epoch, Key, KeySeg}; use namada_core::tendermint::abci::types::{Misbehavior, MisbehaviorKind}; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::dec::Dec; -use namada_core::types::key::{common, tm_raw_hash_to_string}; -use namada_core::types::storage::BlockHeight; -pub use namada_core::types::storage::{Epoch, Key, KeySeg}; use namada_storage::collections::lazy_map::{self, Collectable, LazyMap}; use namada_storage::{StorageRead, StorageWrite}; pub use namada_trans_token as token; @@ -164,7 +164,7 @@ where pub fn is_delegator( storage: &S, address: &Address, - epoch: Option, + epoch: Option, ) -> namada_storage::Result where S: StorageRead, @@ -2501,7 +2501,7 @@ pub mod test_utils { storage: &mut S, params: &PosParams, validators: impl Iterator, - current_epoch: namada_core::types::storage::Epoch, + current_epoch: namada_core::storage::Epoch, ) -> namada_storage::Result<()> where S: StorageRead + StorageWrite, @@ -2564,7 +2564,7 @@ pub mod test_utils { storage: &mut S, owned: OwnedPosParams, validators: impl Iterator + Clone, - current_epoch: namada_core::types::storage::Epoch, + current_epoch: namada_core::storage::Epoch, ) -> namada_storage::Result where S: StorageRead + StorageWrite, diff --git a/crates/proof_of_stake/src/parameters.rs b/crates/proof_of_stake/src/parameters.rs index 6062f11a5b..0acafc3d16 100644 --- a/crates/proof_of_stake/src/parameters.rs +++ b/crates/proof_of_stake/src/parameters.rs @@ -3,10 +3,10 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::dec::Dec; -use namada_core::types::storage::Epoch; -use namada_core::types::token; -use namada_core::types::uint::Uint; +use namada_core::dec::Dec; +use namada_core::storage::Epoch; +use namada_core::token; +use namada_core::uint::Uint; use namada_governance::parameters::GovernanceParameters; use thiserror::Error; @@ -297,7 +297,7 @@ mod tests { /// Testing helpers #[cfg(any(test, feature = "testing"))] pub mod testing { - use namada_core::types::dec::Dec; + use namada_core::dec::Dec; use proptest::prelude::*; use super::*; diff --git a/crates/proof_of_stake/src/pos_queries.rs b/crates/proof_of_stake/src/pos_queries.rs index f76d4c6ed8..8b07205f9e 100644 --- a/crates/proof_of_stake/src/pos_queries.rs +++ b/crates/proof_of_stake/src/pos_queries.rs @@ -1,10 +1,10 @@ //! Storage API for querying data about Proof-of-stake related //! data. This includes validator and epoch related data. -use namada_core::types::address::Address; -use namada_core::types::chain::ProposalBytes; -use namada_core::types::storage::{BlockHeight, Epoch}; -use namada_core::types::{key, token}; +use namada_core::address::Address; +use namada_core::chain::ProposalBytes; +use namada_core::storage::{BlockHeight, Epoch}; +use namada_core::{key, token}; use namada_parameters::storage::get_max_proposal_bytes_key; use namada_storage::collections::lazy_map::NestedSubKey; use namada_storage::StorageRead; diff --git a/crates/proof_of_stake/src/queries.rs b/crates/proof_of_stake/src/queries.rs index 0b98810cba..fcd4273ed5 100644 --- a/crates/proof_of_stake/src/queries.rs +++ b/crates/proof_of_stake/src/queries.rs @@ -4,10 +4,10 @@ use std::cmp; use std::collections::{BTreeMap, HashMap, HashSet}; use borsh::BorshDeserialize; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::storage::Epoch; +use namada_core::token; use namada_storage::collections::lazy_map::{NestedSubKey, SubKey}; use namada_storage::{self, StorageRead}; diff --git a/crates/proof_of_stake/src/rewards.rs b/crates/proof_of_stake/src/rewards.rs index c81a517db4..b6a2edd712 100644 --- a/crates/proof_of_stake/src/rewards.rs +++ b/crates/proof_of_stake/src/rewards.rs @@ -2,11 +2,11 @@ use std::collections::{HashMap, HashSet}; -use namada_core::types::address::{self, Address}; -use namada_core::types::dec::Dec; -use namada_core::types::storage::Epoch; -use namada_core::types::token::{self, Amount}; -use namada_core::types::uint::{Uint, I256}; +use namada_core::address::{self, Address}; +use namada_core::dec::Dec; +use namada_core::storage::Epoch; +use namada_core::token::{self, Amount}; +use namada_core::uint::{Uint, I256}; use namada_parameters::storage as params_storage; use namada_storage::collections::lazy_map::NestedSubKey; use namada_storage::{ResultExt, StorageRead, StorageWrite}; diff --git a/crates/proof_of_stake/src/slashing.rs b/crates/proof_of_stake/src/slashing.rs index 3d7361c3cf..acbda17255 100644 --- a/crates/proof_of_stake/src/slashing.rs +++ b/crates/proof_of_stake/src/slashing.rs @@ -4,10 +4,10 @@ use std::cmp::{self, Reverse}; use std::collections::{BTreeMap, BTreeSet, HashMap}; use borsh::BorshDeserialize; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::storage::Epoch; +use namada_core::token; use namada_storage::collections::lazy_map::{ Collectable, NestedMap, NestedSubKey, SubKey, }; diff --git a/crates/proof_of_stake/src/storage.rs b/crates/proof_of_stake/src/storage.rs index 36c0af84ac..9cae1168a9 100644 --- a/crates/proof_of_stake/src/storage.rs +++ b/crates/proof_of_stake/src/storage.rs @@ -4,11 +4,11 @@ use std::collections::{BTreeSet, HashSet}; use namada_account::protocol_pk_key; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::key::{common, tm_consensus_key_raw_hash}; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::key::{common, tm_consensus_key_raw_hash}; +use namada_core::storage::Epoch; +use namada_core::token; use namada_governance::storage::get_max_proposal_period; use namada_storage::collections::lazy_map::NestedSubKey; use namada_storage::collections::{LazyCollection, LazySet}; @@ -391,7 +391,7 @@ where pub fn read_validator_deltas_value( storage: &S, validator: &Address, - epoch: &namada_core::types::storage::Epoch, + epoch: &namada_core::storage::Epoch, ) -> namada_storage::Result> where S: StorageRead, @@ -407,7 +407,7 @@ pub fn read_validator_stake( storage: &S, params: &PosParams, validator: &Address, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result where S: StorageRead, @@ -429,7 +429,7 @@ pub fn update_validator_deltas( params: &OwnedPosParams, validator: &Address, delta: token::Change, - current_epoch: namada_core::types::storage::Epoch, + current_epoch: namada_core::storage::Epoch, offset_opt: Option, ) -> namada_storage::Result<()> where @@ -453,7 +453,7 @@ where pub fn read_total_stake( storage: &S, params: &PosParams, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result where S: StorageRead, @@ -472,7 +472,7 @@ where /// Read all addresses from consensus validator set. pub fn read_consensus_validator_set_addresses( storage: &S, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result> where S: StorageRead, @@ -487,7 +487,7 @@ where /// Read all addresses from below-capacity validator set. pub fn read_below_capacity_validator_set_addresses( storage: &S, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result> where S: StorageRead, @@ -502,7 +502,7 @@ where /// Read all addresses from the below-threshold set pub fn read_below_threshold_validator_set_addresses( storage: &S, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result> where S: StorageRead, @@ -524,7 +524,7 @@ where /// Read all addresses from consensus validator set with their stake. pub fn read_consensus_validator_set_addresses_with_stake( storage: &S, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result> where S: StorageRead, @@ -554,7 +554,7 @@ where /// Count the number of consensus validators pub fn get_num_consensus_validators( storage: &S, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result where S: StorageRead, @@ -568,7 +568,7 @@ where /// Read all addresses from below-capacity validator set with their stake. pub fn read_below_capacity_validator_set_addresses_with_stake( storage: &S, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result> where S: StorageRead, @@ -598,7 +598,7 @@ where /// Read all validator addresses. pub fn read_all_validator_addresses( storage: &S, - epoch: namada_core::types::storage::Epoch, + epoch: namada_core::storage::Epoch, ) -> namada_storage::Result> where S: StorageRead, @@ -615,7 +615,7 @@ pub fn update_total_deltas( storage: &mut S, params: &OwnedPosParams, delta: token::Change, - current_epoch: namada_core::types::storage::Epoch, + current_epoch: namada_core::storage::Epoch, offset_opt: Option, ) -> namada_storage::Result<()> where diff --git a/crates/proof_of_stake/src/storage_key.rs b/crates/proof_of_stake/src/storage_key.rs index 6135468a95..c64a677ce6 100644 --- a/crates/proof_of_stake/src/storage_key.rs +++ b/crates/proof_of_stake/src/storage_key.rs @@ -1,7 +1,7 @@ //! Proof-of-Stake storage keys and storage integration. -use namada_core::types::address::Address; -use namada_core::types::storage::{DbKeySeg, Epoch, Key, KeySeg}; +use namada_core::address::Address; +use namada_core::storage::{DbKeySeg, Epoch, Key, KeySeg}; use namada_storage::collections::{lazy_map, lazy_vec}; use super::ADDRESS; diff --git a/crates/proof_of_stake/src/tests/helpers.rs b/crates/proof_of_stake/src/tests/helpers.rs index d66b64c504..26e9e53d73 100644 --- a/crates/proof_of_stake/src/tests/helpers.rs +++ b/crates/proof_of_stake/src/tests/helpers.rs @@ -1,13 +1,13 @@ use std::cmp::max; use std::ops::Range; -use namada_core::types::address::testing::address_from_simple_seed; -use namada_core::types::dec::Dec; -use namada_core::types::key::testing::common_sk_from_simple_seed; -use namada_core::types::key::{self, RefTo}; -use namada_core::types::storage::Epoch; -use namada_core::types::token; -use namada_core::types::token::testing::arb_amount_non_zero_ceiled; +use namada_core::address::testing::address_from_simple_seed; +use namada_core::dec::Dec; +use namada_core::key::testing::common_sk_from_simple_seed; +use namada_core::key::{self, RefTo}; +use namada_core::storage::Epoch; +use namada_core::token; +use namada_core::token::testing::arb_amount_non_zero_ceiled; use namada_state::testing::TestWlStorage; use proptest::prop_oneof; use proptest::strategy::{Just, Strategy}; diff --git a/crates/proof_of_stake/src/tests/state_machine.rs b/crates/proof_of_stake/src/tests/state_machine.rs index 3dc34c36fa..e2d1ad0cfe 100644 --- a/crates/proof_of_stake/src/tests/state_machine.rs +++ b/crates/proof_of_stake/src/tests/state_machine.rs @@ -6,12 +6,12 @@ use std::ops::Deref; use assert_matches::assert_matches; use itertools::Itertools; -use namada_core::types::address::{self, Address}; -use namada_core::types::dec::Dec; -use namada_core::types::key; -use namada_core::types::key::common::PublicKey; -use namada_core::types::storage::Epoch; -use namada_core::types::token::Change; +use namada_core::address::{self, Address}; +use namada_core::dec::Dec; +use namada_core::key; +use namada_core::key::common::PublicKey; +use namada_core::storage::Epoch; +use namada_core::token::Change; use namada_governance::parameters::GovernanceParameters; use namada_state::testing::TestWlStorage; use namada_storage::collections::lazy_map::{ diff --git a/crates/proof_of_stake/src/tests/state_machine_v2.rs b/crates/proof_of_stake/src/tests/state_machine_v2.rs index 872625f9d5..ee83c08f0d 100644 --- a/crates/proof_of_stake/src/tests/state_machine_v2.rs +++ b/crates/proof_of_stake/src/tests/state_machine_v2.rs @@ -7,12 +7,12 @@ use std::{cmp, mem}; use assert_matches::assert_matches; use derivative::Derivative; use itertools::Itertools; -use namada_core::types::address::{self, Address}; -use namada_core::types::dec::Dec; -use namada_core::types::key; -use namada_core::types::key::common::PublicKey; -use namada_core::types::storage::Epoch; -use namada_core::types::token::Change; +use namada_core::address::{self, Address}; +use namada_core::dec::Dec; +use namada_core::key; +use namada_core::key::common::PublicKey; +use namada_core::storage::Epoch; +use namada_core::token::Change; use namada_governance::parameters::GovernanceParameters; use namada_state::testing::TestWlStorage; use namada_storage::collections::lazy_map::{NestedSubKey, SubKey}; diff --git a/crates/proof_of_stake/src/tests/test_helper_fns.rs b/crates/proof_of_stake/src/tests/test_helper_fns.rs index 5148224412..b4e08395fd 100644 --- a/crates/proof_of_stake/src/tests/test_helper_fns.rs +++ b/crates/proof_of_stake/src/tests/test_helper_fns.rs @@ -1,11 +1,11 @@ use std::collections::{BTreeMap, BTreeSet}; -use namada_core::types::address::testing::{ +use namada_core::address::testing::{ established_address_1, established_address_2, established_address_3, }; -use namada_core::types::dec::Dec; -use namada_core::types::storage::{Epoch, Key}; -use namada_core::types::token; +use namada_core::dec::Dec; +use namada_core::storage::{Epoch, Key}; +use namada_core::token; use namada_state::testing::TestWlStorage; use namada_storage::collections::lazy_map::NestedMap; use namada_storage::collections::LazyCollection; @@ -1927,7 +1927,7 @@ fn test_compute_amount_after_slashing_withdraw() { /// SM test case 1 from Brent #[test] fn test_from_sm_case_1() { - use namada_core::types::address::testing::established_address_4; + use namada_core::address::testing::established_address_4; let mut storage = TestWlStorage::default(); let gov_params = diff --git a/crates/proof_of_stake/src/tests/test_pos.rs b/crates/proof_of_stake/src/tests/test_pos.rs index 45b4f3a980..fe9477b602 100644 --- a/crates/proof_of_stake/src/tests/test_pos.rs +++ b/crates/proof_of_stake/src/tests/test_pos.rs @@ -3,14 +3,12 @@ use std::collections::{BTreeMap, HashSet}; use assert_matches::assert_matches; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::key::testing::{ - common_sk_from_simple_seed, gen_keypair, -}; -use namada_core::types::key::RefTo; -use namada_core::types::storage::{BlockHeight, Epoch}; -use namada_core::types::{address, key}; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::key::testing::{common_sk_from_simple_seed, gen_keypair}; +use namada_core::key::RefTo; +use namada_core::storage::{BlockHeight, Epoch}; +use namada_core::{address, key}; use namada_state::testing::TestWlStorage; use namada_storage::collections::lazy_map::Collectable; use namada_storage::StorageRead; diff --git a/crates/proof_of_stake/src/tests/test_slash_and_redel.rs b/crates/proof_of_stake/src/tests/test_slash_and_redel.rs index e9118b1472..b7a04b3c86 100644 --- a/crates/proof_of_stake/src/tests/test_slash_and_redel.rs +++ b/crates/proof_of_stake/src/tests/test_slash_and_redel.rs @@ -2,10 +2,10 @@ use std::ops::Deref; use std::str::FromStr; use assert_matches::assert_matches; -use namada_core::types::address; -use namada_core::types::dec::Dec; -use namada_core::types::storage::{BlockHeight, Epoch}; -use namada_core::types::token::NATIVE_MAX_DECIMAL_PLACES; +use namada_core::address; +use namada_core::dec::Dec; +use namada_core::storage::{BlockHeight, Epoch}; +use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use namada_state::testing::TestWlStorage; use namada_storage::collections::lazy_map::Collectable; use namada_storage::StorageRead; diff --git a/crates/proof_of_stake/src/tests/test_validator.rs b/crates/proof_of_stake/src/tests/test_validator.rs index 4ddb17c7c6..2d06174cfb 100644 --- a/crates/proof_of_stake/src/tests/test_validator.rs +++ b/crates/proof_of_stake/src/tests/test_validator.rs @@ -1,14 +1,14 @@ use std::cmp::min; -use namada_core::types::address::testing::arb_established_address; -use namada_core::types::address::{self, Address, EstablishedAddressGen}; -use namada_core::types::dec::Dec; -use namada_core::types::key::testing::{ +use namada_core::address::testing::arb_established_address; +use namada_core::address::{self, Address, EstablishedAddressGen}; +use namada_core::dec::Dec; +use namada_core::key::testing::{ arb_common_keypair, common_sk_from_simple_seed, }; -use namada_core::types::key::{self, common, RefTo}; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::key::{self, common, RefTo}; +use namada_core::storage::Epoch; +use namada_core::token; use namada_state::testing::TestWlStorage; use namada_storage::collections::lazy_map; use proptest::prelude::*; diff --git a/crates/proof_of_stake/src/types/mod.rs b/crates/proof_of_stake/src/types/mod.rs index b2a0d176ad..4b38521a52 100644 --- a/crates/proof_of_stake/src/types/mod.rs +++ b/crates/proof_of_stake/src/types/mod.rs @@ -10,12 +10,12 @@ use std::hash::Hash; use std::ops::Sub; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::key::common; -use namada_core::types::storage::{Epoch, KeySeg}; -use namada_core::types::token; -use namada_core::types::token::Amount; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::key::common; +use namada_core::storage::{Epoch, KeySeg}; +use namada_core::token; +use namada_core::token::Amount; use namada_storage::collections::lazy_map::NestedMap; use namada_storage::collections::{LazyMap, LazySet, LazyVec}; pub use rev_order::ReverseOrdTokenAmount; @@ -469,7 +469,7 @@ impl Display for WeightedValidator { pub struct Position(pub u64); impl KeySeg for Position { - fn parse(string: String) -> namada_core::types::storage::Result + fn parse(string: String) -> namada_core::storage::Result where Self: Sized, { @@ -481,7 +481,7 @@ impl KeySeg for Position { self.0.raw() } - fn to_db_key(&self) -> namada_core::types::storage::DbKeySeg { + fn to_db_key(&self) -> namada_core::storage::DbKeySeg { self.0.to_db_key() } } diff --git a/crates/proof_of_stake/src/types/rev_order.rs b/crates/proof_of_stake/src/types/rev_order.rs index 57619941d4..ef23fb9e53 100644 --- a/crates/proof_of_stake/src/types/rev_order.rs +++ b/crates/proof_of_stake/src/types/rev_order.rs @@ -1,5 +1,5 @@ -use namada_core::types::storage::KeySeg; -use namada_core::types::token; +use namada_core::storage::KeySeg; +use namada_core::token; /// A wrapper over `token::Amount`, whose `KeySeg` implementation has reverse /// order of the `token::Amount` type. @@ -27,7 +27,7 @@ fn invert(amount: token::Amount) -> token::Amount { } impl KeySeg for ReverseOrdTokenAmount { - fn parse(string: String) -> namada_core::types::storage::Result + fn parse(string: String) -> namada_core::storage::Result where Self: Sized, { @@ -39,7 +39,7 @@ impl KeySeg for ReverseOrdTokenAmount { invert(self.0).raw() } - fn to_db_key(&self) -> namada_core::types::storage::DbKeySeg { + fn to_db_key(&self) -> namada_core::storage::DbKeySeg { invert(self.0).to_db_key() } } diff --git a/crates/proof_of_stake/src/validator_set_update.rs b/crates/proof_of_stake/src/validator_set_update.rs index 474af4ddda..8d15820b88 100644 --- a/crates/proof_of_stake/src/validator_set_update.rs +++ b/crates/proof_of_stake/src/validator_set_update.rs @@ -2,10 +2,10 @@ use std::collections::{HashMap, HashSet}; -use namada_core::types::address::Address; -use namada_core::types::key::PublicKeyTmRawHash; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::key::PublicKeyTmRawHash; +use namada_core::storage::Epoch; +use namada_core::token; use namada_storage::collections::lazy_map::{NestedSubKey, SubKey}; use namada_storage::{StorageRead, StorageWrite}; use num_traits::ops::checked::CheckedAdd; diff --git a/crates/replay_protection/src/lib.rs b/crates/replay_protection/src/lib.rs index 7f68314fcd..b014f39f02 100644 --- a/crates/replay_protection/src/lib.rs +++ b/crates/replay_protection/src/lib.rs @@ -1,7 +1,7 @@ //! Replay protection storage keys -use namada_core::types::hash::Hash; -use namada_core::types::storage::Key; +use namada_core::hash::Hash; +use namada_core::storage::Key; const ERROR_MSG: &str = "Cannot obtain a valid db key"; diff --git a/crates/sdk/Cargo.toml b/crates/sdk/Cargo.toml index 707dfa97de..0c620e3d92 100644 --- a/crates/sdk/Cargo.toml +++ b/crates/sdk/Cargo.toml @@ -43,6 +43,7 @@ testing = [ "namada_governance/testing", "namada_ibc/testing", "namada_proof_of_stake/testing", + "namada_storage/testing", "namada_tx/testing", "async-client", "proptest", @@ -131,6 +132,7 @@ namada_proof_of_stake = { path = "../proof_of_stake", default-features = false, "testing", ] } namada_state = { path = "../state", features = ["testing"] } +namada_storage = { path = "../storage", features = ["testing"] } namada_test_utils = { path = "../test_utils" } namada_tx = { path = "../tx", features = ["testing"]} namada_vote_ext = {path = "../vote_ext"} diff --git a/crates/sdk/src/args.rs b/crates/sdk/src/args.rs index e8d2cbcdd2..960095b9a3 100644 --- a/crates/sdk/src/args.rs +++ b/crates/sdk/src/args.rs @@ -4,16 +4,16 @@ use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration as StdDuration; -use namada_core::types::address::Address; -use namada_core::types::chain::ChainId; -use namada_core::types::dec::Dec; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::key::{common, SchemeType}; -use namada_core::types::masp::PaymentAddress; -use namada_core::types::storage::Epoch; -use namada_core::types::time::DateTimeUtc; -use namada_core::types::{storage, token}; +use namada_core::address::Address; +use namada_core::chain::ChainId; +use namada_core::dec::Dec; +use namada_core::ethereum_events::EthAddress; +use namada_core::keccak::KeccakHash; +use namada_core::key::{common, SchemeType}; +use namada_core::masp::PaymentAddress; +use namada_core::storage::Epoch; +use namada_core::time::DateTimeUtc; +use namada_core::{storage, token}; use namada_governance::cli::onchain::{ DefaultProposal, PgfFundingProposal, PgfStewardProposal, }; @@ -93,17 +93,17 @@ pub struct BpConversionTableEntry { impl NamadaTypes for SdkTypes { type AddrOrNativeToken = Address; type Address = Address; - type BalanceOwner = namada_core::types::masp::BalanceOwner; + type BalanceOwner = namada_core::masp::BalanceOwner; type BpConversionTable = HashMap; type ConfigRpcTendermintAddress = tendermint_config::net::Address; type Data = Vec; type EthereumAddress = (); - type Keypair = namada_core::types::key::common::SecretKey; - type PublicKey = namada_core::types::key::common::PublicKey; + type Keypair = namada_core::key::common::SecretKey; + type PublicKey = namada_core::key::common::PublicKey; type TendermintAddress = tendermint_config::net::Address; - type TransferSource = namada_core::types::masp::TransferSource; - type TransferTarget = namada_core::types::masp::TransferTarget; - type ViewingKey = namada_core::types::masp::ExtendedViewingKey; + type TransferSource = namada_core::masp::TransferSource; + type TransferTarget = namada_core::masp::TransferTarget; + type ViewingKey = namada_core::masp::ExtendedViewingKey; } /// Common query arguments diff --git a/crates/sdk/src/error.rs b/crates/sdk/src/error.rs index a8cb147da4..d50e385d41 100644 --- a/crates/sdk/src/error.rs +++ b/crates/sdk/src/error.rs @@ -1,11 +1,11 @@ //! Generic Error Type for all of the Shared Crate +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::ethereum_events::EthAddress; use namada_core::event::EventError; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::storage; -use namada_core::types::storage::Epoch; +use namada_core::storage; +use namada_core::storage::Epoch; use namada_tx::Tx; use prost::EncodeError; use tendermint_rpc::Error as RpcError; diff --git a/crates/sdk/src/eth_bridge/bridge_pool.rs b/crates/sdk/src/eth_bridge/bridge_pool.rs index 6712e463c8..8189953dfb 100644 --- a/crates/sdk/src/eth_bridge/bridge_pool.rs +++ b/crates/sdk/src/eth_bridge/bridge_pool.rs @@ -9,15 +9,15 @@ use borsh_ext::BorshSerializeExt; use ethbridge_bridge_contract::Bridge; use ethers::providers::Middleware; use futures::future::FutureExt; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::eth_abi::Encode; -use namada_core::types::eth_bridge_pool::{ +use namada_core::address::{Address, InternalAddress}; +use namada_core::eth_abi::Encode; +use namada_core::eth_bridge_pool::{ erc20_token_address, GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, }; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::voting_power::FractionalVotingPower; +use namada_core::ethereum_events::EthAddress; +use namada_core::keccak::KeccakHash; +use namada_core::voting_power::FractionalVotingPower; use namada_ethereum_bridge::storage::bridge_pool::get_pending_key; use namada_token::storage_key::balance_key; use namada_token::Amount; @@ -737,9 +737,9 @@ mod recommendations { use std::collections::BTreeSet; use borsh::BorshDeserialize; - use namada_core::types::ethereum_events::Uint as EthUint; - use namada_core::types::storage::BlockHeight; - use namada_core::types::uint::{self, Uint, I256}; + use namada_core::ethereum_events::Uint as EthUint; + use namada_core::storage::BlockHeight; + use namada_core::uint::{self, Uint, I256}; use namada_vote_ext::validator_set_update::{ EthAddrBook, VotingPowersMap, VotingPowersMapExt, }; @@ -1213,7 +1213,7 @@ mod recommendations { #[cfg(test)] mod test_recommendations { - use namada_core::types::address::Address; + use namada_core::address::Address; use super::*; use crate::io::StdIo; @@ -1236,7 +1236,7 @@ mod recommendations { amount: Default::default(), }, gas_fee: GasFee { - token: namada_core::types::address::nam(), + token: namada_core::address::nam(), amount: gas_amount.into(), payer: bertha_address(), }, @@ -1279,7 +1279,7 @@ mod recommendations { /// Add ETH to a conversion table. fn add_eth_to_conversion_table(&mut self) { self.conversion_table.insert( - namada_core::types::address::eth(), + namada_core::address::eth(), args::BpConversionTableEntry { alias: "ETH".into(), conversion_rate: 1e9, // 1 ETH = 1e9 GWEI @@ -1304,7 +1304,7 @@ mod recommendations { amount: Default::default(), }, gas_fee: GasFee { - token: namada_core::types::address::eth(), + token: namada_core::address::eth(), amount: 1_000_000_000_u64.into(), // 1 GWEI payer: bertha_address(), }, @@ -1537,14 +1537,14 @@ mod recommendations { let conversion_table = { let mut t = HashMap::new(); t.insert( - namada_core::types::address::apfel(), + namada_core::address::apfel(), args::BpConversionTableEntry { alias: APFEL.into(), conversion_rate: APF_RATE, }, ); t.insert( - namada_core::types::address::schnitzel(), + namada_core::address::schnitzel(), args::BpConversionTableEntry { alias: SCHNITZEL.into(), conversion_rate: SCH_RATE, @@ -1559,15 +1559,13 @@ mod recommendations { let transfer_paid_in_apfel = { let mut pending = ctx.pending.clone(); pending.transfer.amount = 1.into(); - pending.gas_fee.token = - namada_core::types::address::apfel(); + pending.gas_fee.token = namada_core::address::apfel(); pending }; let transfer_paid_in_schnitzel = { let mut pending = ctx.pending.clone(); pending.transfer.amount = 2.into(); - pending.gas_fee.token = - namada_core::types::address::schnitzel(); + pending.gas_fee.token = namada_core::address::schnitzel(); pending }; // add the transfers to the pool, and expect them to diff --git a/crates/sdk/src/eth_bridge/mod.rs b/crates/sdk/src/eth_bridge/mod.rs index ecebd05c32..98c84fcf6c 100644 --- a/crates/sdk/src/eth_bridge/mod.rs +++ b/crates/sdk/src/eth_bridge/mod.rs @@ -8,7 +8,7 @@ use std::ops::ControlFlow; pub use ethers; use ethers::providers::Middleware; use itertools::Either; -pub use namada_core::types::ethereum_structs as structs; +pub use namada_core::ethereum_structs as structs; pub use namada_ethereum_bridge::storage::eth_bridge_queries::*; pub use namada_ethereum_bridge::storage::parameters::*; pub use namada_ethereum_bridge::storage::wrapped_erc20s; diff --git a/crates/sdk/src/eth_bridge/validator_set.rs b/crates/sdk/src/eth_bridge/validator_set.rs index c11b9b62c6..f532d10825 100644 --- a/crates/sdk/src/eth_bridge/validator_set.rs +++ b/crates/sdk/src/eth_bridge/validator_set.rs @@ -10,10 +10,10 @@ use data_encoding::HEXLOWER; use ethbridge_bridge_contract::Bridge; use ethers::providers::Middleware; use futures::future::{self, FutureExt}; +use namada_core::eth_abi::EncodeCell; +use namada_core::ethereum_events::EthAddress; use namada_core::hints; -use namada_core::types::eth_abi::EncodeCell; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::storage::Epoch; +use namada_core::storage::Epoch; use namada_ethereum_bridge::storage::proof::EthereumProof; use namada_vote_ext::validator_set_update::{ ValidatorSetArgs, VotingPowersMap, @@ -24,7 +24,7 @@ use crate::control_flow::install_shutdown_signal; use crate::control_flow::time::{self, Duration, Instant}; use crate::error::{Error as SdkError, EthereumBridgeError, QueryError}; use crate::eth_bridge::ethers::abi::{AbiDecode, AbiType, Tokenizable}; -use crate::eth_bridge::ethers::core::types::TransactionReceipt; +use crate::eth_bridge::ethers::types::TransactionReceipt; use crate::eth_bridge::structs::Signature; use crate::internal_macros::{echo_error, trace_error}; use crate::io::Io; diff --git a/crates/sdk/src/events/log.rs b/crates/sdk/src/events/log.rs index 596c23bdc9..fa47d0fd3c 100644 --- a/crates/sdk/src/events/log.rs +++ b/crates/sdk/src/events/log.rs @@ -85,7 +85,7 @@ impl EventLog { #[cfg(test)] mod tests { - use namada_core::types::hash::Hash; + use namada_core::hash::Hash; use super::*; use crate::events::{EventLevel, EventType}; diff --git a/crates/sdk/src/events/log/dumb_queries.rs b/crates/sdk/src/events/log/dumb_queries.rs index 8a639b5a1b..1d2b0527a2 100644 --- a/crates/sdk/src/events/log/dumb_queries.rs +++ b/crates/sdk/src/events/log/dumb_queries.rs @@ -8,8 +8,8 @@ use std::collections::HashMap; -use namada_core::types::hash::Hash; -use namada_core::types::storage::BlockHeight; +use namada_core::hash::Hash; +use namada_core::storage::BlockHeight; use crate::events::{Event, EventType}; use crate::ibc::core::client::types::Height as IbcHeight; diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 74b15fbfd3..e495abe216 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -1,6 +1,6 @@ extern crate alloc; -pub use namada_core::{borsh, ibc, tendermint, tendermint_proto, types}; +pub use namada_core::*; #[cfg(feature = "tendermint-rpc")] pub use tendermint_rpc; pub use { @@ -36,13 +36,12 @@ use std::path::PathBuf; use std::str::FromStr; use args::{InputAmount, SdkTypes}; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::ethereum_events::EthAddress; use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId}; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::key::*; -use namada_core::types::masp::{TransferSource, TransferTarget}; -use namada_core::types::token; +use namada_core::key::*; +use namada_core::masp::{TransferSource, TransferTarget}; use namada_tx::data::wrapper::GasLimit; use namada_tx::Tx; use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; @@ -767,17 +766,15 @@ pub mod testing { use ibc::primitives::proto::Any; use masp_primitives::transaction::TransparentAddress; use namada_account::{InitAccount, UpdateAccount}; - use namada_core::types::address::testing::{ + use namada_core::address::testing::{ arb_established_address, arb_non_internal_address, }; - use namada_core::types::address::MASP; - use namada_core::types::eth_bridge_pool::PendingTransfer; - use namada_core::types::hash::testing::arb_hash; - use namada_core::types::storage::testing::arb_epoch; - use namada_core::types::token::testing::{ - arb_denominated_amount, arb_transfer, - }; - use namada_core::types::token::Transfer; + use namada_core::address::MASP; + use namada_core::eth_bridge_pool::PendingTransfer; + use namada_core::hash::testing::arb_hash; + use namada_core::storage::testing::arb_epoch; + use namada_core::token::testing::{arb_denominated_amount, arb_transfer}; + use namada_core::token::Transfer; use namada_governance::storage::proposal::testing::{ arb_init_proposal, arb_vote_proposal, }; @@ -797,9 +794,13 @@ pub mod testing { use super::*; use crate::account::tests::{arb_init_account, arb_update_account}; + use crate::chain::ChainId; + use crate::eth_bridge_pool::testing::arb_pending_transfer; + use crate::key::testing::arb_common_pk; use crate::masp::testing::{ arb_deshielding_transfer, arb_shielded_transfer, arb_shielding_transfer, }; + use crate::time::{DateTime, DateTimeUtc, Utc}; use crate::tx::data::pgf::tests::arb_update_steward_commission; use crate::tx::data::pos::tests::{ arb_become_validator, arb_bond, arb_commission_change, @@ -807,10 +808,6 @@ pub mod testing { arb_withdraw, }; use crate::tx::{Code, Commitment, Header, MaspBuilder, Section}; - use crate::types::chain::ChainId; - use crate::types::eth_bridge_pool::testing::arb_pending_transfer; - use crate::types::key::testing::arb_common_pk; - use crate::types::time::{DateTime, DateTimeUtc, Utc}; #[derive(Debug)] #[allow(clippy::large_enum_variant)] diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index c3cf8d1bf3..ae95247866 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -51,15 +51,15 @@ use masp_proofs::bellman::groth16::PreparedVerifyingKey; use masp_proofs::bls12_381::Bls12; use masp_proofs::prover::LocalTxProver; use masp_proofs::sapling::SaplingVerificationContext; -use namada_core::types::address::{Address, MASP}; -use namada_core::types::dec::Dec; -use namada_core::types::masp::{ +use namada_core::address::{Address, MASP}; +use namada_core::dec::Dec; +use namada_core::masp::{ encode_asset_type, AssetData, BalanceOwner, ExtendedViewingKey, PaymentAddress, TransferSource, TransferTarget, }; -use namada_core::types::storage::{BlockHeight, Epoch, IndexedTx, TxIndex}; -use namada_core::types::time::{DateTimeUtc, DurationSecs}; -use namada_core::types::uint::Uint; +use namada_core::storage::{BlockHeight, Epoch, IndexedTx, TxIndex}; +use namada_core::time::{DateTimeUtc, DurationSecs}; +use namada_core::uint::Uint; use namada_ibc::IbcMessage; use namada_token::{self as token, Denomination, MaspDigitPos, Transfer}; use namada_tx::data::{TxResult, WrapperTx}; @@ -702,11 +702,7 @@ impl ShieldedContext { ) -> Result< BTreeMap< IndexedTx, - ( - Epoch, - BTreeSet, - Transaction, - ), + (Epoch, BTreeSet, Transaction), >, Error, > { @@ -791,8 +787,7 @@ impl ShieldedContext { tx: &Tx, action_arg: ExtractShieldedActionArg<'args, C>, check_header: bool, - ) -> Result<(BTreeSet, Transaction), Error> - { + ) -> Result<(BTreeSet, Transaction), Error> { let maybe_transaction = if check_header { let tx_header = tx.header(); // NOTE: simply looking for masp sections attached to the tx @@ -943,7 +938,7 @@ impl ShieldedContext { &mut self, indexed_tx: IndexedTx, epoch: Epoch, - tx_changed_keys: &BTreeSet, + tx_changed_keys: &BTreeSet, shielded: &Transaction, native_token: Address, ) -> Result<(), Error> { @@ -2256,8 +2251,7 @@ impl ShieldedContext { #[cfg(feature = "testing")] { - let builder_hash = - namada_core::types::hash::Hash::sha256(&builder_bytes); + let builder_hash = namada_core::hash::Hash::sha256(&builder_bytes); let saved_filepath = env::current_dir() .map_err(|e| Error::Other(e.to_string()))? @@ -2567,7 +2561,7 @@ enum ExtractShieldedActionArg<'args, C: Client + Sync> { async fn extract_payload_from_shielded_action<'args, C: Client + Sync>( tx_data: &[u8], args: ExtractShieldedActionArg<'args, C>, -) -> Result<(BTreeSet, Transaction), Error> { +) -> Result<(BTreeSet, Transaction), Error> { let message = namada_ibc::decode_message(tx_data) .map_err(|e| Error::Other(e.to_string()))?; @@ -2644,7 +2638,7 @@ async fn extract_payload_from_shielded_action<'args, C: Client + Sync>( TxResult::from_str(&attribute.value).unwrap(); for ibc_event in &tx_result.ibc_events { let event = - namada_core::types::ibc::get_shielded_transfer( + namada_core::ibc::get_shielded_transfer( ibc_event, ) .ok() @@ -2814,15 +2808,15 @@ pub mod testing { use proptest::{collection, option, prop_compose}; use super::*; + use crate::address::testing::arb_address; use crate::masp_primitives::consensus::BranchId; use crate::masp_primitives::constants::VALUE_COMMITMENT_RANDOMNESS_GENERATOR; use crate::masp_primitives::merkle_tree::FrozenCommitmentTree; use crate::masp_primitives::sapling::keys::OutgoingViewingKey; use crate::masp_primitives::sapling::redjubjub::PrivateKey; use crate::masp_primitives::transaction::components::transparent::testing::arb_transparent_address; + use crate::storage::testing::arb_epoch; use crate::token::testing::arb_denomination; - use crate::types::address::testing::arb_address; - use crate::types::storage::testing::arb_epoch; #[derive(Debug, Clone)] // Adapts a CSPRNG from a PRNG for proptesting diff --git a/crates/sdk/src/queries/mod.rs b/crates/sdk/src/queries/mod.rs index bf30131170..5753b989c5 100644 --- a/crates/sdk/src/queries/mod.rs +++ b/crates/sdk/src/queries/mod.rs @@ -2,7 +2,7 @@ //! defined via `router!` macro. // Re-export to show in rustdoc! -use namada_core::types::storage::BlockHeight; +use namada_core::storage::BlockHeight; use namada_state::{DBIter, StorageHasher, DB}; pub use shell::Shell; use shell::SHELL; @@ -97,7 +97,7 @@ pub fn require_no_data(request: &RequestQuery) -> namada_storage::Result<()> { #[cfg(any(test, feature = "testing"))] mod testing { - use namada_core::types::storage::BlockHeight; + use namada_core::storage::BlockHeight; use namada_state::testing::TestWlStorage; use tendermint_rpc::Response; @@ -133,10 +133,7 @@ mod testing { namada_parameters::storage::get_max_block_gas_key(); wl_storage .storage - .write( - &max_block_gas_key, - namada_core::types::encode(&20_000_000_u64), - ) + .write(&max_block_gas_key, namada_core::encode(&20_000_000_u64)) .expect( "Max block gas parameter must be initialized in storage", ); diff --git a/crates/sdk/src/queries/router.rs b/crates/sdk/src/queries/router.rs index 25a55ecf7f..a401094f6c 100644 --- a/crates/sdk/src/queries/router.rs +++ b/crates/sdk/src/queries/router.rs @@ -401,7 +401,7 @@ macro_rules! pattern_and_handler_to_method { `storage_value` and `storage_prefix`) from `storage_value`."] pub async fn storage_value(&self, client: &CLIENT, data: Option>, - height: Option, + height: Option, prove: bool, $( $param: &$param_ty ),* ) @@ -453,7 +453,7 @@ macro_rules! pattern_and_handler_to_method { `storage_value` and `storage_prefix`) from `" $handle "`."] pub async fn $handle(&self, client: &CLIENT, data: Option>, - height: Option, + height: Option, prove: bool, $( $param: &$param_ty ),* ) @@ -844,8 +844,8 @@ macro_rules! router { #[cfg(test)] mod test_rpc_handlers { use borsh_ext::BorshSerializeExt; - use namada_core::types::storage::Epoch; - use namada_core::types::token; + use namada_core::storage::Epoch; + use namada_core::token; use namada_state::{DBIter, StorageHasher, DB}; use crate::queries::{ @@ -971,8 +971,8 @@ mod test_rpc_handlers { /// ``` #[cfg(test)] mod test_rpc { - use namada_core::types::storage::Epoch; - use namada_core::types::token; + use namada_core::storage::Epoch; + use namada_core::token; use super::test_rpc_handlers::*; @@ -1009,10 +1009,10 @@ mod test_rpc { #[cfg(test)] mod test { + use namada_core::storage::Epoch; use namada_core::tendermint::block; - use namada_core::types::storage::Epoch; - use namada_core::types::token; - use namada_core::types::token::NATIVE_MAX_DECIMAL_PLACES; + use namada_core::token; + use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use super::test_rpc::TEST_RPC; use crate::queries::testing::TestClient; diff --git a/crates/sdk/src/queries/shell.rs b/crates/sdk/src/queries/shell.rs index 3450425eff..4c37ade7ce 100644 --- a/crates/sdk/src/queries/shell.rs +++ b/crates/sdk/src/queries/shell.rs @@ -8,15 +8,15 @@ use masp_primitives::asset_type::AssetType; use masp_primitives::merkle_tree::MerklePath; use masp_primitives::sapling::Node; use namada_account::{Account, AccountPublicKeysMap}; +use namada_core::address::Address; +use namada_core::dec::Dec; +use namada_core::hash::Hash; use namada_core::hints; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::hash::Hash; -use namada_core::types::storage::{ +use namada_core::storage::{ self, BlockHeight, BlockResults, Epoch, KeySeg, PrefixValue, }; -use namada_core::types::token::{Denomination, MaspDigitPos}; -use namada_core::types::uint::Uint; +use namada_core::token::{Denomination, MaspDigitPos}; +use namada_core::uint::Uint; use namada_state::{DBIter, LastBlock, StorageHasher, DB}; use namada_storage::{self, ResultExt, StorageRead}; #[cfg(any(test, feature = "async-client"))] @@ -615,7 +615,7 @@ where #[cfg(test)] mod test { - use namada_core::types::address; + use namada_core::address; use namada_token::storage_key::balance_key; use crate::queries::RPC; diff --git a/crates/sdk/src/queries/shell/eth_bridge.rs b/crates/sdk/src/queries/shell/eth_bridge.rs index 92ee5f3ca8..913155d5b2 100644 --- a/crates/sdk/src/queries/shell/eth_bridge.rs +++ b/crates/sdk/src/queries/shell/eth_bridge.rs @@ -6,20 +6,17 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use borsh_ext::BorshSerializeExt; -use namada_core::hints; -use namada_core::types::address::Address; -use namada_core::types::eth_abi::{Encode, EncodeCell}; -use namada_core::types::eth_bridge_pool::{ - PendingTransfer, PendingTransferAppendix, -}; -use namada_core::types::ethereum_events::{ +use namada_core::address::Address; +use namada_core::eth_abi::{Encode, EncodeCell}; +use namada_core::eth_bridge_pool::{PendingTransfer, PendingTransferAppendix}; +use namada_core::ethereum_events::{ EthAddress, EthereumEvent, TransferToEthereum, }; -use namada_core::types::ethereum_structs; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::storage::{BlockHeight, DbKeySeg, Epoch, Key}; -use namada_core::types::token::Amount; -use namada_core::types::voting_power::FractionalVotingPower; +use namada_core::keccak::KeccakHash; +use namada_core::storage::{BlockHeight, DbKeySeg, Epoch, Key}; +use namada_core::token::Amount; +use namada_core::voting_power::FractionalVotingPower; +use namada_core::{ethereum_structs, hints}; use namada_ethereum_bridge::protocol::transactions::votes::{ EpochedVotingPower, EpochedVotingPowerExt, }; @@ -837,15 +834,15 @@ mod test_ethbridge_router { use std::collections::BTreeMap; use assert_matches::assert_matches; - use namada_core::types::address::nam; - use namada_core::types::address::testing::established_address_1; - use namada_core::types::eth_abi::Encode; - use namada_core::types::eth_bridge_pool::{ + use namada_core::address::nam; + use namada_core::address::testing::established_address_1; + use namada_core::eth_abi::Encode; + use namada_core::eth_bridge_pool::{ GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, }; - use namada_core::types::ethereum_events::EthAddress; - use namada_core::types::storage::BlockHeight; - use namada_core::types::voting_power::{ + use namada_core::ethereum_events::EthAddress; + use namada_core::storage::BlockHeight; + use namada_core::voting_power::{ EthBridgeVotingPower, FractionalVotingPower, }; use namada_ethereum_bridge::protocol::transactions::validator_set_update::aggregate_votes; @@ -1443,8 +1440,8 @@ mod test_ethbridge_router { .write(&get_pending_key(&transfer), &transfer) .expect("Test failed"); - let event_transfer: namada_core::types::ethereum_events::TransferToEthereum - = (&transfer).into(); + let event_transfer: namada_core::ethereum_events::TransferToEthereum = + (&transfer).into(); let eth_event = EthereumEvent::TransfersToEthereum { nonce: Default::default(), transfers: vec![event_transfer.clone()], @@ -1791,7 +1788,7 @@ mod test_ethbridge_router { #[cfg(any(feature = "testing", test))] #[allow(dead_code)] mod test_utils { - use namada_core::types::address::Address; + use namada_core::address::Address; pub use namada_ethereum_bridge::test_utils::*; /// An established user address for testing & development diff --git a/crates/sdk/src/queries/types.rs b/crates/sdk/src/queries/types.rs index 614a717a8e..00b57368cc 100644 --- a/crates/sdk/src/queries/types.rs +++ b/crates/sdk/src/queries/types.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; -use namada_core::types::storage::BlockHeight; +use namada_core::storage::BlockHeight; use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use thiserror::Error; diff --git a/crates/sdk/src/queries/vp/pgf.rs b/crates/sdk/src/queries/vp/pgf.rs index 4b8431e854..7b767911bb 100644 --- a/crates/sdk/src/queries/vp/pgf.rs +++ b/crates/sdk/src/queries/vp/pgf.rs @@ -1,4 +1,4 @@ -use namada_core::types::address::Address; +use namada_core::address::Address; use namada_governance::pgf::parameters::PgfParameters; use namada_governance::pgf::storage::steward::StewardDetail; use namada_governance::storage::proposal::StoragePgfFunding; diff --git a/crates/sdk/src/queries/vp/pos.rs b/crates/sdk/src/queries/vp/pos.rs index 47a7f33cf9..2182ebbc03 100644 --- a/crates/sdk/src/queries/vp/pos.rs +++ b/crates/sdk/src/queries/vp/pos.rs @@ -3,10 +3,10 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::key::common; -use namada_core::types::storage::Epoch; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::key::common; +use namada_core::storage::Epoch; +use namada_core::token; use namada_proof_of_stake::parameters::PosParams; use namada_proof_of_stake::queries::{ find_delegation_validators, find_delegations, diff --git a/crates/sdk/src/queries/vp/token.rs b/crates/sdk/src/queries/vp/token.rs index fb77a396a4..e9696e796d 100644 --- a/crates/sdk/src/queries/vp/token.rs +++ b/crates/sdk/src/queries/vp/token.rs @@ -1,7 +1,7 @@ //! Token validity predicate queries -use namada_core::types::address::Address; -use namada_core::types::token; +use namada_core::address::Address; +use namada_core::token; use namada_state::{DBIter, StorageHasher, DB}; use namada_token::{read_denom, read_total_supply}; @@ -40,8 +40,8 @@ where #[cfg(any(test, feature = "async-client"))] pub mod client_only_methods { use borsh::BorshDeserialize; - use namada_core::types::address::Address; - use namada_core::types::token; + use namada_core::address::Address; + use namada_core::token; use namada_token::storage_key::balance_key; use super::Token; diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index bed1ebe51d..eab9238337 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -10,16 +10,16 @@ use masp_primitives::asset_type::AssetType; use masp_primitives::merkle_tree::MerklePath; use masp_primitives::sapling::Node; use namada_account::Account; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::hash::Hash; -use namada_core::types::key::common; -use namada_core::types::storage::{ +use namada_core::address::{Address, InternalAddress}; +use namada_core::hash::Hash; +use namada_core::key::common; +use namada_core::storage::{ BlockHeight, BlockResults, Epoch, Key, PrefixValue, }; -use namada_core::types::token::{ +use namada_core::token::{ Amount, DenominatedAmount, Denomination, MaspDigitPos, }; -use namada_core::types::{storage, token}; +use namada_core::{storage, token}; use namada_governance::parameters::GovernanceParameters; use namada_governance::pgf::parameters::PgfParameters; use namada_governance::pgf::storage::steward::StewardDetail; diff --git a/crates/sdk/src/signing.rs b/crates/sdk/src/signing.rs index 1519b1ae49..961c796c52 100644 --- a/crates/sdk/src/signing.rs +++ b/crates/sdk/src/signing.rs @@ -11,17 +11,15 @@ use masp_primitives::transaction::components::sapling::fees::{ InputView, OutputView, }; use namada_account::{AccountPublicKeysMap, InitAccount, UpdateAccount}; -use namada_core::types::address::{ - Address, ImplicitAddress, InternalAddress, MASP, -}; -use namada_core::types::key::*; -use namada_core::types::masp::{AssetData, ExtendedViewingKey, PaymentAddress}; -use namada_core::types::sign::SignatureIndex; -use namada_core::types::storage::Epoch; -use namada_core::types::token; -use namada_core::types::token::Transfer; -// use namada_core::types::storage::Key; -use namada_core::types::token::{Amount, DenominatedAmount}; +use namada_core::address::{Address, ImplicitAddress, InternalAddress, MASP}; +use namada_core::key::*; +use namada_core::masp::{AssetData, ExtendedViewingKey, PaymentAddress}; +use namada_core::sign::SignatureIndex; +use namada_core::storage::Epoch; +use namada_core::token; +use namada_core::token::Transfer; +// use namada_core::storage::Key; +use namada_core::token::{Amount, DenominatedAmount}; use namada_governance::storage::proposal::{ InitProposalData, ProposalType, VoteProposalData, }; @@ -41,6 +39,7 @@ use tokio::sync::RwLock; use super::masp::{ShieldedContext, ShieldedTransfer}; use crate::args::SdkTypes; use crate::error::{EncodingError, Error, TxSubmitError}; +use crate::eth_bridge_pool::PendingTransfer; use crate::ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use crate::ibc::primitives::proto::Any; use crate::io::*; @@ -56,7 +55,6 @@ use crate::tx::{ TX_UPDATE_STEWARD_COMMISSION, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM, VP_USER_WASM, }; -use crate::types::eth_bridge_pool::PendingTransfer; pub use crate::wallet::store::AddressVpType; use crate::wallet::{Wallet, WalletIo}; use crate::{args, display_line, rpc, MaybeSend, Namada}; @@ -506,7 +504,7 @@ pub async fn wrap_tx( Some(diff) if !diff.is_zero() => { if let Some(spending_key) = args.fee_unshield.clone() { // Unshield funds for fee payment - let target = namada_core::types::masp::TransferTarget::Address( + let target = namada_core::masp::TransferTarget::Address( fee_payer_address.clone(), ); let fee_amount = DenominatedAmount::new( @@ -638,7 +636,7 @@ pub async fn wrap_tx( let mut hasher = sha2::Sha256::new(); section.hash(&mut hasher); tx.add_section(section); - namada_core::types::hash::Hash(hasher.finalize().into()) + namada_core::hash::Hash(hasher.finalize().into()) }); tx.add_wrapper( diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index a5ff9da0da..ee8c1de075 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -19,6 +19,9 @@ use masp_primitives::transaction::components::transparent::fees::{ }; use masp_primitives::transaction::components::I128Sum; use namada_account::{InitAccount, UpdateAccount}; +use namada_core::address::{Address, InternalAddress, MASP}; +use namada_core::dec::Dec; +use namada_core::hash::Hash; use namada_core::ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use namada_core::ibc::apps::transfer::types::packet::PacketData; use namada_core::ibc::apps::transfer::types::PrefixedCoin; @@ -26,15 +29,12 @@ use namada_core::ibc::core::channel::types::timeout::TimeoutHeight; use namada_core::ibc::core::client::types::Height as IbcHeight; use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId}; use namada_core::ibc::primitives::{Msg, Timestamp as IbcTimestamp}; -use namada_core::types::address::{Address, InternalAddress, MASP}; -use namada_core::types::dec::Dec; -use namada_core::types::hash::Hash; -use namada_core::types::ibc::{IbcShieldedTransfer, MsgShieldedTransfer}; -use namada_core::types::key::*; -use namada_core::types::masp::{AssetData, TransferSource, TransferTarget}; -use namada_core::types::storage::Epoch; -use namada_core::types::time::DateTimeUtc; -use namada_core::types::{storage, token}; +use namada_core::ibc::{IbcShieldedTransfer, MsgShieldedTransfer}; +use namada_core::key::*; +use namada_core::masp::{AssetData, TransferSource, TransferTarget}; +use namada_core::storage::Epoch; +use namada_core::time::DateTimeUtc; +use namada_core::{storage, token}; use namada_governance::cli::onchain::{ DefaultProposal, OnChainProposal, PgfFundingProposal, PgfStewardProposal, }; diff --git a/crates/sdk/src/wallet/alias.rs b/crates/sdk/src/wallet/alias.rs index 48ab4a9fa0..1801d5fbad 100644 --- a/crates/sdk/src/wallet/alias.rs +++ b/crates/sdk/src/wallet/alias.rs @@ -7,7 +7,7 @@ use std::io::Read; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::{Address, InternalAddress}; +use namada_core::address::{Address, InternalAddress}; use serde::{Deserialize, Serialize}; /// Aliases created from raw strings are kept in-memory as given, but their diff --git a/crates/sdk/src/wallet/derivation_path.rs b/crates/sdk/src/wallet/derivation_path.rs index 3210450d26..79296038ac 100644 --- a/crates/sdk/src/wallet/derivation_path.rs +++ b/crates/sdk/src/wallet/derivation_path.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use derivation_path::{ChildIndex, DerivationPath as DerivationPathInner}; use masp_primitives::zip32; -use namada_core::types::key::SchemeType; +use namada_core::key::SchemeType; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use thiserror::Error; use tiny_hderive::bip44::{ @@ -272,7 +272,7 @@ impl From for Vec { #[cfg(test)] mod tests { - use namada_core::types::key::SchemeType; + use namada_core::key::SchemeType; use super::DerivationPath; diff --git a/crates/sdk/src/wallet/mod.rs b/crates/sdk/src/wallet/mod.rs index de8c52ff8c..11e3f0eb19 100644 --- a/crates/sdk/src/wallet/mod.rs +++ b/crates/sdk/src/wallet/mod.rs @@ -12,9 +12,9 @@ use std::str::FromStr; use alias::Alias; use bip39::{Language, Mnemonic, MnemonicType, Seed}; use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::key::*; -use namada_core::types::masp::{ +use namada_core::address::Address; +use namada_core::key::*; +use namada_core::masp::{ ExtendedSpendingKey, ExtendedViewingKey, PaymentAddress, }; pub use pre_genesis::gen_key_to_store; diff --git a/crates/sdk/src/wallet/pre_genesis.rs b/crates/sdk/src/wallet/pre_genesis.rs index abbb918470..dbe1a11571 100644 --- a/crates/sdk/src/wallet/pre_genesis.rs +++ b/crates/sdk/src/wallet/pre_genesis.rs @@ -1,5 +1,5 @@ //! Provides functionality for managing validator keys -use namada_core::types::key::{common, SchemeType}; +use namada_core::key::{common, SchemeType}; use rand::{CryptoRng, Rng}; use serde::{Deserialize, Serialize}; use thiserror::Error; diff --git a/crates/sdk/src/wallet/store.rs b/crates/sdk/src/wallet/store.rs index 37d2dc1e44..6e2fd77faa 100644 --- a/crates/sdk/src/wallet/store.rs +++ b/crates/sdk/src/wallet/store.rs @@ -7,9 +7,9 @@ use std::str::FromStr; use bimap::BiBTreeMap; use itertools::Itertools; use masp_primitives::zip32; -use namada_core::types::address::{Address, ImplicitAddress}; -use namada_core::types::key::*; -use namada_core::types::masp::{ +use namada_core::address::{Address, ImplicitAddress}; +use namada_core::key::*; +use namada_core::masp::{ ExtendedSpendingKey, ExtendedViewingKey, PaymentAddress, }; use serde::{Deserialize, Serialize}; diff --git a/crates/shielded_token/src/conversion.rs b/crates/shielded_token/src/conversion.rs index b2a560d3c5..d247b65026 100644 --- a/crates/shielded_token/src/conversion.rs +++ b/crates/shielded_token/src/conversion.rs @@ -1,8 +1,8 @@ //! MASP rewards conversions -use namada_core::types::address::{Address, MASP}; -use namada_core::types::dec::Dec; -use namada_core::types::uint::Uint; +use namada_core::address::{Address, MASP}; +use namada_core::dec::Dec; +use namada_core::uint::Uint; use namada_parameters as parameters; use namada_storage::{StorageRead, StorageWrite}; use namada_trans_token::inflation::{ @@ -208,8 +208,8 @@ where use masp_primitives::merkle_tree::FrozenCommitmentTree; use masp_primitives::sapling::Node; use masp_primitives::transaction::components::I128Sum as MaspAmount; - use namada_core::types::masp::encode_asset_type; - use namada_core::types::storage::Epoch; + use namada_core::masp::encode_asset_type; + use namada_core::storage::Epoch; use namada_storage::ResultExt; use namada_trans_token::{MaspDigitPos, NATIVE_MAX_DECIMAL_PLACES}; use rayon::iter::{ @@ -485,7 +485,7 @@ where // Update the anchor in storage storage.write( &crate::storage_key::masp_convert_anchor_key(), - namada_core::types::hash::Hash( + namada_core::hash::Hash( bls12_381::Scalar::from(storage.conversion_state().tree.root()) .to_bytes(), ), @@ -526,10 +526,10 @@ mod tests { use std::collections::HashMap; use std::str::FromStr; - use namada_core::types::address; - use namada_core::types::dec::testing::arb_non_negative_dec; - use namada_core::types::time::DurationSecs; - use namada_core::types::token::testing::arb_amount; + use namada_core::address; + use namada_core::dec::testing::arb_non_negative_dec; + use namada_core::time::DurationSecs; + use namada_core::token::testing::arb_amount; use namada_parameters::{EpochDuration, Parameters}; use namada_storage::testing::TestStorage; use namada_trans_token::{write_denom, Denomination}; diff --git a/crates/shielded_token/src/lib.rs b/crates/shielded_token/src/lib.rs index b5f0583738..08c70719b8 100644 --- a/crates/shielded_token/src/lib.rs +++ b/crates/shielded_token/src/lib.rs @@ -8,7 +8,7 @@ pub mod utils; use std::str::FromStr; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::dec::Dec; +use namada_core::dec::Dec; pub use namada_storage::conversion_state::{ ConversionState, WithConversionState, }; diff --git a/crates/shielded_token/src/storage.rs b/crates/shielded_token/src/storage.rs index 05b42c7ab7..0c975296ab 100644 --- a/crates/shielded_token/src/storage.rs +++ b/crates/shielded_token/src/storage.rs @@ -1,7 +1,7 @@ -use namada_core::types::address::Address; -use namada_core::types::token; -use namada_core::types::token::Amount; -use namada_core::types::uint::Uint; +use namada_core::address::Address; +use namada_core::token; +use namada_core::token::Amount; +use namada_core::uint::Uint; use namada_storage as storage; use namada_storage::{StorageRead, StorageWrite}; use storage::ResultExt; diff --git a/crates/shielded_token/src/storage_key.rs b/crates/shielded_token/src/storage_key.rs index e58ffe93a0..832a8ac9dc 100644 --- a/crates/shielded_token/src/storage_key.rs +++ b/crates/shielded_token/src/storage_key.rs @@ -2,9 +2,9 @@ use masp_primitives::bls12_381::Scalar; use masp_primitives::sapling::Nullifier; -use namada_core::types::address::{self, Address}; -use namada_core::types::hash::Hash; -use namada_core::types::storage::{self, DbKeySeg, KeySeg}; +use namada_core::address::{self, Address}; +use namada_core::hash::Hash; +use namada_core::storage::{self, DbKeySeg, KeySeg}; use namada_trans_token::storage_key::parameter_prefix; /// Key segment prefix for pinned shielded transactions diff --git a/crates/shielded_token/src/utils.rs b/crates/shielded_token/src/utils.rs index 4dfbaa9e89..42fc6413dd 100644 --- a/crates/shielded_token/src/utils.rs +++ b/crates/shielded_token/src/utils.rs @@ -3,7 +3,7 @@ use masp_primitives::merkle_tree::CommitmentTree; use masp_primitives::sapling::Node; use masp_primitives::transaction::Transaction; -use namada_core::types::storage::IndexedTx; +use namada_core::storage::IndexedTx; use namada_storage::{Error, Result, StorageRead, StorageWrite}; use crate::storage_key::{ diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index fa7b0ab116..f111212c5e 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -7,22 +7,20 @@ use core::fmt::Debug; use std::cmp::Ordering; use std::format; +use namada_core::address::{Address, EstablishedAddressGen, InternalAddress}; use namada_core::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt}; -use namada_core::tendermint::merkle::proof::ProofOps; -use namada_core::types::address::{ - Address, EstablishedAddressGen, InternalAddress, -}; -use namada_core::types::chain::{ChainId, CHAIN_ID_LENGTH}; -use namada_core::types::eth_bridge_pool::is_pending_transfer_key; -use namada_core::types::hash::{Error as HashError, Hash}; -pub use namada_core::types::hash::{Sha256Hasher, StorageHasher}; -pub use namada_core::types::storage::{ +use namada_core::chain::{ChainId, CHAIN_ID_LENGTH}; +use namada_core::eth_bridge_pool::is_pending_transfer_key; +use namada_core::hash::{Error as HashError, Hash}; +pub use namada_core::hash::{Sha256Hasher, StorageHasher}; +pub use namada_core::storage::{ BlockHash, BlockHeight, BlockResults, Epoch, Epochs, EthEventsQueue, Header, Key, KeySeg, TxIndex, BLOCK_HASH_LENGTH, BLOCK_HEIGHT_LENGTH, EPOCH_TYPE_LENGTH, }; -use namada_core::types::time::DateTimeUtc; -use namada_core::types::{encode, ethereum_structs, storage}; +use namada_core::tendermint::merkle::proof::ProofOps; +use namada_core::time::DateTimeUtc; +use namada_core::{encode, ethereum_structs, storage}; use namada_gas::{ MEMORY_ACCESS_GAS_PER_BYTE, STORAGE_ACCESS_GAS_PER_BYTE, STORAGE_WRITE_GAS_PER_BYTE, @@ -156,9 +154,9 @@ pub enum Error { #[error("Found an unknown key: {key}")] UnknownKey { key: String }, #[error("Storage key error {0}")] - KeyError(namada_core::types::storage::Error), + KeyError(namada_core::storage::Error), #[error("Coding error: {0}")] - CodingError(#[from] namada_core::types::DecodeError), + CodingError(#[from] namada_core::DecodeError), #[error("Merkle tree error: {0}")] MerkleTreeError(MerkleTreeError), #[error("DB error: {0}")] @@ -1102,8 +1100,8 @@ impl From for Error { /// Helpers for testing components that depend on storage #[cfg(any(test, feature = "testing"))] pub mod testing { - use namada_core::types::address; - use namada_core::types::hash::Sha256Hasher; + use namada_core::address; + use namada_core::hash::Sha256Hasher; use super::mockdb::MockDB; use super::*; @@ -1172,9 +1170,9 @@ mod tests { use std::collections::BTreeMap; use chrono::{TimeZone, Utc}; - use namada_core::types::dec::Dec; - use namada_core::types::time::{self, Duration}; - use namada_core::types::token; + use namada_core::dec::Dec; + use namada_core::time::{self, Duration}; + use namada_core::token; use namada_parameters::Parameters; use proptest::prelude::*; use proptest::test_runner::Config; diff --git a/crates/state/src/wl_storage.rs b/crates/state/src/wl_storage.rs index 270a8fc005..4dc2f36fae 100644 --- a/crates/state/src/wl_storage.rs +++ b/crates/state/src/wl_storage.rs @@ -2,10 +2,10 @@ use std::iter::Peekable; -use namada_core::types::address::Address; -use namada_core::types::hash::{Hash, StorageHasher}; -use namada_core::types::storage::{self, BlockHeight, Epochs}; -use namada_core::types::time::DateTimeUtc; +use namada_core::address::Address; +use namada_core::hash::{Hash, StorageHasher}; +use namada_core::storage::{self, BlockHeight, Epochs}; +use namada_core::time::DateTimeUtc; use namada_parameters::EpochDuration; use namada_storage::conversion_state::{ConversionState, WithConversionState}; use namada_storage::{ResultExt, StorageRead, StorageWrite}; @@ -591,9 +591,9 @@ where mod tests { use std::collections::BTreeMap; + use namada_core::address::InternalAddress; use namada_core::borsh::{BorshDeserialize, BorshSerializeExt}; - use namada_core::types::address::InternalAddress; - use namada_core::types::storage::DbKeySeg; + use namada_core::storage::DbKeySeg; use proptest::prelude::*; use proptest::test_runner::Config; // Use `RUST_LOG=info` (or another tracing level) and `--nocapture` to diff --git a/crates/state/src/write_log.rs b/crates/state/src/write_log.rs index 840bf0dd8b..0261d3e288 100644 --- a/crates/state/src/write_log.rs +++ b/crates/state/src/write_log.rs @@ -4,12 +4,10 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use itertools::Itertools; -use namada_core::types::address::{ - Address, EstablishedAddressGen, InternalAddress, -}; -use namada_core::types::hash::{Hash, StorageHasher}; -use namada_core::types::ibc::IbcEvent; -use namada_core::types::storage; +use namada_core::address::{Address, EstablishedAddressGen, InternalAddress}; +use namada_core::hash::{Hash, StorageHasher}; +use namada_core::ibc::IbcEvent; +use namada_core::storage; use namada_gas::{MEMORY_ACCESS_GAS_PER_BYTE, STORAGE_WRITE_GAS_PER_BYTE}; use namada_replay_protection as replay_protection; use namada_trans_token::storage_key::{ @@ -731,8 +729,8 @@ impl WriteLog { #[cfg(test)] mod tests { use assert_matches::assert_matches; - use namada_core::types::hash::Hash; - use namada_core::types::{address, storage}; + use namada_core::hash::Hash; + use namada_core::{address, storage}; use pretty_assertions::assert_eq; use proptest::prelude::*; @@ -1108,9 +1106,9 @@ mod tests { /// Helpers for testing with write log. #[cfg(any(test, feature = "testing"))] pub mod testing { - use namada_core::types::address::testing::arb_address; - use namada_core::types::hash::HASH_LENGTH; - use namada_core::types::storage::testing::arb_key; + use namada_core::address::testing::arb_address; + use namada_core::hash::HASH_LENGTH; + use namada_core::storage::testing::arb_key; use proptest::collection; use proptest::prelude::{any, prop_oneof, Just, Strategy}; diff --git a/crates/storage/src/collections/lazy_map.rs b/crates/storage/src/collections/lazy_map.rs index f2d24f7dd1..7c7ea1c2b9 100644 --- a/crates/storage/src/collections/lazy_map.rs +++ b/crates/storage/src/collections/lazy_map.rs @@ -6,7 +6,7 @@ use std::hash::Hash; use std::marker::PhantomData; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::storage::{self, DbKeySeg, KeySeg}; +use namada_core::storage::{self, DbKeySeg, KeySeg}; use thiserror::Error; use super::super::Result; @@ -539,7 +539,7 @@ where #[cfg(test)] mod test { - use namada_core::types::address::{self, Address}; + use namada_core::address::{self, Address}; use super::*; use crate::testing::TestStorage; diff --git a/crates/storage/src/collections/lazy_set.rs b/crates/storage/src/collections/lazy_set.rs index ab4e41705b..bee96d41a5 100644 --- a/crates/storage/src/collections/lazy_set.rs +++ b/crates/storage/src/collections/lazy_set.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use std::marker::PhantomData; -use namada_core::types::storage::{self, DbKeySeg, KeySeg}; +use namada_core::storage::{self, DbKeySeg, KeySeg}; use thiserror::Error; use super::super::Result; @@ -213,7 +213,7 @@ where #[cfg(test)] mod test { - use namada_core::types::address::{self, Address}; + use namada_core::address::{self, Address}; use super::*; use crate::testing::TestStorage; diff --git a/crates/storage/src/collections/lazy_vec.rs b/crates/storage/src/collections/lazy_vec.rs index 12398a3f23..2826620fd7 100644 --- a/crates/storage/src/collections/lazy_vec.rs +++ b/crates/storage/src/collections/lazy_vec.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use std::marker::PhantomData; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::storage::{self, DbKeySeg, KeySeg}; +use namada_core::storage::{self, DbKeySeg, KeySeg}; use thiserror::Error; use super::super::Result; @@ -284,7 +284,7 @@ where #[cfg(test)] mod test { - use namada_core::types::address::{self, Address}; + use namada_core::address::{self, Address}; use super::*; use crate::collections::lazy_map::{self, NestedMap}; diff --git a/crates/storage/src/collections/mod.rs b/crates/storage/src/collections/mod.rs index 8de1f05092..4cc9ca9aea 100644 --- a/crates/storage/src/collections/mod.rs +++ b/crates/storage/src/collections/mod.rs @@ -19,7 +19,7 @@ pub mod lazy_vec; pub use lazy_map::LazyMap; pub use lazy_set::LazySet; pub use lazy_vec::LazyVec; -use namada_core::types::storage; +use namada_core::storage; #[allow(missing_docs)] #[derive(Error, Debug)] diff --git a/crates/storage/src/conversion_state.rs b/crates/storage/src/conversion_state.rs index 5ef405c4db..135b63bab5 100644 --- a/crates/storage/src/conversion_state.rs +++ b/crates/storage/src/conversion_state.rs @@ -2,14 +2,14 @@ use std::collections::BTreeMap; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; use namada_core::masp_primitives::asset_type::AssetType; use namada_core::masp_primitives::convert::AllowedConversion; use namada_core::masp_primitives::merkle_tree::FrozenCommitmentTree; use namada_core::masp_primitives::sapling; -use namada_core::types::address::Address; -use namada_core::types::storage::Epoch; -use namada_core::types::token::{Denomination, MaspDigitPos}; +use namada_core::storage::Epoch; +use namada_core::token::{Denomination, MaspDigitPos}; /// A representation of the conversion state #[derive(Debug, Default, BorshSerialize, BorshDeserialize)] diff --git a/crates/storage/src/db.rs b/crates/storage/src/db.rs index 34f7f90a15..5ce22e85db 100644 --- a/crates/storage/src/db.rs +++ b/crates/storage/src/db.rs @@ -1,13 +1,13 @@ use std::fmt::Debug; -use namada_core::types::address::EstablishedAddressGen; -use namada_core::types::hash::{Error as HashError, Hash}; -use namada_core::types::storage::{ +use namada_core::address::EstablishedAddressGen; +use namada_core::hash::{Error as HashError, Hash}; +use namada_core::storage::{ BlockHash, BlockHeight, BlockResults, Epoch, Epochs, EthEventsQueue, Header, Key, }; -use namada_core::types::time::DateTimeUtc; -use namada_core::types::{ethereum_events, ethereum_structs}; +use namada_core::time::DateTimeUtc; +use namada_core::{ethereum_events, ethereum_structs}; use namada_merkle_tree::{ Error as MerkleTreeError, MerkleTreeStoresRead, MerkleTreeStoresWrite, StoreType, @@ -25,9 +25,9 @@ pub enum Error { #[error("Found an unknown key: {key}")] UnknownKey { key: String }, #[error("Storage key error {0}")] - KeyError(namada_core::types::storage::Error), + KeyError(namada_core::storage::Error), #[error("Coding error: {0}")] - CodingError(#[from] namada_core::types::DecodeError), + CodingError(#[from] namada_core::DecodeError), #[error("Merkle tree error: {0}")] MerkleTreeError(#[from] MerkleTreeError), #[error("DB error: {0}")] diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index a2ebabb6a2..9b8e478d93 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -11,12 +11,10 @@ pub mod types; pub use db::{Error as DbError, Result as DbResult, *}; pub use error::{CustomError, Error, OptionExt, Result, ResultExt}; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt}; -use namada_core::types::address::Address; -pub use namada_core::types::hash::StorageHasher; -use namada_core::types::storage::{ - self, BlockHash, BlockHeight, Epoch, Epochs, Header, TxIndex, -}; +pub use namada_core::hash::StorageHasher; +pub use namada_core::storage::*; /// Common storage read interface /// @@ -40,10 +38,7 @@ pub trait StorageRead { /// Storage read Borsh encoded value. It will try to read from the storage /// and decode it if found. - fn read( - &self, - key: &storage::Key, - ) -> Result> { + fn read(&self, key: &Key) -> Result> { let bytes = self.read_bytes(key)?; match bytes { Some(bytes) => { @@ -55,10 +50,10 @@ pub trait StorageRead { } /// Storage read raw bytes. It will try to read from the storage. - fn read_bytes(&self, key: &storage::Key) -> Result>>; + fn read_bytes(&self, key: &Key) -> Result>>; /// Storage `has_key` in. It will try to read from the storage. - fn has_key(&self, key: &storage::Key) -> Result; + fn has_key(&self, key: &Key) -> Result; /// Storage prefix iterator ordered by the storage keys. It will try to get /// an iterator from the storage. @@ -67,7 +62,7 @@ pub trait StorageRead { /// [`fn@iter_prefix_bytes`] instead. fn iter_prefix<'iter>( &'iter self, - prefix: &storage::Key, + prefix: &Key, ) -> Result>; /// Storage prefix iterator. It will try to read from the storage. @@ -135,27 +130,19 @@ pub trait StorageRead { /// Common storage write interface pub trait StorageWrite { /// Write a value to be encoded with Borsh at the given key to storage. - fn write( - &mut self, - key: &storage::Key, - val: T, - ) -> Result<()> { + fn write(&mut self, key: &Key, val: T) -> Result<()> { let bytes = val.serialize_to_vec(); self.write_bytes(key, bytes) } /// Write a value as bytes at the given key to storage. - fn write_bytes( - &mut self, - key: &storage::Key, - val: impl AsRef<[u8]>, - ) -> Result<()>; + fn write_bytes(&mut self, key: &Key, val: impl AsRef<[u8]>) -> Result<()>; /// Delete a value at the given key from storage. - fn delete(&mut self, key: &storage::Key) -> Result<()>; + fn delete(&mut self, key: &Key) -> Result<()>; /// Delete all key-vals with a matching prefix. - fn delete_prefix(&mut self, prefix: &storage::Key) -> Result<()> + fn delete_prefix(&mut self, prefix: &Key) -> Result<()> where Self: StorageRead + Sized, { @@ -164,7 +151,7 @@ pub trait StorageWrite { let (key, _val) = res?; Ok(key) }) - .collect::>>(); + .collect::>>(); for key in keys? { // Skip validity predicates as they cannot be deleted if key.is_validity_predicate().is_none() { @@ -178,13 +165,13 @@ pub trait StorageWrite { /// Iterate items matching the given prefix, ordered by the storage keys. pub fn iter_prefix_bytes<'a>( storage: &'a impl StorageRead, - prefix: &storage::Key, -) -> Result)>> + 'a> { + prefix: &Key, +) -> Result)>> + 'a> { let iter = storage.iter_prefix(prefix)?; let iter = itertools::unfold(iter, |iter| { match storage.iter_next(iter) { Ok(Some((key, val))) => { - let key = match storage::Key::parse(key).into_storage_result() { + let key = match Key::parse(key).into_storage_result() { Ok(key) => key, Err(err) => { // Propagate key encoding errors into Iterator's Item @@ -207,8 +194,8 @@ pub fn iter_prefix_bytes<'a>( /// storage keys. pub fn iter_prefix<'a, T>( storage: &'a impl StorageRead, - prefix: &storage::Key, -) -> Result> + 'a> + prefix: &Key, +) -> Result> + 'a> where T: BorshDeserialize, { @@ -216,7 +203,7 @@ where let iter = itertools::unfold(iter, |iter| { match storage.iter_next(iter) { Ok(Some((key, val))) => { - let key = match storage::Key::parse(key).into_storage_result() { + let key = match Key::parse(key).into_storage_result() { Ok(key) => key, Err(err) => { // Propagate key encoding errors into Iterator's Item @@ -253,12 +240,12 @@ where /// don't pass the filter. For `iter_prefix_bytes`, `filter` works fine. pub fn iter_prefix_with_filter<'a, T, F>( storage: &'a impl StorageRead, - prefix: &storage::Key, + prefix: &Key, filter: F, -) -> Result> + 'a> +) -> Result> + 'a> where T: BorshDeserialize, - F: Fn(&storage::Key) -> bool + 'a, + F: Fn(&Key) -> bool + 'a, { let iter = storage.iter_prefix(prefix)?; let iter = itertools::unfold(iter, move |iter| { @@ -267,15 +254,14 @@ where loop { match storage.iter_next(iter) { Ok(Some((key, val))) => { - let key = - match storage::Key::parse(key).into_storage_result() { - Ok(key) => key, - Err(err) => { - // Propagate key encoding errors into Iterator's - // Item - return Some(Err(err)); - } - }; + let key = match Key::parse(key).into_storage_result() { + Ok(key) => key, + Err(err) => { + // Propagate key encoding errors into Iterator's + // Item + return Some(Err(err)); + } + }; // Check the predicate if !filter(&key) { continue; @@ -305,9 +291,9 @@ where /// Helpers for testing components that depend on storage #[cfg(any(test, feature = "testing"))] pub mod testing { - - use namada_core::types::address; - use namada_core::types::chain::ChainId; + use namada_core::address; + use namada_core::chain::ChainId; + pub use namada_core::storage::testing::*; use super::mockdb::MockDB; use super::*; @@ -322,10 +308,10 @@ pub mod testing { pred_epochs: Epochs, native_token: Address, conversion_state: ConversionState, - merkle_tree_key_filter: fn(&storage::Key) -> bool, + merkle_tree_key_filter: fn(&Key) -> bool, } - fn merklize_all_keys(_key: &storage::Key) -> bool { + fn merklize_all_keys(_key: &Key) -> bool { true } @@ -348,17 +334,17 @@ pub mod testing { impl StorageRead for TestStorage { type PrefixIter<'iter> = PrefixIter<'iter> where Self: 'iter; - fn read_bytes(&self, key: &storage::Key) -> Result>> { + fn read_bytes(&self, key: &Key) -> Result>> { self.db.read_subspace_val(key).into_storage_result() } - fn has_key(&self, key: &storage::Key) -> Result { + fn has_key(&self, key: &Key) -> Result { Ok(self.read_bytes(key)?.is_some()) } fn iter_prefix<'iter>( &'iter self, - prefix: &storage::Key, + prefix: &Key, ) -> Result> { let storage_iter = self.db.iter_prefix(Some(prefix)); Ok(PrefixIter { @@ -412,7 +398,7 @@ pub mod testing { impl StorageWrite for TestStorage { fn write_bytes( &mut self, - key: &storage::Key, + key: &Key, val: impl AsRef<[u8]>, ) -> Result<()> { let is_key_merklized = (self.merkle_tree_key_filter)(key); @@ -422,7 +408,7 @@ pub mod testing { Ok(()) } - fn delete(&mut self, key: &storage::Key) -> Result<()> { + fn delete(&mut self, key: &Key) -> Result<()> { let is_key_merklized = (self.merkle_tree_key_filter)(key); self.db .delete_subspace_val(self.height, key, is_key_merklized) diff --git a/crates/storage/src/mockdb.rs b/crates/storage/src/mockdb.rs index 2827bed5d9..43eb0915db 100644 --- a/crates/storage/src/mockdb.rs +++ b/crates/storage/src/mockdb.rs @@ -8,18 +8,17 @@ use std::str::FromStr; use itertools::Either; use namada_core::borsh::{BorshDeserialize, BorshSerializeExt}; -use namada_core::types; -use namada_core::types::hash::Hash; -use namada_core::types::storage::{ +use namada_core::hash::Hash; +use namada_core::storage::{ BlockHeight, BlockResults, Epoch, EthEventsQueue, Header, Key, KeySeg, KEY_SEGMENT_SEPARATOR, }; -use namada_core::types::time::DateTimeUtc; -use namada_core::types::{ethereum_events, ethereum_structs}; +use namada_core::time::DateTimeUtc; +use namada_core::{decode, encode, ethereum_events, ethereum_structs}; use namada_merkle_tree::{ base_tree_key_prefix, subtree_key_prefix, MerkleTreeStoresRead, StoreType, }; -use namada_replay_protection as replay_protection; +use {namada_core, namada_replay_protection as replay_protection}; use crate::conversion_state::ConversionState; use crate::db::{ @@ -67,66 +66,52 @@ impl DB for MockDB { fn read_last_block(&self) -> Result> { // Block height let height: BlockHeight = match self.0.borrow().get("height") { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; // Block results let results_path = format!("results/{}", height.raw()); let results: BlockResults = match self.0.borrow().get(results_path.as_str()) { - Some(bytes) => { - types::decode(bytes).map_err(Error::CodingError)? - } + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; // Epoch start height and time let next_epoch_min_start_height: BlockHeight = match self.0.borrow().get("next_epoch_min_start_height") { - Some(bytes) => { - types::decode(bytes).map_err(Error::CodingError)? - } + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; let next_epoch_min_start_time: DateTimeUtc = match self.0.borrow().get("next_epoch_min_start_time") { - Some(bytes) => { - types::decode(bytes).map_err(Error::CodingError)? - } + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; let update_epoch_blocks_delay: Option = match self.0.borrow().get("update_epoch_blocks_delay") { - Some(bytes) => { - types::decode(bytes).map_err(Error::CodingError)? - } + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; let conversion_state: ConversionState = match self.0.borrow().get("conversion_state") { - Some(bytes) => { - types::decode(bytes).map_err(Error::CodingError)? - } + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; let tx_queue: TxQueue = match self.0.borrow().get("tx_queue") { - Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?, + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; let ethereum_height: Option = match self.0.borrow().get("ethereum_height") { - Some(bytes) => { - types::decode(bytes).map_err(Error::CodingError)? - } + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; let eth_events_queue: EthEventsQueue = match self.0.borrow().get("ethereum_height") { - Some(bytes) => { - types::decode(bytes).map_err(Error::CodingError)? - } + Some(bytes) => decode(bytes).map_err(Error::CodingError)?, None => return Ok(None), }; @@ -154,7 +139,7 @@ impl DB for MockDB { match segments.get(3) { Some(&"root") => merkle_tree_stores.set_root( &st, - types::decode(bytes) + decode(bytes) .map_err(Error::CodingError)?, ), Some(&"store") => merkle_tree_stores @@ -168,29 +153,21 @@ impl DB for MockDB { // the block header doesn't have to be restored } "hash" => { - hash = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + hash = Some(decode(bytes).map_err(Error::CodingError)?) } "time" => { - time = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + time = Some(decode(bytes).map_err(Error::CodingError)?) } "epoch" => { - epoch = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + epoch = Some(decode(bytes).map_err(Error::CodingError)?) } "pred_epochs" => { - pred_epochs = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ) + pred_epochs = + Some(decode(bytes).map_err(Error::CodingError)?) } "address_gen" => { - address_gen = Some( - types::decode(bytes).map_err(Error::CodingError)?, - ); + address_gen = + Some(decode(bytes).map_err(Error::CodingError)?); } _ => unknown_key_error(path)?, }, @@ -207,7 +184,7 @@ impl DB for MockDB { { merkle_tree_stores.set_root( st, - types::decode(bytes).map_err(Error::CodingError)?, + decode(bytes).map_err(Error::CodingError)?, ); } let store_key = prefix_key.with_segment("store".to_owned()); @@ -276,29 +253,28 @@ impl DB for MockDB { // Epoch start height and time self.0.borrow_mut().insert( "next_epoch_min_start_height".into(), - types::encode(&next_epoch_min_start_height), + encode(&next_epoch_min_start_height), ); self.0.borrow_mut().insert( "next_epoch_min_start_time".into(), - types::encode(&next_epoch_min_start_time), + encode(&next_epoch_min_start_time), ); self.0.borrow_mut().insert( "update_epoch_blocks_delay".into(), - types::encode(&update_epoch_blocks_delay), + encode(&update_epoch_blocks_delay), ); self.0 .borrow_mut() - .insert("ethereum_height".into(), types::encode(ðereum_height)); - self.0.borrow_mut().insert( - "eth_events_queue".into(), - types::encode(ð_events_queue), - ); + .insert("ethereum_height".into(), encode(ðereum_height)); + self.0 + .borrow_mut() + .insert("eth_events_queue".into(), encode(ð_events_queue)); self.0 .borrow_mut() - .insert("tx_queue".into(), types::encode(&tx_queue)); + .insert("tx_queue".into(), encode(&tx_queue)); self.0 .borrow_mut() - .insert("conversion_state".into(), types::encode(conversion_state)); + .insert("conversion_state".into(), encode(conversion_state)); let prefix_key = Key::from(height.to_db_key()); // Merkle tree @@ -314,7 +290,7 @@ impl DB for MockDB { key_prefix.clone().with_segment("root".to_owned()); self.0.borrow_mut().insert( root_key.to_string(), - types::encode(merkle_tree_stores.root(st)), + encode(merkle_tree_stores.root(st)), ); let store_key = key_prefix.with_segment("store".to_owned()); self.0.borrow_mut().insert( @@ -340,27 +316,21 @@ impl DB for MockDB { let key = prefix_key .push(&"hash".to_owned()) .map_err(Error::KeyError)?; - self.0 - .borrow_mut() - .insert(key.to_string(), types::encode(&hash)); + self.0.borrow_mut().insert(key.to_string(), encode(&hash)); } // Block time { let key = prefix_key .push(&"time".to_owned()) .map_err(Error::KeyError)?; - self.0 - .borrow_mut() - .insert(key.to_string(), types::encode(&time)); + self.0.borrow_mut().insert(key.to_string(), encode(&time)); } // Block epoch { let key = prefix_key .push(&"epoch".to_owned()) .map_err(Error::KeyError)?; - self.0 - .borrow_mut() - .insert(key.to_string(), types::encode(&epoch)); + self.0.borrow_mut().insert(key.to_string(), encode(&epoch)); } // Predecessor block epochs { @@ -369,7 +339,7 @@ impl DB for MockDB { .map_err(Error::KeyError)?; self.0 .borrow_mut() - .insert(key.to_string(), types::encode(&pred_epochs)); + .insert(key.to_string(), encode(&pred_epochs)); } // Address gen { @@ -377,19 +347,15 @@ impl DB for MockDB { .push(&"address_gen".to_owned()) .map_err(Error::KeyError)?; let value = &address_gen; - self.0 - .borrow_mut() - .insert(key.to_string(), types::encode(value)); + self.0.borrow_mut().insert(key.to_string(), encode(value)); } self.0 .borrow_mut() - .insert("height".to_owned(), types::encode(&height)); + .insert("height".to_owned(), encode(&height)); // Block results { let results_path = format!("results/{}", height.raw()); - self.0 - .borrow_mut() - .insert(results_path, types::encode(&results)); + self.0.borrow_mut().insert(results_path, encode(&results)); } Ok(()) } @@ -430,7 +396,7 @@ impl DB for MockDB { let bytes = self.0.borrow().get(&root_key.to_string()).cloned(); match bytes { Some(b) => { - let root = types::decode(b).map_err(Error::CodingError)?; + let root = decode(b).map_err(Error::CodingError)?; merkle_tree_stores.set_root(st, root); } None => return Ok(None), diff --git a/crates/storage/src/tx_queue.rs b/crates/storage/src/tx_queue.rs index a183ec649f..3d5d9c7d87 100644 --- a/crates/storage/src/tx_queue.rs +++ b/crates/storage/src/tx_queue.rs @@ -1,5 +1,5 @@ use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::ethereum_events::EthereumEvent; +use namada_core::ethereum_events::EthereumEvent; use namada_gas::Gas; use namada_tx::Tx; diff --git a/crates/test_utils/src/tx_data.rs b/crates/test_utils/src/tx_data.rs index a985479237..945873b3ad 100644 --- a/crates/test_utils/src/tx_data.rs +++ b/crates/test_utils/src/tx_data.rs @@ -2,9 +2,9 @@ //! Namada transaction. use borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::storage; -use namada_core::types::token::Amount; +use namada_core::address::Address; +use namada_core::storage; +use namada_core::token::Amount; /// Represents an arbitrary write to storage at the specified key. This should /// be used alongside the test `tx_write.wasm`. diff --git a/crates/tests/src/e2e/eth_bridge_tests.rs b/crates/tests/src/e2e/eth_bridge_tests.rs index ece8eb2ee0..95d9dbc9c5 100644 --- a/crates/tests/src/e2e/eth_bridge_tests.rs +++ b/crates/tests/src/e2e/eth_bridge_tests.rs @@ -7,24 +7,24 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use color_eyre::eyre::{eyre, Result}; use expectrl::ControlCode; +use namada::control_flow::time::{Constant, Sleep}; +use namada::core::address::wnam; +use namada::core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; +use namada::core::ethereum_events::EthAddress; +use namada::core::storage::{self, Epoch}; +use namada::core::{address, token}; use namada::eth_bridge::oracle; use namada::eth_bridge::storage::vote_tallies; use namada::ledger::eth_bridge::{ ContractVersion, Contracts, EthereumBridgeParams, MinimumConfirmations, UpgradeableContract, }; -use namada::types::address::wnam; -use namada::types::control_flow::time::{Constant, Sleep}; -use namada::types::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; -use namada::types::ethereum_events::EthAddress; -use namada::types::storage::{self, Epoch}; -use namada::types::{address, token}; use namada_apps::config::ethereum_bridge; -use namada_core::types::address::Address; -use namada_core::types::ethereum_events::{ +use namada_core::address::Address; +use namada_core::ethereum_events::{ EthereumEvent, TransferToEthereum, TransferToNamada, }; -use namada_core::types::token::Amount; +use namada_core::token::Amount; use namada_test_utils::tx_data::TxWriteData; use namada_test_utils::TestWasms; use tokio::time::{Duration, Instant}; diff --git a/crates/tests/src/e2e/eth_bridge_tests/helpers.rs b/crates/tests/src/e2e/eth_bridge_tests/helpers.rs index 70e27b02ca..813cad5e99 100644 --- a/crates/tests/src/e2e/eth_bridge_tests/helpers.rs +++ b/crates/tests/src/e2e/eth_bridge_tests/helpers.rs @@ -7,15 +7,15 @@ use data_encoding::HEXLOWER; use eyre::{eyre, Context, Result}; use hyper::client::HttpConnector; use hyper::{Body, Client, Method, Request, StatusCode}; +use namada::core::address::{wnam, Address}; +use namada::core::ethereum_events::{ + EthAddress, EthereumEvent, TransferToNamada, Uint, +}; use namada::ledger::eth_bridge::{ wrapped_erc20s, ContractVersion, Contracts, EthereumBridgeParams, MinimumConfirmations, UpgradeableContract, }; use namada::token; -use namada::types::address::{wnam, Address}; -use namada::types::ethereum_events::{ - EthAddress, EthereumEvent, TransferToNamada, Uint, -}; use namada_apps::config::ethereum_bridge; use crate::e2e::helpers::{ diff --git a/crates/tests/src/e2e/helpers.rs b/crates/tests/src/e2e/helpers.rs index 8a24b1f304..b35da30c88 100644 --- a/crates/tests/src/e2e/helpers.rs +++ b/crates/tests/src/e2e/helpers.rs @@ -15,18 +15,18 @@ use color_eyre::owo_colors::OwoColorize; use data_encoding::HEXLOWER; use escargot::CargoBuild; use eyre::eyre; +use namada::core::address::Address; +use namada::core::key::*; +use namada::core::storage::Epoch; use namada::ledger::queries::{Rpc, RPC}; use namada::tendermint_rpc::HttpClient; use namada::token; -use namada::types::address::Address; -use namada::types::key::*; -use namada::types::storage::Epoch; use namada_apps::cli::context::ENV_VAR_CHAIN_ID; use namada_apps::config::genesis::chain::DeriveEstablishedAddress; use namada_apps::config::genesis::templates; use namada_apps::config::utils::convert_tm_addr_to_socket_addr; use namada_apps::config::{Config, TendermintMode}; -use namada_core::types::token::NATIVE_MAX_DECIMAL_PLACES; +use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use namada_sdk::wallet::fs::FsWalletUtils; use namada_sdk::wallet::Wallet; use toml::Value; diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 4cd825b8c8..a742c05bf2 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -17,6 +17,10 @@ use std::path::{Path, PathBuf}; use color_eyre::eyre::Result; use eyre::eyre; +use namada::core::address::{Address, InternalAddress}; +use namada::core::key::PublicKey; +use namada::core::storage::{BlockHeight, Epoch, Key}; +use namada::core::token::Amount; use namada::governance::cli::onchain::PgfFunding; use namada::governance::storage::proposal::{PGFIbcTarget, PGFTarget}; use namada::ibc::apps::transfer::types::VERSION as ICS20_VERSION; @@ -63,10 +67,6 @@ use namada::ledger::storage::ics23_specs::ibc_proof_specs; use namada::state::Sha256Hasher; use namada::tendermint::abci::Event as AbciEvent; use namada::tendermint::block::Height as TmHeight; -use namada::types::address::{Address, InternalAddress}; -use namada::types::key::PublicKey; -use namada::types::storage::{BlockHeight, Epoch, Key}; -use namada::types::token::Amount; use namada_apps::cli::context::ENV_VAR_CHAIN_ID; use namada_apps::client::rpc::{ query_pos_parameters, query_storage_value, query_storage_value_bytes, @@ -79,7 +79,7 @@ use namada_apps::facade::tendermint::block::Header as TmHeader; use namada_apps::facade::tendermint::merkle::proof::ProofOps as TmProof; use namada_apps::facade::tendermint_config::net::Address as TendermintAddress; use namada_apps::facade::tendermint_rpc::{Client, HttpClient, Url}; -use namada_core::types::string_encoding::StringEncoded; +use namada_core::string_encoding::StringEncoded; use namada_sdk::masp::fs::FsShieldedUtils; use prost::Message; use setup::constants::*; diff --git a/crates/tests/src/e2e/ledger_tests.rs b/crates/tests/src/e2e/ledger_tests.rs index a713314c6c..f0ec766b2d 100644 --- a/crates/tests/src/e2e/ledger_tests.rs +++ b/crates/tests/src/e2e/ledger_tests.rs @@ -21,17 +21,17 @@ use borsh_ext::BorshSerializeExt; use color_eyre::eyre::Result; use color_eyre::owo_colors::OwoColorize; use data_encoding::HEXLOWER; +use namada::core::address::Address; +use namada::core::storage::Epoch; use namada::governance::cli::onchain::{PgfFunding, StewardsUpdate}; use namada::governance::storage::proposal::{PGFInternalTarget, PGFTarget}; use namada::token; -use namada::types::address::Address; -use namada::types::storage::Epoch; use namada_apps::cli::context::ENV_VAR_CHAIN_ID; use namada_apps::config::ethereum_bridge; use namada_apps::config::utils::convert_tm_addr_to_socket_addr; use namada_apps::facade::tendermint_config::net::Address as TendermintAddress; -use namada_core::types::chain::ChainId; -use namada_core::types::token::NATIVE_MAX_DECIMAL_PLACES; +use namada_core::chain::ChainId; +use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use namada_sdk::governance::pgf::cli::steward::Commission; use namada_sdk::masp::fs::FsShieldedUtils; use namada_test_utils::TestWasms; @@ -540,7 +540,7 @@ fn ledger_txs_and_queries() -> Result<()> { vec![ "init-account", "--public-keys", - // Value obtained from `namada::types::key::ed25519::tests::gen_keypair` + // Value obtained from `namada::core::key::ed25519::tests::gen_keypair` "tpknam1qpqfzxu3gt05jx2mvg82f4anf90psqerkwqhjey4zlqv0qfgwuvkzt5jhkp", "--threshold", "1", @@ -2667,7 +2667,7 @@ fn double_signing_gets_slashed() -> Result<()> { use std::net::SocketAddr; use std::str::FromStr; - use namada::types::key::{self, ed25519, SigScheme}; + use namada::core::key::{self, ed25519, SigScheme}; use namada_apps::client; use namada_apps::config::Config; diff --git a/crates/tests/src/e2e/multitoken_tests/helpers.rs b/crates/tests/src/e2e/multitoken_tests/helpers.rs index caddb88f41..948fc750da 100644 --- a/crates/tests/src/e2e/multitoken_tests/helpers.rs +++ b/crates/tests/src/e2e/multitoken_tests/helpers.rs @@ -5,8 +5,8 @@ use std::str::FromStr; use borsh::BorshSerialize; use color_eyre::eyre::Result; use eyre::Context; -use namada_core::types::address::Address; -use namada_core::types::{storage, token}; +use namada_core::address::Address; +use namada_core::{storage, token}; use namada_test_utils::tx_data::TxWriteData; use namada_test_utils::TestWasms; use namada_tx_prelude::storage::KeySeg; @@ -41,7 +41,7 @@ pub fn init_multitoken_vp(test: &Test, rpc_addr: &str) -> Result { ARBITRARY_SIGNER, "--public-key", // Value obtained from - // `namada::types::key::ed25519::tests::gen_keypair` + // `namada::core::key::ed25519::tests::gen_keypair` "001be519a321e29020fa3cbfbfd01bd5e92db134305609270b71dace25b5a21168", "--code-path", &multitoken_vp_wasm_path, diff --git a/crates/tests/src/e2e/setup.rs b/crates/tests/src/e2e/setup.rs index 34517848c3..a7f8f968e2 100644 --- a/crates/tests/src/e2e/setup.rs +++ b/crates/tests/src/e2e/setup.rs @@ -18,7 +18,7 @@ use expectrl::stream::log::LogStream; use expectrl::{ControlCode, Eof, WaitStatus}; use eyre::eyre; use itertools::{Either, Itertools}; -use namada::types::chain::ChainId; +use namada::core::chain::ChainId; use namada_apps::cli::context::ENV_VAR_CHAIN_ID; use namada_apps::client::utils::{ self, validator_pre_genesis_dir, validator_pre_genesis_txs_file, @@ -27,10 +27,10 @@ use namada_apps::config::genesis::utils::read_toml; use namada_apps::config::genesis::{templates, transactions, GenesisAddress}; use namada_apps::config::{ethereum_bridge, genesis, Config}; use namada_apps::{config, wallet}; -use namada_core::types::address::Address; -use namada_core::types::key::{RefTo, SchemeType}; -use namada_core::types::string_encoding::StringEncoded; -use namada_core::types::token::NATIVE_MAX_DECIMAL_PLACES; +use namada_core::address::Address; +use namada_core::key::{RefTo, SchemeType}; +use namada_core::string_encoding::StringEncoded; +use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use namada_sdk::wallet::alias::Alias; use namada_tx_prelude::token; use once_cell::sync::Lazy; diff --git a/crates/tests/src/integration/masp.rs b/crates/tests/src/integration/masp.rs index deef3c1061..6846895030 100644 --- a/crates/tests/src/integration/masp.rs +++ b/crates/tests/src/integration/masp.rs @@ -7,7 +7,7 @@ use namada::state::StorageWrite; use namada::token; use namada_apps::node::ledger::shell::testing::client::run; use namada_apps::node::ledger::shell::testing::utils::{Bin, CapturedOutput}; -use namada_core::types::dec::Dec; +use namada_core::dec::Dec; use namada_sdk::masp::fs::FsShieldedUtils; use test_log::test; diff --git a/crates/tests/src/integration/setup.rs b/crates/tests/src/integration/setup.rs index beb9bf1798..da21de8dda 100644 --- a/crates/tests/src/integration/setup.rs +++ b/crates/tests/src/integration/setup.rs @@ -5,8 +5,8 @@ use std::str::FromStr; use std::sync::{Arc, Mutex}; use color_eyre::eyre::{eyre, Result}; +use namada::core::dec::Dec; use namada::token; -use namada::types::dec::Dec; use namada_apps::cli::args; use namada_apps::client::utils::PRE_GENESIS_DIR; use namada_apps::config; @@ -23,7 +23,7 @@ use namada_apps::node::ledger::shell::testing::node::{ use namada_apps::node::ledger::shell::testing::utils::TestDir; use namada_apps::node::ledger::shell::Shell; use namada_apps::wallet::pre_genesis; -use namada_core::types::chain::ChainIdPrefix; +use namada_core::chain::ChainIdPrefix; use namada_sdk::wallet::alias::Alias; use crate::e2e::setup::{copy_wasm_to_chain_dir, SINGLE_NODE_NET_GENESIS}; diff --git a/crates/tests/src/native_vp/eth_bridge_pool.rs b/crates/tests/src/native_vp/eth_bridge_pool.rs index 2f0109c73f..18d707cf66 100644 --- a/crates/tests/src/native_vp/eth_bridge_pool.rs +++ b/crates/tests/src/native_vp/eth_bridge_pool.rs @@ -4,17 +4,17 @@ mod test_bridge_pool_vp { use borsh::BorshDeserialize; use borsh_ext::BorshSerializeExt; + use namada::core::address::{nam, wnam}; + use namada::core::chain::ChainId; + use namada::core::eth_bridge_pool::{ + GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, + }; + use namada::core::ethereum_events::EthAddress; + use namada::core::key::{common, ed25519, SecretKey}; + use namada::core::token::Amount; use namada::eth_bridge::storage::bridge_pool::BRIDGE_POOL_ADDRESS; use namada::ledger::native_vp::ethereum_bridge::bridge_pool_vp::BridgePoolVp; use namada::tx::Tx; - use namada::types::address::{nam, wnam}; - use namada::types::chain::ChainId; - use namada::types::eth_bridge_pool::{ - GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, - }; - use namada::types::ethereum_events::EthAddress; - use namada::types::key::{common, ed25519, SecretKey}; - use namada::types::token::Amount; use namada_apps::wallet::defaults::{albert_address, bertha_address}; use namada_apps::wasm_loader; use namada_sdk::eth_bridge::{ @@ -35,7 +35,7 @@ mod test_bridge_pool_vp { /// A signing keypair for good old Bertha. fn bertha_keypair() -> common::SecretKey { // generated from - // [`namada::types::key::ed25519::gen_keypair`] + // [`namada::core::key::ed25519::gen_keypair`] let bytes = [ 240, 3, 224, 69, 201, 148, 60, 53, 112, 79, 80, 107, 101, 127, 186, 6, 176, 162, 113, 224, 62, 8, 183, 187, 124, 234, 244, 251, 92, 36, diff --git a/crates/tests/src/native_vp/mod.rs b/crates/tests/src/native_vp/mod.rs index f2928545b0..75dd2344df 100644 --- a/crates/tests/src/native_vp/mod.rs +++ b/crates/tests/src/native_vp/mod.rs @@ -4,12 +4,12 @@ pub mod pos; use std::cell::RefCell; use std::collections::BTreeSet; +use namada::core::address::Address; +use namada::core::storage; use namada::ledger::gas::VpGasMeter; use namada::ledger::native_vp::{Ctx, NativeVp}; use namada::state::mockdb::MockDB; use namada::state::Sha256Hasher; -use namada::types::address::Address; -use namada::types::storage; use namada::vm::WasmCacheRwAccess; use crate::tx::TestTxEnv; diff --git a/crates/tests/src/native_vp/pos.rs b/crates/tests/src/native_vp/pos.rs index f4a3c6bc5e..73e2eb7315 100644 --- a/crates/tests/src/native_vp/pos.rs +++ b/crates/tests/src/native_vp/pos.rs @@ -95,10 +95,10 @@ //! - add slashes //! - add rewards +use namada::core::storage::Epoch; use namada::proof_of_stake::parameters::{OwnedPosParams, PosParams}; use namada::proof_of_stake::test_utils::test_init_genesis as init_genesis; use namada::proof_of_stake::types::GenesisValidator; -use namada::types::storage::Epoch; use crate::tx::tx_host_env; @@ -147,11 +147,11 @@ pub fn init_pos( #[cfg(test)] mod tests { + use namada::core::address; + use namada::core::key::common::PublicKey; + use namada::core::storage::Epoch; use namada::ledger::pos::{PosParams, PosVP}; use namada::token; - use namada::types::address; - use namada::types::key::common::PublicKey; - use namada::types::storage::Epoch; use namada_tx_prelude::proof_of_stake::parameters::testing::arb_pos_params; use namada_tx_prelude::Address; use proptest::prelude::*; @@ -571,6 +571,11 @@ pub mod testing { use derivative::Derivative; use itertools::Either; + use namada::core::dec::Dec; + use namada::core::key::common::PublicKey; + use namada::core::key::RefTo; + use namada::core::storage::Epoch; + use namada::core::{address, key}; use namada::ledger::gas::TxGasMeter; use namada::proof_of_stake::epoched::DynEpochOffset; use namada::proof_of_stake::parameters::testing::arb_rate; @@ -582,11 +587,6 @@ pub mod testing { use namada::proof_of_stake::ADDRESS as POS_ADDRESS; use namada::token; use namada::token::{Amount, Change}; - use namada::types::dec::Dec; - use namada::types::key::common::PublicKey; - use namada::types::key::RefTo; - use namada::types::storage::Epoch; - use namada::types::{address, key}; use namada_tx_prelude::{Address, StorageRead, StorageWrite}; use proptest::prelude::*; diff --git a/crates/tests/src/storage.rs b/crates/tests/src/storage.rs index 154b55de56..3a5c9a5118 100644 --- a/crates/tests/src/storage.rs +++ b/crates/tests/src/storage.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use derivative::Derivative; -use namada::types::storage; +use namada::core::storage; /// A list of changes, which must be applied in the same order to get to the /// current state. diff --git a/crates/tests/src/storage_api/collections/lazy_map.rs b/crates/tests/src/storage_api/collections/lazy_map.rs index 0e9309df49..91ef7a1fb8 100644 --- a/crates/tests/src/storage_api/collections/lazy_map.rs +++ b/crates/tests/src/storage_api/collections/lazy_map.rs @@ -4,8 +4,8 @@ mod tests { use std::convert::TryInto; use borsh::{BorshDeserialize, BorshSerialize}; - use namada::types::address::{self, Address}; - use namada::types::storage; + use namada::core::address::{self, Address}; + use namada::core::storage; use namada_tx_prelude::collections::{LazyCollection, LazyMap}; use namada_tx_prelude::storage::KeySeg; use namada_vp_prelude::collection_validation::{self, LazyCollectionExt}; diff --git a/crates/tests/src/storage_api/collections/lazy_set.rs b/crates/tests/src/storage_api/collections/lazy_set.rs index 2fa04a3e40..3817ac90a5 100644 --- a/crates/tests/src/storage_api/collections/lazy_set.rs +++ b/crates/tests/src/storage_api/collections/lazy_set.rs @@ -3,8 +3,8 @@ mod tests { use std::collections::BTreeSet; use std::convert::TryInto; - use namada::types::address::{self, Address}; - use namada::types::storage; + use namada::core::address::{self, Address}; + use namada::core::storage; use namada_tx_prelude::collections::{LazyCollection, LazySet}; use namada_tx_prelude::storage::KeySeg; use namada_vp_prelude::collection_validation::{self, LazyCollectionExt}; diff --git a/crates/tests/src/storage_api/collections/lazy_vec.rs b/crates/tests/src/storage_api/collections/lazy_vec.rs index 7a3c3f0b14..523204627d 100644 --- a/crates/tests/src/storage_api/collections/lazy_vec.rs +++ b/crates/tests/src/storage_api/collections/lazy_vec.rs @@ -3,8 +3,8 @@ mod tests { use std::convert::TryInto; use borsh::{BorshDeserialize, BorshSerialize}; - use namada::types::address::{self, Address}; - use namada::types::storage; + use namada::core::address::{self, Address}; + use namada::core::storage; use namada_tx_prelude::collections::{lazy_vec, LazyCollection, LazyVec}; use namada_tx_prelude::storage::KeySeg; use namada_vp_prelude::collection_validation::{self, LazyCollectionExt}; diff --git a/crates/tests/src/storage_api/collections/nested_lazy_map.rs b/crates/tests/src/storage_api/collections/nested_lazy_map.rs index 9a4d487886..b247cbed58 100644 --- a/crates/tests/src/storage_api/collections/nested_lazy_map.rs +++ b/crates/tests/src/storage_api/collections/nested_lazy_map.rs @@ -4,8 +4,8 @@ mod tests { use std::convert::TryInto; use borsh::{BorshDeserialize, BorshSerialize}; - use namada::types::address::{self, Address}; - use namada::types::storage; + use namada::core::address::{self, Address}; + use namada::core::storage; use namada_tx_prelude::collections::lazy_map::{ NestedMap, NestedSubKey, SubKey, }; diff --git a/crates/tests/src/vm_host_env/ibc.rs b/crates/tests/src/vm_host_env/ibc.rs index 97e564324a..0cf6910ba1 100644 --- a/crates/tests/src/vm_host_env/ibc.rs +++ b/crates/tests/src/vm_host_env/ibc.rs @@ -6,6 +6,12 @@ use ibc_testkit::testapp::ibc::clients::mock::client_state::{ }; use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusState; use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader; +use namada::core::address::{self, Address, InternalAddress}; +use namada::core::hash::Hash; +use namada::core::storage::{ + self, BlockHash, BlockHeight, Epoch, Key, TxIndex, +}; +use namada::core::time::DurationSecs; use namada::gas::TxGasMeter; use namada::governance::parameters::GovernanceParameters; use namada::ibc::apps::transfer::types::error::TokenTransferError; @@ -75,12 +81,6 @@ use namada::state::Sha256Hasher; use namada::tendermint::time::Time as TmTime; use namada::token::{self, Amount, DenominatedAmount}; use namada::tx::Tx; -use namada::types::address::{self, Address, InternalAddress}; -use namada::types::hash::Hash; -use namada::types::storage::{ - self, BlockHash, BlockHeight, Epoch, Key, TxIndex, -}; -use namada::types::time::DurationSecs; use namada::vm::{wasm, WasmCacheRwAccess}; use namada_test_utils::TestWasms; use namada_tx_prelude::BorshSerializeExt; @@ -266,7 +266,7 @@ pub fn init_storage() -> (Address, Address) { // max_expected_time_per_block let time = DurationSecs::from(Duration::new(60, 0)); let key = get_max_expected_time_per_block_key(); - let bytes = namada::types::encode(&time); + let bytes = namada::core::encode(&time); tx_host_env::with(|env| { env.wl_storage.storage.write(&key, &bytes).unwrap(); }); diff --git a/crates/tests/src/vm_host_env/mod.rs b/crates/tests/src/vm_host_env/mod.rs index 2269acf1a8..40981f3e5e 100644 --- a/crates/tests/src/vm_host_env/mod.rs +++ b/crates/tests/src/vm_host_env/mod.rs @@ -24,6 +24,11 @@ mod tests { use borsh_ext::BorshSerializeExt; use itertools::Itertools; use namada::account::pks_handle; + use namada::core::hash::Hash; + use namada::core::key::*; + use namada::core::storage::{self, BlockHash, BlockHeight, Key, KeySeg}; + use namada::core::time::DateTimeUtc; + use namada::core::{address, key}; use namada::ibc::context::transfer_mod::testing::DummyTransferModule; use namada::ibc::primitives::Msg; use namada::ibc::Error as IbcActionError; @@ -34,11 +39,6 @@ mod tests { use namada::ledger::tx_env::TxEnv; use namada::token::{self, Amount}; use namada::tx::Tx; - use namada::types::hash::Hash; - use namada::types::key::*; - use namada::types::storage::{self, BlockHash, BlockHeight, Key, KeySeg}; - use namada::types::time::DateTimeUtc; - use namada::types::{address, key}; use namada_test_utils::TestWasms; use namada_tx_prelude::address::InternalAddress; use namada_tx_prelude::chain::ChainId; diff --git a/crates/tests/src/vm_host_env/tx.rs b/crates/tests/src/vm_host_env/tx.rs index c91807589a..25fc05fbb1 100644 --- a/crates/tests/src/vm_host_env/tx.rs +++ b/crates/tests/src/vm_host_env/tx.rs @@ -1,6 +1,10 @@ use std::borrow::Borrow; use std::collections::BTreeSet; +use namada::core::address::Address; +use namada::core::hash::Hash; +use namada::core::storage::{Key, TxIndex}; +use namada::core::time::DurationSecs; use namada::ledger::gas::TxGasMeter; use namada::ledger::parameters::{self, EpochDuration}; use namada::ledger::storage::mockdb::MockDB; @@ -9,10 +13,6 @@ use namada::ledger::storage::write_log::WriteLog; use namada::ledger::storage::{Sha256Hasher, WlStorage}; pub use namada::tx::data::TxType; use namada::tx::Tx; -use namada::types::address::Address; -use namada::types::hash::Hash; -use namada::types::storage::{Key, TxIndex}; -use namada::types::time::DurationSecs; use namada::vm::prefix_iter::PrefixIterators; use namada::vm::wasm::run::Error; use namada::vm::wasm::{self, TxCache, VpCache}; @@ -524,8 +524,8 @@ mod native_tx_host_env { #[cfg(test)] mod tests { + use namada::core::storage; use namada::ledger::storage::mockdb::MockDB; - use namada::types::storage; use namada::vm::host_env::{self, TxVmEnv}; use namada::vm::memory::VmMemory; use proptest::prelude::*; @@ -772,7 +772,7 @@ mod tests { any::(), any::(), any::(), - namada::types::storage::testing::arb_key(), + namada::core::storage::testing::arb_key(), arb_u64(), arb_u64(), any::>(), diff --git a/crates/tests/src/vm_host_env/vp.rs b/crates/tests/src/vm_host_env/vp.rs index a1963fe4ce..c99e3dea9d 100644 --- a/crates/tests/src/vm_host_env/vp.rs +++ b/crates/tests/src/vm_host_env/vp.rs @@ -1,5 +1,7 @@ use std::collections::BTreeSet; +use namada::core::address::{self, Address}; +use namada::core::storage::{self, Key, TxIndex}; use namada::gas::TxGasMeter; use namada::ledger::gas::VpGasMeter; use namada::ledger::storage::mockdb::MockDB; @@ -8,8 +10,6 @@ use namada::ledger::storage::write_log::WriteLog; use namada::ledger::storage::{Sha256Hasher, WlStorage}; use namada::tx::data::TxType; use namada::tx::Tx; -use namada::types::address::{self, Address}; -use namada::types::storage::{self, Key, TxIndex}; use namada::vm::prefix_iter::PrefixIterators; use namada::vm::wasm::{self, VpCache}; use namada::vm::{self, WasmCacheRwAccess}; @@ -239,7 +239,7 @@ mod native_vp_host_env { _ctx: VpCtx<'static, Self::Db, Self::H, Self::Eval, Self::CA>, _vp_code_hash: Vec, _input_data: Vec, - ) -> namada::types::internal::HostEnvResult { + ) -> namada::core::internal::HostEnvResult { unimplemented!( "The \"wasm-runtime\" feature must be enabled to test with \ the `eval` function." diff --git a/crates/token/src/lib.rs b/crates/token/src/lib.rs index ceedef5546..136b324001 100644 --- a/crates/token/src/lib.rs +++ b/crates/token/src/lib.rs @@ -9,8 +9,8 @@ pub mod storage_key { pub use namada_trans_token::storage_key::*; } +use namada_core::address::Address; use namada_core::event::EmitEvents; -use namada_core::types::address::Address; use namada_storage::{Result, StorageRead, StorageWrite}; /// Initialize parameters for the token in storage during the genesis block. diff --git a/crates/trans_token/src/inflation.rs b/crates/trans_token/src/inflation.rs index 545970f8de..b9be694a20 100644 --- a/crates/trans_token/src/inflation.rs +++ b/crates/trans_token/src/inflation.rs @@ -2,8 +2,8 @@ //! proof-of-stake, providing liquity to shielded asset pools, and public goods //! funding. -use namada_core::types::dec::Dec; -use namada_core::types::uint::Uint; +use namada_core::dec::Dec; +use namada_core::uint::Uint; /// Holds the PD controller values that should be updated in storage #[allow(missing_docs)] diff --git a/crates/trans_token/src/lib.rs b/crates/trans_token/src/lib.rs index 21c8516a7b..ea8b646005 100644 --- a/crates/trans_token/src/lib.rs +++ b/crates/trans_token/src/lib.rs @@ -4,5 +4,5 @@ pub mod inflation; mod storage; pub mod storage_key; -pub use namada_core::types::token::*; +pub use namada_core::token::*; pub use storage::*; diff --git a/crates/trans_token/src/storage.rs b/crates/trans_token/src/storage.rs index 4f03ed1509..2e38e97fa4 100644 --- a/crates/trans_token/src/storage.rs +++ b/crates/trans_token/src/storage.rs @@ -1,6 +1,6 @@ +use namada_core::address::{Address, InternalAddress}; use namada_core::hints; -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::token::{self, Amount, DenominatedAmount}; +use namada_core::token::{self, Amount, DenominatedAmount}; use namada_storage as storage; use namada_storage::{StorageRead, StorageWrite}; @@ -229,7 +229,7 @@ pub fn denom_to_amount( #[cfg(test)] mod testing { - use namada_core::types::{address, token}; + use namada_core::{address, token}; use namada_storage::testing::TestStorage; use super::{burn_tokens, credit_tokens, read_balance, read_total_supply}; diff --git a/crates/trans_token/src/storage_key.rs b/crates/trans_token/src/storage_key.rs index 7797d68b51..9f0d2247c3 100644 --- a/crates/trans_token/src/storage_key.rs +++ b/crates/trans_token/src/storage_key.rs @@ -1,7 +1,7 @@ //! Transparent token storage keys -use namada_core::types::address::{Address, InternalAddress}; -use namada_core::types::storage::{self, DbKeySeg, KeySeg}; +use namada_core::address::{Address, InternalAddress}; +use namada_core::storage::{self, DbKeySeg, KeySeg}; /// Key segment for a balance key pub const BALANCE_STORAGE_KEY: &str = "balance"; @@ -196,7 +196,7 @@ pub fn is_any_shielded_action_balance_key( [ token, &Address::Internal( - namada_core::types::address::InternalAddress::Ibc, + namada_core::address::InternalAddress::Ibc, ), ] }) diff --git a/crates/tx/src/data/eval_vp.rs b/crates/tx/src/data/eval_vp.rs index e248018ad5..69562734fa 100644 --- a/crates/tx/src/data/eval_vp.rs +++ b/crates/tx/src/data/eval_vp.rs @@ -1,5 +1,5 @@ use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::hash::Hash; +use namada_core::hash::Hash; use serde::{Deserialize, Serialize}; use crate::Tx; diff --git a/crates/tx/src/data/mod.rs b/crates/tx/src/data/mod.rs index f3d93131b7..61b10896ab 100644 --- a/crates/tx/src/data/mod.rs +++ b/crates/tx/src/data/mod.rs @@ -18,14 +18,14 @@ use std::fmt::{self, Display}; use std::str::FromStr; pub use decrypted::*; +use namada_core::address::Address; use namada_core::borsh::{ BorshDeserialize, BorshSchema, BorshSerialize, BorshSerializeExt, }; -use namada_core::types::address::Address; -use namada_core::types::ethereum_structs::EthBridgeEvent; -use namada_core::types::hash::Hash; -use namada_core::types::ibc::IbcEvent; -use namada_core::types::storage; +use namada_core::ethereum_structs::EthBridgeEvent; +use namada_core::hash::Hash; +use namada_core::ibc::IbcEvent; +use namada_core::storage; use namada_gas::{Gas, VpsGas}; use num_derive::{FromPrimitive, ToPrimitive}; use num_traits::{FromPrimitive, ToPrimitive}; @@ -341,10 +341,10 @@ impl TxSentinel { #[cfg(test)] mod test_process_tx { use assert_matches::assert_matches; - use namada_core::types::address::nam; - use namada_core::types::key::*; - use namada_core::types::storage::Epoch; - use namada_core::types::token::{Amount, DenominatedAmount}; + use namada_core::address::nam; + use namada_core::key::*; + use namada_core::storage::Epoch; + use namada_core::token::{Amount, DenominatedAmount}; use super::*; use crate::{Code, Data, Section, Signature, Tx, TxError}; @@ -505,7 +505,7 @@ fn test_process_tx_decrypted_unsigned() { /// signature #[test] fn test_process_tx_decrypted_signed() { - use namada_core::types::key::*; + use namada_core::key::*; use crate::{Code, Data, Section, Signature, Tx}; @@ -517,7 +517,7 @@ fn test_process_tx_decrypted_signed() { ed25519::SigScheme::generate(&mut rng).try_to_sk().unwrap() } - use namada_core::types::key::Signature as S; + use namada_core::key::Signature as S; let mut decrypted = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted)); // Invalid signed data diff --git a/crates/tx/src/data/pgf.rs b/crates/tx/src/data/pgf.rs index 284b930dd1..5343ae4daa 100644 --- a/crates/tx/src/data/pgf.rs +++ b/crates/tx/src/data/pgf.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; +use namada_core::dec::Dec; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -33,8 +33,8 @@ pub struct UpdateStewardCommission { #[cfg(any(test, feature = "testing"))] /// Tests and strategies for PGF pub mod tests { - use namada_core::types::address::testing::arb_non_internal_address; - use namada_core::types::dec::testing::arb_dec; + use namada_core::address::testing::arb_non_internal_address; + use namada_core::dec::testing::arb_dec; use proptest::{collection, prop_compose}; use super::UpdateStewardCommission; diff --git a/crates/tx/src/data/pos.rs b/crates/tx/src/data/pos.rs index 73d42d997e..3805556780 100644 --- a/crates/tx/src/data/pos.rs +++ b/crates/tx/src/data/pos.rs @@ -1,10 +1,10 @@ //! Types used for PoS system transactions +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::dec::Dec; -use namada_core::types::key::{common, secp256k1}; -use namada_core::types::token; +use namada_core::dec::Dec; +use namada_core::key::{common, secp256k1}; +use namada_core::token; use serde::{Deserialize, Serialize}; /// A tx data type to become a validator account. @@ -214,10 +214,10 @@ pub struct ConsensusKeyChange { #[cfg(any(test, feature = "testing"))] /// Tests and strategies for proof-of-stake pub mod tests { - use namada_core::types::address::testing::arb_non_internal_address; - use namada_core::types::dec::testing::arb_dec; - use namada_core::types::key::testing::{arb_common_pk, arb_pk}; - use namada_core::types::token::testing::arb_amount; + use namada_core::address::testing::arb_non_internal_address; + use namada_core::dec::testing::arb_dec; + use namada_core::key::testing::{arb_common_pk, arb_pk}; + use namada_core::token::testing::arb_amount; use proptest::{option, prop_compose}; use super::*; diff --git a/crates/tx/src/data/protocol.rs b/crates/tx/src/data/protocol.rs index b1ce5892fa..f9244e62d2 100644 --- a/crates/tx/src/data/protocol.rs +++ b/crates/tx/src/data/protocol.rs @@ -4,7 +4,7 @@ use namada_core::borsh::{ BorshDeserialize, BorshSchema, BorshSerialize, BorshSerializeExt, }; -use namada_core::types::key::*; +use namada_core::key::*; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; diff --git a/crates/tx/src/data/wrapper.rs b/crates/tx/src/data/wrapper.rs index a5867ad932..a70ebaa39d 100644 --- a/crates/tx/src/data/wrapper.rs +++ b/crates/tx/src/data/wrapper.rs @@ -8,15 +8,15 @@ pub mod wrapper_tx { pub use ark_bls12_381::Bls12_381 as EllipticCurve; use masp_primitives::transaction::Transaction; + use namada_core::address::{Address, MASP}; use namada_core::borsh::{ BorshDeserialize, BorshSchema, BorshSerialize, BorshSerializeExt, }; - use namada_core::types::address::{Address, MASP}; - use namada_core::types::hash::Hash; - use namada_core::types::key::*; - use namada_core::types::storage::Epoch; - use namada_core::types::token::{Amount, DenominatedAmount, Transfer}; - use namada_core::types::uint::Uint; + use namada_core::hash::Hash; + use namada_core::key::*; + use namada_core::storage::Epoch; + use namada_core::token::{Amount, DenominatedAmount, Transfer}; + use namada_core::uint::Uint; use namada_gas::Gas; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; diff --git a/crates/tx/src/lib.rs b/crates/tx/src/lib.rs index 61e7a9040d..6c866e8513 100644 --- a/crates/tx/src/lib.rs +++ b/crates/tx/src/lib.rs @@ -8,8 +8,8 @@ use std::collections::HashMap; use data::TxType; use namada_core::event::{Event, EventLevel, EventType}; -pub use namada_core::types::key::SignableEthMessage; -pub use namada_core::types::sign::SignatureIndex; +pub use namada_core::key::SignableEthMessage; +pub use namada_core::sign::SignatureIndex; pub use types::{ standalone_signature, verify_standalone_sig, Code, Commitment, CompressedSignature, Data, DecodeError, Header, MaspBuilder, Memo, Section, diff --git a/crates/tx/src/types.rs b/crates/tx/src/types.rs index 432e217e29..3c0d51da53 100644 --- a/crates/tx/src/types.rs +++ b/crates/tx/src/types.rs @@ -10,18 +10,18 @@ use masp_primitives::transaction::builder::Builder; use masp_primitives::transaction::components::sapling::builder::SaplingMetadata; use masp_primitives::transaction::Transaction; use masp_primitives::zip32::ExtendedFullViewingKey; +use namada_core::account::AccountPublicKeysMap; +use namada_core::address::Address; use namada_core::borsh::schema::{add_definition, Declaration, Definition}; use namada_core::borsh::{ BorshDeserialize, BorshSchema, BorshSerialize, BorshSerializeExt, }; -use namada_core::types::account::AccountPublicKeysMap; -use namada_core::types::address::Address; -use namada_core::types::chain::ChainId; -use namada_core::types::key::*; -use namada_core::types::masp::AssetData; -use namada_core::types::sign::SignatureIndex; -use namada_core::types::storage::Epoch; -use namada_core::types::time::DateTimeUtc; +use namada_core::chain::ChainId; +use namada_core::key::*; +use namada_core::masp::AssetData; +use namada_core::sign::SignatureIndex; +use namada_core::storage::Epoch; +use namada_core::time::DateTimeUtc; use serde::de::Error as SerdeError; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; @@ -36,7 +36,7 @@ use crate::proto; #[derive(Error, Debug)] pub enum VerifySigError { #[error("{0}")] - VerifySig(#[from] namada_core::types::key::VerifySigError), + VerifySig(#[from] namada_core::key::VerifySigError), #[error("{0}")] Gas(#[from] namada_gas::Error), #[error("The wrapper signature is invalid.")] @@ -249,7 +249,7 @@ pub struct CommitmentError; )] pub enum Commitment { /// Result of applying hash function to bytes - Hash(namada_core::types::hash::Hash), + Hash(namada_core::hash::Hash), /// Result of applying identity function to bytes Id(Vec), } @@ -279,7 +279,7 @@ impl Commitment { } /// Return the contained hash commitment - pub fn hash(&self) -> namada_core::types::hash::Hash { + pub fn hash(&self) -> namada_core::hash::Hash { match self { Self::Id(code) => hash_tx(code), Self::Hash(hash) => *hash, @@ -327,7 +327,7 @@ impl Code { /// Make a new code section with the given hash pub fn from_hash( - hash: namada_core::types::hash::Hash, + hash: namada_core::hash::Hash, tag: Option, ) -> Self { Self { @@ -377,7 +377,7 @@ pub enum Signer { )] pub struct Signature { /// The hash of the section being signed - pub targets: Vec, + pub targets: Vec, /// The public keys against which the signatures should be verified pub signer: Signer, /// The signature over the above hash @@ -387,7 +387,7 @@ pub struct Signature { impl Signature { /// Sign the given section hash with the given key and return a section pub fn new( - targets: Vec, + targets: Vec, secret_keys: BTreeMap, signer: Option
, ) -> Self { @@ -437,13 +437,13 @@ impl Signature { } /// Get the hash of this section - pub fn get_hash(&self) -> namada_core::types::hash::Hash { - namada_core::types::hash::Hash( + pub fn get_hash(&self) -> namada_core::hash::Hash { + namada_core::hash::Hash( self.hash(&mut Sha256::new()).finalize_reset().into(), ) } - pub fn get_raw_hash(&self) -> namada_core::types::hash::Hash { + pub fn get_raw_hash(&self) -> namada_core::hash::Hash { Self { signer: Signer::PubKeys(vec![]), signatures: BTreeMap::new(), @@ -657,7 +657,7 @@ impl From for Vec { )] pub struct MaspBuilder { /// The MASP transaction that this section witnesses - pub target: namada_core::types::hash::Hash, + pub target: namada_core::hash::Hash, /// The decoded set of asset types used by the transaction. Useful for /// offline wallets trying to display AssetTypes. pub asset_types: HashSet, @@ -757,8 +757,8 @@ impl Section { } /// Get the hash of this section - pub fn get_hash(&self) -> namada_core::types::hash::Hash { - namada_core::types::hash::Hash( + pub fn get_hash(&self) -> namada_core::hash::Hash { + namada_core::hash::Hash( self.hash(&mut Sha256::new()).finalize_reset().into(), ) } @@ -864,14 +864,14 @@ pub struct Header { /// A transaction timestamp pub timestamp: DateTimeUtc, /// The SHA-256 hash of the transaction's code section - pub code_hash: namada_core::types::hash::Hash, + pub code_hash: namada_core::hash::Hash, /// The SHA-256 hash of the transaction's data section - pub data_hash: namada_core::types::hash::Hash, + pub data_hash: namada_core::hash::Hash, /// The SHA-256 hash of the transaction's memo section /// /// In case a memo is not present in the transaction, a /// byte array filled with zeroes is present instead - pub memo_hash: namada_core::types::hash::Hash, + pub memo_hash: namada_core::hash::Hash, /// The type of this transaction pub tx_type: TxType, } @@ -884,9 +884,9 @@ impl Header { chain_id: ChainId::default(), expiration: None, timestamp: DateTimeUtc::now(), - code_hash: namada_core::types::hash::Hash::default(), - data_hash: namada_core::types::hash::Hash::default(), - memo_hash: namada_core::types::hash::Hash::default(), + code_hash: namada_core::hash::Hash::default(), + data_hash: namada_core::hash::Hash::default(), + memo_hash: namada_core::hash::Hash::default(), } } @@ -1024,12 +1024,12 @@ impl Tx { } /// Get the transaction header hash - pub fn header_hash(&self) -> namada_core::types::hash::Hash { + pub fn header_hash(&self) -> namada_core::hash::Hash { Section::Header(self.header.clone()).get_hash() } /// Gets the hash of the decrypted transaction's header - pub fn raw_header_hash(&self) -> namada_core::types::hash::Hash { + pub fn raw_header_hash(&self) -> namada_core::hash::Hash { let mut raw_header = self.header(); raw_header.tx_type = TxType::Raw; @@ -1037,7 +1037,7 @@ impl Tx { } /// Get hashes of all the sections in this transaction - pub fn sechashes(&self) -> Vec { + pub fn sechashes(&self) -> Vec { let mut hashes = vec![self.header_hash()]; for sec in &self.sections { hashes.push(sec.get_hash()); @@ -1054,7 +1054,7 @@ impl Tx { /// Get the transaction section with the given hash pub fn get_section( &self, - hash: &namada_core::types::hash::Hash, + hash: &namada_core::hash::Hash, ) -> Option> { if self.header_hash() == *hash { return Some(Cow::Owned(Section::Header(self.header.clone()))); @@ -1072,18 +1072,18 @@ impl Tx { } /// Set the transaction memo hash stored in the header - pub fn set_memo_sechash(&mut self, hash: namada_core::types::hash::Hash) { + pub fn set_memo_sechash(&mut self, hash: namada_core::hash::Hash) { self.header.memo_hash = hash; } /// Get the hash of this transaction's memo from the heeader - pub fn memo_sechash(&self) -> &namada_core::types::hash::Hash { + pub fn memo_sechash(&self) -> &namada_core::hash::Hash { &self.header.memo_hash } /// Get the memo designated by the memo hash in the header pub fn memo(&self) -> Option> { - if self.memo_sechash() == &namada_core::types::hash::Hash::default() { + if self.memo_sechash() == &namada_core::hash::Hash::default() { return None; } match self @@ -1103,12 +1103,12 @@ impl Tx { } /// Get the hash of this transaction's code from the heeader - pub fn code_sechash(&self) -> &namada_core::types::hash::Hash { + pub fn code_sechash(&self) -> &namada_core::hash::Hash { &self.header.code_hash } /// Set the transaction code hash stored in the header - pub fn set_code_sechash(&mut self, hash: namada_core::types::hash::Hash) { + pub fn set_code_sechash(&mut self, hash: namada_core::hash::Hash) { self.header.code_hash = hash } @@ -1133,12 +1133,12 @@ impl Tx { } /// Get the transaction data hash stored in the header - pub fn data_sechash(&self) -> &namada_core::types::hash::Hash { + pub fn data_sechash(&self) -> &namada_core::hash::Hash { &self.header.data_hash } /// Set the transaction data hash stored in the header - pub fn set_data_sechash(&mut self, hash: namada_core::types::hash::Hash) { + pub fn set_data_sechash(&mut self, hash: namada_core::hash::Hash) { self.header.data_hash = hash } @@ -1179,7 +1179,7 @@ impl Tx { /// public key pub fn verify_signatures( &self, - hashes: &[namada_core::types::hash::Hash], + hashes: &[namada_core::hash::Hash], public_keys_index_map: AccountPublicKeysMap, signer: &Option
, threshold: u8, @@ -1252,7 +1252,7 @@ impl Tx { pub fn verify_signature( &self, public_key: &common::PublicKey, - hashes: &[namada_core::types::hash::Hash], + hashes: &[namada_core::hash::Hash], ) -> Result<&Signature, VerifySigError> { self.verify_signatures( hashes, @@ -1390,9 +1390,9 @@ impl Tx { /// Add an extra section to the tx builder by hash pub fn add_extra_section_from_hash( &mut self, - hash: namada_core::types::hash::Hash, + hash: namada_core::hash::Hash, tag: Option, - ) -> namada_core::types::hash::Hash { + ) -> namada_core::hash::Hash { let sechash = self .add_section(Section::ExtraData(Code::from_hash(hash, tag))) .get_hash(); @@ -1404,7 +1404,7 @@ impl Tx { &mut self, code: Vec, tag: Option, - ) -> (&mut Self, namada_core::types::hash::Hash) { + ) -> (&mut Self, namada_core::hash::Hash) { let sechash = self .add_section(Section::ExtraData(Code::new(code, tag))) .get_hash(); @@ -1415,7 +1415,7 @@ impl Tx { pub fn add_memo( &mut self, memo: &[u8], - ) -> (&mut Self, namada_core::types::hash::Hash) { + ) -> (&mut Self, namada_core::hash::Hash) { let sechash = self .add_section(Section::ExtraData(Code::new(memo.to_vec(), None))) .get_hash(); @@ -1427,7 +1427,7 @@ impl Tx { pub fn add_masp_tx_section( &mut self, tx: Transaction, - ) -> (&mut Self, namada_core::types::hash::Hash) { + ) -> (&mut Self, namada_core::hash::Hash) { let sechash = self.add_section(Section::MaspTx(tx)).get_hash(); (self, sechash) } @@ -1441,7 +1441,7 @@ impl Tx { /// Add wasm code to the tx builder from hash pub fn add_code_from_hash( &mut self, - code_hash: namada_core::types::hash::Hash, + code_hash: namada_core::hash::Hash, tag: Option, ) -> &mut Self { self.set_code(Code::from_hash(code_hash, tag)); @@ -1478,7 +1478,7 @@ impl Tx { fee_payer: common::PublicKey, epoch: Epoch, gas_limit: GasLimit, - fee_unshield_hash: Option, + fee_unshield_hash: Option, ) -> &mut Self { self.header.tx_type = TxType::Wrapper(Box::new(WrapperTx::new( fee, diff --git a/crates/tx_env/src/lib.rs b/crates/tx_env/src/lib.rs index bc482d5004..25242bfacf 100644 --- a/crates/tx_env/src/lib.rs +++ b/crates/tx_env/src/lib.rs @@ -1,10 +1,10 @@ //! Transaction environment contains functions that can be called from //! inside a tx. +use namada_core::address::Address; use namada_core::borsh::BorshSerialize; -use namada_core::types::address::Address; -use namada_core::types::ibc::IbcEvent; -use namada_core::types::storage; +use namada_core::ibc::IbcEvent; +use namada_core::storage; use namada_storage::{Result, StorageRead, StorageWrite}; /// Transaction host functions diff --git a/crates/tx_prelude/src/ibc.rs b/crates/tx_prelude/src/ibc.rs index 0857875382..9ae6f732bb 100644 --- a/crates/tx_prelude/src/ibc.rs +++ b/crates/tx_prelude/src/ibc.rs @@ -3,9 +3,9 @@ use std::cell::RefCell; use std::rc::Rc; -use namada_core::types::address::{Address, InternalAddress}; -pub use namada_core::types::ibc::{IbcEvent, IbcShieldedTransfer}; -use namada_core::types::token::DenominatedAmount; +use namada_core::address::{Address, InternalAddress}; +pub use namada_core::ibc::{IbcEvent, IbcShieldedTransfer}; +use namada_core::token::DenominatedAmount; pub use namada_ibc::storage::is_ibc_key; pub use namada_ibc::{ IbcActions, IbcCommonContext, IbcStorageContext, ProofSpec, TransferModule, diff --git a/crates/tx_prelude/src/key.rs b/crates/tx_prelude/src/key.rs index a273d25cc7..7f499b8254 100644 --- a/crates/tx_prelude/src/key.rs +++ b/crates/tx_prelude/src/key.rs @@ -1,6 +1,6 @@ //! Cryptographic signature keys -pub use namada_core::types::key::*; +pub use namada_core::key::*; use super::*; diff --git a/crates/tx_prelude/src/lib.rs b/crates/tx_prelude/src/lib.rs index fcb059fdb7..b83f2cf345 100644 --- a/crates/tx_prelude/src/lib.rs +++ b/crates/tx_prelude/src/lib.rs @@ -17,20 +17,20 @@ use core::slice; use std::marker::PhantomData; use masp_primitives::transaction::Transaction; +use namada_core::account::AccountPublicKeysMap; +pub use namada_core::address::Address; pub use namada_core::borsh::{ BorshDeserialize, BorshSerialize, BorshSerializeExt, }; -use namada_core::types::account::AccountPublicKeysMap; -pub use namada_core::types::address::Address; -use namada_core::types::chain::CHAIN_ID_LENGTH; -pub use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::internal::HostEnvResult; -use namada_core::types::key::common; -use namada_core::types::storage::TxIndex; -pub use namada_core::types::storage::{ +use namada_core::chain::CHAIN_ID_LENGTH; +pub use namada_core::ethereum_events::EthAddress; +use namada_core::internal::HostEnvResult; +use namada_core::key::common; +use namada_core::storage::TxIndex; +pub use namada_core::storage::{ self, BlockHash, BlockHeight, Epoch, Header, BLOCK_HASH_LENGTH, }; -pub use namada_core::types::{encode, eth_bridge_pool, *}; +pub use namada_core::{encode, eth_bridge_pool, *}; pub use namada_governance::storage as gov_storage; pub use namada_macros::transaction; pub use namada_parameters::storage as parameters_storage; @@ -160,9 +160,7 @@ impl StorageRead for Ctx { } } - fn get_block_hash( - &self, - ) -> Result { + fn get_block_hash(&self) -> Result { let result = Vec::with_capacity(BLOCK_HASH_LENGTH); unsafe { namada_tx_get_block_hash(result.as_ptr() as _); @@ -173,22 +171,17 @@ impl StorageRead for Ctx { Ok(BlockHash::try_from(slice).expect("Cannot convert the hash")) } - fn get_block_epoch( - &self, - ) -> Result { + fn get_block_epoch(&self) -> Result { Ok(Epoch(unsafe { namada_tx_get_block_epoch() })) } - fn get_pred_epochs( - &self, - ) -> Result { + fn get_pred_epochs(&self) -> Result { let read_result = unsafe { namada_tx_get_pred_epochs() }; let bytes = read_from_buffer(read_result, namada_tx_result_buffer) .ok_or(Error::SimpleMessage( "Missing result from `namada_tx_get_pred_epochs` call", ))?; - Ok(namada_core::types::decode(bytes) - .expect("Cannot decode pred epochs")) + Ok(namada_core::decode(bytes).expect("Cannot decode pred epochs")) } /// Get the native token address diff --git a/crates/tx_prelude/src/proof_of_stake.rs b/crates/tx_prelude/src/proof_of_stake.rs index 50ad3daf73..96526b80c1 100644 --- a/crates/tx_prelude/src/proof_of_stake.rs +++ b/crates/tx_prelude/src/proof_of_stake.rs @@ -1,8 +1,8 @@ //! Proof of Stake system integration with functions for transactions -use namada_core::types::dec::Dec; -use namada_core::types::key::common; -use namada_core::types::{key, token}; +use namada_core::dec::Dec; +use namada_core::key::common; +use namada_core::{key, token}; pub use namada_proof_of_stake::parameters::PosParams; use namada_proof_of_stake::storage::read_pos_params; use namada_proof_of_stake::types::{ResultSlashing, ValidatorMetaData}; diff --git a/crates/tx_prelude/src/token.rs b/crates/tx_prelude/src/token.rs index 88371c9864..a42794e8bb 100644 --- a/crates/tx_prelude/src/token.rs +++ b/crates/tx_prelude/src/token.rs @@ -1,4 +1,4 @@ -use namada_core::types::address::Address; +use namada_core::address::Address; use namada_proof_of_stake::token::storage_key::{ balance_key, minted_balance_key, minter_key, }; diff --git a/crates/vm_env/src/lib.rs b/crates/vm_env/src/lib.rs index 63b5b01bc7..a8b15a90d4 100644 --- a/crates/vm_env/src/lib.rs +++ b/crates/vm_env/src/lib.rs @@ -8,7 +8,7 @@ use std::mem::ManuallyDrop; use borsh::BorshDeserialize; -use namada_core::types::internal::{HostEnvResult, KeyVal}; +use namada_core::internal::{HostEnvResult, KeyVal}; /// Transaction environment imports pub mod tx { diff --git a/crates/vote_ext/src/bridge_pool_roots.rs b/crates/vote_ext/src/bridge_pool_roots.rs index 2db9dbdfca..41b1f85b54 100644 --- a/crates/vote_ext/src/bridge_pool_roots.rs +++ b/crates/vote_ext/src/bridge_pool_roots.rs @@ -5,11 +5,11 @@ use std::collections::HashSet; use std::ops::{Deref, DerefMut}; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::key::common; -use namada_core::types::key::common::Signature; -use namada_core::types::storage::BlockHeight; +use namada_core::key::common; +use namada_core::key::common::Signature; +use namada_core::storage::BlockHeight; use namada_tx::Signed; /// A vote extension containing a validator's signature diff --git a/crates/vote_ext/src/ethereum_events.rs b/crates/vote_ext/src/ethereum_events.rs index 35733dcdc9..7c9903ddb7 100644 --- a/crates/vote_ext/src/ethereum_events.rs +++ b/crates/vote_ext/src/ethereum_events.rs @@ -4,11 +4,11 @@ use std::collections::{BTreeSet, HashMap}; use std::ops::Deref; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::ethereum_events::EthereumEvent; -use namada_core::types::key::common::{self, Signature}; -use namada_core::types::storage::BlockHeight; +use namada_core::ethereum_events::EthereumEvent; +use namada_core::key::common::{self, Signature}; +use namada_core::storage::BlockHeight; use namada_tx::Signed; /// Type alias for an [`EthereumEventsVext`]. @@ -153,10 +153,10 @@ impl VextDigest { #[cfg(test)] mod tests { - use namada_core::types::address::{self, Address}; - use namada_core::types::ethereum_events::{EthereumEvent, Uint}; - use namada_core::types::hash::Hash; - use namada_core::types::key; + use namada_core::address::{self, Address}; + use namada_core::ethereum_events::{EthereumEvent, Uint}; + use namada_core::hash::Hash; + use namada_core::key; use namada_tx::Signed; use super::*; diff --git a/crates/vote_ext/src/lib.rs b/crates/vote_ext/src/lib.rs index ca49e96801..4c7d84d427 100644 --- a/crates/vote_ext/src/lib.rs +++ b/crates/vote_ext/src/lib.rs @@ -7,8 +7,8 @@ pub mod validator_set_update; use namada_core::borsh::{ BorshDeserialize, BorshSchema, BorshSerialize, BorshSerializeExt, }; -use namada_core::types::chain::ChainId; -use namada_core::types::key::common; +use namada_core::chain::ChainId; +use namada_core::key::common; use namada_tx::data::protocol::{ProtocolTx, ProtocolTxType}; use namada_tx::data::TxType; use namada_tx::{Signature, Signed, Tx, TxError}; diff --git a/crates/vote_ext/src/validator_set_update.rs b/crates/vote_ext/src/validator_set_update.rs index 6e4a181319..0ef30c2d69 100644 --- a/crates/vote_ext/src/validator_set_update.rs +++ b/crates/vote_ext/src/validator_set_update.rs @@ -4,17 +4,15 @@ use std::cmp::Ordering; use std::collections::HashMap; use std::ops::Deref; +use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::types::address::Address; -use namada_core::types::eth_abi::{AbiEncode, Encode, Token}; -use namada_core::types::ethereum_events::EthAddress; -use namada_core::types::keccak::KeccakHash; -use namada_core::types::key::common::{self, Signature}; -use namada_core::types::storage::Epoch; -use namada_core::types::voting_power::{ - EthBridgeVotingPower, FractionalVotingPower, -}; -use namada_core::types::{ethereum_structs, token}; +use namada_core::eth_abi::{AbiEncode, Encode, Token}; +use namada_core::ethereum_events::EthAddress; +use namada_core::keccak::KeccakHash; +use namada_core::key::common::{self, Signature}; +use namada_core::storage::Epoch; +use namada_core::voting_power::{EthBridgeVotingPower, FractionalVotingPower}; +use namada_core::{ethereum_structs, token}; use namada_tx::Signed; // the contract versions and namespaces plugged into validator set hashes @@ -384,10 +382,10 @@ impl Encode<1> for ValidatorSetArgs { // this is only here so we don't pollute the // outer namespace with serde traits mod tag { - use namada_core::types::eth_abi::{AbiEncode, Encode, Token}; - use namada_core::types::hash::KeccakHasher; - use namada_core::types::keccak::KeccakHash; - use namada_core::types::key::Signable; + use namada_core::eth_abi::{AbiEncode, Encode, Token}; + use namada_core::hash::KeccakHasher; + use namada_core::keccak::KeccakHash; + use namada_core::key::Signable; use serde::{Deserialize, Serialize}; use super::{ @@ -428,7 +426,7 @@ mod tests { use std::str::FromStr; use data_encoding::HEXLOWER; - use namada_core::types::ethereum_events::EthAddress; + use namada_core::ethereum_events::EthAddress; use super::*; diff --git a/crates/vp_env/src/collection_validation/lazy_map.rs b/crates/vp_env/src/collection_validation/lazy_map.rs index c1fd0949fa..80b83d4cd3 100644 --- a/crates/vp_env/src/collection_validation/lazy_map.rs +++ b/crates/vp_env/src/collection_validation/lazy_map.rs @@ -5,7 +5,7 @@ use core::hash::Hash; use std::collections::HashMap; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::storage; +use namada_core::storage; use namada_storage::collections::lazy_map::{LazyMap, NestedSubKey, SubKey}; use namada_storage::collections::{Nested, Simple}; diff --git a/crates/vp_env/src/collection_validation/lazy_set.rs b/crates/vp_env/src/collection_validation/lazy_set.rs index bfa5828b4a..bc450b6a21 100644 --- a/crates/vp_env/src/collection_validation/lazy_set.rs +++ b/crates/vp_env/src/collection_validation/lazy_set.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; -use namada_core::types::storage; +use namada_core::storage; use namada_storage::collections::lazy_set::{LazySet, SubKey}; use super::LazyCollectionExt; diff --git a/crates/vp_env/src/collection_validation/lazy_vec.rs b/crates/vp_env/src/collection_validation/lazy_vec.rs index 9382c21f22..f6af86c805 100644 --- a/crates/vp_env/src/collection_validation/lazy_vec.rs +++ b/crates/vp_env/src/collection_validation/lazy_vec.rs @@ -4,7 +4,7 @@ use std::collections::BTreeSet; use std::fmt::Debug; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; -use namada_core::types::storage; +use namada_core::storage; use namada_storage::collections::lazy_vec::{ Index, LazyVec, SubKey, ValidationError, }; diff --git a/crates/vp_env/src/collection_validation/mod.rs b/crates/vp_env/src/collection_validation/mod.rs index d74053fb6c..a1ba83a683 100644 --- a/crates/vp_env/src/collection_validation/mod.rs +++ b/crates/vp_env/src/collection_validation/mod.rs @@ -8,7 +8,7 @@ use std::fmt::Debug; use derivative::Derivative; use namada_core::borsh::BorshDeserialize; -use namada_core::types::storage; +use namada_core::storage; use namada_storage::collections::LazyCollection; use crate::VpEnv; diff --git a/crates/vp_env/src/lib.rs b/crates/vp_env/src/lib.rs index 9009f72b39..3cbc515343 100644 --- a/crates/vp_env/src/lib.rs +++ b/crates/vp_env/src/lib.rs @@ -5,16 +5,16 @@ pub mod collection_validation; // TODO: this should be re-exported from namada_shielded_token use masp_primitives::transaction::Transaction; +use namada_core::address::Address; use namada_core::borsh::BorshDeserialize; -use namada_core::types::address::Address; -use namada_core::types::hash::Hash; -use namada_core::types::ibc::{ +use namada_core::hash::Hash; +use namada_core::ibc::{ get_shielded_transfer, IbcEvent, MsgShieldedTransfer, EVENT_TYPE_PACKET, }; -use namada_core::types::storage::{ +use namada_core::storage::{ BlockHash, BlockHeight, Epoch, Epochs, Header, Key, TxIndex, }; -use namada_core::types::token::Transfer; +use namada_core::token::Transfer; use namada_storage::{OptionExt, ResultExt, StorageRead}; use namada_tx::Tx; diff --git a/crates/vp_prelude/src/lib.rs b/crates/vp_prelude/src/lib.rs index 0f57f495c4..1ae4c492b5 100644 --- a/crates/vp_prelude/src/lib.rs +++ b/crates/vp_prelude/src/lib.rs @@ -7,7 +7,7 @@ #![deny(rustdoc::private_intra_doc_links)] pub mod ibc { - pub use namada_core::types::ibc::IbcEvent; + pub use namada_core::ibc::IbcEvent; pub use namada_ibc::storage::is_ibc_key; } @@ -18,17 +18,17 @@ pub use std::collections::{BTreeSet, HashSet}; use std::convert::TryFrom; use std::marker::PhantomData; +pub use namada_core::address::Address; pub use namada_core::borsh::{ BorshDeserialize, BorshSerialize, BorshSerializeExt, }; -pub use namada_core::types::address::Address; -use namada_core::types::chain::CHAIN_ID_LENGTH; -use namada_core::types::hash::{Hash, HASH_LENGTH}; -use namada_core::types::internal::HostEnvResult; -use namada_core::types::storage::{ +use namada_core::chain::CHAIN_ID_LENGTH; +use namada_core::hash::{Hash, HASH_LENGTH}; +use namada_core::internal::HostEnvResult; +use namada_core::storage::{ BlockHash, BlockHeight, Epoch, Epochs, Header, TxIndex, BLOCK_HASH_LENGTH, }; -pub use namada_core::types::*; +pub use namada_core::*; pub use namada_governance::pgf::storage as pgf_storage; pub use namada_governance::storage as gov_storage; pub use namada_macros::validity_predicate; @@ -551,7 +551,7 @@ fn get_pred_epochs() -> Result { "Missing result from `namada_vp_get_pred_epochs` call", ), )?; - Ok(namada_core::types::decode(bytes).expect("Cannot decode pred epochs")) + Ok(namada_core::decode(bytes).expect("Cannot decode pred epochs")) } fn get_native_token() -> Result { diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 803639bbd5..0657ef88bf 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3420,7 +3420,6 @@ dependencies = [ "k256", "masp_primitives", "namada_macros", - "num-derive", "num-integer", "num-rational 0.4.1", "num-traits", @@ -3428,7 +3427,6 @@ dependencies = [ "num_enum", "primitive-types", "proptest", - "prost 0.12.3", "prost-types 0.12.3", "rand 0.8.5", "rand_core 0.6.4", @@ -3582,7 +3580,7 @@ dependencies = [ [[package]] name = "namada_replay_protection" -version = "0.31.1" +version = "0.31.5" dependencies = [ "namada_core", ] diff --git a/wasm/wasm_source/src/tx_bond.rs b/wasm/wasm_source/src/tx_bond.rs index 94c2339d49..68283ee00a 100644 --- a/wasm/wasm_source/src/tx_bond.rs +++ b/wasm/wasm_source/src/tx_bond.rs @@ -20,14 +20,14 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { mod tests { use std::collections::BTreeSet; + use namada::core::dec::Dec; + use namada::core::storage::Epoch; use namada::ledger::pos::{OwnedPosParams, PosVP}; use namada::proof_of_stake::storage::{ bond_handle, read_consensus_validator_set_addresses_with_stake, read_total_stake, read_validator_stake, }; use namada::proof_of_stake::types::{GenesisValidator, WeightedValidator}; - use namada::types::dec::Dec; - use namada::types::storage::Epoch; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; diff --git a/wasm/wasm_source/src/tx_change_validator_commission.rs b/wasm/wasm_source/src/tx_change_validator_commission.rs index ce95c6d780..c081651b90 100644 --- a/wasm/wasm_source/src/tx_change_validator_commission.rs +++ b/wasm/wasm_source/src/tx_change_validator_commission.rs @@ -22,11 +22,11 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { mod tests { use std::cmp; + use namada::core::dec::{Dec, POS_DECIMAL_PRECISION}; + use namada::core::storage::Epoch; use namada::ledger::pos::{OwnedPosParams, PosVP}; use namada::proof_of_stake::storage::validator_commission_rate_handle; use namada::proof_of_stake::types::GenesisValidator; - use namada::types::dec::{Dec, POS_DECIMAL_PRECISION}; - use namada::types::storage::Epoch; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; diff --git a/wasm/wasm_source/src/tx_redelegate.rs b/wasm/wasm_source/src/tx_redelegate.rs index c4f9e240bb..a00f533ab0 100644 --- a/wasm/wasm_source/src/tx_redelegate.rs +++ b/wasm/wasm_source/src/tx_redelegate.rs @@ -24,14 +24,14 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { mod tests { use std::collections::BTreeSet; + use namada::core::dec::Dec; + use namada::core::storage::Epoch; use namada::ledger::pos::{OwnedPosParams, PosVP}; use namada::proof_of_stake::storage::{ bond_handle, read_consensus_validator_set_addresses_with_stake, read_total_stake, read_validator_stake, unbond_handle, }; use namada::proof_of_stake::types::{GenesisValidator, WeightedValidator}; - use namada::types::dec::Dec; - use namada::types::storage::Epoch; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; diff --git a/wasm/wasm_source/src/tx_unbond.rs b/wasm/wasm_source/src/tx_unbond.rs index 5d982c11bb..135b59be69 100644 --- a/wasm/wasm_source/src/tx_unbond.rs +++ b/wasm/wasm_source/src/tx_unbond.rs @@ -27,14 +27,14 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { mod tests { use std::collections::BTreeSet; + use namada::core::dec::Dec; + use namada::core::storage::Epoch; use namada::ledger::pos::{OwnedPosParams, PosVP}; use namada::proof_of_stake::storage::{ bond_handle, read_consensus_validator_set_addresses_with_stake, read_total_stake, read_validator_stake, unbond_handle, }; use namada::proof_of_stake::types::{GenesisValidator, WeightedValidator}; - use namada::types::dec::Dec; - use namada::types::storage::Epoch; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; diff --git a/wasm/wasm_source/src/tx_withdraw.rs b/wasm/wasm_source/src/tx_withdraw.rs index 260da26c11..c6578ae3a3 100644 --- a/wasm/wasm_source/src/tx_withdraw.rs +++ b/wasm/wasm_source/src/tx_withdraw.rs @@ -23,11 +23,11 @@ fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { #[cfg(test)] mod tests { + use namada::core::dec::Dec; + use namada::core::storage::Epoch; use namada::ledger::pos::{OwnedPosParams, PosVP}; use namada::proof_of_stake::storage::unbond_handle; use namada::proof_of_stake::types::GenesisValidator; - use namada::types::dec::Dec; - use namada::types::storage::Epoch; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; diff --git a/wasm/wasm_source/src/vp_implicit.rs b/wasm/wasm_source/src/vp_implicit.rs index e880a75934..c8fdf07455 100644 --- a/wasm/wasm_source/src/vp_implicit.rs +++ b/wasm/wasm_source/src/vp_implicit.rs @@ -286,11 +286,11 @@ fn validate_pos_changes( #[cfg(test)] mod tests { // Use this as `#[test]` annotation to enable logging + use namada::core::dec::Dec; + use namada::core::storage::Epoch; use namada::ledger::pos::{GenesisValidator, PosParams}; use namada::tx::data::TxType; use namada::tx::{Code, Data, Signature}; - use namada::types::dec::Dec; - use namada::types::storage::Epoch; use namada_test_utils::TestWasms; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; diff --git a/wasm/wasm_source/src/vp_user.rs b/wasm/wasm_source/src/vp_user.rs index ca91a20997..fef53b4304 100644 --- a/wasm/wasm_source/src/vp_user.rs +++ b/wasm/wasm_source/src/vp_user.rs @@ -332,11 +332,11 @@ fn validate_pos_changes( #[cfg(test)] mod tests { use address::testing::arb_non_internal_address; + use namada::core::dec::Dec; + use namada::core::storage::Epoch; use namada::ledger::pos::{GenesisValidator, PosParams}; use namada::tx::data::{self, TxType}; use namada::tx::{Code, Data, Signature}; - use namada::types::dec::Dec; - use namada::types::storage::Epoch; use namada_test_utils::TestWasms; // Use this as `#[test]` annotation to enable logging use namada_tests::log::test; diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 83e0dcff85..66f34d13fc 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3420,7 +3420,6 @@ dependencies = [ "k256", "masp_primitives", "namada_macros", - "num-derive", "num-integer", "num-rational 0.4.1", "num-traits", @@ -3428,7 +3427,6 @@ dependencies = [ "num_enum", "primitive-types", "proptest", - "prost 0.12.3", "prost-types 0.12.3", "rand 0.8.5", "rand_core 0.6.4", @@ -3582,7 +3580,7 @@ dependencies = [ [[package]] name = "namada_replay_protection" -version = "0.31.1" +version = "0.31.5" dependencies = [ "namada_core", ] From 94d1a0b2048bb33fd2043aa27a69d388d965163a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Fri, 2 Feb 2024 09:20:12 +0000 Subject: [PATCH 15/19] changelog: add #2503 --- .changelog/unreleased/improvements/2503-refactor-core.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/2503-refactor-core.md diff --git a/.changelog/unreleased/improvements/2503-refactor-core.md b/.changelog/unreleased/improvements/2503-refactor-core.md new file mode 100644 index 0000000000..ce17f4bec7 --- /dev/null +++ b/.changelog/unreleased/improvements/2503-refactor-core.md @@ -0,0 +1,2 @@ +- Refactored core crate to flatten the modules structure. + ([\#2503](https://github.com/anoma/namada/pull/2503)) \ No newline at end of file From 8424f96fd7d52cd40c7a54ae23c4fd8d60764c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Fri, 2 Feb 2024 09:30:33 +0000 Subject: [PATCH 16/19] gov: replace namada_state dep with namada_storage --- Cargo.lock | 2 +- crates/governance/Cargo.toml | 2 +- crates/governance/src/parameters.rs | 4 +-- crates/governance/src/pgf/inflation.rs | 20 ++++-------- crates/governance/src/pgf/parameters.rs | 4 +-- crates/governance/src/pgf/storage/keys.rs | 2 +- crates/governance/src/pgf/storage/mod.rs | 19 +++++------ crates/governance/src/storage/mod.rs | 39 ++++++++--------------- wasm/Cargo.lock | 2 +- wasm_for_tests/wasm_source/Cargo.lock | 2 +- 10 files changed, 37 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 70279d8475..1366316eb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4444,7 +4444,7 @@ dependencies = [ "namada_core", "namada_macros", "namada_parameters", - "namada_state", + "namada_storage", "namada_trans_token", "proptest", "serde 1.0.193", diff --git a/crates/governance/Cargo.toml b/crates/governance/Cargo.toml index 2693a0dc96..4550eda46c 100644 --- a/crates/governance/Cargo.toml +++ b/crates/governance/Cargo.toml @@ -19,7 +19,7 @@ testing = ["proptest"] namada_core = { path = "../core" } namada_macros = {path = "../macros"} namada_parameters = {path = "../parameters"} -namada_state = {path = "../state"} +namada_storage = {path = "../storage"} namada_trans_token = {path = "../trans_token"} borsh.workspace = true diff --git a/crates/governance/src/parameters.rs b/crates/governance/src/parameters.rs index b1537bf381..5318ec2880 100644 --- a/crates/governance/src/parameters.rs +++ b/crates/governance/src/parameters.rs @@ -1,6 +1,6 @@ use namada_core::borsh::{BorshDeserialize, BorshSerialize}; use namada_core::token; -use namada_state::{StorageRead, StorageResult, StorageWrite}; +use namada_storage::{Result, StorageRead, StorageWrite}; use super::storage::keys as goverance_storage; @@ -46,7 +46,7 @@ impl Default for GovernanceParameters { impl GovernanceParameters { /// Initialize governance parameters into storage - pub fn init_storage(&self, storage: &mut S) -> StorageResult<()> + pub fn init_storage(&self, storage: &mut S) -> Result<()> where S: StorageRead + StorageWrite, { diff --git a/crates/governance/src/pgf/inflation.rs b/crates/governance/src/pgf/inflation.rs index a057c8b479..a77373e4f9 100644 --- a/crates/governance/src/pgf/inflation.rs +++ b/crates/governance/src/pgf/inflation.rs @@ -3,9 +3,7 @@ use namada_core::address::Address; use namada_core::token; use namada_parameters::storage as params_storage; -use namada_state::{ - DBIter, StorageHasher, StorageRead, StorageResult, WlStorage, DB, -}; +use namada_storage::{Result, StorageRead, StorageWrite}; use namada_trans_token::credit_tokens; use namada_trans_token::storage_key::minted_balance_key; @@ -13,19 +11,13 @@ use crate::pgf::storage::{get_parameters, get_payments, get_stewards}; use crate::storage::proposal::{PGFIbcTarget, PGFTarget}; /// Apply the PGF inflation. -pub fn apply_inflation( - storage: &mut WlStorage, +pub fn apply_inflation( + storage: &mut S, transfer_over_ibc: F, -) -> StorageResult<()> +) -> Result<()> where - D: DB + for<'iter> DBIter<'iter> + Sync + 'static, - H: StorageHasher + Sync + 'static, - F: Fn( - &mut WlStorage, - &Address, - &Address, - &PGFIbcTarget, - ) -> StorageResult<()>, + S: StorageWrite + StorageRead, + F: Fn(&mut S, &Address, &Address, &PGFIbcTarget) -> Result<()>, { let pgf_parameters = get_parameters(storage)?; let staking_token = storage.get_native_token()?; diff --git a/crates/governance/src/pgf/parameters.rs b/crates/governance/src/pgf/parameters.rs index 5e9bb34f34..69e6fea9d3 100644 --- a/crates/governance/src/pgf/parameters.rs +++ b/crates/governance/src/pgf/parameters.rs @@ -3,7 +3,7 @@ use std::collections::BTreeSet; use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; use namada_core::dec::Dec; -use namada_state::{StorageRead, StorageResult, StorageWrite}; +use namada_storage::{Result, StorageRead, StorageWrite}; use serde::{Deserialize, Serialize}; use super::storage::keys as pgf_storage; @@ -44,7 +44,7 @@ impl Default for PgfParameters { impl PgfParameters { /// Initialize governance parameters into storage - pub fn init_storage(&self, storage: &mut S) -> StorageResult<()> + pub fn init_storage(&self, storage: &mut S) -> Result<()> where S: StorageRead + StorageWrite, { diff --git a/crates/governance/src/pgf/storage/keys.rs b/crates/governance/src/pgf/storage/keys.rs index 3d856f066b..dcdee44d83 100644 --- a/crates/governance/src/pgf/storage/keys.rs +++ b/crates/governance/src/pgf/storage/keys.rs @@ -1,7 +1,7 @@ use namada_core::address::Address; use namada_core::storage::{DbKeySeg, Key, KeySeg}; use namada_macros::StorageKeys; -use namada_state::collections::{lazy_map, LazyCollection, LazyMap}; +use namada_storage::collections::{lazy_map, LazyCollection, LazyMap}; use crate::pgf::storage::steward::StewardDetail; use crate::pgf::ADDRESS; diff --git a/crates/governance/src/pgf/storage/mod.rs b/crates/governance/src/pgf/storage/mod.rs index fd8190dd51..2775398a9f 100644 --- a/crates/governance/src/pgf/storage/mod.rs +++ b/crates/governance/src/pgf/storage/mod.rs @@ -9,7 +9,7 @@ use std::collections::HashMap; use namada_core::address::Address; use namada_core::dec::Dec; -use namada_state::{StorageRead, StorageResult, StorageWrite}; +use namada_storage::{Result, StorageRead, StorageWrite}; use crate::pgf::parameters::PgfParameters; use crate::pgf::storage::keys as pgf_keys; @@ -17,7 +17,7 @@ use crate::pgf::storage::steward::StewardDetail; use crate::storage::proposal::StoragePgfFunding; /// Query the current pgf steward set -pub fn get_stewards(storage: &S) -> StorageResult> +pub fn get_stewards(storage: &S) -> Result> where S: StorageRead, { @@ -36,7 +36,7 @@ where pub fn get_steward( storage: &S, address: &Address, -) -> StorageResult> +) -> Result> where S: StorageRead, { @@ -44,7 +44,7 @@ where } /// Check if an address is a steward -pub fn is_steward(storage: &S, address: &Address) -> StorageResult +pub fn is_steward(storage: &S, address: &Address) -> Result where S: StorageRead, { @@ -52,10 +52,7 @@ where } /// Remove a steward -pub fn remove_steward( - storage: &mut S, - address: &Address, -) -> StorageResult<()> +pub fn remove_steward(storage: &mut S, address: &Address) -> Result<()> where S: StorageRead + StorageWrite, { @@ -65,7 +62,7 @@ where } /// Query the current pgf continous payments -pub fn get_payments(storage: &S) -> StorageResult> +pub fn get_payments(storage: &S) -> Result> where S: StorageRead, { @@ -81,7 +78,7 @@ where } /// Query the pgf parameters -pub fn get_parameters(storage: &S) -> StorageResult +pub fn get_parameters(storage: &S) -> Result where S: StorageRead, { @@ -108,7 +105,7 @@ pub fn update_commission( storage: &mut S, address: Address, reward_distribution: HashMap, -) -> StorageResult<()> +) -> Result<()> where S: StorageRead + StorageWrite, { diff --git a/crates/governance/src/storage/mod.rs b/crates/governance/src/storage/mod.rs index bc8c36a4ea..a6cc8bc787 100644 --- a/crates/governance/src/storage/mod.rs +++ b/crates/governance/src/storage/mod.rs @@ -12,9 +12,7 @@ use std::collections::BTreeMap; use namada_core::address::Address; use namada_core::borsh::BorshDeserialize; use namada_core::storage::Epoch; -use namada_state::{ - iter_prefix, StorageError, StorageRead, StorageResult, StorageWrite, -}; +use namada_storage::{iter_prefix, Error, Result, StorageRead, StorageWrite}; use namada_trans_token as token; use crate::parameters::GovernanceParameters; @@ -32,7 +30,7 @@ pub fn init_proposal( data: InitProposalData, content: Vec, code: Option>, -) -> StorageResult<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -57,7 +55,7 @@ where governance_keys::get_proposal_code_key(proposal_id); let proposal_code = code .clone() - .ok_or(StorageError::new_const("Missing proposal code"))?; + .ok_or(Error::new_const("Missing proposal code"))?; storage.write_bytes(&proposal_code_key, proposal_code)? } _ => storage.write(&proposal_type_key, data.r#type.clone())?, @@ -78,7 +76,7 @@ where let proposal_code_key = governance_keys::get_proposal_code_key(proposal_id); let proposal_code = - code.ok_or(StorageError::new_const("Missing proposal code"))?; + code.ok_or(Error::new_const("Missing proposal code"))?; storage.write_bytes(&proposal_code_key, proposal_code)?; } @@ -109,10 +107,7 @@ where } /// A proposal vote transaction. -pub fn vote_proposal( - storage: &mut S, - data: VoteProposalData, -) -> StorageResult<()> +pub fn vote_proposal(storage: &mut S, data: VoteProposalData) -> Result<()> where S: StorageRead + StorageWrite, { @@ -132,7 +127,7 @@ pub fn write_proposal_result( storage: &mut S, proposal_id: u64, proposal_result: ProposalResult, -) -> StorageResult<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -145,7 +140,7 @@ where pub fn get_proposal_by_id( storage: &S, id: u64, -) -> StorageResult> +) -> Result> where S: StorageRead, { @@ -178,10 +173,7 @@ where } /// Query all the votes for a proposal_id -pub fn get_proposal_votes( - storage: &S, - proposal_id: u64, -) -> StorageResult> +pub fn get_proposal_votes(storage: &S, proposal_id: u64) -> Result> where S: StorageRead, { @@ -216,10 +208,7 @@ where } /// Check if an accepted proposal is being executed -pub fn is_proposal_accepted( - storage: &S, - tx_data: &[u8], -) -> StorageResult +pub fn is_proposal_accepted(storage: &S, tx_data: &[u8]) -> Result where S: StorageRead, { @@ -237,7 +226,7 @@ where pub fn get_proposal_code( storage: &S, proposal_id: u64, -) -> StorageResult>> +) -> Result>> where S: StorageRead, { @@ -249,7 +238,7 @@ where pub fn get_proposal_author( storage: &S, proposal_id: u64, -) -> StorageResult> +) -> Result> where S: StorageRead, { @@ -258,7 +247,7 @@ where } /// Get governance parameters -pub fn get_parameters(storage: &S) -> StorageResult +pub fn get_parameters(storage: &S) -> Result where S: StorageRead, { @@ -295,7 +284,7 @@ where } /// Get governance "max_proposal_period" parameter -pub fn get_max_proposal_period(storage: &S) -> StorageResult +pub fn get_max_proposal_period(storage: &S) -> Result where S: StorageRead, { @@ -309,7 +298,7 @@ where pub fn get_proposal_result( storage: &S, proposal_id: u64, -) -> StorageResult> +) -> Result> where S: StorageRead, { diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 0657ef88bf..feeef48f40 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3491,7 +3491,7 @@ dependencies = [ "namada_core", "namada_macros", "namada_parameters", - "namada_state", + "namada_storage", "namada_trans_token", "proptest", "serde", diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 66f34d13fc..762a63baeb 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3491,7 +3491,7 @@ dependencies = [ "namada_core", "namada_macros", "namada_parameters", - "namada_state", + "namada_storage", "namada_trans_token", "proptest", "serde", From 224798f39fa031f82e958544e2e3bc9424488814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Fri, 2 Feb 2024 09:49:06 +0000 Subject: [PATCH 17/19] changelog: add #2506 --- .changelog/unreleased/improvements/2506-refactor-gov.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/2506-refactor-gov.md diff --git a/.changelog/unreleased/improvements/2506-refactor-gov.md b/.changelog/unreleased/improvements/2506-refactor-gov.md new file mode 100644 index 0000000000..3b4b0d144f --- /dev/null +++ b/.changelog/unreleased/improvements/2506-refactor-gov.md @@ -0,0 +1,2 @@ +- Refactored governance crate dependencies. + ([\#2506](https://github.com/anoma/namada/pull/2506)) \ No newline at end of file From 8fdd83aaddd39bb7d21de46e9698e11c50cd61da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Fri, 2 Feb 2024 10:32:48 +0000 Subject: [PATCH 18/19] core: prevent from using addresses for testing in non-test code --- crates/apps/src/lib/bench_utils.rs | 6 +- crates/apps/src/lib/config/genesis.rs | 2 +- .../src/lib/config/genesis/transactions.rs | 23 +-- crates/apps/src/lib/node/ledger/shell/mod.rs | 29 ++-- .../lib/node/ledger/shell/prepare_proposal.rs | 17 ++- .../lib/node/ledger/shell/process_proposal.rs | 9 +- .../apps/src/lib/node/ledger/storage/mod.rs | 20 +-- crates/apps/src/lib/wallet/defaults.rs | 5 +- crates/benches/host_env.rs | 2 +- crates/benches/native_vps.rs | 2 +- crates/benches/process_wrapper.rs | 4 +- crates/benches/vps.rs | 12 +- crates/core/src/address.rs | 141 +++++++++--------- crates/core/src/eth_bridge_pool.rs | 3 +- .../transactions/ethereum_events/events.rs | 4 +- crates/ethereum_bridge/src/storage/mod.rs | 2 +- .../src/storage/wrapped_erc20s.rs | 3 +- crates/ethereum_bridge/src/test_utils.rs | 3 +- crates/merkle_tree/Cargo.toml | 2 + crates/merkle_tree/src/eth_bridge_pool.rs | 3 +- .../ethereum_bridge/bridge_pool_vp.rs | 6 +- .../ledger/native_vp/ethereum_bridge/vp.rs | 3 +- crates/namada/src/ledger/native_vp/ibc/mod.rs | 4 +- .../namada/src/ledger/native_vp/multitoken.rs | 3 +- crates/sdk/src/eth_bridge/bridge_pool.rs | 16 +- crates/sdk/src/queries/shell/eth_bridge.rs | 3 +- crates/shielded_token/src/conversion.rs | 14 +- crates/state/src/lib.rs | 2 +- crates/storage/src/lib.rs | 2 +- crates/tests/src/native_vp/eth_bridge_pool.rs | 2 +- crates/trans_token/src/storage.rs | 2 +- crates/tx/src/data/mod.rs | 2 +- wasm/wasm_source/src/vp_implicit.rs | 12 +- wasm/wasm_source/src/vp_user.rs | 16 +- 34 files changed, 199 insertions(+), 180 deletions(-) diff --git a/crates/apps/src/lib/bench_utils.rs b/crates/apps/src/lib/bench_utils.rs index 1db7a07411..9a242a920c 100644 --- a/crates/apps/src/lib/bench_utils.rs +++ b/crates/apps/src/lib/bench_utils.rs @@ -350,7 +350,7 @@ impl BenchShell { pub fn generate_ibc_transfer_tx(&self) -> Tx { let token = PrefixedCoin { - denom: address::nam().to_string().parse().unwrap(), + denom: address::testing::nam().to_string().parse().unwrap(), amount: Amount::native_whole(1000) .to_string_native() .split('.') @@ -1005,7 +1005,7 @@ impl BenchShieldedCtx { &namada, &source, &target, - &address::nam(), + &address::testing::nam(), denominated_amount, ), ) @@ -1034,7 +1034,7 @@ impl BenchShieldedCtx { Transfer { source: source.effective_address(), target: target.effective_address(), - token: address::nam(), + token: address::testing::nam(), amount: DenominatedAmount::native(amount), key: None, shielded: shielded_section_hash, diff --git a/crates/apps/src/lib/config/genesis.rs b/crates/apps/src/lib/config/genesis.rs index 074d17966a..321f48a6ef 100644 --- a/crates/apps/src/lib/config/genesis.rs +++ b/crates/apps/src/lib/config/genesis.rs @@ -313,7 +313,7 @@ pub fn make_dev_genesis( use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::time::Duration; - use namada::core::address::wnam; + use namada::core::address::testing::wnam; use namada::core::chain::ChainIdPrefix; use namada::core::ethereum_events::EthAddress; use namada::core::key::*; diff --git a/crates/apps/src/lib/config/genesis/transactions.rs b/crates/apps/src/lib/config/genesis/transactions.rs index 8d3e6facfc..d53203c705 100644 --- a/crates/apps/src/lib/config/genesis/transactions.rs +++ b/crates/apps/src/lib/config/genesis/transactions.rs @@ -11,7 +11,7 @@ use ledger_namada_rs::NamadaApp; use ledger_transport_hid::hidapi::HidApi; use ledger_transport_hid::TransportNativeHID; use namada::account::AccountPublicKeysMap; -use namada::core::address::{nam, Address, EstablishedAddress}; +use namada::core::address::{Address, EstablishedAddress}; use namada::core::chain::ChainId; use namada::core::dec::Dec; use namada::core::key::{ @@ -81,7 +81,7 @@ fn get_tx_args(use_device: bool) -> TxArgs { wallet_alias_force: false, fee_amount: None, wrapper_fee_payer: None, - fee_token: nam(), + fee_token: genesis_fee_token_address(), fee_unshield: None, gas_limit: Default::default(), expiration: None, @@ -120,13 +120,13 @@ fn get_tx_to_sign(tag: impl AsRef, data: impl BorshSerialize) -> Tx { salt: [0; 8], data: data.serialize_to_vec(), }); - let pk = get_sentinel_pubkey(); + let fee_payer = genesis_fee_payer_pk(); tx.add_wrapper( Fee { amount_per_gas_unit: DenominatedAmount::native(0.into()), - token: Address::from(&pk), + token: genesis_fee_token_address(), }, - pk, + fee_payer, Default::default(), Default::default(), None, @@ -134,12 +134,17 @@ fn get_tx_to_sign(tag: impl AsRef, data: impl BorshSerialize) -> Tx { tx } -/// Get a dummy public key. +/// Get a dummy public key for a fee payer - there are no fees for genesis tx #[inline] -fn get_sentinel_pubkey() -> common::PublicKey { +fn genesis_fee_payer_pk() -> common::PublicKey { common::SecretKey::Ed25519(ed25519::SigScheme::from_bytes([0; 32])).ref_to() } +/// Dummy genesis fee token address - there are no fees for genesis tx +fn genesis_fee_token_address() -> Address { + Address::from(&genesis_fee_payer_pk()) +} + pub struct GenesisValidatorData { pub address: EstablishedAddress, pub commission_rate: Dec, @@ -741,7 +746,7 @@ impl Signed { account_public_keys_map: Some(pks.iter().cloned().collect()), public_keys: pks.clone(), threshold, - fee_payer: get_sentinel_pubkey(), + fee_payer: genesis_fee_payer_pk(), }; let mut tx = self.data.tx_to_sign(); @@ -769,7 +774,7 @@ impl Signed { _parts: HashSet, _user: (), ) -> Result { - if pubkey == get_sentinel_pubkey() { + if pubkey == genesis_fee_payer_pk() { Ok(tx) } else { Err(namada_sdk::error::Error::Other(format!( diff --git a/crates/apps/src/lib/node/ledger/shell/mod.rs b/crates/apps/src/lib/node/ledger/shell/mod.rs index 977387b280..d0d12ac014 100644 --- a/crates/apps/src/lib/node/ledger/shell/mod.rs +++ b/crates/apps/src/lib/node/ledger/shell/mod.rs @@ -410,16 +410,24 @@ where std::fs::create_dir(&base_dir) .expect("Creating directory for Namada should not fail"); } - let native_token = if cfg!(feature = "integration") - || (!cfg!(test) && !cfg!(feature = "benches")) - { + + // For all tests except integration use hard-coded native token addr ... + #[cfg(all( + any(test, feature = "testing", feature = "benches"), + not(feature = "integration"), + ))] + let native_token = address::testing::nam(); + // ... Otherwise, look it up from the genesis file + #[cfg(not(all( + any(test, feature = "testing", feature = "benches"), + not(feature = "integration"), + )))] + let native_token = { let chain_dir = base_dir.join(chain_id.as_str()); let genesis = genesis::chain::Finalized::read_toml_files(&chain_dir) .expect("Missing genesis files"); genesis.get_native_token().clone() - } else { - address::nam() }; // load last state from storage @@ -1935,7 +1943,7 @@ mod test_utils { ); let vp_wasm_compilation_cache = 50 * 1024 * 1024; // 50 kiB let tx_wasm_compilation_cache = 50 * 1024 * 1024; // 50 kiB - let native_token = address::nam(); + let native_token = address::testing::nam(); let mut shell = Shell::::new( config::Ledger::new( base_dir.clone(), @@ -2742,9 +2750,10 @@ mod shell_tests { #[test] fn test_fee_non_whitelisted_token() { let (shell, _recv, _, _) = test_utils::setup(); - let apfel_denom = read_denom(&shell.wl_storage, &address::apfel()) - .expect("unable to read denomination from storage") - .expect("unable to find denomination of apfels"); + let apfel_denom = + read_denom(&shell.wl_storage, &address::testing::apfel()) + .expect("unable to read denomination from storage") + .expect("unable to find denomination of apfels"); let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( @@ -2753,7 +2762,7 @@ mod shell_tests { 100.into(), apfel_denom, ), - token: address::apfel(), + token: address::testing::apfel(), }, crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), diff --git a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs index 9b56878f16..a8860c1607 100644 --- a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -1183,13 +1183,13 @@ mod test_prepare_proposal { // Remove the allowed btc *local_config = Some(ValidatorLocalConfig { accepted_gas_tokens: std::collections::HashMap::from([( - namada::core::address::nam(), + namada::core::address::testing::nam(), Amount::from(1), )]), }); } - let btc_denom = read_denom(&shell.wl_storage, &address::btc()) + let btc_denom = read_denom(&shell.wl_storage, &address::testing::btc()) .expect("unable to read denomination from storage") .expect("unable to find denomination of btcs"); @@ -1199,7 +1199,7 @@ mod test_prepare_proposal { 100.into(), btc_denom, ), - token: address::btc(), + token: address::testing::btc(), }, crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), @@ -1237,9 +1237,10 @@ mod test_prepare_proposal { fn test_fee_non_whitelisted_token() { let (shell, _recv, _, _) = test_utils::setup(); - let apfel_denom = read_denom(&shell.wl_storage, &address::apfel()) - .expect("unable to read denomination from storage") - .expect("unable to find denomination of apfels"); + let apfel_denom = + read_denom(&shell.wl_storage, &address::testing::apfel()) + .expect("unable to read denomination from storage") + .expect("unable to find denomination of apfels"); let wrapper = WrapperTx::new( Fee { @@ -1247,7 +1248,7 @@ mod test_prepare_proposal { 100.into(), apfel_denom, ), - token: address::apfel(), + token: address::testing::apfel(), }, crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), @@ -1289,7 +1290,7 @@ mod test_prepare_proposal { // Remove btc and increase minimum for nam *local_config = Some(ValidatorLocalConfig { accepted_gas_tokens: std::collections::HashMap::from([( - namada::core::address::nam(), + namada::core::address::testing::nam(), Amount::from(100), )]), }); diff --git a/crates/apps/src/lib/node/ledger/shell/process_proposal.rs b/crates/apps/src/lib/node/ledger/shell/process_proposal.rs index 4f4e3eb132..2414ed4757 100644 --- a/crates/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/crates/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -1868,9 +1868,10 @@ mod test_process_proposal { fn test_fee_non_whitelisted_token() { let (shell, _recv, _, _) = test_utils::setup(); - let apfel_denom = read_denom(&shell.wl_storage, &address::apfel()) - .expect("unable to read denomination from storage") - .expect("unable to find denomination of apfels"); + let apfel_denom = + read_denom(&shell.wl_storage, &address::testing::apfel()) + .expect("unable to read denomination from storage") + .expect("unable to find denomination of apfels"); let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( @@ -1879,7 +1880,7 @@ mod test_process_proposal { 100.into(), apfel_denom, ), - token: address::apfel(), + token: address::testing::apfel(), }, crate::wallet::defaults::albert_keypair().ref_to(), Epoch(0), diff --git a/crates/apps/src/lib/node/ledger/storage/mod.rs b/crates/apps/src/lib/node/ledger/storage/mod.rs index 8f9aef8476..551cf41628 100644 --- a/crates/apps/src/lib/node/ledger/storage/mod.rs +++ b/crates/apps/src/lib/node/ledger/storage/mod.rs @@ -87,7 +87,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -139,7 +139,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -201,7 +201,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -226,7 +226,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -273,7 +273,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -341,7 +341,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -433,7 +433,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -552,7 +552,7 @@ mod tests { let mut storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, Some(5), is_merklized_storage_key, @@ -654,7 +654,7 @@ mod tests { let storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, is_merklized_storage_key, @@ -769,7 +769,7 @@ mod tests { let storage = PersistentStorage::open( db_path.path(), ChainId::default(), - address::nam(), + address::testing::nam(), None, None, merkle_tree_key_filter, diff --git a/crates/apps/src/lib/wallet/defaults.rs b/crates/apps/src/lib/wallet/defaults.rs index 3b06bdfb13..1885c2ade7 100644 --- a/crates/apps/src/lib/wallet/defaults.rs +++ b/crates/apps/src/lib/wallet/defaults.rs @@ -13,9 +13,10 @@ mod dev { use std::collections::HashMap; use lazy_static::lazy_static; - use namada::core::address::{ - apfel, btc, dot, eth, kartoffel, nam, schnitzel, Address, + use namada::core::address::testing::{ + apfel, btc, dot, eth, kartoffel, nam, schnitzel, }; + use namada::core::address::Address; use namada::core::key::*; use namada::ledger::{governance, pgf, pos}; use namada_sdk::wallet::alias::Alias; diff --git a/crates/benches/host_env.rs b/crates/benches/host_env.rs index a659e7aa51..1e97a5936d 100644 --- a/crates/benches/host_env.rs +++ b/crates/benches/host_env.rs @@ -21,7 +21,7 @@ fn tx_section_signature_validation(c: &mut Criterion) { let transfer_data = Transfer { source: defaults::albert_address(), target: defaults::bertha_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(500).native_denominated(), key: None, shielded: None, diff --git a/crates/benches/native_vps.rs b/crates/benches/native_vps.rs index e4d94d764f..3806d4f7c7 100644 --- a/crates/benches/native_vps.rs +++ b/crates/benches/native_vps.rs @@ -415,7 +415,7 @@ fn vp_multitoken(c: &mut Criterion) { Transfer { source: defaults::albert_address(), target: defaults::bertha_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(1000).native_denominated(), key: None, shielded: None, diff --git a/crates/benches/process_wrapper.rs b/crates/benches/process_wrapper.rs index 4264748e53..4dad8ae840 100644 --- a/crates/benches/process_wrapper.rs +++ b/crates/benches/process_wrapper.rs @@ -23,7 +23,7 @@ fn process_tx(c: &mut Criterion) { Transfer { source: defaults::albert_address(), target: defaults::bertha_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(1).native_denominated(), key: None, shielded: None, @@ -36,7 +36,7 @@ fn process_tx(c: &mut Criterion) { tx.update_header(namada::tx::data::TxType::Wrapper(Box::new( WrapperTx::new( Fee { - token: address::nam(), + token: address::testing::nam(), amount_per_gas_unit: DenominatedAmount::native(1.into()), }, defaults::albert_keypair().ref_to(), diff --git a/crates/benches/vps.rs b/crates/benches/vps.rs index 352fe39f25..d552c32a9a 100644 --- a/crates/benches/vps.rs +++ b/crates/benches/vps.rs @@ -41,7 +41,7 @@ fn vp_user(c: &mut Criterion) { Transfer { source: defaults::albert_address(), target: defaults::bertha_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(1000).native_denominated(), key: None, shielded: None, @@ -56,7 +56,7 @@ fn vp_user(c: &mut Criterion) { Transfer { source: defaults::bertha_address(), target: defaults::albert_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(1000).native_denominated(), key: None, shielded: None, @@ -187,7 +187,7 @@ fn vp_implicit(c: &mut Criterion) { Transfer { source: Address::from(&implicit_account.to_public()), target: defaults::bertha_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(500).native_denominated(), key: None, shielded: None, @@ -202,7 +202,7 @@ fn vp_implicit(c: &mut Criterion) { Transfer { source: defaults::bertha_address(), target: Address::from(&implicit_account.to_public()), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(1000).native_denominated(), key: None, shielded: None, @@ -330,7 +330,7 @@ fn vp_validator(c: &mut Criterion) { Transfer { source: defaults::validator_address(), target: defaults::bertha_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(1000).native_denominated(), key: None, shielded: None, @@ -345,7 +345,7 @@ fn vp_validator(c: &mut Criterion) { Transfer { source: defaults::bertha_address(), target: defaults::validator_address(), - token: address::nam(), + token: address::testing::nam(), amount: Amount::native_whole(1000).native_denominated(), key: None, shielded: None, diff --git a/crates/core/src/address.rs b/crates/core/src/address.rs index 9cd8f3c64d..3b1655f84c 100644 --- a/crates/core/src/address.rs +++ b/crates/core/src/address.rs @@ -3,7 +3,6 @@ mod raw; -use std::collections::HashMap; use std::fmt::{Debug, Display}; use std::hash::Hash; use std::str::FromStr; @@ -18,7 +17,6 @@ use crate::ethereum_events::EthAddress; use crate::ibc::primitives::Signer; use crate::ibc::IbcTokenHash; use crate::key::PublicKeyHash; -use crate::token::Denomination; use crate::{impl_display_and_from_str_via_format, key, string_encoding}; /// The length of an established [`Address`] encoded with Borsh. @@ -586,74 +584,6 @@ impl InternalAddress { } } -/// Temporary helper for testing -pub fn nam() -> Address { - Address::decode("tnam1q99c37u38grkdcc2qze0hz4zjjd8zr3yucd3mzgz") - .expect("The token address decoding shouldn't fail") -} - -/// Temporary helper for testing -pub fn btc() -> Address { - Address::decode("tnam1qy7jxng788scr4fdqxqxtc2ze2guq5478cml9cd9") - .expect("The token address decoding shouldn't fail") -} - -/// Temporary helper for testing -pub fn eth() -> Address { - Address::decode("tnam1qyr9vd8ltunq72qc7pk58v7jdsedt4mggqqpxs03") - .expect("The token address decoding shouldn't fail") -} - -/// Temporary helper for testing -pub fn dot() -> Address { - Address::decode("tnam1qx6k4wau5t6m8g2hjq55fje2ynpvh5t27s8p3p0l") - .expect("The token address decoding shouldn't fail") -} - -/// Temporary helper for testing -pub fn schnitzel() -> Address { - Address::decode("tnam1q9euzsu2qfv4y6p0dqaga20n0u0yp8c3ec006yg2") - .expect("The token address decoding shouldn't fail") -} - -/// Temporary helper for testing -pub fn apfel() -> Address { - Address::decode("tnam1qxlmdmw2y6hzvjg34zca8r6d4s6zmtkhty8myzu4") - .expect("The token address decoding shouldn't fail") -} - -/// Temporary helper for testing -pub fn kartoffel() -> Address { - Address::decode("tnam1q87teqzjytwa9xd9qk8u558xxnrwuzdjzs7zvhzr") - .expect("The token address decoding shouldn't fail") -} - -/// Temporary helper for testing -pub const fn wnam() -> EthAddress { - // TODO: Replace this with the real wNam ERC20 address once it exists - // "DEADBEEF DEADBEEF DEADBEEF DEADBEEF DEADBEEF" - EthAddress([ - 222, 173, 190, 239, 222, 173, 190, 239, 222, 173, 190, 239, 222, 173, - 190, 239, 222, 173, 190, 239, - ]) -} - -/// Temporary helper for testing, a hash map of tokens addresses with their -/// informal currency codes and number of decimal places. -pub fn tokens() -> HashMap<&'static str, Denomination> { - vec![ - ("nam", 6.into()), - ("btc", 8.into()), - ("eth", 18.into()), - ("dot", 10.into()), - ("schnitzel", 6.into()), - ("apfel", 6.into()), - ("kartoffel", 6.into()), - ] - .into_iter() - .collect() -} - #[cfg(test)] pub mod tests { use proptest::prelude::*; @@ -745,10 +675,13 @@ pub fn gen_deterministic_established_address(seed: impl AsRef) -> Address { /// Helpers for testing with addresses. #[cfg(any(test, feature = "testing"))] pub mod testing { + use std::collections::HashMap; + use proptest::prelude::*; use super::*; use crate::key::*; + use crate::token::Denomination; /// Generate a new established address. pub fn gen_established_address() -> Address { @@ -907,4 +840,72 @@ pub mod testing { // TODO: generate random erc20 addr data InternalAddress::Nut(arbitrary_eth_address()) } + + /// NAM token address for testing + pub fn nam() -> Address { + Address::decode("tnam1q99c37u38grkdcc2qze0hz4zjjd8zr3yucd3mzgz") + .expect("The token address decoding shouldn't fail") + } + + /// BTC token address for testing + pub fn btc() -> Address { + Address::decode("tnam1qy7jxng788scr4fdqxqxtc2ze2guq5478cml9cd9") + .expect("The token address decoding shouldn't fail") + } + + /// ETH token address for testing + pub fn eth() -> Address { + Address::decode("tnam1qyr9vd8ltunq72qc7pk58v7jdsedt4mggqqpxs03") + .expect("The token address decoding shouldn't fail") + } + + /// DOT token address for testing + pub fn dot() -> Address { + Address::decode("tnam1qx6k4wau5t6m8g2hjq55fje2ynpvh5t27s8p3p0l") + .expect("The token address decoding shouldn't fail") + } + + /// Imaginary token address for testing + pub fn schnitzel() -> Address { + Address::decode("tnam1q9euzsu2qfv4y6p0dqaga20n0u0yp8c3ec006yg2") + .expect("The token address decoding shouldn't fail") + } + + /// Imaginary token address for testing + pub fn apfel() -> Address { + Address::decode("tnam1qxlmdmw2y6hzvjg34zca8r6d4s6zmtkhty8myzu4") + .expect("The token address decoding shouldn't fail") + } + + /// Imaginary token address for testing + pub fn kartoffel() -> Address { + Address::decode("tnam1q87teqzjytwa9xd9qk8u558xxnrwuzdjzs7zvhzr") + .expect("The token address decoding shouldn't fail") + } + + /// Imaginary eth address for testing + pub const fn wnam() -> EthAddress { + // TODO: Replace this with the real wNam ERC20 address once it exists + // "DEADBEEF DEADBEEF DEADBEEF DEADBEEF DEADBEEF" + EthAddress([ + 222, 173, 190, 239, 222, 173, 190, 239, 222, 173, 190, 239, 222, + 173, 190, 239, 222, 173, 190, 239, + ]) + } + + /// A hash map of tokens addresses with their informal currency codes and + /// number of decimal places. + pub fn tokens() -> HashMap<&'static str, Denomination> { + vec![ + ("nam", 6.into()), + ("btc", 8.into()), + ("eth", 18.into()), + ("dot", 10.into()), + ("schnitzel", 6.into()), + ("apfel", 6.into()), + ("kartoffel", 6.into()), + ] + .into_iter() + .collect() + } } diff --git a/crates/core/src/eth_bridge_pool.rs b/crates/core/src/eth_bridge_pool.rs index b2d9c82986..86fa7daaea 100644 --- a/crates/core/src/eth_bridge_pool.rs +++ b/crates/core/src/eth_bridge_pool.rs @@ -434,8 +434,7 @@ pub mod testing { #[cfg(test)] mod test_eth_bridge_pool_types { use super::*; - use crate::address::nam; - use crate::address::testing::established_address_1; + use crate::address::testing::{established_address_1, nam}; /// Test that [`PendingTransfer`] and [`TransferToEthereum`] /// have the same keccak hash, after being ABI encoded. diff --git a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs index 09980ad331..b1f3c7ad00 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs @@ -585,8 +585,8 @@ mod tests { use assert_matches::assert_matches; use eyre::Result; - use namada_core::address::testing::gen_implicit_address; - use namada_core::address::{gen_established_address, nam, wnam}; + use namada_core::address::gen_established_address; + use namada_core::address::testing::{gen_implicit_address, nam, wnam}; use namada_core::borsh::BorshSerializeExt; use namada_core::eth_bridge_pool::GasFee; use namada_core::ethereum_events::testing::{ diff --git a/crates/ethereum_bridge/src/storage/mod.rs b/crates/ethereum_bridge/src/storage/mod.rs index b4e4470944..3adcd0efb3 100644 --- a/crates/ethereum_bridge/src/storage/mod.rs +++ b/crates/ethereum_bridge/src/storage/mod.rs @@ -69,7 +69,7 @@ pub fn bridge_contract_key() -> Key { #[cfg(test)] mod test { use namada_core::address; - use namada_core::address::nam; + use namada_core::address::testing::nam; use namada_core::ethereum_events::testing::arbitrary_eth_address; use super::*; diff --git a/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs b/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs index 551da0a8ad..a5f31d6c31 100644 --- a/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs +++ b/crates/ethereum_bridge/src/storage/wrapped_erc20s.rs @@ -110,7 +110,8 @@ mod test { use std::str::FromStr; use assert_matches::assert_matches; - use namada_core::address::{nam, Address}; + use namada_core::address::testing::nam; + use namada_core::address::Address; use namada_core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; use namada_core::storage::DbKeySeg; diff --git a/crates/ethereum_bridge/src/test_utils.rs b/crates/ethereum_bridge/src/test_utils.rs index f823cc7f47..e6ab489c41 100644 --- a/crates/ethereum_bridge/src/test_utils.rs +++ b/crates/ethereum_bridge/src/test_utils.rs @@ -4,7 +4,8 @@ use std::collections::HashMap; use std::num::NonZeroU64; use namada_account::protocol_pk_key; -use namada_core::address::{self, wnam, Address}; +use namada_core::address::testing::wnam; +use namada_core::address::{self, Address}; use namada_core::dec::Dec; use namada_core::ethereum_events::EthAddress; use namada_core::keccak::KeccakHash; diff --git a/crates/merkle_tree/Cargo.toml b/crates/merkle_tree/Cargo.toml index 329389a0d8..4fc284deb9 100644 --- a/crates/merkle_tree/Cargo.toml +++ b/crates/merkle_tree/Cargo.toml @@ -23,6 +23,8 @@ prost.workspace = true thiserror.workspace = true [dev-dependencies] +namada_core = { path = "../core", features = ["testing"] } + assert_matches.workspace = true proptest.workspace = true itertools.workspace = true diff --git a/crates/merkle_tree/src/eth_bridge_pool.rs b/crates/merkle_tree/src/eth_bridge_pool.rs index 32d0f0462c..12f0e9303c 100644 --- a/crates/merkle_tree/src/eth_bridge_pool.rs +++ b/crates/merkle_tree/src/eth_bridge_pool.rs @@ -373,7 +373,8 @@ mod test_bridge_pool_tree { use assert_matches::assert_matches; use itertools::Itertools; - use namada_core::address::{nam, Address}; + use namada_core::address::testing::nam; + use namada_core::address::Address; use namada_core::eth_bridge_pool::{ GasFee, TransferToEthereum, TransferToEthereumKind, }; diff --git a/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs b/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs index 09aef4623d..60e846fb44 100644 --- a/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs +++ b/crates/namada/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs @@ -642,7 +642,6 @@ mod test_bridge_pool_vp { use std::env::temp_dir; use borsh::BorshDeserialize; - use namada_core::address; use namada_core::borsh::BorshSerializeExt; use namada_ethereum_bridge::storage::bridge_pool::get_signed_root_key; use namada_ethereum_bridge::storage::parameters::{ @@ -654,7 +653,8 @@ mod test_bridge_pool_vp { use namada_tx::data::TxType; use super::*; - use crate::address::{nam, wnam, InternalAddress}; + use crate::address::testing::{nam, wnam}; + use crate::address::InternalAddress; use crate::chain::ChainId; use crate::eth_bridge_pool::{GasFee, TransferToEthereum}; use crate::hash::Hash; @@ -917,7 +917,7 @@ mod test_bridge_pool_vp { storage: State::::open( std::path::Path::new(""), ChainId::default(), - address::nam(), + nam(), None, None, namada_sdk::state::merklize_all_keys, diff --git a/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs b/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs index 289769eb88..3f72e60d5c 100644 --- a/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs +++ b/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs @@ -176,8 +176,7 @@ mod tests { use rand::Rng; use super::*; - use crate::address::testing::established_address_1; - use crate::address::{nam, wnam}; + use crate::address::testing::{established_address_1, nam, wnam}; use crate::ethereum_bridge::storage::bridge_pool::BRIDGE_POOL_ADDRESS; use crate::ethereum_bridge::storage::parameters::{ Contracts, EthereumBridgeParams, UpgradeableContract, diff --git a/crates/namada/src/ledger/native_vp/ibc/mod.rs b/crates/namada/src/ledger/native_vp/ibc/mod.rs index db0ed077e1..bf54ed1088 100644 --- a/crates/namada/src/ledger/native_vp/ibc/mod.rs +++ b/crates/namada/src/ledger/native_vp/ibc/mod.rs @@ -328,9 +328,9 @@ mod tests { use super::*; use crate::core::address::testing::{ - established_address_1, established_address_2, + established_address_1, established_address_2, nam, }; - use crate::core::address::{nam, InternalAddress}; + use crate::core::address::InternalAddress; use crate::core::storage::Epoch; use crate::ibc::apps::transfer::types::events::{ AckEvent, DenomTraceEvent, RecvEvent, TimeoutEvent, TransferEvent, diff --git a/crates/namada/src/ledger/native_vp/multitoken.rs b/crates/namada/src/ledger/native_vp/multitoken.rs index 4a4cdeadf8..9e3783a17a 100644 --- a/crates/namada/src/ledger/native_vp/multitoken.rs +++ b/crates/namada/src/ledger/native_vp/multitoken.rs @@ -224,9 +224,8 @@ mod tests { use super::*; use crate::address::{Address, InternalAddress}; - use crate::core::address::nam; use crate::core::address::testing::{ - established_address_1, established_address_2, + established_address_1, established_address_2, nam, }; use crate::key::testing::keypair_1; use crate::ledger::gas::VpGasMeter; diff --git a/crates/sdk/src/eth_bridge/bridge_pool.rs b/crates/sdk/src/eth_bridge/bridge_pool.rs index 8189953dfb..e15ce4a674 100644 --- a/crates/sdk/src/eth_bridge/bridge_pool.rs +++ b/crates/sdk/src/eth_bridge/bridge_pool.rs @@ -1213,7 +1213,7 @@ mod recommendations { #[cfg(test)] mod test_recommendations { - use namada_core::address::Address; + use namada_core::address; use super::*; use crate::io::StdIo; @@ -1236,7 +1236,7 @@ mod recommendations { amount: Default::default(), }, gas_fee: GasFee { - token: namada_core::address::nam(), + token: address::testing::nam(), amount: gas_amount.into(), payer: bertha_address(), }, @@ -1279,7 +1279,7 @@ mod recommendations { /// Add ETH to a conversion table. fn add_eth_to_conversion_table(&mut self) { self.conversion_table.insert( - namada_core::address::eth(), + address::testing::eth(), args::BpConversionTableEntry { alias: "ETH".into(), conversion_rate: 1e9, // 1 ETH = 1e9 GWEI @@ -1304,7 +1304,7 @@ mod recommendations { amount: Default::default(), }, gas_fee: GasFee { - token: namada_core::address::eth(), + token: address::testing::eth(), amount: 1_000_000_000_u64.into(), // 1 GWEI payer: bertha_address(), }, @@ -1537,14 +1537,14 @@ mod recommendations { let conversion_table = { let mut t = HashMap::new(); t.insert( - namada_core::address::apfel(), + address::testing::apfel(), args::BpConversionTableEntry { alias: APFEL.into(), conversion_rate: APF_RATE, }, ); t.insert( - namada_core::address::schnitzel(), + address::testing::schnitzel(), args::BpConversionTableEntry { alias: SCHNITZEL.into(), conversion_rate: SCH_RATE, @@ -1559,13 +1559,13 @@ mod recommendations { let transfer_paid_in_apfel = { let mut pending = ctx.pending.clone(); pending.transfer.amount = 1.into(); - pending.gas_fee.token = namada_core::address::apfel(); + pending.gas_fee.token = address::testing::apfel(); pending }; let transfer_paid_in_schnitzel = { let mut pending = ctx.pending.clone(); pending.transfer.amount = 2.into(); - pending.gas_fee.token = namada_core::address::schnitzel(); + pending.gas_fee.token = address::testing::schnitzel(); pending }; // add the transfers to the pool, and expect them to diff --git a/crates/sdk/src/queries/shell/eth_bridge.rs b/crates/sdk/src/queries/shell/eth_bridge.rs index 913155d5b2..0962f08d3b 100644 --- a/crates/sdk/src/queries/shell/eth_bridge.rs +++ b/crates/sdk/src/queries/shell/eth_bridge.rs @@ -834,8 +834,7 @@ mod test_ethbridge_router { use std::collections::BTreeMap; use assert_matches::assert_matches; - use namada_core::address::nam; - use namada_core::address::testing::established_address_1; + use namada_core::address::testing::{established_address_1, nam}; use namada_core::eth_abi::Encode; use namada_core::eth_bridge_pool::{ GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, diff --git a/crates/shielded_token/src/conversion.rs b/crates/shielded_token/src/conversion.rs index d247b65026..c71205bb6f 100644 --- a/crates/shielded_token/src/conversion.rs +++ b/crates/shielded_token/src/conversion.rs @@ -631,13 +631,13 @@ mod tests { pub fn tokens() -> HashMap { vec![ - (address::nam(), ("nam", 6.into())), - (address::btc(), ("btc", 8.into())), - (address::eth(), ("eth", 18.into())), - (address::dot(), ("dot", 10.into())), - (address::schnitzel(), ("schnitzel", 6.into())), - (address::apfel(), ("apfel", 6.into())), - (address::kartoffel(), ("kartoffel", 6.into())), + (address::testing::nam(), ("nam", 6.into())), + (address::testing::btc(), ("btc", 8.into())), + (address::testing::eth(), ("eth", 18.into())), + (address::testing::dot(), ("dot", 10.into())), + (address::testing::schnitzel(), ("schnitzel", 6.into())), + (address::testing::apfel(), ("apfel", 6.into())), + (address::testing::kartoffel(), ("kartoffel", 6.into())), ] .into_iter() .collect() diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index f111212c5e..f27d8fbeb0 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -1145,7 +1145,7 @@ pub mod testing { conversion_state: ConversionState::default(), tx_queue: TxQueue::default(), expired_txs_queue: ExpiredTxsQueue::default(), - native_token: address::nam(), + native_token: address::testing::nam(), ethereum_height: None, eth_events_queue: EthEventsQueue::default(), storage_read_past_height_limit: Some(1000), diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 9b8e478d93..e39bb485a2 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -324,7 +324,7 @@ pub mod testing { height: BlockHeight::first(), epoch: Epoch::default(), pred_epochs: Epochs::default(), - native_token: address::nam(), + native_token: address::testing::nam(), conversion_state: ConversionState::default(), merkle_tree_key_filter: merklize_all_keys, } diff --git a/crates/tests/src/native_vp/eth_bridge_pool.rs b/crates/tests/src/native_vp/eth_bridge_pool.rs index 18d707cf66..93b5ea35ed 100644 --- a/crates/tests/src/native_vp/eth_bridge_pool.rs +++ b/crates/tests/src/native_vp/eth_bridge_pool.rs @@ -4,7 +4,7 @@ mod test_bridge_pool_vp { use borsh::BorshDeserialize; use borsh_ext::BorshSerializeExt; - use namada::core::address::{nam, wnam}; + use namada::core::address::testing::{nam, wnam}; use namada::core::chain::ChainId; use namada::core::eth_bridge_pool::{ GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, diff --git a/crates/trans_token/src/storage.rs b/crates/trans_token/src/storage.rs index 2e38e97fa4..ca429b7f5b 100644 --- a/crates/trans_token/src/storage.rs +++ b/crates/trans_token/src/storage.rs @@ -237,7 +237,7 @@ mod testing { #[test] fn test_burn_native_tokens() { let mut storage = TestStorage::default(); - let native_token = address::nam(); + let native_token = address::testing::nam(); // Get some addresses let addr1 = address::testing::gen_implicit_address(); diff --git a/crates/tx/src/data/mod.rs b/crates/tx/src/data/mod.rs index 61b10896ab..e187bdd9fb 100644 --- a/crates/tx/src/data/mod.rs +++ b/crates/tx/src/data/mod.rs @@ -341,7 +341,7 @@ impl TxSentinel { #[cfg(test)] mod test_process_tx { use assert_matches::assert_matches; - use namada_core::address::nam; + use namada_core::address::testing::nam; use namada_core::key::*; use namada_core::storage::Epoch; use namada_core::token::{Amount, DenominatedAmount}; diff --git a/wasm/wasm_source/src/vp_implicit.rs b/wasm/wasm_source/src/vp_implicit.rs index c8fdf07455..0f47ddbb19 100644 --- a/wasm/wasm_source/src/vp_implicit.rs +++ b/wasm/wasm_source/src/vp_implicit.rs @@ -433,7 +433,7 @@ mod tests { let public_key = secret_key.ref_to(); let vp_owner: Address = (&public_key).into(); let source = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); // Spawn the accounts to be able to modify their storage tx_env.spawn_accounts([&vp_owner, &source, &token]); @@ -517,7 +517,7 @@ mod tests { let public_key = secret_key.ref_to(); let vp_owner: Address = (&public_key).into(); let target = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); let bond_amount = token::Amount::from_uint(5_098_123, 0).unwrap(); let unbond_amount = token::Amount::from_uint(3_098_123, 0).unwrap(); @@ -601,7 +601,7 @@ mod tests { let public_key = secret_key.ref_to(); let vp_owner: Address = (&public_key).into(); let target = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); let bond_amount = token::Amount::from_uint(5_098_123, 0).unwrap(); let unbond_amount = token::Amount::from_uint(3_098_123, 0).unwrap(); @@ -666,7 +666,7 @@ mod tests { let public_key = secret_key.ref_to(); let vp_owner: Address = (&public_key).into(); let target = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); // Spawn the accounts to be able to modify their storage @@ -725,7 +725,7 @@ mod tests { let public_key = secret_key.ref_to(); let vp_owner: Address = (&public_key).into(); let target = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); tx_env.init_parameters(None, None, None, None); @@ -798,7 +798,7 @@ mod tests { let vp_owner: Address = (&public_key).into(); let source = address::testing::established_address_2(); let target = address::testing::established_address_3(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); // Spawn the accounts to be able to modify their storage diff --git a/wasm/wasm_source/src/vp_user.rs b/wasm/wasm_source/src/vp_user.rs index fef53b4304..ddaf25caee 100644 --- a/wasm/wasm_source/src/vp_user.rs +++ b/wasm/wasm_source/src/vp_user.rs @@ -377,7 +377,7 @@ mod tests { let vp_owner = address::testing::established_address_1(); let source = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); // Spawn the accounts to be able to modify their storage @@ -432,7 +432,7 @@ mod tests { let vp_owner = address::testing::established_address_1(); let target = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); // Spawn the accounts to be able to modify their storage @@ -489,7 +489,7 @@ mod tests { let keypair = key::testing::keypair_1(); let public_key = keypair.ref_to(); let target = address::testing::established_address_2(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); // Spawn the accounts to be able to modify their storage @@ -584,7 +584,7 @@ mod tests { let public_key = secret_key.ref_to(); let vp_owner: Address = address::testing::established_address_2(); let target = address::testing::established_address_3(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); let bond_amount = token::Amount::from_uint(5_098_123, 0).unwrap(); let unbond_amount = token::Amount::from_uint(3_098_123, 0).unwrap(); @@ -748,7 +748,7 @@ mod tests { let secret_key = key::testing::keypair_1(); let public_key = secret_key.ref_to(); let target = address::testing::established_address_3(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); let bond_amount = token::Amount::from_uint(5_098_123, 0).unwrap(); let unbond_amount = token::Amount::from_uint(3_098_123, 0).unwrap(); @@ -844,7 +844,7 @@ mod tests { let public_key = secret_key.ref_to(); let vp_owner: Address = address::testing::established_address_2(); let target = address::testing::established_address_3(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); let bond_amount = token::Amount::from_uint(5_098_123, 0).unwrap(); let unbond_amount = token::Amount::from_uint(3_098_123, 0).unwrap(); @@ -1033,7 +1033,7 @@ mod tests { let secret_key = key::testing::keypair_1(); let public_key = secret_key.ref_to(); let target = address::testing::established_address_3(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); let bond_amount = token::Amount::from_uint(5_098_123, 0).unwrap(); let unbond_amount = token::Amount::from_uint(3_098_123, 0).unwrap(); @@ -1109,7 +1109,7 @@ mod tests { let vp_owner = address::testing::established_address_1(); let source = address::testing::established_address_2(); let target = address::testing::established_address_3(); - let token = address::nam(); + let token = address::testing::nam(); let amount = token::Amount::from_uint(10_098_123, 0).unwrap(); // Spawn the accounts to be able to modify their storage From d44bf1e2c242e076ca96e23c1e27dfba663c12b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Fri, 2 Feb 2024 10:36:30 +0000 Subject: [PATCH 19/19] changelog: add #2507 --- .../unreleased/improvements/2507-refactor-testing-addrs.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/2507-refactor-testing-addrs.md diff --git a/.changelog/unreleased/improvements/2507-refactor-testing-addrs.md b/.changelog/unreleased/improvements/2507-refactor-testing-addrs.md new file mode 100644 index 0000000000..a52905d84f --- /dev/null +++ b/.changelog/unreleased/improvements/2507-refactor-testing-addrs.md @@ -0,0 +1,2 @@ +- Hid addresses used for testing from public API. + ([\#2507](https://github.com/anoma/namada/pull/2507)) \ No newline at end of file