From 1c6819ac4438c81e8166110d91350954cd6d9494 Mon Sep 17 00:00:00 2001 From: Stjepan Golemac Date: Wed, 18 Oct 2023 14:59:04 +0200 Subject: [PATCH] feat: strict mode turned off by default --- romeo/src/bitcoin_client.rs | 1 + romeo/src/config.rs | 7 +++++++ romeo/src/state.rs | 28 ++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/romeo/src/bitcoin_client.rs b/romeo/src/bitcoin_client.rs index 9007b6cd..5852e46c 100644 --- a/romeo/src/bitcoin_client.rs +++ b/romeo/src/bitcoin_client.rs @@ -270,6 +270,7 @@ mod tests { stacks_credentials, stacks_network, hiro_api_key: None, + strict: true, }; let client = Client::new(conf.clone()).unwrap(); diff --git a/romeo/src/config.rs b/romeo/src/config.rs index 5d9e7377..cb0ad9dc 100644 --- a/romeo/src/config.rs +++ b/romeo/src/config.rs @@ -56,6 +56,9 @@ pub struct Config { /// optional api key used for the stacks node pub hiro_api_key: Option, + + /// Strict mode + pub strict: bool, } impl Config { @@ -95,6 +98,7 @@ impl Config { config_file.contract_name.as_str(), ), hiro_api_key, + strict: config_file.strict.unwrap_or_default(), }) } @@ -141,6 +145,9 @@ struct ConfigFile { /// optional api key used for the stacks node pub hiro_api_key: Option, + + /// Strict mode + pub strict: Option, } impl ConfigFile { diff --git a/romeo/src/state.rs b/romeo/src/state.rs index 99d5e72a..3a877bc2 100644 --- a/romeo/src/state.rs +++ b/romeo/src/state.rs @@ -142,7 +142,7 @@ impl State { self.process_set_contract_public_key(txid) } Event::StacksTransactionUpdate(txid, status) => self - .process_stacks_transaction_update(txid, status) + .process_stacks_transaction_update(txid, status, config) .into_iter() .collect(), Event::BitcoinTransactionUpdate(txid, status) => self @@ -221,6 +221,7 @@ impl State { &mut self, txid: StacksTxId, status: TransactionStatus, + config: &Config, ) -> Vec { let mut tasks = self.get_bitcoin_transactions(); @@ -238,17 +239,32 @@ impl State { has_pending_task, } = public_key_setup else { - panic!("Got an {:?} status update for a public key set Stacks transaction that is not acknowledged: {}", status, txid); + if config.strict { + panic!("Got an {:?} status update for a public key set Stacks transaction that is not acknowledged: {}", status, txid); + } else { + debug!("Ignoring a Stacks transaction update for a non acknowledged transaction"); + return vec![]; + } }; if txid != *current_txid { - panic!("Got an {:?} status update for a Stacks transaction that is not public key set: {}", status, txid); + if config.strict { + panic!("Got an {:?} status update for a Stacks transaction that is not public key set: {}", status, txid); + } else { + debug!("Ignoring a Stacks transaction update for a non public key set transaction"); + return vec![]; + } } if !*has_pending_task { - panic!( - "Got an {:?} status update for a public key set Stacks transaction that doesn't have a pending task: {}", status, txid - ); + if config.strict { + panic!( + "Got an {:?} status update for a public key set Stacks transaction that doesn't have a pending task: {}", status, txid + ); + } else { + debug!("Ignoring a Stacks transaction update for a transaction that doesn't have a pending task"); + return vec![]; + } } *current_status = status.clone();