Browse Source

Use "msatoshi" not "msatoshis" everywhere.

Including in JSON API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
68632e6020
  1. 18
      daemon/channel.c
  2. 6
      daemon/commit_tx.c
  3. 36
      daemon/db.c
  4. 6
      daemon/db.h
  5. 2
      daemon/htlc.h
  6. 20
      daemon/invoice.c
  7. 4
      daemon/invoice.h
  8. 4
      daemon/log.c
  9. 2
      daemon/packets.c
  10. 54
      daemon/peer.c
  11. 4
      daemon/peer.h
  12. 2
      daemon/routing.h
  13. 38
      daemon/test/test.sh

18
daemon/channel.c

@ -209,11 +209,11 @@ bool cstate_add_htlc(struct channel_state *cstate, const struct htlc *htlc,
/* Remember to count the new one in total txsize if not dust! */ /* Remember to count the new one in total txsize if not dust! */
nondust = cstate->num_nondust; nondust = cstate->num_nondust;
if (!is_dust(htlc->msatoshis / 1000)) if (!is_dust(htlc->msatoshi / 1000))
nondust++; nondust++;
if (!change_funding(cstate->anchor, cstate->fee_rate, if (!change_funding(cstate->anchor, cstate->fee_rate,
htlc->msatoshis, creator, recipient, nondust, htlc->msatoshi, creator, recipient, nondust,
must_afford_fee)) must_afford_fee))
return false; return false;
@ -232,14 +232,14 @@ static void remove_htlc(struct channel_state *cstate,
/* Remember to remove this one in total txsize if not dust! */ /* Remember to remove this one in total txsize if not dust! */
nondust = cstate->num_nondust; nondust = cstate->num_nondust;
if (!is_dust(htlc->msatoshis / 1000)) { if (!is_dust(htlc->msatoshi / 1000)) {
assert(nondust > 0); assert(nondust > 0);
nondust--; nondust--;
} }
/* Can't fail since msatoshis is positive. */ /* Can't fail since msatoshi is positive. */
if (!change_funding(cstate->anchor, cstate->fee_rate, if (!change_funding(cstate->anchor, cstate->fee_rate,
-(int64_t)htlc->msatoshis, -(int64_t)htlc->msatoshi,
&cstate->side[beneficiary], &cstate->side[beneficiary],
&cstate->side[!beneficiary], nondust, false)) &cstate->side[!beneficiary], nondust, false))
abort(); abort();
@ -272,10 +272,10 @@ void force_add_htlc(struct channel_state *cstate, const struct htlc *htlc)
creator = &cstate->side[htlc_owner(htlc)]; creator = &cstate->side[htlc_owner(htlc)];
creator->num_htlcs++; creator->num_htlcs++;
creator->pay_msat -= htlc->msatoshis; creator->pay_msat -= htlc->msatoshi;
/* Remember to count the new one in total txsize if not dust! */ /* Remember to count the new one in total txsize if not dust! */
if (!is_dust(htlc->msatoshis / 1000)) if (!is_dust(htlc->msatoshi / 1000))
cstate->num_nondust++; cstate->num_nondust++;
} }
@ -283,9 +283,9 @@ static void force_remove_htlc(struct channel_state *cstate,
enum side beneficiary, enum side beneficiary,
const struct htlc *htlc) const struct htlc *htlc)
{ {
cstate->side[beneficiary].pay_msat += htlc->msatoshis; cstate->side[beneficiary].pay_msat += htlc->msatoshi;
cstate->side[htlc_owner(htlc)].num_htlcs--; cstate->side[htlc_owner(htlc)].num_htlcs--;
if (!is_dust(htlc->msatoshis / 1000)) if (!is_dust(htlc->msatoshi / 1000))
cstate->num_nondust--; cstate->num_nondust--;
} }

6
daemon/commit_tx.c

@ -201,10 +201,10 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
wscript = wscript_for_htlc(tx, peer, h, rhash, side); wscript = wscript_for_htlc(tx, peer, h, rhash, side);
/* If we pay any HTLC, it's txout is not just to other side. */ /* If we pay any HTLC, it's txout is not just to other side. */
if (add_output(tx, scriptpubkey_p2wsh(tx, wscript), if (add_output(tx, scriptpubkey_p2wsh(tx, wscript),
h->msatoshis / 1000, &total)) { h->msatoshi / 1000, &total)) {
*otherside_only = false; *otherside_only = false;
log_debug(peer->log, "Pays %"PRIu64" to htlc %"PRIu64, log_debug(peer->log, "Pays %"PRIu64" to htlc %"PRIu64,
h->msatoshis / 1000, h->id); h->msatoshi / 1000, h->id);
log_add_struct(peer->log, " expiry %s", log_add_struct(peer->log, " expiry %s",
struct abs_locktime, &h->expiry); struct abs_locktime, &h->expiry);
log_add_struct(peer->log, " rhash %s", struct sha256, log_add_struct(peer->log, " rhash %s", struct sha256,
@ -213,7 +213,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx,
tal_hexstr(tx, wscript, tal_count(wscript))); tal_hexstr(tx, wscript, tal_count(wscript)));
} else } else
log_debug(peer->log, "DOES NOT pay %"PRIu64" to htlc %"PRIu64, log_debug(peer->log, "DOES NOT pay %"PRIu64" to htlc %"PRIu64,
h->msatoshis / 1000, h->id); h->msatoshi / 1000, h->id);
} }
assert(total <= peer->anchor.satoshis); assert(total <= peer->anchor.satoshis);

36
daemon/db.c

@ -1020,7 +1020,7 @@ static void db_load_pay(struct lightningd_state *dstate)
struct sha256 rhash; struct sha256 rhash;
struct htlc *htlc; struct htlc *htlc;
struct pubkey *peer_id; struct pubkey *peer_id;
u64 htlc_id, msatoshis; u64 htlc_id, msatoshi;
struct pubkey *ids; struct pubkey *ids;
struct rval *r; struct rval *r;
void *fail; void *fail;
@ -1034,7 +1034,7 @@ static void db_load_pay(struct lightningd_state *dstate)
sqlite3_column_count(stmt)); sqlite3_column_count(stmt));
sha256_from_sql(stmt, 0, &rhash); sha256_from_sql(stmt, 0, &rhash);
msatoshis = sqlite3_column_int64(stmt, 1); msatoshi = sqlite3_column_int64(stmt, 1);
ids = pubkeys_from_arr(ctx, dstate->secpctx, ids = pubkeys_from_arr(ctx, dstate->secpctx,
sqlite3_column_blob(stmt, 2), sqlite3_column_blob(stmt, 2),
sqlite3_column_bytes(stmt, 2)); sqlite3_column_bytes(stmt, 2));
@ -1067,7 +1067,7 @@ static void db_load_pay(struct lightningd_state *dstate)
} else } else
htlc = NULL; htlc = NULL;
if (!pay_add(dstate, &rhash, msatoshis, ids, htlc, fail, r)) if (!pay_add(dstate, &rhash, msatoshi, ids, htlc, fail, r))
fatal("db_load_pay: could not add pay"); fatal("db_load_pay: could not add pay");
} }
tal_free(ctx); tal_free(ctx);
@ -1088,7 +1088,7 @@ static void db_load_invoice(struct lightningd_state *dstate)
while ((err = sqlite3_step(stmt)) != SQLITE_DONE) { while ((err = sqlite3_step(stmt)) != SQLITE_DONE) {
struct rval r; struct rval r;
u64 msatoshis; u64 msatoshi;
bool complete; bool complete;
const char *label; const char *label;
@ -1101,10 +1101,10 @@ static void db_load_invoice(struct lightningd_state *dstate)
sqlite3_column_count(stmt)); sqlite3_column_count(stmt));
from_sql_blob(stmt, 0, &r, sizeof(r)); from_sql_blob(stmt, 0, &r, sizeof(r));
msatoshis = sqlite3_column_int64(stmt, 1); msatoshi = sqlite3_column_int64(stmt, 1);
label = (const char *)sqlite3_column_text(stmt, 2); label = (const char *)sqlite3_column_text(stmt, 2);
complete = sqlite3_column_int(stmt, 3); complete = sqlite3_column_int(stmt, 3);
invoice_add(dstate, &r, msatoshis, label, complete); invoice_add(dstate, &r, msatoshi, label, complete);
} }
tal_free(ctx); tal_free(ctx);
} }
@ -1193,12 +1193,12 @@ void db_init(struct lightningd_state *dstate)
TABLE(wallet, TABLE(wallet,
SQL_PRIVKEY(privkey)) SQL_PRIVKEY(privkey))
TABLE(pay, TABLE(pay,
SQL_RHASH(rhash), SQL_U64(msatoshis), SQL_RHASH(rhash), SQL_U64(msatoshi),
SQL_BLOB(ids), SQL_PUBKEY(htlc_peer), SQL_BLOB(ids), SQL_PUBKEY(htlc_peer),
SQL_U64(htlc_id), SQL_R(r), SQL_FAIL(fail), SQL_U64(htlc_id), SQL_R(r), SQL_FAIL(fail),
"PRIMARY KEY(rhash)") "PRIMARY KEY(rhash)")
TABLE(invoice, TABLE(invoice,
SQL_R(r), SQL_U64(msatoshis), SQL_INVLABEL(label), SQL_R(r), SQL_U64(msatoshi), SQL_INVLABEL(label),
SQL_BOOL(complete), SQL_BOOL(complete),
"PRIMARY KEY(r)") "PRIMARY KEY(r)")
TABLE(anchors, TABLE(anchors,
@ -1209,7 +1209,7 @@ void db_init(struct lightningd_state *dstate)
/* FIXME: state in key is overkill: just need side */ /* FIXME: state in key is overkill: just need side */
TABLE(htlcs, TABLE(htlcs,
SQL_PUBKEY(peer), SQL_U64(id), SQL_PUBKEY(peer), SQL_U64(id),
SQL_STATENAME(state), SQL_U64(msatoshis), SQL_STATENAME(state), SQL_U64(msatoshi),
SQL_U32(expiry), SQL_RHASH(rhash), SQL_R(r), SQL_U32(expiry), SQL_RHASH(rhash), SQL_R(r),
SQL_ROUTING(routing), SQL_PUBKEY(src_peer), SQL_ROUTING(routing), SQL_PUBKEY(src_peer),
SQL_U64(src_id), SQL_BLOB(fail), SQL_U64(src_id), SQL_BLOB(fail),
@ -1482,7 +1482,7 @@ bool db_new_htlc(struct peer *peer, const struct htlc *htlc)
pubkey_to_hexstr(ctx, peer->dstate->secpctx, peer->id), pubkey_to_hexstr(ctx, peer->dstate->secpctx, peer->id),
htlc->id, htlc->id,
htlc_state_name(htlc->state), htlc_state_name(htlc->state),
htlc->msatoshis, htlc->msatoshi,
abs_locktime_to_blocks(&htlc->expiry), abs_locktime_to_blocks(&htlc->expiry),
tal_hexstr(ctx, &htlc->rhash, sizeof(htlc->rhash)), tal_hexstr(ctx, &htlc->rhash, sizeof(htlc->rhash)),
tal_hexstr(ctx, htlc->routing, tal_count(htlc->routing)), tal_hexstr(ctx, htlc->routing, tal_count(htlc->routing)),
@ -1495,7 +1495,7 @@ bool db_new_htlc(struct peer *peer, const struct htlc *htlc)
peerid, peerid,
htlc->id, htlc->id,
htlc_state_name(htlc->state), htlc_state_name(htlc->state),
htlc->msatoshis, htlc->msatoshi,
abs_locktime_to_blocks(&htlc->expiry), abs_locktime_to_blocks(&htlc->expiry),
tal_hexstr(ctx, &htlc->rhash, sizeof(htlc->rhash)), tal_hexstr(ctx, &htlc->rhash, sizeof(htlc->rhash)),
tal_hexstr(ctx, htlc->routing, tal_count(htlc->routing))); tal_hexstr(ctx, htlc->routing, tal_count(htlc->routing)));
@ -1859,7 +1859,7 @@ bool db_update_their_closing(struct peer *peer)
bool db_new_pay_command(struct lightningd_state *dstate, bool db_new_pay_command(struct lightningd_state *dstate,
const struct sha256 *rhash, const struct sha256 *rhash,
const struct pubkey *ids, const struct pubkey *ids,
u64 msatoshis, u64 msatoshi,
const struct htlc *htlc) const struct htlc *htlc)
{ {
const char *errmsg, *ctx = tal(dstate, char); const char *errmsg, *ctx = tal(dstate, char);
@ -1870,7 +1870,7 @@ bool db_new_pay_command(struct lightningd_state *dstate,
assert(!dstate->db->in_transaction); assert(!dstate->db->in_transaction);
errmsg = db_exec(ctx, dstate, "INSERT INTO pay VALUES (x'%s', %"PRIu64", x'%s', x'%s', %"PRIu64", NULL, NULL);", errmsg = db_exec(ctx, dstate, "INSERT INTO pay VALUES (x'%s', %"PRIu64", x'%s', x'%s', %"PRIu64", NULL, NULL);",
tal_hexstr(ctx, rhash, sizeof(*rhash)), tal_hexstr(ctx, rhash, sizeof(*rhash)),
msatoshis, msatoshi,
pubkeys_to_hex(ctx, dstate->secpctx, ids), pubkeys_to_hex(ctx, dstate->secpctx, ids),
pubkey_to_hexstr(ctx, dstate->secpctx, htlc->peer->id), pubkey_to_hexstr(ctx, dstate->secpctx, htlc->peer->id),
htlc->id); htlc->id);
@ -1883,7 +1883,7 @@ bool db_new_pay_command(struct lightningd_state *dstate,
bool db_replace_pay_command(struct lightningd_state *dstate, bool db_replace_pay_command(struct lightningd_state *dstate,
const struct sha256 *rhash, const struct sha256 *rhash,
const struct pubkey *ids, const struct pubkey *ids,
u64 msatoshis, u64 msatoshi,
const struct htlc *htlc) const struct htlc *htlc)
{ {
const char *errmsg, *ctx = tal(dstate, char); const char *errmsg, *ctx = tal(dstate, char);
@ -1892,8 +1892,8 @@ bool db_replace_pay_command(struct lightningd_state *dstate,
log_add_struct(dstate->base_log, "(%s)", struct sha256, rhash); log_add_struct(dstate->base_log, "(%s)", struct sha256, rhash);
assert(!dstate->db->in_transaction); assert(!dstate->db->in_transaction);
errmsg = db_exec(ctx, dstate, "UPDATE pay SET msatoshis=%"PRIu64", ids=x'%s', htlc_peer=x'%s', htlc_id=%"PRIu64", r=NULL, fail=NULL WHERE rhash=x'%s';", errmsg = db_exec(ctx, dstate, "UPDATE pay SET msatoshi=%"PRIu64", ids=x'%s', htlc_peer=x'%s', htlc_id=%"PRIu64", r=NULL, fail=NULL WHERE rhash=x'%s';",
msatoshis, msatoshi,
pubkeys_to_hex(ctx, dstate->secpctx, ids), pubkeys_to_hex(ctx, dstate->secpctx, ids),
pubkey_to_hexstr(ctx, dstate->secpctx, htlc->peer->id), pubkey_to_hexstr(ctx, dstate->secpctx, htlc->peer->id),
htlc->id, htlc->id,
@ -1931,7 +1931,7 @@ bool db_complete_pay_command(struct lightningd_state *dstate,
} }
bool db_new_invoice(struct lightningd_state *dstate, bool db_new_invoice(struct lightningd_state *dstate,
u64 msatoshis, u64 msatoshi,
const char *label, const char *label,
const struct rval *r) const struct rval *r)
{ {
@ -1944,7 +1944,7 @@ bool db_new_invoice(struct lightningd_state *dstate,
/* Insert label as hex; suspect injection attacks. */ /* Insert label as hex; suspect injection attacks. */
errmsg = db_exec(ctx, dstate, "INSERT INTO invoice VALUES (x'%s', %"PRIu64", x'%s', %s);", errmsg = db_exec(ctx, dstate, "INSERT INTO invoice VALUES (x'%s', %"PRIu64", x'%s', %s);",
tal_hexstr(ctx, r, sizeof(*r)), tal_hexstr(ctx, r, sizeof(*r)),
msatoshis, msatoshi,
tal_hexstr(ctx, label, strlen(label)), tal_hexstr(ctx, label, strlen(label)),
sql_bool(false)); sql_bool(false));
if (errmsg) if (errmsg)

6
daemon/db.h

@ -30,15 +30,15 @@ bool db_update_their_closing(struct peer *peer);
bool db_new_pay_command(struct lightningd_state *dstate, bool db_new_pay_command(struct lightningd_state *dstate,
const struct sha256 *rhash, const struct sha256 *rhash,
const struct pubkey *ids, const struct pubkey *ids,
u64 msatoshis, u64 msatoshi,
const struct htlc *htlc); const struct htlc *htlc);
bool db_replace_pay_command(struct lightningd_state *dstate, bool db_replace_pay_command(struct lightningd_state *dstate,
const struct sha256 *rhash, const struct sha256 *rhash,
const struct pubkey *ids, const struct pubkey *ids,
u64 msatoshis, u64 msatoshi,
const struct htlc *htlc); const struct htlc *htlc);
bool db_new_invoice(struct lightningd_state *dstate, bool db_new_invoice(struct lightningd_state *dstate,
u64 msatoshis, u64 msatoshi,
const char *label, const char *label,
const struct rval *r); const struct rval *r);

2
daemon/htlc.h

@ -51,7 +51,7 @@ struct htlc {
/* The unique ID for this peer and this direction (LOCAL or REMOTE) */ /* The unique ID for this peer and this direction (LOCAL or REMOTE) */
u64 id; u64 id;
/* The amount in millisatoshi. */ /* The amount in millisatoshi. */
u64 msatoshis; u64 msatoshi;
/* When the HTLC can no longer be redeemed. */ /* When the HTLC can no longer be redeemed. */
struct abs_locktime expiry; struct abs_locktime expiry;
/* The hash of the preimage which can redeem this HTLC */ /* The hash of the preimage which can redeem this HTLC */

20
daemon/invoice.c

@ -33,13 +33,13 @@ static struct invoice *find_invoice_by_label(struct lightningd_state *dstate,
void invoice_add(struct lightningd_state *dstate, void invoice_add(struct lightningd_state *dstate,
const struct rval *r, const struct rval *r,
u64 msatoshis, u64 msatoshi,
const char *label, const char *label,
bool complete) bool complete)
{ {
struct invoice *invoice = tal(dstate, struct invoice); struct invoice *invoice = tal(dstate, struct invoice);
invoice->msatoshis = msatoshis; invoice->msatoshi = msatoshi;
invoice->r = *r; invoice->r = *r;
invoice->complete = complete; invoice->complete = complete;
invoice->label = tal_strdup(invoice, label); invoice->label = tal_strdup(invoice, label);
@ -51,11 +51,11 @@ static void json_invoice(struct command *cmd,
const char *buffer, const jsmntok_t *params) const char *buffer, const jsmntok_t *params)
{ {
struct invoice *invoice; struct invoice *invoice;
jsmntok_t *msatoshis, *r, *label; jsmntok_t *msatoshi, *r, *label;
struct json_result *response = new_json_result(cmd); struct json_result *response = new_json_result(cmd);
if (!json_get_params(buffer, params, if (!json_get_params(buffer, params,
"amount", &msatoshis, "amount", &msatoshi,
"label", &label, "label", &label,
"?r", &r, "?r", &r,
NULL)) { NULL)) {
@ -81,11 +81,11 @@ static void json_invoice(struct command *cmd,
return; return;
} }
if (!json_tok_u64(buffer, msatoshis, &invoice->msatoshis) if (!json_tok_u64(buffer, msatoshi, &invoice->msatoshi)
|| invoice->msatoshis == 0) { || invoice->msatoshi == 0) {
command_fail(cmd, "'%.*s' is not a valid positive number", command_fail(cmd, "'%.*s' is not a valid positive number",
msatoshis->end - msatoshis->start, msatoshi->end - msatoshi->start,
buffer + msatoshis->start); buffer + msatoshi->start);
return; return;
} }
@ -102,7 +102,7 @@ static void json_invoice(struct command *cmd,
} }
invoice->complete = false; invoice->complete = false;
if (!db_new_invoice(cmd->dstate, invoice->msatoshis, invoice->label, if (!db_new_invoice(cmd->dstate, invoice->msatoshi, invoice->label,
&invoice->r)) { &invoice->r)) {
command_fail(cmd, "database error"); command_fail(cmd, "database error");
return; return;
@ -122,6 +122,6 @@ static void json_invoice(struct command *cmd,
const struct json_command invoice_command = { const struct json_command invoice_command = {
"invoice", "invoice",
json_invoice, json_invoice,
"Create invoice for {msatoshis} with {label} (with a set {r}, otherwise generate one)", "Create invoice for {msatoshi} with {label} (with a set {r}, otherwise generate one)",
"Returns the {rhash} on success. " "Returns the {rhash} on success. "
}; };

4
daemon/invoice.h

@ -8,7 +8,7 @@ struct lightningd_state;
struct invoice { struct invoice {
struct list_node list; struct list_node list;
const char *label; const char *label;
u64 msatoshis; u64 msatoshi;
struct rval r; struct rval r;
struct sha256 rhash; struct sha256 rhash;
bool complete; bool complete;
@ -19,7 +19,7 @@ struct invoice {
/* From database */ /* From database */
void invoice_add(struct lightningd_state *dstate, void invoice_add(struct lightningd_state *dstate,
const struct rval *r, const struct rval *r,
u64 msatoshis, u64 msatoshi,
const char *label, const char *label,
bool complete); bool complete);

4
daemon/log.c

@ -314,12 +314,12 @@ static char *to_string_(const tal_t *ctx,
} else if (streq(structname, "struct htlc")) { } else if (streq(structname, "struct htlc")) {
const struct htlc *h = u.htlc; const struct htlc *h = u.htlc;
s = tal_fmt(ctx, "{ id=%"PRIu64 s = tal_fmt(ctx, "{ id=%"PRIu64
" msatoshis=%"PRIu64 " msatoshi=%"PRIu64
" expiry=%s" " expiry=%s"
" rhash=%s" " rhash=%s"
" rval=%s" " rval=%s"
" src=%s }", " src=%s }",
h->id, h->msatoshis, h->id, h->msatoshi,
to_string(ctx, lr, struct abs_locktime, &h->expiry), to_string(ctx, lr, struct abs_locktime, &h->expiry),
to_string(ctx, lr, struct sha256, &h->rhash), to_string(ctx, lr, struct sha256, &h->rhash),
h->r ? tal_hexstr(ctx, h->r, sizeof(*h->r)) h->r ? tal_hexstr(ctx, h->r, sizeof(*h->r))

2
daemon/packets.c

@ -139,7 +139,7 @@ void queue_pkt_htlc_add(struct peer *peer, struct htlc *htlc)
update_add_htlc__init(u); update_add_htlc__init(u);
u->id = htlc->id; u->id = htlc->id;
u->amount_msat = htlc->msatoshis; u->amount_msat = htlc->msatoshi;
u->r_hash = sha256_to_proto(u, &htlc->rhash); u->r_hash = sha256_to_proto(u, &htlc->rhash);
u->expiry = abs_locktime_to_proto(u, &htlc->expiry); u->expiry = abs_locktime_to_proto(u, &htlc->expiry);
u->route = tal(u, Routing); u->route = tal(u, Routing);

54
daemon/peer.c

@ -422,7 +422,7 @@ static void set_htlc_fail(struct peer *peer,
static void route_htlc_onwards(struct peer *peer, static void route_htlc_onwards(struct peer *peer,
struct htlc *htlc, struct htlc *htlc,
u64 msatoshis, u64 msatoshi,
const BitcoinPubkey *pb_id, const BitcoinPubkey *pb_id,
const u8 *rest_of_route, const u8 *rest_of_route,
const struct peer *only_dest) const struct peer *only_dest)
@ -462,13 +462,13 @@ static void route_htlc_onwards(struct peer *peer,
return; return;
/* Offered fee must be sufficient. */ /* Offered fee must be sufficient. */
if ((s64)(htlc->msatoshis - msatoshis) if ((s64)(htlc->msatoshi - msatoshi)
< connection_fee(next->nc, msatoshis)) { < connection_fee(next->nc, msatoshi)) {
log_unusual(peer->log, log_unusual(peer->log,
"Insufficient fee for HTLC %"PRIu64 "Insufficient fee for HTLC %"PRIu64
": %"PRIi64" on %"PRIu64, ": %"PRIi64" on %"PRIu64,
htlc->id, htlc->msatoshis - msatoshis, htlc->id, htlc->msatoshi - msatoshi,
msatoshis); msatoshi);
command_htlc_set_fail(peer, htlc, PAYMENT_REQUIRED_402, command_htlc_set_fail(peer, htlc, PAYMENT_REQUIRED_402,
"Insufficent fee"); "Insufficent fee");
return; return;
@ -478,7 +478,7 @@ static void route_htlc_onwards(struct peer *peer,
struct pubkey, next->id); struct pubkey, next->id);
/* This checks the HTLC itself is possible. */ /* This checks the HTLC itself is possible. */
err = command_htlc_add(next, msatoshis, err = command_htlc_add(next, msatoshi,
abs_locktime_to_blocks(&htlc->expiry) abs_locktime_to_blocks(&htlc->expiry)
- next->nc->delay, - next->nc->delay,
&htlc->rhash, htlc, rest_of_route, &htlc->rhash, htlc, rest_of_route,
@ -548,13 +548,13 @@ static void their_htlc_added(struct peer *peer, struct htlc *htlc,
goto free_rest; goto free_rest;
} }
if (htlc->msatoshis != invoice->msatoshis) { if (htlc->msatoshi != invoice->msatoshi) {
log_unusual(peer->log, "Short payment for '%s' HTLC %"PRIu64 log_unusual(peer->log, "Short payment for '%s' HTLC %"PRIu64
": %"PRIu64" not %"PRIu64 " satoshi!", ": %"PRIu64" not %"PRIu64 " satoshi!",
invoice->label, invoice->label,
htlc->id, htlc->id,
htlc->msatoshis, htlc->msatoshi,
invoice->msatoshis); invoice->msatoshi);
command_htlc_set_fail(peer, htlc, command_htlc_set_fail(peer, htlc,
UNAUTHORIZED_401, UNAUTHORIZED_401,
"incorrect amount"); "incorrect amount");
@ -1637,7 +1637,7 @@ static const struct bitcoin_tx *htlc_fulfill_tx(const struct peer *peer,
tx->input[0].index = out_num; tx->input[0].index = out_num;
tx->input[0].txid = peer->onchain.txid; tx->input[0].txid = peer->onchain.txid;
satoshis = htlc->msatoshis / 1000; satoshis = htlc->msatoshi / 1000;
tx->input[0].amount = tal_dup(tx->input, u64, &satoshis); tx->input[0].amount = tal_dup(tx->input, u64, &satoshis);
tx->input[0].sequence_number = bitcoin_nsequence(&peer->remote.locktime); tx->input[0].sequence_number = bitcoin_nsequence(&peer->remote.locktime);
@ -1758,7 +1758,7 @@ static bool command_htlc_fulfill(struct peer *peer, struct htlc *htlc)
return true; return true;
} }
const char *command_htlc_add(struct peer *peer, u64 msatoshis, const char *command_htlc_add(struct peer *peer, u64 msatoshi,
unsigned int expiry, unsigned int expiry,
const struct sha256 *rhash, const struct sha256 *rhash,
struct htlc *src, struct htlc *src,
@ -1807,7 +1807,7 @@ const char *command_htlc_add(struct peer *peer, u64 msatoshis,
} }
*htlc = peer_new_htlc(peer, peer->htlc_id_counter, *htlc = peer_new_htlc(peer, peer->htlc_id_counter,
msatoshis, rhash, expiry, route, tal_count(route), msatoshi, rhash, expiry, route, tal_count(route),
src, SENT_ADD_HTLC); src, SENT_ADD_HTLC);
/* BOLT #2: /* BOLT #2:
@ -1823,7 +1823,7 @@ const char *command_htlc_add(struct peer *peer, u64 msatoshis,
*/ */
log_unusual(peer->log, "add_htlc: fail: Cannot afford %"PRIu64 log_unusual(peer->log, "add_htlc: fail: Cannot afford %"PRIu64
" milli-satoshis in their commit tx", " milli-satoshis in their commit tx",
msatoshis); msatoshi);
log_add_struct(peer->log, " channel state %s", log_add_struct(peer->log, " channel state %s",
struct channel_state, struct channel_state,
peer->remote.staging_cstate); peer->remote.staging_cstate);
@ -2517,7 +2517,7 @@ static void htlc_destroy(struct htlc *htlc)
struct htlc *peer_new_htlc(struct peer *peer, struct htlc *peer_new_htlc(struct peer *peer,
u64 id, u64 id,
u64 msatoshis, u64 msatoshi,
const struct sha256 *rhash, const struct sha256 *rhash,
u32 expiry, u32 expiry,
const u8 *route, const u8 *route,
@ -2529,7 +2529,7 @@ struct htlc *peer_new_htlc(struct peer *peer,
h->peer = peer; h->peer = peer;
h->state = state; h->state = state;
h->id = id; h->id = id;
h->msatoshis = msatoshis; h->msatoshi = msatoshi;
h->rhash = *rhash; h->rhash = *rhash;
h->r = NULL; h->r = NULL;
h->fail = NULL; h->fail = NULL;
@ -3175,7 +3175,7 @@ static const struct bitcoin_tx *htlc_timeout_tx(const struct peer *peer,
tx->lock_time = htlc->expiry.locktime; tx->lock_time = htlc->expiry.locktime;
tx->input[0].index = out_num; tx->input[0].index = out_num;
tx->input[0].txid = peer->onchain.txid; tx->input[0].txid = peer->onchain.txid;
satoshis = htlc->msatoshis / 1000; satoshis = htlc->msatoshi / 1000;
tx->input[0].amount = tal_dup(tx->input, u64, &satoshis); tx->input[0].amount = tal_dup(tx->input, u64, &satoshis);
tx->input[0].sequence_number = bitcoin_nsequence(&peer->remote.locktime); tx->input[0].sequence_number = bitcoin_nsequence(&peer->remote.locktime);
@ -4240,7 +4240,7 @@ static void json_add_htlcs(struct json_result *response,
continue; continue;
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_u64(response, "msatoshis", h->msatoshis); json_add_u64(response, "msatoshi", h->msatoshi);
json_add_abstime(response, "expiry", &h->expiry); json_add_abstime(response, "expiry", &h->expiry);
json_add_hex(response, "rhash", &h->rhash, sizeof(h->rhash)); json_add_hex(response, "rhash", &h->rhash, sizeof(h->rhash));
json_add_string(response, "state", htlc_state_name(h->state)); json_add_string(response, "state", htlc_state_name(h->state));
@ -4340,7 +4340,7 @@ static void json_gethtlcs(struct command *cmd,
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_u64(response, "id", h->id); json_add_u64(response, "id", h->id);
json_add_string(response, "state", htlc_state_name(h->state)); json_add_string(response, "state", htlc_state_name(h->state));
json_add_u64(response, "msatoshis", h->msatoshis); json_add_u64(response, "msatoshi", h->msatoshi);
json_add_abstime(response, "expiry", &h->expiry); json_add_abstime(response, "expiry", &h->expiry);
json_add_hex(response, "rhash", &h->rhash, sizeof(h->rhash)); json_add_hex(response, "rhash", &h->rhash, sizeof(h->rhash));
if (h->r) if (h->r)
@ -4389,9 +4389,9 @@ static void json_newhtlc(struct command *cmd,
const char *buffer, const jsmntok_t *params) const char *buffer, const jsmntok_t *params)
{ {
struct peer *peer; struct peer *peer;
jsmntok_t *peeridtok, *msatoshistok, *expirytok, *rhashtok; jsmntok_t *peeridtok, *msatoshitok, *expirytok, *rhashtok;
unsigned int expiry; unsigned int expiry;
u64 msatoshis; u64 msatoshi;
struct sha256 rhash; struct sha256 rhash;
struct json_result *response = new_json_result(cmd); struct json_result *response = new_json_result(cmd);
struct htlc *htlc; struct htlc *htlc;
@ -4400,11 +4400,11 @@ static void json_newhtlc(struct command *cmd,
if (!json_get_params(buffer, params, if (!json_get_params(buffer, params,
"peerid", &peeridtok, "peerid", &peeridtok,
"msatoshis", &msatoshistok, "msatoshi", &msatoshitok,
"expiry", &expirytok, "expiry", &expirytok,
"rhash", &rhashtok, "rhash", &rhashtok,
NULL)) { NULL)) {
command_fail(cmd, "Need peerid, msatoshis, expiry and rhash"); command_fail(cmd, "Need peerid, msatoshi, expiry and rhash");
return; return;
} }
@ -4424,10 +4424,10 @@ static void json_newhtlc(struct command *cmd,
return; return;
} }
if (!json_tok_u64(buffer, msatoshistok, &msatoshis)) { if (!json_tok_u64(buffer, msatoshitok, &msatoshi)) {
command_fail(cmd, "'%.*s' is not a valid number", command_fail(cmd, "'%.*s' is not a valid number",
(int)(msatoshistok->end - msatoshistok->start), (int)(msatoshitok->end - msatoshitok->start),
buffer + msatoshistok->start); buffer + msatoshitok->start);
return; return;
} }
if (!json_tok_number(buffer, expirytok, &expiry)) { if (!json_tok_number(buffer, expirytok, &expiry)) {
@ -4447,7 +4447,7 @@ static void json_newhtlc(struct command *cmd,
} }
log_debug(peer->log, "JSON command to add new HTLC"); log_debug(peer->log, "JSON command to add new HTLC");
err = command_htlc_add(peer, msatoshis, expiry, &rhash, NULL, err = command_htlc_add(peer, msatoshi, expiry, &rhash, NULL,
onion_create(cmd, cmd->dstate->secpctx, onion_create(cmd, cmd->dstate->secpctx,
NULL, NULL, 0), NULL, NULL, 0),
&error_code, &htlc); &error_code, &htlc);
@ -4467,7 +4467,7 @@ static void json_newhtlc(struct command *cmd,
const struct json_command newhtlc_command = { const struct json_command newhtlc_command = {
"newhtlc", "newhtlc",
json_newhtlc, json_newhtlc,
"Offer {peerid} an HTLC worth {msatoshis} in {expiry} (block number) with {rhash}", "Offer {peerid} an HTLC worth {msatoshi} in {expiry} (block number) with {rhash}",
"Returns { id: u64 } result on success" "Returns { id: u64 } result on success"
}; };

4
daemon/peer.h

@ -256,7 +256,7 @@ struct commit_info *new_commit_info(const tal_t *ctx, u64 commit_num);
/* Freeing removes from map, too */ /* Freeing removes from map, too */
struct htlc *peer_new_htlc(struct peer *peer, struct htlc *peer_new_htlc(struct peer *peer,
u64 id, u64 id,
u64 msatoshis, u64 msatoshi,
const struct sha256 *rhash, const struct sha256 *rhash,
u32 expiry, u32 expiry,
const u8 *route, const u8 *route,
@ -264,7 +264,7 @@ struct htlc *peer_new_htlc(struct peer *peer,
struct htlc *src, struct htlc *src,
enum htlc_state state); enum htlc_state state);
const char *command_htlc_add(struct peer *peer, u64 msatoshis, const char *command_htlc_add(struct peer *peer, u64 msatoshi,
unsigned int expiry, unsigned int expiry,
const struct sha256 *rhash, const struct sha256 *rhash,
struct htlc *src, struct htlc *src,

2
daemon/routing.h

@ -43,7 +43,7 @@ struct node *get_node(struct lightningd_state *dstate,
const struct pubkey *id); const struct pubkey *id);
/* msatoshi must be possible (< 21 million BTC), ie < 2^60. /* msatoshi must be possible (< 21 million BTC), ie < 2^60.
* If it returns more than msatoshis, it overflowed. */ * If it returns more than msatoshi, it overflowed. */
s64 connection_fee(const struct node_connection *c, u64 msatoshi); s64 connection_fee(const struct node_connection *c, u64 msatoshi);
/* Updates existing connection, or creates new one as required. */ /* Updates existing connection, or creates new one as required. */

38
daemon/test/test.sh

@ -541,7 +541,7 @@ if [ -n "$DIFFERENT_FEES" ]; then
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id` HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 [ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
check_status_single lcli2 0 0 "" $(($AMOUNT - $HTLC_AMOUNT - $ONE_HTLCS_FEE2)) $(($ONE_HTLCS_FEE2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } " check_status_single lcli2 0 0 "" $(($AMOUNT - $HTLC_AMOUNT - $ONE_HTLCS_FEE2)) $(($ONE_HTLCS_FEE2)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } "
lcli2 fulfillhtlc $ID1 $HTLCID $SECRET lcli2 fulfillhtlc $ID1 $HTLCID $SECRET
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 [ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
@ -592,20 +592,20 @@ HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
if [ -n "$MANUALCOMMIT" ]; then if [ -n "$MANUALCOMMIT" ]; then
# They should register a staged htlc. # They should register a staged htlc.
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_HTLC } " $B_AMOUNT $B_FEE "" check_status $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_HTLC } " $B_AMOUNT $B_FEE ""
# Now commit it. # Now commit it.
lcli1 commit $ID2 lcli1 commit $ID2
# Node 1 hasn't got it committed, but node2 should have told it to stage. # Node 1 hasn't got it committed, but node2 should have told it to stage.
check_status_single lcli1 $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_REVOCATION } " $B_AMOUNT $B_FEE "" check_status_single lcli1 $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_REVOCATION } " $B_AMOUNT $B_FEE ""
# Check channel status # Check channel status
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT)) A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
A_FEE=$(($A_FEE + $EXTRA_FEE)) A_FEE=$(($A_FEE + $EXTRA_FEE))
# Node 2 has it committed. # Node 2 has it committed.
check_status_single lcli2 $B_AMOUNT $B_FEE "" $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_REVOCATION } " check_status_single lcli2 $B_AMOUNT $B_FEE "" $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_REVOCATION } "
# There should be no "both committed" here yet # There should be no "both committed" here yet
if lcli1 getlog debug | $FGREP "Both committed"; then if lcli1 getlog debug | $FGREP "Both committed"; then
@ -629,7 +629,7 @@ else
fi fi
# Both should have committed tx. # Both should have committed tx.
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE "" check_status $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
if [ -n "$STEAL" ]; then if [ -n "$STEAL" ]; then
STEAL_TX=`$LCLI1 dev-signcommit $ID2 | cut -d\" -f4` STEAL_TX=`$LCLI1 dev-signcommit $ID2 | cut -d\" -f4`
@ -650,7 +650,7 @@ if [ -n "$DUMP_ONCHAIN" ]; then
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL check_peerstate lcli2 STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL
# both still know about htlc # both still know about htlc
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE "" check_status $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
# Generate 6 blocks so CSV timeout has expired. # Generate 6 blocks so CSV timeout has expired.
$CLI generate 6 $CLI generate 6
@ -714,7 +714,7 @@ HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
# Check channel status # Check channel status
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT)) A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
A_FEE=$(($A_FEE + $EXTRA_FEE)) A_FEE=$(($A_FEE + $EXTRA_FEE))
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE "" check_status $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
lcli2 failhtlc $ID1 $HTLCID 695 lcli2 failhtlc $ID1 $HTLCID 695
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
@ -734,7 +734,7 @@ HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
# Check channel status # Check channel status
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT)) A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
A_FEE=$(($A_FEE + $EXTRA_FEE)) A_FEE=$(($A_FEE + $EXTRA_FEE))
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE "" check_status $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
# Make sure node1 accepts the expiry packet. # Make sure node1 accepts the expiry packet.
while [ $(blockheight) != $EXPIRY ]; do while [ $(blockheight) != $EXPIRY ]; do
@ -745,7 +745,7 @@ done
$CLI generate 1 $CLI generate 1
if [ -n "$MANUALCOMMIT" ]; then if [ -n "$MANUALCOMMIT" ]; then
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_REMOVE_HTLC } " $B_AMOUNT $B_FEE "" check_status $A_AMOUNT $A_FEE "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_REMOVE_HTLC } " $B_AMOUNT $B_FEE ""
lcli2 commit $ID1 lcli2 commit $ID1
lcli1 commit $ID2 lcli1 commit $ID2
@ -784,7 +784,7 @@ HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 [ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE "" check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
lcli2 fulfillhtlc $ID1 $HTLCID $SECRET lcli2 fulfillhtlc $ID1 $HTLCID $SECRET
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
@ -814,7 +814,7 @@ HTLCID2=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH2 | extract_id`
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
# A covers the extra part of the fee. # A covers the extra part of the fee.
check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE - $EXTRA_FEE / 2)) $(($A_FEE + $EXTRA_FEE + $EXTRA_FEE / 2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION } " 0 $(($B_FEE + $EXTRA_FEE / 2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } " check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE - $EXTRA_FEE / 2)) $(($A_FEE + $EXTRA_FEE + $EXTRA_FEE / 2)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION } " 0 $(($B_FEE + $EXTRA_FEE / 2)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } "
# Fail both, to reset. # Fail both, to reset.
lcli1 failhtlc $ID2 $HTLCID 830 lcli1 failhtlc $ID2 $HTLCID 830
@ -835,7 +835,7 @@ HTLCID2=`lcli2 newhtlc $ID1 $HTLC_AMOUNT $EXPIRY $RHASH2 | extract_id`
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 [ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1 [ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $(($B_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION } " check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $(($B_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION } "
if [ -n "$CLOSE_WITH_HTLCS" ]; then if [ -n "$CLOSE_WITH_HTLCS" ]; then
# Now begin close # Now begin close
@ -893,14 +893,14 @@ HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
if [ -n "$MANUALCOMMIT" ]; then if [ -n "$MANUALCOMMIT" ]; then
# node2 will consider this committed. # node2 will consider this committed.
check_status_single lcli2 $(($B_AMOUNT - $EXTRA_FEE/2)) $(($B_FEE + $EXTRA_FEE/2)) "" $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE/2)) $(($A_FEE + $EXTRA_FEE/2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_REVOCATION } " check_status_single lcli2 $(($B_AMOUNT - $EXTRA_FEE/2)) $(($B_FEE + $EXTRA_FEE/2)) "" $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE/2)) $(($A_FEE + $EXTRA_FEE/2)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_REVOCATION } "
else else
# It will start committing by itself # It will start committing by itself
check_status_single lcli2 $(($B_AMOUNT - $EXTRA_FEE/2)) $(($B_FEE + $EXTRA_FEE/2)) "" $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE/2)) $(($A_FEE + $EXTRA_FEE/2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_COMMIT } " check_status_single lcli2 $(($B_AMOUNT - $EXTRA_FEE/2)) $(($B_FEE + $EXTRA_FEE/2)) "" $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE/2)) $(($A_FEE + $EXTRA_FEE/2)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_COMMIT } "
fi fi
# node1 will still be awaiting node2's revocation reply. # node1 will still be awaiting node2's revocation reply.
check_status_single lcli1 $(($A_AMOUNT)) $(($A_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_COMMIT } " $B_AMOUNT $B_FEE "" check_status_single lcli1 $(($A_AMOUNT)) $(($A_FEE)) "{ msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_COMMIT } " $B_AMOUNT $B_FEE ""
# Now send another offer, and enable node2 output. # Now send another offer, and enable node2 output.
HTLCID2=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH2 | extract_id` HTLCID2=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH2 | extract_id`
@ -918,9 +918,9 @@ check_balance_single lcli1 $(($A_AMOUNT - $HTLC_AMOUNT*2 - $EXTRA_FEE)) $(($A_FE
check_balance_single lcli2 $(($B_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) $(($A_AMOUNT - $HTLC_AMOUNT*2 - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) check_balance_single lcli2 $(($B_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) $(($A_AMOUNT - $HTLC_AMOUNT*2 - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE))
# Once both balances are correct, this should be right. # Once both balances are correct, this should be right.
lcli1 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION } ], their_htlcs : [ ]" || lcli1 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } ], their_htlcs : [ ]" lcli1 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION }, { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION } ], their_htlcs : [ ]" || lcli1 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION }, { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } ], their_htlcs : [ ]"
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 } ]" lcli2 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ ], their_htlcs : [ { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION }, { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION } ]" || lcli2 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ ], their_htlcs : [ { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION }, { msatoshi : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } ]"
# Just for once, reconnect/restart node 2. # Just for once, reconnect/restart node 2.
case "$RECONNECT" in case "$RECONNECT" in
@ -1023,7 +1023,7 @@ if [ ! -n "$MANUALCOMMIT" ]; then
fi fi
# Try underpaying. # Try underpaying.
PAID=`echo "$ROUTE" | sed -n 's/.*"msatoshis" : \([0-9]*\),.*/\1/p'` PAID=`echo "$ROUTE" | sed -n 's/.*"msatoshi" : \([0-9]*\),.*/\1/p'`
UNDERPAY=`echo "$ROUTE" | sed "s/: $PAID,/: $(($PAID - 1)),/"` UNDERPAY=`echo "$ROUTE" | sed "s/: $PAID,/: $(($PAID - 1)),/"`
if lcli1 sendpay "$UNDERPAY" $RHASH5; then if lcli1 sendpay "$UNDERPAY" $RHASH5; then
echo Paid with too little? >&2 echo Paid with too little? >&2
@ -1071,7 +1071,7 @@ if [ ! -n "$MANUALCOMMIT" ]; then
lcli1 sendpay "$ROUTE" $RHASH5 lcli1 sendpay "$ROUTE" $RHASH5
# Re-send to different id or amount should complain. # Re-send to different id or amount should complain.
SHORTROUTE=`echo "$ROUTE" | sed 's/, { "id" : .* }//' | sed 's/"msatoshis" : [0-9]*,/"msatoshis" : '$HTLC_AMOUNT,/` SHORTROUTE=`echo "$ROUTE" | sed 's/, { "id" : .* }//' | sed 's/"msatoshi" : [0-9]*,/"msatoshi" : '$HTLC_AMOUNT,/`
lcli1 sendpay "$SHORTROUTE" $RHASH5 | $FGREP "already succeeded to $ID3" lcli1 sendpay "$SHORTROUTE" $RHASH5 | $FGREP "already succeeded to $ID3"
lcli1 sendpay "$UNDERPAY" $RHASH5 | $FGREP "already succeeded with amount $HTLC_AMOUNT" lcli1 sendpay "$UNDERPAY" $RHASH5 | $FGREP "already succeeded with amount $HTLC_AMOUNT"

Loading…
Cancel
Save