mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
commit
e5b44ff232
7
Makefile
7
Makefile
@ -15,7 +15,7 @@ BOLTVERSION := master
|
||||
#NO_VALGRIND := 1
|
||||
|
||||
# This is where we add new features as bitcoin adds them.
|
||||
FEATURES :=
|
||||
FEATURES :=
|
||||
|
||||
TEST_PROGRAMS := \
|
||||
test/test_protocol \
|
||||
@ -225,7 +225,10 @@ check-bolt: check-bolt.o $(CCAN_OBJS)
|
||||
|
||||
check-bolt.o: $(CCAN_HEADERS)
|
||||
|
||||
check-source: check-makefile check-source-bolt \
|
||||
check-whitespace:
|
||||
if grep -n '[ ]$$' Makefile daemon/test/Makefile daemon/Makefile bitcoin/Makefile check-bolt.c $(CORE_SRC) $(BITCOIN_SRC) $(DAEMON_SRC); then echo Extraneous whitespace found >&2; exit 1; fi
|
||||
|
||||
check-source: check-makefile check-source-bolt check-whitespace \
|
||||
$(CORE_SRC:%=check-src-include-order/%) \
|
||||
$(BITCOIN_SRC:%=check-src-include-order/%) \
|
||||
$(CORE_HEADERS:%=check-hdr-include-order/%) \
|
||||
|
@ -72,7 +72,7 @@ bool seconds_to_abs_locktime(u32 seconds, struct abs_locktime *abs)
|
||||
{
|
||||
return abs_seconds_to_locktime(seconds, &abs->locktime);
|
||||
}
|
||||
|
||||
|
||||
bool blocks_to_abs_locktime(u32 blocks, struct abs_locktime *abs)
|
||||
{
|
||||
return abs_blocks_to_locktime(blocks, &abs->locktime);
|
||||
|
@ -40,7 +40,7 @@ bool pubkey_from_privkey(secp256k1_context *secpctx,
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool pubkey_from_hexstr(secp256k1_context *secpctx,
|
||||
const char *derstr, size_t slen, struct pubkey *key)
|
||||
{
|
||||
@ -65,7 +65,7 @@ char *pubkey_to_hexstr(const tal_t *ctx, secp256k1_context *secpctx,
|
||||
pubkey_to_der(secpctx, der, key);
|
||||
return tal_hexstr(ctx, der, sizeof(der));
|
||||
}
|
||||
|
||||
|
||||
bool pubkey_eq(const struct pubkey *a, const struct pubkey *b)
|
||||
{
|
||||
return structeq(&a->pubkey, &b->pubkey);
|
||||
|
@ -159,7 +159,7 @@ static bool key_less(secp256k1_context *secpctx,
|
||||
|
||||
return memcmp(a_der, b_der, sizeof(a_der)) < 0;
|
||||
}
|
||||
|
||||
|
||||
/* tal_count() gives the length of the script. */
|
||||
u8 *bitcoin_redeem_2of2(const tal_t *ctx,
|
||||
secp256k1_context *secpctx,
|
||||
@ -245,13 +245,13 @@ void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx,
|
||||
input->witness[0] = stack_sig(input->witness, secpctx, sig);
|
||||
input->witness[1] = stack_key(input->witness, secpctx, key);
|
||||
}
|
||||
|
||||
|
||||
/* Create an output script for a 32-byte witness. */
|
||||
u8 *scriptpubkey_p2wsh(const tal_t *ctx, const u8 *witnessscript)
|
||||
{
|
||||
struct sha256 h;
|
||||
u8 *script = tal_arr(ctx, u8, 0);
|
||||
|
||||
|
||||
add_op(&script, OP_0);
|
||||
sha256(&h, witnessscript, tal_count(witnessscript));
|
||||
add_push_bytes(&script, h.u.u8, sizeof(h.u.u8));
|
||||
@ -266,7 +266,7 @@ u8 *scriptpubkey_p2wpkh(const tal_t *ctx,
|
||||
struct ripemd160 h;
|
||||
u8 der[PUBKEY_DER_LEN];
|
||||
u8 *script = tal_arr(ctx, u8, 0);
|
||||
|
||||
|
||||
add_op(&script, OP_0);
|
||||
pubkey_to_der(secpctx, der, key);
|
||||
hash160(&h, der, sizeof(der));
|
||||
@ -406,7 +406,7 @@ u8 *bitcoin_redeem_htlc_recv(const tal_t *ctx,
|
||||
add_op(&script, OP_ENDIF);
|
||||
|
||||
add_push_key(&script, secpctx, theirkey);
|
||||
|
||||
|
||||
add_op(&script, OP_ENDIF);
|
||||
add_op(&script, OP_CHECKSIG);
|
||||
|
||||
@ -514,7 +514,7 @@ u8 *bitcoin_redeem_secret_or_delay(const tal_t *ctx,
|
||||
add_push_bytes(&script, ripemd.u.u8, sizeof(ripemd.u.u8));
|
||||
add_op(&script, OP_EQUAL);
|
||||
add_op(&script, OP_IF);
|
||||
|
||||
|
||||
/* They can collect the funds. */
|
||||
add_push_key(&script, secpctx, key_if_secret_known);
|
||||
|
||||
|
@ -71,7 +71,7 @@ static void dump_tx(const char *msg,
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void sign_hash(secp256k1_context *secpctx,
|
||||
const struct privkey *privkey,
|
||||
const struct sha256_double *h,
|
||||
@ -159,7 +159,7 @@ bool check_tx_sig(secp256k1_context *secpctx,
|
||||
/* We only use SIGHASH_ALL for the moment. */
|
||||
if (sig->stype != SIGHASH_ALL)
|
||||
return false;
|
||||
|
||||
|
||||
ret = check_signed_hash(secpctx, &hash, &sig->sig, key);
|
||||
if (!ret)
|
||||
dump_tx("Sig failed", tx, input_num,
|
||||
@ -209,7 +209,7 @@ static bool IsValidSignatureEncoding(const unsigned char sig[], size_t len)
|
||||
// Verify that the length of the signature matches the sum of the length
|
||||
// of the elements.
|
||||
if ((size_t)(lenR + lenS + 7) != len) return false;
|
||||
|
||||
|
||||
// Check whether the R element is an integer.
|
||||
if (sig[2] != 0x02) return false;
|
||||
|
||||
|
12
bitcoin/tx.c
12
bitcoin/tx.c
@ -31,7 +31,7 @@ static void push_tx_output(const struct bitcoin_tx_output *output,
|
||||
/* BIP 141:
|
||||
* It is followed by stack items, with each item starts with a var_int
|
||||
* to indicate the length. */
|
||||
static void push_witness(const u8 *witness,
|
||||
static void push_witness(const u8 *witness,
|
||||
void (*push)(const void *, size_t, void *), void *pushp)
|
||||
{
|
||||
push_varint_blob(witness, tal_count(witness), push, pushp);
|
||||
@ -140,7 +140,7 @@ static void hash_prevouts(struct sha256_double *h, const struct bitcoin_tx *tx)
|
||||
}
|
||||
sha256_double_done(&ctx, h);
|
||||
}
|
||||
|
||||
|
||||
static void hash_sequence(struct sha256_double *h, const struct bitcoin_tx *tx)
|
||||
{
|
||||
struct sha256_ctx ctx;
|
||||
@ -172,7 +172,7 @@ static void hash_outputs(struct sha256_double *h, const struct bitcoin_tx *tx)
|
||||
tx->output[i].script_length,
|
||||
push_sha, &ctx);
|
||||
}
|
||||
|
||||
|
||||
sha256_double_done(&ctx, h);
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ static u64 pull_length(const u8 **cursor, size_t *max)
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
static void pull_input(const tal_t *ctx, const u8 **cursor, size_t *max,
|
||||
struct bitcoin_tx_input *input)
|
||||
{
|
||||
@ -381,7 +381,7 @@ static void pull_witness(struct bitcoin_tx_input *inputs, size_t i,
|
||||
|
||||
inputs[i].witness = tal_arr(inputs, u8 *, num);
|
||||
for (j = 0; j < num; j++) {
|
||||
inputs[i].witness[j] = pull_witness_item(inputs[i].witness,
|
||||
inputs[i].witness[j] = pull_witness_item(inputs[i].witness,
|
||||
cursor, max);
|
||||
}
|
||||
}
|
||||
@ -451,7 +451,7 @@ struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex,
|
||||
|
||||
if (len)
|
||||
goto fail_free_tx;
|
||||
|
||||
|
||||
tal_free(linear_tx);
|
||||
return tx;
|
||||
|
||||
|
@ -228,7 +228,7 @@ static void fail_nobolt(const char *filename,
|
||||
filename, line, bolt_prefix);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
static struct bolt_file *find_bolt(const char *bolt_prefix,
|
||||
struct bolt_file *bolts)
|
||||
{
|
||||
@ -297,4 +297,3 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ static char *bcli_args(struct bitcoin_cli *bcli)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void bcli_finished(struct io_conn *conn, struct bitcoin_cli *bcli)
|
||||
{
|
||||
int ret, status;
|
||||
|
@ -149,7 +149,7 @@ static void connect_block(struct lightningd_state *dstate,
|
||||
b->mediantime = get_mediantime(topo, b);
|
||||
|
||||
block_map_add(&topo->block_map, b);
|
||||
|
||||
|
||||
/* Now we see if any of those txs are interesting. */
|
||||
for (i = 0; i < tal_count(b->full_txs); i++) {
|
||||
struct bitcoin_tx *tx = b->full_txs[i];
|
||||
@ -584,7 +584,7 @@ static void json_dev_broadcast(struct command *cmd,
|
||||
if (enable)
|
||||
rebroadcast_txs(cmd->dstate, cmd);
|
||||
else
|
||||
command_success(cmd, null_response(cmd));
|
||||
command_success(cmd, null_response(cmd));
|
||||
}
|
||||
|
||||
const struct json_command dev_broadcast_command = {
|
||||
|
@ -10,7 +10,7 @@
|
||||
uint64_t fee_by_feerate(size_t txsize, uint64_t fee_rate)
|
||||
{
|
||||
/* BOLT #2:
|
||||
*
|
||||
*
|
||||
* The fee for a transaction MUST be calculated by multiplying this
|
||||
* bytecount by the fee rate, dividing by 1000 and truncating
|
||||
* (rounding down) the result to an even number of satoshis.
|
||||
@ -211,12 +211,12 @@ bool cstate_add_htlc(struct channel_state *cstate, const struct htlc *htlc,
|
||||
|
||||
creator = &cstate->side[htlc_owner(htlc)];
|
||||
recipient = &cstate->side[!htlc_owner(htlc)];
|
||||
|
||||
|
||||
/* Remember to count the new one in total txsize if not dust! */
|
||||
nondust = cstate->num_nondust;
|
||||
if (!is_dust(htlc->msatoshi / 1000))
|
||||
nondust++;
|
||||
|
||||
|
||||
if (!change_funding(cstate->anchor, cstate->fee_rate,
|
||||
htlc->msatoshi, creator, recipient, nondust,
|
||||
must_afford_fee))
|
||||
@ -278,7 +278,7 @@ void force_add_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
||||
creator = &cstate->side[htlc_owner(htlc)];
|
||||
creator->num_htlcs++;
|
||||
creator->pay_msat -= htlc->msatoshi;
|
||||
|
||||
|
||||
/* Remember to count the new one in total txsize if not dust! */
|
||||
if (!is_dust(htlc->msatoshi / 1000))
|
||||
cstate->num_nondust++;
|
||||
@ -298,7 +298,7 @@ void force_fail_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
||||
{
|
||||
force_remove_htlc(cstate, htlc_owner(htlc), htlc);
|
||||
}
|
||||
|
||||
|
||||
void force_fulfill_htlc(struct channel_state *cstate, const struct htlc *htlc)
|
||||
{
|
||||
force_remove_htlc(cstate, !htlc_owner(htlc), htlc);
|
||||
|
@ -69,7 +69,7 @@ u8 *commit_output_to_us(const tal_t *ctx,
|
||||
u8 *tmp;
|
||||
if (!wscript)
|
||||
wscript = &tmp;
|
||||
|
||||
|
||||
/* Our output to ourself is encumbered by delay. */
|
||||
if (side == LOCAL) {
|
||||
*wscript = bitcoin_redeem_secret_or_delay(ctx,
|
||||
|
@ -50,10 +50,10 @@ struct key_negotiate {
|
||||
|
||||
/* Logging structure we're using. */
|
||||
struct log *log;
|
||||
|
||||
|
||||
/* Did we expect a particular ID? */
|
||||
const struct pubkey *expected_id;
|
||||
|
||||
|
||||
/* Callback once it's all done. */
|
||||
struct io_plan *(*cb)(struct io_conn *conn,
|
||||
struct lightningd_state *dstate,
|
||||
@ -138,7 +138,7 @@ static void le64_nonce(unsigned char *npub, u64 nonce)
|
||||
memcpy(npub, &le_nonce, sizeof(le_nonce));
|
||||
BUILD_ASSERT(crypto_aead_chacha20poly1305_NPUBBYTES == sizeof(le_nonce));
|
||||
}
|
||||
|
||||
|
||||
/* Encrypts data..data + len - 1 inclusive into data..data + len - 1 and
|
||||
* then writes the authentication tag at data+len.
|
||||
*
|
||||
@ -175,7 +175,7 @@ static bool decrypt_in_place(void *data, size_t len,
|
||||
|
||||
le64_nonce(npub, *nonce);
|
||||
mlen = len + crypto_aead_chacha20poly1305_ABYTES;
|
||||
|
||||
|
||||
ret = crypto_aead_chacha20poly1305_decrypt(data, &mlen, NULL,
|
||||
memcheck(data, mlen), mlen,
|
||||
NULL, 0,
|
||||
|
48
daemon/db.c
48
daemon/db.c
@ -686,7 +686,7 @@ static void load_peer_htlcs(struct peer *peer)
|
||||
peer->remote.staging_cstate->side[REMOTE].fee_msat,
|
||||
peer->remote.staging_cstate->side[LOCAL].num_htlcs,
|
||||
peer->remote.staging_cstate->side[REMOTE].num_htlcs);
|
||||
|
||||
|
||||
tal_free(ctx);
|
||||
}
|
||||
|
||||
@ -776,7 +776,7 @@ static const char *linearize_shachain(const tal_t *ctx,
|
||||
push_le64(0, push, &p);
|
||||
push(zeroes, sizeof(zeroes), &p);
|
||||
}
|
||||
|
||||
|
||||
assert(tal_count(p) == SHACHAIN_SIZE);
|
||||
str = tal_hexstr(ctx, p, tal_count(p));
|
||||
tal_free(p);
|
||||
@ -1359,7 +1359,7 @@ void db_set_anchor(struct peer *peer)
|
||||
peerid = pubkey_to_hexstr(ctx, peer->dstate->secpctx, peer->id);
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO anchors VALUES (x'%s', x'%s', %u, %"PRIu64", %i, %u, %s);",
|
||||
peerid,
|
||||
tal_hexstr(ctx, &peer->anchor.txid, sizeof(peer->anchor.txid)),
|
||||
@ -1369,7 +1369,7 @@ void db_set_anchor(struct peer *peer)
|
||||
peer->anchor.min_depth,
|
||||
sql_bool(peer->anchor.ours));
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO commit_info VALUES(x'%s', '%s', 0, x'%s', %"PRIi64", %s, NULL);",
|
||||
peerid,
|
||||
side_to_str(LOCAL),
|
||||
@ -1379,7 +1379,7 @@ void db_set_anchor(struct peer *peer)
|
||||
sig_to_sql(ctx, peer->dstate->secpctx,
|
||||
peer->local.commit->sig));
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO commit_info VALUES(x'%s', '%s', 0, x'%s', %"PRIi64", %s, NULL);",
|
||||
peerid,
|
||||
side_to_str(REMOTE),
|
||||
@ -1405,7 +1405,7 @@ void db_set_visible_state(struct peer *peer)
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO their_visible_state VALUES (x'%s', %s, x'%s', x'%s', %u, %u, %"PRIu64", x'%s');",
|
||||
peerid,
|
||||
sql_bool(peer->remote.offer_anchor),
|
||||
@ -1431,7 +1431,7 @@ void db_update_next_revocation_hash(struct peer *peer)
|
||||
tal_hexstr(ctx, &peer->remote.next_revocation_hash,
|
||||
sizeof(peer->remote.next_revocation_hash)));
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"UPDATE their_visible_state SET next_revocation_hash=x'%s' WHERE peer=x'%s';",
|
||||
tal_hexstr(ctx, &peer->remote.next_revocation_hash,
|
||||
sizeof(peer->remote.next_revocation_hash)),
|
||||
@ -1446,19 +1446,19 @@ void db_create_peer(struct peer *peer)
|
||||
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO peers VALUES (x'%s', '%s', %s, %"PRIi64");",
|
||||
peerid,
|
||||
state_name(peer->state),
|
||||
sql_bool(peer->local.offer_anchor),
|
||||
peer->local.commit_fee_rate);
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO peer_secrets VALUES (x'%s', %s);",
|
||||
peerid, peer_secrets_for_db(ctx, peer));
|
||||
|
||||
if (peer->local.offer_anchor)
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO anchor_inputs VALUES"
|
||||
" (x'%s', x'%s', %u, %"PRIi64", %"PRIi64", x'%s');",
|
||||
peerid,
|
||||
@ -1469,7 +1469,7 @@ void db_create_peer(struct peer *peer)
|
||||
peer->anchor.input->out_amount,
|
||||
pubkey_to_hexstr(ctx, peer->dstate->secpctx,
|
||||
&peer->anchor.input->walletkey));
|
||||
|
||||
|
||||
tal_free(ctx);
|
||||
}
|
||||
|
||||
@ -1524,7 +1524,7 @@ void db_new_htlc(struct peer *peer, const struct htlc *htlc)
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
|
||||
if (htlc->src) {
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO htlcs VALUES"
|
||||
" (x'%s', %"PRIu64", '%s', %"PRIu64", %u, x'%s', NULL, x'%s', x'%s', %"PRIu64", NULL);",
|
||||
pubkey_to_hexstr(ctx, peer->dstate->secpctx, peer->id),
|
||||
@ -1537,7 +1537,7 @@ void db_new_htlc(struct peer *peer, const struct htlc *htlc)
|
||||
peerid,
|
||||
htlc->src->id);
|
||||
} else {
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO htlcs VALUES"
|
||||
" (x'%s', %"PRIu64", '%s', %"PRIu64", %u, x'%s', NULL, x'%s', NULL, NULL, NULL);",
|
||||
peerid,
|
||||
@ -1560,7 +1560,7 @@ void db_new_feechange(struct peer *peer, const struct feechange *feechange)
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"INSERT INTO feechanges VALUES"
|
||||
" (x'%s', '%s', %"PRIu64");",
|
||||
peerid,
|
||||
@ -1580,7 +1580,7 @@ void db_update_htlc_state(struct peer *peer, const struct htlc *htlc,
|
||||
htlc->id, htlc_state_name(oldstate),
|
||||
htlc_state_name(htlc->state));
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"UPDATE htlcs SET state='%s' WHERE peer=x'%s' AND id=%"PRIu64" AND state='%s';",
|
||||
htlc_state_name(htlc->state), peerid,
|
||||
htlc->id, htlc_state_name(oldstate));
|
||||
@ -1599,7 +1599,7 @@ void db_update_feechange_state(struct peer *peer,
|
||||
feechange_state_name(oldstate),
|
||||
feechange_state_name(f->state));
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"UPDATE feechanges SET state='%s' WHERE peer=x'%s' AND state='%s';",
|
||||
feechange_state_name(f->state), peerid,
|
||||
feechange_state_name(oldstate));
|
||||
@ -1616,7 +1616,7 @@ void db_remove_feechange(struct peer *peer, const struct feechange *feechange,
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"DELETE FROM feechanges WHERE peer=x'%s' AND state='%s';",
|
||||
peerid, feechange_state_name(oldstate));
|
||||
|
||||
@ -1631,7 +1631,7 @@ void db_update_state(struct peer *peer)
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"UPDATE peers SET state='%s' WHERE peer=x'%s';",
|
||||
state_name(peer->state), peerid);
|
||||
tal_free(ctx);
|
||||
@ -1645,7 +1645,7 @@ void db_htlc_fulfilled(struct peer *peer, const struct htlc *htlc)
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"UPDATE htlcs SET r=x'%s' WHERE peer=x'%s' AND id=%"PRIu64" AND state='%s';",
|
||||
tal_hexstr(ctx, htlc->r, sizeof(*htlc->r)),
|
||||
peerid,
|
||||
@ -1663,7 +1663,7 @@ void db_htlc_failed(struct peer *peer, const struct htlc *htlc)
|
||||
log_debug(peer->log, "%s(%s)", __func__, peerid);
|
||||
|
||||
assert(peer->dstate->db->in_transaction);
|
||||
db_exec(__func__, peer->dstate,
|
||||
db_exec(__func__, peer->dstate,
|
||||
"UPDATE htlcs SET fail=x'%s' WHERE peer=x'%s' AND id=%"PRIu64" AND state='%s';",
|
||||
tal_hexstr(ctx, htlc->fail, sizeof(*htlc->fail)),
|
||||
peerid,
|
||||
@ -1714,7 +1714,7 @@ void db_remove_their_prev_revocation_hash(struct peer *peer)
|
||||
peerid);
|
||||
tal_free(ctx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void db_save_shachain(struct peer *peer)
|
||||
{
|
||||
@ -1952,7 +1952,7 @@ bool db_new_invoice(struct lightningd_state *dstate,
|
||||
{
|
||||
const tal_t *ctx = tal_tmpctx(dstate);
|
||||
bool ok;
|
||||
|
||||
|
||||
log_debug(dstate->base_log, "%s", __func__);
|
||||
|
||||
assert(!dstate->db->in_transaction);
|
||||
@ -1976,7 +1976,7 @@ void db_resolve_invoice(struct lightningd_state *dstate,
|
||||
log_debug(dstate->base_log, "%s", __func__);
|
||||
|
||||
assert(dstate->db->in_transaction);
|
||||
|
||||
|
||||
db_exec(__func__, dstate, "UPDATE invoice SET paid_num=%"PRIu64" WHERE label=x'%s';",
|
||||
paid_num, tal_hexstr(ctx, label, strlen(label)));
|
||||
tal_free(ctx);
|
||||
@ -1991,7 +1991,7 @@ bool db_remove_invoice(struct lightningd_state *dstate,
|
||||
log_debug(dstate->base_log, "%s", __func__);
|
||||
|
||||
assert(!dstate->db->in_transaction);
|
||||
|
||||
|
||||
ok = db_exec(__func__, dstate, "DELETE FROM invoice WHERE label=x'%s';",
|
||||
tal_hexstr(ctx, label, strlen(label)));
|
||||
tal_free(ctx);
|
||||
|
@ -141,4 +141,3 @@ void feechange_changestate(struct peer *peer,
|
||||
db_update_feechange_state(peer, f, oldstate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ struct peer;
|
||||
|
||||
struct feechange {
|
||||
/* What's the status */
|
||||
enum feechange_state state;
|
||||
enum feechange_state state;
|
||||
/* The rate. */
|
||||
u64 fee_rate;
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ struct htlc {
|
||||
/* Block number where we abort if it's still live (LOCAL only) */
|
||||
u32 deadline;
|
||||
/* What's the status. */
|
||||
enum htlc_state state;
|
||||
enum htlc_state state;
|
||||
/* The unique ID for this peer and this direction (LOCAL or REMOTE) */
|
||||
u64 id;
|
||||
/* The amount in millisatoshi. */
|
||||
|
@ -82,7 +82,7 @@ static void tell_waiter(struct command *cmd, const struct invoice *paid)
|
||||
json_object_end(response);
|
||||
command_success(cmd, response);
|
||||
}
|
||||
|
||||
|
||||
void resolve_invoice(struct lightningd_state *dstate,
|
||||
struct invoice *invoice)
|
||||
{
|
||||
@ -100,13 +100,13 @@ void resolve_invoice(struct lightningd_state *dstate,
|
||||
|
||||
db_resolve_invoice(dstate, invoice->label, invoice->paid_num);
|
||||
}
|
||||
|
||||
|
||||
static void json_invoice(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
struct invoice *invoice;
|
||||
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,
|
||||
"amount", &msatoshi,
|
||||
@ -163,7 +163,7 @@ static void json_invoice(struct command *cmd,
|
||||
&invoice->r)) {
|
||||
command_fail(cmd, "database error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* OK, connect it to main state, respond with hash */
|
||||
tal_steal(cmd->dstate, invoice);
|
||||
list_add(&cmd->dstate->unpaid, &invoice->list);
|
||||
@ -208,7 +208,7 @@ static void json_listinvoice(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
jsmntok_t *label = NULL;
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
|
||||
if (!json_get_params(buffer, params,
|
||||
"?label", &label,
|
||||
@ -217,7 +217,7 @@ static void json_listinvoice(struct command *cmd,
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
json_array_start(response, NULL);
|
||||
json_add_invoices(response, &cmd->dstate->paid, buffer, label);
|
||||
json_add_invoices(response, &cmd->dstate->unpaid, buffer, label);
|
||||
@ -259,7 +259,7 @@ static void json_delinvoice(struct command *cmd,
|
||||
return;
|
||||
}
|
||||
list_del_from(&cmd->dstate->unpaid, &i->list);
|
||||
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "label", i->label);
|
||||
json_add_hex(response, "rhash", &i->rhash, sizeof(i->rhash));
|
||||
|
@ -163,7 +163,7 @@ const jsmntok_t *json_get_member(const char *buffer, const jsmntok_t tok[],
|
||||
for (t = tok + 1; t < end; t = json_next(t+1))
|
||||
if (json_tok_streq(buffer, t, label))
|
||||
return t + 1;
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -277,7 +277,7 @@ jsmntok_t *json_parse_input(const char *input, int len, bool *valid)
|
||||
|
||||
toks = tal_arr(input, jsmntok_t, 10);
|
||||
|
||||
again:
|
||||
again:
|
||||
jsmn_init(&parser);
|
||||
ret = jsmn_parse(&parser, input, len, toks, tal_count(toks) - 1);
|
||||
|
||||
@ -299,7 +299,7 @@ again:
|
||||
/* Make sure last one is always referencable. */
|
||||
toks[ret].type = -1;
|
||||
toks[ret].start = toks[ret].end = toks[ret].size = 0;
|
||||
|
||||
|
||||
return toks;
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ void json_add_u64(struct json_result *result, const char *fieldname,
|
||||
json_start_member(result, fieldname);
|
||||
result_append_fmt(result, "%"PRIu64, value);
|
||||
}
|
||||
|
||||
|
||||
void json_add_literal(struct json_result *result, const char *fieldname,
|
||||
const char *literal, int len)
|
||||
{
|
||||
@ -473,7 +473,7 @@ struct json_result *new_json_result(const tal_t *ctx)
|
||||
r->indent = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
const char *json_result_string(const struct json_result *result)
|
||||
{
|
||||
assert(!result->indent);
|
||||
|
@ -248,8 +248,8 @@ static void json_restart(struct command *cmd,
|
||||
debug_dump_peers(cmd->dstate);
|
||||
io_break(cmd->dstate);
|
||||
command_success(cmd, null_response(cmd));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static const struct json_command dev_restart_command = {
|
||||
"dev-restart",
|
||||
json_restart,
|
||||
@ -374,7 +374,7 @@ static void json_result(struct json_connection *jcon,
|
||||
struct json_result *null_response(const tal_t *ctx)
|
||||
{
|
||||
struct json_result *response;
|
||||
|
||||
|
||||
response = new_json_result(ctx);
|
||||
json_object_start(response, NULL);
|
||||
json_object_end(response);
|
||||
@ -502,7 +502,7 @@ static struct io_plan *write_json(struct io_conn *conn,
|
||||
struct json_connection *jcon)
|
||||
{
|
||||
struct json_output *out;
|
||||
|
||||
|
||||
out = list_pop(&jcon->output, struct json_output, list);
|
||||
if (!out) {
|
||||
if (jcon->stop) {
|
||||
|
@ -328,7 +328,7 @@ static void check_config(struct lightningd_state *dstate)
|
||||
|
||||
if (dstate->config.anchor_confirms == 0)
|
||||
fatal("anchor-confirms must be greater than zero");
|
||||
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* a node MUST estimate the deadline for successful redemption
|
||||
@ -481,7 +481,7 @@ int main(int argc, char *argv[])
|
||||
if (!streq(protobuf_c_version(), PROTOBUF_C_VERSION))
|
||||
errx(1, "Compiled against protobuf %s, but have %s",
|
||||
PROTOBUF_C_VERSION, protobuf_c_version());
|
||||
|
||||
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"\n"
|
||||
"A bitcoin lightning daemon.",
|
||||
@ -556,7 +556,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* And send out anchors again if we're waiting. */
|
||||
rebroadcast_anchors(dstate);
|
||||
|
||||
|
||||
for (;;) {
|
||||
struct timer *expired;
|
||||
void *v = io_loop(&dstate->timers, &expired);
|
||||
|
@ -52,11 +52,11 @@ struct config {
|
||||
|
||||
/* How many blocks before upstream HTLC expiry do we panic and dump? */
|
||||
u32 deadline_blocks;
|
||||
|
||||
|
||||
/* Fee rates. */
|
||||
u32 fee_base;
|
||||
s32 fee_per_satoshi;
|
||||
|
||||
|
||||
/* How long between polling bitcoind. */
|
||||
struct timerel poll_time;
|
||||
|
||||
@ -72,7 +72,7 @@ struct config {
|
||||
|
||||
/* Here's where the global variables hide! */
|
||||
struct lightningd_state {
|
||||
/* Where all our logging goes. */
|
||||
/* Where all our logging goes. */
|
||||
struct log_record *log_record;
|
||||
struct log *base_log;
|
||||
FILE *logf;
|
||||
@ -98,7 +98,7 @@ struct lightningd_state {
|
||||
|
||||
/* Cached block topology. */
|
||||
struct topology *topology;
|
||||
|
||||
|
||||
/* Our peers. */
|
||||
struct list_head peers;
|
||||
|
||||
@ -107,7 +107,7 @@ struct lightningd_state {
|
||||
|
||||
/* Any outstanding "pay" commands. */
|
||||
struct list_head pay_commands;
|
||||
|
||||
|
||||
/* Crypto tables for global use. */
|
||||
secp256k1_context *secpctx;
|
||||
|
||||
@ -133,7 +133,7 @@ struct lightningd_state {
|
||||
u64 invoices_completed;
|
||||
/* Waiting for new invoices to be paid. */
|
||||
struct list_head invoice_waiters;
|
||||
|
||||
|
||||
/* All known nodes. */
|
||||
struct node_map *nodes;
|
||||
|
||||
@ -142,7 +142,7 @@ struct lightningd_state {
|
||||
|
||||
/* For testing: don't broadcast txs (but pretend it worked)(. */
|
||||
bool dev_no_broadcast;
|
||||
|
||||
|
||||
/* Re-exec hack for testing. */
|
||||
char **reexec;
|
||||
|
||||
|
@ -85,4 +85,4 @@ bool netaddr_from_fd(int fd, int type, int protocol, struct netaddr *a)
|
||||
a->addrlen = sizeof(a->saddr);
|
||||
return getpeername(fd, &a->saddr.s, &a->addrlen) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ char *opt_set_time(const char *arg, struct timerel *t)
|
||||
return tal_fmt(NULL, "Unknown time unit %s", endp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void opt_show_time(char buf[OPT_SHOW_LEN], const struct timerel *t)
|
||||
{
|
||||
if (t->ts.tv_nsec) {
|
||||
|
@ -40,7 +40,7 @@ static Pkt *make_pkt(const tal_t *ctx, Pkt__PktCase type, const void *msg)
|
||||
size_t len;
|
||||
u8 *packed;
|
||||
Pkt *cpy;
|
||||
|
||||
|
||||
len = pkt__get_packed_size(pkt);
|
||||
packed = tal_arr(pkt, u8, len);
|
||||
pkt__pack(pkt, packed);
|
||||
@ -353,7 +353,7 @@ Pkt *accept_pkt_anchor(struct peer *peer, const Pkt *pkt)
|
||||
|
||||
if (anchor_too_large(a->amount))
|
||||
return pkt_err(peer, "Anchor millisatoshis exceeds 32 bits");
|
||||
|
||||
|
||||
proto_to_sha256(a->txid, &peer->anchor.txid.sha);
|
||||
peer->anchor.index = a->output_index;
|
||||
peer->anchor.satoshis = a->amount;
|
||||
@ -559,7 +559,7 @@ Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt)
|
||||
&peer->remote.next_revocation_hash);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Pkt *accept_pkt_close_shutdown(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
const CloseShutdown *c = pkt->close_shutdown;
|
||||
|
@ -41,7 +41,7 @@ Pkt *accept_pkt_open_commit_sig(struct peer *peer, const Pkt *pkt,
|
||||
struct bitcoin_signature *sig);
|
||||
|
||||
Pkt *accept_pkt_open_complete(struct peer *peer, const Pkt *pkt);
|
||||
|
||||
|
||||
Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt, struct htlc **h);
|
||||
|
||||
Pkt *accept_pkt_htlc_fail(struct peer *peer, const Pkt *pkt, struct htlc **h,
|
||||
|
@ -15,5 +15,4 @@ bool pay_add(struct lightningd_state *dstate,
|
||||
struct htlc *htlc,
|
||||
const u8 *fail,
|
||||
const struct rval *r);
|
||||
|
||||
#endif /* LIGHTNING_DAEMON_PAY_H */
|
||||
|
@ -741,7 +741,7 @@ static bool open_wait_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
case STATE_OPEN_WAIT_THEIRCOMPLETE:
|
||||
if (pkt->pkt_case != PKT__PKT_OPEN_COMPLETE)
|
||||
return peer_received_unexpected_pkt(peer, pkt, __func__);
|
||||
|
||||
|
||||
err = accept_pkt_open_complete(peer, pkt);
|
||||
if (err) {
|
||||
peer_open_complete(peer, err->error->problem);
|
||||
@ -811,7 +811,7 @@ static void route_htlc_onwards(struct peer *peer,
|
||||
struct sha256, &htlc->rhash);
|
||||
log_add(peer->log, " (id %"PRIu64")", htlc->id);
|
||||
}
|
||||
|
||||
|
||||
next = find_peer_by_pkhash(peer->dstate, pb_id);
|
||||
if (!next || !next->nc) {
|
||||
log_unusual(peer->log, "Can't route HTLC %"PRIu64": no %speer ",
|
||||
@ -824,7 +824,7 @@ static void route_htlc_onwards(struct peer *peer,
|
||||
|
||||
if (only_dest && next != only_dest)
|
||||
return;
|
||||
|
||||
|
||||
/* Offered fee must be sufficient. */
|
||||
if ((s64)(htlc->msatoshi - msatoshi)
|
||||
< connection_fee(next->nc, msatoshi)) {
|
||||
@ -917,7 +917,7 @@ static void their_htlc_added(struct peer *peer, struct htlc *htlc,
|
||||
"unknown rhash");
|
||||
goto free_packet;
|
||||
}
|
||||
|
||||
|
||||
if (htlc->msatoshi != invoice->msatoshi) {
|
||||
log_unusual(peer->log, "Short payment for '%s' HTLC %"PRIu64
|
||||
": %"PRIu64" not %"PRIu64 " satoshi!",
|
||||
@ -1035,14 +1035,14 @@ static bool adjust_cstate_side(struct channel_state *cstate,
|
||||
{
|
||||
int oldf = htlc_state_flags(old), newf = htlc_state_flags(new);
|
||||
bool old_committed, new_committed;
|
||||
|
||||
/* We applied changes to staging_cstate when we first received
|
||||
|
||||
/* We applied changes to staging_cstate when we first received
|
||||
* add/remove packet, so we could make sure it was valid. Don't
|
||||
* do that again. */
|
||||
if (old == SENT_ADD_HTLC || old == RCVD_REMOVE_HTLC
|
||||
|| old == RCVD_ADD_HTLC || old == SENT_REMOVE_HTLC)
|
||||
return true;
|
||||
|
||||
|
||||
old_committed = (oldf & HTLC_FLAG(side, HTLC_F_COMMITTED));
|
||||
new_committed = (newf & HTLC_FLAG(side, HTLC_F_COMMITTED));
|
||||
|
||||
@ -1082,7 +1082,7 @@ static void adjust_cstate_fee_side(struct channel_state *cstate,
|
||||
enum feechange_state new,
|
||||
enum side side)
|
||||
{
|
||||
/* We applied changes to staging_cstate when we first received
|
||||
/* We applied changes to staging_cstate when we first received
|
||||
* feechange packet, so we could make sure it was valid. Don't
|
||||
* do that again. */
|
||||
if (old == SENT_FEECHANGE || old == RCVD_FEECHANGE)
|
||||
@ -1344,7 +1344,7 @@ static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||
ci = new_commit_info(peer, peer->local.commit->commit_num + 1);
|
||||
|
||||
db_start_transaction(peer);
|
||||
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A node MUST NOT send an `update_commit` message which does
|
||||
@ -1446,7 +1446,7 @@ static Pkt *handle_pkt_commit(struct peer *peer, const Pkt *pkt)
|
||||
/* If we're shutting down and no more HTLCs, begin closing */
|
||||
if (peer->closing.their_script && !committed_to_htlcs(peer))
|
||||
start_closing_in_transaction(peer);
|
||||
|
||||
|
||||
if (db_commit_transaction(peer) != NULL)
|
||||
return pkt_err(peer, "Database error");
|
||||
|
||||
@ -1462,7 +1462,7 @@ static Pkt *handle_pkt_htlc_add(struct peer *peer, const Pkt *pkt)
|
||||
if (err)
|
||||
return err;
|
||||
assert(htlc->state == RCVD_ADD_HTLC);
|
||||
|
||||
|
||||
/* BOLT #2:
|
||||
*
|
||||
* A node MUST NOT offer `amount_msat` it cannot pay for in
|
||||
@ -1482,7 +1482,7 @@ static Pkt *handle_pkt_htlc_add(struct peer *peer, const Pkt *pkt)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static Pkt *handle_pkt_htlc_fail(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
struct htlc *htlc;
|
||||
@ -1498,7 +1498,7 @@ static Pkt *handle_pkt_htlc_fail(struct peer *peer, const Pkt *pkt)
|
||||
log_debug(peer->log, "HTLC %"PRIu64" failed twice", htlc->id);
|
||||
htlc->fail = tal_free(htlc->fail);
|
||||
}
|
||||
|
||||
|
||||
db_start_transaction(peer);
|
||||
|
||||
set_htlc_fail(peer, htlc, fail, tal_count(fail));
|
||||
@ -1527,7 +1527,7 @@ static Pkt *handle_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt)
|
||||
err = accept_pkt_htlc_fulfill(peer, pkt, &htlc, &r);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
||||
/* Reconnect may mean HTLC was already fulfilled. That's OK. */
|
||||
if (!htlc->r) {
|
||||
db_start_transaction(peer);
|
||||
@ -1635,7 +1635,7 @@ static Pkt *handle_pkt_revocation(struct peer *peer, const Pkt *pkt,
|
||||
return pkt_err(peer, "database error");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* This is the io loop while we're doing shutdown. */
|
||||
static bool shutdown_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
@ -1658,7 +1658,7 @@ static bool shutdown_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
|
||||
case PKT__PKT_UPDATE_ADD_HTLC:
|
||||
/* BOLT #2:
|
||||
*
|
||||
*
|
||||
* A node MUST NOT send a `update_add_htlc` after a
|
||||
* `close_shutdown` */
|
||||
if (peer->closing.their_script)
|
||||
@ -1666,10 +1666,10 @@ static bool shutdown_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
else
|
||||
err = handle_pkt_htlc_add(peer, pkt);
|
||||
break;
|
||||
|
||||
|
||||
case PKT__PKT_CLOSE_SHUTDOWN:
|
||||
/* BOLT #2:
|
||||
*
|
||||
*
|
||||
* A node... MUST NOT send more than one `close_shutdown`. */
|
||||
if (peer->closing.their_script)
|
||||
return peer_received_unexpected_pkt(peer, pkt, __func__);
|
||||
@ -1686,7 +1686,7 @@ static bool shutdown_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case PKT__PKT_UPDATE_FULFILL_HTLC:
|
||||
err = handle_pkt_htlc_fulfill(peer, pkt);
|
||||
break;
|
||||
@ -1757,7 +1757,7 @@ static bool do_commit(struct peer *peer, struct command *jsoncmd)
|
||||
&peer->remote.commit->revocation_hash);
|
||||
|
||||
db_start_transaction(peer);
|
||||
|
||||
|
||||
errmsg = changestates(peer, changes, ARRAY_SIZE(changes),
|
||||
feechanges, ARRAY_SIZE(feechanges), true);
|
||||
if (errmsg) {
|
||||
@ -1864,7 +1864,7 @@ static bool peer_start_shutdown(struct peer *peer)
|
||||
|
||||
return db_commit_transaction(peer) == NULL;
|
||||
}
|
||||
|
||||
|
||||
/* This is the io loop while we're in normal mode. */
|
||||
static bool normal_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
{
|
||||
@ -1877,7 +1877,7 @@ static bool normal_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
case PKT__PKT_UPDATE_ADD_HTLC:
|
||||
err = handle_pkt_htlc_add(peer, pkt);
|
||||
break;
|
||||
|
||||
|
||||
case PKT__PKT_UPDATE_FULFILL_HTLC:
|
||||
err = handle_pkt_htlc_fulfill(peer, pkt);
|
||||
break;
|
||||
@ -1914,7 +1914,7 @@ static bool normal_pkt_in(struct peer *peer, const Pkt *pkt)
|
||||
/* Fall thru. */
|
||||
default:
|
||||
return peer_received_unexpected_pkt(peer, pkt, __func__);
|
||||
}
|
||||
}
|
||||
|
||||
if (err) {
|
||||
return peer_comms_err(peer, err);
|
||||
@ -2638,7 +2638,7 @@ static void try_commit(struct peer *peer)
|
||||
* reconnect, rather than using timer! */
|
||||
log_debug(peer->log, "try_commit: state=%s, re-queueing timer",
|
||||
state_name(peer->state));
|
||||
|
||||
|
||||
remote_changes_pending(peer);
|
||||
}
|
||||
}
|
||||
@ -2678,7 +2678,7 @@ static bool peer_reconnected(struct peer *peer,
|
||||
io_set_finish(conn, peer_disconnect, peer);
|
||||
|
||||
name = netaddr_name(peer, &addr);
|
||||
log_info(peer->log, "Reconnected %s %s",
|
||||
log_info(peer->log, "Reconnected %s %s",
|
||||
we_connected ? "out to" : "in from", name);
|
||||
tal_free(name);
|
||||
|
||||
@ -2734,7 +2734,7 @@ struct peer *new_peer(struct lightningd_state *dstate,
|
||||
peer->local.staging_cstate = peer->remote.staging_cstate = NULL;
|
||||
peer->log = tal_steal(peer, log);
|
||||
log_debug(peer->log, "New peer %p", peer);
|
||||
|
||||
|
||||
htlc_map_init(&peer->htlcs);
|
||||
memset(peer->feechanges, 0, sizeof(peer->feechanges));
|
||||
shachain_init(&peer->their_preimages);
|
||||
@ -2805,7 +2805,7 @@ static bool peer_first_connected(struct peer *peer,
|
||||
|
||||
name = netaddr_name(peer, &addr);
|
||||
idstr = pubkey_to_hexstr(name, peer->dstate->secpctx, peer->id);
|
||||
log_info(peer->log, "Connected %s %s id %s, changing prefix",
|
||||
log_info(peer->log, "Connected %s %s id %s, changing prefix",
|
||||
we_connected ? "out to" : "in from", name, idstr);
|
||||
set_log_prefix(peer->log, tal_fmt(name, "%s:", idstr));
|
||||
tal_free(name);
|
||||
@ -2821,7 +2821,7 @@ static void htlc_destroy(struct htlc *htlc)
|
||||
fatal("Could not find htlc to destroy");
|
||||
}
|
||||
|
||||
struct htlc *peer_new_htlc(struct peer *peer,
|
||||
struct htlc *peer_new_htlc(struct peer *peer,
|
||||
u64 id,
|
||||
u64 msatoshi,
|
||||
const struct sha256 *rhash,
|
||||
@ -3216,7 +3216,7 @@ static bool any_deadline_past(struct peer *peer)
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void check_htlc_expiry(struct peer *peer)
|
||||
{
|
||||
@ -3272,7 +3272,7 @@ static void peer_depth_ok(struct peer *peer)
|
||||
queue_pkt_open_complete(peer);
|
||||
|
||||
db_start_transaction(peer);
|
||||
|
||||
|
||||
switch (peer->state) {
|
||||
case STATE_OPEN_WAIT_ANCHORDEPTH_AND_THEIRCOMPLETE:
|
||||
set_peer_state(peer, STATE_OPEN_WAIT_THEIRCOMPLETE,
|
||||
@ -3342,7 +3342,7 @@ static enum watch_result anchor_depthchange(struct peer *peer,
|
||||
get_feerate(peer->dstate));
|
||||
peer_fail(peer, __func__);
|
||||
}
|
||||
|
||||
|
||||
return KEEP_WATCHING;
|
||||
}
|
||||
|
||||
@ -3552,7 +3552,7 @@ static void fail_own_htlc(struct peer *peer, struct htlc *htlc)
|
||||
db_commit_transaction(peer);
|
||||
}
|
||||
|
||||
/* We've spent an HTLC output to get our funds back. There's still a
|
||||
/* We've spent an HTLC output to get our funds back. There's still a
|
||||
* chance that they could also spend the HTLC output (using the preimage),
|
||||
* so we need to wait for some confirms.
|
||||
*
|
||||
@ -3739,7 +3739,7 @@ static enum watch_result our_htlc_spent(struct peer *peer,
|
||||
|| tal_count(tx->input[input_num].witness) != 3
|
||||
|| tal_count(tx->input[input_num].witness[1]) != sizeof(preimage))
|
||||
fatal("Impossible HTLC spend for %"PRIu64, h->id);
|
||||
|
||||
|
||||
/* Our timeout tx has all-zeroes, so we can distinguish it. */
|
||||
if (memeqzero(tx->input[input_num].witness[1], sizeof(preimage)))
|
||||
/* They might try to race us. */
|
||||
@ -3811,7 +3811,7 @@ static void resolve_their_htlc(struct peer *peer, unsigned int out_num)
|
||||
*/
|
||||
watch_tx(peer->onchain.tx, peer, peer->onchain.tx,
|
||||
their_htlc_depth, int2ptr(out_num));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* BOLT #onchain:
|
||||
@ -3934,7 +3934,7 @@ static enum watch_result check_for_resolution(struct peer *peer,
|
||||
{
|
||||
size_t i, n = tal_count(peer->onchain.resolved);
|
||||
size_t forever = peer->dstate->config.forever_confirms;
|
||||
|
||||
|
||||
/* BOLT #onchain:
|
||||
*
|
||||
* A node MUST *resolve* all outputs as specified below, and MUST be
|
||||
@ -3980,7 +3980,7 @@ static enum watch_result check_for_resolution(struct peer *peer,
|
||||
return DELETE_WATCH;
|
||||
}
|
||||
|
||||
static bool find_their_old_tx(struct peer *peer,
|
||||
static bool find_their_old_tx(struct peer *peer,
|
||||
const struct sha256_double *txid,
|
||||
u64 *idx)
|
||||
{
|
||||
@ -4123,7 +4123,7 @@ static struct sha256 *get_rhash(struct peer *peer, u64 commit_num,
|
||||
*rhash = *peer->their_prev_revocation_hash;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* We assume the tx is valid! Don't do a blockchain.info and feed this
|
||||
* invalid transactions! */
|
||||
static enum watch_result anchor_spent(struct peer *peer,
|
||||
@ -4226,7 +4226,7 @@ static enum watch_result anchor_spent(struct peer *peer,
|
||||
|
||||
/* If we've just closed connection, make output close it. */
|
||||
io_wake(peer);
|
||||
|
||||
|
||||
/* BOLT #onchain:
|
||||
*
|
||||
* A node SHOULD fail the connection if it is not already
|
||||
@ -4364,7 +4364,7 @@ static struct io_plan *peer_reconnect(struct io_conn *conn, struct peer *peer)
|
||||
}
|
||||
|
||||
/* 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.. */
|
||||
* 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)? */
|
||||
@ -4404,7 +4404,7 @@ static void try_reconnect(struct peer *peer)
|
||||
log_debug(peer->log, "try_reconnect: no known address");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
fd = socket(addr->addr.saddr.s.sa_family, addr->addr.type,
|
||||
addr->addr.protocol);
|
||||
if (fd < 0) {
|
||||
@ -4494,7 +4494,7 @@ static void json_getpeers(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
struct peer *p;
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_array_start(response, "peers");
|
||||
@ -4939,7 +4939,7 @@ static void json_commit(struct command *cmd,
|
||||
|
||||
do_commit(peer, cmd);
|
||||
}
|
||||
|
||||
|
||||
const struct json_command dev_commit_command = {
|
||||
"dev-commit",
|
||||
json_commit,
|
||||
@ -5006,7 +5006,7 @@ static void json_feerate(struct command *cmd,
|
||||
}
|
||||
log_debug(cmd->jcon->log, "Fee rate changed to %"PRIu64, feerate);
|
||||
cmd->dstate->config.default_fee_rate = feerate;
|
||||
|
||||
|
||||
command_success(cmd, null_response(cmd));
|
||||
}
|
||||
|
||||
@ -5158,7 +5158,7 @@ static void json_output(struct command *cmd,
|
||||
/* Flush any outstanding output */
|
||||
if (peer->output_enabled)
|
||||
io_wake(peer);
|
||||
|
||||
|
||||
command_success(cmd, null_response(cmd));
|
||||
}
|
||||
const struct json_command dev_output_command = {
|
||||
|
@ -39,7 +39,7 @@ struct their_commit {
|
||||
struct sha256_double txid;
|
||||
u64 commit_num;
|
||||
};
|
||||
|
||||
|
||||
struct commit_info {
|
||||
/* Commit number (0 == from open) */
|
||||
u64 commit_num;
|
||||
@ -97,7 +97,7 @@ struct peer {
|
||||
|
||||
/* Are we connected now? (Crypto handshake completed). */
|
||||
bool connected;
|
||||
|
||||
|
||||
/* If we're doing an open, this is the command which triggered it */
|
||||
struct command *open_jsoncmd;
|
||||
|
||||
@ -112,7 +112,7 @@ struct peer {
|
||||
|
||||
/* Order counter for transmission of revocations/commitments. */
|
||||
s64 order_counter;
|
||||
|
||||
|
||||
/* Current received packet. */
|
||||
Pkt *inpkt;
|
||||
|
||||
@ -124,7 +124,7 @@ struct peer {
|
||||
|
||||
/* Number of commitment signatures we've received. */
|
||||
u64 their_commitsigs;
|
||||
|
||||
|
||||
/* Anchor tx output */
|
||||
struct {
|
||||
struct sha256_double txid;
|
||||
@ -137,7 +137,7 @@ struct peer {
|
||||
|
||||
/* If we're creating anchor, this tells us where to source it */
|
||||
struct anchor_input *input;
|
||||
|
||||
|
||||
/* If we created it, we keep entire tx. */
|
||||
const struct bitcoin_tx *tx;
|
||||
|
||||
@ -199,7 +199,7 @@ struct peer {
|
||||
|
||||
/* Current ongoing packetflow */
|
||||
struct io_data *io_data;
|
||||
|
||||
|
||||
/* What happened. */
|
||||
struct log *log;
|
||||
|
||||
@ -208,16 +208,16 @@ struct peer {
|
||||
|
||||
/* Bitcoin transctions we're broadcasting (see chaintopology.c) */
|
||||
struct list_head outgoing_txs;
|
||||
|
||||
|
||||
/* Timeout for collecting changes before sending commit. */
|
||||
struct oneshot *commit_timer;
|
||||
|
||||
|
||||
/* Private keys for dealing with this peer. */
|
||||
struct peer_secrets *secrets;
|
||||
|
||||
/* Our route connection to peer: NULL until we are in normal mode. */
|
||||
struct node_connection *nc;
|
||||
|
||||
|
||||
/* For testing. */
|
||||
bool fake_close;
|
||||
bool output_enabled;
|
||||
@ -227,7 +227,7 @@ struct peer {
|
||||
|
||||
/* If we have sent a new commit tx, but not received their revocation */
|
||||
struct sha256 *their_prev_revocation_hash;
|
||||
|
||||
|
||||
/* this is where we will store their revocation preimages*/
|
||||
struct shachain their_preimages;
|
||||
};
|
||||
@ -260,7 +260,7 @@ void peer_add_their_commit(struct peer *peer,
|
||||
struct commit_info *new_commit_info(const tal_t *ctx, u64 commit_num);
|
||||
|
||||
/* Freeing removes from map, too */
|
||||
struct htlc *peer_new_htlc(struct peer *peer,
|
||||
struct htlc *peer_new_htlc(struct peer *peer,
|
||||
u64 id,
|
||||
u64 msatoshi,
|
||||
const struct sha256 *rhash,
|
||||
|
@ -39,4 +39,3 @@ const struct siphash_seed *siphash_seed(void)
|
||||
|
||||
return &siphashseed;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ void peer_get_revocation_preimage(const struct peer *peer, u64 index,
|
||||
// generate hashes in reverse order, otherwise the first hash gives away everything
|
||||
shachain_from_seed(&peer->secrets->revocation_seed, 0xFFFFFFFFFFFFFFFFL - index, preimage);
|
||||
}
|
||||
|
||||
|
||||
void peer_get_revocation_hash(const struct peer *peer, u64 index,
|
||||
struct sha256 *rhash)
|
||||
{
|
||||
@ -199,7 +199,7 @@ void peer_set_secrets_from_db(struct peer *peer,
|
||||
|
||||
assert(!peer->secrets);
|
||||
peer->secrets = ps;
|
||||
|
||||
|
||||
if (commit_privkey_len != sizeof(ps->commit)
|
||||
|| final_privkey_len != sizeof(ps->final)
|
||||
|| revocation_seed_len != sizeof(ps->revocation_seed))
|
||||
|
@ -26,20 +26,20 @@ enum state {
|
||||
*/
|
||||
STATE_NORMAL,
|
||||
STATE_NORMAL_COMMITTING,
|
||||
|
||||
|
||||
/*
|
||||
* Closing (handled outside state machine).
|
||||
*/
|
||||
STATE_SHUTDOWN,
|
||||
STATE_SHUTDOWN_COMMITTING,
|
||||
STATE_MUTUAL_CLOSING,
|
||||
|
||||
|
||||
/* Four states to represent closing onchain (for getpeers) */
|
||||
STATE_CLOSE_ONCHAIN_CHEATED,
|
||||
STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL,
|
||||
STATE_CLOSE_ONCHAIN_OUR_UNILATERAL,
|
||||
STATE_CLOSE_ONCHAIN_MUTUAL,
|
||||
|
||||
|
||||
/* All closed. */
|
||||
STATE_CLOSED,
|
||||
|
||||
|
@ -13,7 +13,7 @@ void db_update_htlc_state(struct peer *peer UNNEEDED, const struct htlc *htlc UN
|
||||
{ fprintf(stderr, "db_update_htlc_state called!\n"); abort(); }
|
||||
/* Generated stub for log_ */
|
||||
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
|
||||
|
||||
|
||||
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
||||
/* AUTOGENERATED MOCKS END */
|
||||
|
||||
|
@ -41,7 +41,7 @@ bool restore_wallet_address(struct lightningd_state *dstate,
|
||||
tal_free(redeemscript);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void new_keypair(struct lightningd_state *dstate,
|
||||
struct privkey *privkey, struct pubkey *pubkey)
|
||||
{
|
||||
@ -74,7 +74,7 @@ bool wallet_add_signed_input(struct lightningd_state *dstate,
|
||||
assert(input_num < tx->input_count);
|
||||
if (!w)
|
||||
return false;
|
||||
|
||||
|
||||
redeemscript = bitcoin_redeem_p2wpkh(tx, dstate->secpctx, &w->pubkey);
|
||||
|
||||
sig.stype = SIGHASH_ALL;
|
||||
@ -113,11 +113,11 @@ bool wallet_can_spend(struct lightningd_state *dstate,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void json_newaddr(struct command *cmd,
|
||||
const char *buffer, const jsmntok_t *params)
|
||||
{
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
struct json_result *response = new_json_result(cmd);
|
||||
struct wallet *w = tal(cmd->dstate, struct wallet);
|
||||
u8 *redeemscript;
|
||||
struct sha256 h;
|
||||
@ -130,7 +130,7 @@ static void json_newaddr(struct command *cmd,
|
||||
|
||||
list_add_tail(&cmd->dstate->wallet, &w->list);
|
||||
db_add_wallet_privkey(cmd->dstate, &w->privkey);
|
||||
|
||||
|
||||
json_object_start(response, NULL);
|
||||
json_add_string(response, "address",
|
||||
p2sh_to_base58(cmd, cmd->dstate->testnet, &w->p2sh));
|
||||
|
@ -12,7 +12,7 @@
|
||||
*
|
||||
* - HTLC spend tx:
|
||||
* - Reached a given depth.
|
||||
*
|
||||
*
|
||||
* - Anchor tx output:
|
||||
* - Is spent by their current tx.
|
||||
* - Is spent by a revoked tx.
|
||||
@ -115,7 +115,7 @@ bool watching_txid(struct lightningd_state *dstate,
|
||||
{
|
||||
return txwatch_hash_get(&dstate->txwatches, txid) != NULL;
|
||||
}
|
||||
|
||||
|
||||
struct txwatch *watch_tx_(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
const struct bitcoin_tx *tx,
|
||||
|
@ -25,7 +25,7 @@ struct txwatch_output {
|
||||
struct txowatch {
|
||||
/* Peer who owns us. */
|
||||
struct peer *peer;
|
||||
|
||||
|
||||
/* Output to watch. */
|
||||
struct txwatch_output out;
|
||||
|
||||
|
@ -25,7 +25,7 @@ Signature *signature_to_proto(const tal_t *ctx,
|
||||
memcpy(&pb->s2, compact + 40, 8);
|
||||
memcpy(&pb->s3, compact + 48, 8);
|
||||
memcpy(&pb->s4, compact + 56, 8);
|
||||
|
||||
|
||||
return pb;
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ Locktime *rel_locktime_to_proto(const tal_t *ctx,
|
||||
{
|
||||
Locktime *l = tal(ctx, Locktime);
|
||||
locktime__init(l);
|
||||
|
||||
|
||||
if (rel_locktime_is_seconds(locktime)) {
|
||||
l->locktime_case = LOCKTIME__LOCKTIME_SECONDS;
|
||||
l->seconds = rel_locktime_to_seconds(locktime);
|
||||
@ -183,7 +183,7 @@ static void proto_tal_free(void *allocator_data, void *pointer)
|
||||
{
|
||||
tal_free(pointer);
|
||||
}
|
||||
|
||||
|
||||
/* Get allocator so decoded protobuf will be tal off it. */
|
||||
struct ProtobufCAllocator *make_prototal(const tal_t *ctx)
|
||||
{
|
||||
@ -196,7 +196,7 @@ struct ProtobufCAllocator *make_prototal(const tal_t *ctx)
|
||||
|
||||
return prototal;
|
||||
}
|
||||
|
||||
|
||||
/* Now steal object off of allocator (and free prototal) */
|
||||
void steal_from_prototal(const tal_t *ctx, struct ProtobufCAllocator *prototal,
|
||||
const void *pb)
|
||||
|
@ -231,7 +231,7 @@ struct peer {
|
||||
|
||||
/* What we save on disk. */
|
||||
struct database db;
|
||||
|
||||
|
||||
/* All htlcs. */
|
||||
struct htlc **htlcs;
|
||||
|
||||
@ -305,7 +305,7 @@ static struct htlc *find_htlc(struct peer *peer, unsigned int htlc_id, int side)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static struct htlc *new_htlc(struct peer *peer, unsigned int htlc_id, int side)
|
||||
{
|
||||
size_t n = tal_count(peer->htlcs);
|
||||
@ -376,7 +376,7 @@ static bool change_htlcs_(struct peer *peer, bool commit,
|
||||
|
||||
#define change_htlcs(peer, table, commit) \
|
||||
change_htlcs_((peer), (commit), (table), ARRAY_SIZE(table))
|
||||
|
||||
|
||||
static struct commit_info *new_commit_info(const struct peer *peer,
|
||||
struct commit_info *prev)
|
||||
{
|
||||
@ -524,7 +524,7 @@ static void PRINTF_FMT(2,3) record_send(struct peer *peer, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void PRINTF_FMT(2,3) record_recv(struct peer *peer, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -593,7 +593,7 @@ static void send_remove(struct peer *peer, unsigned int htlc)
|
||||
if (!h)
|
||||
errx(1, "%s: send_remove: htlc %u does not exist",
|
||||
peer->name, htlc);
|
||||
|
||||
|
||||
htlc_changestate(peer, h, false, RECV_ADD_ACK_REVOCATION, SENT_REMOVE_HTLC);
|
||||
xmit_remove_htlc(peer, h);
|
||||
}
|
||||
@ -617,7 +617,7 @@ static struct commit_info *last_unrevoked(struct commit_info *ci)
|
||||
/* If this is already revoked, all are. */
|
||||
if (ci->revoked)
|
||||
return NULL;
|
||||
|
||||
|
||||
/* Find revoked commit; one we hit before that was last unrevoked. */
|
||||
for (; ci; next = ci, ci = ci->prev) {
|
||||
if (ci->revoked)
|
||||
@ -945,7 +945,7 @@ static void do_cmd(struct peer *peer)
|
||||
}
|
||||
|
||||
peer->info = tal_strdup(peer, "");
|
||||
|
||||
|
||||
if (sscanf(cmd, "offer %u", &htlc) == 1)
|
||||
send_offer(peer, htlc);
|
||||
else if (sscanf(cmd, "remove %u", &htlc) == 1)
|
||||
@ -1034,11 +1034,11 @@ static void new_peer(const char *name,
|
||||
peer->htlcs = tal_arr(peer, struct htlc *, 0);
|
||||
|
||||
memset(&peer->db, 0, sizeof(peer->db));
|
||||
|
||||
|
||||
/* Create first, signed commit info. */
|
||||
peer->local = new_commit_info(peer, NULL);
|
||||
peer->local->counterparty_signed = true;
|
||||
|
||||
|
||||
peer->remote = new_commit_info(peer, NULL);
|
||||
peer->remote->counterparty_signed = true;
|
||||
|
||||
@ -1236,13 +1236,13 @@ static void read_from_client(const char *desc, int fd, void *dst, size_t len)
|
||||
}
|
||||
alarm(0);
|
||||
}
|
||||
|
||||
|
||||
static void write_to_client(const char *desc, int fd, const void *dst, size_t len)
|
||||
{
|
||||
if (!write_all(fd, dst, len))
|
||||
err(1, "Writing to %s", desc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void stop_clients(int acmd[2],
|
||||
int bcmd[2],
|
||||
@ -1287,7 +1287,7 @@ int main(int argc, char *argv[])
|
||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||
if (argc != 1)
|
||||
errx(1, "no arguments accepted");
|
||||
|
||||
|
||||
if (do_svg)
|
||||
svg = tal_strdup(NULL, "");
|
||||
else
|
||||
@ -1307,7 +1307,7 @@ int main(int argc, char *argv[])
|
||||
#else
|
||||
signal(SIGALRM, do_nothing);
|
||||
#endif
|
||||
|
||||
|
||||
start_clients(a_to_b, b_to_a, acmd, bcmd, adonefd, bdonefd);
|
||||
|
||||
while (fgets(cmd, sizeof(cmd), stdin)) {
|
||||
@ -1323,7 +1323,7 @@ int main(int argc, char *argv[])
|
||||
if (strstarts(cmd, "A:")) {
|
||||
cmdfd = acmd[1];
|
||||
donefd = adonefd[0];
|
||||
} else if (strstarts(cmd, "B:")) {
|
||||
} else if (strstarts(cmd, "B:")) {
|
||||
cmdfd = bcmd[1];
|
||||
donefd = bdonefd[0];
|
||||
} else if (strstarts(cmd, "echo ")) {
|
||||
|
@ -149,9 +149,9 @@ struct peer {
|
||||
/* Current input and idata (for fail()) */
|
||||
enum state_input current_input;
|
||||
const union input *current_idata;
|
||||
|
||||
|
||||
const char *error;
|
||||
|
||||
|
||||
/* ID. */
|
||||
const char *name;
|
||||
/* The other peer's data. */
|
||||
@ -325,7 +325,7 @@ static void update_core(struct core_state *core, const struct peer *peer)
|
||||
|
||||
for (i = core->num_outputs; i < ARRAY_SIZE(core->outputs); i++)
|
||||
assert(core->outputs[i] == 0);
|
||||
|
||||
|
||||
core->has_current_htlc = peer->current_htlc.htlc.id != -1;
|
||||
core->state = peer->state;
|
||||
BUILD_ASSERT(STATE_MAX < 256);
|
||||
@ -397,7 +397,7 @@ static const struct trail *clone_trail(const tal_t *ctx,
|
||||
|
||||
if (!trail)
|
||||
return NULL;
|
||||
|
||||
|
||||
t = tal_dup(ctx, struct trail, trail);
|
||||
t->before = tal_dup(t, struct peer, trail->before);
|
||||
t->after = trail->after ? tal_dup(t, struct peer, trail->after)
|
||||
@ -708,7 +708,7 @@ Pkt *accept_pkt_open_commit_sig(const tal_t *ctx,
|
||||
return pkt_err(ctx, "Error inject");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Pkt *accept_pkt_open_complete(const tal_t *ctx,
|
||||
struct peer *peer,
|
||||
const Pkt *pkt)
|
||||
@ -747,7 +747,7 @@ Pkt *accept_pkt_htlc_fail(const tal_t *ctx,
|
||||
|
||||
/* The shouldn't fail unless it's to them */
|
||||
assert(h->to_them);
|
||||
|
||||
|
||||
/* This is the current htlc */
|
||||
set_current_htlc(peer, h->id, h->to_them, false);
|
||||
return NULL;
|
||||
@ -980,7 +980,7 @@ static void init_trail(struct trail *t,
|
||||
|| input == BITCOIN_HTLC_TOTHEM_SPENT
|
||||
|| input == BITCOIN_HTLC_TOUS_TIMEOUT
|
||||
|| input == BITCOIN_HTLC_FULFILL_SPEND_DONE
|
||||
|| input == BITCOIN_HTLC_RETURN_SPEND_DONE)
|
||||
|| input == BITCOIN_HTLC_RETURN_SPEND_DONE)
|
||||
t->htlc_id = idata->htlc->id;
|
||||
else if (input == PKT_UPDATE_ADD_HTLC)
|
||||
t->htlc_id = htlc_id_from_pkt(idata->pkt);
|
||||
@ -1123,7 +1123,7 @@ static void remove_htlc_id(struct peer *peer, unsigned int id)
|
||||
peer->htlcs_to_them, &peer->num_htlcs_to_them,
|
||||
ARRAY_SIZE(peer->htlcs_to_us), h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static bool outstanding_htlc_watches(const struct peer *peer)
|
||||
{
|
||||
@ -1143,7 +1143,7 @@ static bool add_event_(struct peer *peer, enum state_input input)
|
||||
/* This is how they say "no event please" */
|
||||
if (input == INPUT_NONE)
|
||||
return true;
|
||||
|
||||
|
||||
assert(input < 64);
|
||||
if (have_event(peer->core.event_notifies, input))
|
||||
return false;
|
||||
@ -1156,7 +1156,7 @@ static bool remove_event_(uint64_t *events, enum state_input input)
|
||||
/* This is how they say "no event please" */
|
||||
if (input == INPUT_NONE)
|
||||
return true;
|
||||
|
||||
|
||||
assert(input < 64);
|
||||
if (!have_event(*events, input))
|
||||
return false;
|
||||
@ -1201,7 +1201,7 @@ void bitcoin_create_anchor(struct peer *peer, enum state_input done)
|
||||
assert(done == BITCOIN_ANCHOR_CREATED);
|
||||
if (peer->anchor)
|
||||
report_trail(peer->trail, "Anchor already created?");
|
||||
|
||||
|
||||
peer->anchor = true;
|
||||
add_event(peer, done);
|
||||
}
|
||||
@ -1263,7 +1263,7 @@ void peer_watch_close(struct peer *peer,
|
||||
enum state_input done, enum state_input timedout)
|
||||
{
|
||||
add_event(peer, done);
|
||||
|
||||
|
||||
/* We assume this. */
|
||||
assert(timedout == INPUT_CLOSE_COMPLETE_TIMEOUT || timedout == INPUT_NONE);
|
||||
add_event(peer, timedout);
|
||||
@ -1383,7 +1383,7 @@ void peer_unwatch_htlc_output(struct peer *peer,
|
||||
if (!outstanding_htlc_watches(peer))
|
||||
add_event(peer, all_done);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void peer_unwatch_all_htlc_outputs(struct peer *peer)
|
||||
{
|
||||
@ -1498,14 +1498,14 @@ void peer_htlc_declined(struct peer *peer, const Pkt *pkt)
|
||||
clear_current_htlc(peer);
|
||||
peer->htlc_declined = true;
|
||||
}
|
||||
|
||||
|
||||
const struct htlc *peer_tx_revealed_r_value(struct peer *peer,
|
||||
const struct bitcoin_event *btc)
|
||||
{
|
||||
const struct htlc *htlc = (struct htlc *)btc;
|
||||
add_rval(peer, htlc->id);
|
||||
return htlc;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *check_changes(const struct peer *old, struct peer *new,
|
||||
enum state_input input)
|
||||
@ -1652,7 +1652,7 @@ static void record_output(enum state_input **outputs, enum state_input out)
|
||||
tal_resize(outputs, n+1);
|
||||
(*outputs)[n] = out;
|
||||
}
|
||||
|
||||
|
||||
static void record_state(struct state_dump **sd,
|
||||
enum state_input input,
|
||||
enum state newstate,
|
||||
@ -1681,7 +1681,7 @@ static void record_state(struct state_dump **sd,
|
||||
(*sd)[n].next = newstate;
|
||||
(*sd)[n].pkt = pkt;
|
||||
}
|
||||
|
||||
|
||||
static bool error_path(enum state_input i, enum state src, enum state dst)
|
||||
{
|
||||
return state_is_error(dst) || i == PKT_ERROR;
|
||||
@ -1832,7 +1832,7 @@ static void try_input(const struct peer *peer,
|
||||
|| i == BITCOIN_ANCHOR_OTHERSPEND
|
||||
|| i == BITCOIN_CLOSE_DONE)
|
||||
copy.anchor_spent = true;
|
||||
|
||||
|
||||
eliminate_input(&hist->inputs_per_state[copy.state], i);
|
||||
cstatus = state(ctx, ©, i, idata, &output, &broadcast);
|
||||
|
||||
@ -1880,7 +1880,7 @@ static void try_input(const struct peer *peer,
|
||||
record_state(&hist->state_dump[peer->state], i, copy.state,
|
||||
(const char *)output);
|
||||
}
|
||||
|
||||
|
||||
/* Have we been in this overall situation before? */
|
||||
if (!sithash_update(&hist->sithash, ©)) {
|
||||
/*
|
||||
@ -2038,7 +2038,7 @@ static void run_peer(const struct peer *peer,
|
||||
|
||||
/* We want to frob some things... */
|
||||
copy_peers(©, &other, peer);
|
||||
|
||||
|
||||
/* If in init state, we can only send start command. */
|
||||
if (peer->state == STATE_INIT) {
|
||||
if (streq(peer->name, "A"))
|
||||
@ -2050,7 +2050,7 @@ static void run_peer(const struct peer *peer,
|
||||
prev_trail, hist);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Try the event notifiers */
|
||||
old_notifies = copy.core.event_notifies;
|
||||
for (i = 0; i < 64; i++) {
|
||||
@ -2175,7 +2175,7 @@ static void run_peer(const struct peer *peer,
|
||||
/* Allowed to send packets? */
|
||||
if (copy.cond != PEER_CLOSED) {
|
||||
enum state_input i;
|
||||
|
||||
|
||||
if (other.core.num_outputs) {
|
||||
i = other.core.outputs[0];
|
||||
if (i == PKT_ERROR)
|
||||
@ -2215,7 +2215,7 @@ static bool record_input_mapping(int b)
|
||||
mapping_inputs[n] = b;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static enum state_input **map_inputs(void)
|
||||
{
|
||||
enum state_input **inps = tal_arr(NULL, enum state_input *, STATE_MAX);
|
||||
@ -2378,7 +2378,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
} while (!more_failpoints);
|
||||
|
||||
|
||||
for (i = 0; i < STATE_MAX; i++) {
|
||||
bool a_expect = true, b_expect = true;
|
||||
|
||||
@ -2468,6 +2468,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user