protocol: increase HTLC precision to 1/1000 satoshi.

This gets truncated for on-chain transactions (thus, rounding may
contribute to fees).

This also means we currently have an upper bound of 0.04 BTC per HTLC;
this can be increased later if required.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2015-09-24 15:00:47 +09:30
parent 58a62e782d
commit 5bc22f0368
13 changed files with 75 additions and 62 deletions

View File

@@ -88,7 +88,9 @@ int main(int argc, char *argv[])
/* This is what the anchor pays to. */
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
close_tx = create_close_tx(ctx, o1, o2, a, cstate->a.pay, cstate->b.pay);
close_tx = create_close_tx(ctx, o1, o2, a,
cstate->a.pay_msat / 1000,
cstate->b.pay_msat / 1000);
/* Sign it for them. */
sign_tx_input(ctx, close_tx, 0, redeemscript, tal_count(redeemscript),

View File

@@ -66,7 +66,9 @@ int main(int argc, char *argv[])
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
/* Now create the close tx to spend 2/2 output of anchor. */
close_tx = create_close_tx(ctx, o1, o2, a, cstate->a.pay, cstate->b.pay);
close_tx = create_close_tx(ctx, o1, o2, a,
cstate->a.pay_msat / 1000,
cstate->b.pay_msat / 1000);
/* Signatures well-formed? */
sig1.stype = sig2.stype = SIGHASH_ALL;

View File

@@ -144,7 +144,7 @@ struct channel_state *gather_updates(const tal_t *ctx,
sig = pkt->open_commit_sig->sig;
break;
case PKT__PKT_UPDATE_ADD_HTLC:
amount = pkt->update_add_htlc->amount;
amount = pkt->update_add_htlc->amount_msat;
if (received) {
if (!funding_delta(o2, o1, oa, 0, amount,
&cstate->b, &cstate->a))
@@ -173,7 +173,7 @@ struct channel_state *gather_updates(const tal_t *ctx,
pkt->update_remove_htlc->r_hash);
if (n == tal_count(cstate->b.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->b.htlcs[n]->amount;
amount = cstate->b.htlcs[n]->amount_msat;
if (!funding_delta(o2, o1, oa, 0, -amount,
&cstate->b, &cstate->a))
errx(1, "Impossible htlc %llu %s",
@@ -184,7 +184,7 @@ struct channel_state *gather_updates(const tal_t *ctx,
pkt->update_remove_htlc->r_hash);
if (n == tal_count(cstate->a.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->a.htlcs[n]->amount;
amount = cstate->a.htlcs[n]->amount_msat;
if (!funding_delta(o1, o2, oa, 0, -amount,
&cstate->a, &cstate->b))
errx(1, "Impossible htlc %llu %s",
@@ -211,7 +211,7 @@ struct channel_state *gather_updates(const tal_t *ctx,
n = find_htlc(&cstate->a, rh);
if (n == tal_count(cstate->a.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->a.htlcs[n]->amount;
amount = cstate->a.htlcs[n]->amount_msat;
if (!funding_delta(o1, o2, oa, amount, -amount,
&cstate->a, &cstate->b))
errx(1, "Impossible htlc %llu %s",
@@ -222,7 +222,7 @@ struct channel_state *gather_updates(const tal_t *ctx,
n = find_htlc(&cstate->b, rh);
if (n == tal_count(cstate->b.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->b.htlcs[n]->amount;
amount = cstate->b.htlcs[n]->amount_msat;
if (!funding_delta(o2, o1, oa, amount, -amount,
&cstate->b, &cstate->a))
errx(1, "Impossible htlc %llu %s",
@@ -238,9 +238,9 @@ struct channel_state *gather_updates(const tal_t *ctx,
case PKT__PKT_UPDATE:
if (received)
delta = -pkt->update->delta;
delta = -pkt->update->delta_msat;
else
delta = pkt->update->delta;
delta = pkt->update->delta_msat;
if (!funding_delta(o1, o2, oa, delta, 0,
&cstate->a, &cstate->b))
errx(1, "Impossible funding update %lli %s",

View File

@@ -24,10 +24,10 @@ done
scripts/generate-block.sh init
A1=`scripts/get-new-address.sh`
TX=`$CLI sendmany "" "{ \"$A1\":10 }"`
TX=`$CLI sendmany "" "{ \"$A1\":0.01 }"`
scripts/generate-block.sh
# Find the inputs number corresponding to that 10 btc out
# Find the inputs number corresponding to that 0.01 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
for i in $(seq 1 $($CLI listunspent | grep -c txid) ); do scripts/getinput.sh $i | grep -q "$TX.*/1000000/" && echo -n "$i "; done
echo

View File

@@ -53,7 +53,7 @@ A_INPUTNUM=$1
shift
#A_INPUTNUM=4
#B_INPUTNUM=1
A_AMOUNT=100000000
A_AMOUNT=900000
A_CHANGEADDR=`scripts/get-new-address.sh`
A_TMPADDR=`scripts/get-new-address.sh`