From d0700744f43f6862e72276880794646955dc33ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 2 Jul 2024 12:28:20 +0100 Subject: [PATCH 1/4] add namada_systems crate with systems' abstract interfaces --- Cargo.lock | 8 +++ Cargo.toml | 1 + crates/core/src/ibc.rs | 38 +---------- crates/core/src/lib.rs | 2 - crates/core/src/parameters.rs | 35 ---------- crates/core/src/token.rs | 61 ----------------- crates/systems/Cargo.toml | 17 +++++ crates/systems/src/ethereum_bridge.rs | 1 + crates/{core => systems}/src/governance.rs | 0 crates/systems/src/ibc.rs | 39 +++++++++++ crates/systems/src/lib.rs | 27 ++++++++ crates/systems/src/parameters.rs | 38 +++++++++++ crates/systems/src/pgf.rs | 1 + .../{core => systems}/src/proof_of_stake.rs | 4 +- crates/systems/src/shielded_token.rs | 1 + crates/systems/src/trans_token.rs | 65 +++++++++++++++++++ 16 files changed, 201 insertions(+), 137 deletions(-) create mode 100644 crates/systems/Cargo.toml create mode 100644 crates/systems/src/ethereum_bridge.rs rename crates/{core => systems}/src/governance.rs (100%) create mode 100644 crates/systems/src/ibc.rs create mode 100644 crates/systems/src/lib.rs create mode 100644 crates/systems/src/parameters.rs create mode 100644 crates/systems/src/pgf.rs rename crates/{core => systems}/src/proof_of_stake.rs (91%) create mode 100644 crates/systems/src/shielded_token.rs create mode 100644 crates/systems/src/trans_token.rs diff --git a/Cargo.lock b/Cargo.lock index 84887c1eaa..a6218fd5a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5146,6 +5146,14 @@ dependencies = [ "tracing", ] +[[package]] +name = "namada_systems" +version = "0.41.0" +dependencies = [ + "namada_core", + "namada_storage", +] + [[package]] name = "namada_test_utils" version = "0.41.0" diff --git a/Cargo.toml b/Cargo.toml index 9ebfa971e1..dc7269cfc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ members = [ "crates/shielded_token", "crates/state", "crates/storage", + "crates/systems", "crates/test_utils", "crates/tests", "crates/token", diff --git a/crates/core/src/ibc.rs b/crates/core/src/ibc.rs index e6ab24da1d..4f0f62ecaa 100644 --- a/crates/core/src/ibc.rs +++ b/crates/core/src/ibc.rs @@ -1,54 +1,18 @@ //! IBC-related data types -use std::collections::{BTreeMap, BTreeSet}; use std::fmt::Display; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use data_encoding::{DecodePartial, HEXLOWER, HEXLOWER_PERMISSIVE}; pub use ibc::*; -use masp_primitives::transaction::components::ValueSum; -use masp_primitives::transaction::TransparentAddress; use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; use serde::{Deserialize, Serialize}; use super::address::HASH_LEN; -use crate::address::Address; use crate::hash::Hash; -use crate::masp::TAddrData; -use crate::{storage, token}; - -/// Abstract IBC storage read interface -pub trait Read { - /// Storage error - type Err; - - /// Extract MASP transaction from IBC envelope - fn try_extract_masp_tx_from_envelope( - tx_data: &[u8], - ) -> Result, Self::Err>; - - /// Apply relevant IBC packets to the changed balances structure - fn apply_ibc_packet( - storage: &S, - tx_data: &[u8], - acc: ChangedBalances, - keys_changed: &BTreeSet, - ) -> Result; -} - -/// Balances changed by a transaction -#[derive(Default, Debug, Clone)] -pub struct ChangedBalances { - /// Map between MASP transparent address and namada types - pub decoder: BTreeMap, - /// Balances before the tx - pub pre: BTreeMap>, - /// Balances after the tx - pub post: BTreeMap>, -} /// IBC token hash derived from a denomination. #[derive( @@ -69,7 +33,7 @@ pub struct ChangedBalances { #[repr(transparent)] pub struct IbcTokenHash(pub [u8; HASH_LEN]); -impl std::fmt::Display for IbcTokenHash { +impl Display for IbcTokenHash { #[inline(always)] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", HEXLOWER.encode(&self.0)) diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 200b6971cf..058fa07f7b 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -21,9 +21,7 @@ pub mod arith; pub mod bytes; #[cfg(any(test, feature = "control_flow"))] pub mod control_flow; -pub mod governance; pub mod hints; -pub mod proof_of_stake; // TODO(namada#3248): only re-export v037 `tendermint-rs` pub use {masp_primitives, tendermint, tendermint_proto}; diff --git a/crates/core/src/parameters.rs b/crates/core/src/parameters.rs index db013266d2..41a03f3991 100644 --- a/crates/core/src/parameters.rs +++ b/crates/core/src/parameters.rs @@ -12,41 +12,6 @@ use super::hash::Hash; use super::time::DurationSecs; use super::token; use crate::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use crate::storage; - -/// Abstract parameters storage keys interface -pub trait Keys { - /// Key for implicit VP - fn implicit_vp_key() -> storage::Key; -} - -/// Abstract parameters storage read interface -pub trait Read { - /// Storage error - type Err; - - /// Read all parameters - fn read(storage: &S) -> Result; - - /// Read MASP epoch multiplier - fn masp_epoch_multiplier(storage: &S) -> Result; - - /// Read the the epoch duration parameter from store - fn epoch_duration_parameter( - storage: &S, - ) -> Result; - - /// Helper function to retrieve the `is_native_token_transferable` protocol - /// parameter from storage - fn is_native_token_transferable(storage: &S) -> Result; -} - -/// Abstract parameters storage write interface -pub trait Write: Read { - /// Write all parameters - fn write(storage: &mut S, parameters: &Parameters) - -> Result<(), Self::Err>; -} /// Protocol parameters #[derive( diff --git a/crates/core/src/token.rs b/crates/core/src/token.rs index d27e44f08d..70cdeff7dc 100644 --- a/crates/core/src/token.rs +++ b/crates/core/src/token.rs @@ -14,73 +14,12 @@ use namada_migrations::*; use serde::{Deserialize, Serialize}; use thiserror::Error; -use crate::address::Address; use crate::arith::{self, checked, CheckedAdd, CheckedSub}; use crate::dec::{Dec, POS_DECIMAL_PRECISION}; use crate::storage; use crate::storage::{DbKeySeg, KeySeg}; use crate::uint::{self, Uint, I256}; -/// Abstract token keys interface -pub trait Keys { - /// Key for transparent token balance - fn balance_key(token: &Address, owner: &Address) -> storage::Key; - - /// Returns the owner address if the given storage key is a balance key for - /// the given token. - fn is_balance_key<'a>( - token_addr: &Address, - key: &'a storage::Key, - ) -> Option<&'a Address>; - - /// Check if the given storage key is a balance key for an unspecified - /// token. If it is, return the token and owner address. - fn is_any_token_balance_key(key: &storage::Key) -> Option<[&Address; 2]>; - - /// Obtain a storage key for the multitoken minter. - fn minter_key(token_addr: &Address) -> storage::Key; -} - -/// Abstract token storage read interface -pub trait Read { - /// Storage error - type Err; -} - -/// Abstract token storage write interface -pub trait Write: Read { - /// Transfer `token` from `src` to `dest`. Returns an `Err` if `src` has - /// insufficient balance or if the transfer the `dest` would overflow (This - /// can only happen if the total supply doesn't fit in `token::Amount`). - fn transfer( - storage: &mut S, - token: &Address, - src: &Address, - dest: &Address, - amount: Amount, - ) -> Result<(), Self::Err>; - - /// Burn a specified amount of tokens from some address. If the burn amount - /// is larger than the total balance of the given address, then the - /// remaining balance is burned. The total supply of the token is - /// properly adjusted. - fn burn_tokens( - storage: &mut S, - token: &Address, - source: &Address, - amount: Amount, - ) -> Result<(), Self::Err>; - - /// Credit tokens to an account, to be used only by protocol. In - /// transactions, this would get rejected by the default `vp_token`. - fn credit_tokens( - storage: &mut S, - token: &Address, - dest: &Address, - amount: Amount, - ) -> Result<(), Self::Err>; -} - /// Amount in micro units. For different granularity another representation /// might be more appropriate. #[derive( diff --git a/crates/systems/Cargo.toml b/crates/systems/Cargo.toml new file mode 100644 index 0000000000..de36aa7d86 --- /dev/null +++ b/crates/systems/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "namada_systems" +description = "Namada systems abstract interfaces" +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" } +namada_storage = { path = "../storage" } diff --git a/crates/systems/src/ethereum_bridge.rs b/crates/systems/src/ethereum_bridge.rs new file mode 100644 index 0000000000..250acbde8d --- /dev/null +++ b/crates/systems/src/ethereum_bridge.rs @@ -0,0 +1 @@ +//! Ethereum bridge abstract interfaces diff --git a/crates/core/src/governance.rs b/crates/systems/src/governance.rs similarity index 100% rename from crates/core/src/governance.rs rename to crates/systems/src/governance.rs diff --git a/crates/systems/src/ibc.rs b/crates/systems/src/ibc.rs new file mode 100644 index 0000000000..f10ec8c49f --- /dev/null +++ b/crates/systems/src/ibc.rs @@ -0,0 +1,39 @@ +//! IBC abstract interfaces + +use std::collections::{BTreeMap, BTreeSet}; + +use masp_primitives::transaction::components::ValueSum; +use masp_primitives::transaction::TransparentAddress; +use namada_core::address::Address; +use namada_core::masp::TAddrData; +use namada_core::{masp_primitives, storage, token}; + +/// Abstract IBC storage read interface +pub trait Read { + /// Storage error + type Err; + + /// Extract MASP transaction from IBC envelope + fn try_extract_masp_tx_from_envelope( + tx_data: &[u8], + ) -> Result, Self::Err>; + + /// Apply relevant IBC packets to the changed balances structure + fn apply_ibc_packet( + storage: &S, + tx_data: &[u8], + acc: ChangedBalances, + keys_changed: &BTreeSet, + ) -> Result; +} + +/// Balances changed by a transaction +#[derive(Default, Debug, Clone)] +pub struct ChangedBalances { + /// Map between MASP transparent address and namada types + pub decoder: BTreeMap, + /// Balances before the tx + pub pre: BTreeMap>, + /// Balances after the tx + pub post: BTreeMap>, +} diff --git a/crates/systems/src/lib.rs b/crates/systems/src/lib.rs new file mode 100644 index 0000000000..7874403d6a --- /dev/null +++ b/crates/systems/src/lib.rs @@ -0,0 +1,27 @@ +//! Abstract interfaces for interacting with Namada systems. + +#![doc(html_favicon_url = "https://dev.namada.net/master/favicon.png")] +#![doc(html_logo_url = "https://dev.namada.net/master/rustdoc-logo.png")] +#![deny(rustdoc::broken_intra_doc_links)] +#![deny(rustdoc::private_intra_doc_links)] +#![warn( + missing_docs, + rust_2018_idioms, + clippy::cast_sign_loss, + clippy::cast_possible_truncation, + clippy::cast_possible_wrap, + clippy::cast_lossless, + clippy::arithmetic_side_effects, + clippy::dbg_macro, + clippy::print_stdout, + clippy::print_stderr +)] + +pub mod ethereum_bridge; +pub mod governance; +pub mod ibc; +pub mod parameters; +pub mod pgf; +pub mod proof_of_stake; +pub mod shielded_token; +pub mod trans_token; diff --git a/crates/systems/src/parameters.rs b/crates/systems/src/parameters.rs new file mode 100644 index 0000000000..c6e89a3e30 --- /dev/null +++ b/crates/systems/src/parameters.rs @@ -0,0 +1,38 @@ +//! Parameters abstract interfaces + +pub use namada_core::parameters::*; +use namada_core::storage; + +/// Abstract parameters storage keys interface +pub trait Keys { + /// Key for implicit VP + fn implicit_vp_key() -> storage::Key; +} + +/// Abstract parameters storage read interface +pub trait Read { + /// Storage error + type Err; + + /// Read all parameters + fn read(storage: &S) -> Result; + + /// Read MASP epoch multiplier + fn masp_epoch_multiplier(storage: &S) -> Result; + + /// Read the the epoch duration parameter from store + fn epoch_duration_parameter( + storage: &S, + ) -> Result; + + /// Helper function to retrieve the `is_native_token_transferable` protocol + /// parameter from storage + fn is_native_token_transferable(storage: &S) -> Result; +} + +/// Abstract parameters storage write interface +pub trait Write: Read { + /// Write all parameters + fn write(storage: &mut S, parameters: &Parameters) + -> Result<(), Self::Err>; +} diff --git a/crates/systems/src/pgf.rs b/crates/systems/src/pgf.rs new file mode 100644 index 0000000000..13cf6f31cf --- /dev/null +++ b/crates/systems/src/pgf.rs @@ -0,0 +1 @@ +//! PGF abstract interfaces diff --git a/crates/core/src/proof_of_stake.rs b/crates/systems/src/proof_of_stake.rs similarity index 91% rename from crates/core/src/proof_of_stake.rs rename to crates/systems/src/proof_of_stake.rs index f2a73c4fda..12e7af1f13 100644 --- a/crates/core/src/proof_of_stake.rs +++ b/crates/systems/src/proof_of_stake.rs @@ -1,7 +1,7 @@ //! Proof-of-Stake abstract interfaces -use crate::address::Address; -use crate::storage; +use namada_core::address::Address; +use namada_core::storage; /// Abstract PoS storage read interface pub trait Read { diff --git a/crates/systems/src/shielded_token.rs b/crates/systems/src/shielded_token.rs new file mode 100644 index 0000000000..27f7e3fa92 --- /dev/null +++ b/crates/systems/src/shielded_token.rs @@ -0,0 +1 @@ +//! Shielded token abstract interfaces diff --git a/crates/systems/src/trans_token.rs b/crates/systems/src/trans_token.rs new file mode 100644 index 0000000000..6eac8a1976 --- /dev/null +++ b/crates/systems/src/trans_token.rs @@ -0,0 +1,65 @@ +//! Transparent token abstract interfaces + +use namada_core::address::Address; +use namada_core::storage; +pub use namada_core::token::*; + +/// Abstract token keys interface +pub trait Keys { + /// Key for transparent token balance + fn balance_key(token: &Address, owner: &Address) -> storage::Key; + + /// Returns the owner address if the given storage key is a balance key for + /// the given token. + fn is_balance_key<'a>( + token_addr: &Address, + key: &'a storage::Key, + ) -> Option<&'a Address>; + + /// Check if the given storage key is a balance key for an unspecified + /// token. If it is, return the token and owner address. + fn is_any_token_balance_key(key: &storage::Key) -> Option<[&Address; 2]>; + + /// Obtain a storage key for the multitoken minter. + fn minter_key(token_addr: &Address) -> storage::Key; +} + +/// Abstract token storage read interface +pub trait Read { + /// Storage error + type Err; +} + +/// Abstract token storage write interface +pub trait Write: Read { + /// Transfer `token` from `src` to `dest`. Returns an `Err` if `src` has + /// insufficient balance or if the transfer the `dest` would overflow (This + /// can only happen if the total supply doesn't fit in `token::Amount`). + fn transfer( + storage: &mut S, + token: &Address, + src: &Address, + dest: &Address, + amount: Amount, + ) -> Result<(), Self::Err>; + + /// Burn a specified amount of tokens from some address. If the burn amount + /// is larger than the total balance of the given address, then the + /// remaining balance is burned. The total supply of the token is + /// properly adjusted. + fn burn_tokens( + storage: &mut S, + token: &Address, + source: &Address, + amount: Amount, + ) -> Result<(), Self::Err>; + + /// Credit tokens to an account, to be used only by protocol. In + /// transactions, this would get rejected by the default `vp_token`. + fn credit_tokens( + storage: &mut S, + token: &Address, + dest: &Address, + amount: Amount, + ) -> Result<(), Self::Err>; +} From 7992a2e45dede45f55d15f63c47a5266365855b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 2 Jul 2024 12:44:25 +0100 Subject: [PATCH 2/4] update systems crates to use namada_systems --- Cargo.lock | 8 ++++++++ crates/ethereum_bridge/Cargo.toml | 1 + crates/ethereum_bridge/src/vp/bridge_pool_vp.rs | 2 +- crates/ethereum_bridge/src/vp/eth_bridge_vp.rs | 2 +- crates/ethereum_bridge/src/vp/nut_vp.rs | 2 +- crates/governance/Cargo.toml | 1 + crates/governance/src/lib.rs | 3 ++- crates/governance/src/vp/mod.rs | 3 ++- crates/ibc/Cargo.toml | 1 + crates/ibc/src/lib.rs | 3 ++- crates/ibc/src/vp/context.rs | 2 +- crates/ibc/src/vp/mod.rs | 4 ++-- crates/parameters/Cargo.toml | 1 + crates/parameters/src/lib.rs | 2 +- crates/parameters/src/vp.rs | 2 +- crates/proof_of_stake/Cargo.toml | 1 + crates/proof_of_stake/src/lib.rs | 3 ++- crates/proof_of_stake/src/vp.rs | 2 +- crates/shielded_token/Cargo.toml | 1 + crates/shielded_token/src/vp.rs | 5 ++--- crates/state/Cargo.toml | 1 + crates/state/src/lib.rs | 2 +- crates/trans_token/Cargo.toml | 1 + crates/trans_token/src/lib.rs | 6 +++--- crates/trans_token/src/vp.rs | 2 +- wasm/Cargo.lock | 16 ++++++++++++++++ wasm_for_tests/Cargo.lock | 16 ++++++++++++++++ 27 files changed, 72 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a6218fd5a5..598fd20d09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4680,6 +4680,7 @@ dependencies = [ "namada_proof_of_stake", "namada_state", "namada_storage", + "namada_systems", "namada_token", "namada_trans_token", "namada_tx", @@ -4764,6 +4765,7 @@ dependencies = [ "namada_parameters", "namada_proof_of_stake", "namada_state", + "namada_systems", "namada_token", "namada_trans_token", "namada_tx", @@ -4801,6 +4803,7 @@ dependencies = [ "namada_proof_of_stake", "namada_state", "namada_storage", + "namada_systems", "namada_token", "namada_tx", "namada_vm", @@ -4944,6 +4947,7 @@ dependencies = [ "namada_macros", "namada_state", "namada_storage", + "namada_systems", "namada_tx", "namada_vp", "smooth-operator", @@ -4970,6 +4974,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -5083,6 +5088,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -5117,6 +5123,7 @@ dependencies = [ "namada_parameters", "namada_replay_protection", "namada_storage", + "namada_systems", "namada_tx", "patricia_tree", "pretty_assertions", @@ -5244,6 +5251,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_tx", "namada_vm", "namada_vp", diff --git a/crates/ethereum_bridge/Cargo.toml b/crates/ethereum_bridge/Cargo.toml index cd2aed558b..49cc6e9c4f 100644 --- a/crates/ethereum_bridge/Cargo.toml +++ b/crates/ethereum_bridge/Cargo.toml @@ -35,6 +35,7 @@ namada_parameters = {path = "../parameters"} namada_proof_of_stake = {path = "../proof_of_stake", default-features = false} namada_state = {path = "../state"} namada_storage = {path = "../storage"} +namada_systems = { path = "../systems" } namada_trans_token = {path = "../trans_token"} namada_tx = {path = "../tx"} namada_vote_ext = {path = "../vote_ext"} diff --git a/crates/ethereum_bridge/src/vp/bridge_pool_vp.rs b/crates/ethereum_bridge/src/vp/bridge_pool_vp.rs index 0687d17aec..2413b635c7 100644 --- a/crates/ethereum_bridge/src/vp/bridge_pool_vp.rs +++ b/crates/ethereum_bridge/src/vp/bridge_pool_vp.rs @@ -26,9 +26,9 @@ use namada_core::eth_bridge_pool::{ use namada_core::ethereum_events::EthAddress; use namada_core::hints; use namada_core::storage::Key; -use namada_core::token::{self, Amount}; use namada_core::uint::I320; use namada_state::{ResultExt, StateRead}; +use namada_systems::trans_token::{self as token, Amount}; use namada_tx::BatchedTxRef; use namada_vp::native_vp::{self, Ctx, NativeVp, StorageReader, VpEvaluator}; diff --git a/crates/ethereum_bridge/src/vp/eth_bridge_vp.rs b/crates/ethereum_bridge/src/vp/eth_bridge_vp.rs index 2a10ec9399..aae9f14bb8 100644 --- a/crates/ethereum_bridge/src/vp/eth_bridge_vp.rs +++ b/crates/ethereum_bridge/src/vp/eth_bridge_vp.rs @@ -7,8 +7,8 @@ use namada_core::address::Address; use namada_core::booleans::BoolResultUnitExt; use namada_core::collections::HashSet; use namada_core::storage::Key; -use namada_core::token::{self, Amount}; use namada_state::StateRead; +use namada_systems::trans_token::{self as token, Amount}; use namada_tx::BatchedTxRef; use namada_vp::native_vp::{self, Ctx, NativeVp, StorageReader, VpEvaluator}; diff --git a/crates/ethereum_bridge/src/vp/nut_vp.rs b/crates/ethereum_bridge/src/vp/nut_vp.rs index 727f9c1c1f..8ac7155f35 100644 --- a/crates/ethereum_bridge/src/vp/nut_vp.rs +++ b/crates/ethereum_bridge/src/vp/nut_vp.rs @@ -6,8 +6,8 @@ use std::marker::PhantomData; use namada_core::address::{Address, InternalAddress}; use namada_core::booleans::BoolResultUnitExt; use namada_core::storage::Key; -use namada_core::token::{self, Amount}; use namada_state::StateRead; +use namada_systems::trans_token::{self as token, Amount}; use namada_tx::BatchedTxRef; use namada_vp::native_vp::{self, Ctx, NativeVp, VpEvaluator}; use namada_vp::VpEnv; diff --git a/crates/governance/Cargo.toml b/crates/governance/Cargo.toml index 2a8c94f592..72cacdd3d0 100644 --- a/crates/governance/Cargo.toml +++ b/crates/governance/Cargo.toml @@ -27,6 +27,7 @@ namada_macros = { path = "../macros" } namada_migrations = { path= "../migrations", optional = true } namada_parameters = { path = "../parameters" } namada_state = { path = "../state" } +namada_systems = { path = "../systems" } namada_trans_token = { path = "../trans_token" } namada_tx = { path = "../tx" } namada_vp = { path = "../vp" } diff --git a/crates/governance/src/lib.rs b/crates/governance/src/lib.rs index e1ef6ebcbc..33d93a5335 100644 --- a/crates/governance/src/lib.rs +++ b/crates/governance/src/lib.rs @@ -35,6 +35,7 @@ pub mod utils; pub mod vp; use namada_state::StorageRead; +pub use namada_systems::governance::*; pub use storage::proposal::{InitProposalData, ProposalType, VoteProposalData}; pub use storage::vote::ProposalVote; pub use storage::{init_proposal, is_proposal_accepted, vote_proposal}; @@ -46,7 +47,7 @@ pub const ADDRESS: Address = address::GOV; #[derive(Debug)] pub struct Store(PhantomData); -impl namada_core::governance::Read for Store +impl Read for Store where S: StorageRead, { diff --git a/crates/governance/src/vp/mod.rs b/crates/governance/src/vp/mod.rs index 5ea32be495..44bef35cde 100644 --- a/crates/governance/src/vp/mod.rs +++ b/crates/governance/src/vp/mod.rs @@ -9,9 +9,10 @@ use std::marker::PhantomData; use borsh::BorshDeserialize; use namada_core::arith::{self, checked}; use namada_core::booleans::{BoolResultUnitExt, ResultBoolExt}; +use namada_core::storage; use namada_core::storage::Epoch; -use namada_core::{proof_of_stake, storage, token}; use namada_state::{StateRead, StorageRead}; +use namada_systems::{proof_of_stake, trans_token as token}; use namada_tx::action::{Action, GovAction, Read}; use namada_tx::BatchedTxRef; use namada_vp::native_vp::{Ctx, CtxPreStorageRead, NativeVp, VpEvaluator}; diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index d79d51ba9c..9beb30b2dc 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -30,6 +30,7 @@ namada_migrations = {path = "../migrations", optional = true} namada_parameters = { path = "../parameters" } namada_state = { path = "../state" } namada_storage = { path = "../storage" } +namada_systems = { path = "../systems" } namada_token = { path = "../token" } namada_tx = { path = "../tx" } namada_vp = { path = "../vp" } diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index 242a5d1c2d..a13902d33d 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -94,6 +94,7 @@ use namada_state::{ DBIter, Key, ResultExt, State, StorageError, StorageHasher, StorageRead, StorageWrite, WlState, DB, }; +use namada_systems::ibc::ChangedBalances; use namada_token::transaction::components::ValueSum; use namada_token::Transfer; pub use nft::*; @@ -212,7 +213,7 @@ impl TryFrom for IbcTransferInfo { #[derive(Debug)] pub struct Store(PhantomData); -impl namada_core::ibc::Read for Store +impl namada_systems::ibc::Read for Store where S: StorageRead, { diff --git a/crates/ibc/src/vp/context.rs b/crates/ibc/src/vp/context.rs index 4b43236a3c..82fc8f1bcd 100644 --- a/crates/ibc/src/vp/context.rs +++ b/crates/ibc/src/vp/context.rs @@ -8,13 +8,13 @@ use namada_core::arith::checked; use namada_core::borsh::BorshSerializeExt; use namada_core::collections::{HashMap, HashSet}; use namada_core::storage::{BlockHeight, Epoch, Epochs, Header, Key, TxIndex}; -use namada_core::token::{self, Amount}; use namada_events::Event; use namada_gas::MEMORY_ACCESS_GAS_PER_BYTE; use namada_state::write_log::StorageModification; use namada_state::{ PrefixIter, StateRead, StorageError, StorageRead, StorageWrite, }; +use namada_systems::trans_token::{self as token, Amount}; use namada_vp::native_vp::{CtxPreStorageRead, VpEvaluator}; use namada_vp::VpEnv; diff --git a/crates/ibc/src/vp/mod.rs b/crates/ibc/src/vp/mod.rs index dddd47b1d9..bb680c9f45 100644 --- a/crates/ibc/src/vp/mod.rs +++ b/crates/ibc/src/vp/mod.rs @@ -16,11 +16,11 @@ use namada_core::address::Address; use namada_core::arith::{self, checked}; use namada_core::collections::HashSet; use namada_core::storage::Key; -use namada_core::token::{self, Amount}; -use namada_core::{governance, parameters, proof_of_stake}; use namada_gas::{IBC_ACTION_EXECUTE_GAS, IBC_ACTION_VALIDATE_GAS}; use namada_state::write_log::StorageModification; use namada_state::{StateRead, StorageError}; +use namada_systems::trans_token::{self as token, Amount}; +use namada_systems::{governance, parameters, proof_of_stake}; use namada_tx::BatchedTxRef; use namada_vp::native_vp::{ self, Ctx, CtxPreStorageRead, NativeVp, VpEvaluator, diff --git a/crates/parameters/Cargo.toml b/crates/parameters/Cargo.toml index 67ffbb957f..5e44fde53d 100644 --- a/crates/parameters/Cargo.toml +++ b/crates/parameters/Cargo.toml @@ -24,6 +24,7 @@ namada_core = { path = "../core" } namada_macros = { path = "../macros" } namada_state = { path = "../state" } namada_storage = { path = "../storage" } +namada_systems = { path = "../systems" } namada_tx = { path = "../tx" } namada_vp = { path = "../vp" } diff --git a/crates/parameters/src/lib.rs b/crates/parameters/src/lib.rs index 8ffe5bb8f9..f5d531fe29 100644 --- a/crates/parameters/src/lib.rs +++ b/crates/parameters/src/lib.rs @@ -26,11 +26,11 @@ use std::marker::PhantomData; use namada_core::address::{Address, InternalAddress}; use namada_core::arith::checked; use namada_core::chain::ProposalBytes; -pub use namada_core::parameters::*; use namada_core::storage::BlockHeight; use namada_core::time::DurationSecs; use namada_core::{hints, token}; use namada_storage::{ResultExt, StorageRead, StorageWrite}; +pub use namada_systems::parameters::*; pub use storage::{get_gas_scale, get_max_block_gas}; use thiserror::Error; pub use wasm_allowlist::{is_tx_allowed, is_vp_allowed}; diff --git a/crates/parameters/src/vp.rs b/crates/parameters/src/vp.rs index 2e3cdaca46..7b5b4e2082 100644 --- a/crates/parameters/src/vp.rs +++ b/crates/parameters/src/vp.rs @@ -5,9 +5,9 @@ use std::marker::PhantomData; use namada_core::address::Address; use namada_core::booleans::BoolResultUnitExt; -use namada_core::governance; use namada_core::storage::Key; use namada_state::{StateRead, StorageError}; +use namada_systems::governance; use namada_tx::BatchedTxRef; use namada_vp::native_vp::{ self, Ctx, CtxPreStorageRead, NativeVp, VpEvaluator, diff --git a/crates/proof_of_stake/Cargo.toml b/crates/proof_of_stake/Cargo.toml index 72a1da3232..f858812ee9 100644 --- a/crates/proof_of_stake/Cargo.toml +++ b/crates/proof_of_stake/Cargo.toml @@ -31,6 +31,7 @@ namada_macros = { path = "../macros" } namada_migrations = { path = "../migrations", optional = true } namada_state = { path = "../state" } namada_storage = { path = "../storage" } +namada_systems = { path = "../systems" } namada_parameters = { path = "../parameters" } namada_trans_token = { path = "../trans_token" } namada_tx = { path = "../tx" } diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 0717490396..00b2328ea4 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -52,6 +52,7 @@ use namada_core::tendermint::abci::types::Misbehavior; use namada_events::EmitEvents; use namada_storage::collections::lazy_map::{self, Collectable, LazyMap}; use namada_storage::{OptionExt, StorageRead, StorageWrite}; +pub use namada_systems::proof_of_stake::*; pub use namada_trans_token as token; pub use parameters::{OwnedPosParams, PosParams}; pub use pos_queries::PosQueries; @@ -112,7 +113,7 @@ use crate::validator_set_update::{ #[derive(Debug)] pub struct Store(PhantomData); -impl namada_core::proof_of_stake::Read for Store +impl Read for Store where S: StorageRead, { diff --git a/crates/proof_of_stake/src/vp.rs b/crates/proof_of_stake/src/vp.rs index f86d613803..2c82ca8211 100644 --- a/crates/proof_of_stake/src/vp.rs +++ b/crates/proof_of_stake/src/vp.rs @@ -5,9 +5,9 @@ use std::marker::PhantomData; use namada_core::address::Address; use namada_core::booleans::BoolResultUnitExt; -use namada_core::governance; use namada_core::storage::Key; use namada_state::{StateRead, StorageError}; +use namada_systems::governance; use namada_tx::action::{ Action, Bond, ClaimRewards, PosAction, Read, Redelegation, Unbond, Withdraw, }; diff --git a/crates/shielded_token/Cargo.toml b/crates/shielded_token/Cargo.toml index a361bfaa9c..39f3d6aec7 100644 --- a/crates/shielded_token/Cargo.toml +++ b/crates/shielded_token/Cargo.toml @@ -30,6 +30,7 @@ namada_gas = { path = "../gas" } namada_parameters = { path = "../parameters" } namada_state = { path = "../state" } namada_storage = { path = "../storage" } +namada_systems = { path = "../systems" } namada_trans_token = { path = "../trans_token" } namada_tx = { path = "../tx" } namada_vp = { path = "../vp" } diff --git a/crates/shielded_token/src/vp.rs b/crates/shielded_token/src/vp.rs index 39827d1289..9ed5534e31 100644 --- a/crates/shielded_token/src/vp.rs +++ b/crates/shielded_token/src/vp.rs @@ -18,12 +18,12 @@ use namada_core::booleans::BoolResultUnitExt; use namada_core::collections::HashSet; use namada_core::masp::{addr_taddr, encode_asset_type, MaspEpoch, TAddrData}; use namada_core::storage::Key; -use namada_core::token::MaspDigitPos; use namada_core::uint::I320; -use namada_core::{governance, ibc, parameters, token}; use namada_state::{ ConversionState, OptionExt, ResultExt, StateRead, StorageError, }; +use namada_systems::trans_token::{Amount, MaspDigitPos}; +use namada_systems::{governance, ibc, parameters, trans_token as token}; use namada_trans_token::read_denom; use namada_tx::action::Read; use namada_tx::BatchedTxRef; @@ -32,7 +32,6 @@ use namada_vp::native_vp::{ }; use namada_vp::{native_vp, VpEnv}; use thiserror::Error; -use token::Amount; use crate::storage_key::{ is_masp_key, is_masp_nullifier_key, is_masp_token_map_key, diff --git a/crates/state/Cargo.toml b/crates/state/Cargo.toml index 15254e328d..564a0014a6 100644 --- a/crates/state/Cargo.toml +++ b/crates/state/Cargo.toml @@ -36,6 +36,7 @@ namada_merkle_tree = { path = "../merkle_tree" } namada_migrations = { path = "../migrations", optional = true } namada_replay_protection = { path = "../replay_protection" } namada_storage = { path = "../storage" } +namada_systems = { path = "../systems" } namada_tx = { path = "../tx" } borsh.workspace = true diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 9d4aae39ba..e414eba6f3 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -35,7 +35,6 @@ use namada_core::arith::{self, checked}; use namada_core::eth_bridge_pool::is_pending_transfer_key; pub use namada_core::hash::Sha256Hasher; use namada_core::hash::{Error as HashError, Hash}; -use namada_core::parameters; pub use namada_core::storage::{ BlockHash, BlockHeight, BlockResults, Epoch, Epochs, EthEventsQueue, Header, Key, KeySeg, TxIndex, BLOCK_HASH_LENGTH, BLOCK_HEIGHT_LENGTH, @@ -60,6 +59,7 @@ pub use namada_storage::{ Result as StorageResult, ResultExt, StorageHasher, StorageRead, StorageWrite, DB, }; +use namada_systems::parameters; use thiserror::Error; use wl_state::TxWlState; pub use wl_state::{FullAccessState, TempWlState, WlState}; diff --git a/crates/trans_token/Cargo.toml b/crates/trans_token/Cargo.toml index 4e187c6731..6edf89c1a2 100644 --- a/crates/trans_token/Cargo.toml +++ b/crates/trans_token/Cargo.toml @@ -23,6 +23,7 @@ namada_core = { path = "../core" } namada_events = { path = "../events", default-features = false } namada_state = { path = "../state" } namada_storage = { path = "../storage" } +namada_systems = { path = "../systems" } namada_tx = { path = "../tx" } namada_vp = { path = "../vp" } diff --git a/crates/trans_token/src/lib.rs b/crates/trans_token/src/lib.rs index 67115034cb..da7ccb9c52 100644 --- a/crates/trans_token/src/lib.rs +++ b/crates/trans_token/src/lib.rs @@ -25,8 +25,8 @@ pub mod vp; use std::marker::PhantomData; use namada_core::address::Address; -pub use namada_core::token::*; use namada_storage::{StorageRead, StorageWrite}; +pub use namada_systems::trans_token::*; pub use storage::*; /// Transparent token storage `Keys/Read/Write` implementation @@ -59,14 +59,14 @@ impl Keys for Store { } } -impl namada_core::token::Read for Store +impl Read for Store where S: StorageRead, { type Err = namada_storage::Error; } -impl namada_core::token::Write for Store +impl Write for Store where S: StorageWrite + StorageRead, { diff --git a/crates/trans_token/src/vp.rs b/crates/trans_token/src/vp.rs index fc66a64092..da45edff19 100644 --- a/crates/trans_token/src/vp.rs +++ b/crates/trans_token/src/vp.rs @@ -8,9 +8,9 @@ use namada_core::booleans::BoolResultUnitExt; use namada_core::collections::HashMap; use namada_core::storage::{Key, KeySeg}; use namada_core::token::Amount; -use namada_core::{governance, parameters}; use namada_state::{StateRead, StorageError}; use namada_storage::StorageRead; +use namada_systems::{governance, parameters}; use namada_tx::action::{ Action, Bond, ClaimRewards, GovAction, PosAction, Read, Withdraw, }; diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index b67ad5e32f..4610620c1e 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3574,6 +3574,7 @@ dependencies = [ "namada_proof_of_stake", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vote_ext", @@ -3622,6 +3623,7 @@ dependencies = [ "namada_macros", "namada_parameters", "namada_state", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -3653,6 +3655,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_token", "namada_tx", "namada_vp", @@ -3700,6 +3703,7 @@ dependencies = [ "namada_macros", "namada_state", "namada_storage", + "namada_systems", "namada_tx", "namada_vp", "smooth-operator", @@ -3722,6 +3726,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -3824,6 +3829,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -3851,6 +3857,7 @@ dependencies = [ "namada_merkle_tree", "namada_replay_protection", "namada_storage", + "namada_systems", "namada_tx", "patricia_tree", "proptest", @@ -3876,6 +3883,14 @@ dependencies = [ "tracing", ] +[[package]] +name = "namada_systems" +version = "0.41.0" +dependencies = [ + "namada_core", + "namada_storage", +] + [[package]] name = "namada_test_utils" version = "0.41.0" @@ -3939,6 +3954,7 @@ dependencies = [ "namada_events", "namada_state", "namada_storage", + "namada_systems", "namada_tx", "namada_vp", "thiserror", diff --git a/wasm_for_tests/Cargo.lock b/wasm_for_tests/Cargo.lock index 4b03d66267..633d4f6634 100644 --- a/wasm_for_tests/Cargo.lock +++ b/wasm_for_tests/Cargo.lock @@ -3574,6 +3574,7 @@ dependencies = [ "namada_proof_of_stake", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vote_ext", @@ -3622,6 +3623,7 @@ dependencies = [ "namada_macros", "namada_parameters", "namada_state", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -3653,6 +3655,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_token", "namada_tx", "namada_vp", @@ -3700,6 +3703,7 @@ dependencies = [ "namada_macros", "namada_state", "namada_storage", + "namada_systems", "namada_tx", "namada_vp", "smooth-operator", @@ -3722,6 +3726,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -3824,6 +3829,7 @@ dependencies = [ "namada_parameters", "namada_state", "namada_storage", + "namada_systems", "namada_trans_token", "namada_tx", "namada_vp", @@ -3851,6 +3857,7 @@ dependencies = [ "namada_merkle_tree", "namada_replay_protection", "namada_storage", + "namada_systems", "namada_tx", "patricia_tree", "proptest", @@ -3876,6 +3883,14 @@ dependencies = [ "tracing", ] +[[package]] +name = "namada_systems" +version = "0.41.0" +dependencies = [ + "namada_core", + "namada_storage", +] + [[package]] name = "namada_test_utils" version = "0.41.0" @@ -3939,6 +3954,7 @@ dependencies = [ "namada_events", "namada_state", "namada_storage", + "namada_systems", "namada_tx", "namada_vp", "thiserror", From 98aa9df4fa80c4af18ddf22ab99ba44c70bb4022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 2 Jul 2024 12:54:53 +0100 Subject: [PATCH 3/4] systems: use the concrete storage error and result type --- crates/governance/src/lib.rs | 7 +- crates/governance/src/vp/mod.rs | 10 +-- crates/ibc/src/lib.rs | 6 +- crates/ibc/src/vp/context.rs | 14 +--- crates/ibc/src/vp/mod.rs | 39 +++------- crates/parameters/src/lib.rs | 17 ++--- crates/parameters/src/vp.rs | 12 +--- crates/proof_of_stake/src/lib.rs | 103 +++++++++++++-------------- crates/proof_of_stake/src/vp.rs | 7 +- crates/shielded_token/src/vp.rs | 34 ++------- crates/systems/src/governance.rs | 10 +-- crates/systems/src/ibc.rs | 8 +-- crates/systems/src/parameters.rs | 17 ++--- crates/systems/src/proof_of_stake.rs | 10 ++- crates/systems/src/trans_token.rs | 12 ++-- crates/token/src/lib.rs | 2 +- crates/trans_token/src/lib.rs | 13 ++-- crates/trans_token/src/vp.rs | 22 ++---- 18 files changed, 115 insertions(+), 228 deletions(-) diff --git a/crates/governance/src/lib.rs b/crates/governance/src/lib.rs index 33d93a5335..293515dc17 100644 --- a/crates/governance/src/lib.rs +++ b/crates/governance/src/lib.rs @@ -51,12 +51,7 @@ impl Read for Store where S: StorageRead, { - type Err = namada_state::StorageError; - - fn is_proposal_accepted( - storage: &S, - tx_data: &[u8], - ) -> Result { + fn is_proposal_accepted(storage: &S, tx_data: &[u8]) -> Result { storage::is_proposal_accepted(storage, tx_data) } } diff --git a/crates/governance/src/vp/mod.rs b/crates/governance/src/vp/mod.rs index 44bef35cde..11016f28c3 100644 --- a/crates/governance/src/vp/mod.rs +++ b/crates/governance/src/vp/mod.rs @@ -66,10 +66,7 @@ where S: StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - PoS: proof_of_stake::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = namada_state::StorageError, - >, + PoS: proof_of_stake::Read>, TokenKeys: token::Keys, { type Error = Error; @@ -220,10 +217,7 @@ where S: StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - PoS: proof_of_stake::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = namada_state::StorageError, - >, + PoS: proof_of_stake::Read>, TokenKeys: token::Keys, { /// Instantiate a Governance VP diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index a13902d33d..a6ba6242ed 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -217,11 +217,9 @@ impl namada_systems::ibc::Read for Store where S: StorageRead, { - type Err = namada_storage::Error; - fn try_extract_masp_tx_from_envelope( tx_data: &[u8], - ) -> Result, Self::Err> + ) -> namada_storage::Result> { let msg = decode_message(tx_data).into_storage_result().ok(); let tx = if let Some(IbcMessage::Envelope(ref envelope)) = msg { @@ -241,7 +239,7 @@ where tx_data: &[u8], mut accum: ChangedBalances, keys_changed: &BTreeSet, - ) -> Result { + ) -> namada_storage::Result { let msg = decode_message(tx_data).into_storage_result().ok(); match msg { None => {} diff --git a/crates/ibc/src/vp/context.rs b/crates/ibc/src/vp/context.rs index 82fc8f1bcd..38e57ff64a 100644 --- a/crates/ibc/src/vp/context.rs +++ b/crates/ibc/src/vp/context.rs @@ -11,6 +11,7 @@ use namada_core::storage::{BlockHeight, Epoch, Epochs, Header, Key, TxIndex}; use namada_events::Event; use namada_gas::MEMORY_ACCESS_GAS_PER_BYTE; use namada_state::write_log::StorageModification; +pub use namada_state::StorageResult as Result; use namada_state::{ PrefixIter, StateRead, StorageError, StorageRead, StorageWrite, }; @@ -22,9 +23,6 @@ use crate::event::IbcEvent; use crate::storage::is_ibc_key; use crate::{IbcCommonContext, IbcStorageContext}; -/// Result of a storage API call. -pub type Result = std::result::Result; - /// Pseudo execution environment context for ibc native vp #[derive(Debug)] pub struct PseudoExecutionContext<'view, 'a, S, CA, EVAL, Token> @@ -214,10 +212,7 @@ where EVAL: 'static + VpEvaluator<'a, S, CA, EVAL>, CA: 'static + Clone, Token: token::Keys - + token::Write< - PseudoExecutionStorage<'view, 'a, S, CA, EVAL>, - Err = StorageError, - >, + + token::Write>, { type Storage = PseudoExecutionStorage<'view, 'a, S, CA, EVAL>; @@ -288,10 +283,7 @@ where CA: 'static + Clone, EVAL: 'static + VpEvaluator<'a, S, CA, EVAL>, Token: token::Keys - + token::Write< - PseudoExecutionStorage<'view, 'a, S, CA, EVAL>, - Err = StorageError, - >, + + token::Write>, { } diff --git a/crates/ibc/src/vp/mod.rs b/crates/ibc/src/vp/mod.rs index bb680c9f45..b15bf5854f 100644 --- a/crates/ibc/src/vp/mod.rs +++ b/crates/ibc/src/vp/mod.rs @@ -18,7 +18,7 @@ use namada_core::collections::HashSet; use namada_core::storage::Key; use namada_gas::{IBC_ACTION_EXECUTE_GAS, IBC_ACTION_VALIDATE_GAS}; use namada_state::write_log::StorageModification; -use namada_state::{StateRead, StorageError}; +use namada_state::StateRead; use namada_systems::trans_token::{self as token, Amount}; use namada_systems::{governance, parameters, proof_of_stake}; use namada_tx::BatchedTxRef; @@ -84,24 +84,13 @@ where S: 'static + StateRead, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL> + Debug, CA: 'static + Clone + Debug, - Gov: governance::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Gov: governance::Read>, Params: parameters::Keys - + parameters::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + + parameters::Read>, Token: token::Keys - + token::Write< - PseudoExecutionStorage<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - > + Debug, - PoS: proof_of_stake::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + + token::Write> + + Debug, + PoS: proof_of_stake::Read>, { type Error = Error; @@ -151,19 +140,11 @@ where EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL> + Debug, CA: 'static + Clone + Debug, Params: parameters::Keys - + parameters::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + + parameters::Read>, Token: token::Keys - + token::Write< - PseudoExecutionStorage<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - > + Debug, - PoS: proof_of_stake::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + + token::Write> + + Debug, + PoS: proof_of_stake::Read>, { /// Instantiate IBC VP pub fn new(ctx: Ctx<'ctx, S, CA, EVAL>) -> Self { diff --git a/crates/parameters/src/lib.rs b/crates/parameters/src/lib.rs index f5d531fe29..588f58af4d 100644 --- a/crates/parameters/src/lib.rs +++ b/crates/parameters/src/lib.rs @@ -49,23 +49,19 @@ impl Read for Store where S: StorageRead, { - type Err = namada_storage::Error; - - fn read(storage: &S) -> Result { + fn read(storage: &S) -> Result { read(storage) } - fn masp_epoch_multiplier(storage: &S) -> Result { + fn masp_epoch_multiplier(storage: &S) -> Result { read_masp_epoch_multiplier_parameter(storage) } - fn epoch_duration_parameter( - storage: &S, - ) -> Result { + fn epoch_duration_parameter(storage: &S) -> Result { read_epoch_duration_parameter(storage) } - fn is_native_token_transferable(storage: &S) -> Result { + fn is_native_token_transferable(storage: &S) -> Result { storage::is_native_token_transferable(storage) } } @@ -74,10 +70,7 @@ impl Write for Store where S: StorageRead + StorageWrite, { - fn write( - storage: &mut S, - parameters: &Parameters, - ) -> Result<(), Self::Err> { + fn write(storage: &mut S, parameters: &Parameters) -> Result<()> { init_storage(parameters, storage) } } diff --git a/crates/parameters/src/vp.rs b/crates/parameters/src/vp.rs index 7b5b4e2082..26b7c5c8e5 100644 --- a/crates/parameters/src/vp.rs +++ b/crates/parameters/src/vp.rs @@ -6,7 +6,7 @@ use std::marker::PhantomData; use namada_core::address::Address; use namada_core::booleans::BoolResultUnitExt; use namada_core::storage::Key; -use namada_state::{StateRead, StorageError}; +use namada_state::StateRead; use namada_systems::governance; use namada_tx::BatchedTxRef; use namada_vp::native_vp::{ @@ -44,10 +44,7 @@ where S: 'static + StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - Gov: governance::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Gov: governance::Read>, { type Error = Error; @@ -92,10 +89,7 @@ where S: 'static + StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - Gov: governance::Read< - CtxPreStorageRead<'ctx, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Gov: governance::Read>, { /// Instantiate parameters VP pub fn new(ctx: Ctx<'ctx, S, CA, EVAL>) -> Self { diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 00b2328ea4..733677583d 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -117,9 +117,7 @@ impl Read for Store where S: StorageRead, { - type Err = namada_storage::Error; - - fn is_validator(storage: &S, address: &Address) -> Result { + fn is_validator(storage: &S, address: &Address) -> Result { is_validator(storage, address) } @@ -127,11 +125,11 @@ where storage: &S, address: &Address, epoch: Option, - ) -> Result { + ) -> Result { is_delegator(storage, address, epoch) } - fn pipeline_len(storage: &S) -> Result { + fn pipeline_len(storage: &S) -> Result { let params = storage::read_owned_pos_params(storage)?; Ok(params.pipeline_len) } @@ -156,7 +154,7 @@ pub fn init_genesis( storage: &mut S, params: &OwnedPosParams, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -182,7 +180,7 @@ pub fn copy_genesis_validator_sets( storage: &mut S, params: &OwnedPosParams, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -201,10 +199,7 @@ where } /// Check if the provided address is a validator address -pub fn is_validator( - storage: &S, - address: &Address, -) -> namada_storage::Result +pub fn is_validator(storage: &S, address: &Address) -> Result where S: StorageRead, { @@ -221,7 +216,7 @@ pub fn is_delegator( storage: &S, address: &Address, epoch: Option, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -266,7 +261,7 @@ pub fn bond_tokens( amount: token::Amount, current_epoch: Epoch, offset_opt: Option, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -373,7 +368,7 @@ where fn compute_total_consensus_stake( storage: &S, epoch: Epoch, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -398,7 +393,7 @@ where pub fn compute_and_store_total_consensus_stake( storage: &mut S, epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -423,7 +418,7 @@ pub fn unbond_tokens( amount: token::Amount, current_epoch: Epoch, is_redelegation: bool, -) -> namada_storage::Result +) -> Result where S: StorageRead + StorageWrite, { @@ -553,7 +548,7 @@ where }; Ok((epoch, value)) }) - .collect::>>()?; + .collect::>>()?; // `updatedBonded` // Remove bonds for all the full unbonds. @@ -860,7 +855,7 @@ fn fold_and_slash_redelegated_bonds( start_epoch: Epoch, list_slashes: &[Slash], slash_epoch_filter: impl Fn(Epoch) -> bool, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -871,7 +866,7 @@ where let validator_slashes: Vec = validator_slashes_handle(src_validator) .iter(storage)? - .collect::>>()?; + .collect::>>()?; // Merge the two lists of slashes let mut merged: Vec = validator_slashes .into_iter() @@ -918,12 +913,12 @@ fn find_bonds_to_remove( storage: &S, bonds_handle: &LazyMap, amount: token::Amount, -) -> namada_storage::Result +) -> Result where S: StorageRead, { #[allow(clippy::needless_collect)] - let bonds: Vec> = bonds_handle.iter(storage)?.collect(); + let bonds: Vec> = bonds_handle.iter(storage)?.collect(); let mut bonds_for_removal = BondsForRemovalRes::default(); let mut remaining = amount; @@ -962,7 +957,7 @@ fn compute_modified_redelegation( redelegated_bonds: &RedelegatedTokens, start_epoch: Epoch, amount_to_unbond: token::Amount, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -1003,7 +998,7 @@ where let (_, amount) = res?; Ok(amount) }) - .collect::>>()? + .collect::>>()? .into_iter(), ) .ok_or_err_msg("token amount overflow")?; @@ -1061,7 +1056,7 @@ fn update_redelegated_bonds( storage: &mut S, redelegated_bonds: &RedelegatedTokens, modified_redelegation: &ModifiedRedelegation, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -1137,7 +1132,7 @@ fn compute_new_redelegated_unbonds( redelegated_bonds: &RedelegatedBondsOrUnbonds, epochs_to_remove: &BTreeSet, modified: &ModifiedRedelegation, -) -> namada_storage::Result +) -> Result where S: StorageRead + StorageWrite, { @@ -1259,7 +1254,7 @@ where Ok((start, rbonds)) } }) - .collect::>()?; + .collect::>()?; Ok(new_redelegated_unbonds) } @@ -1294,7 +1289,7 @@ pub struct BecomeValidator<'a> { pub fn become_validator( storage: &mut S, args: BecomeValidator<'_>, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -1417,7 +1412,7 @@ pub fn change_consensus_key( validator: &Address, consensus_key: &common::PublicKey, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -1455,7 +1450,7 @@ pub fn withdraw_tokens( source: Option<&Address>, validator: &Address, current_epoch: Epoch, -) -> namada_storage::Result +) -> Result where S: StorageRead + StorageWrite, { @@ -1594,7 +1589,7 @@ pub fn change_validator_commission_rate( validator: &Address, new_rate: Dec, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -1655,7 +1650,7 @@ fn bond_amounts_for_query( params: &PosParams, bond_id: &BondId, epoch: Epoch, -) -> namada_storage::Result> +) -> Result> where S: StorageRead, { @@ -1773,7 +1768,7 @@ pub fn raw_bond_amount( storage: &S, bond_id: &BondId, epoch: Epoch, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -1790,7 +1785,7 @@ pub fn bond_amount( storage: &S, bond_id: &BondId, epoch: Epoch, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -1867,7 +1862,7 @@ pub fn bond_amounts_for_rewards( bond_id: &BondId, claim_start: Epoch, claim_end: Epoch, -) -> namada_storage::Result> +) -> Result> where S: StorageRead, { @@ -1972,7 +1967,7 @@ pub fn genesis_validator_set_tendermint( params: &PosParams, current_epoch: Epoch, mut f: impl FnMut(ValidatorSetUpdate) -> T, -) -> namada_storage::Result> +) -> Result> where S: StorageRead, { @@ -2007,7 +2002,7 @@ pub fn unjail_validator( storage: &mut S, validator: &Address, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2075,7 +2070,7 @@ pub fn is_validator_frozen( validator: &Address, current_epoch: Epoch, params: &PosParams, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -2096,7 +2091,7 @@ pub fn get_total_consensus_stake( storage: &S, epoch: Epoch, params: &PosParams, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -2113,7 +2108,7 @@ pub fn redelegate_tokens( dest_validator: &Address, current_epoch: Epoch, amount: token::Amount, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2339,7 +2334,7 @@ pub fn deactivate_validator( storage: &mut S, validator: &Address, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2420,7 +2415,7 @@ pub fn reactivate_validator( storage: &mut S, validator: &Address, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2483,7 +2478,7 @@ where pub fn prune_liveness_data( storage: &mut S, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2520,7 +2515,7 @@ pub fn record_liveness_data( votes_epoch: Epoch, votes_height: BlockHeight, pos_params: &PosParams, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2602,7 +2597,7 @@ pub fn jail_for_liveness( params: &PosParams, current_epoch: Epoch, jail_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2672,7 +2667,7 @@ pub mod test_utils { params: &PosParams, validators: impl Iterator, current_epoch: namada_core::storage::Epoch, - ) -> namada_storage::Result<()> + ) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2735,7 +2730,7 @@ pub mod test_utils { owned: OwnedPosParams, validators: impl Iterator + Clone, current_epoch: namada_core::storage::Epoch, - ) -> namada_storage::Result + ) -> Result where S: StorageRead + StorageWrite, { @@ -2826,7 +2821,7 @@ pub fn change_validator_metadata( name: Option, commission_rate: Option, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -2866,7 +2861,7 @@ pub fn claim_reward_tokens( source: Option<&Address>, validator: &Address, current_epoch: Epoch, -) -> namada_storage::Result +) -> Result where S: StorageRead + StorageWrite, { @@ -2903,7 +2898,7 @@ pub fn query_reward_tokens( source: Option<&Address>, validator: &Address, current_epoch: Epoch, -) -> namada_storage::Result +) -> Result where S: StorageRead, { @@ -2931,7 +2926,7 @@ pub fn jail_validator( validator: &Address, current_epoch: Epoch, validator_set_update_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -3027,7 +3022,7 @@ pub fn finalize_block( validator_set_update_epoch: Epoch, votes: Vec, byzantine_validators: Vec, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageWrite + StorageRead, { @@ -3134,7 +3129,7 @@ fn add_delegation_target( validator: &Address, epoch: Epoch, _current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -3183,7 +3178,7 @@ fn remove_delegation_target( validator: &Address, epoch: Epoch, current_epoch: Epoch, -) -> namada_storage::Result<()> +) -> Result<()> where S: StorageRead + StorageWrite, { @@ -3209,7 +3204,7 @@ fn prune_old_delegations( params: &PosParams, delegations: &mut DelegationEpochs, current_epoch: Epoch, -) -> namada_storage::Result<()> { +) -> Result<()> { let delta = crate::epoched::OffsetMaxProposalPeriodOrSlashProcessingLenPlus::value( params, diff --git a/crates/proof_of_stake/src/vp.rs b/crates/proof_of_stake/src/vp.rs index 2c82ca8211..869f733e18 100644 --- a/crates/proof_of_stake/src/vp.rs +++ b/crates/proof_of_stake/src/vp.rs @@ -6,7 +6,7 @@ use std::marker::PhantomData; use namada_core::address::Address; use namada_core::booleans::BoolResultUnitExt; use namada_core::storage::Key; -use namada_state::{StateRead, StorageError}; +use namada_state::StateRead; use namada_systems::governance; use namada_tx::action::{ Action, Bond, ClaimRewards, PosAction, Read, Redelegation, Unbond, Withdraw, @@ -54,10 +54,7 @@ where S: StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - Gov: governance::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Gov: governance::Read>, { type Error = Error; diff --git a/crates/shielded_token/src/vp.rs b/crates/shielded_token/src/vp.rs index 9ed5534e31..2d73650b02 100644 --- a/crates/shielded_token/src/vp.rs +++ b/crates/shielded_token/src/vp.rs @@ -19,9 +19,7 @@ use namada_core::collections::HashSet; use namada_core::masp::{addr_taddr, encode_asset_type, MaspEpoch, TAddrData}; use namada_core::storage::Key; use namada_core::uint::I320; -use namada_state::{ - ConversionState, OptionExt, ResultExt, StateRead, StorageError, -}; +use namada_state::{ConversionState, OptionExt, ResultExt, StateRead}; use namada_systems::trans_token::{Amount, MaspDigitPos}; use namada_systems::{governance, ibc, parameters, trans_token as token}; use namada_trans_token::read_denom; @@ -81,18 +79,9 @@ where S: 'static + StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - Params: parameters::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, - Gov: governance::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, - Ibc: ibc::Read< - CtxPostStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Params: parameters::Read>, + Gov: governance::Read>, + Ibc: ibc::Read>, TransToken: token::Keys, { /// Instantiate MASP VP @@ -930,18 +919,9 @@ where S: 'static + StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - Params: parameters::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, - Gov: governance::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, - Ibc: ibc::Read< - CtxPostStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Params: parameters::Read>, + Gov: governance::Read>, + Ibc: ibc::Read>, TransToken: token::Keys, { type Error = Error; diff --git a/crates/systems/src/governance.rs b/crates/systems/src/governance.rs index fb2d53970a..b6857b0eb5 100644 --- a/crates/systems/src/governance.rs +++ b/crates/systems/src/governance.rs @@ -1,13 +1,9 @@ //! Governance abstract interfaces +pub use namada_storage::Result; + /// Abstract governance storage read interface pub trait Read { - /// Storage error - type Err; - /// Check if an accepted proposal is being executed - fn is_proposal_accepted( - storage: &S, - tx_data: &[u8], - ) -> Result; + fn is_proposal_accepted(storage: &S, tx_data: &[u8]) -> Result; } diff --git a/crates/systems/src/ibc.rs b/crates/systems/src/ibc.rs index f10ec8c49f..970ceac999 100644 --- a/crates/systems/src/ibc.rs +++ b/crates/systems/src/ibc.rs @@ -7,16 +7,14 @@ use masp_primitives::transaction::TransparentAddress; use namada_core::address::Address; use namada_core::masp::TAddrData; use namada_core::{masp_primitives, storage, token}; +pub use namada_storage::Result; /// Abstract IBC storage read interface pub trait Read { - /// Storage error - type Err; - /// Extract MASP transaction from IBC envelope fn try_extract_masp_tx_from_envelope( tx_data: &[u8], - ) -> Result, Self::Err>; + ) -> Result>; /// Apply relevant IBC packets to the changed balances structure fn apply_ibc_packet( @@ -24,7 +22,7 @@ pub trait Read { tx_data: &[u8], acc: ChangedBalances, keys_changed: &BTreeSet, - ) -> Result; + ) -> Result; } /// Balances changed by a transaction diff --git a/crates/systems/src/parameters.rs b/crates/systems/src/parameters.rs index c6e89a3e30..049df39948 100644 --- a/crates/systems/src/parameters.rs +++ b/crates/systems/src/parameters.rs @@ -2,6 +2,7 @@ pub use namada_core::parameters::*; use namada_core::storage; +pub use namada_storage::Result; /// Abstract parameters storage keys interface pub trait Keys { @@ -11,28 +12,22 @@ pub trait Keys { /// Abstract parameters storage read interface pub trait Read { - /// Storage error - type Err; - /// Read all parameters - fn read(storage: &S) -> Result; + fn read(storage: &S) -> Result; /// Read MASP epoch multiplier - fn masp_epoch_multiplier(storage: &S) -> Result; + fn masp_epoch_multiplier(storage: &S) -> Result; /// Read the the epoch duration parameter from store - fn epoch_duration_parameter( - storage: &S, - ) -> Result; + fn epoch_duration_parameter(storage: &S) -> Result; /// Helper function to retrieve the `is_native_token_transferable` protocol /// parameter from storage - fn is_native_token_transferable(storage: &S) -> Result; + fn is_native_token_transferable(storage: &S) -> Result; } /// Abstract parameters storage write interface pub trait Write: Read { /// Write all parameters - fn write(storage: &mut S, parameters: &Parameters) - -> Result<(), Self::Err>; + fn write(storage: &mut S, parameters: &Parameters) -> Result<()>; } diff --git a/crates/systems/src/proof_of_stake.rs b/crates/systems/src/proof_of_stake.rs index 12e7af1f13..170bc49862 100644 --- a/crates/systems/src/proof_of_stake.rs +++ b/crates/systems/src/proof_of_stake.rs @@ -2,14 +2,12 @@ use namada_core::address::Address; use namada_core::storage; +pub use namada_storage::Result; /// Abstract PoS storage read interface pub trait Read { - /// Storage error - type Err; - /// Check if the provided address is a validator address - fn is_validator(storage: &S, address: &Address) -> Result; + fn is_validator(storage: &S, address: &Address) -> Result; /// Check if the provided address is a delegator address, optionally at a /// particular epoch. Returns `false` if the address is a validator. @@ -17,8 +15,8 @@ pub trait Read { storage: &S, address: &Address, epoch: Option, - ) -> Result; + ) -> Result; /// Read PoS pipeline length parameter - fn pipeline_len(storage: &S) -> Result; + fn pipeline_len(storage: &S) -> Result; } diff --git a/crates/systems/src/trans_token.rs b/crates/systems/src/trans_token.rs index 6eac8a1976..3399809a19 100644 --- a/crates/systems/src/trans_token.rs +++ b/crates/systems/src/trans_token.rs @@ -3,6 +3,7 @@ use namada_core::address::Address; use namada_core::storage; pub use namada_core::token::*; +pub use namada_storage::Result; /// Abstract token keys interface pub trait Keys { @@ -25,10 +26,7 @@ pub trait Keys { } /// Abstract token storage read interface -pub trait Read { - /// Storage error - type Err; -} +pub trait Read {} /// Abstract token storage write interface pub trait Write: Read { @@ -41,7 +39,7 @@ pub trait Write: Read { src: &Address, dest: &Address, amount: Amount, - ) -> Result<(), Self::Err>; + ) -> Result<()>; /// Burn a specified amount of tokens from some address. If the burn amount /// is larger than the total balance of the given address, then the @@ -52,7 +50,7 @@ pub trait Write: Read { token: &Address, source: &Address, amount: Amount, - ) -> Result<(), Self::Err>; + ) -> Result<()>; /// Credit tokens to an account, to be used only by protocol. In /// transactions, this would get rejected by the default `vp_token`. @@ -61,5 +59,5 @@ pub trait Write: Read { token: &Address, dest: &Address, amount: Amount, - ) -> Result<(), Self::Err>; + ) -> Result<()>; } diff --git a/crates/token/src/lib.rs b/crates/token/src/lib.rs index 4faf13d99c..f521450fd2 100644 --- a/crates/token/src/lib.rs +++ b/crates/token/src/lib.rs @@ -45,7 +45,7 @@ use std::collections::BTreeMap; use namada_core::address::Address; use namada_core::masp::TxId; use namada_events::EmitEvents; -use namada_storage::{Result, StorageRead, StorageWrite}; +use namada_storage::{StorageRead, StorageWrite}; /// Initialize parameters for the token in storage during the genesis block. pub fn write_params( diff --git a/crates/trans_token/src/lib.rs b/crates/trans_token/src/lib.rs index da7ccb9c52..50e37b1a55 100644 --- a/crates/trans_token/src/lib.rs +++ b/crates/trans_token/src/lib.rs @@ -59,12 +59,7 @@ impl Keys for Store { } } -impl Read for Store -where - S: StorageRead, -{ - type Err = namada_storage::Error; -} +impl Read for Store where S: StorageRead {} impl Write for Store where @@ -76,7 +71,7 @@ where src: &Address, dest: &Address, amount: Amount, - ) -> Result<(), Self::Err> { + ) -> Result<()> { storage::transfer(storage, token, src, dest, amount) } @@ -85,7 +80,7 @@ where token: &Address, source: &Address, amount: Amount, - ) -> Result<(), Self::Err> { + ) -> Result<()> { storage::burn_tokens(storage, token, source, amount) } @@ -94,7 +89,7 @@ where token: &Address, dest: &Address, amount: Amount, - ) -> Result<(), Self::Err> { + ) -> Result<()> { storage::credit_tokens(storage, token, dest, amount) } } diff --git a/crates/trans_token/src/vp.rs b/crates/trans_token/src/vp.rs index da45edff19..24c49fff4d 100644 --- a/crates/trans_token/src/vp.rs +++ b/crates/trans_token/src/vp.rs @@ -8,7 +8,7 @@ use namada_core::booleans::BoolResultUnitExt; use namada_core::collections::HashMap; use namada_core::storage::{Key, KeySeg}; use namada_core::token::Amount; -use namada_state::{StateRead, StorageError}; +use namada_state::StateRead; use namada_storage::StorageRead; use namada_systems::{governance, parameters}; use namada_tx::action::{ @@ -63,14 +63,8 @@ where S: 'static + StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - Params: parameters::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, - Gov: governance::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Params: parameters::Read>, + Gov: governance::Read>, { type Error = Error; @@ -300,14 +294,8 @@ where S: 'static + StateRead, CA: 'static + Clone, EVAL: 'static + VpEvaluator<'ctx, S, CA, EVAL>, - Params: parameters::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, - Gov: governance::Read< - CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>, - Err = StorageError, - >, + Params: parameters::Read>, + Gov: governance::Read>, { /// Instantiate token VP pub fn new(ctx: Ctx<'ctx, S, CA, EVAL>) -> Self { From c64c7aa6fbbd730ba181b8b4571973fea5c9e8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 9 Jul 2024 16:58:19 +0100 Subject: [PATCH 4/4] changelog: add #3472 --- .changelog/unreleased/improvements/3472-systems-crate.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changelog/unreleased/improvements/3472-systems-crate.md diff --git a/.changelog/unreleased/improvements/3472-systems-crate.md b/.changelog/unreleased/improvements/3472-systems-crate.md new file mode 100644 index 0000000000..c1a67cb0cd --- /dev/null +++ b/.changelog/unreleased/improvements/3472-systems-crate.md @@ -0,0 +1,5 @@ +- Added a new namada_systems crate to contain abstract systems interfaces, + previously added to core crate. Also switched to use the concrete + storage error and result type instead of the generic associated + type which reduces the amount of typing needed one the caller side. + ([\#3472](https://github.com/anoma/namada/pull/3472)) \ No newline at end of file