Skip to content

Commit 2440266

Browse files
committed
Make coordinator config optional
1 parent d0206aa commit 2440266

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

src/config.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ pub struct BitcoindConfig {
127127
pub poll_interval_secs: Duration,
128128
}
129129

130+
/// Everything we need to know for talking to coordinator
131+
#[derive(Debug, Clone, Deserialize)]
132+
pub struct CoordinatorConfig {
133+
/// The Noise static public key of the sync server
134+
#[serde(deserialize_with = "deserialize_noisepubkey")]
135+
pub noise_key: NoisePubkey,
136+
/// The host of the sync server (may be an IP or a hidden service)
137+
/// TODO: change for enum handling multiple choice.
138+
pub host: SocketAddr,
139+
}
140+
130141
#[derive(Debug, Clone, Deserialize)]
131142
pub struct ScriptsConfig {
132143
#[serde(deserialize_with = "deserialize_fromstr")]
@@ -149,12 +160,8 @@ pub struct Config {
149160
/// The Noise static public keys of "our" stakeholder
150161
#[serde(deserialize_with = "deserialize_noisepubkey")]
151162
pub stakeholder_noise_key: NoisePubkey,
152-
/// The host of the sync server (may be an IP or a hidden service)
153-
/// TODO: change for enum handling multiple choice.
154-
pub coordinator_host: SocketAddr,
155-
/// The Noise static public key of the sync server
156-
#[serde(deserialize_with = "deserialize_noisepubkey")]
157-
pub coordinator_noise_key: NoisePubkey,
163+
/// Everything we need to know to talk to coordinator
164+
pub coordinator_config: Option<CoordinatorConfig>,
158165
/// An optional custom data directory
159166
// TODO: have a default implem as in cosignerd
160167
pub data_dir: Option<PathBuf>,
@@ -353,8 +360,9 @@ mod tests {
353360
354361
stakeholder_noise_key = "3de4539519b6baca35ad14cd5bac9a4e0875a851632112405bb0547e6fcf16f6"
355362
356-
coordinator_host = "127.0.0.1:1"
357-
coordinator_noise_key = "d91563973102454a7830137e92d0548bc83b4ea2799f1df04622ca1307381402"
363+
[coordinator_config]
364+
host = "127.0.0.1:1"
365+
noise_key = "d91563973102454a7830137e92d0548bc83b4ea2799f1df04622ca1307381402"
358366
359367
[scripts_config]
360368
cpfp_descriptor = "wsh(thresh(1,pk(xpub6BaZSKgpaVvibu2k78QsqeDWXp92xLHZxiu1WoqLB9hKhsBf3miBUDX7PJLgSPvkj66ThVHTqdnbXpeu8crXFmDUd4HeM4s4miQS2xsv3Qb/*)))#cwycq5xu"
@@ -385,8 +393,9 @@ mod tests {
385393
386394
stakeholder_noise_key = "3de4539519b6baca35ad14cd5bac9a4e0875a851632112405bb0547e6fcf16f6"
387395
388-
coordinator_host = "127.0.0.1:1"
389-
coordinator_noise_key = "d91563973102454a7830137e92d0548bc83b4ea2799f1df04622ca1307381402"
396+
[coordinator_config]
397+
host = "127.0.0.1:1"
398+
noise_key = "d91563973102454a7830137e92d0548bc83b4ea2799f1df04622ca1307381402"
390399
391400
[[plugins]]
392401
path = "src/config.rs"
@@ -417,8 +426,9 @@ mod tests {
417426
418427
stakeholder_noise_key = "3de4539519b6baca35ad14cd5bac9a4e0875a851632112405bb0547e6fcf16f6"
419428
420-
coordinator_host = "127.0.0.1:1"
421-
coordinator_noise_key = "d91563973102454a7830137e92d0548bc83b4ea2799f1df04622ca1307381402"
429+
[coordinator_config]
430+
host = "127.0.0.1:1"
431+
noise_key = "d91563973102454a7830137e92d0548bc83b4ea2799f1df04622ca1307381402"
422432
423433
[scripts_config]
424434
cpfp_descriptor = "wsh(thresh(1,pk(xpub6BaZSKgpaVvibu2k78QsqeDWXp92xLHZxiu1WoqLB9hKhsBf3miBUDX7PJLgSPvkj66ThVHTqdnbXpeu8crXFmDUd4HeM4s4miQS2xsv3Qb/*)))#cwycq5xu"

src/poller.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn check_for_unvault(
361361
bitcoind: &BitcoinD,
362362
current_tip: &ChainTip,
363363
db_updates: &mut DbUpdates,
364-
coordinator_client: &coordinator::CoordinatorClient,
364+
coordinator_client: Option<&coordinator::CoordinatorClient>,
365365
) -> Result<Vec<VaultInfo>, PollerError> {
366366
let deleg_vaults = db_blank_vaults(db_path)?;
367367
let mut new_attempts = vec![];
@@ -398,15 +398,21 @@ fn check_for_unvault(
398398
// If needed to be canceled it will be marked as such when plugins tell us so.
399399
db_updates.new_unvaulted.insert(db_vault.id, db_vault);
400400

401-
let candidate_tx =
402-
match coordinator_client.get_spend_transaction(db_vault.deposit_outpoint.clone()) {
401+
let candidate_tx = if let Some(client) = coordinator_client {
402+
match client.get_spend_transaction(db_vault.deposit_outpoint.clone()) {
403403
Ok(res) => res,
404404
Err(_e) => {
405405
// Because we do not trust the coordinator, we consider it refuses to deliver the
406406
// spend tx if a communication error happened.
407407
None
408408
}
409-
};
409+
}
410+
} else {
411+
// No coordinator configuration was found in the config
412+
// therefore no spend transaction can be shared to plugins
413+
None
414+
};
415+
410416
let vault_info = VaultInfo {
411417
value: db_vault.amount,
412418
deposit_outpoint: db_vault.deposit_outpoint,
@@ -499,7 +505,7 @@ fn new_block(
499505
config: &Config,
500506
bitcoind: &BitcoinD,
501507
current_tip: &ChainTip,
502-
coordinator_client: &coordinator::CoordinatorClient,
508+
coordinator_client: Option<&coordinator::CoordinatorClient>,
503509
) -> Result<(), PollerError> {
504510
// We want to update our state for a given height, therefore we need to stop the updating
505511
// process if we notice that the chain moved forward under us (or we could end up assuming
@@ -584,11 +590,9 @@ pub fn main_loop(
584590
bitcoind: &BitcoinD,
585591
noise_privkey: NoisePrivkey,
586592
) -> Result<(), PollerError> {
587-
let coordinator_client = coordinator::CoordinatorClient::new(
588-
noise_privkey,
589-
config.coordinator_host,
590-
config.coordinator_noise_key,
591-
);
593+
let coordinator_client = config.coordinator_config.as_ref().map(|config| {
594+
coordinator::CoordinatorClient::new(noise_privkey, config.host, config.noise_key)
595+
});
592596
loop {
593597
let db_instance = db_instance(db_path)?;
594598
let bitcoind_tip = bitcoind.chain_tip();
@@ -605,7 +609,7 @@ pub fn main_loop(
605609
config,
606610
bitcoind,
607611
&bitcoind_tip,
608-
&coordinator_client,
612+
coordinator_client.as_ref(),
609613
) {
610614
Ok(()) => {}
611615
// Retry immediately if the tip changed while we were updating ourselves

0 commit comments

Comments
 (0)