Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: strict mode turned off by default #309

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions romeo/src/bitcoin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ mod tests {
stacks_credentials,
stacks_network,
hiro_api_key: None,
strict: true,
};

let client = Client::new(conf.clone()).unwrap();
Expand Down
7 changes: 7 additions & 0 deletions romeo/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@

/// optional api key used for the stacks node
pub hiro_api_key: Option<String>,

/// Strict mode
pub strict: bool,
}

impl Config {
Expand Down Expand Up @@ -95,6 +98,7 @@
config_file.contract_name.as_str(),
),
hiro_api_key,
strict: config_file.strict.unwrap_or_default(),

Check warning on line 101 in romeo/src/config.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/config.rs#L101

Added line #L101 was not covered by tests
})
}

Expand Down Expand Up @@ -141,6 +145,9 @@

/// optional api key used for the stacks node
pub hiro_api_key: Option<String>,

/// Strict mode
pub strict: Option<bool>,
}

impl ConfigFile {
Expand Down
28 changes: 22 additions & 6 deletions romeo/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
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
Expand Down Expand Up @@ -221,6 +221,7 @@
&mut self,
txid: StacksTxId,
status: TransactionStatus,
config: &Config,

Check warning on line 224 in romeo/src/state.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/state.rs#L224

Added line #L224 was not covered by tests
) -> Vec<Task> {
let mut tasks = self.get_bitcoin_transactions();

Expand All @@ -238,17 +239,32 @@
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);

Check warning on line 243 in romeo/src/state.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/state.rs#L242-L243

Added lines #L242 - L243 were not covered by tests
} else {
debug!("Ignoring a Stacks transaction update for a non acknowledged transaction");
return vec![];

Check warning on line 246 in romeo/src/state.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/state.rs#L245-L246

Added lines #L245 - L246 were not covered by tests
}
};

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);

Check warning on line 252 in romeo/src/state.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/state.rs#L251-L252

Added lines #L251 - L252 were not covered by tests
} else {
debug!("Ignoring a Stacks transaction update for a non public key set transaction");
return vec![];

Check warning on line 255 in romeo/src/state.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/state.rs#L254-L255

Added lines #L254 - L255 were not covered by tests
}
}

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
);

Check warning on line 263 in romeo/src/state.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/state.rs#L260-L263

Added lines #L260 - L263 were not covered by tests
} else {
debug!("Ignoring a Stacks transaction update for a transaction that doesn't have a pending task");
return vec![];

Check warning on line 266 in romeo/src/state.rs

View check run for this annotation

Codecov / codecov/patch

romeo/src/state.rs#L265-L266

Added lines #L265 - L266 were not covered by tests
}
}

*current_status = status.clone();
Expand Down
Loading