Skip to content

Commit

Permalink
Add debug-write of IBC messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarkushin committed Mar 18, 2024
1 parent 69a41d9 commit 8b71414
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 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 hyperspace/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rand = "0.8.5"
itertools = "0.10.5"
scale-decode = "0.5.0"
scale-encode = "0.1.2"
sha2 = "0.10.8"

# ibc
ibc = { path = "../../ibc/modules", features = [] }
Expand Down
18 changes: 18 additions & 0 deletions hyperspace/core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use ibc_proto::google::protobuf::Any;
use metrics::handler::MetricsHandler;
use primitives::Chain;
use sha2::Digest;

const DEBUG_MESSAGES: bool = true;

/// This sends messages to the sink chain in a gas-aware manner.
pub async fn flush_message_batch(
Expand All @@ -29,6 +32,21 @@ pub async fn flush_message_batch(
metrics.handle_transaction_costs(batch_weight, &msgs).await;
}

if DEBUG_MESSAGES {
let name = sink.name();
for msg in &msgs {
let content = format!("{}\n{}", msg.type_url, hex::encode(&msg.value));
let mut hasher = sha2::Sha256::default();
hasher.update(content.as_bytes());
let hash = hex::encode(&hasher.finalize());
let f_name = format!("messages/{}_{}_{hash}.txt", name, msg.type_url);
log::debug!(target: "hyperspace", "Writing message to file: {}", f_name);
if let Err(e) = std::fs::write(f_name, content) {
log::error!(target: "hyperspace", "Failed to write message to file: {:?}", e);
}
}
}

log::debug!(target: "hyperspace", "Outgoing messages weight: {} block max weight: {}", batch_weight, block_max_weight);
let ratio = (batch_weight / block_max_weight) as usize;
if ratio == 0 {
Expand Down

0 comments on commit 8b71414

Please sign in to comment.