mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
protocol: switch to single-funder anchor model.
Most complex change was gather_updates(), which handles all the "what is the current state of the channel" logic for our dumb test utils. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -8,10 +8,6 @@ set -e
|
||||
|
||||
. `dirname $0`/vars.sh
|
||||
|
||||
if [ n"$1" = n--privkey ]; then
|
||||
KEY=1
|
||||
shift
|
||||
fi
|
||||
NUM=1
|
||||
if [ $# = 1 ]; then
|
||||
NUM=$1
|
||||
@@ -19,18 +15,15 @@ if [ $# = 1 ]; then
|
||||
fi
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "Usage: getinput.sh [--privkey] [INPUT-INDEX]"
|
||||
echo "Usage: getinput.sh [INPUT-INDEX]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -n "$KEY" ]; then
|
||||
ADDR=`$CLI listunspent | sed -n 's/^ *"address" *: *"\([0-9a-zA-Z]*\)",$/\1/p' | tail -n +$NUM | head -n1`
|
||||
$CLI dumpprivkey $ADDR
|
||||
else
|
||||
TXID=`$CLI listunspent | sed -n 's/^ *"txid" *: *"\([0-9a-f]*\)",$/\1/p' | tail -n +$NUM | head -n1`
|
||||
OUTNUM=`$CLI listunspent | sed -n 's/^ *"vout" *: *\([0-9]*\),$/\1/p' | tail -n +$NUM | head -n1`
|
||||
AMOUNT=`$CLI listunspent | sed -n 's/^ *"amount" *: *\([0-9.]*\),$/\1/p' | tail -n +$NUM | head -n1 | tr -d . | sed 's/^0*//'`
|
||||
SCRIPT=`$CLI listunspent | sed -n 's/^ *"scriptPubKey" *: *"\([0-9a-f]*\)",$/\1/p' | tail -n +$NUM | head -n1`
|
||||
TXID=`$CLI listunspent | sed -n 's/^ *"txid" *: *"\([0-9a-f]*\)",$/\1/p' | tail -n +$NUM | head -n1`
|
||||
OUTNUM=`$CLI listunspent | sed -n 's/^ *"vout" *: *\([0-9]*\),$/\1/p' | tail -n +$NUM | head -n1`
|
||||
AMOUNT=`$CLI listunspent | sed -n 's/^ *"amount" *: *\([0-9.]*\),$/\1/p' | tail -n +$NUM | head -n1 | tr -d . | sed 's/^0*//'`
|
||||
SCRIPT=`$CLI listunspent | sed -n 's/^ *"scriptPubKey" *: *"\([0-9a-f]*\)",$/\1/p' | tail -n +$NUM | head -n1`
|
||||
ADDR=`$CLI listunspent | sed -n 's/^ *"address" *: *"\([0-9a-zA-Z]*\)",$/\1/p' | tail -n +$NUM | head -n1`
|
||||
PRIVKEY=`$CLI dumpprivkey $ADDR`
|
||||
|
||||
echo $TXID/$OUTNUM/$AMOUNT/$SCRIPT
|
||||
fi
|
||||
echo $TXID/$OUTNUM/$AMOUNT/$SCRIPT/$PRIVKEY
|
||||
|
||||
@@ -24,11 +24,10 @@ done
|
||||
scripts/generate-block.sh init
|
||||
|
||||
A1=`scripts/get-new-address.sh`
|
||||
A2=`scripts/get-new-address.sh`
|
||||
TX=`$CLI sendmany "" "{ \"$A1\":10, \"$A2\":10 }"`
|
||||
TX=`$CLI sendmany "" "{ \"$A1\":10 }"`
|
||||
scripts/generate-block.sh
|
||||
|
||||
# Find the inputs numbers corresponding to those 10 btc outs
|
||||
echo "Arguments to test.sh:"
|
||||
# Find the inputs number corresponding to that 10 btc out
|
||||
echo "Argument to test.sh:"
|
||||
for i in $(seq 1 $($CLI listunspent | grep -c txid) ); do scripts/getinput.sh $i | grep -q "$TX.*/1000000000/" && echo -n "$i "; done
|
||||
echo
|
||||
|
||||
@@ -36,18 +36,16 @@ send_after_delay()
|
||||
$CLI sendrawtransaction $1
|
||||
}
|
||||
|
||||
if [ $# -lt 2 ]; then
|
||||
echo Usage: "INPUT1" "INPUT2" "[--steal|--unilateral]" >&2
|
||||
if [ $# = 0 ]; then
|
||||
echo Usage: "INPUT" "[--steal|--unilateral]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
A_INPUTNUM=$1
|
||||
B_INPUTNUM=$2
|
||||
shift 2
|
||||
shift
|
||||
#A_INPUTNUM=4
|
||||
#B_INPUTNUM=1
|
||||
A_AMOUNT=100000000
|
||||
B_AMOUNT=200000000
|
||||
|
||||
A_CHANGEADDR=`scripts/get-new-address.sh`
|
||||
A_TMPADDR=`scripts/get-new-address.sh`
|
||||
@@ -66,79 +64,104 @@ B_FINALADDR=`scripts/get-new-address.sh`
|
||||
#B_FINALADDR=mvQgfEX4iMSEYqD31524jASQviPwPwpvuv
|
||||
|
||||
A_TXIN=`scripts/getinput.sh $A_INPUTNUM`
|
||||
A_TXINKEY=`scripts/getinput.sh --privkey $A_INPUTNUM`
|
||||
B_TXIN=`scripts/getinput.sh $B_INPUTNUM`
|
||||
B_TXINKEY=`scripts/getinput.sh --privkey $B_INPUTNUM`
|
||||
|
||||
A_SEED=00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff
|
||||
B_SEED=112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00
|
||||
|
||||
A_CHANGEPUBKEY=`getpubkey $A_CHANGEADDR`
|
||||
A_TMPKEY=`getprivkey $A_TMPADDR`
|
||||
A_TMPPUBKEY=`getpubkey $A_TMPADDR`
|
||||
A_FINALKEY=`getprivkey $A_FINALADDR`
|
||||
A_FINALPUBKEY=`getpubkey $A_FINALADDR`
|
||||
|
||||
B_CHANGEPUBKEY=`getpubkey $B_CHANGEADDR`
|
||||
B_TMPKEY=`getprivkey $B_TMPADDR`
|
||||
B_TMPPUBKEY=`getpubkey $B_TMPADDR`
|
||||
B_FINALKEY=`getprivkey $B_FINALADDR`
|
||||
B_FINALPUBKEY=`getpubkey $B_FINALADDR`
|
||||
|
||||
# Both sides say what they want from channel
|
||||
$PREFIX ./open-channel $A_SEED $A_AMOUNT $A_CHANGEPUBKEY $A_TMPKEY $A_FINALKEY $A_TXIN > A-open.pb
|
||||
# Both sides say what they want from channel (A offers anchor)
|
||||
$PREFIX ./open-channel --offer-anchor $A_SEED $A_TMPPUBKEY $A_FINALPUBKEY > A-open.pb
|
||||
# B asks for a (dangerously) short locktime, for testing unilateral close.
|
||||
$PREFIX ./open-channel --locktime=60 $B_SEED $B_AMOUNT $B_CHANGEPUBKEY $B_TMPKEY $B_FINALKEY $B_TXIN > B-open.pb
|
||||
$PREFIX ./open-channel --locktime=60 $B_SEED $B_TMPPUBKEY $B_FINALPUBKEY > B-open.pb
|
||||
|
||||
# Now sign anchor.
|
||||
$PREFIX ./open-anchor-scriptsigs A-open.pb B-open.pb $A_TXINKEY > A-anchor-scriptsigs.pb
|
||||
$PREFIX ./open-anchor-scriptsigs B-open.pb A-open.pb $B_TXINKEY > B-anchor-scriptsigs.pb
|
||||
# Now A creates anchor (does not broadcast!)
|
||||
$PREFIX ./create-anchor-tx A-open.pb B-open.pb $A_AMOUNT $A_CHANGEPUBKEY $A_TXIN > A-anchor.tx
|
||||
|
||||
# Now create commit signature
|
||||
$PREFIX ./open-commit-sig A-open.pb B-open.pb $A_TMPKEY > A-commit-sig.pb
|
||||
# Now A sends info about anchor output, and signature for commit tx.
|
||||
$PREFIX ./open-anchor A-open.pb B-open.pb A-anchor.tx $A_TMPKEY > A-anchor.pb
|
||||
|
||||
$PREFIX ./open-commit-sig B-open.pb A-open.pb $B_TMPKEY > B-commit-sig.pb
|
||||
# Now B signs commit sig for anchor.
|
||||
$PREFIX ./open-commit-sig B-open.pb A-open.pb A-anchor.pb $B_TMPKEY > B-commit-sig.pb
|
||||
|
||||
# Now check it.
|
||||
$PREFIX ./check-commit-sig A-open.pb B-open.pb B-commit-sig.pb $A_TMPKEY > A-commit.tx
|
||||
$PREFIX ./check-commit-sig B-open.pb A-open.pb A-commit-sig.pb $B_TMPKEY > B-commit.tx
|
||||
# Now check sigs.
|
||||
$PREFIX ./check-commit-sig A-open.pb B-open.pb A-anchor.pb $A_TMPKEY B-commit-sig.pb
|
||||
$PREFIX ./check-commit-sig B-open.pb A-open.pb A-anchor.pb $B_TMPKEY
|
||||
|
||||
# Now check anchor sigs and make sure they're the same.
|
||||
$PREFIX ./check-anchor-scriptsigs A-open.pb B-open.pb A-anchor-scriptsigs.pb B-anchor-scriptsigs.pb > A-anchor.tx
|
||||
$PREFIX ./check-anchor-scriptsigs B-open.pb A-open.pb B-anchor-scriptsigs.pb A-anchor-scriptsigs.pb > B-anchor.tx
|
||||
cmp A-anchor.tx B-anchor.tx
|
||||
# A broadcasts anchor
|
||||
$CLI sendrawtransaction `cut -d: -f1 A-anchor.tx` > A-anchor.txid
|
||||
|
||||
# Broadcast
|
||||
$CLI sendrawtransaction `cut -d: -f1 A-anchor.tx` > anchor.txid
|
||||
# Wait for confirms
|
||||
while [ 0$($CLI getrawtransaction $(cat A-anchor.txid) 1 | sed -n 's/.*"confirmations" : \([0-9]*\),/\1/p') -lt $($PREFIX ./get-anchor-depth A-open.pb) ]; do scripts/generate-block.sh; done
|
||||
|
||||
# # Wait for confirms
|
||||
# while [ 0$($CLI getrawtransaction $(cat anchor.txid) 1 | sed -n 's/.*"confirmations" : \([0-9]*\),/\1/p') -lt $($PREFIX ./get-anchor-depth A-open.pb) ]; do scripts/generate-block.sh; done
|
||||
while [ 0$($CLI getrawtransaction $(cat A-anchor.txid) 1 | sed -n 's/.*"confirmations" : \([0-9]*\),/\1/p') -lt $($PREFIX ./get-anchor-depth B-open.pb) ]; do scripts/generate-block.sh; done
|
||||
|
||||
# while [ 0$($CLI getrawtransaction $(cat anchor.txid) 1 | sed -n 's/.*"confirmations" : \([0-9]*\),/\1/p') -lt $($PREFIX ./get-anchor-depth B-open.pb) ]; do scripts/generate-block.sh; done
|
||||
# Update traffic sent so far.
|
||||
A_UPDATE_PKTS="-- -B-commit-sig.pb"
|
||||
B_UPDATE_PKTS="-- +B-commit-sig.pb"
|
||||
|
||||
# Just for testing, generate the first transaction.
|
||||
$PREFIX ./create-commit-tx A-anchor.tx A-open.pb B-open.pb $A_TMPKEY B-commit-sig.pb > A-commit-0.tx
|
||||
# Just for testing, generate the first commit transactions.
|
||||
$PREFIX ./create-commit-tx A-open.pb B-open.pb A-anchor.pb $A_TMPKEY $A_UPDATE_PKTS > A-commit-0.tx
|
||||
$PREFIX ./create-commit-tx B-open.pb A-open.pb A-anchor.pb $B_TMPKEY $B_UPDATE_PKTS > B-commit-0.tx
|
||||
|
||||
# Now, update the channel, so I pay you 500 satoshi.
|
||||
$PREFIX ./update-channel --to-them=500 $A_SEED > A-update-1.pb
|
||||
$PREFIX ./update-channel-accept $B_SEED B-anchor.tx B-open.pb A-open.pb $B_TMPKEY A-update-1.pb > B-update-accept-1.pb
|
||||
$PREFIX ./update-channel-signature $A_SEED A-anchor.tx A-open.pb B-open.pb $A_TMPKEY A-update-1.pb B-update-accept-1.pb > A-update-sig-1.pb
|
||||
$PREFIX ./update-channel-complete $B_SEED B-anchor.tx B-open.pb A-open.pb A-update-1.pb A-update-sig-1.pb > B-update-complete-1.pb
|
||||
$PREFIX ./update-channel --to-them=500 $A_SEED 1 > A-update-1.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS +A-update-1.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS -A-update-1.pb"
|
||||
|
||||
$PREFIX ./update-channel-accept $B_SEED B-open.pb A-open.pb A-anchor.pb $B_TMPKEY $B_UPDATE_PKTS > B-update-accept-1.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS -B-update-accept-1.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS +B-update-accept-1.pb"
|
||||
|
||||
$PREFIX ./update-channel-signature $A_SEED A-open.pb B-open.pb A-anchor.pb $A_TMPKEY $A_UPDATE_PKTS > A-update-sig-1.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS +A-update-sig-1.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS -A-update-sig-1.pb"
|
||||
|
||||
$PREFIX ./update-channel-complete $B_SEED B-open.pb A-open.pb A-anchor.pb $B_UPDATE_PKTS > B-update-complete-1.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS -B-update-complete-1.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS +B-update-complete-1.pb"
|
||||
|
||||
# Just for testing, generate second transaction
|
||||
$PREFIX ./create-commit-tx A-anchor.tx A-open.pb B-open.pb $A_TMPKEY B-update-accept-1.pb A-update-1.pb > A-commit-1.tx
|
||||
$PREFIX ./create-commit-tx A-open.pb B-open.pb A-anchor.pb $A_TMPKEY $A_UPDATE_PKTS > A-commit-1.tx
|
||||
$PREFIX ./create-commit-tx B-open.pb A-open.pb A-anchor.pb $B_TMPKEY $B_UPDATE_PKTS > B-commit-1.tx
|
||||
|
||||
# Now you pay me 1000.
|
||||
$PREFIX ./update-channel --from-them=1000 $A_SEED A-update-1.pb > A-update-2.pb
|
||||
$PREFIX ./update-channel-accept $B_SEED B-anchor.tx B-open.pb A-open.pb $B_TMPKEY A-update-2.pb A-update-1.pb > B-update-accept-2.pb 2>/dev/null
|
||||
$PREFIX ./update-channel-signature $A_SEED A-anchor.tx A-open.pb B-open.pb $A_TMPKEY A-update-2.pb B-update-accept-2.pb A-update-1.pb > A-update-sig-2.pb
|
||||
$PREFIX ./update-channel-complete $B_SEED B-anchor.tx B-open.pb A-open.pb A-update-2.pb A-update-sig-2.pb A-update-1.pb > B-update-complete-2.pb
|
||||
# Now you pay me 250.
|
||||
$PREFIX ./update-channel --to-them=250 $B_SEED 2 > B-update-2.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS -B-update-2.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS +B-update-2.pb"
|
||||
|
||||
$PREFIX ./update-channel-accept $A_SEED A-open.pb B-open.pb A-anchor.pb $A_TMPKEY $A_UPDATE_PKTS > A-update-accept-2.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS +A-update-accept-2.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS -A-update-accept-2.pb"
|
||||
|
||||
$PREFIX ./update-channel-signature $B_SEED B-open.pb A-open.pb A-anchor.pb $B_TMPKEY $B_UPDATE_PKTS > B-update-sig-2.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS -B-update-sig-2.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS +B-update-sig-2.pb"
|
||||
|
||||
$PREFIX ./update-channel-complete $A_SEED A-open.pb B-open.pb A-anchor.pb $A_UPDATE_PKTS > A-update-complete-2.pb
|
||||
A_UPDATE_PKTS="$A_UPDATE_PKTS +A-update-complete-2.pb"
|
||||
B_UPDATE_PKTS="$B_UPDATE_PKTS -A-update-complete-2.pb"
|
||||
|
||||
# Just for testing, generate third transaction
|
||||
$PREFIX ./create-commit-tx A-anchor.tx A-open.pb B-open.pb $A_TMPKEY B-update-accept-2.pb A-update-1.pb A-update-2.pb > A-commit-2.tx
|
||||
$PREFIX ./create-commit-tx A-open.pb B-open.pb A-anchor.pb $A_TMPKEY $A_UPDATE_PKTS > A-commit-2.tx
|
||||
$PREFIX ./create-commit-tx B-open.pb A-open.pb A-anchor.pb $B_TMPKEY $B_UPDATE_PKTS > B-commit-2.tx
|
||||
|
||||
if [ x"$1" = x--steal ]; then
|
||||
# A stupidly broadcasts a revoked transaction.
|
||||
$CLI sendrawtransaction `cut -d: -f1 A-commit-1.tx` > A-commit-1.txid
|
||||
|
||||
# B uses the preimage from A-update-sig-2 to cash in.
|
||||
$PREFIX ./create-steal-tx A-commit-1.tx A-update-sig-2.pb $B_FINALKEY B-open.pb A-open.pb $B_CHANGEPUBKEY > B-commit-steal.tx
|
||||
# B uses the preimage from A-update-complete-2 to cash in.
|
||||
$PREFIX ./create-steal-tx A-commit-1.tx A-update-complete-2.pb $B_FINALKEY B-open.pb A-open.pb $B_CHANGEPUBKEY > B-commit-steal.tx
|
||||
|
||||
$CLI sendrawtransaction `cut -d: -f1 B-commit-steal.tx` > B-commit-steal.txid
|
||||
exit 0
|
||||
@@ -146,14 +169,14 @@ fi
|
||||
|
||||
if [ x"$1" = x--unilateral ]; then
|
||||
$CLI sendrawtransaction `cut -d: -f1 A-commit-2.tx` > A-commit-2.txid
|
||||
$PREFIX ./create-commit-spend-tx A-commit-2.tx A-open.pb B-open.pb $A_FINALKEY $A_CHANGEPUBKEY A-update-1.pb A-update-2.pb > A-spend.tx
|
||||
$PREFIX ./create-commit-spend-tx A-commit-2.tx A-open.pb B-open.pb A-anchor.pb $A_FINALKEY $A_CHANGEPUBKEY $A_UPDATE_PKTS > A-spend.tx
|
||||
send_after_delay `cut -d: -f1 A-spend.tx` > A-spend.txid
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Now close channel by mutual consent.
|
||||
$PREFIX ./close-channel A-anchor.tx A-open.pb B-open.pb $A_TMPKEY A-update-1.pb A-update-2.pb > A-close.pb
|
||||
$PREFIX ./close-channel --complete B-anchor.tx B-open.pb A-open.pb $B_TMPKEY A-update-1.pb A-update-2.pb > B-close-complete.pb
|
||||
$PREFIX ./create-close-tx A-anchor.tx A-open.pb B-open.pb A-close.pb B-close-complete.pb A-update-1.pb A-update-2.pb > A-close.tx
|
||||
$PREFIX ./close-channel A-open.pb B-open.pb A-anchor.pb $A_TMPKEY $A_UPDATE_PKTS > A-close.pb
|
||||
$PREFIX ./close-channel --complete B-open.pb A-open.pb A-anchor.pb $B_TMPKEY $B_UPDATE_PKTS > B-close-complete.pb
|
||||
$PREFIX ./create-close-tx A-open.pb B-open.pb A-anchor.pb A-close.pb B-close-complete.pb $A_UPDATE_PKTS > A-close.tx
|
||||
|
||||
$CLI sendrawtransaction `cut -d: -f1 A-close.tx` > close.txid
|
||||
|
||||
Reference in New Issue
Block a user