Skip to content

Tweak and Expand the chanmon_consistency fuzz target #753

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

I spent some time with chanmon_consistency to expand the errors it could catch. Luckily no bugs turned up (yet) from this work.

@codecov
Copy link

codecov bot commented Nov 18, 2020

Codecov Report

Merging #753 (401880f) into main (4e82003) will decrease coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #753      +/-   ##
==========================================
- Coverage   91.45%   91.38%   -0.07%     
==========================================
  Files          37       37              
  Lines       22249    22249              
==========================================
- Hits        20347    20333      -14     
- Misses       1902     1916      +14     
Impacted Files Coverage Δ
lightning/src/ln/functional_tests.rs 96.92% <0.00%> (-0.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e82003...6563f7a. Read the comment docs.

Comment on lines 417 to 425
match err.as_str() {
"Peer for first hop currently disconnected/pending monitor update!" => test_return!(),
_ if err.starts_with("Cannot push more than their max accepted HTLCs ") => test_return!(),
_ if err.starts_with("Cannot send value that would put us over the max HTLC value in flight our peer will accept ") => test_return!(),
_ if err.starts_with("Cannot send value that would put our balance under counterparty-announced channel reserve value") => test_return!(),
_ if err.starts_with("Cannot send value that would overdraw remaining funds.") => test_return!(),
_ if err.starts_with("Cannot send value that would not leave enough to pay for fees.") => test_return!(),
_ => panic!(err),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critically, we keep going after hitting an error, as there's no
reason channels should get out of sync even if a send fails.

Doesn't this still result in the test returning if a send fails?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - we only return from do_test if either we read a byte we don't know how to process or we run out of bytes. Prior to this we would test_return!() if we max out sending over a channel as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye, think it was changed as the quoted code is using test_return! but now is {}. So should be good.

Comment on lines -705 to +720
0x03 => *monitor_a.update_ret.lock().unwrap() = Ok(()),
0x04 => *monitor_b.update_ret.lock().unwrap() = Ok(()),
0x05 => *monitor_c.update_ret.lock().unwrap() = Ok(()),
0x06 => {
0x04 => *monitor_a.update_ret.lock().unwrap() = Ok(()),
0x05 => *monitor_b.update_ret.lock().unwrap() = Ok(()),
0x06 => *monitor_c.update_ret.lock().unwrap() = Ok(()),

0x08 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help me understand why values like 0x03 and 0x07 are skipped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep related message groups having the same binary prefix. Honestly it probably doesn't matter, but fuzzers do do some bit-twiddling-based tweaking and I figured no reason to not have bit-twiddling often have similar effects. I noted it in a new comment.

Instead of simply always considering a payment-send failure as
acceptable (and aborting fuzzing), we check that a payment send
failure is from a list of errors that we know we can hit, mostly
around maxing out our channel balance.

Critically, we keep going after hitting an error, as there's no
reason channels should get out of sync even if a send fails.
This should make it a bit easier for the fuzzer to hit any given
balance breakdown during run as well as tweaks the command strings
to be more bit-pattern friendly.
In previous versions of related commits, the macros in
chanmon_consistency ended up blowing up rustc a bit resulting in
20+GB memory usage and long compile times. Shorter function bodies
by avoiding macros where possible fix this.
We should never generate Ignore-action HandleError events anymore
This adds a new command string in the chanmon_consistency fuzzer
which tests that, once all pending HTLCs are settled, at least one
side of a channel can still send funds.

While this should have caught the recent(ish) spec bug where
channels could get stuck, I did not attempt to reproduce said bug
with this patch.
@TheBlueMatt
Copy link
Collaborator Author

Gonna take so that we can talk about/analyze things like #757 against git latest instead of against some random branch.

@TheBlueMatt TheBlueMatt merged commit 8f10a1d into lightningdevkit:main Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants