Skip to content

backend/btc/address: be explicit about chainIndex/addressIndex #3325

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

benma
Copy link
Contributor

@benma benma commented May 6, 2025

The relative keypath always has two elements, the first element indicating change and the second indicating the address index.

A relative keypath of arbitrary length is harder to handle. E.g. it is not compatible with output descriptors with multipath indices (xpub/<0;1>/*), where also two elements are required to derive an address (the multipath index selecting between <X;Y> and the address index).

The unit tests change because the GetAddress test function used an empty relative path instead of a chainIndex and addressIndex, which now was forced to change with the stricter types.

I considered keeping ChainIndex uint32 instead of Change bool,
because in multipaths, one could have more than two,
e.g. xpub/<X;Y;Z>/*, but I prefer the stricter type and it's not
likely we will ever need more than two (receive & change).

@benma benma requested a review from bznein May 6, 2025 10:34
@benma benma force-pushed the address-refactor branch 2 times, most recently from 5d93dbb to f42c977 Compare May 6, 2025 10:39
Copy link
Collaborator

@bznein bznein left a comment

Choose a reason for hiding this comment

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

Overall LGTM with one minor comment on docs

@@ -47,22 +47,28 @@ type AccountAddress struct {
}

// NewAccountAddress creates a new account address.
// The chainIndex is 0 for receive and 1 for change.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not clear what "chainIndex" is here; it's not one of the argument (though I assume you refer to the one accessed via derivation.SimpleChainIndex()? ) maybe we can make it clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah it's a leftover comment from before I introduced the Derivation struct. Removed.

The relative keypath always has two elements, the first element
indicating change and the second indicating the address index.

A relative keypath of arbitrary length is harder to handle. E.g. it is
not compatible with output descriptors with multipath
indices (`xpub/<0;1>/*`), where also two elements are required to
derive an address (the multipath index selecting between `<X;Y>` and the address index).

The unit tests change because the GetAddress test function used an
empty relative path instead of a chainIndex and addressIndex, which
now was forced to change with the stricter types.

I considered keeping `ChainIndex uint32` instead of `Change bool`,
because in multipaths, one could have more than two,
e.g. `xpub/<X;Y;Z>/*`, but I prefer the stricter type and it's not
likely we will ever need more than two (receive & change).
@benma benma force-pushed the address-refactor branch from f42c977 to d2331ca Compare May 6, 2025 20:22
Copy link
Collaborator

@bznein bznein left a comment

Choose a reason for hiding this comment

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

LGTM

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