Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecations for v0.9.4 #4362

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 1 addition & 63 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ void bitcoind_estimate_fees_(struct bitcoind *bitcoind,

struct sendrawtx_call {
struct bitcoind *bitcoind;
const char *hextx;
void (*cb)(struct bitcoind *bitcoind,
bool success,
const char *err_msg,
Expand Down Expand Up @@ -292,59 +291,6 @@ static void sendrawtx_callback(const char *buf, const jsmntok_t *toks,
tal_free(call);
}

/* For compatibility with `sendrawtransaction` plugins written for
* 0.9.0 or earlier.
* Once this deprecated API is removed, we can just delete this function
* and use sendrawtx_callback directly in bitcoind_sendrawtx_ahf_.
*/
static void sendrawtx_compatv090_callback(const char *buf,
const jsmntok_t *toks,
const jsmntok_t *idtok,
struct sendrawtx_call *call)
{
struct jsonrpc_request *req;

static bool warned = false;


/* If deprecated APIs not enabled, fail it outright. */
if (!deprecated_apis)
goto fallback;

/* If we got a JSONRPC2_INVALID_PARAMS error, assume it is
* because it is an old plugin which does not support the
* new `allowhighfees` parameter.
*/
if (json_scan(tmpctx, buf, toks, "{error:{code:"
stringify(JSONRPC2_INVALID_PARAMS)"}}") != NULL) {
goto fallback;
}

/* Possibly it is because `allowhighfees` is not understood
* by the plugin. */
if (!warned) {
warned = true;
log_unusual(call->bitcoind->log,
"`sendrawtransaction` failed when given two "
"arguments, will retry with single-argument "
"deprecated API.");
}

/* Retry with a single argument, hextx. */
req = jsonrpc_request_start(call->bitcoind, "sendrawtransaction",
call->bitcoind->log,
NULL, sendrawtx_callback, call);
json_add_string(req->stream, "tx", call->hextx);
jsonrpc_request_end(req);
bitcoin_plugin_send(call->bitcoind, req);

return;

fallback:
sendrawtx_callback(buf, toks, idtok, call);
return;
}

void bitcoind_sendrawtx_ahf_(struct bitcoind *bitcoind,
const char *hextx,
bool allowhighfees,
Expand All @@ -356,21 +302,13 @@ void bitcoind_sendrawtx_ahf_(struct bitcoind *bitcoind,
struct sendrawtx_call *call = tal(bitcoind, struct sendrawtx_call);

call->bitcoind = bitcoind;
/* For compatibility with 0.9.0 or earlier.
* Once removed, we can remove the hextx field in
* struct sendrawtx_call as well.
*/
if (deprecated_apis)
call->hextx = tal_strdup(call, hextx);
else
call->hextx = NULL;
call->cb = cb;
call->cb_arg = cb_arg;
log_debug(bitcoind->log, "sendrawtransaction: %s", hextx);

req = jsonrpc_request_start(bitcoind, "sendrawtransaction",
bitcoind->log,
NULL, sendrawtx_compatv090_callback,
NULL, sendrawtx_callback,
call);
json_add_string(req->stream, "tx", hextx);
json_add_bool(req->stream, "allowhighfees", allowhighfees);
Expand Down
3 changes: 0 additions & 3 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ void json_add_payment_fields(struct json_stream *response,
if (amount_msat_greater(t->msatoshi, AMOUNT_MSAT(0)))
json_add_amount_msat_compat(response, t->msatoshi, "msatoshi",
"amount_msat");
else if (deprecated_apis)
json_add_null(response, "amount_msat");


json_add_amount_msat_compat(response, t->msatoshi_sent,
"msatoshi_sent", "amount_sent_msat");
Expand Down
8 changes: 6 additions & 2 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1722,8 +1722,7 @@ static void add_amount_sent(struct plugin *p,

/* If this is an unannotated partial payment we drop out estimate for
* all parts. */
/* FIXME: with deprecated_apis, amount_msat can be 'null' */
if (msattok == NULL || !json_to_msat(buf, msattok, &recv)) {
if (msattok == NULL) {
mpp->amount = tal_free(mpp->amount);
return;
}
Expand All @@ -1734,6 +1733,11 @@ static void add_amount_sent(struct plugin *p,
if (mpp->amount == NULL)
return;

if (!json_to_msat(buf, msattok, &recv))
plugin_err(p, "Cannot convert amount_sat %.*s",
json_tok_full_len(msattok),
json_tok_full(buf, msattok));

if (!amount_msat_add(mpp->amount, *mpp->amount, recv))
plugin_log(p, LOG_BROKEN,
"Cannot add amount_msat for %s: %s + %s",
Expand Down