-
Notifications
You must be signed in to change notification settings - Fork 407
Require syntactically-valid blockchains in functional and unit tests #846
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
Require syntactically-valid blockchains in functional and unit tests #846
Conversation
Codecov Report
@@ Coverage Diff @@
## main #846 +/- ##
==========================================
- Coverage 90.61% 90.59% -0.03%
==========================================
Files 51 51
Lines 27140 27109 -31
==========================================
- Hits 24593 24559 -34
- Misses 2547 2550 +3
Continue to review full report at Codecov.
|
let (block_header, height) = { | ||
let blocks = node.blocks.lock().unwrap(); | ||
(blocks[blocks.len() - 1].0, blocks[blocks.len() - 1].1) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if this could be simplified a bit without the mutex. Is there a need for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, indeed. We just need interior mutability, so I swapped it for a refcell.
} | ||
|
||
pub fn disconnect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, header: &BlockHeader, height: u32) { | ||
node.chain_monitor.chain_monitor.block_disconnected(header, height); | ||
node.node.block_disconnected(header); | ||
node.node.test_process_background_events(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was removing this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though it happened int he wrong commit, I moved it to a later commit and since no previous tests relied on this behavior, removing this for test_unconf_chan
to use disconnect_block
is nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the commit message for d1d1d1f doesn't reference a valid commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops, its the immediately-preceeding "f" commit - it removes this hunk after "Add assertions for in-order block [dis]connection in ChannelManager"
lightning/src/ln/channelmanager.rs
Outdated
const CLTV_EXPIRY_DELTA: u16 = 6 * 12; //TODO? | ||
const CLTV_EXPIRY_DELTA: u16 = 6 * 6; //TODO? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this affect more than just the tests? If this was intentional, could you make a separate commit explaining the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #849.
6e5ecba
to
80fcdd3
Compare
Fixed a few comments and cleaned up the util method interface more, sadly it required reworking the commits so didn't leave fixup commits in between. Will respond to the further comments tomorrow. |
@@ -44,31 +44,50 @@ use std::sync::Mutex; | |||
use std::mem; | |||
use std::collections::HashMap; | |||
|
|||
pub const CHAN_CONFIRM_DEPTH: u32 = 100; | |||
pub const CHAN_CONFIRM_DEPTH: u32 = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes test logs much nicer to read 👍
5eed67e
to
48c1cba
Compare
Rebased on main/#849 and addressed all the comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Liking how functional_test_utils
is shaping up! Definitely makes the tests easier to read. Left one related comment.
I couldn't quite follow what some of the fixups corresponded to assuming they were going to be squashed with their parent commits. Left a couple comments.
} | ||
|
||
pub fn disconnect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, header: &BlockHeader, height: u32) { | ||
node.chain_monitor.chain_monitor.block_disconnected(header, height); | ||
node.node.block_disconnected(header); | ||
node.node.test_process_background_events(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the commit message for d1d1d1f doesn't reference a valid commit?
lightning/src/ln/functional_tests.rs
Outdated
let mut cfg = UserConfig::default(); | ||
// This test was written when the CLTV_EXPIRY_DELTA was fixed at 12*6, and expects it. | ||
cfg.channel_options.cltv_expiry_delta = 12*6; | ||
cfg.channel_options.announced_channel = true; | ||
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[Some(cfg.clone()), Some(cfg.clone()), Some(cfg.clone())]); | ||
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear what 444c154 is a fixup for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It reverts a hunk from #849 - I could probably not revert it, but I'd need to redo the test changes here to figure out how it used to be.
e0df57f
to
19ed011
Compare
Rebased after merge of 848. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from one minor comment.
Note this depends on #849 which needs to go first. |
It can be quite useful in debugging, and potentially also so for users.
fb1ecd6
to
a61289a
Compare
Sadly the connected-in-order tests have to be skipped in our normal test suite as many tests violate it. Luckily we can still enforce it in the tests which run in other crates. Co-authored-by: Matt Corallo <[email protected]> Co-authored-by: Jeffrey Czyz <[email protected]>
Many functional tests rely on being able to call block_connected arbitrarily, jumping back in time to confirm a transaction at a specific height. Instead, this takes us one step towards having a well-formed blockchain in the functional tests. We also take this opportunity to reduce the number of blocks connected during tests, requiring a number of constant tweaks in various functional tests. Co-authored-by: Valentine Wallace <[email protected]> Co-authored-by: Matt Corallo <[email protected]>
This expands the assertions on block ordering to apply to `#[cfg(test)]` builds in addition to normal builds, requiring that unit and functional tests have syntactically-valid (ie the previous block hash pointer and the heights match the blocks) blockchains. This requires a reasonably nontrivial diff in the functional tests however it is mostly straightforward changes.
See comment in the code. This commit exists only to aid reviewers.
See comment in the code, This commit exists only to aid reviewers.
This also reduces some needless clones and indirections.
a61289a
to
4ebfa1d
Compare
Squashed. The diff from val's last ACK rebased onto main (
|
This is an expansion of #831 and #838 will be rebased on it soon.