mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
peer: restart from the other side.
Testing this revealed that we can't just reconnect when we have something to send, as we might be NATed; we should try to reconnect anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
190b30e958
commit
9f512f6540
2 changed files with 34 additions and 11 deletions
|
@ -2321,7 +2321,7 @@ static struct io_plan *reconnect_pkt_in(struct io_conn *conn, struct peer *peer)
|
|||
return pkt_out(conn, peer);
|
||||
}
|
||||
|
||||
/* Queue prompted us to reconnect, but we need to eliminate it now. */
|
||||
/* We need to eliminate queue now. */
|
||||
clear_output_queue(peer);
|
||||
|
||||
/* They might have missed the error, tell them before hanging up */
|
||||
|
@ -3832,7 +3832,8 @@ static struct io_plan *peer_reconnect(struct io_conn *conn, struct peer *peer)
|
|||
peer->id, crypto_on_reconnect_out, peer);
|
||||
}
|
||||
|
||||
/* Only retry when we want to send something. */
|
||||
/* We can't only retry when we want to send: they may want to send us
|
||||
* something but not be able to connect (NAT). So keep retrying.. */
|
||||
static void reconnect_failed(struct io_conn *conn, struct peer *peer)
|
||||
{
|
||||
/* Already otherwise connected (ie. they connected in)? */
|
||||
|
@ -3841,13 +3842,8 @@ static void reconnect_failed(struct io_conn *conn, struct peer *peer)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!tal_count(peer->outpkt)) {
|
||||
log_debug(peer->log, "reconnect_failed: nothing to send");
|
||||
return;
|
||||
}
|
||||
|
||||
log_debug(peer->log, "Have packets to send, setting timer");
|
||||
new_reltimer(peer->dstate, peer, time_from_sec(60), try_reconnect, peer);
|
||||
log_debug(peer->log, "Setting timer to re-connect");
|
||||
new_reltimer(peer->dstate, peer, time_from_sec(15), try_reconnect, peer);
|
||||
}
|
||||
|
||||
static struct io_plan *init_conn(struct io_conn *conn, struct peer *peer)
|
||||
|
|
|
@ -354,6 +354,14 @@ EOF
|
|||
|
||||
cp $DIR2/config $DIR3/config
|
||||
|
||||
if [ x"$RECONNECT" = xrestart ]; then
|
||||
# Make sure node2 restarts on same port, by setting in config.
|
||||
# Find a free TCP port.
|
||||
port=4000
|
||||
while netstat -ntl | grep -q ":$port "; do port=$(($port + 1)); done
|
||||
echo port=$port >> $DIR2/config
|
||||
fi
|
||||
|
||||
if [ -n "$DIFFERENT_FEES" ]; then
|
||||
# Simply override default fee (estimatefee fails on regtest anyway)
|
||||
CLOSE_FEE_RATE2=50000
|
||||
|
@ -373,11 +381,13 @@ else
|
|||
$LIGHTNINGD1 > $REDIR1 2> $REDIRERR1 &
|
||||
fi
|
||||
|
||||
LIGHTNINGD2="$(readlink -f `pwd`/../lightningd) --lightning-dir=$DIR2"
|
||||
if [ -n "$GDB2" ]; then
|
||||
echo Press return once you run: gdb --args daemon/lightningd --lightning-dir=$DIR2 >&2
|
||||
echo Press return once you run: gdb --args $LIGHTNINGD2 >&2
|
||||
read REPLY
|
||||
else
|
||||
$PREFIX ../lightningd --lightning-dir=$DIR2 > $REDIR2 2> $REDIRERR2 &
|
||||
LIGHTNINGD2="$PREFIX $LIGHTNINGD2"
|
||||
$LIGHTNINGD2 > $REDIR2 2> $REDIRERR2 &
|
||||
fi
|
||||
$PREFIX ../lightningd --lightning-dir=$DIR3 > $DIR3/output 2> $DIR3/errors &
|
||||
|
||||
|
@ -848,6 +858,23 @@ lcli1 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ { msatoshis : $H
|
|||
|
||||
lcli2 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ ], their_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION } ]" || lcli2 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ ], their_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } ]"
|
||||
|
||||
# Just for once, reconnect/restart node 2.
|
||||
case "$RECONNECT" in
|
||||
reconnect)
|
||||
echo RECONNECTING NODE2
|
||||
$LCLI2 dev-reconnect $ID1 >/dev/null
|
||||
sleep 1
|
||||
;;
|
||||
restart)
|
||||
echo RESTARTING NODE2
|
||||
$LCLI2 -- dev-restart $LIGHTNINGD2 >/dev/null 2>&1 || true
|
||||
if ! check "$LCLI2 getlog 2>/dev/null | fgrep -q Hello"; then
|
||||
echo "Node2 dev-restart failed!">&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# Node2 collects the HTLCs.
|
||||
lcli2 fulfillhtlc $ID1 $HTLCID $SECRET
|
||||
lcli2 fulfillhtlc $ID1 $HTLCID2 $SECRET2
|
||||
|
|
Loading…
Add table
Reference in a new issue