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

refactor: improve debug logging of PrepareProposal and ProcessProposal #59

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion abci/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
version = "0.14.0-dev.9"
version = "0.14.0-dev.10"
name = "tenderdash-abci"
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -49,6 +49,7 @@ tracing-subscriber = { version = "0.3", optional = true, default-features = fals
"ansi",
"env-filter",
] }
serde_json = "1.0.114"
thiserror = { version = "1.0.39" }
url = { version = "2.3.1" }
semver = { version = "1.0.17" }
Expand Down
126 changes: 125 additions & 1 deletion abci/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! ABCI application interface.

use tenderdash_proto::abci::{ExecTxResult, ValidatorSetUpdate};
use tracing::{debug, error};

use crate::proto::{
Expand Down Expand Up @@ -182,7 +183,8 @@
if let response::Value::Exception(_) = response {
tracing::error!(?response, "sending ABCI exception");
} else {
tracing::trace!(?response, "sending ABCI response");
let response_log = serialize_response_for_logging(&response);
tracing::trace!(?response_log, "sending ABCI response");
};

Some(abci::Response {
Expand All @@ -191,6 +193,128 @@
}
}

fn serialize_response_for_logging(response: &response::Value) -> String {
match response {
response::Value::PrepareProposal(response) => {
let tx_records_hex: Vec<String> = response
.tx_records
.iter()
.map(|tx_record| {
// Convert each byte array in tx_record to hex string
let tx_hex = hex::encode(&tx_record.tx);
serde_json::json!({
"action": tx_record.action, // Adjust according to actual fields
"tx": tx_hex,
})
.to_string()
})
.collect();

let app_hash_hex = hex::encode(&response.app_hash);

let tx_results_hex: Vec<String> = exec_tx_results_to_string(&response.tx_results);

let consensus_params = format!("{:?}", response.consensus_param_updates);

let validator_set_update =
validator_set_update_to_string(response.validator_set_update.as_ref());

serde_json::json!({
"tx_records": tx_records_hex,
"app_hash": app_hash_hex,
"tx_results": tx_results_hex,
"consensus_param_updates": consensus_params,
"core_chain_lock_update": response.core_chain_lock_update,
"validator_set_update": validator_set_update,
})
.to_string()
},
response::Value::ProcessProposal(response) => {
let status_string = match response.status {
0 => "Unknown",
1 => "Accepted",
2 => "Rejected",
_ => "Unknown(too high)",
};

let app_hash_hex = hex::encode(&response.app_hash);

let tx_results_hex: Vec<String> = exec_tx_results_to_string(&response.tx_results);

let consensus_params = format!("{:?}", response.consensus_param_updates);

let validator_set_update =
validator_set_update_to_string(response.validator_set_update.as_ref());

serde_json::json!({
"status": status_string,
"app_hash": app_hash_hex,
"tx_results": tx_results_hex,
"consensus_param_updates": consensus_params,
"validator_set_update": validator_set_update,
})
.to_string()
},
value => format!("{:?}", value),
}
}

fn exec_tx_results_to_string(tx_results: &Vec<ExecTxResult>) -> Vec<String> {
Fixed Show fixed Hide fixed
tx_results
.iter()
.map(|tx_result| {
let data_hex = hex::encode(&tx_result.data);

// Assuming `Event` is another complex type, you would serialize it similarly.
// Here, we'll just represent events as an array of placeholders. You should
// replace this with the actual serialization of `Event`.
let events_serialized = format!("{:?}", tx_result.events);

serde_json::json!({
"code": tx_result.code,
"data": data_hex,
"log": tx_result.log,
"info": tx_result.info,
"gas_wanted": tx_result.gas_wanted,
Fixed Show fixed Hide fixed
"gas_used": tx_result.gas_used,
"events": events_serialized,
"codespace": tx_result.codespace,
})
.to_string()
})
.collect()
}

fn validator_set_update_to_string(validator_set_update: Option<&ValidatorSetUpdate>) -> String {
validator_set_update
.as_ref()
.map(|validator_set_update| {
let quorum_hash_hex = hex::encode(&validator_set_update.quorum_hash);

let validator_updates_string: Vec<String> = validator_set_update
.validator_updates
.iter()
.map(|validator_update| {
let pro_tx_hash_hex = hex::encode(&validator_update.pro_tx_hash);
serde_json::json!({
"pub_key" : validator_update.pub_key,
"power" :validator_update.power,
"pro_tx_hash" : pro_tx_hash_hex,
"node_address" : validator_update.node_address,
})
.to_string()
})
.collect();
serde_json::json!({
"validator_updates": validator_updates_string,
"threshold_public_key": validator_set_update.threshold_public_key,
"quorum_hash": quorum_hash_hex,
})
.to_string()
})
.unwrap_or("None".to_string())
}

/// Check if ABCI version sent by Tenderdash matches version of linked protobuf
/// data objects.
///
Expand Down
2 changes: 1 addition & 1 deletion proto-compiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
version = "0.14.0-dev.9"
version = "0.14.0-dev.10"
name = "tenderdash-proto-compiler"
authors = ["Informal Systems <[email protected]>", "Dash Core Group"]
edition = "2021"
Expand Down
2 changes: 2 additions & 0 deletions proto-compiler/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const DERIVE_FROM_STR: &str = r#"#[derive(derive_more::FromStr)]"#;
/// The first item is a path as defined in the prost_build::Config::btree_map
/// here: <https://docs.rs/prost-build/0.6.1/prost_build/struct.Config.html#method.btree_map>
pub static CUSTOM_TYPE_ATTRIBUTES: &[(&str, &str)] = &[
(".tendermint.abci.Event", SERIALIZED),
(".tendermint.abci.EventAttribute", SERIALIZED),
(".tendermint.libs.bits.BitArray", SERIALIZED),
(".tendermint.types.BlockIDFlag", PRIMITIVE_ENUM),
(".tendermint.types.Block", SERIALIZED),
Expand Down
2 changes: 1 addition & 1 deletion proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
version = "0.14.0-dev.9"
version = "0.14.0-dev.10"
name = "tenderdash-proto"
edition = "2021"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Arguments:

Examples:

./scripts/release.sh -t 0.14.0-dev.2 -a 0.14.0-dev.6
./scripts/release.sh -t 0.14.0-dev.2 -a 0.14.0-dev.7
./scripts/release.sh -t 0.14.5 -a 0.14.12


Expand Down
Loading