mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-09 17:14:28 +01:00
daemon: handle HTLC as per BOLT #2 algorithm.
From BOLT#2 (rev 8ee09e749990a11fa53bea03d5961cfde4be4616): Thus each node (conceptually) tracks: ... 3. Two *unacked changesets*: one for the local commitment (their proposals) and one for the remote (our proposals) 4. Two *acked changesets*: one for the local commitment (our proposals, acknowledged) and one for the remote (their proposals, acknowledged). (Note that an implementation MAY optimize this internally, for example, pre-applying the changesets in some cases). In our case, we apply the unacked changes immediately into staging_cstate, and save them in an unacked_changes array. That array gets applied to staging_cstate as soon as it's acked (we only allow one outstanding update_commit, so we only need one array). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -149,10 +149,11 @@ check_status()
|
||||
check_staged()
|
||||
{
|
||||
lcli="$1"
|
||||
num_htlcs="$2"
|
||||
what="$2"
|
||||
num_htlcs="$3"
|
||||
|
||||
if check "$lcli getpeers | tr -s '\012\011\" ' ' ' | $FGREP 'staged_changes : '$num_htlcs"; then :; else
|
||||
echo Cannot find $lcli output: '"staged_changes" : '$num_htlcs >&2
|
||||
if check "$lcli getpeers | tr -s '\012\011\" ' ' ' | $FGREP ${what}_'staged_changes : '$num_htlcs"; then :; else
|
||||
echo Cannot find $lcli output: '"'${what}_'staged_changes" : '$num_htlcs >&2
|
||||
$lcli getpeers | tr -s '\012\011 ' ' ' >&2
|
||||
return 1
|
||||
fi
|
||||
@@ -351,15 +352,17 @@ lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH
|
||||
if [ -n "$MANUALCOMMIT" ]; then
|
||||
# Nothing should have changed!
|
||||
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
||||
# But 2 should register a staged htlc.
|
||||
check_staged lcli2 1
|
||||
# But they should register a staged htlc.
|
||||
check_staged lcli2 local 1
|
||||
check_staged lcli1 remote 1
|
||||
|
||||
# Now commit it.
|
||||
lcli1 commit $ID2
|
||||
|
||||
# Node 1 hasn't got it committed, but node2 should have told it to stage.
|
||||
check_status_single lcli1 $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
||||
check_staged lcli1 1
|
||||
check_staged lcli1 local 1
|
||||
check_staged lcli2 remote 1
|
||||
|
||||
# Check channel status
|
||||
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
|
||||
|
||||
Reference in New Issue
Block a user