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

BTC - Sanity swap setup #964

Closed
offerm opened this issue May 15, 2019 · 14 comments

Comments

Projects
None yet
3 participants
@offerm
Copy link
Contributor

commented May 15, 2019

on test2:

15/05/2019 09:44:13.204 [P2P] verbose: received 0 nodes (0 new) from 03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0
15/05/2019 09:44:13.209 [SWAPS] warn: sanity swap could not be initiated for BTC using rHash b30a94bc2c66f2bc20b37a194f7e6763af0f54e0166c7ce82b71b22845d3d534: 12 UNIMPLEMENTED: unknown
 service invoicesrpc.Invoices
15/05/2019 09:44:13.210 [SWAPS] warn: sanity swap could not be initiated for BTC using rHash a914a8e68bd5d26546a3a2c95701fca70b6aba7724f058305c7d21a16cde1054: 12 UNIMPLEMENTED: unknown
 service invoicesrpc.Invoices
15/05/2019 09:44:13.212 [SWAPS] error: could not add invoice for sanity swap: Error: 12 UNIMPLEMENTED: unknown service invoicesrpc.Invoices
    at Object.exports.createStatusError (/opt/xud/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/opt/xud/node_modules/grpc/src/client_interceptors.js:1204:28)
    at InterceptingListener._callNext (/opt/xud/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/opt/xud/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/opt/xud/node_modules/grpc/src/client_interceptors.js:845:24)

What should be checked?

@sangaman

This comment has been minimized.

Copy link
Collaborator

commented May 15, 2019

Ah this is probably because lnd was built without the invoices rpc subserver, which is required for hold invoices. When you compile lnd, use make tags="invoicesrpc". Let me know if that resolves this for you.

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2019

@sangaman
I recompiled LND. Command I used was GO111MODULE=off GOPATH=$GOPATH make tags="invoicesrpc" followed by make install`

restart lnd and xud

same problem.

Maybe there is a need to generate the proto files with this flag too?

@sangaman

This comment has been minimized.

Copy link
Collaborator

commented May 16, 2019

Hm that's strange. Could you confirm that lnd is version 0.6 or higher? I don't believe you need to generate any proto files, as that has been done when the proto definitions were changed.

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2019

{
        "version": "0.6.1-beta commit=v0.6.1-beta-rc2",
        "identity_pubkey": "03d6747c9ff24aa8b025027e30556897543642910cbdec066d54f86841ab80966b",
        "alias": "BTC@xud-test-2",
        "num_pending_channels": 0,
        "num_active_channels": 1,
        "num_inactive_channels": 0,
        "num_peers": 1,
        "block_height": 282933,
        "block_hash": "029af48e7c1349d1afa4205097a450fdd39d5395bf23c770a38ca4a68a3bd94f",
        "best_header_timestamp": 1558014772,
        "synced_to_chain": true,
        "testnet": false,
        "chains": [
                {
                        "chain": "bitcoin",
                        "network": "simnet"
                }
        ],
        "uris": null
}

Also lncli does not show addholdinvoice option.

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2019

Don't we need the tags="invoicesrpc" on the make install?

@sangaman

This comment has been minimized.

Copy link
Collaborator

commented May 16, 2019

I don't believe there's any new lncli commands for hold invoices. I also can't find a clear answer on whether the invoicesrpc tag should be for make or make install, does adding it to make install solve the issue?

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 16, 2019

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 17, 2019

@sangaman

I now see this:

17/05/2019 10:57:36.297 [GLOBAL] info: config loaded
17/05/2019 10:57:36.426 [DB] info: connected to database /home/xud/.xud/xud-simnet.db
17/05/2019 10:57:36.508 [RAIDEN] info: trying to verify connection to raiden with uri: localhost:5001
17/05/2019 10:57:36.532 [LND] info: trying to verify connection to lnd for BTC at localhost:10002
17/05/2019 10:57:36.573 [RAIDEN] info: RaidenClient status: ConnectionVerified
17/05/2019 10:57:36.539 [LND] info: trying to verify connection to lnd for LTC at localhost:10001
17/05/2019 10:57:36.604 [LND] error: could not verify connection to lnd for LTC at localhost:10001, error: {"code":14,"metadata":{"_internal_repr":{}},"details":"Connect Failed"},
          retrying in 5000 ms
17/05/2019 10:57:36.605 [LND] info: LndClient status: Disconnected
17/05/2019 10:57:36.619 [LND] info: LndClient status: ConnectionVerified
17/05/2019 10:57:36.628 [GLOBAL] info: Local nodePubKey is 028599d05b18c0c3f8028915a17d603416f7276c822b6b2d20e71a3502bd0f9e0a
17/05/2019 10:57:36.629 [P2P] info: Connecting to simnet XU network
17/05/2019 10:57:36.638 [HTTP] info: http server listening on 127.0.0.1:8887
17/05/2019 10:57:36.634 [P2P] info: p2p server listening on 0.0.0.0:8885
17/05/2019 10:57:36.647 [RPC] info: gRPC server listening on 0.0.0.0:8886
17/05/2019 10:57:36.662 [P2P] info: Connecting to known / previously connected peers
17/05/2019 10:57:36.693 [P2P] warn: could not open connection to peer (xud1.test.exchangeunion.com:8885): could not connect to peer at xud1.test.exchangeunion.com:8885: connect ECONNRE
FUSED 35.196.118.79:8885
17/05/2019 10:57:36.768 [RPC] info: gRPC Web API proxy listening on port 8080
17/05/2019 10:57:36.779 [P2P] debug: Connected pre-handshake to peer xud3.test.exchangeunion.com:8885
17/05/2019 10:57:36.799 [P2P] debug: Peer (xud3.test.exchangeunion.com:8885) session in-encryption enabled
17/05/2019 10:57:36.802 [P2P] debug: Connection attempt #1 to peer (xud1.test.exchangeunion.com:8885) failed: connect ECONNREFUSED 35.196.118.79:8885. retrying in 5 sec...
17/05/2019 10:57:36.815 [P2P] debug: Peer (03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0) session out-encryption enabled
17/05/2019 10:57:36.817 [P2P] verbose: opened connection to 03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0 at xud3.test.exchangeunion.com:8885
17/05/2019 10:57:36.831 [P2P] debug: received sanitySwap from 03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0: {"currency":"BTC","rHash":"ac6c52f70bee84503a06dfe558b
7f3940ea5e9fd43bbe4643bebd3a45abf060e"}
17/05/2019 10:57:36.834 [P2P] debug: received sanitySwap from 03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0: {"currency":"WETH","rHash":"a419ad0b2a16c3cbc737a8e13d
c63a370ec4ee10f807f61f00575dd9d51f7e1a"}
17/05/2019 10:57:36.835 [P2P] verbose: received 0 nodes (0 new) from 03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0
17/05/2019 10:57:36.864 [LND] debug: added invoice of 1 for ac6c52f70bee84503a06dfe558b7f3940ea5e9fd43bbe4643bebd3a45abf060e
17/05/2019 10:57:36.869 [LND] debug: added invoice of 1 for 82754a11fb2e03524ed6c5f0fde2d00669cea862bf5c5ac2c5e8128967f73122

What is the reason for the last invoice? 82754a11fb2e03524ed6c5f0fde2d00669cea862bf5c5ac2c5e8128967f73122?

@sangaman

This comment has been minimized.

Copy link
Collaborator

commented May 17, 2019

I believe that one is the sanity swap we initiated, and one is likely the swap the peer initiated. You can see that we received sanity swap packets from the peer indicating that they are initiating swaps themselves.

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 17, 2019

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 17, 2019

There is once invoice of a swap we initiated and one invoice for a swap the partner initiated.
Works OK.
Suggest to clarify, as part of the log prints, that we are adding the invoice for a wap we initiate.

@offerm

This comment has been minimized.

Copy link
Contributor Author

commented May 17, 2019

@sangaman The BTC swap, when working, is OK.

But if the swap fails (once side is not properly configured), the nodes will go on reconnect loop a a swap will be attempted every time. The problem is that there is no cleanup in such case and the number of "open" invoices increases on LND. I currently have 5587 invoices.....

Also, the broken side, which can't addholdinvoices, issue a message

17/05/2019 14:48:36.891 [SWAPS] warn: sanity swap could not be initiated for BTC using rHash 30089fe452bade21e6d341a5931ff40cc1598cf83f083998b23a0e7f0e9f782e: 12 UNIMPLEMENTED: unknown
 service invoicesrpc.Invoices

but still sends the SanitySwap packet to the peer:

17/05/2019 14:48:36.902 [P2P] debug: received sanitySwap from 03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0: {"currency":"BTC","rHash":"30089fe452bade21e6d341a5931
ff40cc1598cf83f083998b23a0e7f0e9f782e"}

@offerm offerm added the bug label May 17, 2019

@sangaman

This comment has been minimized.

Copy link
Collaborator

commented May 17, 2019

There ought to be cleanup of the open invoices when the swaps fail via the CancelInvoice call, I'll investigate to see why it might not be happening. I'll also see why it might send a swap request even if the add invoice call fails. Thanks for testing this out.

@sangaman

This comment has been minimized.

Copy link
Collaborator

commented May 18, 2019

I found one place where we're not canceling hold invoices after a failed sanity swap, which is when we accept a sanity swap but it's never actually initiated by the peer. I'll open a PR to fix that.

And in regards to sending the sanity swap packet even when the AddHoldInvoice call fails, in reviewing I actually did that deliberately. The AddHoldInvoice call and the sanity swap request happen in parallel to minimize delay, if the add invoice call fails then the sanity swap will wind up failing.

sangaman added a commit that referenced this issue May 18, 2019

fix(swaps): remove stalled sanity swap invoice
This adds a timeout for sanity that we have accepted and added an
invoice for. If the time limit is exceeded, we remove the sanity swap
and its corresponding invoice. This prevents invoices and sanity swaps
that are stalled from accumulating, avoiding a potential memory leak.

Fixes #964.

@kilrau kilrau added this to the 1.0.0 milestone May 20, 2019

@kilrau kilrau added the P2 label May 21, 2019

sangaman added a commit that referenced this issue May 21, 2019

fix(swaps): remove stalled sanity swap invoice
This adds a timeout for sanity that we have accepted and added an
invoice for. If the time limit is exceeded, we remove the sanity swap
and its corresponding invoice. This prevents invoices and sanity swaps
that are stalled from accumulating, avoiding a potential memory leak.

Fixes #964.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.