mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
psbt: sort maps before serializing, to stabilize comparison
Our psbt input/output comparison functions use serialization to compare the things, but if there's a map with things in it and the map isn't sorted exactly the same, it's highly likely you'll mark an identical inputs as different. To fix this, we sort all the input/output maps before linearizing them.
This commit is contained in:
@@ -68,9 +68,12 @@ static const u8 *linearize_input(const tal_t *ctx,
|
||||
abort();
|
||||
psbt->inputs[0] = *in;
|
||||
psbt->num_inputs++;
|
||||
/* Blank out unknowns. These are unordered and serializing
|
||||
* them might have different outputs for identical data */
|
||||
psbt->inputs[0].unknowns.num_items = 0;
|
||||
|
||||
|
||||
/* Sort the inputs, so serializing them is ok */
|
||||
wally_map_sort(&psbt->inputs[0].unknowns, 0);
|
||||
wally_map_sort(&psbt->inputs[0].keypaths, 0);
|
||||
wally_map_sort(&psbt->inputs[0].signatures, 0);
|
||||
|
||||
const u8 *bytes = psbt_get_bytes(ctx, psbt, &byte_len);
|
||||
|
||||
@@ -97,9 +100,9 @@ static const u8 *linearize_output(const tal_t *ctx,
|
||||
|
||||
psbt->outputs[0] = *out;
|
||||
psbt->num_outputs++;
|
||||
/* Blank out unknowns. These are unordered and serializing
|
||||
* them might have different outputs for identical data */
|
||||
psbt->outputs[0].unknowns.num_items = 0;
|
||||
/* Sort the outputs, so serializing them is ok */
|
||||
wally_map_sort(&psbt->outputs[0].unknowns, 0);
|
||||
wally_map_sort(&psbt->outputs[0].keypaths, 0);
|
||||
|
||||
const u8 *bytes = psbt_get_bytes(ctx, psbt, &byte_len);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user