Skip to content

Commit

Permalink
fixup! Merge branch 'tiago/type-safe-events' (#2787)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Apr 5, 2024
1 parent fe32804 commit fa569a9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 52 deletions.
28 changes: 8 additions & 20 deletions crates/apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use namada::core::storage::{BlockHash, BlockResults, Epoch, Header};
use namada::gas::event::WithGasUsed;
use namada::governance::pgf::inflation as pgf_inflation;
use namada::hash::Hash;
use namada::ledger::events::extend::{
ComposeEvent, Height, Info, Log, ValidMaspTx,
};
use namada::ledger::events::{EmitEvents, EventType};
use namada::ledger::events::extend::{ComposeEvent, Height, Info, ValidMaspTx};
use namada::ledger::events::EmitEvents;
use namada::ledger::gas::GasMetering;
use namada::ledger::ibc;
use namada::ledger::pos::namada_proof_of_stake;
Expand Down Expand Up @@ -132,15 +130,6 @@ where
if new_epoch {
// Apply PoS and PGF inflation
self.apply_inflation(current_epoch)?;

// Take IBC events that may be emitted from PGF
for ibc_event in self.state.write_log_mut().take_ibc_events() {
let mut event = Event::from(ibc_event.clone());
// Add the height for IBC event query
let height = self.state.in_mem().get_last_block_height() + 1;
event["height"] = height.to_string();
response.events.push(event);
}
}

let mut stats = InternalStats::default();
Expand Down Expand Up @@ -413,8 +402,7 @@ where
.map(|args| args.is_committed_fee_unshield)
.unwrap_or_default()
{
tx_event["is_valid_masp_tx"] =
format!("{}", tx_index);
tx_event.extend(ValidMaspTx(tx_index));

Check warning on line 405 in crates/apps/src/lib/node/ledger/shell/finalize_block.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/shell/finalize_block.rs#L404-L405

Added lines #L404 - L405 were not covered by tests
}

// If an inner tx failed for any reason but invalid
Expand All @@ -441,10 +429,10 @@ where
tx_event["hash"],

Check warning on line 429 in crates/apps/src/lib/node/ledger/shell/finalize_block.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/shell/finalize_block.rs#L428-L429

Added lines #L428 - L429 were not covered by tests
msg,
);
tx_event["gas_used"] =
tx_gas_meter.get_tx_consumed_gas().to_string();
tx_event["info"] = msg.to_string();
tx_event["code"] = ResultCode::InvalidTx.into();
tx_event
.extend(WithGasUsed(tx_gas_meter.get_tx_consumed_gas()))
.extend(Info(msg.to_string()))
.extend(Code(ResultCode::InvalidTx));
}
Err(msg) => {
tracing::info!(
Expand Down Expand Up @@ -491,7 +479,7 @@ where
.extend(Info(msg.to_string()));

// If wrapper, invalid tx error code
tx_event["code"] = ResultCode::InvalidTx.into();
tx_event.extend(Code(ResultCode::InvalidTx));
// The fee unshield operation could still have been
// committed
if wrapper_args
Expand Down
22 changes: 9 additions & 13 deletions crates/apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use namada::governance::{
storage as gov_api, ProposalVote, ADDRESS as gov_address,
};
use namada::ibc;
use namada::ledger::events::extend::{ComposeEvent, Height};
use namada::ledger::governance::utils::ProposalEvent;
use namada::ledger::pos::BondId;
use namada::proof_of_stake::bond_amount;
Expand Down Expand Up @@ -132,7 +133,6 @@ where
proposal_code.is_some(),
result,
)

Check warning on line 135 in crates/apps/src/lib/node/ledger/shell/governance.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/shell/governance.rs#L131-L135

Added lines #L131 - L135 were not covered by tests
.into()
}
ProposalType::DefaultWithWasm(_) => {
let proposal_code =
Expand Down Expand Up @@ -182,24 +182,20 @@ where
id
);

for ibc_event in
shell.state.write_log_mut().take_ibc_events()
{
let mut event = Event::from(ibc_event.clone());
// Add the height for IBC event query
let height =
shell.state.in_mem().get_last_block_height()
+ 1;
event["height"] = height.to_string();
events.emit(event);
}

ProposalEvent::pgf_payments_proposal_event(id, result)
}
};
events.emit(proposal_event);
proposals_result.passed.push(id);

// Take events that could have been emitted by PGF
// over IBC, governance proposal execution, etc
for event in shell.state.write_log_mut().take_ibc_events() {
events.emit(event.with(Height(
shell.state.in_mem().get_last_block_height() + 1,
)));
}

Check warning on line 197 in crates/apps/src/lib/node/ledger/shell/governance.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/shell/governance.rs#L193-L197

Added lines #L193 - L197 were not covered by tests

gov_api::get_proposal_author(&shell.state, id)?
}
TallyResult::Rejected => {
Expand Down
9 changes: 0 additions & 9 deletions crates/core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,6 @@ pub enum EventError {
}

impl Event {
/// Create an accepted tx event with empty attributes.
pub fn accepted_tx() -> Self {
Self {
event_type: EventType::Accepted,
level: EventLevel::Tx,
attributes: HashMap::new(),
}
}

/// Create an applied tx event with empty attributes.
pub fn applied_tx() -> Self {
Self {
Expand Down
2 changes: 0 additions & 2 deletions crates/core/src/event/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ impl ExtendEvent for ValidMaspTx {

#[cfg(test)]
mod event_composition_tests {
use std::collections::HashMap;

use super::*;

#[test]
Expand Down
7 changes: 1 addition & 6 deletions crates/tx/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ use crate::TxType;
/// already filled in
pub fn new_tx_event(tx: &Tx, height: u64) -> Event {
let base_event = match tx.header().tx_type {
TxType::Wrapper(_) => {
Event::accepted_tx().with(TxHash(tx.header_hash()))
}
TxType::Decrypted(_) => Event::applied_tx()
.with(TxHash(tx.clone().update_header(TxType::Raw).header_hash())),
TxType::Protocol(_) => {
TxType::Wrapper(_) | TxType::Protocol(_) => {
Event::applied_tx().with(TxHash(tx.header_hash()))
}
_ => unreachable!(),
Expand Down
2 changes: 0 additions & 2 deletions crates/tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ mod types;

use data::TxType;
pub use event::new_tx_event;
use namada_core::collections::HashMap;
use namada_core::event::{Event, EventLevel, EventType};
pub use namada_core::key::SignableEthMessage;
pub use namada_core::sign::SignatureIndex;
pub use types::{
Expand Down

0 comments on commit fa569a9

Please sign in to comment.