mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 07:34:21 +01:00
daemon: rename 'state' to 'dstate' everywhere.
This is the daemon state, not the state machine state. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -55,7 +55,7 @@ bool txowatch_eq(const struct txowatch *w, const struct txwatch_output *out)
|
||||
|
||||
static void destroy_txowatch(struct txowatch *w)
|
||||
{
|
||||
txowatch_hash_del(&w->peer->state->txowatches, w);
|
||||
txowatch_hash_del(&w->peer->dstate->txowatches, w);
|
||||
}
|
||||
|
||||
/* Watch a txo. */
|
||||
@@ -75,7 +75,7 @@ static void insert_txo_watch(struct peer *peer,
|
||||
w->cb = cb;
|
||||
w->cbdata = cbdata;
|
||||
|
||||
txowatch_hash_add(&w->peer->state->txowatches, w);
|
||||
txowatch_hash_add(&w->peer->dstate->txowatches, w);
|
||||
tal_add_destructor(w, destroy_txowatch);
|
||||
}
|
||||
|
||||
@@ -96,11 +96,11 @@ bool txwatch_eq(const struct txwatch *w, const struct sha256_double *txid)
|
||||
|
||||
static void destroy_txwatch(struct txwatch *w)
|
||||
{
|
||||
txwatch_hash_del(&w->state->txwatches, w);
|
||||
txwatch_hash_del(&w->dstate->txwatches, w);
|
||||
}
|
||||
|
||||
static struct txwatch *insert_txwatch(const tal_t *ctx,
|
||||
struct lightningd_state *state,
|
||||
struct lightningd_state *dstate,
|
||||
struct peer *peer,
|
||||
const struct sha256_double *txid,
|
||||
void (*cb)(struct peer *, int, void *),
|
||||
@@ -109,7 +109,7 @@ static struct txwatch *insert_txwatch(const tal_t *ctx,
|
||||
struct txwatch *w;
|
||||
|
||||
/* We could have a null-watch on it because we saw it spend a TXO */
|
||||
w = txwatch_hash_get(&state->txwatches, txid);
|
||||
w = txwatch_hash_get(&dstate->txwatches, txid);
|
||||
if (w) {
|
||||
assert(!w->cb);
|
||||
tal_free(w);
|
||||
@@ -118,12 +118,12 @@ static struct txwatch *insert_txwatch(const tal_t *ctx,
|
||||
w = tal(ctx, struct txwatch);
|
||||
w->depth = 0;
|
||||
w->txid = *txid;
|
||||
w->state = state;
|
||||
w->dstate = dstate;
|
||||
w->peer = peer;
|
||||
w->cb = cb;
|
||||
w->cbdata = cbdata;
|
||||
|
||||
txwatch_hash_add(&w->state->txwatches, w);
|
||||
txwatch_hash_add(&w->dstate->txwatches, w);
|
||||
tal_add_destructor(w, destroy_txwatch);
|
||||
|
||||
return w;
|
||||
@@ -141,7 +141,7 @@ void add_anchor_watch_(struct peer *peer,
|
||||
struct ripemd160 redeemhash;
|
||||
u8 *redeemscript;
|
||||
|
||||
insert_txwatch(peer, peer->state, peer, txid, anchor_cb, cbdata);
|
||||
insert_txwatch(peer, peer->dstate, peer, txid, anchor_cb, cbdata);
|
||||
insert_txo_watch(peer, txid, out, spend_cb, cbdata);
|
||||
|
||||
redeemscript = bitcoin_redeem_2of2(peer, &peer->them.commitkey,
|
||||
@@ -153,7 +153,7 @@ void add_anchor_watch_(struct peer *peer,
|
||||
/* Telling bitcoind to watch the redeemhash address means
|
||||
* it'll tell is about the anchor itself (spend to that
|
||||
* address), and any commit txs (spend from that address).*/
|
||||
bitcoind_watch_addr(peer->state, &redeemhash);
|
||||
bitcoind_watch_addr(peer->dstate, &redeemhash);
|
||||
}
|
||||
|
||||
void add_commit_tx_watch_(struct peer *peer,
|
||||
@@ -161,13 +161,13 @@ void add_commit_tx_watch_(struct peer *peer,
|
||||
void (*cb)(struct peer *peer, int depth, void *),
|
||||
void *cbdata)
|
||||
{
|
||||
insert_txwatch(peer, peer->state, peer, txid, cb, cbdata);
|
||||
insert_txwatch(peer, peer->dstate, peer, txid, cb, cbdata);
|
||||
|
||||
/* We are already watching the anchor txo, so we don't need to
|
||||
* watch anything else. */
|
||||
}
|
||||
|
||||
static void tx_watched_inputs(struct lightningd_state *state,
|
||||
static void tx_watched_inputs(struct lightningd_state *dstate,
|
||||
const struct bitcoin_tx *tx, void *unused)
|
||||
{
|
||||
size_t in;
|
||||
@@ -179,20 +179,20 @@ static void tx_watched_inputs(struct lightningd_state *state,
|
||||
out.txid = tx->input[in].txid;
|
||||
out.index = tx->input[in].index;
|
||||
|
||||
txow = txowatch_hash_get(&state->txowatches, &out);
|
||||
txow = txowatch_hash_get(&dstate->txowatches, &out);
|
||||
if (txow)
|
||||
txow->cb(txow->peer, tx, txow->cbdata);
|
||||
}
|
||||
}
|
||||
|
||||
static void watched_transaction(struct lightningd_state *state,
|
||||
static void watched_transaction(struct lightningd_state *dstate,
|
||||
const struct sha256_double *txid,
|
||||
int confirmations)
|
||||
{
|
||||
struct txwatch *txw;
|
||||
|
||||
/* Are we watching this txid directly (or already reported)? */
|
||||
txw = txwatch_hash_get(&state->txwatches, txid);
|
||||
txw = txwatch_hash_get(&dstate->txwatches, txid);
|
||||
if (txw) {
|
||||
if (confirmations != txw->depth) {
|
||||
txw->depth = confirmations;
|
||||
@@ -203,28 +203,28 @@ static void watched_transaction(struct lightningd_state *state,
|
||||
}
|
||||
|
||||
/* Don't report about this txid twice. */
|
||||
insert_txwatch(state, state, NULL, txid, NULL, NULL);
|
||||
insert_txwatch(dstate, dstate, NULL, txid, NULL, NULL);
|
||||
|
||||
/* Maybe it spent an output we're watching? */
|
||||
bitcoind_txid_lookup(state, txid, tx_watched_inputs, NULL);
|
||||
bitcoind_txid_lookup(dstate, txid, tx_watched_inputs, NULL);
|
||||
}
|
||||
|
||||
static struct timeout watch_timeout;
|
||||
|
||||
static void start_poll_transactions(struct lightningd_state *state)
|
||||
static void start_poll_transactions(struct lightningd_state *dstate)
|
||||
{
|
||||
if (state->bitcoind_in_progress != 0) {
|
||||
log_unusual(state->base_log,
|
||||
if (dstate->bitcoind_in_progress != 0) {
|
||||
log_unusual(dstate->base_log,
|
||||
"Delaying start poll: %u commands in progress",
|
||||
state->bitcoind_in_progress);
|
||||
dstate->bitcoind_in_progress);
|
||||
} else
|
||||
bitcoind_poll_transactions(state, watched_transaction);
|
||||
refresh_timeout(state, &watch_timeout);
|
||||
bitcoind_poll_transactions(dstate, watched_transaction);
|
||||
refresh_timeout(dstate, &watch_timeout);
|
||||
}
|
||||
|
||||
void setup_watch_timer(struct lightningd_state *state)
|
||||
void setup_watch_timer(struct lightningd_state *dstate)
|
||||
{
|
||||
init_timeout(&watch_timeout, 30, start_poll_transactions, state);
|
||||
init_timeout(&watch_timeout, 30, start_poll_transactions, dstate);
|
||||
/* Run once immediately, in case there are issues. */
|
||||
start_poll_transactions(state);
|
||||
start_poll_transactions(dstate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user