Skip to content

Commit

Permalink
feat(inx): more detailed logging of INX events (#349)
Browse files Browse the repository at this point in the history
* feat(inx): more detailed logging

* Fmt
  • Loading branch information
grtlr authored Jun 27, 2022
1 parent 73f7f48 commit 986cdbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
7 changes: 4 additions & 3 deletions bin/inx-chronicle/src/stardust_inx/cone_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ impl HandleEvent<Result<inx::proto::BlockWithMetadata, Status>> for ConeStream {
block_metadata_result: Result<inx::proto::BlockWithMetadata, Status>,
white_flag_index: &mut Self::State,
) -> Result<(), Self::Error> {
log::trace!("Received Stardust Block Event");

let inx_block_with_metadata: inx::BlockWithMetadata = block_metadata_result?.try_into()?;
log::trace!("Received Stardust block event");
let block_metadata = block_metadata_result?;
log::trace!("Block data: {:?}", block_metadata);
let inx_block_with_metadata: inx::BlockWithMetadata = block_metadata.try_into()?;
let BlockWithMetadata { metadata, block, raw } = inx_block_with_metadata;

self.db
Expand Down
31 changes: 12 additions & 19 deletions bin/inx-chronicle/src/stardust_inx/ledger_update_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ use super::{cone_stream::ConeStream, InxError};
#[derive(Debug)]
pub struct LedgerUpdateStream {
db: MongoDb,
inx_client: InxClient<Channel>,
inx: InxClient<Channel>,
range: RangeInclusive<MilestoneIndex>,
}

impl LedgerUpdateStream {
pub fn new(db: MongoDb, inx: InxClient<Channel>, range: RangeInclusive<MilestoneIndex>) -> Self {
Self {
db,
inx_client: inx,
range,
}
Self { db, inx, range }
}
}

Expand All @@ -40,7 +36,7 @@ impl Actor for LedgerUpdateStream {

async fn init(&mut self, cx: &mut ActorContext<Self>) -> Result<Self::State, Self::Error> {
let ledger_update_stream = self
.inx_client
.inx
.listen_to_ledger_updates(if *self.range.end() == u32::MAX {
inx::proto::MilestoneRangeRequest::from(*self.range.start()..)
} else {
Expand Down Expand Up @@ -103,12 +99,13 @@ impl HandleEvent<Result<inx::proto::LedgerUpdate, Status>> for LedgerUpdateStrea

self.db.insert_ledger_updates(output_updates_iter).await?;

let milestone: inx::Milestone = self
.inx_client
.read_milestone(inx::proto::MilestoneRequest::from_index(ledger_update.milestone_index))
.await?
.into_inner()
.try_into()?;
let milestone_request = inx::proto::MilestoneRequest::from_index(ledger_update.milestone_index);

let milestone_proto = self.inx.read_milestone(milestone_request.clone()).await?.into_inner();

log::trace!("Received milestone: `{:?}`", milestone_proto);

let milestone: inx::Milestone = milestone_proto.try_into()?;

let milestone_index = milestone.milestone_info.milestone_index.into();
let milestone_timestamp = milestone.milestone_info.milestone_timestamp.into();
Expand All @@ -126,12 +123,8 @@ impl HandleEvent<Result<inx::proto::LedgerUpdate, Status>> for LedgerUpdateStrea
.insert_milestone(milestone_id, milestone_index, milestone_timestamp, payload)
.await?;

cx.spawn_child(ConeStream::new(
milestone_index,
self.inx_client.clone(),
self.db.clone(),
))
.await;
cx.spawn_child(ConeStream::new(milestone_index, self.inx.clone(), self.db.clone()))
.await;

Ok(())
}
Expand Down

0 comments on commit 986cdbf

Please sign in to comment.