common: add tal_arr_eq helper.

We do `memeq(a, tal_bytelen(a), b, tal_bytelen(b))` remarkably often...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-02-14 20:08:33 +10:30 committed by Christian Decker
parent b6cc0ce425
commit df44431f8c
50 changed files with 98 additions and 178 deletions

View File

@ -133,8 +133,7 @@ static bool input_identical(const struct wally_psbt *a,
const u8 *b_in = linearize_input(tmpctx, const u8 *b_in = linearize_input(tmpctx,
&b->inputs[b_index]); &b->inputs[b_index]);
return memeq(a_in, tal_bytelen(a_in), return tal_arr_eq(a_in, b_in);
b_in, tal_bytelen(b_in));
} }
static bool output_identical(const struct wally_psbt *a, static bool output_identical(const struct wally_psbt *a,
@ -146,8 +145,7 @@ static bool output_identical(const struct wally_psbt *a,
&a->outputs[a_index]); &a->outputs[a_index]);
const u8 *b_out = linearize_output(tmpctx, const u8 *b_out = linearize_output(tmpctx,
&b->outputs[b_index]); &b->outputs[b_index]);
return memeq(a_out, tal_bytelen(a_out), return tal_arr_eq(a_out, b_out);
b_out, tal_bytelen(b_out));
} }
static void sort_inputs(struct wally_psbt *psbt) static void sort_inputs(struct wally_psbt *psbt)

View File

@ -106,8 +106,7 @@ static void test_b11(const char *b11str,
list); list);
list_for_each(&b11->extra_fields, b11_extra, list) { list_for_each(&b11->extra_fields, b11_extra, list) {
assert(expect_extra->tag == b11_extra->tag); assert(expect_extra->tag == b11_extra->tag);
assert(memeq(expect_extra->data, tal_bytelen(expect_extra->data), assert(tal_arr_eq(expect_extra->data, b11_extra->data));
b11_extra->data, tal_bytelen(b11_extra->data)));
expect_extra = list_next(&expect_b11->extra_fields, expect_extra = list_next(&expect_b11->extra_fields,
expect_extra, list); expect_extra, list);
} }

View File

@ -205,7 +205,7 @@ int main(int argc, char *argv[])
tal_resize(&enc, tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE); tal_resize(&enc, tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE);
dec = cryptomsg_decrypt_body(enc, &cs_in, enc); dec = cryptomsg_decrypt_body(enc, &cs_in, enc);
assert(memeq(dec, tal_bytelen(dec), msg, tal_bytelen(msg))); assert(tal_arr_eq(dec, (u8 *)msg));
} }
common_shutdown(); common_shutdown();
return 0; return 0;

View File

@ -120,8 +120,7 @@ static void test_featurebits_or(void)
set_feature_bit(&control, i); set_feature_bit(&control, i);
} }
u8 *result = featurebits_or(tmpctx, take(f1), f2); u8 *result = featurebits_or(tmpctx, take(f1), f2);
assert( assert(tal_arr_eq(result, control));
memeq(result, tal_bytelen(result), control, tal_bytelen(control)));
} }
static bool feature_set_eq(const struct feature_set *f1, static bool feature_set_eq(const struct feature_set *f1,
@ -129,8 +128,7 @@ static bool feature_set_eq(const struct feature_set *f1,
{ {
/* We assume minimal sizing */ /* We assume minimal sizing */
for (size_t i = 0; i < ARRAY_SIZE(f1->bits); i++) { for (size_t i = 0; i < ARRAY_SIZE(f1->bits); i++) {
if (!memeq(f1->bits[i], tal_bytelen(f1->bits[i]), if (!tal_arr_eq(f1->bits[i], f2->bits[i]))
f2->bits[i], tal_bytelen(f2->bits[i])))
return false; return false;
} }
return true; return true;

View File

@ -176,7 +176,7 @@ int main(int argc, char *argv[])
expected = json_tok_bin_from_hex(tmpctx, json, json_get_member(json, toks, "onion")); expected = json_tok_bin_from_hex(tmpctx, json, json_get_member(json, toks, "onion"));
actual = serialize_onionpacket(tmpctx, op); actual = serialize_onionpacket(tmpctx, op);
assert(memeq(expected, tal_bytelen(expected), actual, tal_bytelen(actual))); assert(tal_arr_eq(expected, actual));
/* Now decode! */ /* Now decode! */
op = parse_onionpacket(tmpctx, actual, tal_bytelen(actual), NULL); op = parse_onionpacket(tmpctx, actual, tal_bytelen(actual), NULL);
@ -187,8 +187,7 @@ int main(int argc, char *argv[])
json_to_secret(json, t, &mykey); json_to_secret(json, t, &mykey);
test_ecdh(&op->ephemeralkey, &ss); test_ecdh(&op->ephemeralkey, &ss);
rs = process_onionpacket(tmpctx, op, &ss, assoc_data, tal_bytelen(assoc_data), true); rs = process_onionpacket(tmpctx, op, &ss, assoc_data, tal_bytelen(assoc_data), true);
assert(memeq(rs->raw_payload, tal_bytelen(rs->raw_payload), assert(tal_arr_eq(rs->raw_payload, payloads[i]));
payloads[i], tal_bytelen(payloads[i])));
if (rs->nextcase == ONION_FORWARD) if (rs->nextcase == ONION_FORWARD)
op = rs->next; op = rs->next;
else else

View File

@ -158,8 +158,7 @@ int main(int argc, char *argv[])
json_tok_bin_from_hex, json_tok_bin_from_hex,
&payload), &payload),
JSON_SCAN(json_to_pubkey, &ids[i])) == NULL); JSON_SCAN(json_to_pubkey, &ids[i])) == NULL);
assert(memeq(payload, tal_bytelen(payload), assert(tal_arr_eq(payload, onionhops[i]));
onionhops[i], tal_bytelen(onionhops[i])));
} }
/* Now, create onion! */ /* Now, create onion! */
@ -174,8 +173,7 @@ int main(int argc, char *argv[])
JSON_SCAN_TAL(tmpctx, JSON_SCAN_TAL(tmpctx,
json_tok_bin_from_hex, json_tok_bin_from_hex,
&expected_onion)) == NULL); &expected_onion)) == NULL);
assert(memeq(expected_onion, tal_bytelen(expected_onion), assert(tal_arr_eq(expected_onion, onion));
onion, tal_bytelen(onion)));
/* FIXME: unwrap and test! */ /* FIXME: unwrap and test! */
#if 0 #if 0
@ -196,8 +194,7 @@ int main(int argc, char *argv[])
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &expected_onion)) JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &expected_onion))
== NULL); == NULL);
serialized = serialize_onionpacket(tmpctx, op); serialized = serialize_onionpacket(tmpctx, op);
assert(memeq(expected_onion, tal_bytelen(expected_onion), assert(tal_arr_eq(expected_onion, serialized));
serialized, tal_bytelen(serialized)));
if (blinding) { if (blinding) {
assert(unblind_onion(blinding, test_ecdh, assert(unblind_onion(blinding, test_ecdh,
@ -207,8 +204,7 @@ int main(int argc, char *argv[])
} }
rs = process_onionpacket(tmpctx, op, &ss, associated_data, rs = process_onionpacket(tmpctx, op, &ss, associated_data,
tal_bytelen(associated_data), true); tal_bytelen(associated_data), true);
assert(memeq(rs->raw_payload, tal_bytelen(rs->raw_payload), assert(tal_arr_eq(rs->raw_payload, onionhops[i]));
onionhops[i], tal_bytelen(onionhops[i])));
if (rs->nextcase == ONION_FORWARD) if (rs->nextcase == ONION_FORWARD)
op = rs->next; op = rs->next;
else else

View File

@ -183,8 +183,7 @@ int main(int argc, char *argv[])
json_get_member(json, t, "encoded_tlvs")); json_get_member(json, t, "encoded_tlvs"));
expected = json_to_enctlvs(tmpctx, json, expected = json_to_enctlvs(tmpctx, json,
json_get_member(json, t, "tlvs")); json_get_member(json, t, "tlvs"));
assert(memeq(expected, tal_bytelen(expected), assert(tal_arr_eq(expected, enctlvs[i]));
enctlvs[i], tal_bytelen(enctlvs[i])));
} }
/* Now do the blinding. */ /* Now do the blinding. */
@ -221,8 +220,7 @@ int main(int argc, char *argv[])
expected_enctlv = json_tok_bin_from_hex(tmpctx,json, expected_enctlv = json_tok_bin_from_hex(tmpctx,json,
json_get_member(json, t, json_get_member(json, t,
"encrypted_data")); "encrypted_data"));
assert(memeq(enctlv, tal_bytelen(enctlv), assert(tal_arr_eq(enctlv, expected_enctlv));
expected_enctlv, tal_bytelen(expected_enctlv)));
json_to_pubkey(json, json_get_member(json, t, "blinded_node_id"), json_to_pubkey(json, json_get_member(json, t, "blinded_node_id"),
&expected_alias); &expected_alias);

View File

@ -219,7 +219,7 @@ static void run_unit_tests(void)
oreply = unwrap_onionreply(tmpctx, ss, 5, reply, &origin_index); oreply = unwrap_onionreply(tmpctx, ss, 5, reply, &origin_index);
printf("unwrapped %s\n", tal_hex(tmpctx, oreply)); printf("unwrapped %s\n", tal_hex(tmpctx, oreply));
assert(memeq(raw, tal_bytelen(raw), oreply, tal_bytelen(oreply))); assert(tal_arr_eq(raw, oreply));
assert(origin_index == 4); assert(origin_index == 4);
} }

View File

@ -1,6 +1,7 @@
#include "config.h" #include "config.h"
#include <bitcoin/chainparams.h> #include <bitcoin/chainparams.h>
#include <ccan/list/list.h> #include <ccan/list/list.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h> #include <ccan/str/hex/hex.h>
#include <ccan/tal/path/path.h> #include <ccan/tal/path/path.h>
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
@ -76,6 +77,11 @@ u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len)
return data; return data;
} }
bool tal_arr_eq_(const void *a, const void *b, size_t unused)
{
return memeq(a, tal_bytelen(a), b, tal_bytelen(b));
}
/* Use the POSIX C locale. */ /* Use the POSIX C locale. */
void setup_locale(void) void setup_locale(void)
{ {

View File

@ -62,6 +62,12 @@ u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len);
(*(p))[n_] = (s); \ (*(p))[n_] = (s); \
} while(0) } while(0)
/* Checks if two tal_arr are equal: sizeof checks types are the same */
#define tal_arr_eq(a, b) tal_arr_eq_((a), (b), sizeof((a) == (b)))
/* Avoids double-evaluation in macro */
bool tal_arr_eq_(const void *a, const void *b, size_t unused);
/** /**
* Remove an element from an array * Remove an element from an array
* *

View File

@ -205,8 +205,7 @@ int main(int argc, char *argv[])
wscript = bitcoin_redeem_2of2(ctx, &local_fundingkey, &remote_fundingkey); wscript = bitcoin_redeem_2of2(ctx, &local_fundingkey, &remote_fundingkey);
expect_scriptpubkey = scriptpubkey_p2wsh(ctx, wscript); expect_scriptpubkey = scriptpubkey_p2wsh(ctx, wscript);
if (!memeq(expect_scriptpubkey, tal_bytelen(expect_scriptpubkey), if (!tal_arr_eq(expect_scriptpubkey, scriptpubkey)) {
scriptpubkey, tal_bytelen(scriptpubkey))) {
printf("*** FATAL *** outscript %s should be %s\n", printf("*** FATAL *** outscript %s should be %s\n",
tal_hex(ctx, scriptpubkey), tal_hex(ctx, scriptpubkey),
tal_hex(ctx, expect_scriptpubkey)); tal_hex(ctx, expect_scriptpubkey));

View File

@ -241,8 +241,7 @@ static void runtest(const char *filename)
if (oniontok) { if (oniontok) {
onion = json_tok_bin_from_hex(ctx, buffer, oniontok); onion = json_tok_bin_from_hex(ctx, buffer, oniontok);
if (!memeq(onion, tal_bytelen(onion), serialized, if (!tal_arr_eq(onion, serialized))
tal_bytelen(serialized)))
errx(1, errx(1,
"Generated does not match the expected onion: \n" "Generated does not match the expected onion: \n"
"generated: %s\n" "generated: %s\n"

View File

@ -642,8 +642,7 @@ void gossmap_manage_handle_get_txout_reply(struct gossmap_manage *gm, const u8 *
goto bad; goto bad;
} }
if (!memeq(outscript, tal_bytelen(outscript), if (!tal_arr_eq(outscript, pca->scriptpubkey)) {
pca->scriptpubkey, tal_bytelen(pca->scriptpubkey))) {
peer_warning(gm, pca->source_peer, peer_warning(gm, pca->source_peer,
"channel_announcement: txout %s expected %s, got %s", "channel_announcement: txout %s expected %s, got %s",
short_channel_id_to_str(tmpctx, &scid), short_channel_id_to_str(tmpctx, &scid),

View File

@ -500,9 +500,7 @@ static void handle_peer_shutdown(struct state *state, u8 *msg)
open_err_fatal(state, "Bad shutdown %s", tal_hex(msg, msg)); open_err_fatal(state, "Bad shutdown %s", tal_hex(msg, msg));
if (tal_count(state->upfront_shutdown_script[REMOTE]) if (tal_count(state->upfront_shutdown_script[REMOTE])
&& !memeq(scriptpubkey, tal_count(scriptpubkey), && !tal_arr_eq(scriptpubkey, state->upfront_shutdown_script[REMOTE]))
state->upfront_shutdown_script[REMOTE],
tal_count(state->upfront_shutdown_script[REMOTE])))
open_err_fatal(state, open_err_fatal(state,
"scriptpubkey %s is not as agreed upfront (%s)", "scriptpubkey %s is not as agreed upfront (%s)",
tal_hex(state, scriptpubkey), tal_hex(state, scriptpubkey),

View File

@ -75,7 +75,7 @@ static void test_encrypt_decrypt_equality(const u8 *msg)
tal_resize(&enc, tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE); tal_resize(&enc, tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE);
dec = cryptomsg_decrypt_body(msg, &cs_in, enc); dec = cryptomsg_decrypt_body(msg, &cs_in, enc);
assert(memeq(dec, tal_bytelen(dec), msg, tal_bytelen(msg))); assert(tal_arr_eq(dec, msg));
} }
/* Test header decryption of arbitrary bytes (should always fail). */ /* Test header decryption of arbitrary bytes (should always fail). */

View File

@ -60,14 +60,11 @@ static bool equal(const struct accept_channel *x,
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->upfront_shutdown_script, if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
tal_bytelen(x->tlvs->upfront_shutdown_script), y->tlvs->upfront_shutdown_script))
y->tlvs->upfront_shutdown_script,
tal_bytelen(y->tlvs->upfront_shutdown_script)))
return false; return false;
return memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type), return tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type);
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -86,14 +86,11 @@ static bool equal(const struct accept_channel2 *x,
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->upfront_shutdown_script, if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
tal_bytelen(x->tlvs->upfront_shutdown_script), y->tlvs->upfront_shutdown_script))
y->tlvs->upfront_shutdown_script,
tal_bytelen(y->tlvs->upfront_shutdown_script)))
return false; return false;
if (!memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type), if (!tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type))
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type)))
return false; return false;
if (!!x->tlvs->require_confirmed_inputs != if (!!x->tlvs->require_confirmed_inputs !=

View File

@ -53,8 +53,7 @@ static bool equal(const struct channel_announcement *x,
if (!node_id_eq(&x->node_id_2, &y->node_id_2)) if (!node_id_eq(&x->node_id_2, &y->node_id_2))
return false; return false;
return memeq(x->features, tal_bytelen(x->features), y->features, return tal_arr_eq(x->features, y->features);
tal_bytelen(y->features));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -35,9 +35,7 @@ static bool equal(const struct channel_ready *x, const struct channel_ready *y)
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
return memeq( return tal_arr_eq(x->tlvs->short_channel_id, y->tlvs->short_channel_id);
x->tlvs->short_channel_id, tal_bytelen(x->tlvs->short_channel_id),
y->tlvs->short_channel_id, tal_bytelen(y->tlvs->short_channel_id));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -44,26 +44,16 @@ static bool equal(const struct channel_reestablish *x,
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->next_funding, tal_bytelen(x->tlvs->next_funding), if (!tal_arr_eq(x->tlvs->next_funding, y->tlvs->next_funding))
y->tlvs->next_funding, tal_bytelen(y->tlvs->next_funding)))
return false; return false;
if (!memeq(x->tlvs->next_to_send, tal_bytelen(x->tlvs->next_to_send), if (!tal_arr_eq(x->tlvs->next_to_send, y->tlvs->next_to_send))
y->tlvs->next_to_send, tal_bytelen(y->tlvs->next_to_send)))
return false; return false;
if (!memeq(x->tlvs->desired_channel_type, if (!tal_arr_eq(x->tlvs->desired_channel_type, y->tlvs->desired_channel_type))
tal_bytelen(x->tlvs->desired_channel_type),
y->tlvs->desired_channel_type,
tal_bytelen(y->tlvs->desired_channel_type)))
return false; return false;
if (!memeq(x->tlvs->current_channel_type, if (!tal_arr_eq(x->tlvs->current_channel_type, y->tlvs->current_channel_type))
tal_bytelen(x->tlvs->current_channel_type),
y->tlvs->current_channel_type,
tal_bytelen(y->tlvs->current_channel_type)))
return false; return false;
return memeq(x->tlvs->upgradable_channel_type, return tal_arr_eq(x->tlvs->upgradable_channel_type,
tal_bytelen(x->tlvs->upgradable_channel_type), y->tlvs->upgradable_channel_type);
y->tlvs->upgradable_channel_type,
tal_bytelen(y->tlvs->upgradable_channel_type));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -37,8 +37,7 @@ static bool equal(const struct closing_signed *x,
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
return memeq(x->tlvs->fee_range, tal_bytelen(x->tlvs->fee_range), return tal_arr_eq(x->tlvs->fee_range, y->tlvs->fee_range);
y->tlvs->fee_range, tal_bytelen(y->tlvs->fee_range));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -36,13 +36,11 @@ static bool equal(struct commitment_signed *x, struct commitment_signed *y)
if (memcmp(x, y, upto_htlc_signature) != 0) if (memcmp(x, y, upto_htlc_signature) != 0)
return false; return false;
if (!memeq(x->htlc_signature, tal_bytelen(x->htlc_signature), if (!tal_arr_eq(x->htlc_signature, y->htlc_signature))
y->htlc_signature, tal_bytelen(y->htlc_signature)))
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
return memeq(x->tlvs->splice_info, tal_bytelen(x->tlvs->splice_info), return tal_arr_eq(x->tlvs->splice_info, y->tlvs->splice_info);
y->tlvs->splice_info, tal_bytelen(y->tlvs->splice_info));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -28,8 +28,7 @@ static bool equal(const struct error *x, const struct error *y)
{ {
if (!channel_id_eq(&x->channel_id, &y->channel_id)) if (!channel_id_eq(&x->channel_id, &y->channel_id))
return false; return false;
return memeq(x->data, tal_bytelen(x->data), y->data, return tal_arr_eq(x->data, y->data);
tal_bytelen(y->data));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -27,21 +27,17 @@ static struct init *decode(const tal_t *ctx, const void *p)
static bool equal(const struct init *x, const struct init *y) static bool equal(const struct init *x, const struct init *y)
{ {
if (!memeq(x->globalfeatures, tal_bytelen(x->globalfeatures), if (!tal_arr_eq(x->globalfeatures, y->globalfeatures))
y->globalfeatures, tal_bytelen(y->globalfeatures)))
return false; return false;
if (!memeq(x->features, tal_bytelen(x->features), y->features, if (!tal_arr_eq(x->features, y->features))
tal_bytelen(y->features)))
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->networks, tal_bytelen(x->tlvs->networks), if (!tal_arr_eq(x->tlvs->networks, y->tlvs->networks))
y->tlvs->networks, tal_bytelen(y->tlvs->networks)))
return false; return false;
return memeq(x->tlvs->remote_addr, tal_bytelen(x->tlvs->remote_addr), return tal_arr_eq(x->tlvs->remote_addr, y->tlvs->remote_addr);
y->tlvs->remote_addr, tal_bytelen(y->tlvs->remote_addr));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -56,8 +56,7 @@ static bool equal(const struct node_announcement *x,
{ {
if (memcmp(&x->signature, &y->signature, sizeof(x->signature)) != 0) if (memcmp(&x->signature, &y->signature, sizeof(x->signature)) != 0)
return false; return false;
if (!memeq(x->features, tal_bytelen(x->features), y->features, if (!tal_arr_eq(x->features, y->features))
tal_bytelen(y->features)))
return false; return false;
if (x->timestamp != y->timestamp) if (x->timestamp != y->timestamp)
return false; return false;
@ -67,8 +66,7 @@ static bool equal(const struct node_announcement *x,
return false; return false;
if (memcmp(x->alias, y->alias, sizeof(x->alias)) != 0) if (memcmp(x->alias, y->alias, sizeof(x->alias)) != 0)
return false; return false;
if (!memeq(x->addresses, tal_bytelen(x->addresses), y->addresses, if (!tal_arr_eq(x->addresses, y->addresses))
tal_bytelen(y->addresses)))
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);

View File

@ -27,8 +27,7 @@ static bool equal(const struct onion_message *x, const struct onion_message *y)
{ {
if (memcmp(&x->blinding, &y->blinding, sizeof(x->blinding)) != 0) if (memcmp(&x->blinding, &y->blinding, sizeof(x->blinding)) != 0)
return false; return false;
return memeq(x->onionmsg, tal_bytelen(x->onionmsg), y->onionmsg, return tal_arr_eq(x->onionmsg, y->onionmsg);
tal_bytelen(y->onionmsg));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -68,14 +68,11 @@ static bool equal(const struct open_channel *x, const struct open_channel *y)
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->upfront_shutdown_script, if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
tal_bytelen(x->tlvs->upfront_shutdown_script), y->tlvs->upfront_shutdown_script))
y->tlvs->upfront_shutdown_script,
tal_bytelen(y->tlvs->upfront_shutdown_script)))
return false; return false;
return memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type), return tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type);
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -82,14 +82,11 @@ static bool equal(const struct open_channel2 *x, const struct open_channel2 *y)
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->upfront_shutdown_script, if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
tal_bytelen(x->tlvs->upfront_shutdown_script), y->tlvs->upfront_shutdown_script))
y->tlvs->upfront_shutdown_script,
tal_bytelen(y->tlvs->upfront_shutdown_script)))
return false; return false;
if (!memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type), if (!tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type))
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type)))
return false; return false;
if (!request_funds_equal(x->tlvs->request_funds, if (!request_funds_equal(x->tlvs->request_funds,

View File

@ -24,8 +24,7 @@ static struct peer_storage *decode(const tal_t *ctx, const void *p)
static bool equal(const struct peer_storage *x, const struct peer_storage *y) static bool equal(const struct peer_storage *x, const struct peer_storage *y)
{ {
return memeq(x->blob, tal_bytelen(x->blob), y->blob, return tal_arr_eq(x->blob, y->blob);
tal_bytelen(y->blob));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -27,8 +27,7 @@ static bool equal(const struct ping *x, const struct ping *y)
{ {
if (x->num_pong_bytes != y->num_pong_bytes) if (x->num_pong_bytes != y->num_pong_bytes)
return false; return false;
return memeq(x->ignored, tal_bytelen(x->ignored), y->ignored, return tal_arr_eq(x->ignored, y->ignored);
tal_bytelen(y->ignored));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -24,8 +24,7 @@ static struct pong *decode(const tal_t *ctx, const void *p)
static bool equal(const struct pong *x, const struct pong *y) static bool equal(const struct pong *x, const struct pong *y)
{ {
return memeq(x->ignored, tal_bytelen(x->ignored), y->ignored, return tal_arr_eq(x->ignored, y->ignored);
tal_bytelen(y->ignored));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -38,8 +38,7 @@ static bool equal(const struct query_channel_range *x,
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
return memeq(x->tlvs->query_option, tal_bytelen(x->tlvs->query_option), return tal_arr_eq(x->tlvs->query_option, y->tlvs->query_option);
y->tlvs->query_option, tal_bytelen(y->tlvs->query_option));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -38,9 +38,7 @@ query_flags_equal(const struct tlv_query_short_channel_ids_tlvs_query_flags *x,
return false; return false;
if (x->encoding_type != y->encoding_type) if (x->encoding_type != y->encoding_type)
return false; return false;
return memeq( return tal_arr_eq(x->encoded_query_flags, y->encoded_query_flags);
x->encoded_query_flags, tal_bytelen(x->encoded_query_flags),
y->encoded_query_flags, tal_bytelen(y->encoded_query_flags));
} }
static bool equal(const struct query_short_channel_ids *x, static bool equal(const struct query_short_channel_ids *x,
@ -49,8 +47,7 @@ static bool equal(const struct query_short_channel_ids *x,
if (memcmp(&x->chain_hash, &y->chain_hash, sizeof(x->chain_hash)) != 0) if (memcmp(&x->chain_hash, &y->chain_hash, sizeof(x->chain_hash)) != 0)
return false; return false;
if (!memeq(x->encoded_short_ids, tal_bytelen(x->encoded_short_ids), if (!tal_arr_eq(x->encoded_short_ids, y->encoded_short_ids))
y->encoded_short_ids, tal_bytelen(y->encoded_short_ids)))
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);

View File

@ -43,8 +43,7 @@ static bool timestamps_tlv_equal(
return false; return false;
if (x->encoding_type != y->encoding_type) if (x->encoding_type != y->encoding_type)
return false; return false;
return memeq(x->encoded_timestamps, tal_bytelen(x->encoded_timestamps), return tal_arr_eq(x->encoded_timestamps, y->encoded_timestamps);
y->encoded_timestamps, tal_bytelen(y->encoded_timestamps));
} }
static bool equal(const struct reply_channel_range *x, static bool equal(const struct reply_channel_range *x,
@ -56,8 +55,7 @@ static bool equal(const struct reply_channel_range *x,
if (x->sync_complete != y->sync_complete) if (x->sync_complete != y->sync_complete)
return false; return false;
if (!memeq(x->encoded_short_ids, tal_bytelen(x->encoded_short_ids), if (!tal_arr_eq(x->encoded_short_ids, y->encoded_short_ids))
y->encoded_short_ids, tal_bytelen(y->encoded_short_ids)))
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
@ -66,9 +64,7 @@ static bool equal(const struct reply_channel_range *x,
y->tlvs->timestamps_tlv)) y->tlvs->timestamps_tlv))
return false; return false;
return memeq( return tal_arr_eq(x->tlvs->checksums_tlv, y->tlvs->checksums_tlv);
x->tlvs->checksums_tlv, tal_bytelen(x->tlvs->checksums_tlv),
y->tlvs->checksums_tlv, tal_bytelen(y->tlvs->checksums_tlv));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -41,8 +41,7 @@ static bool equal(const struct shutdown *x, const struct shutdown *y)
{ {
if (!channel_id_eq(&x->channel_id, &y->channel_id)) if (!channel_id_eq(&x->channel_id, &y->channel_id))
return false; return false;
if (!memeq(x->scriptpubkey, tal_bytelen(x->scriptpubkey), if (!tal_arr_eq(x->scriptpubkey, y->scriptpubkey))
y->scriptpubkey, tal_bytelen(y->scriptpubkey)))
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);

View File

@ -28,8 +28,7 @@ static bool equal(const struct tx_abort *x, const struct tx_abort *y)
{ {
if (!channel_id_eq(&x->channel_id, &y->channel_id)) if (!channel_id_eq(&x->channel_id, &y->channel_id))
return false; return false;
return memeq(x->data, tal_bytelen(x->data), y->data, return tal_arr_eq(x->data, y->data);
tal_bytelen(y->data));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -31,10 +31,8 @@ static bool equal(const struct tx_ack_rbf *x, const struct tx_ack_rbf *y)
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->funding_output_contribution, if (!tal_arr_eq(x->tlvs->funding_output_contribution,
tal_bytelen(x->tlvs->funding_output_contribution), y->tlvs->funding_output_contribution))
y->tlvs->funding_output_contribution,
tal_bytelen(y->tlvs->funding_output_contribution)))
return false; return false;
return !!x->tlvs->require_confirmed_inputs == return !!x->tlvs->require_confirmed_inputs ==

View File

@ -35,8 +35,7 @@ static bool equal(const struct tx_add_input *x, const struct tx_add_input *y)
if (memcmp(x, y, upto_prevtx) != 0) if (memcmp(x, y, upto_prevtx) != 0)
return false; return false;
return memeq(x->prevtx, tal_bytelen(x->prevtx), y->prevtx, return tal_arr_eq(x->prevtx, y->prevtx);
tal_bytelen(y->prevtx));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -34,8 +34,7 @@ static bool equal(const struct tx_add_output *x, const struct tx_add_output *y)
if (memcmp(x, y, upto_script) != 0) if (memcmp(x, y, upto_script) != 0)
return false; return false;
return memeq(x->script, tal_bytelen(x->script), y->script, return tal_arr_eq(x->script, y->script);
tal_bytelen(y->script));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -36,10 +36,8 @@ static bool equal(const struct tx_init_rbf *x, const struct tx_init_rbf *y)
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
if (!memeq(x->tlvs->funding_output_contribution, if (!tal_arr_eq(x->tlvs->funding_output_contribution,
tal_bytelen(x->tlvs->funding_output_contribution), y->tlvs->funding_output_contribution))
y->tlvs->funding_output_contribution,
tal_bytelen(y->tlvs->funding_output_contribution)))
return false; return false;
return !!x->tlvs->require_confirmed_inputs == return !!x->tlvs->require_confirmed_inputs ==

View File

@ -42,8 +42,7 @@ static bool witnesses_equal(struct witness **x, struct witness **y)
for (size_t i = 0; i < tal_count(x); ++i) { for (size_t i = 0; i < tal_count(x); ++i) {
assert(x[i] && y[i]); assert(x[i] && y[i]);
if (!memeq(x[i]->witness_data, tal_bytelen(x[i]->witness_data), if (!tal_arr_eq(x[i]->witness_data, y[i]->witness_data))
y[i]->witness_data, tal_bytelen(y[i]->witness_data)))
return false; return false;
} }
return true; return true;
@ -59,10 +58,8 @@ static bool equal(const struct tx_signatures *x, const struct tx_signatures *y)
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
return memeq(x->tlvs->funding_outpoint_sig, return tal_arr_eq(x->tlvs->funding_outpoint_sig,
tal_bytelen(x->tlvs->funding_outpoint_sig), y->tlvs->funding_outpoint_sig);
y->tlvs->funding_outpoint_sig,
tal_bytelen(y->tlvs->funding_outpoint_sig));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -47,9 +47,7 @@ static bool equal(const struct update_add_htlc *x,
return false; return false;
assert(x->tlvs && y->tlvs); assert(x->tlvs && y->tlvs);
return memeq( return tal_arr_eq(x->tlvs->blinding_point, y->tlvs->blinding_point);
x->tlvs->blinding_point, tal_bytelen(x->tlvs->blinding_point),
y->tlvs->blinding_point, tal_bytelen(y->tlvs->blinding_point));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -32,8 +32,7 @@ static bool equal(const struct update_fail_htlc *x,
if (memcmp(x, y, upto_reason) != 0) if (memcmp(x, y, upto_reason) != 0)
return false; return false;
return memeq(x->reason, tal_bytelen(x->reason), y->reason, return tal_arr_eq(x->reason, y->reason);
tal_bytelen(y->reason));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -28,8 +28,7 @@ static bool equal(const struct warning *x, const struct warning *y)
{ {
if (!channel_id_eq(&x->channel_id, &y->channel_id)) if (!channel_id_eq(&x->channel_id, &y->channel_id))
return false; return false;
return memeq(x->data, tal_bytelen(x->data), y->data, return tal_arr_eq(x->data, y->data);
tal_bytelen(y->data));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -25,8 +25,7 @@ static struct your_peer_storage *decode(const tal_t *ctx, const void *p)
static bool equal(const struct your_peer_storage *x, static bool equal(const struct your_peer_storage *x,
const struct your_peer_storage *y) const struct your_peer_storage *y)
{ {
return memeq(x->blob, tal_bytelen(x->blob), y->blob, return tal_arr_eq(x->blob, y->blob);
tal_bytelen(y->blob));
} }
void run(const u8 *data, size_t size) void run(const u8 *data, size_t size)

View File

@ -296,9 +296,7 @@ struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
/* Make sure we've got the right info! */ /* Make sure we've got the right info! */
if (utxos[i]->scriptPubkey) if (utxos[i]->scriptPubkey)
assert(memeq(utxos[i]->scriptPubkey, assert(tal_arr_eq(utxos[i]->scriptPubkey, scriptPubkey));
tal_bytelen(utxos[i]->scriptPubkey),
scriptPubkey, tal_bytelen(scriptPubkey)));
} else { } else {
scriptSig = NULL; scriptSig = NULL;
redeemscript = NULL; redeemscript = NULL;

View File

@ -1579,7 +1579,7 @@ static bool bitcoin_tx_eq(const struct bitcoin_tx *tx1,
bool eq; bool eq;
lin1 = linearize_tx(NULL, tx1); lin1 = linearize_tx(NULL, tx1);
lin2 = linearize_tx(lin1, tx2); lin2 = linearize_tx(lin1, tx2);
eq = memeq(lin1, tal_count(lin1), lin2, tal_count(lin2)); eq = tal_arr_eq(lin1, lin2);
tal_free(lin1); tal_free(lin1);
return eq; return eq;
} }
@ -1628,11 +1628,9 @@ static bool channelseq(struct channel *c1, struct channel *c2)
CHECK((c1->scid == NULL && c2->scid == NULL) CHECK((c1->scid == NULL && c2->scid == NULL)
|| short_channel_id_eq(c1->scid, c2->scid)); || short_channel_id_eq(c1->scid, c2->scid));
CHECK(amount_msat_eq(c1->our_msat, c2->our_msat)); CHECK(amount_msat_eq(c1->our_msat, c2->our_msat));
CHECK((c1->shutdown_scriptpubkey[REMOTE] == NULL && c2->shutdown_scriptpubkey[REMOTE] == NULL) || memeq( CHECK((c1->shutdown_scriptpubkey[REMOTE] == NULL && c2->shutdown_scriptpubkey[REMOTE] == NULL) || tal_arr_eq(
c1->shutdown_scriptpubkey[REMOTE], c1->shutdown_scriptpubkey[REMOTE],
tal_count(c1->shutdown_scriptpubkey[REMOTE]), c2->shutdown_scriptpubkey[REMOTE]));
c2->shutdown_scriptpubkey[REMOTE],
tal_count(c2->shutdown_scriptpubkey[REMOTE])));
CHECK(bitcoin_outpoint_eq(&c1->funding, &c2->funding)); CHECK(bitcoin_outpoint_eq(&c1->funding, &c2->funding));
CHECK(pubkey_eq(&ci1->remote_fundingkey, &ci2->remote_fundingkey)); CHECK(pubkey_eq(&ci1->remote_fundingkey, &ci2->remote_fundingkey));
CHECK(pubkey_eq(&ci1->theirbase.revocation, &ci2->theirbase.revocation)); CHECK(pubkey_eq(&ci1->theirbase.revocation, &ci2->theirbase.revocation));
@ -1669,10 +1667,8 @@ static bool channelseq(struct channel *c1, struct channel *c2)
&c2->last_sig, sizeof(c2->last_sig))); &c2->last_sig, sizeof(c2->last_sig)));
CHECK(c1->final_key_idx == c2->final_key_idx); CHECK(c1->final_key_idx == c2->final_key_idx);
CHECK(memeq(c1->shutdown_scriptpubkey[REMOTE], CHECK(tal_arr_eq(c1->shutdown_scriptpubkey[REMOTE],
tal_count(c1->shutdown_scriptpubkey[REMOTE]), c2->shutdown_scriptpubkey[REMOTE]));
c2->shutdown_scriptpubkey[REMOTE],
tal_count(c2->shutdown_scriptpubkey[REMOTE])));
CHECK(c1->last_was_revoke == c2->last_was_revoke); CHECK(c1->last_was_revoke == c2->last_was_revoke);

View File

@ -20,9 +20,9 @@ static const u8 *scriptpubkey_keyof(const u8 *out)
return out; return out;
} }
static int scriptpubkey_eq(const u8 *a, const u8 *b) static bool scriptpubkey_eq(const u8 *a, const u8 *b)
{ {
return memeq(a, tal_bytelen(a), b, tal_bytelen(b)); return tal_arr_eq(a, b);
} }
HTABLE_DEFINE_TYPE(u8, scriptpubkey_keyof, scriptpubkey_hash, scriptpubkey_eq, scriptpubkeyset); HTABLE_DEFINE_TYPE(u8, scriptpubkey_keyof, scriptpubkey_hash, scriptpubkey_eq, scriptpubkeyset);

View File

@ -831,11 +831,6 @@ static bool tlv_networks_eq(const struct bitcoin_blkid *a,
return true; return true;
} }
static bool talarr_eq(const void *a, const void *b)
{
return memeq(a, tal_bytelen(a), b, tal_bytelen(b));
}
static bool init_eq(const struct msg_init *a, static bool init_eq(const struct msg_init *a,
const struct msg_init *b) const struct msg_init *b)
{ {
@ -843,7 +838,7 @@ static bool init_eq(const struct msg_init *a,
return false; return false;
return eq_tlv(a, b, networks, tlv_networks_eq) return eq_tlv(a, b, networks, tlv_networks_eq)
&& eq_tlv(a, b, remote_addr, talarr_eq); && eq_tlv(a, b, remote_addr, tal_arr_eq);
} }
static bool update_fee_eq(const struct msg_update_fee *a, static bool update_fee_eq(const struct msg_update_fee *a,

View File

@ -534,7 +534,7 @@ int main(int argc, char *argv[])
p2 = tal_arr(tmpctx, u8, 0); p2 = tal_arr(tmpctx, u8, 0);
towire_tlv_n1(&p2, tlv_n1); towire_tlv_n1(&p2, tlv_n1);
assert(memeq(p2, tal_count(p2), orig_p, tal_count(orig_p))); assert(tal_arr_eq(p2, orig_p));
} }
/* BOLT #1: /* BOLT #1:
@ -632,8 +632,7 @@ int main(int argc, char *argv[])
u8 *p2 = tal_arr(tmpctx, u8, 0); u8 *p2 = tal_arr(tmpctx, u8, 0);
towire_tlv_n1(&p2, tlv_n1); towire_tlv_n1(&p2, tlv_n1);
assert(memeq(orig_p, tal_count(orig_p), assert(tal_arr_eq(orig_p, p2));
p2, tal_count(p2)));
} }
} }
common_shutdown(); common_shutdown();