From e8fe0c2d1e1ec5d90590015c284f2c0e252b1ae8 Mon Sep 17 00:00:00 2001 From: Karel Moravec Date: Fri, 19 Jul 2024 00:37:50 +0200 Subject: [PATCH] feat: change public key --- .../vm/interpreter/src/fvm/checkpoint.rs | 2 +- fendermint/vm/interpreter/src/fvm/observe.rs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fendermint/vm/interpreter/src/fvm/checkpoint.rs b/fendermint/vm/interpreter/src/fvm/checkpoint.rs index cb4b1b465..bf52eff94 100644 --- a/fendermint/vm/interpreter/src/fvm/checkpoint.rs +++ b/fendermint/vm/interpreter/src/fvm/checkpoint.rs @@ -258,7 +258,7 @@ where emit(CheckpointSigned { height: height.value(), hash: HexEncodableBlockHash(cp.block_hash.to_vec()), - validator: &hex::encode(validator_ctx.public_key.serialize()), + validator: validator_ctx.public_key, }); tracing::debug!(?height, "submitted checkpoint signature"); diff --git a/fendermint/vm/interpreter/src/fvm/observe.rs b/fendermint/vm/interpreter/src/fvm/observe.rs index 52ad9dd7c..687819836 100644 --- a/fendermint/vm/interpreter/src/fvm/observe.rs +++ b/fendermint/vm/interpreter/src/fvm/observe.rs @@ -11,6 +11,7 @@ use prometheus::{ Histogram, IntCounter, IntGauge, IntGaugeVec, Registry, }; +use fendermint_crypto::PublicKey; use fvm_shared::message::Message; register_metrics! { @@ -77,7 +78,7 @@ impl_traceables!( TraceLevel::Info, "Bottomup", CheckpointCreated, - CheckpointSigned<'a>, + CheckpointSigned, CheckpointFinalized ); @@ -102,16 +103,16 @@ impl Recordable for CheckpointCreated { } #[derive(Debug)] -pub struct CheckpointSigned<'a> { +pub struct CheckpointSigned { pub height: u64, pub hash: HexEncodableBlockHash, - pub validator: &'a str, + pub validator: PublicKey, } -impl Recordable for CheckpointSigned<'_> { +impl Recordable for CheckpointSigned { fn record_metrics(&self) { BOTTOMUP_CHECKPOINT_SIGNED_HEIGHT - .with_label_values(&[self.validator]) + .with_label_values(&[format!("{:?}", self.validator).as_str()]) .set(self.height as i64); } } @@ -141,9 +142,11 @@ mod tests { #[test] fn test_emit() { + use fendermint_crypto::SecretKey; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; use fvm_shared::econ::TokenAmount; + use rand::thread_rng; let message = Message { version: 1, @@ -173,10 +176,14 @@ mod tests { msg_count: 2, config_number: 3, }); + + let mut r = thread_rng(); + let secret_key = SecretKey::random(&mut r); + emit(CheckpointSigned { height: 1, hash: HexEncodableBlockHash(hash.clone()), - validator: "validator", + validator: secret_key.public_key(), }); } }