Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix close fail retry #7072

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions common/psbt_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions common/test/run-bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion common/test/run-cryptomsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions common/test/run-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,15 @@ 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,
const struct feature_set *f2)
{
/* 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;
Expand Down
5 changes: 2 additions & 3 deletions common/test/run-onion-test-vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions common/test/run-route_blinding_onion_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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! */
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions common/test/run-route_blinding_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion common/test/run-sphinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions common/utils.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
3 changes: 1 addition & 2 deletions devtools/checkchannels.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions devtools/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions gossipd/gossmap_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down