From 786732601c3e794685db261d6949ec6152bb7662 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 4 Dec 2021 21:56:06 +1030 Subject: [PATCH] common: remove unused functions or make static. Signed-off-by: Rusty Russell --- common/bolt12.c | 6 +-- common/bolt12.h | 15 -------- common/dijkstra.c | 6 --- common/dijkstra.h | 3 -- common/gossip_store.h | 6 --- common/htlc_wire.c | 8 ++-- common/htlc_wire.h | 4 -- common/json.c | 19 ++-------- common/json.h | 7 ---- common/json_helpers.c | 12 ------ common/json_helpers.h | 5 --- common/json_stream.c | 8 +++- common/json_stream.h | 9 ----- common/json_tok.c | 8 ++-- common/json_tok.h | 4 -- common/permute_tx.c | 87 ------------------------------------------- common/permute_tx.h | 7 ---- 17 files changed, 22 insertions(+), 192 deletions(-) diff --git a/common/bolt12.c b/common/bolt12.c index 6fa064bdc..a57a16627 100644 --- a/common/bolt12.c +++ b/common/bolt12.c @@ -415,17 +415,17 @@ struct tlv_invoice *invoice_decode(const tal_t *ctx, return invoice; } -bool bolt12_has_invoice_prefix(const char *str) +static bool bolt12_has_invoice_prefix(const char *str) { return strstarts(str, "lni1") || strstarts(str, "LNI1"); } -bool bolt12_has_request_prefix(const char *str) +static bool bolt12_has_request_prefix(const char *str) { return strstarts(str, "lnr1") || strstarts(str, "LNR1"); } -bool bolt12_has_offer_prefix(const char *str) +static bool bolt12_has_offer_prefix(const char *str) { return strstarts(str, "lno1") || strstarts(str, "LNO1"); } diff --git a/common/bolt12.h b/common/bolt12.h index e451c2897..4aa4ce761 100644 --- a/common/bolt12.h +++ b/common/bolt12.h @@ -115,21 +115,6 @@ void offer_period_paywindow(const struct tlv_offer_recurrence *recurrence, u64 *period_start, u64 *period_end); -/** - * Preliminary prefix check to see if the string might be a bolt12 invoice. - */ -bool bolt12_has_invoice_prefix(const char *str); - -/** - * Preliminary prefix check to see if the string might be a bolt12 request. - */ -bool bolt12_has_request_prefix(const char *str); - -/** - * Preliminary prefix check to see if the string might be a bolt12 offer. - */ -bool bolt12_has_offer_prefix(const char *str); - /** * Preliminary prefix check to see if the string might be a bolt12 string. */ diff --git a/common/dijkstra.c b/common/dijkstra.c index 5607a1c60..1920017a8 100644 --- a/common/dijkstra.c +++ b/common/dijkstra.c @@ -35,12 +35,6 @@ u32 dijkstra_distance(const struct dijkstra *dij, u32 node_idx) return dij[node_idx].distance; } -/* Total CLTV delay */ -u32 dijkstra_delay(const struct dijkstra *dij, u32 node_idx) -{ - return dij[node_idx].total_delay; -} - struct gossmap_chan *dijkstra_best_chan(const struct dijkstra *dij, u32 node_idx) { diff --git a/common/dijkstra.h b/common/dijkstra.h index 788182cd6..1a7d0a209 100644 --- a/common/dijkstra.h +++ b/common/dijkstra.h @@ -39,9 +39,6 @@ dijkstra_(const tal_t *ctx, /* Returns UINT_MAX if unreachable. */ u32 dijkstra_distance(const struct dijkstra *dij, u32 node_idx); -/* Total CLTV delay (0 if unreachable) */ -u32 dijkstra_delay(const struct dijkstra *dij, u32 node_idx); - /* Best path we found to here */ struct gossmap_chan *dijkstra_best_chan(const struct dijkstra *dij, u32 node_idx); diff --git a/common/gossip_store.h b/common/gossip_store.h index 5e7d13bce..b23e99f43 100644 --- a/common/gossip_store.h +++ b/common/gossip_store.h @@ -43,12 +43,6 @@ struct gossip_hdr { */ u8 *gossip_store_next(const tal_t *ctx, struct per_peer_state *pps); -/** - * Switches the gossip store fd, and gets to the correct offset. - */ -void gossip_store_switch_fd(struct per_peer_state *pps, - int newfd, u64 offset_shorter); - /** * Sets up the tiemstamp filter once they told us to set it.( */ diff --git a/common/htlc_wire.c b/common/htlc_wire.c index 3a175e832..d0a024fe4 100644 --- a/common/htlc_wire.c +++ b/common/htlc_wire.c @@ -5,8 +5,8 @@ #include #include -struct failed_htlc *failed_htlc_dup(const tal_t *ctx, - const struct failed_htlc *f TAKES) +static struct failed_htlc *failed_htlc_dup(const tal_t *ctx, + const struct failed_htlc *f TAKES) { struct failed_htlc *newf; @@ -129,7 +129,7 @@ void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed) } } -void towire_htlc_state(u8 **pptr, const enum htlc_state hstate) +static void towire_htlc_state(u8 **pptr, const enum htlc_state hstate) { towire_u8(pptr, hstate); } @@ -234,7 +234,7 @@ struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, si return failed; } -enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max) +static enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max) { enum htlc_state hstate = fromwire_u8(cursor, max); if (hstate >= HTLC_STATE_INVALID) { diff --git a/common/htlc_wire.h b/common/htlc_wire.h index 0779dbfec..80fe23217 100644 --- a/common/htlc_wire.h +++ b/common/htlc_wire.h @@ -74,14 +74,11 @@ struct existing_htlc *new_existing_htlc(const tal_t *ctx, const struct preimage *preimage TAKES, const struct failed_htlc *failed TAKES); -struct failed_htlc *failed_htlc_dup(const tal_t *ctx, const struct failed_htlc *f TAKES); - void towire_added_htlc(u8 **pptr, const struct added_htlc *added); void towire_existing_htlc(u8 **pptr, const struct existing_htlc *existing); void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled); void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed); void towire_changed_htlc(u8 **pptr, const struct changed_htlc *changed); -void towire_htlc_state(u8 **pptr, const enum htlc_state hstate); void towire_side(u8 **pptr, const enum side side); void towire_shachain(u8 **pptr, const struct shachain *shachain); @@ -95,7 +92,6 @@ struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max); void fromwire_changed_htlc(const u8 **cursor, size_t *max, struct changed_htlc *changed); -enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max); enum side fromwire_side(const u8 **cursor, size_t *max); void fromwire_shachain(const u8 **cursor, size_t *max, struct shachain *shachain); diff --git a/common/json.c b/common/json.c index d48edcb24..1955b4f83 100644 --- a/common/json.c +++ b/common/json.c @@ -300,8 +300,9 @@ const jsmntok_t *json_next(const jsmntok_t *tok) return t; } -const jsmntok_t *json_get_membern(const char *buffer, const jsmntok_t tok[], - const char *label, size_t len) +static const jsmntok_t *json_get_membern(const char *buffer, + const jsmntok_t tok[], + const char *label, size_t len) { const jsmntok_t *t; size_t i; @@ -665,20 +666,6 @@ const char *jsmntype_to_string(jsmntype_t t) return "INVALID"; } -void json_tok_print(const char *buffer, const jsmntok_t *tok) -{ - const jsmntok_t *first = tok; - const jsmntok_t *last = json_next(tok); - printf("size: %d, count: %td\n", tok->size, last - first); - while (first != last) { - printf("%td. %.*s, %s\n", first - tok, - first->end - first->start, buffer + first->start, - jsmntype_to_string(first->type)); - first++; - } - printf("\n"); -} - jsmntok_t *json_tok_copy(const tal_t *ctx, const jsmntok_t *tok) { return tal_dup_arr(ctx, jsmntok_t, tok, json_next(tok) - tok, 0); diff --git a/common/json.h b/common/json.h index 922d5a94f..eb4fb0548 100644 --- a/common/json.h +++ b/common/json.h @@ -90,10 +90,6 @@ const jsmntok_t *json_next(const jsmntok_t *tok); const jsmntok_t *json_get_member(const char *buffer, const jsmntok_t tok[], const char *label); -/* Get top-level member, with explicit label length */ -const jsmntok_t *json_get_membern(const char *buffer, const jsmntok_t tok[], - const char *label, size_t len); - /* Get index'th array member. */ const jsmntok_t *json_get_arr(const jsmntok_t tok[], size_t index); @@ -134,9 +130,6 @@ jsmntok_t *json_parse_simple(const tal_t *ctx, const char *input, int len); /* Convert a jsmntype_t enum to a human readable string. */ const char *jsmntype_to_string(jsmntype_t t); -/* Print a json value for debugging purposes. */ -void json_tok_print(const char *buffer, const jsmntok_t *params); - /* Return a copy of a json value as an array. */ jsmntok_t *json_tok_copy(const tal_t *ctx, const jsmntok_t *tok); diff --git a/common/json_helpers.c b/common/json_helpers.c index 17ee69935..8d9cb3522 100644 --- a/common/json_helpers.c +++ b/common/json_helpers.c @@ -282,18 +282,6 @@ void json_add_short_channel_id(struct json_stream *response, short_channel_id_outnum(scid)); } -void json_add_short_channel_id_dir(struct json_stream *response, - const char *fieldname, - const struct short_channel_id_dir *scidd) -{ - json_add_member(response, fieldname, true, "%dx%dx%d/%d", - short_channel_id_blocknum(&scidd->scid), - short_channel_id_txnum(&scidd->scid), - short_channel_id_outnum(&scidd->scid), - scidd->dir - ); -} - void json_add_address(struct json_stream *response, const char *fieldname, const struct wireaddr *addr) { diff --git a/common/json_helpers.h b/common/json_helpers.h index 3e1064240..e37cb95e8 100644 --- a/common/json_helpers.h +++ b/common/json_helpers.h @@ -132,11 +132,6 @@ void json_add_short_channel_id(struct json_stream *response, const char *fieldname, const struct short_channel_id *id); -/* '"fieldname" : "1234:5:6/7"' */ -void json_add_short_channel_id_dir(struct json_stream *response, - const char *fieldname, - const struct short_channel_id_dir *id); - /* JSON serialize a network address for a node */ void json_add_address(struct json_stream *response, const char *fieldname, const struct wireaddr *addr); diff --git a/common/json_stream.c b/common/json_stream.c index 0025eb5b8..59a8a88bf 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -43,7 +43,13 @@ struct json_stream *json_stream_dup(const tal_t *ctx, return js; } -bool json_stream_still_writing(const struct json_stream *js) +/** + * json_stream_still_writing - is someone currently writing to this stream? + * @js: the json_stream. + * + * Has this json_stream not been closed yet? + */ +static bool json_stream_still_writing(const struct json_stream *js) { return js->writer != NULL; } diff --git a/common/json_stream.h b/common/json_stream.h index f47f4cf38..db595ca77 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -65,15 +65,6 @@ void json_stream_close(struct json_stream *js, struct command *writer); /* For low-level JSON stream access: */ void json_stream_log_suppress(struct json_stream *js, const char *cmd_name); -/** - * json_stream_still_writing - is someone currently writing to this stream? - * @js: the json_stream. - * - * Has this json_stream not been closed yet? - */ -bool json_stream_still_writing(const struct json_stream *js); - - /* '"fieldname" : [ ' or '[ ' if fieldname is NULL */ void json_array_start(struct json_stream *js, const char *fieldname); /* '"fieldname" : { ' or '{ ' if fieldname is NULL */ diff --git a/common/json_tok.c b/common/json_tok.c index ad88451eb..4be957dfe 100644 --- a/common/json_tok.c +++ b/common/json_tok.c @@ -581,9 +581,11 @@ struct command_result *param_extra_tlvs(struct command *cmd, const char *name, return NULL; } -struct command_result *param_routehint(struct command *cmd, const char *name, - const char *buffer, const jsmntok_t *tok, - struct route_info **ri) +static struct command_result *param_routehint(struct command *cmd, + const char *name, + const char *buffer, + const jsmntok_t *tok, + struct route_info **ri) { size_t i; const jsmntok_t *curr; diff --git a/common/json_tok.h b/common/json_tok.h index cbaa61dfa..e4c59d5ce 100644 --- a/common/json_tok.h +++ b/common/json_tok.h @@ -198,10 +198,6 @@ struct command_result *param_extra_tlvs(struct command *cmd, const char *name, const jsmntok_t *tok, struct tlv_field **fields); -struct command_result *param_routehint(struct command *cmd, const char *name, - const char *buffer, const jsmntok_t *tok, - struct route_info **ri); - struct command_result * param_routehint_array(struct command *cmd, const char *name, const char *buffer, const jsmntok_t *tok, struct route_info ***ris); diff --git a/common/permute_tx.c b/common/permute_tx.c index bf97206d5..75fdf6140 100644 --- a/common/permute_tx.c +++ b/common/permute_tx.c @@ -2,93 +2,6 @@ #include #include -static bool input_better(const struct wally_tx_input *a, - const struct wally_tx_input *b) -{ - int cmp; - - cmp = memcmp(a->txhash, b->txhash, sizeof(a->txhash)); - if (cmp != 0) - return cmp < 0; - if (a->index != b->index) - return a->index < b->index; - - /* These shouldn't happen, but let's get a canonical order anyway. */ - if (a->script_len != b->script_len) - return a->script_len < b->script_len; - - cmp = memcmp(a->script, b->script, a->script_len); - if (cmp != 0) - return cmp < 0; - return a->sequence < b->sequence; -} - -static size_t find_best_in(struct wally_tx_input *inputs, size_t num) -{ - size_t i, best = 0; - - for (i = 1; i < num; i++) { - if (input_better(&inputs[i], &inputs[best])) - best = i; - } - return best; -} - -static void swap_wally_inputs(struct wally_tx_input *inputs, - struct wally_tx_input *psbt_global_ins, - struct wally_psbt_input *psbt_ins, - const void **map, - size_t i1, size_t i2) -{ - struct wally_tx_input tmpinput; - struct wally_psbt_input tmppsbtin; - const void *tmp; - - if (i1 == i2) - return; - - tmpinput = inputs[i1]; - inputs[i1] = inputs[i2]; - inputs[i2] = tmpinput; - - /* For the PSBT, we swap the psbt inputs and - * the global tx's inputs */ - tmpinput = psbt_global_ins[i1]; - psbt_global_ins[i1] = psbt_global_ins[i2]; - psbt_global_ins[i2] = tmpinput; - - tmppsbtin = psbt_ins[i1]; - psbt_ins[i1] = psbt_ins[i2]; - psbt_ins[i2] = tmppsbtin; - - if (map) { - tmp = map[i1]; - map[i1] = map[i2]; - map[i2] = tmp; - } -} - -void permute_inputs(struct bitcoin_tx *tx, const void **map) -{ - size_t i, best_pos; - struct wally_tx_input *inputs = tx->wtx->inputs; - size_t num_inputs = tx->wtx->num_inputs; - - /* We can't permute nothing! */ - if (num_inputs == 0) - return; - - /* Now do a dumb sort (num_inputs is small). */ - for (i = 0; i < num_inputs-1; i++) { - best_pos = i + find_best_in(inputs + i, num_inputs - i); - /* Swap best into first place. */ - swap_wally_inputs(tx->wtx->inputs, - tx->psbt->tx->inputs, - tx->psbt->inputs, - map, i, best_pos); - } -} - static void swap_wally_outputs(struct wally_tx_output *outputs, struct wally_tx_output *psbt_global_outs, struct wally_psbt_output *psbt_outs, diff --git a/common/permute_tx.h b/common/permute_tx.h index 4107fd430..ac44c8e01 100644 --- a/common/permute_tx.h +++ b/common/permute_tx.h @@ -5,13 +5,6 @@ struct htlc; -/** - * permute_inputs: permute the transaction inputs into BIP69 order. - * @tx: the transaction whose inputs are to be sorted (inputs must be tal_arr). - * @map: if non-NULL, pointers to be permuted the same as the inputs. - */ -void permute_inputs(struct bitcoin_tx *tx, const void **map); - /** * permute_outputs: permute the transaction outputs into BIP69 + cltv order. * @tx: the transaction whose outputs are to be sorted (outputs must be tal_arr).