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

Add option to skip channel checks #173

Merged
merged 1 commit into from
Nov 15, 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
7 changes: 5 additions & 2 deletions dlc-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,14 @@ where

/// Function to call to check the state of the currently executing DLCs and
/// update them if possible.
pub fn periodic_check(&mut self) -> Result<(), Error> {
pub fn periodic_check(&mut self, check_channels: bool) -> Result<(), Error> {
self.check_signed_contracts()?;
self.check_confirmed_contracts()?;
self.check_preclosed_contracts()?;
self.channel_checks()?;

if check_channels {
self.channel_checks()?;
}

Ok(())
}
Expand Down
32 changes: 16 additions & 16 deletions dlc-manager/tests/channel_execution_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,13 @@ fn channel_execution_test(test_params: TestParams, path: TestPath) {
alice_manager_send
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("to be able to do the periodic check");

bob_manager_send
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("to be able to do the periodic check");

assert_contract_state!(alice_manager_send, contract_id, Confirmed);
Expand Down Expand Up @@ -736,7 +736,7 @@ fn close_established_channel<F>(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("to be able to do the periodic check");

let wait = dlc_manager::manager::CET_NSEQUENCE;
Expand All @@ -746,7 +746,7 @@ fn close_established_channel<F>(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("to be able to do the periodic check");

// Should not have changed state before the CET is spendable.
Expand All @@ -757,7 +757,7 @@ fn close_established_channel<F>(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("to be able to do the periodic check");

//
Expand All @@ -768,16 +768,16 @@ fn close_established_channel<F>(
second
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("to be able to do the periodic check");

assert_channel_state!(second, channel_id, Signed, CounterClosed);
assert_contract_state!(second, contract_id, PreClosed);

generate_blocks(6);

first.lock().unwrap().periodic_check().unwrap();
second.lock().unwrap().periodic_check().unwrap();
first.lock().unwrap().periodic_check(true).unwrap();
second.lock().unwrap().periodic_check(true).unwrap();

assert_contract_state!(first, contract_id, Closed);
assert_contract_state!(second, contract_id, Closed);
Expand Down Expand Up @@ -811,7 +811,7 @@ fn cheat_punish<F: Fn(u64)>(
second
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("the check to succeed");

assert_channel_state!(second, channel_id, Signed, ClosedPunished);
Expand Down Expand Up @@ -1127,7 +1127,7 @@ fn collaborative_close<F: Fn(u64)>(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("the check to succeed");

assert_channel_state!(first, channel_id, Signed, CollaborativelyClosed);
Expand Down Expand Up @@ -1164,7 +1164,7 @@ fn renew_timeout(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("not to error");

assert_channel_state!(first, channel_id, Signed, Closed);
Expand All @@ -1189,7 +1189,7 @@ fn renew_timeout(
second
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("not to error");

assert_channel_state!(second, channel_id, Signed, Closed);
Expand All @@ -1202,7 +1202,7 @@ fn renew_timeout(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("not to error");

assert_channel_state!(first, channel_id, Signed, Closed);
Expand Down Expand Up @@ -1239,7 +1239,7 @@ fn settle_timeout(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("not to error");

assert_channel_state!(first, channel_id, Signed, Closing);
Expand All @@ -1264,7 +1264,7 @@ fn settle_timeout(
second
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("not to error");

assert_channel_state!(second, channel_id, Signed, Closing);
Expand All @@ -1277,7 +1277,7 @@ fn settle_timeout(
first
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("not to error");

assert_channel_state!(first, channel_id, Signed, Closing);
Expand Down
2 changes: 1 addition & 1 deletion dlc-manager/tests/manager_execution_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ macro_rules! periodic_check {
($d:expr, $id:expr, $p:ident) => {
$d.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("Periodic check error");

assert_contract_state!($d, $id, $p);
Expand Down
2 changes: 1 addition & 1 deletion sample/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub(crate) async fn poll_for_user_input(
manager_clone
.lock()
.unwrap()
.periodic_check()
.periodic_check(true)
.expect("Error doing periodic check.");
let contracts = manager_clone
.lock()
Expand Down