@@ -347,14 +347,15 @@ static void peer_breakdown(struct peer *peer)
347
347
if (peer -> closing .their_sig ) {
348
348
const struct bitcoin_tx * close = mk_bitcoin_close (peer , peer );
349
349
log_unusual (peer -> log , "Peer breakdown: sending close tx" );
350
- broadcast_tx (peer , close , NULL );
350
+ broadcast_tx (peer -> dstate -> topology , peer , close , NULL );
351
351
tal_free (close );
352
352
/* If we have a signed commit tx (maybe not if we just offered
353
353
* anchor, or they supplied anchor, or no outputs to us). */
354
354
} else if (peer -> local .commit && peer -> local .commit -> sig ) {
355
355
log_unusual (peer -> log , "Peer breakdown: sending commit tx" );
356
356
sign_commit_tx (peer );
357
- broadcast_tx (peer , peer -> local .commit -> tx , NULL );
357
+ broadcast_tx (peer -> dstate -> topology , peer ,
358
+ peer -> local .commit -> tx , NULL );
358
359
} else {
359
360
log_info (peer -> log , "Peer breakdown: nothing to do" );
360
361
/* We close immediately. */
@@ -644,7 +645,8 @@ static bool open_ouranchor_pkt_in(struct peer *peer, const Pkt *pkt)
644
645
if (db_commit_transaction (peer ) != NULL )
645
646
return peer_database_err (peer );
646
647
647
- broadcast_tx (peer , peer -> anchor .tx , funding_tx_failed );
648
+ broadcast_tx (peer -> dstate -> topology ,
649
+ peer , peer -> anchor .tx , funding_tx_failed );
648
650
peer_watch_anchor (peer , peer -> local .mindepth );
649
651
return true;
650
652
}
@@ -878,7 +880,7 @@ static void their_htlc_added(struct peer *peer, struct htlc *htlc,
878
880
}
879
881
880
882
if (abs_locktime_to_blocks (& htlc -> expiry ) <=
881
- get_block_height (peer -> dstate ) + peer -> dstate -> config .min_htlc_expiry ) {
883
+ get_block_height (peer -> dstate -> topology ) + peer -> dstate -> config .min_htlc_expiry ) {
882
884
log_unusual (peer -> log , "HTLC %" PRIu64 " expires too soon:"
883
885
" block %u" ,
884
886
htlc -> id , abs_locktime_to_blocks (& htlc -> expiry ));
@@ -888,7 +890,7 @@ static void their_htlc_added(struct peer *peer, struct htlc *htlc,
888
890
}
889
891
890
892
if (abs_locktime_to_blocks (& htlc -> expiry ) >
891
- get_block_height (peer -> dstate ) + peer -> dstate -> config .max_htlc_expiry ) {
893
+ get_block_height (peer -> dstate -> topology ) + peer -> dstate -> config .max_htlc_expiry ) {
892
894
log_unusual (peer -> log , "HTLC %" PRIu64 " expires too far:"
893
895
" block %u" ,
894
896
htlc -> id , abs_locktime_to_blocks (& htlc -> expiry ));
@@ -1313,7 +1315,7 @@ static bool closing_pkt_in(struct peer *peer, const Pkt *pkt)
1313
1315
* SHOULD sign and broadcast the final closing transaction.
1314
1316
*/
1315
1317
close = mk_bitcoin_close (peer , peer );
1316
- broadcast_tx (peer , close , NULL );
1318
+ broadcast_tx (peer -> dstate -> topology , peer , close , NULL );
1317
1319
tal_free (close );
1318
1320
return false;
1319
1321
}
@@ -2058,7 +2060,8 @@ static bool fulfill_onchain(struct peer *peer, struct htlc *htlc)
2058
2060
return false;
2059
2061
peer -> onchain .resolved [i ]
2060
2062
= htlc_fulfill_tx (peer , i );
2061
- broadcast_tx (peer , peer -> onchain .resolved [i ], NULL );
2063
+ broadcast_tx (peer -> dstate -> topology ,
2064
+ peer , peer -> onchain .resolved [i ], NULL );
2062
2065
return true;
2063
2066
}
2064
2067
}
@@ -2106,14 +2109,14 @@ const char *command_htlc_add(struct peer *peer, u64 msatoshi,
2106
2109
return "bad expiry" ;
2107
2110
}
2108
2111
2109
- if (expiry < get_block_height (peer -> dstate ) + peer -> dstate -> config .min_htlc_expiry ) {
2112
+ if (expiry < get_block_height (peer -> dstate -> topology ) + peer -> dstate -> config .min_htlc_expiry ) {
2110
2113
log_unusual (peer -> log , "add_htlc: fail: expiry %u is too soon" ,
2111
2114
expiry );
2112
2115
* error_code = BAD_REQUEST_400 ;
2113
2116
return "expiry too soon" ;
2114
2117
}
2115
2118
2116
- if (expiry > get_block_height (peer -> dstate ) + peer -> dstate -> config .max_htlc_expiry ) {
2119
+ if (expiry > get_block_height (peer -> dstate -> topology ) + peer -> dstate -> config .max_htlc_expiry ) {
2117
2120
log_unusual (peer -> log , "add_htlc: fail: expiry %u is too far" ,
2118
2121
expiry );
2119
2122
* error_code = BAD_REQUEST_400 ;
@@ -2842,7 +2845,7 @@ static bool peer_first_connected(struct peer *peer,
2842
2845
peer -> conn = conn ;
2843
2846
io_set_finish (conn , peer_disconnect , peer );
2844
2847
2845
- peer -> anchor .min_depth = get_block_height (peer -> dstate );
2848
+ peer -> anchor .min_depth = get_block_height (peer -> dstate -> topology );
2846
2849
2847
2850
/* FIXME: Attach IO logging for this peer. */
2848
2851
if (!netaddr_from_fd (io_conn_fd (conn ), addr_type , addr_protocol , & addr ))
@@ -3249,7 +3252,7 @@ AUTODATA(json_command, &connect_command);
3249
3252
/* Have any of our HTLCs passed their deadline? */
3250
3253
static bool any_deadline_past (struct peer * peer )
3251
3254
{
3252
- u32 height = get_block_height (peer -> dstate );
3255
+ u32 height = get_block_height (peer -> dstate -> topology );
3253
3256
struct htlc_map_iter it ;
3254
3257
struct htlc * h ;
3255
3258
@@ -3272,7 +3275,7 @@ static bool any_deadline_past(struct peer *peer)
3272
3275
3273
3276
static void check_htlc_expiry (struct peer * peer )
3274
3277
{
3275
- u32 height = get_block_height (peer -> dstate );
3278
+ u32 height = get_block_height (peer -> dstate -> topology );
3276
3279
struct htlc_map_iter it ;
3277
3280
struct htlc * h ;
3278
3281
@@ -3400,8 +3403,9 @@ static enum watch_result anchor_depthchange(struct peer *peer,
3400
3403
return KEEP_WATCHING ;
3401
3404
}
3402
3405
3403
- void peers_new_block (struct lightningd_state * dstate , unsigned int height )
3406
+ void notify_new_block (struct topology * topo , unsigned int height )
3404
3407
{
3408
+ struct lightningd_state * dstate = tal_parent (topo );
3405
3409
/* This is where we check for anchor timeouts. */
3406
3410
struct peer * peer ;
3407
3411
@@ -3632,7 +3636,7 @@ static enum watch_result our_htlc_depth(struct peer *peer,
3632
3636
if (depth == 0 )
3633
3637
return KEEP_WATCHING ;
3634
3638
3635
- height = get_block_height (peer -> dstate );
3639
+ height = get_block_height (peer -> dstate -> topology );
3636
3640
3637
3641
/* FIXME-OLD #onchain:
3638
3642
*
@@ -3663,7 +3667,8 @@ static enum watch_result our_htlc_depth(struct peer *peer,
3663
3667
peer ,
3664
3668
peer -> onchain .resolved [out_num ],
3665
3669
our_htlc_timeout_depth , h );
3666
- broadcast_tx (peer , peer -> onchain .resolved [out_num ], NULL );
3670
+ broadcast_tx (peer -> dstate -> topology ,
3671
+ peer , peer -> onchain .resolved [out_num ], NULL );
3667
3672
}
3668
3673
return DELETE_WATCH ;
3669
3674
}
@@ -3696,7 +3701,7 @@ static enum watch_result their_htlc_depth(struct peer *peer,
3696
3701
if (depth == 0 )
3697
3702
return KEEP_WATCHING ;
3698
3703
3699
- height = get_block_height (peer -> dstate );
3704
+ height = get_block_height (peer -> dstate -> topology );
3700
3705
3701
3706
/* FIXME-OLD #onchain:
3702
3707
*
@@ -3732,7 +3737,8 @@ static enum watch_result our_main_output_depth(struct peer *peer,
3732
3737
*/
3733
3738
peer -> onchain .resolved [peer -> onchain .to_us_idx ]
3734
3739
= bitcoin_spend_ours (peer );
3735
- broadcast_tx (peer , peer -> onchain .resolved [peer -> onchain .to_us_idx ],
3740
+ broadcast_tx (peer -> dstate -> topology ,
3741
+ peer , peer -> onchain .resolved [peer -> onchain .to_us_idx ],
3736
3742
NULL );
3737
3743
return DELETE_WATCH ;
3738
3744
}
@@ -3852,7 +3858,8 @@ static void resolve_their_htlc(struct peer *peer, unsigned int out_num)
3852
3858
*/
3853
3859
if (peer -> onchain .htlcs [out_num ]-> r ) {
3854
3860
peer -> onchain .resolved [out_num ] = htlc_fulfill_tx (peer , out_num );
3855
- broadcast_tx (peer , peer -> onchain .resolved [out_num ], NULL );
3861
+ broadcast_tx (peer -> dstate -> topology ,
3862
+ peer , peer -> onchain .resolved [out_num ], NULL );
3856
3863
} else {
3857
3864
/* FIXME-OLD #onchain:
3858
3865
*
@@ -4012,7 +4019,7 @@ static enum watch_result check_for_resolution(struct peer *peer,
4012
4019
struct sha256_double txid ;
4013
4020
4014
4021
bitcoin_txid (peer -> onchain .resolved [i ], & txid );
4015
- if (get_tx_depth (peer -> dstate , & txid ) < forever )
4022
+ if (get_tx_depth (peer -> dstate -> topology , & txid ) < forever )
4016
4023
return KEEP_WATCHING ;
4017
4024
}
4018
4025
@@ -4146,7 +4153,7 @@ static void resolve_their_steal(struct peer *peer,
4146
4153
}
4147
4154
assert (n == tal_count (steal_tx -> input ));
4148
4155
4149
- broadcast_tx (peer , steal_tx , NULL );
4156
+ broadcast_tx (peer -> dstate -> topology , peer , steal_tx , NULL );
4150
4157
}
4151
4158
4152
4159
static struct sha256 * get_rhash (struct peer * peer , u64 commit_num ,
@@ -4485,6 +4492,22 @@ void reconnect_peers(struct lightningd_state *dstate)
4485
4492
try_reconnect (peer );
4486
4493
}
4487
4494
4495
+ /* Return earliest block we're interested in, or 0 for none. */
4496
+ u32 get_peer_min_block (struct lightningd_state * dstate )
4497
+ {
4498
+ u32 min_block = 0 ;
4499
+ struct peer * peer ;
4500
+
4501
+ /* If loaded from database, go back to earliest possible peer anchor. */
4502
+ list_for_each (& dstate -> peers , peer , list ) {
4503
+ if (!peer -> anchor .min_depth )
4504
+ continue ;
4505
+ if (min_block == 0 || peer -> anchor .min_depth < min_block )
4506
+ min_block = peer -> anchor .min_depth ;
4507
+ }
4508
+ return min_block ;
4509
+ }
4510
+
4488
4511
/* We may have gone down before broadcasting the anchor. Try again. */
4489
4512
void rebroadcast_anchors (struct lightningd_state * dstate )
4490
4513
{
@@ -4498,7 +4521,8 @@ void rebroadcast_anchors(struct lightningd_state *dstate)
4498
4521
if (!bitcoin_create_anchor (peer ))
4499
4522
peer_fail (peer , __func__ );
4500
4523
else
4501
- broadcast_tx (peer , peer -> anchor .tx , NULL );
4524
+ broadcast_tx (peer -> dstate -> topology ,
4525
+ peer , peer -> anchor .tx , NULL );
4502
4526
}
4503
4527
}
4504
4528
0 commit comments