mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
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:
parent
b6cc0ce425
commit
df44431f8c
@ -133,8 +133,7 @@ static bool input_identical(const struct wally_psbt *a,
|
||||
const u8 *b_in = linearize_input(tmpctx,
|
||||
&b->inputs[b_index]);
|
||||
|
||||
return memeq(a_in, tal_bytelen(a_in),
|
||||
b_in, tal_bytelen(b_in));
|
||||
return tal_arr_eq(a_in, b_in);
|
||||
}
|
||||
|
||||
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]);
|
||||
const u8 *b_out = linearize_output(tmpctx,
|
||||
&b->outputs[b_index]);
|
||||
return memeq(a_out, tal_bytelen(a_out),
|
||||
b_out, tal_bytelen(b_out));
|
||||
return tal_arr_eq(a_out, b_out);
|
||||
}
|
||||
|
||||
static void sort_inputs(struct wally_psbt *psbt)
|
||||
|
@ -106,8 +106,7 @@ static void test_b11(const char *b11str,
|
||||
list);
|
||||
list_for_each(&b11->extra_fields, b11_extra, list) {
|
||||
assert(expect_extra->tag == b11_extra->tag);
|
||||
assert(memeq(expect_extra->data, tal_bytelen(expect_extra->data),
|
||||
b11_extra->data, tal_bytelen(b11_extra->data)));
|
||||
assert(tal_arr_eq(expect_extra->data, b11_extra->data));
|
||||
expect_extra = list_next(&expect_b11->extra_fields,
|
||||
expect_extra, list);
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ int main(int argc, char *argv[])
|
||||
tal_resize(&enc, tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE);
|
||||
|
||||
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();
|
||||
return 0;
|
||||
|
@ -120,8 +120,7 @@ static void test_featurebits_or(void)
|
||||
set_feature_bit(&control, i);
|
||||
}
|
||||
u8 *result = featurebits_or(tmpctx, take(f1), f2);
|
||||
assert(
|
||||
memeq(result, tal_bytelen(result), control, tal_bytelen(control)));
|
||||
assert(tal_arr_eq(result, control));
|
||||
}
|
||||
|
||||
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 */
|
||||
for (size_t i = 0; i < ARRAY_SIZE(f1->bits); i++) {
|
||||
if (!memeq(f1->bits[i], tal_bytelen(f1->bits[i]),
|
||||
f2->bits[i], tal_bytelen(f2->bits[i])))
|
||||
if (!tal_arr_eq(f1->bits[i], f2->bits[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -176,7 +176,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
expected = json_tok_bin_from_hex(tmpctx, json, json_get_member(json, toks, "onion"));
|
||||
actual = serialize_onionpacket(tmpctx, op);
|
||||
assert(memeq(expected, tal_bytelen(expected), actual, tal_bytelen(actual)));
|
||||
assert(tal_arr_eq(expected, actual));
|
||||
|
||||
/* Now decode! */
|
||||
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);
|
||||
test_ecdh(&op->ephemeralkey, &ss);
|
||||
rs = process_onionpacket(tmpctx, op, &ss, assoc_data, tal_bytelen(assoc_data), true);
|
||||
assert(memeq(rs->raw_payload, tal_bytelen(rs->raw_payload),
|
||||
payloads[i], tal_bytelen(payloads[i])));
|
||||
assert(tal_arr_eq(rs->raw_payload, payloads[i]));
|
||||
if (rs->nextcase == ONION_FORWARD)
|
||||
op = rs->next;
|
||||
else
|
||||
|
@ -158,8 +158,7 @@ int main(int argc, char *argv[])
|
||||
json_tok_bin_from_hex,
|
||||
&payload),
|
||||
JSON_SCAN(json_to_pubkey, &ids[i])) == NULL);
|
||||
assert(memeq(payload, tal_bytelen(payload),
|
||||
onionhops[i], tal_bytelen(onionhops[i])));
|
||||
assert(tal_arr_eq(payload, onionhops[i]));
|
||||
}
|
||||
|
||||
/* Now, create onion! */
|
||||
@ -174,8 +173,7 @@ int main(int argc, char *argv[])
|
||||
JSON_SCAN_TAL(tmpctx,
|
||||
json_tok_bin_from_hex,
|
||||
&expected_onion)) == NULL);
|
||||
assert(memeq(expected_onion, tal_bytelen(expected_onion),
|
||||
onion, tal_bytelen(onion)));
|
||||
assert(tal_arr_eq(expected_onion, onion));
|
||||
|
||||
/* FIXME: unwrap and test! */
|
||||
#if 0
|
||||
@ -196,8 +194,7 @@ int main(int argc, char *argv[])
|
||||
JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &expected_onion))
|
||||
== NULL);
|
||||
serialized = serialize_onionpacket(tmpctx, op);
|
||||
assert(memeq(expected_onion, tal_bytelen(expected_onion),
|
||||
serialized, tal_bytelen(serialized)));
|
||||
assert(tal_arr_eq(expected_onion, serialized));
|
||||
|
||||
if (blinding) {
|
||||
assert(unblind_onion(blinding, test_ecdh,
|
||||
@ -207,8 +204,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
rs = process_onionpacket(tmpctx, op, &ss, associated_data,
|
||||
tal_bytelen(associated_data), true);
|
||||
assert(memeq(rs->raw_payload, tal_bytelen(rs->raw_payload),
|
||||
onionhops[i], tal_bytelen(onionhops[i])));
|
||||
assert(tal_arr_eq(rs->raw_payload, onionhops[i]));
|
||||
if (rs->nextcase == ONION_FORWARD)
|
||||
op = rs->next;
|
||||
else
|
||||
|
@ -183,8 +183,7 @@ int main(int argc, char *argv[])
|
||||
json_get_member(json, t, "encoded_tlvs"));
|
||||
expected = json_to_enctlvs(tmpctx, json,
|
||||
json_get_member(json, t, "tlvs"));
|
||||
assert(memeq(expected, tal_bytelen(expected),
|
||||
enctlvs[i], tal_bytelen(enctlvs[i])));
|
||||
assert(tal_arr_eq(expected, enctlvs[i]));
|
||||
}
|
||||
|
||||
/* Now do the blinding. */
|
||||
@ -221,8 +220,7 @@ int main(int argc, char *argv[])
|
||||
expected_enctlv = json_tok_bin_from_hex(tmpctx,json,
|
||||
json_get_member(json, t,
|
||||
"encrypted_data"));
|
||||
assert(memeq(enctlv, tal_bytelen(enctlv),
|
||||
expected_enctlv, tal_bytelen(expected_enctlv)));
|
||||
assert(tal_arr_eq(enctlv, expected_enctlv));
|
||||
|
||||
json_to_pubkey(json, json_get_member(json, t, "blinded_node_id"),
|
||||
&expected_alias);
|
||||
|
@ -219,7 +219,7 @@ static void run_unit_tests(void)
|
||||
|
||||
oreply = unwrap_onionreply(tmpctx, ss, 5, reply, &origin_index);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
#include <bitcoin/chainparams.h>
|
||||
#include <ccan/list/list.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/tal/path/path.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;
|
||||
}
|
||||
|
||||
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. */
|
||||
void setup_locale(void)
|
||||
{
|
||||
|
@ -62,6 +62,12 @@ u8 *tal_hexdata(const tal_t *ctx, const void *str, size_t len);
|
||||
(*(p))[n_] = (s); \
|
||||
} 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
|
||||
*
|
||||
|
@ -205,8 +205,7 @@ int main(int argc, char *argv[])
|
||||
wscript = bitcoin_redeem_2of2(ctx, &local_fundingkey, &remote_fundingkey);
|
||||
expect_scriptpubkey = scriptpubkey_p2wsh(ctx, wscript);
|
||||
|
||||
if (!memeq(expect_scriptpubkey, tal_bytelen(expect_scriptpubkey),
|
||||
scriptpubkey, tal_bytelen(scriptpubkey))) {
|
||||
if (!tal_arr_eq(expect_scriptpubkey, scriptpubkey)) {
|
||||
printf("*** FATAL *** outscript %s should be %s\n",
|
||||
tal_hex(ctx, scriptpubkey),
|
||||
tal_hex(ctx, expect_scriptpubkey));
|
||||
|
@ -241,8 +241,7 @@ static void runtest(const char *filename)
|
||||
|
||||
if (oniontok) {
|
||||
onion = json_tok_bin_from_hex(ctx, buffer, oniontok);
|
||||
if (!memeq(onion, tal_bytelen(onion), serialized,
|
||||
tal_bytelen(serialized)))
|
||||
if (!tal_arr_eq(onion, serialized))
|
||||
errx(1,
|
||||
"Generated does not match the expected onion: \n"
|
||||
"generated: %s\n"
|
||||
|
@ -642,8 +642,7 @@ void gossmap_manage_handle_get_txout_reply(struct gossmap_manage *gm, const u8 *
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!memeq(outscript, tal_bytelen(outscript),
|
||||
pca->scriptpubkey, tal_bytelen(pca->scriptpubkey))) {
|
||||
if (!tal_arr_eq(outscript, pca->scriptpubkey)) {
|
||||
peer_warning(gm, pca->source_peer,
|
||||
"channel_announcement: txout %s expected %s, got %s",
|
||||
short_channel_id_to_str(tmpctx, &scid),
|
||||
|
@ -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));
|
||||
|
||||
if (tal_count(state->upfront_shutdown_script[REMOTE])
|
||||
&& !memeq(scriptpubkey, tal_count(scriptpubkey),
|
||||
state->upfront_shutdown_script[REMOTE],
|
||||
tal_count(state->upfront_shutdown_script[REMOTE])))
|
||||
&& !tal_arr_eq(scriptpubkey, state->upfront_shutdown_script[REMOTE]))
|
||||
open_err_fatal(state,
|
||||
"scriptpubkey %s is not as agreed upfront (%s)",
|
||||
tal_hex(state, scriptpubkey),
|
||||
|
@ -75,7 +75,7 @@ static void test_encrypt_decrypt_equality(const u8 *msg)
|
||||
tal_resize(&enc, tal_bytelen(enc) - CRYPTOMSG_HDR_SIZE);
|
||||
|
||||
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). */
|
||||
|
@ -60,14 +60,11 @@ static bool equal(const struct accept_channel *x,
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
||||
if (!memeq(x->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(x->tlvs->upfront_shutdown_script),
|
||||
y->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(y->tlvs->upfront_shutdown_script)))
|
||||
if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
|
||||
y->tlvs->upfront_shutdown_script))
|
||||
return false;
|
||||
|
||||
return memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type),
|
||||
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type));
|
||||
return tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -86,14 +86,11 @@ static bool equal(const struct accept_channel2 *x,
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
||||
if (!memeq(x->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(x->tlvs->upfront_shutdown_script),
|
||||
y->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(y->tlvs->upfront_shutdown_script)))
|
||||
if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
|
||||
y->tlvs->upfront_shutdown_script))
|
||||
return false;
|
||||
|
||||
if (!memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type),
|
||||
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type)))
|
||||
if (!tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type))
|
||||
return false;
|
||||
|
||||
if (!!x->tlvs->require_confirmed_inputs !=
|
||||
|
@ -53,8 +53,7 @@ static bool equal(const struct channel_announcement *x,
|
||||
if (!node_id_eq(&x->node_id_2, &y->node_id_2))
|
||||
return false;
|
||||
|
||||
return memeq(x->features, tal_bytelen(x->features), y->features,
|
||||
tal_bytelen(y->features));
|
||||
return tal_arr_eq(x->features, y->features);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -35,9 +35,7 @@ static bool equal(const struct channel_ready *x, const struct channel_ready *y)
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
return memeq(
|
||||
x->tlvs->short_channel_id, tal_bytelen(x->tlvs->short_channel_id),
|
||||
y->tlvs->short_channel_id, tal_bytelen(y->tlvs->short_channel_id));
|
||||
return tal_arr_eq(x->tlvs->short_channel_id, y->tlvs->short_channel_id);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -44,26 +44,16 @@ static bool equal(const struct channel_reestablish *x,
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
||||
if (!memeq(x->tlvs->next_funding, tal_bytelen(x->tlvs->next_funding),
|
||||
y->tlvs->next_funding, tal_bytelen(y->tlvs->next_funding)))
|
||||
if (!tal_arr_eq(x->tlvs->next_funding, y->tlvs->next_funding))
|
||||
return false;
|
||||
if (!memeq(x->tlvs->next_to_send, tal_bytelen(x->tlvs->next_to_send),
|
||||
y->tlvs->next_to_send, tal_bytelen(y->tlvs->next_to_send)))
|
||||
if (!tal_arr_eq(x->tlvs->next_to_send, y->tlvs->next_to_send))
|
||||
return false;
|
||||
if (!memeq(x->tlvs->desired_channel_type,
|
||||
tal_bytelen(x->tlvs->desired_channel_type),
|
||||
y->tlvs->desired_channel_type,
|
||||
tal_bytelen(y->tlvs->desired_channel_type)))
|
||||
if (!tal_arr_eq(x->tlvs->desired_channel_type, y->tlvs->desired_channel_type))
|
||||
return false;
|
||||
if (!memeq(x->tlvs->current_channel_type,
|
||||
tal_bytelen(x->tlvs->current_channel_type),
|
||||
y->tlvs->current_channel_type,
|
||||
tal_bytelen(y->tlvs->current_channel_type)))
|
||||
if (!tal_arr_eq(x->tlvs->current_channel_type, y->tlvs->current_channel_type))
|
||||
return false;
|
||||
return memeq(x->tlvs->upgradable_channel_type,
|
||||
tal_bytelen(x->tlvs->upgradable_channel_type),
|
||||
y->tlvs->upgradable_channel_type,
|
||||
tal_bytelen(y->tlvs->upgradable_channel_type));
|
||||
return tal_arr_eq(x->tlvs->upgradable_channel_type,
|
||||
y->tlvs->upgradable_channel_type);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -37,8 +37,7 @@ static bool equal(const struct closing_signed *x,
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
return memeq(x->tlvs->fee_range, tal_bytelen(x->tlvs->fee_range),
|
||||
y->tlvs->fee_range, tal_bytelen(y->tlvs->fee_range));
|
||||
return tal_arr_eq(x->tlvs->fee_range, y->tlvs->fee_range);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -36,13 +36,11 @@ static bool equal(struct commitment_signed *x, struct commitment_signed *y)
|
||||
if (memcmp(x, y, upto_htlc_signature) != 0)
|
||||
return false;
|
||||
|
||||
if (!memeq(x->htlc_signature, tal_bytelen(x->htlc_signature),
|
||||
y->htlc_signature, tal_bytelen(y->htlc_signature)))
|
||||
if (!tal_arr_eq(x->htlc_signature, y->htlc_signature))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
return memeq(x->tlvs->splice_info, tal_bytelen(x->tlvs->splice_info),
|
||||
y->tlvs->splice_info, tal_bytelen(y->tlvs->splice_info));
|
||||
return tal_arr_eq(x->tlvs->splice_info, y->tlvs->splice_info);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -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))
|
||||
return false;
|
||||
return memeq(x->data, tal_bytelen(x->data), y->data,
|
||||
tal_bytelen(y->data));
|
||||
return tal_arr_eq(x->data, y->data);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -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)
|
||||
{
|
||||
if (!memeq(x->globalfeatures, tal_bytelen(x->globalfeatures),
|
||||
y->globalfeatures, tal_bytelen(y->globalfeatures)))
|
||||
if (!tal_arr_eq(x->globalfeatures, y->globalfeatures))
|
||||
return false;
|
||||
if (!memeq(x->features, tal_bytelen(x->features), y->features,
|
||||
tal_bytelen(y->features)))
|
||||
if (!tal_arr_eq(x->features, y->features))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
||||
if (!memeq(x->tlvs->networks, tal_bytelen(x->tlvs->networks),
|
||||
y->tlvs->networks, tal_bytelen(y->tlvs->networks)))
|
||||
if (!tal_arr_eq(x->tlvs->networks, y->tlvs->networks))
|
||||
return false;
|
||||
|
||||
return memeq(x->tlvs->remote_addr, tal_bytelen(x->tlvs->remote_addr),
|
||||
y->tlvs->remote_addr, tal_bytelen(y->tlvs->remote_addr));
|
||||
return tal_arr_eq(x->tlvs->remote_addr, y->tlvs->remote_addr);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -56,8 +56,7 @@ static bool equal(const struct node_announcement *x,
|
||||
{
|
||||
if (memcmp(&x->signature, &y->signature, sizeof(x->signature)) != 0)
|
||||
return false;
|
||||
if (!memeq(x->features, tal_bytelen(x->features), y->features,
|
||||
tal_bytelen(y->features)))
|
||||
if (!tal_arr_eq(x->features, y->features))
|
||||
return false;
|
||||
if (x->timestamp != y->timestamp)
|
||||
return false;
|
||||
@ -67,8 +66,7 @@ static bool equal(const struct node_announcement *x,
|
||||
return false;
|
||||
if (memcmp(x->alias, y->alias, sizeof(x->alias)) != 0)
|
||||
return false;
|
||||
if (!memeq(x->addresses, tal_bytelen(x->addresses), y->addresses,
|
||||
tal_bytelen(y->addresses)))
|
||||
if (!tal_arr_eq(x->addresses, y->addresses))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
@ -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)
|
||||
return false;
|
||||
return memeq(x->onionmsg, tal_bytelen(x->onionmsg), y->onionmsg,
|
||||
tal_bytelen(y->onionmsg));
|
||||
return tal_arr_eq(x->onionmsg, y->onionmsg);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -68,14 +68,11 @@ static bool equal(const struct open_channel *x, const struct open_channel *y)
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
||||
if (!memeq(x->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(x->tlvs->upfront_shutdown_script),
|
||||
y->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(y->tlvs->upfront_shutdown_script)))
|
||||
if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
|
||||
y->tlvs->upfront_shutdown_script))
|
||||
return false;
|
||||
|
||||
return memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type),
|
||||
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type));
|
||||
return tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -82,14 +82,11 @@ static bool equal(const struct open_channel2 *x, const struct open_channel2 *y)
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
||||
if (!memeq(x->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(x->tlvs->upfront_shutdown_script),
|
||||
y->tlvs->upfront_shutdown_script,
|
||||
tal_bytelen(y->tlvs->upfront_shutdown_script)))
|
||||
if (!tal_arr_eq(x->tlvs->upfront_shutdown_script,
|
||||
y->tlvs->upfront_shutdown_script))
|
||||
return false;
|
||||
|
||||
if (!memeq(x->tlvs->channel_type, tal_bytelen(x->tlvs->channel_type),
|
||||
y->tlvs->channel_type, tal_bytelen(y->tlvs->channel_type)))
|
||||
if (!tal_arr_eq(x->tlvs->channel_type, y->tlvs->channel_type))
|
||||
return false;
|
||||
|
||||
if (!request_funds_equal(x->tlvs->request_funds,
|
||||
|
@ -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)
|
||||
{
|
||||
return memeq(x->blob, tal_bytelen(x->blob), y->blob,
|
||||
tal_bytelen(y->blob));
|
||||
return tal_arr_eq(x->blob, y->blob);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -27,8 +27,7 @@ static bool equal(const struct ping *x, const struct ping *y)
|
||||
{
|
||||
if (x->num_pong_bytes != y->num_pong_bytes)
|
||||
return false;
|
||||
return memeq(x->ignored, tal_bytelen(x->ignored), y->ignored,
|
||||
tal_bytelen(y->ignored));
|
||||
return tal_arr_eq(x->ignored, y->ignored);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -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)
|
||||
{
|
||||
return memeq(x->ignored, tal_bytelen(x->ignored), y->ignored,
|
||||
tal_bytelen(y->ignored));
|
||||
return tal_arr_eq(x->ignored, y->ignored);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -38,8 +38,7 @@ static bool equal(const struct query_channel_range *x,
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
return memeq(x->tlvs->query_option, tal_bytelen(x->tlvs->query_option),
|
||||
y->tlvs->query_option, tal_bytelen(y->tlvs->query_option));
|
||||
return tal_arr_eq(x->tlvs->query_option, y->tlvs->query_option);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -38,9 +38,7 @@ query_flags_equal(const struct tlv_query_short_channel_ids_tlvs_query_flags *x,
|
||||
return false;
|
||||
if (x->encoding_type != y->encoding_type)
|
||||
return false;
|
||||
return memeq(
|
||||
x->encoded_query_flags, tal_bytelen(x->encoded_query_flags),
|
||||
y->encoded_query_flags, tal_bytelen(y->encoded_query_flags));
|
||||
return tal_arr_eq(x->encoded_query_flags, y->encoded_query_flags);
|
||||
}
|
||||
|
||||
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)
|
||||
return false;
|
||||
|
||||
if (!memeq(x->encoded_short_ids, tal_bytelen(x->encoded_short_ids),
|
||||
y->encoded_short_ids, tal_bytelen(y->encoded_short_ids)))
|
||||
if (!tal_arr_eq(x->encoded_short_ids, y->encoded_short_ids))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
@ -43,8 +43,7 @@ static bool timestamps_tlv_equal(
|
||||
return false;
|
||||
if (x->encoding_type != y->encoding_type)
|
||||
return false;
|
||||
return memeq(x->encoded_timestamps, tal_bytelen(x->encoded_timestamps),
|
||||
y->encoded_timestamps, tal_bytelen(y->encoded_timestamps));
|
||||
return tal_arr_eq(x->encoded_timestamps, y->encoded_timestamps);
|
||||
}
|
||||
|
||||
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)
|
||||
return false;
|
||||
|
||||
if (!memeq(x->encoded_short_ids, tal_bytelen(x->encoded_short_ids),
|
||||
y->encoded_short_ids, tal_bytelen(y->encoded_short_ids)))
|
||||
if (!tal_arr_eq(x->encoded_short_ids, y->encoded_short_ids))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
@ -66,9 +64,7 @@ static bool equal(const struct reply_channel_range *x,
|
||||
y->tlvs->timestamps_tlv))
|
||||
return false;
|
||||
|
||||
return memeq(
|
||||
x->tlvs->checksums_tlv, tal_bytelen(x->tlvs->checksums_tlv),
|
||||
y->tlvs->checksums_tlv, tal_bytelen(y->tlvs->checksums_tlv));
|
||||
return tal_arr_eq(x->tlvs->checksums_tlv, y->tlvs->checksums_tlv);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -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))
|
||||
return false;
|
||||
if (!memeq(x->scriptpubkey, tal_bytelen(x->scriptpubkey),
|
||||
y->scriptpubkey, tal_bytelen(y->scriptpubkey)))
|
||||
if (!tal_arr_eq(x->scriptpubkey, y->scriptpubkey))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
|
@ -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))
|
||||
return false;
|
||||
return memeq(x->data, tal_bytelen(x->data), y->data,
|
||||
tal_bytelen(y->data));
|
||||
return tal_arr_eq(x->data, y->data);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -31,10 +31,8 @@ static bool equal(const struct tx_ack_rbf *x, const struct tx_ack_rbf *y)
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
if (!memeq(x->tlvs->funding_output_contribution,
|
||||
tal_bytelen(x->tlvs->funding_output_contribution),
|
||||
y->tlvs->funding_output_contribution,
|
||||
tal_bytelen(y->tlvs->funding_output_contribution)))
|
||||
if (!tal_arr_eq(x->tlvs->funding_output_contribution,
|
||||
y->tlvs->funding_output_contribution))
|
||||
return false;
|
||||
|
||||
return !!x->tlvs->require_confirmed_inputs ==
|
||||
|
@ -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)
|
||||
return false;
|
||||
|
||||
return memeq(x->prevtx, tal_bytelen(x->prevtx), y->prevtx,
|
||||
tal_bytelen(y->prevtx));
|
||||
return tal_arr_eq(x->prevtx, y->prevtx);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -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)
|
||||
return false;
|
||||
|
||||
return memeq(x->script, tal_bytelen(x->script), y->script,
|
||||
tal_bytelen(y->script));
|
||||
return tal_arr_eq(x->script, y->script);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -36,10 +36,8 @@ static bool equal(const struct tx_init_rbf *x, const struct tx_init_rbf *y)
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
if (!memeq(x->tlvs->funding_output_contribution,
|
||||
tal_bytelen(x->tlvs->funding_output_contribution),
|
||||
y->tlvs->funding_output_contribution,
|
||||
tal_bytelen(y->tlvs->funding_output_contribution)))
|
||||
if (!tal_arr_eq(x->tlvs->funding_output_contribution,
|
||||
y->tlvs->funding_output_contribution))
|
||||
return false;
|
||||
|
||||
return !!x->tlvs->require_confirmed_inputs ==
|
||||
|
@ -42,8 +42,7 @@ static bool witnesses_equal(struct witness **x, struct witness **y)
|
||||
|
||||
for (size_t i = 0; i < tal_count(x); ++i) {
|
||||
assert(x[i] && y[i]);
|
||||
if (!memeq(x[i]->witness_data, tal_bytelen(x[i]->witness_data),
|
||||
y[i]->witness_data, tal_bytelen(y[i]->witness_data)))
|
||||
if (!tal_arr_eq(x[i]->witness_data, y[i]->witness_data))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -59,10 +58,8 @@ static bool equal(const struct tx_signatures *x, const struct tx_signatures *y)
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
return memeq(x->tlvs->funding_outpoint_sig,
|
||||
tal_bytelen(x->tlvs->funding_outpoint_sig),
|
||||
y->tlvs->funding_outpoint_sig,
|
||||
tal_bytelen(y->tlvs->funding_outpoint_sig));
|
||||
return tal_arr_eq(x->tlvs->funding_outpoint_sig,
|
||||
y->tlvs->funding_outpoint_sig);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -47,9 +47,7 @@ static bool equal(const struct update_add_htlc *x,
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
return memeq(
|
||||
x->tlvs->blinding_point, tal_bytelen(x->tlvs->blinding_point),
|
||||
y->tlvs->blinding_point, tal_bytelen(y->tlvs->blinding_point));
|
||||
return tal_arr_eq(x->tlvs->blinding_point, y->tlvs->blinding_point);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -32,8 +32,7 @@ static bool equal(const struct update_fail_htlc *x,
|
||||
if (memcmp(x, y, upto_reason) != 0)
|
||||
return false;
|
||||
|
||||
return memeq(x->reason, tal_bytelen(x->reason), y->reason,
|
||||
tal_bytelen(y->reason));
|
||||
return tal_arr_eq(x->reason, y->reason);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -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))
|
||||
return false;
|
||||
return memeq(x->data, tal_bytelen(x->data), y->data,
|
||||
tal_bytelen(y->data));
|
||||
return tal_arr_eq(x->data, y->data);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -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,
|
||||
const struct your_peer_storage *y)
|
||||
{
|
||||
return memeq(x->blob, tal_bytelen(x->blob), y->blob,
|
||||
tal_bytelen(y->blob));
|
||||
return tal_arr_eq(x->blob, y->blob);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
|
@ -296,9 +296,7 @@ struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
|
||||
|
||||
/* Make sure we've got the right info! */
|
||||
if (utxos[i]->scriptPubkey)
|
||||
assert(memeq(utxos[i]->scriptPubkey,
|
||||
tal_bytelen(utxos[i]->scriptPubkey),
|
||||
scriptPubkey, tal_bytelen(scriptPubkey)));
|
||||
assert(tal_arr_eq(utxos[i]->scriptPubkey, scriptPubkey));
|
||||
} else {
|
||||
scriptSig = NULL;
|
||||
redeemscript = NULL;
|
||||
|
@ -1579,7 +1579,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_count(lin1), lin2, tal_count(lin2));
|
||||
eq = tal_arr_eq(lin1, lin2);
|
||||
tal_free(lin1);
|
||||
return eq;
|
||||
}
|
||||
@ -1628,11 +1628,9 @@ static bool channelseq(struct channel *c1, struct channel *c2)
|
||||
CHECK((c1->scid == NULL && c2->scid == NULL)
|
||||
|| short_channel_id_eq(c1->scid, c2->scid));
|
||||
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],
|
||||
tal_count(c1->shutdown_scriptpubkey[REMOTE]),
|
||||
c2->shutdown_scriptpubkey[REMOTE],
|
||||
tal_count(c2->shutdown_scriptpubkey[REMOTE])));
|
||||
c2->shutdown_scriptpubkey[REMOTE]));
|
||||
CHECK(bitcoin_outpoint_eq(&c1->funding, &c2->funding));
|
||||
CHECK(pubkey_eq(&ci1->remote_fundingkey, &ci2->remote_fundingkey));
|
||||
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)));
|
||||
|
||||
CHECK(c1->final_key_idx == c2->final_key_idx);
|
||||
CHECK(memeq(c1->shutdown_scriptpubkey[REMOTE],
|
||||
tal_count(c1->shutdown_scriptpubkey[REMOTE]),
|
||||
c2->shutdown_scriptpubkey[REMOTE],
|
||||
tal_count(c2->shutdown_scriptpubkey[REMOTE])));
|
||||
CHECK(tal_arr_eq(c1->shutdown_scriptpubkey[REMOTE],
|
||||
c2->shutdown_scriptpubkey[REMOTE]));
|
||||
|
||||
CHECK(c1->last_was_revoke == c2->last_was_revoke);
|
||||
|
||||
|
@ -20,9 +20,9 @@ static const u8 *scriptpubkey_keyof(const u8 *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);
|
||||
|
@ -831,11 +831,6 @@ static bool tlv_networks_eq(const struct bitcoin_blkid *a,
|
||||
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,
|
||||
const struct msg_init *b)
|
||||
{
|
||||
@ -843,7 +838,7 @@ static bool init_eq(const struct msg_init *a,
|
||||
return false;
|
||||
|
||||
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,
|
||||
|
@ -534,7 +534,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
p2 = tal_arr(tmpctx, u8, 0);
|
||||
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:
|
||||
@ -632,8 +632,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
u8 *p2 = tal_arr(tmpctx, u8, 0);
|
||||
towire_tlv_n1(&p2, tlv_n1);
|
||||
assert(memeq(orig_p, tal_count(orig_p),
|
||||
p2, tal_count(p2)));
|
||||
assert(tal_arr_eq(orig_p, p2));
|
||||
}
|
||||
}
|
||||
common_shutdown();
|
||||
|
Loading…
Reference in New Issue
Block a user