Skip to content

Commit

Permalink
systems: use the concrete storage error and result type
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jul 2, 2024
1 parent 7345980 commit 0e1db34
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 217 deletions.
7 changes: 1 addition & 6 deletions crates/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ impl<S> Read<S> for Store<S>
where
S: StorageRead,
{
type Err = namada_state::StorageError;

fn is_proposal_accepted(
storage: &S,
tx_data: &[u8],
) -> Result<bool, Self::Err> {
fn is_proposal_accepted(storage: &S, tx_data: &[u8]) -> Result<bool> {
storage::is_proposal_accepted(storage, tx_data)
}
}
10 changes: 2 additions & 8 deletions crates/governance/src/vp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
TokenKeys: token::Keys,
{
type Error = Error;
Expand Down Expand Up @@ -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<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
TokenKeys: token::Keys,
{
/// Instantiate a Governance VP
Expand Down
14 changes: 3 additions & 11 deletions crates/ibc/src/vp/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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<T> = std::result::Result<T, namada_state::StorageError>;

/// Pseudo execution environment context for ibc native vp
#[derive(Debug)]
pub struct PseudoExecutionContext<'view, 'a, S, CA, EVAL, Token>
Expand Down Expand Up @@ -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<PseudoExecutionStorage<'view, 'a, S, CA, EVAL>>,
{
type Storage = PseudoExecutionStorage<'view, 'a, S, CA, EVAL>;

Expand Down Expand Up @@ -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<PseudoExecutionStorage<'view, 'a, S, CA, EVAL>>,
{
}

Expand Down
39 changes: 10 additions & 29 deletions crates/ibc/src/vp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,24 +83,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<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
Params: parameters::Keys
+ parameters::Read<
CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>,
Err = StorageError,
>,
+ parameters::Read<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
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<PseudoExecutionStorage<'view, 'ctx, S, CA, EVAL>>
+ Debug,
PoS: proof_of_stake::Read<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
{
type Error = Error;

Expand Down Expand Up @@ -150,19 +139,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<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
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<PseudoExecutionStorage<'view, 'ctx, S, CA, EVAL>>
+ Debug,
PoS: proof_of_stake::Read<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
{
/// Instantiate IBC VP
pub fn new(ctx: Ctx<'ctx, S, CA, EVAL>) -> Self {
Expand Down
21 changes: 6 additions & 15 deletions crates/parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,23 @@ impl<S> Read<S> for Store<S>
where
S: StorageRead,
{
type Err = namada_storage::Error;

fn read(storage: &S) -> Result<Parameters, Self::Err> {
fn read(storage: &S) -> Result<Parameters> {
read(storage)
}

fn masp_epoch_multiplier(storage: &S) -> Result<u64, Self::Err> {
fn masp_epoch_multiplier(storage: &S) -> Result<u64> {
read_masp_epoch_multiplier_parameter(storage)
}

fn epoch_duration_parameter(
storage: &S,
) -> Result<EpochDuration, Self::Err> {
fn epoch_duration_parameter(storage: &S) -> Result<EpochDuration> {
read_epoch_duration_parameter(storage)
}

fn max_signatures_per_transaction(
storage: &S,
) -> Result<Option<u8>, Self::Err> {
fn max_signatures_per_transaction(storage: &S) -> Result<Option<u8>> {
max_signatures_per_transaction(storage)
}

fn is_native_token_transferable(storage: &S) -> Result<bool, Self::Err> {
fn is_native_token_transferable(storage: &S) -> Result<bool> {
storage::is_native_token_transferable(storage)
}
}
Expand All @@ -78,10 +72,7 @@ impl<S> Write<S> for Store<S>
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)
}
}
Expand Down
12 changes: 3 additions & 9 deletions crates/parameters/src/vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<CtxPreStorageRead<'view, 'ctx, S, CA, EVAL>>,
{
type Error = Error;

Expand Down Expand Up @@ -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<CtxPreStorageRead<'ctx, 'ctx, S, CA, EVAL>>,
{
/// Instantiate parameters VP
pub fn new(ctx: Ctx<'ctx, S, CA, EVAL>) -> Self {
Expand Down
Loading

0 comments on commit 0e1db34

Please sign in to comment.