Skip to content

Commit 6ef1d58

Browse files
authored
Log consensus-key signer address if specified (#2158)
## Linked Issues/PRs <!-- List of related issues/PRs --> Closes #2132 ## Description Checks if the consensus key is available when running the node, in which case it logs its corresponding public key address <!-- List of detailed changes --> - [x] added two functions `public_key` and `address` to the `signer::SignMode` struct. - [x] changed main binary to display the result of SignMode::address when the consensus key is specified ## Manual testing: ```lang=bash ./target/debug/fuel-core run --db-type in-memory --debug ``` Relevant output: ``` 2024-09-04T15:30:22.400412Z INFO fuel_core_bin::cli::run: 324: Consensus signer is specified and its address is 22ec92c3105c942a6640bdc4e4907286ec4728e8cfc0d8ac59aad4d8e1ccaefb ``` ## Checklist - [ ] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [x] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else?
1 parent 5a6eed0 commit 6ef1d58

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- [2135](https://github.com/FuelLabs/fuel-core/pull/2135): Added metrics logging for number of blocks served over the p2p req/res protocol.
1111
- [2155](https://github.com/FuelLabs/fuel-core/pull/2155): Added trait declaration for block committer data
1212
- [2142](https://github.com/FuelLabs/fuel-core/pull/2142): Added benchmarks for varied forms of db lookups to assist in optimizations.
13+
- [2158](https://github.com/FuelLabs/fuel-core/pull/2158): Log the public address of the signing key, if it is specified
1314

1415
## [Version 0.35.0]
1516

Binary file not shown.

bin/fuel-core/src/cli/run.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,18 @@ impl Command {
354354
);
355355
consensus_signer = SignMode::Key(Secret::new(key.into()));
356356
}
357-
}
357+
};
358+
359+
if let Ok(signer_address) = consensus_signer.address() {
360+
if let Some(address) = signer_address {
361+
info!(
362+
"Consensus signer is specified and its address is {}",
363+
address
364+
);
365+
}
366+
} else {
367+
warn!("Consensus Signer is specified but it was not possible to retrieve its address");
368+
};
358369

359370
if consensus_signer.is_available() && trigger == Trigger::Never {
360371
warn!("Consensus key configured but block production is disabled!");

crates/services/consensus_module/poa/src/signer.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use fuel_core_types::{
1818
},
1919
primitives::SecretKeyWrapper,
2020
},
21+
fuel_crypto::PublicKey,
22+
fuel_tx::{
23+
Address,
24+
Input,
25+
},
2126
fuel_vm::Signature,
2227
secrecy::{
2328
ExposeSecret,
@@ -68,6 +73,34 @@ impl SignMode {
6873
};
6974
Ok(Consensus::PoA(PoAConsensus::new(poa_signature)))
7075
}
76+
77+
/// Returns the public key of the block producer, if any
78+
pub fn public_key(&self) -> anyhow::Result<Option<PublicKey>> {
79+
match self {
80+
SignMode::Unavailable => Ok(None),
81+
SignMode::Key(secret_key) => {
82+
Ok(Some(secret_key.expose_secret().public_key()))
83+
}
84+
85+
#[cfg(feature = "aws-kms")]
86+
SignMode::Kms {
87+
cached_public_key_bytes,
88+
..
89+
} => {
90+
use k256::pkcs8::DecodePublicKey;
91+
92+
let k256_public_key =
93+
k256::PublicKey::from_public_key_der(cached_public_key_bytes)?;
94+
Ok(Some(PublicKey::from(k256_public_key)))
95+
}
96+
}
97+
}
98+
99+
/// Returns the address of the block producer, if any
100+
pub fn address(&self) -> anyhow::Result<Option<Address>> {
101+
let address = self.public_key()?.as_ref().map(Input::owner);
102+
Ok(address)
103+
}
71104
}
72105

73106
#[cfg(feature = "aws-kms")]
@@ -140,6 +173,8 @@ async fn sign_with_kms(
140173

141174
#[cfg(test)]
142175
mod tests {
176+
use std::str::FromStr;
177+
143178
use super::*;
144179
use fuel_core_types::fuel_crypto::SecretKey;
145180
use rand::{
@@ -173,4 +208,51 @@ mod tests {
173208
.is_available())
174209
};
175210
}
211+
212+
// The tests are against a keypair generated using fuel-core-keygen, which has
213+
// been tweaked to display the public key associated with a keypair.
214+
// The keypair used in these tests is the following:
215+
// {
216+
// "address:"e2f3f5109c56eec359c124cbf25f35dcc1495b0bbdac5848e0ff37a86fe69a6d",
217+
// "public_key":"9ab6229de634056cdc67dfba26e6a06e4ba082693ea30395e5994b113ab6c6e3189a12a10d8fb08d1d28f7117ca34f6b16c5132acd9570de6e7a005f6bbd8f3d",
218+
// "secret":"2708b7bad8b5b52d031e5795c1d1995660185f464900cbd593328eb433bdb7f6","type":"block-production"
219+
// }
220+
#[test]
221+
fn public_key() {
222+
assert_eq!(SignMode::Unavailable.public_key().unwrap(), None);
223+
224+
let secret_key = SecretKey::from_str(
225+
"2708b7bad8b5b52d031e5795c1d1995660185f464900cbd593328eb433bdb7f6",
226+
)
227+
.expect("Secret key construction should not fail");
228+
229+
let public_key = "9ab6229de634056cdc67dfba26e6a06e4ba082693ea30395e5994b113ab6c6e3189a12a10d8fb08d1d28f7117ca34f6b16c5132acd9570de6e7a005f6bbd8f3d";
230+
231+
let derived_public_key = SignMode::Key(Secret::new(secret_key.into()))
232+
.public_key()
233+
.expect("Public key derivation should not fail")
234+
.expect("Public key derivation should yield a defined value")
235+
.to_string();
236+
237+
assert_eq!(public_key, &derived_public_key);
238+
}
239+
240+
#[test]
241+
fn address() {
242+
assert_eq!(SignMode::Unavailable.address().unwrap(), None);
243+
244+
let secret_key = SecretKey::from_str(
245+
"2708b7bad8b5b52d031e5795c1d1995660185f464900cbd593328eb433bdb7f6",
246+
)
247+
.expect("Secret key construction should not fail");
248+
249+
let address = "e2f3f5109c56eec359c124cbf25f35dcc1495b0bbdac5848e0ff37a86fe69a6d";
250+
let derived_address = SignMode::Key(Secret::new(secret_key.into()))
251+
.address()
252+
.expect("Address derivation should not fail")
253+
.expect("Address derivation should yield a defined value")
254+
.to_string();
255+
256+
assert_eq!(address, &derived_address);
257+
}
176258
}

0 commit comments

Comments
 (0)