lnd icon indicating copy to clipboard operation
lnd copied to clipboard

NewAddress returns duplicate addresses

Open remnantdev opened this issue 1 year ago • 4 comments
trafficstars

Background

We have noticed that gRPC call to NewAddress did return the same address twice.

From what I can see in our logs the node was in the process of starting.

Is getting a new address guaranteed to return a new address or was it an invalid assumption on our part?

Your environment

  • version of lnd : lnd.017.2.beta
  • which operating system: Alpine Linux v3.18

Steps to reproduce

Not able to reproduce

remnantdev avatar Apr 26 '24 20:04 remnantdev

In address type, which type did you select? The options:

    WITNESS_PUBKEY_HASH = 0;
    NESTED_PUBKEY_HASH = 1;
    UNUSED_WITNESS_PUBKEY_HASH = 2;
    UNUSED_NESTED_PUBKEY_HASH = 3;
    TAPROOT_PUBKEY = 4;
    UNUSED_TAPROOT_PUBKEY = 5;

alexbosworth avatar Apr 28 '24 19:04 alexbosworth

In address type, which type did you select? The options:

    WITNESS_PUBKEY_HASH = 0;
    NESTED_PUBKEY_HASH = 1;
    UNUSED_WITNESS_PUBKEY_HASH = 2;
    UNUSED_NESTED_PUBKEY_HASH = 3;
    TAPROOT_PUBKEY = 4;
    UNUSED_TAPROOT_PUBKEY = 5;

We only use WITNESS_PUBKEY_HASH

remnantdev avatar Apr 29 '24 16:04 remnantdev

With WITNESS_PUBKEY_HASH you should be guaranteed to receive a new address every time. Are you sure you didn't use UNUSED_WITNESS_PUBKEY_HASH? Which would return the same address until some on-chain funds are detected on it (marking it as "used"). If you can reproduce, then please share the logs of both calls.

guggero avatar Apr 29 '24 16:04 guggero

We are sure we used WITNESS_PUBKEY_HASH . We have one usage of UNUSED_WITNESS_PUBKEY_HASH but it is in a totally different context.

I was not able to reproduce, we only noticed it occuring this time because the address was actually used in a transaction but going through our db I could find some duplicate address going all the way back to 2021.

remnantdev avatar Apr 30 '24 03:04 remnantdev

Hi we too got same address twice, despite passing WITNESS_PUBKEY_HASH. Like this is 1 in say 100k cases, like we have been generating lot of onchain addresses and in very very rare scenario got this case of duplicate address. One thing to noticed was that the address api was called multiple time at same timestamp with microseconds different then only got this same address.

saraogiraj94 avatar Jul 05 '24 09:07 saraogiraj94

Thanks for the additional detail. Sounds like a race condition and/or missing database level lock... Should help us find the bug more quickly.

guggero avatar Jul 08 '24 08:07 guggero