Skip to content

Commit

Permalink
update log to display json
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Apr 3, 2024
1 parent cb304f6 commit 9e544f9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
4 changes: 3 additions & 1 deletion crates/astria-core/src/sequencer/v1/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{
},
};

use serde::Serialize;

/// The default sequencer asset base denomination.
pub const DEFAULT_NATIVE_ASSET_DENOM: &str = "nria";

Expand Down Expand Up @@ -118,7 +120,7 @@ impl From<String> for Denom {
}

/// Asset ID, which is the hash of the denomination trace.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct Id([u8; 32]);

impl Id {
Expand Down
3 changes: 2 additions & 1 deletion crates/astria-core/src/sequencer/v1/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use indexmap::IndexMap;
use serde::Serialize;
use sha2::Sha256;
use transaction::SignedTransaction;

Expand Down Expand Up @@ -1238,7 +1239,7 @@ impl FilteredSequencerBlockError {
///
/// A [`Deposit`] is constructed whenever a [`BridgeLockAction`] is executed
/// and stored as part of the block's events.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Deposit {
// the address on the sequencer to which the funds were sent to.
bridge_address: Address,
Expand Down
3 changes: 2 additions & 1 deletion crates/astria-core/src/sequencer/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use indexmap::IndexMap;
use serde::Serialize;
use sha2::{
Digest as _,
Sha256,
Expand Down Expand Up @@ -38,7 +39,7 @@ use self::block::RollupTransactions;
pub const ADDRESS_LEN: usize = 20;
pub const ROLLUP_ID_LEN: usize = 32;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub struct Address([u8; ADDRESS_LEN]);

impl Address {
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default = []
mint = []

[dependencies]
astria-core = { path = "../astria-core", features = ["server"] }
astria-core = { path = "../astria-core", features = ["server", "serde"] }
astria-build-info = { path = "../astria-build-info", features = ["runtime"] }
config = { package = "astria-config", path = "../astria-config" }
merkle = { package = "astria-merkle", path = "../astria-merkle" }
Expand Down
25 changes: 5 additions & 20 deletions crates/astria-sequencer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,10 @@ impl App {
.get_block_deposits()
.await
.context("failed to get block deposits in end_block")?;
debug!(deposits = %DisplayDeposits(&deposits), "end_block: got block deposits");
debug!(
deposits = %telemetry::display::json(&DisplayDeposits(&deposits)),
"end_block: got block deposits"
);
self.current_sequencer_block_builder
.as_mut()
.expect(
Expand Down Expand Up @@ -735,27 +738,9 @@ impl App {
}

/// Display wrapper for `HashMap<RollupId, Vec<Deposit>>`.
#[derive(Debug, serde::Serialize)]
struct DisplayDeposits<'a>(&'a HashMap<RollupId, Vec<Deposit>>);

impl<'a> std::fmt::Display for DisplayDeposits<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "deposits: [ ")?;

let mut deposits_iter = self.0.iter();
if let Some((rollup_id, deposits)) = deposits_iter.next() {
write!(f, "rollup_id={rollup_id} deposit_count={}", deposits.len())?;
}

for (rollup_id, deposits) in deposits_iter {
write!(f, ", ")?;
write!(f, "rollup_id={rollup_id} deposit_count={}", deposits.len())?;
}

write!(f, " ]")?;
Ok(())
}
}

#[derive(Debug)]
struct SequencerBlockBuilder {
header: tendermint::block::Header,
Expand Down

0 comments on commit 9e544f9

Please sign in to comment.