Skip to content

attempt to create API for regular Pings #382

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

Closed
wants to merge 185 commits into from
Closed
Changes from all commits
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
5cbc49c
Merge pull request #1 from rust-bitcoin/master
Aleru Sep 7, 2019
4639eac
first add
Sep 20, 2019
2f76e63
updateS
Sep 22, 2019
ff585e3
add
Sep 22, 2019
64b71b2
commit
Sep 27, 2019
83f352e
commit
Sep 29, 2019
d549e65
updates
Sep 30, 2019
f9ff14e
s
Sep 30, 2019
e3ab572
fixed first bug :D
Oct 1, 2019
8cab2a6
fixed bug for real this time... probably should read docs of related …
Oct 1, 2019
fed5544
coming along nicely
Oct 2, 2019
5b744b3
need docs and test
Oct 3, 2019
1a93d27
updates
Oct 4, 2019
e5aaf3c
commit
Oct 8, 2019
ddfd4ac
x
Oct 9, 2019
8220c8f
n
Oct 12, 2019
b3d42db
another update
Oct 17, 2019
3b0f773
cleaning it up a bit for groupwork
Oct 18, 2019
6d2b565
more cleaning :P
Oct 18, 2019
3e1105f
add todot
Oct 18, 2019
c7a85ee
remove no longer relevant comment
Oct 18, 2019
5cac426
fixed issue of disconnecting peer
Oct 18, 2019
2b5730d
removed extra comment
Oct 18, 2019
cb3ecde
probably ready for PR
Oct 19, 2019
ed56c4f
ready for pr... for real this time!
Oct 19, 2019
707b5d5
ready for pr act 3
Oct 19, 2019
a5dff8e
ready for pr act 4
Oct 19, 2019
5b9a4b6
remove threads
Oct 23, 2019
25013fb
just sharing work, not ready for review
Nov 4, 2019
5641c3b
just sharing work... need to rebase
Nov 4, 2019
4be33a2
Remove long-stale TODO
TheBlueMatt Dec 21, 2018
ba6d43c
Log errors forwarding/failing HTLCs
TheBlueMatt Dec 21, 2018
e11d7d8
Macro-out BroadcastChannelUpdate-on-channel-close in func tests
TheBlueMatt Dec 21, 2018
97c2c86
Fail HTLC backwards on unrevoked remote commitment tx broadcast
TheBlueMatt Dec 21, 2018
8c847f8
More comments/hardening test_fail_backwards_unrevoked_remote_announce
Dec 30, 2018
4ec6b1a
Log resolution of offered HTLC by HTLC-timeout tx
Dec 30, 2018
24facec
Move fail-backwards up for no to-remote output claims
TheBlueMatt Dec 21, 2018
94345f8
Add dust mode to test_commitment_revoked_fail_backward_exhaustive
TheBlueMatt Dec 27, 2018
c18fa4a
Add test_commitment_revoked_fail_backward_exhaustive no_to_remote
TheBlueMatt Dec 27, 2018
9096e11
Macro-DRY HTLC back-fails for revoked remote transaction broadcast
TheBlueMatt Dec 27, 2018
a4fd87c
Fix stale comment in functional_tests after failing back async
TheBlueMatt Jan 5, 2019
ff11e96
Fix multi-remote-HTLC-claim preimage learning
TheBlueMatt Jan 6, 2019
380f97a
Fix source name in is_resolving_htlc_output
TheBlueMatt Jan 7, 2019
55e5eab
Simplify and expand logging in is_resolving_htlc_output
TheBlueMatt Jan 6, 2019
300e69a
Make HTLCOutputInCommitment::transaction_output_index an Option
TheBlueMatt Jan 6, 2019
1091ff6
Merge tracking of HTLCs-in-commitment with outbound-HTLCs
TheBlueMatt Jan 4, 2019
8952d42
Test for failing channel after local commitment dust HTLC timeout
TheBlueMatt Jan 7, 2019
2cd1f70
Check for timing-out HTLCs in remote unrevoked commitments
TheBlueMatt Jan 4, 2019
2e42f4a
Fix comment spelling and clarify algebra a bit.
TheBlueMatt Jan 11, 2019
70d3236
Add option to use libfuzzer sys in full_stack_target
TheBlueMatt Dec 3, 2018
248d170
Add doc to full_stack_target
TheBlueMatt Jan 8, 2019
e6d6dee
Switch to bitcoin_hashes Hash160 in full_stack_target
TheBlueMatt Jan 7, 2019
f1bb325
Fix dead_code warnings in fuzztarget builds
TheBlueMatt Jan 8, 2019
0e10d23
Wrote test to explicitly test BOLT 2 requirements for update_add_htlc
philipr-za Jan 15, 2019
9453423
Fix Router min HTLC comparison
TheBlueMatt Oct 2, 2018
4a99297
Upgrade to secp256k1 v12, bitcoin v16, and crates bitcoin_hashes
TheBlueMatt Jan 16, 2019
da74303
Drop verification context from keys manager
TheBlueMatt Jan 16, 2019
3add21e
Ensure Message always unwraps in fuzztarget
TheBlueMatt Jan 17, 2019
67ad0ba
Remove unused argument from handle_error!
TheBlueMatt Jan 8, 2019
e6a05f5
Rewrite monitor_update_failed as it didn't capture all the options
TheBlueMatt Jan 8, 2019
71b1b95
Fix handling RAA when a monitor update previously failed
TheBlueMatt Jan 9, 2019
e42c3aa
Implement Writeable/Readable for Option<T>
Jan 23, 2019
08dff2a
Implement serialize/deserialize for Router.
Dec 16, 2018
9915a1d
Added tests to check the bolt 2 specs for Sending Node Channel
Nov 30, 2018
5493074
Split up functional_tests into utils and the tests themselves
TheBlueMatt Jan 23, 2019
ec7eefb
Split up monitor-update-failed tests and other functional tests
TheBlueMatt Jan 23, 2019
3977cfa
Fix spelling in do_test_monitor_temporary_update_fail comment
TheBlueMatt Jan 21, 2019
575ccd3
Fix indentation in a few new tests
TheBlueMatt Jan 23, 2019
7d0a276
Fix typos
rex4539 Jan 24, 2019
f79c98f
Fix AwaitingRAA on RAA receipt when monitor updating had failed
TheBlueMatt Jan 11, 2019
949e565
Add a test for the ordering setting in channel_reestablish handling
TheBlueMatt Jan 17, 2019
0e90f64
Remove incorrect debug_assert!() from reestablish handling and test
TheBlueMatt Jan 18, 2019
7e44576
Fix responding to RAAs when monitor updating had already failed
TheBlueMatt Jan 14, 2019
ad47150
Fix holding cell freeing in case we fail to add some HTLC
TheBlueMatt Jan 21, 2019
745e579
Handle monitor update failures in two more places
TheBlueMatt Jan 15, 2019
b231ae7
Drop pending outbound messages on peer disconnection
TheBlueMatt Jan 8, 2019
ef90dcb
Expose CommitmentUpdate contents
TheBlueMatt Jan 8, 2019
ce6cf6c
Take the logger from test_utils into fuzz::test_utils
TheBlueMatt Jan 8, 2019
6f12cdd
Add a fuzz target to test monitor update failure handling
TheBlueMatt Jan 7, 2019
48d7969
Send back the actual received amount, not expected on HTLC fails
TheBlueMatt Jan 22, 2019
9adb49e
Bump bitcoin_hashes to 0.3
TheBlueMatt Jan 25, 2019
f1787db
log_trace information about commitment txn as they're being built
TheBlueMatt Jan 8, 2019
b2f1925
log_trace HTLC transitions in RAA handling (best reviewed with -b)
TheBlueMatt Jan 14, 2019
483e8ef
log_trace HTLC changes in Channel::get_update_fulfill_htlc
TheBlueMatt Jan 15, 2019
64e66e2
Log information about channel freeze/restore from monitor updates
TheBlueMatt Jan 15, 2019
a9f644b
Bump version to 0.0.8
TheBlueMatt Jan 25, 2019
cf7e322
Explicit tests for update_*_htlc message BOLT2 requirements
philipr-za Jan 23, 2019
e8079ce
Fix uneccessary mut found by 1.22
TheBlueMatt Feb 11, 2019
f0c8f6f
util: Derive PartialEq for Level
dongcarl Feb 7, 2019
bc47f28
msgs: Reformulate unknown bits calculation w/ any
dongcarl Feb 7, 2019
c1c1f9e
Add bolt7 msgs serialization tests
Jan 20, 2019
c095ae1
Add bolt2 msgs serialization tests
Feb 14, 2019
edf6b65
Add bolt1 msgs serialization tests
Jan 27, 2019
860488b
Clarify a bit full_stack_target test_no_existing_test_breakage
Feb 28, 2019
456150d
migration to rust-bitcoin 0.17
tamasblummer Mar 4, 2019
698f5c8
Move fail_reason into OutboundHTLCState states
TheBlueMatt Mar 3, 2019
ebd4191
Add a useful log_trace before we release holding cell.
TheBlueMatt Mar 3, 2019
636fa81
Add macro for PaymentSent event checking in test_utils
TheBlueMatt Mar 4, 2019
1b51ef5
Fix inbound channel reserve check for removed-outbound-HTLCs
TheBlueMatt Feb 27, 2019
d1e7151
Fix potential overflow bug introduced in channel reserve check fix
TheBlueMatt Mar 3, 2019
f3b7d1a
Fix HTLC-output-in-commitment sorting for duplicate-HTLCs
TheBlueMatt Mar 7, 2019
7ccb9aa
Remove unused BIP69 input sorting
TheBlueMatt Mar 7, 2019
cacd51f
Extract preimage from revoked HTLC-Success to claim backward
Mar 15, 2019
4e5d744
Update docs for TemporaryFailure to note other use-cases
TheBlueMatt Mar 25, 2019
0e69489
Improve README usability
dongcarl Mar 25, 2019
343b2e1
Add test for tie breaking when sorting outputs
dongcarl Mar 25, 2019
7a85d98
Use more Writeable/Readable for Option<T> in ChannelMonitor
Apr 10, 2019
8ee177f
Make channel open confs configurable (and change from 12 to 6)
sgeisler Mar 26, 2019
b28283a
Add FeeEstimator in ChannelMonitor
Apr 9, 2019
c983ba0
Add fee estimation in check_spend_remote_htlc
Apr 9, 2019
8028e81
Add unit test for get_witnesses_weight
Apr 10, 2019
9a51661
Assert that our weight prediction can't result in unspendable txn
TheBlueMatt Apr 14, 2019
75dfcdf
Add log_trace on completion of monitor update restoration in Chan
TheBlueMatt Mar 5, 2019
2c78fff
Rewrite Channel resend tracking to make it much more reliable
TheBlueMatt Mar 5, 2019
5fda2d2
Fix crash in chanmon_fail_consistency due to fuzz hash collisions
TheBlueMatt Mar 7, 2019
68e3b31
Bump rust-bitcoin dep to 0.18
TheBlueMatt Jun 1, 2019
9272650
Add subcrate that implements network socket handling with Tokio
TheBlueMatt Jun 1, 2019
5e40ff1
Bump version to 0.0.9 to get current master fixes uploaded.
TheBlueMatt Jun 1, 2019
d65409e
Gracefully handle fee-larger-than-claimed-value in ChannelMonitor
TheBlueMatt Jun 14, 2019
fbd3611
Add log_trace on to_remote/to_local inclusion in commitment tx
Jul 3, 2019
4f6f5bd
Drop time_created in HTLCAwaitingACK::AddHTLC (we can use the CLTV)
TheBlueMatt Jul 18, 2019
2877b19
Drop system clock calls for PendingHTLCsForwardable events.
TheBlueMatt Jul 18, 2019
8367bce
Add balance and is_live fields to ChannelDetails
TheBlueMatt Jun 1, 2019
f28fc9c
Track HTLC-failure trigger tx until anti-reorg delay reached
May 31, 2019
2a3ca64
Implement block_disconnect for pruning of waiting-conf HTLC updates
Feb 5, 2019
6b51250
Delay failure of non-dust HTLC-outputs until solving timeout tx matures
Feb 7, 2019
b6419eb
Fail back dust HTLC of local commitment tx after enough confirmations
Feb 7, 2019
195648d
Add block_disconnecting tests to cancel HTLC failure updates
Feb 9, 2019
36c96bc
Move htlc_updated_waiting_threshold_conf to an OnchainEvent model
Mar 31, 2019
d1102eb
Add more comments about timelock assumptions and security model
Jul 18, 2019
02d2125
Add in-flight claim-tx tracking
Mar 31, 2019
4ebb1f9
Implement dynamic height timer for bump candidates txn
Jul 18, 2019
9c5d182
Provide peer local_features to handle_open_channel/accept_channel
Jul 9, 2019
7c5f744
Support option_upfront_shutdown_script for local peer
Jul 9, 2019
02002cb
Implement option_upfront_shutdown_script user-side
Jul 9, 2019
75c6cca
Pass LocalFeatures flag to channel creation test utilities
Jul 11, 2019
6d93853
Pass UserConfig to node creation test utilities
Jul 11, 2019
a1357cb
Test option_upfront_shutdown_script
Jul 11, 2019
d80142c
Drop rng and SystemTime calls from KeysManager
TheBlueMatt Jul 18, 2019
8eca05a
Remove dangling link in fuzz/
TheBlueMatt Jul 19, 2019
395b71e
Move travis fuzzing to 1.34.2 to get integer atomics
TheBlueMatt Jul 19, 2019
63f7b0f
Update commitment tx to match actual tx (dunno when it broke)
TheBlueMatt Jul 19, 2019
441d0f2
Stop using rng in peer_channel_encryptor to generate ephemeral keys
TheBlueMatt Jul 19, 2019
5e60ddb
Make rand a dev-dep by having the user randomize HTLC forward delay
TheBlueMatt Jul 19, 2019
67c594e
forbid unsafe
tamasblummer Jul 24, 2019
0580ca1
Fix some newly-introduced unused-$THING warnings
TheBlueMatt Jul 22, 2019
3f69d6e
Drop msgs bound for a disconnecting peer at disconnect time
TheBlueMatt Jul 23, 2019
6229930
Add deserialize+load steps to chanmon_fail_consistency (fixes #327)
TheBlueMatt Jul 22, 2019
332ff2c
Bump progress tracker
TheBlueMatt Jul 24, 2019
c1b8015
Fix: use our_to_self_delay in check_spend_remote_htlc
Jul 19, 2019
bac63d8
Move BREAKDOWN_TIMEOUT/MAX_LOCAL_BREAKDOWN_TIMEOUT in ChannelManager
Jul 19, 2019
888d584
Add user configurable csv delay encumbering channel refund output,
Jul 19, 2019
51a1e28
Add test_user_configurable_csv_delay
Jul 23, 2019
a6ee6b4
Fix unused variable introduced in my changes in bdbf5666a9d693b9bf1
TheBlueMatt Jul 24, 2019
7bcd554
Do not require upfront_shutdown as the security gain is marginal
TheBlueMatt Jul 25, 2019
60eceee
Make chanmon_fail_consistency slightly less aggressive
TheBlueMatt Jul 25, 2019
39da3bc
Generate codecov.io reports
TheBlueMatt Jul 25, 2019
d573451
Drop update_fee TODOs as we're gonna drop it before 0.1 anyway
TheBlueMatt Jul 28, 2019
5c87798
Drop TODO suggesting we avoid a test-only function to get chan keys
TheBlueMatt Jul 28, 2019
10b34bd
Handle monitor update failures during funding on the funder side
TheBlueMatt Jul 26, 2019
9aed677
Allow a counterparty to resend their funding_locked before ours
TheBlueMatt Jul 29, 2019
b74bd45
Handle monitor update failure during funding on the fundee side
TheBlueMatt Jul 29, 2019
bf08564
Fix travis failure if previous travis run on branch failed to build
TheBlueMatt Jul 30, 2019
24d80c8
Make temporary channel ids unique in full_stack_target
TheBlueMatt Jul 29, 2019
990b9c3
Make SocketDescriptor::send_data take slice instead of vec and offset
rrybarczyk Jul 31, 2019
7cba7a3
Add net-tokio/target to gitignore
rrybarczyk Jul 31, 2019
ed7c5d2
Clarify policy applied in send htlc error msgs
Feb 14, 2019
e7a03df
Support option_data_loss_protect for remote peer
Jul 10, 2019
a70547e
Enforce option_data_loss_protect user-side
Jul 10, 2019
2446b06
Make get_latest_local_commitment_txn public
Aug 1, 2019
9a424f0
Cache to_remote_script if we are fallen-behind
Aug 2, 2019
3e3d523
Add test_data_loss_protect
Jul 23, 2019
9ae5094
tests: Add sanity tests for ChannelOpens
dongcarl Aug 2, 2019
850300b
Updated bitcoin, bitcoin_hashes and secp256k1 dependencies
elichai Aug 23, 2019
b985cb3
Cast weights to u64 to support the new rust-bitcoin api
elichai Aug 23, 2019
52101f5
Remove useless test framework warnings
Oct 26, 2019
7f53143
Disable some useless lints
TheBlueMatt Oct 28, 2019
ef95091
remove threads
Oct 23, 2019
544d789
just sharing work... need to rebase
Nov 4, 2019
59f053a
rebased
Nov 9, 2019
9ac9c72
Update lib.rs
Aleru Nov 10, 2019
e335cd6
Update functional_tests.rs
Aleru Nov 10, 2019
e63c76d
Update functional_tests.rs
Aleru Nov 10, 2019
002a909
Update functional_tests.rs
Aleru Nov 10, 2019
1ef8ef6
Update functional_tests.rs
Aleru Nov 10, 2019
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
94 changes: 89 additions & 5 deletions src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{cmp,error,hash,fmt};


use bitcoin_hashes::sha256::Hash as Sha256;
use bitcoin_hashes::sha256::HashEngine as Sha256Engine;
use bitcoin_hashes::{HashEngine, Hash};
Expand Down Expand Up @@ -115,7 +116,9 @@ struct Peer {
pending_read_is_header: bool,

sync_status: InitSyncTracker,
}

ping_tracker: u8,
}

impl Peer {
/// Returns true if the channel announcements/updates for the given channel should be
Expand Down Expand Up @@ -286,6 +289,8 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
pending_read_is_header: false,

sync_status: InitSyncTracker::NoSyncRequested,

ping_tracker: 0,
}).is_some() {
panic!("PeerManager driver duplicated descriptors!");
};
Expand Down Expand Up @@ -322,6 +327,8 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
pending_read_is_header: false,

sync_status: InitSyncTracker::NoSyncRequested,

ping_tracker: 0,
}).is_some() {
panic!("PeerManager driver duplicated descriptors!");
};
Expand Down Expand Up @@ -684,10 +691,10 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
encode_and_send_msg!(resp, 19);
}
},
19 => {
try_potential_decodeerror!(msgs::Pong::read(&mut reader));
19 => {
peer.ping_tracker = 0;
try_potential_decodeerror!(msgs::Pong::read(&mut reader));
},

// Channel control:
32 => {
let msg = try_potential_decodeerror!(msgs::OpenChannel::read(&mut reader));
Expand Down Expand Up @@ -1097,15 +1104,62 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
}
};
}

/// insure we recieved pong message from all peers or disconnect the peers then ping all peers
pub fn timer_tick_occurred(&self){

let mut peers_lock = self.peers.lock().unwrap();
let peers = peers_lock.borrow_parts();

for (Descriptor, mut Peer) in peers.peers.iter_mut() {

//read all events that have been sent from the Peer
let mut descriptor = Descriptor.clone();
let data: Vec<u8> = Vec::new();
let res = match self.do_read_event(&mut descriptor, data){
Ok(pause_read) => pause_read,
Err(e) => panic!("something is wrong"),
};

// Disconect the Peer if there is an outstanding ping for which we have not been ponged
if Peer.ping_tracker > 0 {
self.disconnect_event(Descriptor);
}


else {

let ping = msgs::Ping {
ponglen: 64,
byteslen: 64,
};

Peer.pending_outbound_buffer.push_back(Peer.channel_encryptor.encrypt_message(&encode_msg!(ping, 18)));

let mut descriptor = Descriptor.clone();
self.do_attempt_write_data(&mut descriptor, &mut Peer);
Peer.ping_tracker += 1;


}
}
}
}





#[cfg(test)]
mod tests {
use ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor};
use ln::msgs;
use util::events;
use util::test_utils;
use util::logger::Logger;
use util::ser::{Writeable, Writer, Readable};

use std::collections::{HashMap,hash_map,HashSet,LinkedList};

use secp256k1::Secp256k1;
use secp256k1::key::{SecretKey, PublicKey};
Expand Down Expand Up @@ -1168,7 +1222,6 @@ mod tests {

let secp_ctx = Secp256k1::new();
let their_id = PublicKey::from_secret_key(&secp_ctx, &peers[1].our_node_secret);

let chan_handler = test_utils::TestChannelMessageHandler::new();
chan_handler.pending_events.lock().unwrap().push(events::MessageSendEvent::HandleError {
node_id: their_id,
Expand All @@ -1180,4 +1233,35 @@ mod tests {
peers[0].process_events();
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 0);
}

#[test]
fn ttt(){

let mut peers = create_network(2);
establish_connection(&peers[0], &peers[1]);
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 1);



for (peer_manager) in peers.iter(){
for (key, val) in peer_manager.peers.lock().unwrap().peers.iter_mut(){
let secp_ctx = Secp256k1::new();
val.their_node_id = std::option::Option::Some(PublicKey::from_secret_key(&secp_ctx, &peer_manager.our_node_secret));

}
}

peers[0].timer_tick_occurred();
//peers[1].process_events();

//assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 1);

//peers[0].timer_tick_occurred();
//peers[0].timer_tick_occurred();

//assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 0);

}

}