Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure that the sim events are logged; improve format of main logs #906

Merged
merged 7 commits into from
Aug 30, 2023
18 changes: 5 additions & 13 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use soroban_env_host::e2e_invoke::get_ledger_changes;
use soroban_env_host::xdr::ReadXdr;
use soroban_env_host::{
budget::Budget,
events::HostEvent,
storage::Storage,
xdr::{
self, AccountId, Error as XdrError, Hash, HostFunction, InvokeContractArgs,
Expand Down Expand Up @@ -320,10 +319,7 @@ impl Cmd {
.await?;

tracing::debug!(?result);
if !events.is_empty() {
tracing::debug!(?events);
}

crate::log::diagnostic_events(&events, false);
let xdr::TransactionMeta::V3(xdr::TransactionMetaV3 {
soroban_meta: Some(xdr::SorobanTransactionMeta { return_value, .. }),
..
Expand Down Expand Up @@ -421,12 +417,8 @@ impl Cmd {
let budget = h.budget_cloned();
let (storage, events) = h.try_finish()?;
let footprint = &create_ledger_footprint(&storage.footprint);
log_events(
footprint,
&[contract_auth.try_into()?],
&events.0,
Some(&budget),
);
crate::log::host_events(&events.0);
log_events(footprint, &[contract_auth.try_into()?], &[], Some(&budget));

let ledger_changes = get_ledger_changes(&budget, &storage, &state)?;
let mut expiration_ledger_bumps: HashMap<LedgerKey, u32> = HashMap::new();
Expand Down Expand Up @@ -496,11 +488,11 @@ impl Cmd {
fn log_events(
footprint: &LedgerFootprint,
auth: &[VecM<SorobanAuthorizationEntry>],
events: &[HostEvent],
events: &[xdr::DiagnosticEvent],
budget: Option<&Budget>,
) {
crate::log::auth(auth);
crate::log::events(events);
crate::log::diagnostic_events(events, true);
crate::log::footprint(footprint);
if let Some(budget) = budget {
crate::log::budget(budget);
Expand Down
6 changes: 4 additions & 2 deletions cmd/soroban-cli/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
pub mod auth;
pub mod budget;
pub mod event;
pub mod diagnostic_event;
pub mod footprint;
pub mod host_event;

pub use auth::*;
pub use budget::*;
pub use event::*;
pub use diagnostic_event::*;
pub use footprint::*;
pub use host_event::*;
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/log/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use soroban_env_host::xdr::{SorobanAuthorizationEntry, VecM};

pub fn auth(auth: &[VecM<SorobanAuthorizationEntry>]) {
if !auth.is_empty() {
tracing::debug!(?auth);
tracing::debug!("{auth:#?}");
}
}
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/log/budget.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use soroban_env_host::budget::Budget;

pub fn budget(budget: &Budget) {
tracing::debug!(?budget);
tracing::debug!("{budget:#?}");
}
11 changes: 11 additions & 0 deletions cmd/soroban-cli/src/log/diagnostic_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use soroban_env_host::xdr::DiagnosticEvent;

pub fn diagnostic_events(events: &[DiagnosticEvent], is_trace: bool) {
for (i, event) in events.iter().enumerate() {
if is_trace {
tracing::trace!("{i}: {event:#?}");
} else {
tracing::info!("{i}: {event:#?}");
}
}
}
7 changes: 0 additions & 7 deletions cmd/soroban-cli/src/log/event.rs

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/log/footprint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use soroban_env_host::xdr::LedgerFootprint;

pub fn footprint(footprint: &LedgerFootprint) {
tracing::debug!(?footprint);
tracing::debug!("{footprint:#?}");
}
7 changes: 7 additions & 0 deletions cmd/soroban-cli/src/log/host_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use soroban_env_host::events::HostEvent;

pub fn host_events(events: &[HostEvent]) {
for (i, event) in events.iter().enumerate() {
tracing::info!("{i}: {event:#?}");
}
}
3 changes: 1 addition & 2 deletions cmd/soroban-cli/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde_aux::prelude::{deserialize_default_from_null, deserialize_number_from_
use soroban_env_host::xdr::DepthLimitedRead;
use soroban_env_host::{
budget::Budget,
events::HostEvent,
xdr::{
self, AccountEntry, AccountId, ContractDataEntry, DiagnosticEvent, Error as XdrError,
LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyAccount, PublicKey, ReadXdr,
Expand Down Expand Up @@ -35,7 +34,7 @@ const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
pub type LogEvents = fn(
footprint: &LedgerFootprint,
auth: &[VecM<SorobanAuthorizationEntry>],
events: &[HostEvent],
events: &[DiagnosticEvent],
budget: Option<&Budget>,
) -> ();

Expand Down
5 changes: 1 addition & 4 deletions cmd/soroban-cli/src/rpc/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ pub fn assemble(
.iter()
.map(DiagnosticEvent::from_xdr_base64)
.collect::<Result<Vec<_>, _>>()?;
if !events.is_empty() {
tracing::debug!(simulation_events=?events);
}

let transaction_data = SorobanTransactionData::from_xdr_base64(&simulation.transaction_data)?;

Expand Down Expand Up @@ -76,7 +73,7 @@ pub fn assemble(
_ => return Err(Error::UnsupportedOperationType),
};
if let Some(log) = log_events {
log(&transaction_data.resources.footprint, &auths, &[], None);
log(&transaction_data.resources.footprint, &auths, &events, None);
}

// update the fees of the actual transaction to meet the minimum resource fees.
Expand Down
Loading