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