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

Stable serialization for psbt inputs/outputs #214

Closed
niftynei opened this issue Aug 7, 2020 · 3 comments
Closed

Stable serialization for psbt inputs/outputs #214

niftynei opened this issue Aug 7, 2020 · 3 comments

Comments

@niftynei
Copy link
Contributor

niftynei commented Aug 7, 2020

c-lightning has a requirement that we can identify modified PSBT entries (inputs + outputs). The comparison function we're using currently uses a linearized form of the PSBT to do a comparison, however this will fail for input/outputs that have identical yet unordered maps as the map data is not sorted before serialization.

Either we should update serialization to be 'stable' i.e. sort all maps before serialization, or add a comparison function.

@niftynei niftynei changed the title Comparison function for psbt inputs/outputs Stable serialization for psbt inputs/outputs Aug 7, 2020
@jgriffiths
Copy link
Contributor

jgriffiths commented Aug 8, 2020

@niftynei a comparison function would be my preferred choice. Do you need a lexicographical compare or just an equality function?

edit: I've checked out the dual funding PR and it seems equality is all that's needed. Might be nice to add a map_sort call so callers can at their preference have stable serialisation by sorting the maps themselves.

@jgriffiths
Copy link
Contributor

@niftynei Please try the above PR. If you sort your input/output maps before linearizing them that should work for you until such time as comparison gets exposed.

@jgriffiths
Copy link
Contributor

Another possibility here to detect changes is to merge any maps being compared and see if their length changes, since adding items ignores duplicates (and under PSBT rules new values in the map entries can be ignored since either old or new values can be chosen).

Looking at the comparison as done by c-lightning I'm going to close this for now, I don't think a compare function thats sufficiently powerful and generic can really be implemented at the library level; for app specific use there is always going to be some bespoke processing that requires custom checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants