Commit graph

58 commits

Author SHA1 Message Date
Oliver Gugger
75bf4e020a
rpcserver+order: remove funding shim on subsequent prepare
Because we have to always expect an OrderMatchPrepare to be sent
multiple times, we need to make sure we clean up our funding shims from
the previous pending batch.
2020-08-21 15:19:44 +02:00
Oliver Gugger
7fb4ef9782
order+rpcserver: enforce order duration limit and multiple 2020-08-18 13:38:35 +02:00
Oliver Gugger
3df4e2f005
multi: move FeeSchedule to terms package
As a preparation to avoid package import cycles when introducing more
generic terms, we move the FeeSchedule interface and its
LinearFeeSchedule implementation to the terms package.
2020-08-18 13:15:34 +02:00
Oliver Gugger
09515098f2
order: use state pending batch when storing account diff 2020-08-17 11:44:30 +02:00
Oliver Gugger
978950600c
multi: update aperture, use lndclient, remove loop
To get rid of the loop dependency, we update aperture (which now houses
all the LSAT code) and use the standalone lndclient repository.
2020-08-11 19:41:01 +02:00
Oliver Gugger
668bc2c279
multi: copy lndclient mocks from loop repository
As a preparation to get rid of the loop dependency, we copy the mocks we
need from the test package of that dependency and use them in our tests.
2020-08-11 10:44:24 +02:00
Olaoluwa Osuntokun
9bb337f684
order: update validateOrder to only accumulate reserved vals for target acct
Without this commit, an account would at times be prevented on
submitting an order that it itself is able to handle.
2020-08-07 18:35:39 -07:00
Olaoluwa Osuntokun
fcdc26afa0
order: add new TestValidateOrderAccountIsolation test case
In this commit, we add a new test that fails with the current logic in
`validateOrder`. The function as isn't doesn't isolate the orders for
each account, so the orders from account A can prevent a user from
making an order to account B.
2020-08-07 18:35:38 -07:00
Johan T. Halseth
5caa1f9d7f
order: require an order's Min/MaxDuration to be at least 144 2020-08-07 16:34:07 +02:00
Johan T. Halseth
81b6dd2139
order: acccount for worst case chain fee in reserved value
Use the MaxBatchFeeRate value to reserve the maximum chain fee that can
be paid by the trader.
2020-08-07 16:34:07 +02:00
Johan T. Halseth
a2abc187f3
multi: rename FundingFeeRate to MaxBatchFeeRate
The funding feerate field was previoulsy unused, so we rename it to
"max batch fee rate" in order to use it to communicate to the server the
maximum fee rate we are willing to pay to be included in a batch.

We also increase the default value to 500 sat/vbyte.
2020-08-07 16:34:07 +02:00
Johan T. Halseth
204a442695
order/manager: check reserved value when submitting order
To check whether the account has enough balance for a new order, sum the
reserved value of all orders before submitting a new one.
2020-08-06 10:52:52 +02:00
Johan T. Halseth
c9e6e2a3a7
order: add ReservedValue to interface
The ReservedValue method returns the worst case value the must be
available in the account to ensure the trader can pay for the order
including its fees.
2020-08-06 10:52:52 +02:00
Johan T. Halseth
93c324c35c
order: add StateExpired to Archived() 2020-08-06 10:52:52 +02:00
Johan T. Halseth
bb89eaba74
order: extract maker and taker delta calculation
To be able to re-use the caluclation for a single order without keeping
a tally.
2020-08-06 10:52:51 +02:00
Olaoluwa Osuntokun
660426609f
Merge pull request #28 from Roasbeef/billions
order: increase precision for the smallest per-block lease rate
2020-07-15 21:12:52 -07:00
Olaoluwa Osuntokun
e31c176f6c
order: increase precision for the smallest per-block lease rate
This is a follow up to #21. In this PR increase the fixed rate
denominator from 1e6 to 1e9 (a factor of 100x), which will allow us to
express a per-block lease rate for the smallest possible order (1 unit,
or 100k sats) over the longest possible lease period (6 months).
2020-07-15 16:27:07 -07:00
Wilmer Paulino
283c0c6ca3
order: expose whether an ongoing batch is present 2020-07-15 15:57:38 -07:00
Olaoluwa Osuntokun
1b498857b2
order+batch: cancel pending funding shims if we reject a batch
In this commit, we ensure that if we need to reject a batch for w/e
reason, then we also unregister all funding shims. Otherwise, if we
repeat a modified version of that batch, then we'd fail early as the
attempt to register than same shim would be rejected.
2020-07-14 20:12:43 -07:00
Olaoluwa Osuntokun
3363f8626a
order: only require advertised addressees for ask orders
In this commit, we relax the node addr requirement to only apply to
those that want to submit ask orders. If you're selling channels, then
you should be an actual routing node, meaning you're accepting inbound
connections. As a result, we now only apply this requirement, as this
allows those that needs inbound channels (putting in bids) to not be
exposed to the network.
2020-07-10 19:58:15 -07:00
Olaoluwa Osuntokun
cd408b366c
Merge pull request #19 from wpaulino/height-hint-sweep
account+order: update account height hints
2020-07-02 17:26:23 -07:00
Olaoluwa Osuntokun
5e4149c32d
order: add String() method for order type 2020-07-01 17:52:06 -07:00
Wilmer Paulino
509cb4e64e
order: update height hint for accounts in batch 2020-07-01 17:01:23 -07:00
Olaoluwa Osuntokun
57fa63c237
multi: rename, fix modules 2020-06-21 19:37:00 -07:00
Oliver Gugger
c46bfef959 client+clmrpc: unify data types for amounts, fees and blocks
We use the same proto message types everywhere for these kinds
of fields:
- absolute amounts (sats): uint64
- fee rates (sat/kWU): uint64
- fee rates (ppm): uint32
- blocks (absolute and relative): uint32

Additionally we unify the comments and remove the [ json_name = "" ]
declarations in the trader proto as they aren't needed with the
jsonpb marshaller that we use.
Then we align the naming of the account key to be called trader key
everywhere instead of user's sub key.
2020-05-27 14:33:34 +02:00
Olaoluwa Osuntokun
33246cda7d multi: fix linter issues 2020-05-26 19:58:14 -07:00
Olaoluwa Osuntokun
9a2268ad48 client: change order.Kit.AcctKey into raw key bytes
In this commit, we change the key stored within the internal order kit
into a raw pubkey array. Along the way we fix a bug in the verifier
tests due to using a map with pointer keys rather than the actual value
itself.
2020-05-26 19:57:54 -07:00
Olaoluwa Osuntokun
20a5085017 client/order: properly set UnitsFilled in ParseRPCMatchedOrders 2020-05-26 19:57:49 -07:00
Olaoluwa Osuntokun
ad5c24bf2a client/order: log expected script when ending state script validation fails 2020-05-26 19:57:48 -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
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
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
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
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
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
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
Oliver Gugger
14aed0976a client+order: fix double encoding of order nonces 2020-04-09 13:14:06 +02:00
Oliver Gugger
15e7a28ccb client+order: fix fee calculation errors 2020-04-03 21:53:04 +02:00
Oliver Gugger
30faf6188b client: add batch persistence 2020-04-03 21:53:04 +02:00
Oliver Gugger
42adb28ff5 client: verify batch 2020-04-03 21:50:22 +02:00
Oliver Gugger
84d8379341 client+order: calculate account dust size 2020-04-03 21:50:21 +02:00