Skip to content

Commit

Permalink
fixup! Merge branch 'tomas/tx-actions' (#2934)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Apr 9, 2024
1 parent 2bcce82 commit d90fb55
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 47 deletions.
55 changes: 49 additions & 6 deletions crates/namada/src/ledger/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
for action in actions {
match action {
Action::Gov(gov_action) => match gov_action {
GovAction::InitProposal { id: _, author } => {
GovAction::InitProposal { author } => {
if !verifiers.contains(&author) {
tracing::info!(
"Unauthorized GovAction::InitProposal"
Expand Down Expand Up @@ -916,7 +916,7 @@ where
let is_post_funds_greater_than_minimum =
post_funds >= min_funds_parameter;
is_post_funds_greater_than_minimum.ok_or_else(|| {
Error(native_vp::Error::new_alloc(format!(
Error::NativeVpError(native_vp::Error::new_alloc(format!(
"Funds must be greater than the minimum funds of {}",
min_funds_parameter.native_denominated()
)))
Expand All @@ -938,7 +938,7 @@ where
let is_post_funds_greater_than_minimum =
post_funds >= min_funds_parameter;
is_post_funds_greater_than_minimum.ok_or_else(|| {
Error(native_vp::Error::new_alloc(format!(
Error::NativeVpError(native_vp::Error::new_alloc(format!(
"Funds {} must be greater than the minimum funds of {}",
post_funds.native_denominated(),
min_funds_parameter.native_denominated()
Expand Down Expand Up @@ -1009,7 +1009,7 @@ where

let author = self.force_read(&author_key, ReadType::Post)?;
namada_account::exists(&self.ctx.pre(), &author)
.map_err(Error)
.map_err(Error::NativeVpError)
.true_or_else(|| {
native_vp::Error::new_alloc(format!(
"No author account {author} could be found for the \
Expand Down Expand Up @@ -1079,7 +1079,7 @@ where
},
|data| {
is_proposal_accepted(&self.ctx.pre(), data.as_ref())
.map_err(Error)?
.map_err(Error::NativeVpError)?
.ok_or_else(|| {
native_vp::Error::new_const(
"Governance parameter changes can only be \
Expand Down Expand Up @@ -1270,6 +1270,7 @@ mod test {
State, StorageRead, TxIndex,
};
use namada_token::storage_key::balance_key;
use namada_tx::action::{Action, GovAction, Write};
use namada_tx::data::TxType;
use namada_tx::{Authorization, Code, Data, Section, Tx};

Expand Down Expand Up @@ -1462,7 +1463,7 @@ mod test {
signer_address: &Address,
no_commiting_key: bool,
) where
S: State,
S: State + namada_tx::action::Write,
{
let counter_key = get_counter_key();
let voting_end_epoch_key = get_voting_end_epoch_key(proposal_id);
Expand All @@ -1479,6 +1480,12 @@ mod test {

transfer(state, signer_address, &ADDRESS, funds);

state
.push_action(Action::Gov(GovAction::InitProposal {
author: signer_address.clone(),
}))
.unwrap();

state
.write_log_mut()
.write(&counter_key, (proposal_id + 1).serialize_to_vec())
Expand Down Expand Up @@ -2315,6 +2322,12 @@ mod test {
validator_address.clone(),
validator_address.clone(),
);
state
.push_action(Action::Gov(GovAction::VoteProposal {
id: 0,
voter: validator_address.clone(),
}))
.unwrap();
state
.write_log_mut()
.write(&vote_key, ProposalVote::Yay.serialize_to_vec())
Expand Down Expand Up @@ -2434,6 +2447,12 @@ mod test {
validator_address.clone(),
validator_address.clone(),
);
state
.push_action(Action::Gov(GovAction::VoteProposal {
id: 0,
voter: validator_address.clone(),
}))
.unwrap();
state
.write_log_mut()
.write(&vote_key, ProposalVote::Yay.serialize_to_vec())
Expand Down Expand Up @@ -2553,6 +2572,12 @@ mod test {
validator_address.clone(),
validator_address.clone(),
);
state
.push_action(Action::Gov(GovAction::VoteProposal {
id: 0,
voter: validator_address.clone(),
}))
.unwrap();
state
.write_log_mut()
.write(&vote_key, ProposalVote::Yay.serialize_to_vec())
Expand Down Expand Up @@ -2689,6 +2714,12 @@ mod test {
delegator_address.clone(),
validator_address.clone(),
);
state
.push_action(Action::Gov(GovAction::VoteProposal {
id: 0,
voter: delegator_address.clone(),
}))
.unwrap();
state
.write_log_mut()
.write(&vote_key, ProposalVote::Yay.serialize_to_vec())
Expand Down Expand Up @@ -2825,6 +2856,12 @@ mod test {
delegator_address.clone(),
validator_address.clone(),
);
state
.push_action(Action::Gov(GovAction::VoteProposal {
id: 0,
voter: delegator_address.clone(),
}))
.unwrap();
state
.write_log_mut()
.write(&vote_key, ProposalVote::Yay.serialize_to_vec())
Expand Down Expand Up @@ -2961,6 +2998,12 @@ mod test {
delegator_address.clone(),
validator_address.clone(),
);
state
.push_action(Action::Gov(GovAction::VoteProposal {
id: 0,
voter: delegator_address.clone(),
}))
.unwrap();
state
.write_log_mut()
.write(&vote_key, ProposalVote::Yay.serialize_to_vec())
Expand Down
8 changes: 0 additions & 8 deletions crates/namada/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ impl Error {
}
}

impl Error {
/// Determine if the error originates from an invalid transaction
/// section signature.
fn is_invalid_section_signature(&self) -> bool {
matches!(self, Self::InvalidSectionSignature(_))
}
}

/// Shell parameters for running wasm transactions.
#[allow(missing_docs)]
#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions crates/namada/src/vm/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,14 +2102,14 @@ where
// Verifier set populated in tx execution
let verifiers = Rc::new(RefCell::new(BTreeSet::<Address>::new()));
// Scoped to drop `verifiers.clone`s after `actions.execute`
{
let transfer = {
let mut actions = IbcActions::new(state.clone(), verifiers.clone());
let module = TransferModule::new(state.clone(), verifiers.clone());
actions.add_transfer_module(module);
let module = NftTransferModule::new(state);
actions.add_transfer_module(module);
actions.execute(&tx_data)?;
}
actions.execute(&tx_data)?
};
// NB: There must be no other strong references to this Rc
let verifiers = Rc::into_inner(verifiers)
.expect("There must be only one strong ref to verifiers set")
Expand Down
49 changes: 49 additions & 0 deletions crates/state/src/wl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,3 +1261,52 @@ where
&mut self.0
}
}

#[cfg(any(test, feature = "testing"))]
impl<D, H> namada_tx::action::Read for FullAccessState<D, H>
where
D: 'static + DB + for<'iter> DBIter<'iter>,
H: 'static + StorageHasher,
{
type Err = Error;

fn read_temp<T: namada_core::borsh::BorshDeserialize>(
&self,
key: &storage::Key,
) -> Result<Option<T>> {
let (log_val, _) = self.write_log().read(key);
match log_val {
Some(crate::write_log::StorageModification::Temp { value }) => {
let value =
namada_core::borsh::BorshDeserialize::try_from_slice(value)
.map_err(Error::BorshCodingError)?;
Ok(Some(value))
}
None => Ok(None),
_ => Err(Error::UnknownKey {
key: key.to_string(),
}),
}
}
}

#[cfg(any(test, feature = "testing"))]
impl<D, H> namada_tx::action::Write for FullAccessState<D, H>
where
D: 'static + DB + for<'iter> DBIter<'iter>,
H: 'static + StorageHasher,
{
fn write_temp<T: namada_core::borsh::BorshSerialize>(
&mut self,
key: &storage::Key,
val: T,
) -> Result<()> {
let _ = self
.write_log_mut()
.write_temp(key, val.serialize_to_vec())
.map_err(|err| Error::Temporary {
error: err.to_string(),
})?;
Ok(())
}
}
Loading

0 comments on commit d90fb55

Please sign in to comment.