Skip to content

Commit

Permalink
fix: metrics validator label to use address instead of pk struct form…
Browse files Browse the repository at this point in the history
…atting (#1201)

Co-authored-by: Karel Moravec <[email protected]>
  • Loading branch information
LePremierHomme and karlem authored Nov 15, 2024
1 parent 510676d commit d33333a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion fendermint/app/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async fn run(settings: Settings) -> anyhow::Result<()> {
.with_max_retries(settings.broadcast.max_retries)
.with_retry_delay(settings.broadcast.retry_delay);

ValidatorContext::new(sk, broadcaster)
ValidatorContext::new(sk, addr, broadcaster)
});

let testing_settings = match settings.testing.as_ref() {
Expand Down
2 changes: 1 addition & 1 deletion fendermint/vm/interpreter/src/fvm/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ where
role: CheckpointSignedRole::Own,
height: height.value(),
hash: HexEncodableBlockHash(cp.block_hash.to_vec()),
validator: validator_ctx.public_key,
validator: validator_ctx.addr,
});

tracing::debug!(?height, "submitted checkpoint signature");
Expand Down
6 changes: 5 additions & 1 deletion fendermint/vm/interpreter/src/fvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub use exec::FvmApplyRet;
use fendermint_crypto::{PublicKey, SecretKey};
pub use fendermint_vm_message::query::FvmQuery;
use fvm_ipld_blockstore::Blockstore;
use fvm_shared::address::Address;
pub use query::FvmQueryRet;
use tendermint_rpc::Client;

Expand All @@ -40,18 +41,21 @@ pub struct ValidatorContext<C> {
secret_key: SecretKey,
/// The public key identifying the validator (corresponds to the secret key.)
public_key: PublicKey,
/// The address associated with the public key.
addr: Address,
/// Used to broadcast transactions. It might use a different secret key for
/// signing transactions than the validator's block producing key.
broadcaster: Broadcaster<C>,
}

impl<C> ValidatorContext<C> {
pub fn new(secret_key: SecretKey, broadcaster: Broadcaster<C>) -> Self {
pub fn new(secret_key: SecretKey, addr: Address, broadcaster: Broadcaster<C>) -> Self {
// Derive the public keys so it's available to check whether this node is a validator at any point in time.
let public_key = secret_key.public_key();
Self {
secret_key,
public_key,
addr,
broadcaster,
}
}
Expand Down
13 changes: 4 additions & 9 deletions fendermint/vm/interpreter/src/fvm/observe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2022-2024 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT

use fvm_shared::address::Address;
use ipc_observability::{
impl_traceable, impl_traceables, lazy_static, register_metrics, serde::HexEncodableBlockHash,
Recordable, TraceLevel, Traceable,
Expand All @@ -11,7 +12,6 @@ use prometheus::{
Histogram, IntCounter, IntGauge, IntGaugeVec, Registry,
};

use fendermint_crypto::PublicKey;
use fvm_shared::message::Message;

register_metrics! {
Expand Down Expand Up @@ -110,13 +110,13 @@ pub struct CheckpointSigned {
pub role: CheckpointSignedRole,
pub height: u64,
pub hash: HexEncodableBlockHash,
pub validator: PublicKey,
pub validator: Address,
}

impl Recordable for CheckpointSigned {
fn record_metrics(&self) {
BOTTOMUP_CHECKPOINT_SIGNED_HEIGHT
.with_label_values(&[format!("{:?}", self.validator).as_str()])
.with_label_values(&[format!("{}", self.validator).as_str()])
.set(self.height as i64);
}
}
Expand Down Expand Up @@ -146,11 +146,9 @@ 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,
Expand Down Expand Up @@ -181,14 +179,11 @@ mod tests {
config_number: 3,
});

let mut r = thread_rng();
let secret_key = SecretKey::random(&mut r);

emit(CheckpointSigned {
role: CheckpointSignedRole::Own,
height: 1,
hash: HexEncodableBlockHash(hash.clone()),
validator: secret_key.public_key(),
validator: Address::new_id(1),
});
}
}

0 comments on commit d33333a

Please sign in to comment.