Skip to content

Make Record.RR() always deterministic#190

Merged
mholt merged 1 commit intolibdns:masterfrom
gucci-on-fleek:deterministic-SvcParams.String
Sep 2, 2025
Merged

Make Record.RR() always deterministic#190
mholt merged 1 commit intolibdns:masterfrom
gucci-on-fleek:deterministic-SvcParams.String

Conversation

@gucci-on-fleek
Copy link
Copy Markdown
Collaborator

SvcParams.String() used to iterate over keys in a random order, which meant that calling ServiceBinding.RR() could return different Data for identical records. This commit sorts the keys in lexicographic order, making the result deterministic.

Furthermore, since it seems useful for code to assume that it can safely roundtrip between Record.RR() and RR.Parse() and that Record.RR() is deterministic, I've now documented this. These are both already the case, but a formal guarantee should make external usage easier.

Related to #189.


RFC 9460 §2.1 says that we're allowed to place the keys in any order that we want, so I decided to sort the keys lexicographically since that was the easiest to implement. However, the canonical order is to sort by the key index, but this would require for us to hardcode the key↔index mapping.

`SvcParams.String()` used to iterate over keys in a random order, which
meant that calling `ServiceBinding.RR()` could return different `Data`
for identical records. This commit sorts the keys in lexicographic
order, making the result deterministic.

Furthermore, since it seems useful for code to assume that it can safely
roundtrip between `Record.RR()` and `RR.Parse()` and that `Record.RR()`
is deterministic, I've now documented this. These are both already the
case, but a formal guarantee should make external usage easier.

Related to libdns#189.
Copy link
Copy Markdown
Contributor

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good change. Thank you! We can switch to the canonical order later if the need arises. The docs you made leave wiggle room for us to change the exact ordering, as long as it's determinstic.

@mholt mholt merged commit 634fd1b into libdns:master Sep 2, 2025
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

Successfully merging this pull request may close these issues.

2 participants