Skip to content

Commit

Permalink
Merge branch 'tiago/wasm-errs-ux' (#2940)
Browse files Browse the repository at this point in the history
* tiago/wasm-errs-ux:
  Changelog for #2940
  Generalize VP status codes
  Add `bitflags` dep
  Poison tx gas meter on gas overflow
  Prevent gas overflows from being ignored during VP execution
  Remove explicit out-of-gas checks during VP execution
  Rebuild wasms for tests
  Fix wasm unit tests
  Return a result of unit from VPs rather than of bools
  Extend bools and results with new helper methods
  • Loading branch information
tzemanovic committed Apr 8, 2024
2 parents 04a82f4 + 620d3d8 commit 0201258
Show file tree
Hide file tree
Showing 76 changed files with 2,530 additions and 1,790 deletions.
4 changes: 4 additions & 0 deletions .changelog/unreleased/improvements/2940-wasm-errs-ux.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Change the return type of a VP's predicate function to a Result of unit or
some error. In case Namada users perform invalid state changes, they should
be met with more descriptive error messages explaining the cause of their tx's
rejection. ([\#2940](https://github.com/anoma/namada/pull/2940))
20 changes: 12 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ base64 = "0.13.0"
bech32 = "0.8.0"
bimap = {version = "0.6.2", features = ["serde"]}
bit-set = "0.5.2"
bitflags = { version = "2.5.0", features = ["serde"] }
blake2b-rs = "0.2.0"
bls12_381 = "0.8"
byte-unit = "4.0.13"
Expand Down
19 changes: 11 additions & 8 deletions crates/apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use namada::proof_of_stake::storage::{
use namada::state::write_log::StorageModification;
use namada::state::{ResultExt, StorageWrite, EPOCH_SWITCH_BLOCKS_DELAY};
use namada::tx::data::protocol::ProtocolTxType;
use namada::tx::data::VpStatusFlags;
use namada::tx::event::{Code, InnerTx};
use namada::tx::new_tx_event;
use namada::vote_ext::ethereum_events::MultiSignedEthEvent;
Expand Down Expand Up @@ -416,7 +417,11 @@ where
// If an inner tx failed for any reason but invalid
// signature, commit its hash to storage, otherwise
// allow for a replay
if !result.vps_result.invalid_sig {
if !result
.vps_result
.status_flags
.contains(VpStatusFlags::INVALID_SIGNATURE)
{
self.commit_inner_tx_hash(replay_protection_hashes);
}

Expand Down Expand Up @@ -784,7 +789,6 @@ mod test_finalize_block {
liveness_missed_votes_handle, liveness_sum_missed_votes_handle,
read_consensus_validator_set_addresses,
};
use namada_sdk::validity_predicate::VpSentinel;
use namada_test_utils::tx_data::TxWriteData;
use namada_test_utils::TestWasms;
use test_log::test;
Expand Down Expand Up @@ -4729,23 +4733,22 @@ mod test_finalize_block {
));
let keys_changed = BTreeSet::from([min_confirmations_key()]);
let verifiers = BTreeSet::default();
let sentinel = RefCell::new(VpSentinel::default());
let ctx = namada::ledger::native_vp::Ctx::new(
shell.mode.get_validator_address().expect("Test failed"),
shell.state.read_only(),
&tx,
&TxIndex(0),
&gas_meter,
&sentinel,
&keys_changed,
&verifiers,
shell.vp_wasm_cache.clone(),
);
let parameters = ParametersVp { ctx };
let result = parameters
.validate_tx(&tx, &keys_changed, &verifiers)
.expect("Test failed");
assert!(result);
assert!(
parameters
.validate_tx(&tx, &keys_changed, &verifiers)
.is_ok()
);

// we advance forward to the next epoch
let mut req = FinalizeBlock::default();
Expand Down
Loading

0 comments on commit 0201258

Please sign in to comment.