Skip to content

Wallet does not unlock immediately. #1029

@bitonic-cjp

Description

@bitonic-cjp

Background

I am writing an application that uses the LND RPC. When it finds the RPC in wallet-locked state, it asks the user for a passphrase, and calls UnlockWallet on the RPC to unlock the wallet. Immediately afterwards, the application continues doing other things on the RPC; these things require the wallet to be unlocked.

Your environment

  • lnd version: 9997014
  • OS: Linux sirius 4.9.0-6-amd64 Fix name typo in README #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02) x86_64 GNU/Linux
  • bitcoind: v0.16.0.0-g4b4d7eb
  • RPC is used from Python 3

Steps to reproduce

Code fragment:

with open(certFile, 'rb') as f:
    cert = f.read()
creds = grpc.ssl_channel_credentials(cert)
with open(macaroonFile, 'rb') as f:
    macaroon_bytes = f.read()
    macaroon = codecs.encode(macaroon_bytes, 'hex')
channel = grpc.secure_channel(
    '%s:%d' % (RPCHost, RPCPort),
    creds)

unlocker = lnrpc.WalletUnlockerStub(channel)

request = ln.UnlockWalletRequest(wallet_password=password.encode())
unlocker.UnlockWallet(request)

#TBD: why is this necessary?:
channel = grpc.secure_channel(
    '%s:%d' % (RPCHost, RPCPort),
    creds)

rpc = lnrpc.LightningStub(channel)

t0 = time.time()
while True:
    print(time.time() - t0)
    try:
        request = ln.GetInfoRequest()
        response = rpc.GetInfo(request, metadata=[('macaroon', macaroon)])
    except grpc.RpcError:
        continue
    break

print(response)

Expected behaviour

1.430511474609375e-06
identity_pubkey: "035276ce74688ac34b25e5c4bae7d9955826793af1107fa670a14cb832140cf68b"
...etc (rest of GetInfo output)

This is what you would get if GetInfo worked on the first attempt.

Actual behaviour

1.430511474609375e-06
0.0007653236389160156
1.000617265701294
identity_pubkey: "035276ce74688ac34b25e5c4bae7d9955826793af1107fa670a14cb832140cf68b"
...etc (rest of GetInfo output)

So, apparently, it takes about a second until GetInfo starts being successful.
Also, it is unclear to me why I need to create the channel a second time. If I don't do this, the code doesn't work at all (the loop in the end continues forever).

Even if there is no server-side bug, an example of how to do client-side initialization the proper way would be highly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    walletThe wallet (lnwallet) which LND uses

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions