Skip to content

Commit 8f87583

Browse files
authored
Merge pull request #4679 from stacks-network/feat/signer-startup-logging-release
feat: add signer startup logging
2 parents 986a3d4 + fabf70e commit 8f87583

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

stacks-signer/src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub enum Command {
6464
GenerateFiles(GenerateFilesArgs),
6565
/// Generate a signature for Stacking transactions
6666
GenerateStackingSignature(GenerateStackingSignatureArgs),
67+
/// Check a configuration file and output config information
68+
CheckConfig(RunSignerArgs),
6769
}
6870

6971
/// Basic arguments for all cyrptographic and stacker-db functionality

stacks-signer/src/config.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use std::fmt::Display;
1718
use std::fs;
1819
use std::net::{SocketAddr, ToSocketAddrs};
1920
use std::path::PathBuf;
@@ -329,6 +330,39 @@ impl GlobalConfig {
329330
pub fn load_from_file(path: &str) -> Result<Self, ConfigError> {
330331
Self::try_from(&PathBuf::from(path))
331332
}
333+
334+
/// Return a string with non-sensitive configuration
335+
/// information for logging purposes
336+
pub fn config_to_log_string(&self) -> String {
337+
let tx_fee = match self.tx_fee_ustx {
338+
0 => "default".to_string(),
339+
_ => (self.tx_fee_ustx as f64 / 1_000_000.0).to_string(),
340+
};
341+
format!(
342+
r#"
343+
Stacks node host: {node_host}
344+
Signer endpoint: {endpoint}
345+
Stacks address: {stacks_address}
346+
Public key: {public_key}
347+
Network: {network}
348+
Database path: {db_path}
349+
DKG transaction fee: {tx_fee} uSTX
350+
"#,
351+
node_host = self.node_host,
352+
endpoint = self.endpoint,
353+
stacks_address = self.stacks_address.to_string(),
354+
public_key = StacksPublicKey::from_private(&self.stacks_private_key).to_hex(),
355+
network = self.network,
356+
db_path = self.db_path.to_str().unwrap_or_default(),
357+
tx_fee = tx_fee
358+
)
359+
}
360+
}
361+
362+
impl Display for GlobalConfig {
363+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
364+
write!(f, "{}", self.config_to_log_string())
365+
}
332366
}
333367

334368
/// Helper function for building a signer config for each provided signer private key
@@ -412,4 +446,24 @@ mod tests {
412446

413447
assert_eq!(config.auth_password, "melon");
414448
}
449+
450+
#[test]
451+
fn test_config_to_string() {
452+
let config = GlobalConfig::load_from_file("./src/tests/conf/signer-0.toml").unwrap();
453+
let config_str = config.config_to_log_string();
454+
assert_eq!(
455+
config_str,
456+
format!(
457+
r#"
458+
Stacks node host: 127.0.0.1:20443
459+
Signer endpoint: [::1]:30000
460+
Stacks address: ST3FPN8KBZ3YPBP0ZJGAAHTVFMQDTJCR5QPS7VTNJ
461+
Public key: 03bc489f27da3701d9f9e577c88de5567cf4023111b7577042d55cde4d823a3505
462+
Network: testnet
463+
Database path: :memory:
464+
DKG transaction fee: 0.01 uSTX
465+
"#
466+
)
467+
);
468+
}
415469
}

stacks-signer/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ use clap::Parser;
3838
use clarity::vm::types::QualifiedContractIdentifier;
3939
use libsigner::{RunningSigner, Signer, SignerEventReceiver, SignerSession, StackerDBSession};
4040
use libstackerdb::StackerDBChunkData;
41-
use slog::{slog_debug, slog_error};
41+
use slog::{slog_debug, slog_error, slog_info};
4242
use stacks_common::codec::read_next;
4343
use stacks_common::types::chainstate::StacksPrivateKey;
4444
use stacks_common::util::hash::to_hex;
4545
use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PublicKey};
46-
use stacks_common::{debug, error};
46+
use stacks_common::{debug, error, info};
4747
use stacks_signer::cli::{
4848
Cli, Command, GenerateFilesArgs, GenerateStackingSignatureArgs, GetChunkArgs,
4949
GetLatestChunkArgs, PutChunkArgs, RunDkgArgs, RunSignerArgs, SignArgs, StackerDBArgs,
@@ -85,6 +85,7 @@ fn write_chunk_to_stdout(chunk_opt: Option<Vec<u8>>) {
8585
fn spawn_running_signer(path: &PathBuf) -> SpawnedSigner {
8686
let config = GlobalConfig::try_from(path).unwrap();
8787
let endpoint = config.endpoint;
88+
info!("Starting signer with config: {}", config);
8889
let (cmd_send, cmd_recv) = channel();
8990
let (res_send, res_recv) = channel();
9091
let ev = SignerEventReceiver::new(config.network.is_mainnet());
@@ -349,6 +350,11 @@ fn handle_generate_stacking_signature(
349350
signature
350351
}
351352

353+
fn handle_check_config(args: RunSignerArgs) {
354+
let config = GlobalConfig::try_from(&args.config).unwrap();
355+
println!("Config: {}", config);
356+
}
357+
352358
/// Helper function for writing the given contents to filename in the given directory
353359
fn write_file(dir: &Path, filename: &str, contents: &str) {
354360
let file_path = dir.join(filename);
@@ -397,6 +403,9 @@ fn main() {
397403
Command::GenerateStackingSignature(args) => {
398404
handle_generate_stacking_signature(args, true);
399405
}
406+
Command::CheckConfig(args) => {
407+
handle_check_config(args);
408+
}
400409
}
401410
}
402411

0 commit comments

Comments
 (0)