diff --git a/abci/Cargo.toml b/abci/Cargo.toml index 43fc89e..90489d2 100644 --- a/abci/Cargo.toml +++ b/abci/Cargo.toml @@ -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" @@ -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" } diff --git a/abci/src/application.rs b/abci/src/application.rs index 07ae4da..3081041 100644 --- a/abci/src/application.rs +++ b/abci/src/application.rs @@ -1,5 +1,6 @@ //! ABCI application interface. +use tenderdash_proto::abci::{ExecTxResult, ValidatorSetUpdate}; use tracing::{debug, error}; use crate::proto::{ @@ -182,7 +183,8 @@ impl RequestDispatcher for A { 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 { @@ -191,6 +193,127 @@ impl RequestDispatcher for A { } } +fn serialize_response_for_logging(response: &response::Value) -> String { + match response { + response::Value::PrepareProposal(response) => { + let tx_records_hex: Vec = 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 = 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 = 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: &[ExecTxResult]) -> Vec { + 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_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 = 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. /// diff --git a/proto-compiler/Cargo.toml b/proto-compiler/Cargo.toml index 9dd520e..89a746f 100644 --- a/proto-compiler/Cargo.toml +++ b/proto-compiler/Cargo.toml @@ -1,5 +1,5 @@ [package] -version = "0.14.0-dev.9" +version = "0.14.0-dev.10" name = "tenderdash-proto-compiler" authors = ["Informal Systems ", "Dash Core Group"] edition = "2021" diff --git a/proto-compiler/src/constants.rs b/proto-compiler/src/constants.rs index 25f27f3..0ff9aca 100644 --- a/proto-compiler/src/constants.rs +++ b/proto-compiler/src/constants.rs @@ -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: 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), diff --git a/proto/Cargo.toml b/proto/Cargo.toml index c4d30e4..75566b3 100644 --- a/proto/Cargo.toml +++ b/proto/Cargo.toml @@ -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" diff --git a/scripts/release.sh b/scripts/release.sh index d4df98c..e78f496 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -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