Browse Source

Remove tal_len, use tal_count() or tal_bytelen().

tal_count() is used where there's a type, even if it's char or u8, and
tal_bytelen() is going to replace tal_len() for clarity: it's only needed
where a pointer is void.

We shim tal_bytelen() for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
5cf34d6618
  1. 4
      bitcoin/pullpush.c
  2. 22
      bitcoin/script.c
  3. 2
      bitcoin/script.h
  4. 8
      bitcoin/signature.c
  5. 2
      bitcoin/test/run-tx-encode.c
  6. 4
      bitcoin/tx.c
  7. 4
      ccan_compat.h
  8. 10
      channeld/channel.c
  9. 2
      channeld/full_channel.c
  10. 6
      channeld/test/run-full_channel.c
  11. 2
      cli/test/run-large-input.c
  12. 4
      common/base32.c
  13. 2
      common/bech32_util.c
  14. 16
      common/bolt11.c
  15. 4
      common/crypto_sync.c
  16. 4
      common/decode_short_channel_ids.c
  17. 8
      common/features.c
  18. 4
      common/htlc_wire.c
  19. 2
      common/json.c
  20. 2
      common/memleak.c
  21. 2
      common/msg_queue.c
  22. 14
      common/permute_tx.c
  23. 4
      common/ping.c
  24. 22
      common/sphinx.c
  25. 10
      common/test/run-bolt11.c
  26. 10
      common/test/run-features.c
  27. 4
      common/test/run-sphinx.c
  28. 2
      common/utils.c
  29. 6
      common/wire_error.c
  30. 10
      common/wireaddr.c
  31. 6
      connectd/connect.c
  32. 6
      connectd/tor_autoservice.c
  33. 4
      devtools/bolt11-cli.c
  34. 18
      gossipd/gossip.c
  35. 2
      gossipd/gossip_store.c
  36. 32
      gossipd/routing.c
  37. 20
      hsmd/hsm.c
  38. 12
      lightningd/gossip_msg.c
  39. 4
      lightningd/invoice.c
  40. 2
      lightningd/log.c
  41. 2
      lightningd/log_status.c
  42. 2
      lightningd/options.c
  43. 8
      lightningd/peer_control.c
  44. 10
      lightningd/peer_htlcs.c
  45. 6
      lightningd/test/run-commit_tx.c
  46. 14
      onchaind/onchain.c
  47. 2
      onchaind/test/run-grind_feerate.c
  48. 4
      tools/generate-wire.py
  49. 6
      wallet/db.c
  50. 12
      wallet/test/run-wallet.c
  51. 2
      wallet/txfilter.c
  52. 6
      wallet/wallet.c
  53. 2
      wallet/walletrpc.c
  54. 2
      wire/test/run-peer-wire.c
  55. 2
      wire/towire.c
  56. 9
      wire/wire_io.c
  57. 4
      wire/wire_sync.c

4
bitcoin/pullpush.c

@ -30,8 +30,8 @@ void push_varint_blob(const tal_t *blob,
void (*push)(const void *, size_t, void *),
void *pushp)
{
push_varint(tal_len(blob), push, pushp);
push(blob, tal_len(blob), pushp);
push_varint(tal_bytelen(blob), push, pushp);
push(blob, tal_bytelen(blob), pushp);
}
void push(const void *data, size_t len, void *pptr_)

22
bitcoin/script.c

@ -369,7 +369,7 @@ u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key)
bool is_p2pkh(const u8 *script, struct bitcoin_address *addr)
{
size_t script_len = tal_len(script);
size_t script_len = tal_count(script);
if (script_len != BITCOIN_SCRIPTPUBKEY_P2PKH_LEN)
return false;
@ -390,7 +390,7 @@ bool is_p2pkh(const u8 *script, struct bitcoin_address *addr)
bool is_p2sh(const u8 *script, struct ripemd160 *addr)
{
size_t script_len = tal_len(script);
size_t script_len = tal_count(script);
if (script_len != BITCOIN_SCRIPTPUBKEY_P2SH_LEN)
return false;
@ -407,7 +407,7 @@ bool is_p2sh(const u8 *script, struct ripemd160 *addr)
bool is_p2wsh(const u8 *script, struct sha256 *addr)
{
size_t script_len = tal_len(script);
size_t script_len = tal_count(script);
if (script_len != BITCOIN_SCRIPTPUBKEY_P2WSH_LEN)
return false;
@ -422,7 +422,7 @@ bool is_p2wsh(const u8 *script, struct sha256 *addr)
bool is_p2wpkh(const u8 *script, struct bitcoin_address *addr)
{
size_t script_len = tal_len(script);
size_t script_len = tal_count(script);
if (script_len != BITCOIN_SCRIPTPUBKEY_P2WPKH_LEN)
return false;
@ -668,7 +668,7 @@ u8 **bitcoin_witness_htlc_timeout_tx(const tal_t *ctx,
witness[1] = stack_sig(witness, remotehtlcsig);
witness[2] = stack_sig(witness, localhtlcsig);
witness[3] = stack_number(witness, 0);
witness[4] = tal_dup_arr(witness, u8, wscript, tal_len(wscript), 0);
witness[4] = tal_dup_arr(witness, u8, wscript, tal_count(wscript), 0);
return witness;
}
@ -685,7 +685,7 @@ u8 **bitcoin_witness_htlc_success_tx(const tal_t *ctx,
witness[1] = stack_sig(witness, remotesig);
witness[2] = stack_sig(witness, localhtlcsig);
witness[3] = stack_preimage(witness, preimage);
witness[4] = tal_dup_arr(witness, u8, wscript, tal_len(wscript), 0);
witness[4] = tal_dup_arr(witness, u8, wscript, tal_count(wscript), 0);
return witness;
}
@ -724,12 +724,12 @@ u8 *bitcoin_wscript_htlc_tx(const tal_t *ctx,
return script;
}
bool scripteq(const tal_t *s1, const tal_t *s2)
bool scripteq(const u8 *s1, const u8 *s2)
{
memcheck(s1, tal_len(s1));
memcheck(s2, tal_len(s2));
memcheck(s1, tal_count(s1));
memcheck(s2, tal_count(s2));
if (tal_len(s1) != tal_len(s2))
if (tal_count(s1) != tal_count(s2))
return false;
return memcmp(s1, s2, tal_len(s1)) == 0;
return memcmp(s1, s2, tal_count(s1)) == 0;
}

2
bitcoin/script.h

@ -136,7 +136,7 @@ bool is_p2wsh(const u8 *script, struct sha256 *addr);
bool is_p2wpkh(const u8 *script, struct bitcoin_address *addr);
/* Are these two scripts equal? */
bool scripteq(const tal_t *s1, const tal_t *s2);
bool scripteq(const u8 *s1, const u8 *s2);
/* OP_DUP + OP_HASH160 + PUSH(20-byte-hash) + OP_EQUALVERIFY + OP_CHECKSIG */
#define BITCOIN_SCRIPTPUBKEY_P2PKH_LEN (1 + 1 + 1 + 20 + 1 + 1)

8
bitcoin/signature.c

@ -43,13 +43,13 @@ static void dump_tx(const char *msg,
warnx("output[%zu].amount = %llu",
i, (long long)tx->output[i].amount);
warnx("output[%zu].script = %zu",
i, tal_len(tx->output[i].script));
for (j = 0; j < tal_len(tx->output[i].script); j++)
i, tal_count(tx->output[i].script));
for (j = 0; j < tal_count(tx->output[i].script); j++)
fprintf(stderr, "%02x", tx->output[i].script[j]);
fprintf(stderr, "\n");
}
warnx("input[%zu].script = %zu", inputnum, tal_len(script));
for (i = 0; i < tal_len(script); i++)
warnx("input[%zu].script = %zu", inputnum, tal_count(script));
for (i = 0; i < tal_count(script); i++)
fprintf(stderr, "%02x", script[i]);
if (key) {
fprintf(stderr, "\nPubkey: ");

2
bitcoin/test/run-tx-encode.c

@ -48,7 +48,7 @@ int main(void)
/* This is a p2sh-p2wpkh: */
/* ScriptSig is push of "version 0 + hash of pubkey" */
hexeq(tx->input[0].script, tal_len(tx->input[0].script),
hexeq(tx->input[0].script, tal_count(tx->input[0].script),
"16" "00" "144aa38e396e1394fb45cbf83f48d1464fbc9f498f");
/* Witness with 2 items */

4
bitcoin/tx.c

@ -341,7 +341,7 @@ static void pull_input(const tal_t *ctx, const u8 **cursor, size_t *max,
input->script = tal_arr(ctx, u8, script_len);
else
input->script = NULL;
pull(cursor, max, input->script, tal_len(input->script));
pull(cursor, max, input->script, tal_count(input->script));
input->sequence_number = pull_le32(cursor, max);
}
@ -350,7 +350,7 @@ static void pull_output(const tal_t *ctx, const u8 **cursor, size_t *max,
{
output->amount = pull_value(cursor, max);
output->script = tal_arr(ctx, u8, pull_length(cursor, max, 1));
pull(cursor, max, output->script, tal_len(output->script));
pull(cursor, max, output->script, tal_count(output->script));
}
static u8 *pull_witness_item(const tal_t *ctx, const u8 **cursor, size_t *max)

4
ccan_compat.h

@ -16,4 +16,8 @@
#define sha256_be16(ctx, v) ccan_sha256_be16(ctx, v)
#define sha256_be32(ctx, v) ccan_sha256_be32(ctx, v)
#define sha256_be64(ctx, v) ccan_sha256_be64(ctx, v)
/* Transition for ccan update. */
#define tal_bytelen(x) tal_len(x)
#endif /* LIGHTNING_CCAN_COMPAT_H */

10
channeld/channel.c

@ -214,7 +214,7 @@ static void billboard_update(const struct peer *peer)
/* Returns a pointer to the new end */
static void *tal_arr_append_(void **p, size_t size)
{
size_t n = tal_len(*p) / size;
size_t n = tal_bytelen(*p) / size;
tal_resize_(p, size, n+1, false);
return (char *)(*p) + n * size;
}
@ -223,7 +223,7 @@ static void *tal_arr_append_(void **p, size_t size)
static void do_peer_write(struct peer *peer)
{
int r;
size_t len = tal_len(peer->peer_outmsg);
size_t len = tal_count(peer->peer_outmsg);
r = write(PEER_FD, peer->peer_outmsg + peer->peer_outoff,
len - peer->peer_outoff);
@ -388,7 +388,7 @@ static void send_announcement_signatures(struct peer *peer)
strerror(errno));
/* Double-check that HSM gave valid signatures. */
sha256_double(&hash, ca + offset, tal_len(ca) - offset);
sha256_double(&hash, ca + offset, tal_count(ca) - offset);
if (!check_signed_hash(&hash, &peer->announcement_node_sigs[LOCAL],
&peer->node_ids[LOCAL])) {
/* It's ok to fail here, the channel announcement is
@ -1735,7 +1735,7 @@ static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
if (h->failcode & BADONION) {
/* Malformed: use special reply since we can't onion. */
struct sha256 sha256_of_onion;
sha256(&sha256_of_onion, h->routing, tal_len(h->routing));
sha256(&sha256_of_onion, h->routing, tal_count(h->routing));
msg = towire_update_fail_malformed_htlc(NULL, &peer->channel_id,
h->id, &sha256_of_onion,
@ -2090,7 +2090,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
enum channel_add_err e;
enum onion_type failcode;
/* Subtle: must be tal_arr since we marshal using tal_len() */
/* Subtle: must be tal object since we marshal using tal_bytelen() */
const char *failmsg;
if (!peer->funding_locked[LOCAL] || !peer->funding_locked[REMOTE])

2
channeld/full_channel.c

@ -1049,7 +1049,7 @@ bool channel_force_htlcs(struct channel *channel,
if (failed[i]->failreason)
htlc->fail = tal_dup_arr(htlc, u8,
failed[i]->failreason,
tal_len(failed[i]->failreason),
tal_count(failed[i]->failreason),
0);
else
htlc->fail = NULL;

6
channeld/test/run-full_channel.c

@ -187,8 +187,8 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
lina = linearize_tx(tmpctx, a);
linb = linearize_tx(tmpctx, b);
for (i = 0; i < tal_len(lina); i++) {
if (i >= tal_len(linb))
for (i = 0; i < tal_count(lina); i++) {
if (i >= tal_count(linb))
errx(1, "Second tx is truncated:\n"
"%s\n"
"%s",
@ -202,7 +202,7 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
tal_hex(tmpctx, lina),
tal_hex(tmpctx, linb));
}
if (i != tal_len(linb))
if (i != tal_count(linb))
errx(1, "First tx is truncated:\n"
"%s\n"
"%s",

2
cli/test/run-large-input.c

@ -106,7 +106,7 @@ int main(int argc UNUSED, char *argv[])
response_off += sizeof(TAILER)-1;
response[response_off++] = '\0';
assert(strlen(response) == response_off - 1);
assert(response_off < tal_len(response));
assert(response_off < tal_count(response));
response_off = 0;
max_read_return = -1;

4
common/base32.c

@ -9,7 +9,7 @@ char *b32_encode(const tal_t *ctx, const void *data, size_t len)
char *str = tal_arr(ctx, char, base32_str_size(len));
base32_chars = base32_lower;
base32_encode(data, len, str, tal_len(str));
base32_encode(data, len, str, tal_count(str));
return str;
}
@ -18,7 +18,7 @@ u8 *b32_decode(const tal_t *ctx, const char *str, size_t len)
u8 *ret = tal_arr(ctx, u8, base32_data_size(str, len));
base32_chars = base32_lower;
if (!base32_decode(str, len, ret, tal_len(ret)))
if (!base32_decode(str, len, ret, tal_count(ret)))
return tal_free(ret);
return ret;
}

2
common/bech32_util.c

@ -9,7 +9,7 @@ static u8 get_bit(const u8 *src, size_t bitoff)
void bech32_push_bits(u5 **data, const void *src, size_t nbits)
{
size_t i, b;
size_t data_len = tal_len(*data);
size_t data_len = tal_count(*data);
for (i = 0; i < nbits; i += b) {
tal_resize(data, data_len+1);

16
common/bolt11.c

@ -351,7 +351,7 @@ static char *decode_f(struct bolt11 *b11,
} else if (version < 17) {
u8 *f = tal_arr(b11, u8, data_length * 5 / 8);
if (version == 0) {
if (tal_len(f) != 20 && tal_len(f) != 32)
if (tal_count(f) != 20 && tal_count(f) != 32)
return tal_fmt(b11,
"f: witness v0 bad length %zu",
data_length);
@ -359,7 +359,7 @@ static char *decode_f(struct bolt11 *b11,
pull_bits_certain(hu5, data, data_len, f, data_length * 5,
false);
fallback = scriptpubkey_witness_raw(b11, version,
f, tal_len(f));
f, tal_count(f));
tal_free(f);
} else
return unknown_field(b11, hu5, data, data_len, 'f',
@ -816,16 +816,16 @@ static void encode_f(u5 **data, const u8 *fallback)
push_fallback_addr(data, 0, &pkh, sizeof(pkh));
} else if (is_p2wsh(fallback, &wsh)) {
push_fallback_addr(data, 0, &wsh, sizeof(wsh));
} else if (tal_len(fallback)
} else if (tal_count(fallback)
&& fallback[0] >= 0x50
&& fallback[0] < (0x50+16)) {
/* Other (future) witness versions: turn OP_N into N */
push_fallback_addr(data, fallback[0] - 0x50, fallback + 1,
tal_len(fallback) - 1);
tal_count(fallback) - 1);
} else {
/* Copy raw. */
push_field(data, 'f',
fallback, tal_len(fallback) * CHAR_BIT);
fallback, tal_count(fallback) * CHAR_BIT);
}
}
@ -836,7 +836,7 @@ static void encode_r(u5 **data, const struct route_info *r)
for (size_t i = 0; i < tal_count(r); i++)
towire_route_info(&rinfo, r);
push_field(data, 'r', rinfo, tal_len(rinfo) * CHAR_BIT);
push_field(data, 'r', rinfo, tal_count(rinfo) * CHAR_BIT);
tal_free(rinfo);
}
@ -848,7 +848,7 @@ static void encode_extra(u5 **data, const struct bolt11_field *extra)
push_varlen_uint(data, tal_count(extra->data), 10);
/* extra->data is already u5s, so do this raw. */
len = tal_len(*data);
len = tal_count(*data);
tal_resize(data, len + tal_count(extra->data));
memcpy(*data + len, extra->data, tal_count(extra->data));
}
@ -938,7 +938,7 @@ char *bolt11_encode_(const tal_t *ctx,
encode_extra(&data, extra);
/* FIXME: towire_ should check this? */
if (tal_len(data) > 65535)
if (tal_count(data) > 65535)
return NULL;
/* Need exact length here */

4
common/crypto_sync.c

@ -38,7 +38,7 @@ bool sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES)
break;
}
#endif
ret = write_all(fd, enc, tal_len(enc));
ret = write_all(fd, enc, tal_count(enc));
tal_free(enc);
#if DEVELOPER
@ -64,7 +64,7 @@ u8 *sync_crypto_read(const tal_t *ctx, struct crypto_state *cs, int fd)
}
enc = tal_arr(ctx, u8, len + 16);
if (!read_all(fd, enc, tal_len(enc))) {
if (!read_all(fd, enc, tal_count(enc))) {
status_trace("Failed reading body: %s", strerror(errno));
return tal_free(enc);
}

4
common/decode_short_channel_ids.c

@ -24,7 +24,7 @@ static u8 *unzlib(const tal_t *ctx, const u8 *encoded, size_t len)
struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded)
{
struct short_channel_id *scids;
size_t max = tal_len(encoded), n;
size_t max = tal_count(encoded), n;
enum scid_encode_types type;
/* BOLT #7:
@ -43,7 +43,7 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded)
encoded = unzlib(tmpctx, encoded, max);
if (!encoded)
return NULL;
max = tal_len(encoded);
max = tal_count(encoded);
/* fall thru */
case SHORTIDS_UNCOMPRESSED:
n = 0;

8
common/features.c

@ -17,7 +17,7 @@ static const u32 global_features[] = {
*/
static void set_bit(u8 **ptr, u32 bit)
{
size_t len = tal_len(*ptr);
size_t len = tal_count(*ptr);
if (bit / 8 >= len) {
size_t newlen = (bit / 8) + 1;
u8 *newarr = tal_arrz(tal_parent(*ptr), u8, newlen);
@ -31,8 +31,8 @@ static void set_bit(u8 **ptr, u32 bit)
static bool test_bit(const u8 *features, size_t byte, unsigned int bit)
{
assert(byte < tal_len(features));
return features[tal_len(features) - 1 - byte] & (1 << (bit % 8));
assert(byte < tal_count(features));
return features[tal_count(features) - 1 - byte] & (1 << (bit % 8));
}
/* We don't insist on anything, it's all optional. */
@ -59,7 +59,7 @@ static bool feature_set(const u8 *features, size_t bit)
{
size_t bytenum = bit / 8;
if (bytenum >= tal_len(features))
if (bytenum >= tal_count(features))
return false;
return test_bit(features, bytenum, bit % 8);

4
common/htlc_wire.c

@ -26,8 +26,8 @@ void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled)
void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed)
{
/* Only one can be set. */
assert(failed->failcode || tal_len(failed->failreason));
assert(!failed->failcode || !tal_len(failed->failreason));
assert(failed->failcode || tal_count(failed->failreason));
assert(!failed->failcode || !tal_count(failed->failreason));
towire_u64(pptr, failed->id);
towire_u16(pptr, failed->failcode);
if (failed->failcode & UPDATE) {

2
common/json.c

@ -423,7 +423,7 @@ void json_add_hex_talarr(struct json_result *result,
const char *fieldname,
const tal_t *data)
{
json_add_hex(result, fieldname, data, tal_len(data));
json_add_hex(result, fieldname, data, tal_bytelen(data));
}
void json_add_object(struct json_result *result, ...)

2
common/memleak.c

@ -128,7 +128,7 @@ static void scan_for_pointers(struct htable *memtable, const tal_t *p)
size_t i, n;
/* Search for (aligned) pointers. */
n = tal_len(p) / sizeof(void *);
n = tal_bytelen(p) / sizeof(void *);
for (i = 0; i < n; i++) {
void *ptr;

2
common/msg_queue.c

@ -13,7 +13,7 @@ static void do_enqueue(struct msg_queue *q, const u8 *add)
{
size_t n = tal_count(q->q);
tal_resize(&q->q, n+1);
q->q[n] = tal_dup_arr(q->ctx, u8, add, tal_len(add), 0);
q->q[n] = tal_dup_arr(q->ctx, u8, add, tal_count(add), 0);
/* In case someone is waiting */
io_wake(q);

14
common/permute_tx.c

@ -14,9 +14,9 @@ static bool input_better(const struct bitcoin_tx_input *a,
return a->index < b->index;
/* These shouldn't happen, but let's get a canonical order anyway. */
if (tal_len(a->script) != tal_len(b->script))
return tal_len(a->script) < tal_len(b->script);
cmp = memcmp(a->script, b->script, tal_len(a->script));
if (tal_count(a->script) != tal_count(b->script))
return tal_count(a->script) < tal_count(b->script);
cmp = memcmp(a->script, b->script, tal_count(a->script));
if (cmp != 0)
return cmp < 0;
return a->sequence_number < b->sequence_number;
@ -102,16 +102,16 @@ static bool output_better(const struct bitcoin_tx_output *a,
return a->amount < b->amount;
/* Lexicographical sort. */
if (tal_len(a->script) < tal_len(b->script))
len = tal_len(a->script);
if (tal_count(a->script) < tal_count(b->script))
len = tal_count(a->script);
else
len = tal_len(b->script);
len = tal_count(b->script);
ret = memcmp(a->script, b->script, len);
if (ret != 0)
return ret < 0;
return tal_len(a->script) < tal_len(b->script);
return tal_count(a->script) < tal_count(b->script);
}
static size_t find_best_out(struct bitcoin_tx_output *outputs, size_t num)

4
common/ping.c

@ -78,12 +78,12 @@ const char *got_pong(const u8 *pong, size_t *num_pings_outstanding)
if (*num_pings_outstanding == 0)
return "Unexpected pong";
for (i = 0; i < tal_len(ignored); i++) {
for (i = 0; i < tal_count(ignored); i++) {
if (ignored[i] < ' ' || ignored[i] == 127)
break;
}
status_trace("Got pong %zu bytes (%.*s...)",
tal_len(ignored), i, (char *)ignored);
tal_count(ignored), i, (char *)ignored);
(*num_pings_outstanding)--;
return NULL;

22
common/sphinx.c

@ -319,7 +319,7 @@ static void serialize_hop_data(tal_t *ctx, u8 *dst, const struct hop_data *data)
towire_u32(&buf, data->outgoing_cltv);
towire_pad(&buf, 12);
towire(&buf, data->hmac, SECURITY_PARAMETER);
memcpy(dst, buf, tal_len(buf));
memcpy(dst, buf, tal_count(buf));
tal_free(buf);
}
@ -456,7 +456,7 @@ struct route_step *process_onionpacket(
u8 *create_onionreply(const tal_t *ctx, const struct secret *shared_secret,
const u8 *failure_msg)
{
size_t msglen = tal_len(failure_msg);
size_t msglen = tal_count(failure_msg);
size_t padlen = ONION_REPLY_SIZE - msglen;
u8 *reply = tal_arr(ctx, u8, 0), *payload = tal_arr(ctx, u8, 0);
u8 key[KEY_LEN];
@ -488,7 +488,7 @@ u8 *create_onionreply(const tal_t *ctx, const struct secret *shared_secret,
* - Note: this value is 118 bytes longer than the longest
* currently-defined message.
*/
assert(tal_len(payload) == ONION_REPLY_SIZE + 4);
assert(tal_count(payload) == ONION_REPLY_SIZE + 4);
/* BOLT #4:
*
@ -497,10 +497,10 @@ u8 *create_onionreply(const tal_t *ctx, const struct secret *shared_secret,
*/
generate_key(key, "um", 2, shared_secret->data);
compute_hmac(hmac, payload, tal_len(payload), key, KEY_LEN);
compute_hmac(hmac, payload, tal_count(payload), key, KEY_LEN);
towire(&reply, hmac, sizeof(hmac));
towire(&reply, payload, tal_len(payload));
towire(&reply, payload, tal_count(payload));
tal_free(payload);
return reply;
@ -510,7 +510,7 @@ u8 *wrap_onionreply(const tal_t *ctx,
const struct secret *shared_secret, const u8 *reply)
{
u8 key[KEY_LEN];
size_t streamlen = tal_len(reply);
size_t streamlen = tal_count(reply);
u8 stream[streamlen];
u8 *result = tal_arr(ctx, u8, streamlen);
@ -533,17 +533,17 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
const int numhops, const u8 *reply)
{
struct onionreply *oreply = tal(tmpctx, struct onionreply);
u8 *msg = tal_arr(oreply, u8, tal_len(reply));
u8 *msg = tal_arr(oreply, u8, tal_count(reply));
u8 key[KEY_LEN], hmac[HMAC_SIZE];
const u8 *cursor;
size_t max;
u16 msglen;
if (tal_len(reply) != ONION_REPLY_SIZE + sizeof(hmac) + 4) {
if (tal_count(reply) != ONION_REPLY_SIZE + sizeof(hmac) + 4) {
return NULL;
}
memcpy(msg, reply, tal_len(reply));
memcpy(msg, reply, tal_count(reply));
oreply->origin_index = -1;
for (int i = 0; i < numhops; i++) {
@ -555,7 +555,7 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
* the origin */
generate_key(key, "um", 2, shared_secrets[i].data);
compute_hmac(hmac, msg + sizeof(hmac),
tal_len(msg) - sizeof(hmac), key, KEY_LEN);
tal_count(msg) - sizeof(hmac), key, KEY_LEN);
if (memcmp(hmac, msg, sizeof(hmac)) == 0) {
oreply->origin_index = i;
break;
@ -566,7 +566,7 @@ struct onionreply *unwrap_onionreply(const tal_t *ctx,
}
cursor = msg + sizeof(hmac);
max = tal_len(msg) - sizeof(hmac);
max = tal_count(msg) - sizeof(hmac);
msglen = fromwire_u16(&cursor, &max);
if (msglen > ONION_REPLY_SIZE) {

10
common/test/run-bolt11.c

@ -48,11 +48,11 @@ static bool test_sign(const u5 *u5bytes,
char *hrp;
struct sha256 sha;
hrp = tal_dup_arr(NULL, char, (char *)hrpu8, tal_len(hrpu8), 1);
hrp[tal_len(hrpu8)] = '\0';
hrp = tal_dup_arr(NULL, char, (char *)hrpu8, tal_count(hrpu8), 1);
hrp[tal_count(hrpu8)] = '\0';
hash_u5_init(&hu5, hrp);
hash_u5(&hu5, u5bytes, tal_len(u5bytes));
hash_u5(&hu5, u5bytes, tal_count(u5bytes));
hash_u5_done(&hu5, &sha);
tal_free(hrp);
@ -94,9 +94,9 @@ static void test_b11(const char *b11str,
assert(tal_count(b11->fallbacks) == tal_count(expect_b11->fallbacks));
for (size_t i = 0; i < tal_count(b11->fallbacks); i++)
assert(memeq(b11->fallbacks[i], tal_len(b11->fallbacks[i]),
assert(memeq(b11->fallbacks[i], tal_count(b11->fallbacks[i]),
expect_b11->fallbacks[i],
tal_len(expect_b11->fallbacks[i])));
tal_count(expect_b11->fallbacks[i])));
/* FIXME: compare routes. */
assert(tal_count(b11->routes) == tal_count(expect_b11->routes));

10
common/test/run-features.c

@ -60,7 +60,7 @@ int main(void)
assert(!feature_offered(bits, 16));
/* We always support no features. */
memset(bits, 0, tal_len(bits));
memset(bits, 0, tal_count(bits));
assert(features_supported(bits, bits));
/* We must support our own features. */
@ -70,18 +70,18 @@ int main(void)
/* We can add random odd features, no problem. */
for (size_t i = 1; i < 16; i += 2) {
bits = tal_dup_arr(tmpctx, u8, lf, tal_len(lf), 0);
bits = tal_dup_arr(tmpctx, u8, lf, tal_count(lf), 0);
set_bit(&bits, i);
assert(features_supported(gf, bits));
bits = tal_dup_arr(tmpctx, u8, gf, tal_len(gf), 0);
bits = tal_dup_arr(tmpctx, u8, gf, tal_count(gf), 0);
set_bit(&bits, i);
assert(features_supported(bits, lf));
}
/* We can't add random even features. */
for (size_t i = 0; i < 16; i += 2) {
bits = tal_dup_arr(tmpctx, u8, lf, tal_len(lf), 0);
bits = tal_dup_arr(tmpctx, u8, lf, tal_count(lf), 0);
set_bit(&bits, i);
/* Special case for missing compulsory feature */
@ -93,7 +93,7 @@ int main(void)
ARRAY_SIZE(local_features)));
}
bits = tal_dup_arr(tmpctx, u8, gf, tal_len(gf), 0);
bits = tal_dup_arr(tmpctx, u8, gf, tal_count(gf), 0);
set_bit(&bits, i);
assert(features_supported(bits, lf)
== feature_supported(i, global_features,

4
common/test/run-sphinx.c

@ -148,12 +148,12 @@ static void run_unit_tests(void)
printf("input_packet %s\n", tal_hex(tmpctx, reply));
reply = wrap_onionreply(tmpctx, &ss[i], reply);
printf("obfuscated_packet %s\n", tal_hex(tmpctx, reply));
assert(memcmp(reply, intermediates[i], tal_len(reply)) == 0);
assert(memcmp(reply, intermediates[i], tal_count(reply)) == 0);
}
oreply = unwrap_onionreply(tmpctx, ss, 5, reply);
printf("unwrapped %s\n", tal_hex(tmpctx, oreply->msg));
assert(memcmp(raw, oreply->msg, tal_len(raw)) == 0);
assert(memcmp(raw, oreply->msg, tal_bytelen(raw)) == 0);
}
int main(int argc, char **argv)

2
common/utils.c

@ -16,7 +16,7 @@ char *tal_hexstr(const tal_t *ctx, const void *data, size_t len)
char *tal_hex(const tal_t *ctx, const tal_t *data)
{
return tal_hexstr(ctx, data, tal_len(data));
return tal_hexstr(ctx, data, tal_bytelen(data));
}
u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len)

6
common/wire_error.c

@ -70,11 +70,11 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
* through 126, inclusive):
* - SHOULD NOT print out `data` verbatim.
*/
for (i = 0; i < tal_len(data); i++) {
for (i = 0; i < tal_count(data); i++) {
if (data[i] < 32 || data[i] > 127) {
/* Convert to hex, minus NUL term */
data = (u8 *)tal_hex(ctx, data);
tal_resize(&data, tal_len(data)-1);
tal_resize(&data, strlen((const char *)data));
break;
}
}
@ -83,5 +83,5 @@ char *sanitize_error(const tal_t *ctx, const u8 *errmsg,
channel_id_is_all(channel_id)
? "ALL"
: type_to_string(ctx, struct channel_id, channel_id),
(int)tal_len(data), (char *)data);
(int)tal_count(data), (char *)data);
}

10
common/wireaddr.c

@ -307,9 +307,9 @@ bool wireaddr_from_hostname(struct wireaddr *addr, const char *hostname,
if (strends(hostname, ".onion")) {
u8 *dec = b32_decode(tmpctx, hostname,
strlen(hostname) - strlen(".onion"));
if (tal_len(dec) == TOR_V2_ADDRLEN)
if (tal_count(dec) == TOR_V2_ADDRLEN)
addr->type = ADDR_TYPE_TOR_V2;
else if (tal_len(dec) == TOR_V3_ADDRLEN)
else if (tal_count(dec) == TOR_V3_ADDRLEN)
addr->type = ADDR_TYPE_TOR_V3;
else {
if (err_msg)
@ -317,9 +317,9 @@ bool wireaddr_from_hostname(struct wireaddr *addr, const char *hostname,
return false;
}
addr->addrlen = tal_len(dec);
addr->addrlen = tal_count(dec);
addr->port = port;
memcpy(&addr->addr, dec, tal_len(dec));
memcpy(&addr->addr, dec, tal_count(dec));
return true;
}
@ -344,7 +344,7 @@ bool wireaddr_from_hostname(struct wireaddr *addr, const char *hostname,
return false;
}
if (broken_reply != NULL && memeq(addrinfo->ai_addr, addrinfo->ai_addrlen, broken_reply, tal_len(broken_reply))) {
if (broken_reply != NULL && memeq(addrinfo->ai_addr, addrinfo->ai_addrlen, broken_reply, tal_count(broken_reply))) {
res = false;
goto cleanup;
}

6
connectd/connect.c

@ -865,7 +865,7 @@ static struct io_plan *handle_returning_peer(struct io_conn *conn,
recv_gossip, NULL);
/* If they told us to send a message, queue it now */
if (tal_len(rpeer->inner_msg))
if (tal_count(rpeer->inner_msg))
msg_enqueue(&peer->local->peer_out, take(rpeer->inner_msg));
/* FIXME: rpeer destructor should close peer_fd, gossip_fd */
@ -1794,9 +1794,9 @@ static void append_peer_features(const struct peer_features ***pf,
new = tal(*pf, struct peer_features);
new->global_features = tal_dup_arr(new, u8, gfeatures,
tal_len(gfeatures), 0);
tal_count(gfeatures), 0);
new->local_features = tal_dup_arr(new, u8, lfeatures,
tal_len(lfeatures), 0);
tal_count(lfeatures), 0);
tal_resize(pf, num_nodes + 1);
(*pf)[num_nodes] = new;
}

6
connectd/tor_autoservice.c

@ -161,13 +161,13 @@ static void negotiate_auth(struct rbuf *rbuf, const char *tor_password)
cookiefileerrno = errno;
continue;
}
assert(tal_len(contents) != 0);
assert(tal_count(contents) != 0);
discard_remaining_response(rbuf);
tor_send_cmd(rbuf,
tal_fmt(tmpctx, "AUTHENTICATE %s",
tal_hexstr(tmpctx,
contents,
tal_len(contents)-1)));
tal_count(contents)-1)));
discard_remaining_response(rbuf);
return;
}
@ -222,7 +222,7 @@ struct wireaddr *tor_autoservice(const tal_t *ctx,
err(1, "Connecting stream socket to Tor service");
buffer = tal_arr(tmpctx, char, rbuf_good_size(fd));
rbuf_init(&rbuf, fd, buffer, tal_len(buffer));
rbuf_init(&rbuf, fd, buffer, tal_count(buffer));
negotiate_auth(&rbuf, tor_password);
onion = make_onion(ctx, &rbuf, laddr);

4
devtools/bolt11-cli.c

@ -157,9 +157,9 @@ int main(int argc, char *argv[])
}
list_for_each(&b11->extra_fields, extra, list) {
char *data = tal_arr(ctx, char, tal_len(extra->data)+1);
char *data = tal_arr(ctx, char, tal_count(extra->data)+1);
for (i = 0; i < tal_len(extra->data); i++)
for (i = 0; i < tal_count(extra->data); i++)
data[i] = bech32_charset[extra->data[i]];
data[i] = '\0';

18
gossipd/gossip.c

@ -234,10 +234,10 @@ static bool encode_short_channel_ids_end(u8 **encoded, size_t max_bytes)
switch ((enum scid_encode_types)(*encoded)[0]) {
case SHORTIDS_ZLIB:
z = zencode_scids(tmpctx, *encoded + 1, tal_len(*encoded) - 1);
z = zencode_scids(tmpctx, *encoded + 1, tal_count(*encoded) - 1);
if (z) {
tal_resize(encoded, 1 + tal_len(z));
memcpy((*encoded) + 1, z, tal_len(z));
tal_resize(encoded, 1 + tal_count(z));
memcpy((*encoded) + 1, z, tal_count(z));
goto check_length;
}
(*encoded)[0] = SHORTIDS_UNCOMPRESSED;
@ -251,10 +251,10 @@ static bool encode_short_channel_ids_end(u8 **encoded, size_t max_bytes)
check_length:
#if DEVELOPER
if (tal_len(*encoded) > max_scids_encode_bytes)
if (tal_count(*encoded) > max_scids_encode_bytes)
return false;
#endif
return tal_len(*encoded) <= max_bytes;
return tal_count(*encoded) <= max_bytes;
}
static void queue_peer_msg(struct peer *peer, const u8 *msg TAKES)
@ -650,7 +650,7 @@ static void handle_pong(struct peer *peer, const u8 *pong)
daemon_conn_send(&peer->daemon->master,
take(towire_gossip_ping_reply(NULL, true,
tal_len(pong))));
tal_count(pong))));
}
static void handle_reply_short_channel_ids_end(struct peer *peer, u8 *msg)
@ -747,7 +747,7 @@ static void handle_reply_channel_range(struct peer *peer, u8 *msg)
/* Add scids */
n = tal_count(peer->query_channel_scids);
tal_resize(&peer->query_channel_scids, n + tal_count(scids));
memcpy(peer->query_channel_scids + n, scids, tal_len(scids));
memcpy(peer->query_channel_scids + n, scids, tal_bytelen(scids));
status_debug("peer %s reply_channel_range %u+%u (of %u+%zu) %zu scids",
type_to_string(tmpctx, struct pubkey, &peer->id),
@ -1494,7 +1494,7 @@ static void append_node(const struct gossip_getnodes_entry ***nodes,
new = tal(*nodes, struct gossip_getnodes_entry);
new->nodeid = *nodeid;
new->global_features = tal_dup_arr(*nodes, u8, gfeatures,
tal_len(gfeatures), 0);
tal_count(gfeatures), 0);
if (!n || n->last_timestamp < 0) {
new->last_timestamp = -1;
new->addresses = NULL;
@ -1556,7 +1556,7 @@ static struct io_plan *ping_req(struct io_conn *conn, struct daemon *daemon,
}
ping = make_ping(peer, num_pong_bytes, len);
if (tal_len(ping) > 65535)
if (tal_count(ping) > 65535)
status_failed(STATUS_FAIL_MASTER_IO, "Oversize ping");
queue_peer_msg(peer, take(ping));

2
gossipd/gossip_store.c

@ -141,7 +141,7 @@ static bool gossip_store_append(int fd, struct routing_state *rstate, const u8 *
return false;
}
msglen = tal_len(msg);
msglen = tal_count(msg);
belen = cpu_to_be32(msglen);
checksum = cpu_to_be32(crc32c(0, msg, msglen));

32
gossipd/routing.c

@ -543,7 +543,7 @@ static u8 *check_channel_update(const tal_t *ctx,
/* 2 byte msg type + 64 byte signatures */
int offset = 66;
struct sha256_double hash;
sha256_double(&hash, update + offset, tal_len(update) - offset);
sha256_double(&hash, update + offset, tal_count(update) - offset);
if (!check_signed_hash(&hash, node_sig, node_key))
return towire_errorfmt(ctx, NULL,
@ -571,7 +571,7 @@ static u8 *check_channel_announcement(const tal_t *ctx,
int offset = 258;
struct sha256_double hash;
sha256_double(&hash, announcement + offset,
tal_len(announcement) - offset);
tal_count(announcement) - offset);
if (!check_signed_hash(&hash, node1_sig, node1_key)) {
return towire_errorfmt(ctx, NULL,
@ -734,7 +734,7 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
chan->satoshis = satoshis;
/* Channel is now public. */
chan->channel_announce = tal_dup_arr(chan, u8, msg, tal_len(msg), 0);
chan->channel_announce = tal_dup_arr(chan, u8, msg, tal_count(msg), 0);
/* Clear any private updates: new updates will trigger broadcast of
* this channel_announce. */
@ -760,7 +760,7 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
pending->updates[0] = NULL;
pending->updates[1] = NULL;
pending->announce = tal_dup_arr(pending, u8,
announce, tal_len(announce), 0);
announce, tal_count(announce), 0);
pending->update_timestamps[0] = pending->update_timestamps[1] = 0;
if (!fromwire_channel_announcement(pending, pending->announce,
@ -922,7 +922,7 @@ void handle_pending_cannouncement(struct routing_state *rstate,
* - if the `short_channel_id`'s output... is spent:
* - MUST ignore the message.
*/
if (tal_len(outscript) == 0) {
if (tal_count(outscript) == 0) {
status_trace("channel_announcement: no unspent txout %s",
type_to_string(pending, struct short_channel_id,
scid));
@ -980,7 +980,7 @@ static void update_pending(struct pending_cannouncement *pending,
status_trace("Replacing existing update");
tal_free(pending->updates[direction]);
}
pending->updates[direction] = tal_dup_arr(pending, u8, update, tal_len(update), 0);
pending->updates[direction] = tal_dup_arr(pending, u8, update, tal_count(update), 0);
pending->update_timestamps[direction] = timestamp;
}
}
@ -1059,7 +1059,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
/* Replace any old one. */
tal_free(chan->half[direction].channel_update);
chan->half[direction].channel_update
= tal_dup_arr(chan, u8, update, tal_len(update), 0);
= tal_dup_arr(chan, u8, update, tal_count(update), 0);
/* For private channels, we get updates without an announce: don't
* broadcast them! */
@ -1096,7 +1096,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
struct bitcoin_blkid chain_hash;
struct chan *chan;
u8 direction;
size_t len = tal_len(update);
size_t len = tal_count(update);
u8 *err;
serialized = tal_dup_arr(tmpctx, u8, update, len, 0);
@ -1179,8 +1179,8 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
if (is_halfchan_defined(c) && timestamp <= c->last_timestamp) {
/* They're not supposed to do this! */
if (timestamp == c->last_timestamp
&& !memeq(c->channel_update, tal_len(c->channel_update),
serialized, tal_len(serialized))) {
&& !memeq(c->channel_update, tal_count(c->channel_update),
serialized, tal_count(serialized))) {
status_unusual("Bad gossip repeated timestamp for %s(%u): %s then %s",
type_to_string(tmpctx,
struct short_channel_id,
@ -1228,7 +1228,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
static struct wireaddr *read_addresses(const tal_t *ctx, const u8 *ser)
{
const u8 *cursor = ser;
size_t max = tal_len(ser);
size_t max = tal_count(ser);
struct wireaddr *wireaddrs = tal_arr(ctx, struct wireaddr, 0);
int numaddrs = 0;
while (cursor && cursor < ser + max) {
@ -1296,7 +1296,7 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
node->gfeatures = tal_steal(node, features);
tal_free(node->node_announcement);
node->node_announcement = tal_dup_arr(node, u8, msg, tal_len(msg), 0);
node->node_announcement = tal_dup_arr(node, u8, msg, tal_count(msg), 0);
/* We might be waiting for channel_announce to be released. */
if (node_has_broadcastable_channels(node)) {
@ -1319,7 +1319,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
u8 *features, *addresses;
struct wireaddr *wireaddrs;
struct pending_node_announce *pna;
size_t len = tal_len(node_ann);
size_t len = tal_count(node_ann);
bool applied;
serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0);
@ -1421,7 +1421,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
pna->timestamp = timestamp;
tal_free(pna->node_announcement);
pna->node_announcement = tal_dup_arr(pna, u8, node_ann,
tal_len(node_ann),
tal_count(node_ann),
0);
}
return NULL;
@ -1581,7 +1581,7 @@ void routing_failure(struct routing_state *rstate,
* reactivated. */
if (failcode & UPDATE) {
u8 *err;
if (tal_len(channel_update) == 0) {
if (tal_count(channel_update) == 0) {
/* Suppress UNUSUAL log if local failure */
if (pubkey_eq(erring_node_pubkey, &rstate->local_id))
return;
@ -1600,7 +1600,7 @@ void routing_failure(struct routing_state *rstate,
return;
}
} else {
if (tal_len(channel_update) != 0)
if (tal_count(channel_update) != 0)
status_unusual("routing_failure: "
"UPDATE bit clear, channel_update given. "
"failcode: 0x%04x",

20
hsmd/hsm.c

@ -208,15 +208,15 @@ static struct io_plan *handle_cannouncement_sig(struct io_conn *conn,
return io_close(conn);
}
if (tal_len(ca) < offset) {
status_broken("bad cannounce length %zu", tal_len(ca));
if (tal_count(ca) < offset) {
status_broken("bad cannounce length %zu", tal_count(ca));
return io_close(conn);
}
/* TODO(cdecker) Check that this is actually a valid
* channel_announcement */
node_key(&node_pkey, NULL);
sha256_double(&hash, ca + offset, tal_len(ca) - offset);
sha256_double(&hash, ca + offset, tal_count(ca) - offset);
sign_hash(&node_pkey, &hash, &node_sig);
sign_hash(&funding_privkey, &hash, &bitcoin_sig);
@ -258,14 +258,14 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn,
tal_hex(tmpctx, dc->msg_in));
return io_close(conn);
}
if (tal_len(cu) < offset) {
if (tal_count(cu) < offset) {
status_broken("inner channel_update too short: %s",
tal_hex(tmpctx, dc->msg_in));
return io_close(conn);
}
node_key(&node_pkey, NULL);
sha256_double(&hash, cu + offset, tal_len(cu) - offset);
sha256_double(&hash, cu + offset, tal_count(cu) - offset);
sign_hash(&node_pkey, &hash, &sig);
@ -1315,11 +1315,11 @@ static void sign_invoice(struct daemon_conn *master, const u8 *msg)
/* FIXME: Check invoice! */
hrp = tal_dup_arr(tmpctx, char, (char *)hrpu8, tal_len(hrpu8), 1);
hrp[tal_len(hrpu8)] = '\0';
hrp = tal_dup_arr(tmpctx, char, (char *)hrpu8, tal_count(hrpu8), 1);
hrp[tal_count(hrpu8)] = '\0';
hash_u5_init(&hu5, hrp);
hash_u5(&hu5, u5bytes, tal_len(u5bytes));
hash_u5(&hu5, u5bytes, tal_count(u5bytes));
hash_u5_done(&hu5, &sha);
node_key(&node_pkey, NULL);
@ -1352,7 +1352,7 @@ static void sign_node_announcement(struct daemon_conn *master, const u8 *msg)
tal_hex(tmpctx, msg));
}
if (tal_len(ann) < offset) {
if (tal_count(ann) < offset) {
status_failed(STATUS_FAIL_GOSSIP_IO,
"Node announcement too short: %s",
tal_hex(tmpctx, msg));
@ -1360,7 +1360,7 @@ static void sign_node_announcement(struct daemon_conn *master, const u8 *msg)
/* FIXME(cdecker) Check the node announcement's content */
node_key(&node_pkey, NULL);
sha256_double(&hash, ann + offset, tal_len(ann) - offset);
sha256_double(&hash, ann + offset, tal_count(ann) - offset);
sign_hash(&node_pkey, &hash, &sig);

12
lightningd/gossip_msg.c

@ -57,8 +57,8 @@ void towire_gossip_getnodes_entry(u8 **pptr,
for (i=0; i<numaddresses; i++) {
towire_wireaddr(pptr, &entry->addresses[i]);
}
towire_u8(pptr, tal_len(entry->alias));
towire(pptr, entry->alias, tal_len(entry->alias));
towire_u8(pptr, tal_count(entry->alias));
towire(pptr, entry->alias, tal_count(entry->alias));
towire(pptr, entry->color, sizeof(entry->color));
}
@ -127,8 +127,8 @@ fromwire_peer_features(const tal_t *ctx, const u8 **pptr, size_t *max)
void towire_peer_features(u8 **pptr, const struct peer_features *pf)
{
towire_u16(pptr, tal_len(pf->local_features));
towire_u8_array(pptr, pf->local_features, tal_len(pf->local_features));
towire_u16(pptr, tal_len(pf->global_features));
towire_u8_array(pptr, pf->global_features, tal_len(pf->global_features));
towire_u16(pptr, tal_count(pf->local_features));
towire_u8_array(pptr, pf->local_features, tal_count(pf->local_features));
towire_u16(pptr, tal_count(pf->global_features));
towire_u8_array(pptr, pf->global_features, tal_count(pf->global_features));
}

4
lightningd/invoice.c

@ -732,10 +732,10 @@ static void json_decodepay(struct command *cmd,
json_array_start(response, "extra");
list_for_each(&b11->extra_fields, extra, list) {
char *data = tal_arr(cmd, char, tal_len(extra->data)+1);
char *data = tal_arr(cmd, char, tal_count(extra->data)+1);
size_t i;
for (i = 0; i < tal_len(extra->data); i++)
for (i = 0; i < tal_count(extra->data); i++)
data[i] = bech32_charset[extra->data[i]];
data[i] = '\0';
json_object_start(response, NULL);

2
lightningd/log.c

@ -98,7 +98,7 @@ static void log_to_stdout(const char *prefix,
static size_t mem_used(const struct log_entry *e)
{
return sizeof(*e) + strlen(e->log) + 1 + tal_len(e->io);
return sizeof(*e) + strlen(e->log) + 1 + tal_count(e->io);
}
static size_t prune_log(struct log_book *log)

2
lightningd/log_status.c

@ -14,7 +14,7 @@ bool log_status_msg(struct log *log, const u8 *msg)
}
} else if (fromwire_status_io(msg, msg, &level, &who, &data)) {
if (level == LOG_IO_IN || level == LOG_IO_OUT) {
log_io(log, level, who, data, tal_len(data));
log_io(log, level, who, data, tal_count(data));
return true;
}
}

2
lightningd/options.c

@ -239,7 +239,7 @@ static char *opt_set_rgb(const char *arg, struct lightningd *ld)
* byte is the green value, and the last byte is the blue value.
*/
ld->rgb = tal_hexdata(ld, arg, strlen(arg));
if (!ld->rgb || tal_len(ld->rgb) != 3)
if (!ld->rgb || tal_count(ld->rgb) != 3)
return tal_fmt(NULL, "rgb '%s' is not six hex digits", arg);
return NULL;
}

8
lightningd/peer_control.c

@ -71,7 +71,7 @@ static void copy_to_parent_log(const char *prefix,
struct log *parent_log)
{
if (level == LOG_IO_IN || level == LOG_IO_OUT)
log_io(parent_log, level, prefix, io, tal_len(io));
log_io(parent_log, level, prefix, io, tal_count(io));
else if (continued)
log_add(parent_log, "%s ... %s", prefix, str);
else
@ -388,7 +388,7 @@ void channel_errmsg(struct channel *channel,
if (err_for_them && !channel->error)
channel->error = tal_dup_arr(channel, u8,
err_for_them,
tal_len(err_for_them), 0);
tal_count(err_for_them), 0);
/* Make sure channel_fail_permanent doesn't tell connectd we died! */
channel->connected = false;
@ -459,10 +459,10 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
" and localfeatures %s",
tal_hexstr(msg,
global_features,
tal_len(global_features)),
tal_count(global_features)),
tal_hexstr(msg,
local_features,
tal_len(local_features)));
tal_count(local_features)));
goto send_error;
}

10
lightningd/peer_htlcs.c

@ -95,7 +95,7 @@ static void fail_in_htlc(struct htlc_in *hin,
assert(failcode || failuremsg);
hin->failcode = failcode;
if (failuremsg)
hin->failuremsg = tal_dup_arr(hin, u8, failuremsg, tal_len(failuremsg), 0);
hin->failuremsg = tal_dup_arr(hin, u8, failuremsg, tal_count(failuremsg), 0);
/* We need this set, since we send it to channeld. */
if (hin->failcode & UPDATE)
@ -377,7 +377,7 @@ static void rcvd_htlc_reply(struct subd *subd, const u8 *msg, const int *fds UNU
if (!hout->in) {
char *localfail = tal_fmt(msg, "%s: %.*s",
onion_type_name(failure_code),
(int)tal_len(failurestr),
(int)tal_count(failurestr),
(const char *)failurestr);
payment_failed(ld, hout, localfail);
} else
@ -784,7 +784,7 @@ static bool peer_failed_our_htlc(struct channel *channel,
hout->failcode = failed->failcode;
if (!failed->failcode)
hout->failuremsg = tal_dup_arr(hout, u8, failed->failreason,
tal_len(failed->failreason), 0);
tal_count(failed->failreason), 0);
else
hout->failuremsg = NULL;
@ -1348,7 +1348,7 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
static void *tal_arr_append_(void **p, size_t size)
{
size_t n = tal_len(*p) / size;
size_t n = tal_bytelen(*p) / size;
tal_resize_(p, size, n+1, false);
return (char *)(*p) + n * size;
}
@ -1418,7 +1418,7 @@ static void add_fail(u64 id, enum side side,
if (failuremsg)
(*f)->failreason
= tal_dup_arr(*f, u8, failuremsg, tal_len(failuremsg), 0);
= tal_dup_arr(*f, u8, failuremsg, tal_count(failuremsg), 0);
else
(*f)->failreason = NULL;
*s = side;

6
lightningd/test/run-commit_tx.c

@ -65,8 +65,8 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
lina = linearize_tx(tmpctx, a);
linb = linearize_tx(tmpctx, b);
for (i = 0; i < tal_len(lina); i++) {
if (i >= tal_len(linb))
for (i = 0; i < tal_count(lina); i++) {
if (i >= tal_count(linb))
errx(1, "Second tx is truncated:\n"
"%s\n"
"%s",
@ -80,7 +80,7 @@ static void tx_must_be_eq(const struct bitcoin_tx *a,
tal_hex(tmpctx, lina),
tal_hex(tmpctx, linb));
}
if (i != tal_len(linb))
if (i != tal_count(linb))
errx(1, "First tx is truncated:\n"
"%s\n"
"%s",

14
onchaind/onchain.c

@ -305,7 +305,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
/* Worst-case sig is 73 bytes */
fee = feerate_per_kw * (measure_tx_weight(tx)
+ 1 + 3 + 73 + 0 + tal_len(wscript))
+ 1 + 3 + 73 + 0 + tal_count(wscript))
/ 1000;
/* Result is trivial? Spend with small feerate, but don't wait
@ -313,7 +313,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
if (tx->output[0].amount < dust_limit_satoshis + fee) {
/* FIXME: We should use SIGHASH_NONE so others can take it */
fee = feerate_floor() * (measure_tx_weight(tx)
+ 1 + 3 + 73 + 0 + tal_len(wscript))
+ 1 + 3 + 73 + 0 + tal_count(wscript))
/ 1000;
/* This shouldn't happen (we don't set feerate below floor!),
* but just in case. */
@ -505,7 +505,7 @@ static void propose_resolution_at_block(struct tracked_output *out,
static bool is_valid_sig(const u8 *e)
{
secp256k1_ecdsa_signature sig;
size_t len = tal_len(e);
size_t len = tal_count(e);
/* Last byte is sighash flags */
if (len < 1)
@ -820,12 +820,12 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out,
tx_type_name(out->tx_type),
output_type_name(out->output_type));
if (tal_len(witness_preimage) != sizeof(preimage))
if (tal_count(witness_preimage) != sizeof(preimage))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"%s/%s spent with bad witness length %zu",
tx_type_name(out->tx_type),
output_type_name(out->output_type),
tal_len(witness_preimage));
tal_count(witness_preimage));
memcpy(&preimage, witness_preimage, sizeof(preimage));
sha256(&sha, &preimage, sizeof(preimage));
ripemd160(&ripemd, &sha, sizeof(sha));
@ -1391,9 +1391,9 @@ static int match_htlc_output(const struct bitcoin_tx *tx,
if (!htlc_scripts[i])
continue;
sha256(&sha, htlc_scripts[i], tal_len(htlc_scripts[i]));
sha256(&sha, htlc_scripts[i], tal_count(htlc_scripts[i]));
if (memeq(tx->output[outnum].script + 2,
tal_len(tx->output[outnum].script) - 2,
tal_count(tx->output[outnum].script) - 2,
&sha, sizeof(sha)))
return i;
}

2
onchaind/test/run-grind_feerate.c

@ -169,7 +169,7 @@ int main(int argc, char *argv[])
*tx->input[0].amount = 700000;
der = tal_hexdata(tmpctx, "30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9",
strlen("30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9"));
if (!signature_from_der(der, tal_len(der), &sig))
if (!signature_from_der(der, tal_count(der), &sig))
abort();
wscript = tal_hexdata(tmpctx, "76a914a8c40c334351dbe8e5908544f1c98fbcfb8719fc8763ac6721038ffd2621647812011960152bfb79c5a2787dfe6c4f37e2222547de054432eb7f7c820120876475527c2103cf8e2f193a6aed60db80af75f3c8d59c2de735b299b7c7083527be9bd23b77a852ae67a914b8bcd51efa35be1e50ae2d5f72f4500acb005c9c88ac6868", strlen("76a914a8c40c334351dbe8e5908544f1c98fbcfb8719fc8763ac6721038ffd2621647812011960152bfb79c5a2787dfe6c4f37e2222547de054432eb7f7c820120876475527c2103cf8e2f193a6aed60db80af75f3c8d59c2de735b299b7c7083527be9bd23b77a852ae67a914b8bcd51efa35be1e50ae2d5f72f4500acb005c9c88ac6868"));

4
tools/generate-wire.py

@ -206,7 +206,7 @@ fromwire_impl_templ = """bool fromwire_{name}({ctx}const void *p{args})
{{
{fields}
\tconst u8 *cursor = p;
\tsize_t plen = tal_len(p);
\tsize_t plen = tal_count(p);
\tif (fromwire_u16(&cursor, &plen) != {enum.name})
\t\treturn false;
@ -235,7 +235,7 @@ printwire_header_templ = """void printwire_{name}(const char *fieldname, const u
"""
printwire_impl_templ = """void printwire_{name}(const char *fieldname, const u8 *cursor)
{{
\tsize_t plen = tal_len(cursor);
\tsize_t plen = tal_count(cursor);
\tif (fromwire_u16(&cursor, &plen) != {enum.name}) {{
\t\tprintf("WRONG TYPE?!\\n");

6
wallet/db.c

@ -741,7 +741,7 @@ bool sqlite3_bind_short_channel_id_array(sqlite3_stmt *stmt, int col,
for (i = 0; i < num; ++i)
towire_short_channel_id(&ser, &id[i]);
sqlite3_bind_blob(stmt, col, ser, tal_len(ser), SQLITE_TRANSIENT);
sqlite3_bind_blob(stmt, col, ser, tal_count(ser), SQLITE_TRANSIENT);
tal_free(ser);
return true;
@ -776,7 +776,7 @@ sqlite3_column_short_channel_id_array(const tal_t *ctx,
bool sqlite3_bind_tx(sqlite3_stmt *stmt, int col, const struct bitcoin_tx *tx)
{
u8 *ser = linearize_tx(NULL, tx);
sqlite3_bind_blob(stmt, col, ser, tal_len(ser), SQLITE_TRANSIENT);
sqlite3_bind_blob(stmt, col, ser, tal_count(ser), SQLITE_TRANSIENT);
tal_free(ser);
return true;
}
@ -838,7 +838,7 @@ bool sqlite3_bind_pubkey_array(sqlite3_stmt *stmt, int col,
for (i = 0; i < n; ++i)
pubkey_to_der(&ders[i * PUBKEY_DER_LEN], &pks[i]);
sqlite3_bind_blob(stmt, col, ders, tal_len(ders), SQLITE_TRANSIENT);
sqlite3_bind_blob(stmt, col, ders, tal_count(ders), SQLITE_TRANSIENT);
tal_free(ders);
return true;

12
wallet/test/run-wallet.c

@ -660,7 +660,7 @@ static bool bitcoin_tx_eq(const struct bitcoin_tx *tx1,
bool eq;
lin1 = linearize_tx(NULL, tx1);
lin2 = linearize_tx(lin1, tx2);
eq = memeq(lin1, tal_len(lin1), lin2, tal_len(lin2));
eq = memeq(lin1, tal_count(lin1), lin2, tal_count(lin2));
tal_free(lin1);
return eq;
}
@ -681,9 +681,9 @@ static bool channelseq(struct channel *c1, struct channel *c2)
CHECK(c1->our_msatoshi == c2->our_msatoshi);
CHECK((c1->remote_shutdown_scriptpubkey == NULL && c2->remote_shutdown_scriptpubkey == NULL) || memeq(
c1->remote_shutdown_scriptpubkey,
tal_len(c1->remote_shutdown_scriptpubkey),
tal_count(c1->remote_shutdown_scriptpubkey),
c2->remote_shutdown_scriptpubkey,
tal_len(c2->remote_shutdown_scriptpubkey)));
tal_count(c2->remote_shutdown_scriptpubkey)));
CHECK(memeq(
&c1->funding_txid,
sizeof(struct sha256_double),
@ -713,9 +713,9 @@ static bool channelseq(struct channel *c1, struct channel *c2)
CHECK(c1->final_key_idx == c2->final_key_idx);
CHECK(memeq(c1->remote_shutdown_scriptpubkey,
tal_len(c1->remote_shutdown_scriptpubkey),
tal_count(c1->remote_shutdown_scriptpubkey),
c2->remote_shutdown_scriptpubkey,
tal_len(c2->remote_shutdown_scriptpubkey)));
tal_count(c2->remote_shutdown_scriptpubkey)));
CHECK(c1->last_was_revoke == c2->last_was_revoke);
@ -759,7 +759,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
mempat(&last_commit, sizeof(last_commit));
pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk);
ci->feerate_per_kw[LOCAL] = ci->feerate_per_kw[REMOTE] = 31337;
mempat(scriptpubkey, tal_len(scriptpubkey));
mempat(scriptpubkey, tal_count(scriptpubkey));
c1.first_blocknum = 1;
c1.final_key_idx = 1337;
p = new_peer(ld, 0, &pk, NULL, NULL, NULL);

2
wallet/txfilter.c

@ -56,7 +56,7 @@ void txfilter_add_scriptpubkey(struct txfilter *filter, const u8 *script TAKES)
{
size_t count = tal_count(filter->scriptpubkeys);
tal_resize(&filter->scriptpubkeys, count + 1);
filter->scriptpubkeys[count] = tal_dup_arr(filter, u8, script, tal_len(script), 0);
filter->scriptpubkeys[count] = tal_dup_arr(filter, u8, script, tal_count(script), 0);
}
void txfilter_add_derkey(struct txfilter *filter,

6
wallet/wallet.c

@ -919,7 +919,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
if (chan->remote_shutdown_scriptpubkey)
sqlite3_bind_blob(stmt, 16, chan->remote_shutdown_scriptpubkey,
tal_len(chan->remote_shutdown_scriptpubkey),
tal_count(chan->remote_shutdown_scriptpubkey),
SQLITE_TRANSIENT);
else
sqlite3_bind_null(stmt, 16);
@ -1602,7 +1602,7 @@ void wallet_payment_store(struct wallet *wallet,
sqlite3_bind_int64(stmt, 4, payment->msatoshi);
sqlite3_bind_int(stmt, 5, payment->timestamp);
sqlite3_bind_blob(stmt, 6, payment->path_secrets,
tal_len(payment->path_secrets),
tal_bytelen(payment->path_secrets),
SQLITE_TRANSIENT);
sqlite3_bind_pubkey_array(stmt, 7, payment->route_nodes);
sqlite3_bind_short_channel_id_array(stmt, 8,
@ -2111,7 +2111,7 @@ void wallet_utxoset_add(struct wallet *w, const struct bitcoin_tx *tx,
sqlite3_bind_int(stmt, 3, blockheight);
sqlite3_bind_null(stmt, 4);
sqlite3_bind_int(stmt, 5, txindex);
sqlite3_bind_blob(stmt, 6, scriptpubkey, tal_len(scriptpubkey), SQLITE_TRANSIENT);
sqlite3_bind_blob(stmt, 6, scriptpubkey, tal_count(scriptpubkey), SQLITE_TRANSIENT);
sqlite3_bind_int64(stmt, 7, satoshis);
db_exec_prepared(w->db, stmt);

2
wallet/walletrpc.c

@ -128,7 +128,7 @@ static void json_withdraw(struct command *cmd,
}
if (!wtx_select_utxos(&withdraw->wtx, feerate_per_kw,
tal_len(withdraw->destination)))
tal_count(withdraw->destination)))
return;
u8 *msg = towire_hsm_sign_withdrawal(cmd,

2
wire/test/run-peer-wire.c

@ -68,7 +68,7 @@ static void set_pubkey(struct pubkey *key)
#define eq_var(p1, p2, field) \
(tal_count((p1)->field) == tal_count((p2)->field) \
&& (tal_count((p1)->field) == 0 || memcmp((p1)->field, (p2)->field, tal_len((p1)->field)) == 0))
&& (tal_count((p1)->field) == 0 || memcmp((p1)->field, (p2)->field, tal_bytelen((p1)->field)) == 0))
/* Convenience structs for everyone! */
struct msg_error {

2
wire/towire.c

@ -160,7 +160,7 @@ void towire_wirestring(u8 **pptr, const char *str)
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
{
u8 *lin = linearize_tx(tmpctx, tx);
towire_u8_array(pptr, lin, tal_len(lin));
towire_u8_array(pptr, lin, tal_count(lin));
}
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)

9
wire/wire_io.c

@ -104,7 +104,7 @@ static int do_write_wire_header(int fd, struct io_plan_arg *arg)
static int do_write_wire(int fd, struct io_plan_arg *arg)
{
ssize_t ret;
size_t totlen = tal_len(arg->u1.cp);
size_t totlen = tal_bytelen(arg->u1.cp);
/* Still writing header? */
if (arg->u2.s & INSIDE_HEADER_BIT)
@ -131,13 +131,14 @@ struct io_plan *io_write_wire_(struct io_conn *conn,
{
struct io_plan_arg *arg = io_plan_arg(conn, IO_OUT);
if (tal_len(data) >= INSIDE_HEADER_BIT) {
if (tal_bytelen(data) >= INSIDE_HEADER_BIT) {
errno = E2BIG;
return io_close(conn);
}
arg->u1.const_vp = tal_dup_arr(conn, u8, memcheck(data, tal_len(data)),
tal_len(data), 0);
arg->u1.const_vp = tal_dup_arr(conn, u8,
memcheck(data, tal_bytelen(data)),
tal_bytelen(data), 0);
/* We use u2 to store the length we've written. */
arg->u2.s = INSIDE_HEADER_BIT;

4
wire/wire_sync.c

@ -7,10 +7,10 @@
bool wire_sync_write(int fd, const void *msg TAKES)
{
wire_len_t hdr = cpu_to_wirelen(tal_len(msg));
wire_len_t hdr = cpu_to_wirelen(tal_bytelen(msg));
bool ret;
assert(tal_len(msg) < WIRE_LEN_LIMIT);
assert(tal_bytelen(msg) < WIRE_LEN_LIMIT);
ret = write_all(fd, &hdr, sizeof(hdr))
&& write_all(fd, msg, tal_count(msg));

Loading…
Cancel
Save