mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-18 22:54:25 +01:00
lightningd/chaintopology: change form of finished callback.
We don't actually use it anywhere, but we actually want to now for CPFP. So give it more parameters and make it return bool so it can be set without necessarily suppressing rexmit. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -179,7 +179,7 @@ static void rebroadcast_txs(struct chain_topology *topo)
|
||||
|
||||
/* Don't free from txmap inside loop! */
|
||||
if (otx->refresh
|
||||
&& !otx->refresh(otx->channel, &otx->tx, otx->refresh_arg)) {
|
||||
&& !otx->refresh(otx->channel, &otx->tx, otx->cbarg)) {
|
||||
tal_steal(cleanup_ctx, otx);
|
||||
continue;
|
||||
}
|
||||
@@ -229,33 +229,40 @@ static void broadcast_done(struct bitcoind *bitcoind,
|
||||
tal_del_destructor2(otx->channel, clear_otx_channel, otx);
|
||||
|
||||
if (otx->finished) {
|
||||
otx->finished(otx->channel, success, msg);
|
||||
tal_free(otx);
|
||||
} else if (we_broadcast(bitcoind->ld->topology, &otx->txid)) {
|
||||
if (otx->finished(otx->channel, otx->tx, success, msg, otx->cbarg)) {
|
||||
tal_free(otx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (we_broadcast(bitcoind->ld->topology, &otx->txid)) {
|
||||
log_debug(
|
||||
bitcoind->ld->topology->log,
|
||||
"Not adding %s to list of outgoing transactions, already "
|
||||
"present",
|
||||
type_to_string(tmpctx, struct bitcoin_txid, &otx->txid));
|
||||
tal_free(otx);
|
||||
} else {
|
||||
/* For continual rebroadcasting, until channel freed. */
|
||||
tal_steal(otx->channel, otx);
|
||||
outgoing_tx_map_add(bitcoind->ld->topology->outgoing_txs, otx);
|
||||
tal_add_destructor2(otx, destroy_outgoing_tx, bitcoind->ld->topology);
|
||||
return;
|
||||
}
|
||||
|
||||
/* For continual rebroadcasting, until channel freed. */
|
||||
tal_steal(otx->channel, otx);
|
||||
outgoing_tx_map_add(bitcoind->ld->topology->outgoing_txs, otx);
|
||||
tal_add_destructor2(otx, destroy_outgoing_tx, bitcoind->ld->topology);
|
||||
}
|
||||
|
||||
void broadcast_tx_(struct chain_topology *topo,
|
||||
struct channel *channel, const struct bitcoin_tx *tx,
|
||||
const char *cmd_id, bool allowhighfees, u32 minblock,
|
||||
void (*finished)(struct channel *channel,
|
||||
bool (*finished)(struct channel *channel,
|
||||
const struct bitcoin_tx *tx,
|
||||
bool success,
|
||||
const char *err),
|
||||
const char *err,
|
||||
void *cbarg),
|
||||
bool (*refresh)(struct channel *channel,
|
||||
const struct bitcoin_tx **tx,
|
||||
void *arg),
|
||||
void *refresh_arg)
|
||||
void *cbarg),
|
||||
void *cbarg)
|
||||
{
|
||||
/* Channel might vanish: topo owns it to start with. */
|
||||
struct outgoing_tx *otx = tal(topo, struct outgoing_tx);
|
||||
@@ -267,9 +274,9 @@ void broadcast_tx_(struct chain_topology *topo,
|
||||
otx->allowhighfees = allowhighfees;
|
||||
otx->finished = finished;
|
||||
otx->refresh = refresh;
|
||||
otx->refresh_arg = refresh_arg;
|
||||
if (taken(otx->refresh_arg))
|
||||
tal_steal(otx, otx->refresh_arg);
|
||||
otx->cbarg = cbarg;
|
||||
if (taken(otx->cbarg))
|
||||
tal_steal(otx, otx->cbarg);
|
||||
if (cmd_id)
|
||||
otx->cmd_id = tal_strdup(otx, cmd_id);
|
||||
else
|
||||
|
||||
@@ -24,9 +24,10 @@ struct outgoing_tx {
|
||||
u32 minblock;
|
||||
bool allowhighfees;
|
||||
const char *cmd_id;
|
||||
void (*finished)(struct channel *channel, bool success, const char *err);
|
||||
bool (*finished)(struct channel *channel, const struct bitcoin_tx *,
|
||||
bool success, const char *err, void *arg);
|
||||
bool (*refresh)(struct channel *, const struct bitcoin_tx **, void *arg);
|
||||
void *refresh_arg;
|
||||
void *cbarg;
|
||||
};
|
||||
|
||||
struct block {
|
||||
@@ -207,30 +208,37 @@ u32 default_locktime(const struct chain_topology *topo);
|
||||
* @cmd_id: the JSON command id which triggered this (or NULL).
|
||||
* @allowhighfees: set to true to override the high-fee checks in the backend.
|
||||
* @minblock: minimum block we can send it at (or 0).
|
||||
* @finished: if non-NULL, call that and don't rebroadcast.
|
||||
* @finished: if non-NULL, call that when sendrawtransaction returns; if it returns true, don't rebroadcast.
|
||||
* @refresh: if non-NULL, callback before re-broadcasting (can replace tx):
|
||||
* if returns false, delete.
|
||||
* @refresh_arg: argument for @refresh
|
||||
* @cbarg: argument for @finished and @refresh
|
||||
*/
|
||||
#define broadcast_tx(topo, channel, tx, cmd_id, allowhighfees, \
|
||||
minblock, finished, refresh, refresh_arg) \
|
||||
minblock, finished, refresh, cbarg) \
|
||||
broadcast_tx_((topo), (channel), (tx), (cmd_id), (allowhighfees), \
|
||||
(minblock), (finished), \
|
||||
(minblock), \
|
||||
typesafe_cb_preargs(bool, void *, \
|
||||
(refresh), (refresh_arg), \
|
||||
(finished), (cbarg), \
|
||||
struct channel *, \
|
||||
const struct bitcoin_tx *, \
|
||||
bool, const char *), \
|
||||
typesafe_cb_preargs(bool, void *, \
|
||||
(refresh), (cbarg), \
|
||||
struct channel *, \
|
||||
const struct bitcoin_tx **), \
|
||||
(refresh_arg))
|
||||
(cbarg))
|
||||
|
||||
void broadcast_tx_(struct chain_topology *topo,
|
||||
struct channel *channel,
|
||||
const struct bitcoin_tx *tx TAKES,
|
||||
const char *cmd_id, bool allowhighfees, u32 minblock,
|
||||
void (*finished)(struct channel *,
|
||||
bool (*finished)(struct channel *,
|
||||
const struct bitcoin_tx *,
|
||||
bool success,
|
||||
const char *err),
|
||||
const char *err,
|
||||
void *),
|
||||
bool (*refresh)(struct channel *, const struct bitcoin_tx **, void *),
|
||||
void *refresh_arg TAKES);
|
||||
void *cbarg TAKES);
|
||||
|
||||
struct chain_topology *new_topology(struct lightningd *ld, struct log *log);
|
||||
void setup_topology(struct chain_topology *topology,
|
||||
|
||||
@@ -55,11 +55,13 @@ void broadcast_tx_(struct chain_topology *topo UNNEEDED,
|
||||
struct channel *channel UNNEEDED,
|
||||
const struct bitcoin_tx *tx TAKES UNNEEDED,
|
||||
const char *cmd_id UNNEEDED, bool allowhighfees UNNEEDED, u32 minblock UNNEEDED,
|
||||
void (*finished)(struct channel * UNNEEDED,
|
||||
bool (*finished)(struct channel * UNNEEDED,
|
||||
const struct bitcoin_tx * UNNEEDED,
|
||||
bool success UNNEEDED,
|
||||
const char *err) UNNEEDED,
|
||||
const char *err UNNEEDED,
|
||||
void *) UNNEEDED,
|
||||
bool (*refresh)(struct channel * UNNEEDED, const struct bitcoin_tx ** UNNEEDED, void *) UNNEEDED,
|
||||
void *refresh_arg TAKES UNNEEDED)
|
||||
void *cbarg TAKES UNNEEDED)
|
||||
{ fprintf(stderr, "broadcast_tx_ called!\n"); abort(); }
|
||||
/* Generated stub for channel_change_state_reason_str */
|
||||
const char *channel_change_state_reason_str(enum state_change reason UNNEEDED)
|
||||
|
||||
@@ -73,11 +73,13 @@ void broadcast_tx_(struct chain_topology *topo UNNEEDED,
|
||||
struct channel *channel UNNEEDED,
|
||||
const struct bitcoin_tx *tx TAKES UNNEEDED,
|
||||
const char *cmd_id UNNEEDED, bool allowhighfees UNNEEDED, u32 minblock UNNEEDED,
|
||||
void (*finished)(struct channel * UNNEEDED,
|
||||
bool (*finished)(struct channel * UNNEEDED,
|
||||
const struct bitcoin_tx * UNNEEDED,
|
||||
bool success UNNEEDED,
|
||||
const char *err) UNNEEDED,
|
||||
const char *err UNNEEDED,
|
||||
void *) UNNEEDED,
|
||||
bool (*refresh)(struct channel * UNNEEDED, const struct bitcoin_tx ** UNNEEDED, void *) UNNEEDED,
|
||||
void *refresh_arg TAKES UNNEEDED)
|
||||
void *cbarg TAKES UNNEEDED)
|
||||
{ fprintf(stderr, "broadcast_tx_ called!\n"); abort(); }
|
||||
/* Generated stub for channel_tell_depth */
|
||||
bool channel_tell_depth(struct lightningd *ld UNNEEDED,
|
||||
|
||||
Reference in New Issue
Block a user