From 96786c4bfa5318985eef53b9b7d41ba8287814c5 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] 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 33d93a53358..293515dc178 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 44bef35cde4..11016f28c3c 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 a13902d33d4..a6ba6242ed5 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 82fc8f1bcd1..38e57ff64ac 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 bb680c9f453..b15bf5854f6 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 f5d531fe29a..588f58af4d9 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 7b5b4e20821..26b7c5c8e57 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 00b2328ea40..733677583d8 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 2c82ca8211e..869f733e18d 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 9ed5534e317..2d73650b025 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 fb2d53970ab..b6857b0eb56 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 f10ec8c49f7..970ceac9995 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 c6e89a3e30e..049df399480 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 12e7af1f138..170bc498628 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 6eac8a19763..3399809a198 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 4faf13d99cc..f521450fd2e 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 da7ccb9c52a..50e37b1a55c 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 da45edff19b..24c49fff4d8 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 {