Commit graph

101 commits

Author SHA1 Message Date
Wilmer Paulino
decd404bc9 rpc: add WithdrawAccount RPC 2020-05-12 15:10:05 -07:00
Wilmer Paulino
ec0ecfa065 account: add support for withdrawals
This commit introduces support for trader account withdrawals to
arbitrary outputs. Traders are able to withdraw their accounts through
either spending paths, multi-sig or expiry, with the latter requiring a
new expiration (to be done as a follow-up). When spending through the
multi-sig path, traders submit their outputs to the auctioneer,
excluding the new account output as that can be reconstructed by the
auctioneer. The auctioneer then creates a transaction adhering to the
trader's constraints and provides a signature back.
2020-05-08 14:25:42 -07:00
Wilmer Paulino
e6727852d0 clmrpc: extend account modification parameters provided to auctioneer 2020-05-08 14:25:41 -07:00
Wilmer Paulino
6e07921286 account: add deep Copy method 2020-05-08 13:33:43 -07:00
Wilmer Paulino
1f0f0ca1fd account: refactor account spend flow within CloseAccount into method
This new method will serve as the unified path for all trader account
modifications.
2020-05-08 13:33:38 -07:00
Wilmer Paulino
35e8630247 account: request auctioneer sig after committing account modifications
This is essential as otherwise if the trader has an unexpected shutdown
between receiving the auctioneer's signature and committing the
modifications to disk, then there would be no context of said
modifications from the PoV of the trader after a restart.
2020-05-08 12:29:07 -07:00
Wilmer Paulino
cd287dcdd1 account: allow option to re-create account output
While the method is yet to be used, this lays down the groundwork for
allowing account modifications in which we're required to recreate the
account output.
2020-05-08 12:29:06 -07:00
Olaoluwa Osuntokun
55bc067f1d client: add logic to register funding shims and open chans in batch lifecycle
In this commit, we add the missing logic to register for funding shims
when we're the taker of an executed order, and also to establish new
channels after we send OrderMatchAccept when we're the maker of an
executed order.
2020-05-07 19:37:05 -07:00
Olaoluwa Osuntokun
5c795ef264 client: add full lnd client to main server
As a temporary work around, we'll also add a full lnd client, as we'll
need to do things like connect to peers, register for funding shims, and
also open channels. In the future we'll catch up lndclient to add these
new methods so we can use mocks in our unit tests.
2020-05-07 19:37:02 -07:00
Olaoluwa Osuntokun
61ea03e4ee client/order: add new PendingChanKey function
The mapping in this function ensures that a given bid/ask pair will have
a unique deterministic pending channel ID to use when registering
funding shims and also making channels.
2020-05-07 19:36:59 -07:00
Wilmer Paulino
9f9e7d7cb6 clientdb: prevent test race condition by not modifying global test var 2020-05-05 14:20:49 -07:00
Wilmer Paulino
4013f33984 auctioneer: remove irrelevant pending batch on stream establishment
This commit aims to address another gap within the system to ensure
trader pending batch states are as accurate as possible. In a previous
commit, we addressed the case of a trader signing for a batch,
disconnecting and not receiving a Finalize message, and seeing a spend
for an account.

Here, we're interested in determining whether a batch a trader signed
for is actually still relevant to the trader. Since any trader can bail
from a batch, the batch may need to be re-done by the auctioneer, and if
a trader that previously signed for a previous version of the batch
remains disconnected, then they won't be aware of said new batch. At
this point, the trader has a lingering pending batch that's no longer
irrelevant, so we remove it. This logic is tied to the connection
establishment between the trader and auctioneer to ensure we handle the
disconnection and crash case of a trader after signing for a batch.
2020-05-05 13:54:39 -07:00
Wilmer Paulino
f7143b56ae server: move db init from RPC to main server
The auctioneer client will require some database methods in a later
commit, but at the moment of initialization, the database does not yet
exist.
2020-05-05 13:54:38 -07:00
Wilmer Paulino
cb9c14b1b1 clientdb: add DeletePendingBatch 2020-05-05 13:54:36 -07:00
Wilmer Paulino
043a9f7d98 account: properly handle spend on pending batch not finalized
This commit aims to address a current gap within the system where trader
account states can become desynchronized if they participated in a batch
and they never received a Finalize message from the auctioneer.

From now on, if an account spend arrives while a trader has a pending
batch, then we assume they weren't able to receive its Finalize message,
and use the spend as an indication that the batch has been finalized.
This works because if a trader signs for a batch and disconnects, the
batch should have already been persisted, and if the batch was actually
finalized (i.e., broadcast without any changes), then the account should
have been spent.
2020-05-05 13:53:32 -07:00
Wilmer Paulino
d167821bee clientdb+order: store pending batch transaction
This is done as preparation to handle traders recovering from batches
which they've participated in and signed for.
2020-05-05 13:51:17 -07:00
Wilmer Paulino
15c5859239 clientdb+order: remove batch ID parameter from MarkBatchComplete
The parameter isn't necessary as traders can only maintain one pending
batch at a time, and the check is already performed by the BatchStorer.
2020-05-05 13:48:28 -07:00
Wilmer Paulino
bda81eefb5 clmrpc: add RelevantBatchSnapshot RPC
This RPC exposes batch snapshots to traders. This is useful when the
trader wants to receive information about a batch they've participated
in for the relevant accounts.

Alternatively, this RPC can also be used by traders as a recovery
mechanism to determine whether they've made it into a finalized batch by
comparing their known batch transaction with the auctioneer's. This will
be expanded on in a later commit.
2020-05-05 13:48:26 -07:00
Wilmer Paulino
e2e566592a chaninfo: add new package to retrieve channel info for auctioneer
When traders create channels as part of a batch, the auctioneer provides
a guarantee to punish any traders who violate the lifetime of a channel
(also known as their maturity height). In order for the auctioneer to
carry out this duty, it'll need to retrieve a set of channel keys from
each trader to detect, in the event of a lifetime violation, who the
responsible trader was. This channel info is retrieved by the traders
from their encrypted SCBs.
2020-05-01 16:08:17 -07:00
Olaoluwa Osuntokun
4d24044ade client/order: add new NewBatchID method 2020-04-29 15:04:49 -07:00
Olaoluwa Osuntokun
853ad0a940 multi: add new OrderSignBegin message, fix OrderMatchSign
We need this method for further synchronization: once this is sent we
expect the traders to respond with signatures for each of the accounts
involved in the batch. The addition of this message also means that the
responder of the channel funding has time to register their shim (done
before they send their Accept message) as we don't send the
OrderSignBegin message until all traders have accepted the batch. The
initiator can now use receipt of the OrderSignBegin as a signal to
initiate the channel funding.

We also fix an existing oversight in the `OrderMatchSign`: it expected a
fully valid witness, but the only thing the traders can produce by
themselves is a signature for their input.
2020-04-29 15:04:42 -07:00
Oliver Gugger
afa03d728b client: expose LSAT identity 2020-04-29 16:19:13 +02:00
Oliver Gugger
9111b99f0b client: add dummy interceptor 2020-04-29 16:18:41 +02:00
Wilmer Paulino
9a2d6c4c50 clientdb: stage batch updates under distinct bucket
If trader A provides a signature for a batch, disconnects, and trader B,
who is also in the auction, bails, then the auctioneer will re-attempt
matchmaking. If trader A hasn't reconnected by and a successful batch is
made without them, then the updates would need to be rolled back.
Previously, since we would overwrite the main account and order state,
we'd lack information in order to do so. By staging the update under a
distinct bucket, we can now do so properly by simply removing the state
within it.
2020-04-27 15:51:58 -07:00
Wilmer Paulino
4b95396cdc clientdb: refactor test cases out of TestPersistBatchResult 2020-04-27 15:50:07 -07:00
Wilmer Paulino
d9738f7368 clientdb: specify src and dst buckets for updateAccountTX 2020-04-27 15:50:03 -07:00
Wilmer Paulino
210415b8b2 clientdb: specify src and dst buckets for updateOrderTX 2020-04-27 15:48:42 -07:00
Wilmer Paulino
c2ae197406 order: commit pending batch before providing signatures to auctioneer
Previously, if the connection between the trader and auctioneer was torn
down before the trader received a batch's finalize message, then the
trader would lose all context about the batch they participated in.
Committing the batch before providing our signatures to the auctioneer
ensures that this cannot happen. Follow-up work will allow the trader to
obtain the latest information regarding a pending batch upon
reconnections.
2020-04-24 10:57:42 -07:00
Wilmer Paulino
6a64971396 clientdb+order: use 2-step commit for batch persistence
This commits serves as preparatory work for committing a pending batch
before providing signatures to the auctioneer. This is achieved by first
storing the batch as pending upon receiving a new batch and marking it
as complete upon receiving a finalize message.
2020-04-24 10:57:41 -07:00
Wilmer Paulino
33c52f1f8c multi: remove expiry from account diffs
The expiry of an account should never change as part of a batch, only as
part of a trader initiated modification.
2020-04-20 11:53:33 -07:00
Wilmer Paulino
8a38d2ad2e account+order: use proper account batch key when storing batch 2020-04-20 11:45:16 -07:00
Wilmer Paulino
a25b1bdaa4 order: use StatePendingUpdate when updating accounts on finalized batch
This ensures that accounts go through the proper flow when they've had
updates applied.
2020-04-20 11:45:15 -07:00
Wilmer Paulino
9d8d04155e auctioneer: prevent subscribing to already subscribed accounts 2020-04-20 11:45:14 -07:00
Wilmer Paulino
a9b2f7569b account: resume flow for accounts that have had updates applied 2020-04-20 11:45:13 -07:00
Wilmer Paulino
10239c5c4b multi: add StatePendingUpdate 2020-04-20 11:45:12 -07:00
Wilmer Paulino
60553c8447 account: assert account is subscribed for updates throughout open flow 2020-04-20 11:45:10 -07:00
Wilmer Paulino
687b1985ed account: remove fallthrough in transition StatePendingUpdate->StateOpen 2020-04-20 11:45:09 -07:00
Wilmer Paulino
dc8ad76c60 account: extract resumeAccount operations on StateOpen into method 2020-04-20 11:45:08 -07:00
Olaoluwa Osuntokun
883632c0d6 Merge pull request #54 from guggero/admin-rpc
server: add admin RPC
2020-04-16 19:55:49 -07:00
Oliver Gugger
6cbd12ffd8 make+auctioncli: add CLI to interact with auction 2020-04-14 16:27:06 +02:00
Oliver Gugger
d2d7e7b006 clientdb: add missing types to codec 2020-04-14 15:41:22 +02:00
Oliver Gugger
367a67c3d7 client+order: remove account from account tally 2020-04-14 15:41:21 +02:00
Olaoluwa Osuntokun
b3e30aaa14 Merge pull request #52 from guggero/order-segregation
orders: segregate active from pending orders on the server-side
2020-04-10 14:13:37 -07:00
Olaoluwa Osuntokun
da5a56b037 Merge pull request #58 from guggero/flake-unit
test: fix flake in race and unit tests
2020-04-09 19:31:37 -07:00
Wilmer Paulino
f8811b9acf account: sort spending transaction according to BIP-69 2020-04-09 09:39:46 -07:00
Wilmer Paulino
2e21bd4971 account: sanity check input and output amounts in spending transaction 2020-04-09 09:39:45 -07:00
Wilmer Paulino
4514df1476 account: refactor toWalletOutput creation outside of createSpendTx 2020-04-09 09:39:44 -07:00
Wilmer Paulino
3edeba4b94 account: rename createCloseTx and refactor return values into struct
This is done in preparation for future work in which we'll allow custom
inputs and outputs to be provided when crafting the spending transaction
of an account.
2020-04-09 09:39:44 -07:00
Oliver Gugger
31adef0e2c client+order: define archived state 2020-04-09 14:32:01 +02:00
Oliver Gugger
a637d5b540 client+order: fix flaky unit tests
Some of the test cases relied on a map's keys always being in the
order they were defined, which is not guaranteed by the runtime.
A data race is also fixed by creating a new instance of the verifier
for each run.
2020-04-09 13:14:30 +02:00