mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-12 22:43:42 +08:00
Update build_signer_config_tomls to have Option<Duration> for event_timeout
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
This commit is contained in:
committed by
jferrant
parent
cc9dd4a364
commit
79001cd73a
@@ -67,7 +67,7 @@ pub trait SignerRunLoop<R, CMD: Send> {
|
||||
mut event_stop_signaler: EVST,
|
||||
) -> Option<R> {
|
||||
loop {
|
||||
let poll_timeout = Duration::from_millis(128); //self.get_event_timeout();
|
||||
let poll_timeout = self.get_event_timeout();
|
||||
let next_event_opt = match event_recv.recv_timeout(poll_timeout) {
|
||||
Ok(event) => Some(event),
|
||||
Err(RecvTimeoutError::Timeout) => None,
|
||||
|
||||
@@ -132,6 +132,7 @@ Generate the necessary files to run a collection of signers to communicate via s
|
||||
- `--private-keys:` A path to a file containing a list of hexadecimal representations of Stacks private keys. Required if `--num-keys` is not set.
|
||||
- `--network`: The network to use. One of "mainnet" or "testnet".
|
||||
- `--dir`: The directory to write files to. Defaults to the current directory.
|
||||
- `--timeout`: Optional timeout in milliseconds to use when polling for updates in the StackerDB runloop.
|
||||
|
||||
## Contributing
|
||||
|
||||
|
||||
@@ -142,6 +142,9 @@ pub struct GenerateFilesArgs {
|
||||
/// The directory to write the test data files to
|
||||
#[arg(long, default_value = ".")]
|
||||
pub dir: PathBuf,
|
||||
/// The number of milliseconds to wait when polling for events from the stacker-db instance.
|
||||
#[arg(long)]
|
||||
pub timeout: Option<u64>,
|
||||
}
|
||||
|
||||
/// Parse the contract ID
|
||||
|
||||
@@ -27,7 +27,7 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
const EVENT_TIMEOUT_SECS: u64 = 5;
|
||||
const EVENT_TIMEOUT_MS: u64 = 5000;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
/// An error occurred parsing the provided configuration
|
||||
@@ -106,7 +106,7 @@ struct RawConfigFile {
|
||||
pub signers: Vec<RawSigners>,
|
||||
/// The signer ID
|
||||
pub signer_id: u32,
|
||||
/// The time to wait (in secs) for a response from the stacker-db instance
|
||||
/// The time to wait (in millisecs) for a response from the stacker-db instance
|
||||
pub event_timeout: Option<u64>,
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ impl TryFrom<RawConfigFile> for Config {
|
||||
signer_key_ids.insert(signer_key, s.key_ids.clone());
|
||||
}
|
||||
let event_timeout =
|
||||
Duration::from_secs(raw_data.event_timeout.unwrap_or(EVENT_TIMEOUT_SECS));
|
||||
Duration::from_millis(raw_data.event_timeout.unwrap_or(EVENT_TIMEOUT_MS));
|
||||
Ok(Self {
|
||||
node_host,
|
||||
endpoint,
|
||||
|
||||
@@ -55,6 +55,7 @@ use std::{
|
||||
net::SocketAddr,
|
||||
path::PathBuf,
|
||||
sync::mpsc::{channel, Receiver},
|
||||
time::Duration,
|
||||
};
|
||||
use wsts::Point;
|
||||
|
||||
@@ -162,6 +163,7 @@ fn handle_generate_files(args: GenerateFilesArgs) {
|
||||
args.num_keys,
|
||||
&args.db_args.host.to_string(),
|
||||
&args.db_args.contract.to_string(),
|
||||
args.timeout.map(Duration::from_millis),
|
||||
);
|
||||
debug!("Built {:?} signer config tomls.", signer_config_tomls.len());
|
||||
for (i, file_contents) in signer_config_tomls.iter().enumerate() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use p256k1::ecdsa;
|
||||
use rand_core::OsRng;
|
||||
use slog::slog_debug;
|
||||
@@ -15,6 +17,7 @@ pub fn build_signer_config_tomls(
|
||||
num_keys: u32,
|
||||
node_host: &str,
|
||||
contract_id: &str,
|
||||
timeout: Option<Duration>,
|
||||
) -> Vec<String> {
|
||||
let num_signers = signer_stacks_private_keys.len() as u32;
|
||||
let mut rng = OsRng;
|
||||
@@ -65,7 +68,7 @@ pub fn build_signer_config_tomls(
|
||||
let id = i;
|
||||
let message_private_key = signer_ecdsa_private_keys[i].to_string();
|
||||
let stacks_private_key = stacks_private_key.to_hex();
|
||||
let signer_config_toml = format!(
|
||||
let mut signer_config_toml = format!(
|
||||
r#"
|
||||
message_private_key = "{message_private_key}"
|
||||
stacks_private_key = "{stacks_private_key}"
|
||||
@@ -77,6 +80,16 @@ signer_id = {id}
|
||||
{signers_array}
|
||||
"#
|
||||
);
|
||||
|
||||
if let Some(timeout) = timeout {
|
||||
let event_timeout_ms = timeout.as_millis();
|
||||
signer_config_toml = format!(
|
||||
r#"
|
||||
{signer_config_toml}
|
||||
event_timeout = {event_timeout_ms}
|
||||
"#
|
||||
)
|
||||
}
|
||||
signer_config_tomls.push(signer_config_toml);
|
||||
}
|
||||
signer_config_tomls
|
||||
|
||||
@@ -176,6 +176,7 @@ fn test_stackerdb_dkg() {
|
||||
num_keys,
|
||||
&conf.node.rpc_bind,
|
||||
&contract_id.to_string(),
|
||||
Some(Duration::from_millis(128)), // Timeout defaults to 5 seconds. Let's override it to 128 milliseconds.
|
||||
);
|
||||
|
||||
// The test starts here
|
||||
|
||||
Reference in New Issue
Block a user