Skip to content

Commit

Permalink
refactor: temp better debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Mar 21, 2024
1 parent 8b5afe6 commit d1585f4
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 4 deletions.
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.6"
version = "0.14.0-dev.7"
name = "tenderdash-abci"
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -39,6 +39,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
123 changes: 123 additions & 0 deletions 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 @@ -191,6 +192,128 @@ impl<A: Application> RequestDispatcher for A {
}
}

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> {
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,
"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.6"
version = "0.14.0-dev.7"
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.EvidenceParams", SERIALIZED),
(".tendermint.types.BlockIDFlag", PRIMITIVE_ENUM),
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.6"
version = "0.14.0-dev.7"
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

0 comments on commit d1585f4

Please sign in to comment.