Commit Graph

67 Commits

Author SHA1 Message Date
Lucas Soriano del Pino
5395303a99 Test on-chain protocol happy path 2020-10-22 11:50:06 +11:00
Lucas Soriano del Pino
d3a7689059 Update comment about minimum stack size 2020-10-21 16:10:20 +11:00
Lucas Soriano del Pino
917aabcc03 Increase Rust minimum stack size a lot more 2020-10-21 16:04:41 +11:00
Lucas Soriano del Pino
8b48191e1c Increase Rust minimum stack size in CI 2020-10-21 15:55:20 +11:00
Lucas Soriano del Pino
04e1dca16a Fix dependency to cross-curve-dleq and ecdsa_fun 2020-10-21 15:14:31 +11:00
Lucas Soriano del Pino
50ed74319f Simplify xmr-btc/tests Monero wallet
- Make it the same for Alice and Bob.
- Make it contain a wallet client instead of the `Monero` struct.

Also:

Remove `Container` from inside `Monero` struct. The caller of `new`
can simply ensure that `Container` is not dropped to keep the
container alive.

This makes the `Monero` struct easier to work with, as it just holds
the data necessary to create the different clients created during
`init`, and does not have any lifetime restrictions.
2020-10-20 12:18:27 +11:00
Lucas Soriano del Pino
55629838f4 Implement test function that calls action_generator_alice 2020-10-19 10:44:25 +11:00
Lucas Soriano del Pino
7c99415cff Write action_generator_alice 2020-10-16 17:05:11 +11:00
Lucas Soriano del Pino
55ea8f23e2 s/{monero,bitcoin}_ledger/{monero,bitcoin}_client/g 2020-10-16 14:17:10 +11:00
Lucas Soriano del Pino
9d64f3fd29 Watch the blockchain during Bitcoin refund 2020-10-16 14:16:06 +11:00
Lucas Soriano del Pino
969ca63081 Split RefundBitcoin into CancelBitcoin and RefundBitcoin 2020-10-16 14:07:31 +11:00
Lucas Soriano del Pino
d813957c5a Rename InsufficientXMR to InsufficientXmr 2020-10-16 14:02:47 +11:00
Lucas Soriano del Pino
bae391ff9c Bubble up unrecoverable errors instead of expecting
This does introduce the ability of expressing incorrect combinations
of the enums `SwapFailed` and `Reason`, but these are just internal
to this function and it's terser that way.
2020-10-16 14:01:57 +11:00
Tobin C. Harding
1251681cfd Calculate amounts from BTC 2020-10-16 12:42:47 +11:00
Lucas Soriano del Pino
e457130b6c Bubble up unrecoverable errors instead of expecting
This does introduce the ability of expressing incorrect combinations
of the enums `SwapFailed` and `Reason`, but these are just internal
to this function and it's terser that way.
2020-10-16 11:43:24 +11:00
Lucas Soriano del Pino
369770488f Document Reason enum 2020-10-16 11:31:16 +11:00
Lucas Soriano del Pino
7d307e581a Fail the swap early if Bitcoin TxLock is never published
This helps distinguish between the case where the refund timelock is
reached before the bitcoin is locked and the case where the refund
timelock is reached after the bitcoin is locked and before Alice sends
over the transfer proof for locking up the monero. In the first case
we can abort without doing anything, but in the second case we must
instruct the caller to refund the bitcoin.
2020-10-16 11:26:17 +11:00
Lucas Soriano del Pino
9f1bf72c7b Only generate refund action after Bitcoin lock 2020-10-16 11:19:38 +11:00
Lucas Soriano del Pino
c1f6adc8ed Refund if Alice takes too long to prove that Monero has been locked 2020-10-16 10:55:13 +11:00
Lucas Soriano del Pino
176b2195e3 Make ReceiveTransferProof async and take &mut self 2020-10-16 10:55:13 +11:00
Tobin C. Harding
3492c46e71 Verify amounts with user 2020-10-16 10:49:19 +11:00
Tobin C. Harding
05766d3146 Add swap/
Add a binary crate `swap` that implements two nodes (Alice and Bob). With this
applied we can start up a node for each role and do:

- Bob: Requests current amounts using BTC is input
- Alice: Responds with amounts
- Bob: (mock) get user input to Ok the amounts

... continue with swap (TODO)
2020-10-16 10:05:06 +11:00
Lucas Soriano del Pino
4723626fc0 Suppress compiler noise in tests folder
By having two modules that declare and use the `harness` module we ran
into a situation where not all parts of the `harness` module were
being used by both of these other test modules. This was producing
annoying warnings.

For now this can be solved by marking the `harness` module declaration
as public. This has no real effect since modules under `/tests` cannot
be depended on elsewhere, but it satisfies the compiler. It does mean
that we will not hear about unused functions, but this change should
be temporary and it's a very minor problem given that it's just test
code.
2020-10-15 21:53:55 +11:00
Lucas Soriano del Pino
f0ecc62748 Check expiry before emitting first action 2020-10-15 21:48:08 +11:00
Lucas Soriano del Pino
df4ffb65c9 Make bitcoin::WatchForRawTransaction infallible
And trigger refund if Alice's redeem transaction takes too long.
2020-10-15 21:22:52 +11:00
Lucas Soriano del Pino
ba3011a9c9 Trigger refund if the publication of Monero TxLock takes too long 2020-10-15 21:22:31 +11:00
Lucas Soriano del Pino
08be87747f Configure exponential backoff so that it never stops retrying 2020-10-15 18:34:13 +11:00
Lucas Soriano del Pino
15f7932f7f Replace monero::CheckTransfer with monero::WatchForTransfer
Instead of checking once to see if Monero's `TxLock` has been
published, the new trait should keep looking until the transaction has
been found.

The new trait also allows the caller to set an expected number of
confirmations on the transaction.

The implementation of the trait is currently part of test code, but it
should be similar to what we will eventually do for an application.
2020-10-15 13:10:31 +11:00
Lucas Soriano del Pino
5daa3ea9a8 [WIP] Generate actions for Bob's on-chain protocol
Mimics what @thomaseizinger did here [1] and here [2].

This has the advantage that the consumer has more freedom to execute
`Action`s without having to implement particular traits. The error
handling required inside this protocol-executing function is also
reduced.

As discussed with Thomas, for this approach to work well, the
trait functions such as `receive_transfer_proof` should be infallible,
and the implementer should be forced to hide IO errors behind a retry
mechanism.

All of these asynchronous calls need to be "raced" against
the abort condition (determined by the `refund_timelock`), which is
missing in the current state of the implementation.

The initial handshake of the protocol has not been included here,
because it may not be easy to integrate this approach with libp2p, but
a couple of messages still need to exchanged. I need @tcharding to
tell me if it's feasible/good to do it like this.

[1]
https://github.com/comit-network/comit-rs/blob/move-nectar-swap-to-comit/nectar/src/swap/comit/herc20_hbit.rs#L57-L184.
[2] e584d2b14f/nectar/src/swap.rs (L716-L751).
2020-10-13 10:53:20 +11:00
Philipp Hoenisch
1ee060b535
Merge pull request #9 from comit-network/re-order-send-recv
Re-order send/receive
2020-10-12 13:07:35 +11:00
Tobin C. Harding
fc12b0d9fd Re-order send/receive
There are no guarantees that send_message and receive_massage do not block
the flow of execution. Therefore they must be paired between Alice/Bob, one
send to one receive in the correct order.

Define Alice to call `receive_message` first, with Bob sending the message. Do
this because we are expecting Alice to be have a well known address, there is no
currently such assumption for Bob.
2020-10-12 08:53:21 +11:00
Tobin C. Harding
911ff396db
Merge pull request #3 from comit-network/readme 2020-10-12 07:35:55 +11:00
rishflab
36608657a5
Merge pull request #2 from comit-network/async-squashed
Execute Alice and Bob state machines concurrently
2020-10-09 12:14:45 +11:00
rishflab
c778f4e204 Remove incorrect todo 2020-10-09 11:46:33 +11:00
rishflab
2c6bb8fa19 Remove redundant attribute 2020-10-09 11:40:00 +11:00
rishflab
51760041f0 Remove duplicated macro definitions 2020-10-09 11:40:00 +11:00
rishflab
666c121bb3 Implement transport traits with generics 2020-10-09 11:40:00 +11:00
rishflab
bf576bf251 Move test functions out of lib 2020-10-09 11:40:00 +11:00
rishflab
61a8a3e428 Improve formatting of tests 2020-10-09 11:40:00 +11:00
rishflab
9f046944a5 Add context to log messages 2020-10-09 11:40:00 +11:00
rishflab
48e5eb8d6c Remove redundant type declarations 2020-10-09 11:40:00 +11:00
rishflab
154b3edcf9 Split SendReceive into seperate traits 2020-10-09 11:40:00 +11:00
rishflab
6b7193b974 Fix clippy warnings 2020-10-09 11:40:00 +11:00
rishflab
697e1195cd Fix Cargo.toml fmt 2020-10-09 11:40:00 +11:00
rishflab
a759f39b1d Fix module ambiguity in tests 2020-10-09 11:40:00 +11:00
rishflab
36ed3a0b8b Rename ImportOutput to reflect purpose 2020-10-09 11:40:00 +11:00
rishflab
213034dc1f Remove unused clone from states 2020-10-09 11:40:00 +11:00
rishflab
d01c05e5f5 Use intellij rust gitignore 2020-10-09 11:40:00 +11:00
rishflab
25edd90fb0 Remove empty lines between imports 2020-10-09 11:40:00 +11:00
rishflab
4e031ff9a2 Loop on blockchain call instead of delaying
Previously there was a delay making a get raw transaction call to
give some time for a transaction to be confirmed on the blockchain.
This has been replaced with a loop that waits until the call is
succesful.
2020-10-09 11:40:00 +11:00