Skip to content

Commit dac0a7f

Browse files
committed
feat: add startup logging with config to signer
1 parent 986a3d4 commit dac0a7f

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

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: 3 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());

0 commit comments

Comments
 (0)