Skip to content

Commit

Permalink
bcli cleanups
Browse files Browse the repository at this point in the history
Correct some comments wrt estimatefees, add a constructor for bitcoind

Signed-off-by: Antoine Poinsot <[email protected]>
  • Loading branch information
darosior committed May 17, 2020
1 parent 6aa2fa2 commit 072c674
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions plugins/bcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static struct command_result *estimatefees_third_step(struct bitcoin_cli *bcli)
struct estimatefees_stash *stash = bcli->stash;
const char **params = tal_arr(bcli->cmd, const char *, 2);

/* If we cannot estimatefees, no need to continue bothering bitcoind. */
/* If we cannot estimate fees, no need to continue bothering bitcoind. */
if (*bcli->exitstatus != 0)
return estimatefees_null_response(bcli);

Expand All @@ -606,7 +606,7 @@ static struct command_result *estimatefees_second_step(struct bitcoin_cli *bcli)
struct estimatefees_stash *stash = bcli->stash;
const char **params = tal_arr(bcli->cmd, const char *, 2);

/* If we cannot estimatefees, no need to continue bothering bitcoind. */
/* If we cannot estimate fees, no need to continue bothering bitcoind. */
if (*bcli->exitstatus != 0)
return estimatefees_null_response(bcli);

Expand Down Expand Up @@ -753,13 +753,13 @@ static struct command_result *getchaininfo(struct command *cmd,
return command_still_pending(cmd);
}

/* Get the current feerates. We us an urgent feerate for unilateral_close and max,
/* Get the current feerates. We use an urgent feerate for unilateral_close and max,
* a slightly less urgent feerate for htlc_resolution and penalty transactions,
* a slow feerate for min, and a normal one for all others.
*
* Calls `estimatesmartfee` with targets 2/CONSERVATIVE (urgent),
* 4/ECONOMICAL (normal), and 100/ECONOMICAL (slow) then returns the
* feerates as sat/kVB.
* Calls `estimatesmartfee` with targets 2/CONSERVATIVE (very urgent),
* 3/CONSERVATIVE (urgent), 4/ECONOMICAL (normal), and 100/ECONOMICAL (slow)
* then returns the feerates as sat/kVB.
*/
static struct command_result *estimatefees(struct command *cmd,
const char *buf UNUSED,
Expand All @@ -771,7 +771,8 @@ static struct command_result *estimatefees(struct command *cmd,
if (!param(cmd, buf, toks, NULL))
return command_param_failed();

/* First call to estimatesmartfee, for urgent estimation. */
/* First call to estimatesmartfee, for very urgent estimation (unilateral
* and max_acceptable feerates). */
params[0] = "2";
params[1] = "CONSERVATIVE";
start_bitcoin_cli(NULL, cmd, estimatefees_second_step, true,
Expand Down Expand Up @@ -930,12 +931,9 @@ static const struct plugin_command commands[] = {
},
};

int main(int argc, char *argv[])
static struct bitcoind *new_bitcoind(const tal_t *ctx)
{
setup_locale();

/* Initialize our global context object here to handle startup options. */
bitcoind = tal(NULL, struct bitcoind);
bitcoind = tal(ctx, struct bitcoind);

bitcoind->cli = NULL;
bitcoind->datadir = NULL;
Expand All @@ -952,6 +950,16 @@ int main(int argc, char *argv[])
bitcoind->max_fee_multiplier = 10;
bitcoind->commit_fee_percent = 100;

return bitcoind;
}

int main(int argc, char *argv[])
{
setup_locale();

/* Initialize our global context object here to handle startup options. */
bitcoind = new_bitcoind(NULL);

plugin_main(argv, init, PLUGIN_STATIC, NULL, commands, ARRAY_SIZE(commands),
NULL, 0, NULL, 0,
plugin_option("bitcoin-datadir",
Expand Down

0 comments on commit 072c674

Please sign in to comment.