Commit Graph

53 Commits

Author SHA1 Message Date
Lucas Soriano del Pino
4ee82a5a2a Execute Alice's on-chain protocol after handshake
Co-authored-by: Tobin C. Harding <tobin@coblox.tech>
2020-10-30 14:00:39 +11:00
Lucas Soriano del Pino
24104d5d35 Test that Alice punishes if Bob is inactive after locking bitcoin 2020-10-26 16:05:30 +11:00
Lucas Soriano del Pino
cea1af1e1a Take bitcoin_tx_lock_timeout as argument to action generators 2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
c86a82b315 Rename action_generator_alice to action_generator 2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
e84c56378c Test that both parties refund if Alice does not redeem
Also:

- Move generator functions to `alice` and `bob` modules. This makes
using `tracing` a lot easier, since the context of the file name let's
us differentiate between Alice's and Bob's generator logs more
clearly.
- Accept 0 confirmations when watching for the Monero lock
transaction. This should eventually be configured by the application,
but in the tests it's making things unexpectedly slower.
2020-10-26 12:30:15 +11:00
rishflab
c781ee949d Move storage into application crate 2020-10-26 10:32:54 +11:00
Philipp Hoenisch
11a4a7563b
Merge pull request #19 from comit-network/move-tor
Moving tor into swap
2020-10-23 13:32:53 +11:00
Philipp Hoenisch
17b32fed90
Moving tor into swap 2020-10-23 12:47:52 +11:00
Philipp Hoenisch
c0109d12cd
Use lib to ensure ports are free 2020-10-23 11:28:58 +11:00
rishflab
a29786e175 Use external serialisation implementation 2020-10-22 19:41:52 +11:00
rishflab
03dee7a3ea Generate temp dir for db 2020-10-22 19:34:53 +11:00
rishflab
3e82211a82 Add database todos 2020-10-22 19:27:28 +11:00
rishflab
e3b68a3864 Improve database type safety
The database is now bound to a type eg. alice::State or bob::State.
The caller cannot expect to retrieve a type that is different to
the type that was stored.
2020-10-22 18:09:16 +11:00
rishflab
8eda051087 Remove redundant serialisation implementation
ECDSAfun's serialisation implementation was already imported
making the custom implementation redundant

Remove remnants of stale comment

Remove redundant conversion

Rename params to be consistent
2020-10-22 18:09:16 +11:00
Tobin C. Harding
ade0e08db6 Merge branch 'master' into on-chain-protocol 2020-10-22 14:49:55 +11:00
Tobin C. Harding
97363cb05c Fix build after merge 2020-10-22 14:43:58 +11:00
Tobin C. Harding
f8adf6d7e0 Merge branch 'on-chain-protocol' of github.com:comit-network/xmr-btc-swap into on-chain-protocol 2020-10-22 14:33:16 +11:00
Lucas Soriano del Pino
5395303a99 Test on-chain protocol happy path 2020-10-22 11:50:06 +11:00
Tobin C. Harding
2a07113074 Fix buld after merge of db branch 2020-10-22 08:28:51 +11:00
Tobin C. Harding
3e0b40c248 Merge branch 'db' into on-chain-protocol 2020-10-22 08:17:54 +11:00
Philipp Hoenisch
ae1ea08bb2
Make it work on CI 2020-10-22 08:03:06 +11:00
Philipp Hoenisch
e1d8a1c39b
PR feedback integrated 2020-10-22 08:03:06 +11:00
Philipp Hoenisch
e67e940768
Split authenticated struct into unauthenticated struct to make it usage more obvious 2020-10-22 08:01:59 +11:00
Philipp Hoenisch
a73f1fcc6f
Start tor from test 2020-10-22 08:01:59 +11:00
rishflab
39afb4196b Save and recover protocol state from disk
NOTE: This implementation saves secrets to disk! It is not
secure.

The storage API allows the caller to atomically record the state
of the protocol. The user can retrieve this recorded state and
re-commence the protocol from that point. The state is recorded
using a hard coded key, causing it to overwrite the previously
recorded state. This limitation means that this recovery
mechanism should not be used in a program that simultaneously
manages the execution of multiple swaps.

An e2e test was added to show how to save, recover and resume
protocol execution. This logic could also be integrated into the
run_until functions to automate saving but was not included at
this stage as protocol execution is currently under development.

Serialisation and deserialisation was implemented on the states
to allow the to be stored using the database. Currently the
secret's are also being stored to disk but should be recovered
from a seed or wallets.
2020-10-21 18:39:45 +11:00
Philipp Hoenisch
295216a8ee
Add Tor feature flag and only run test if enabled 2020-10-21 18:18:25 +11:00
Philipp Hoenisch
5e19949d71
Add library to create a Tor service via Tor control port 2020-10-21 18:18:25 +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
e5ddec76f7 Increase Rust minimum stack size in CI 2020-10-21 16:09:24 +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
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
969ca63081 Split RefundBitcoin into CancelBitcoin and RefundBitcoin 2020-10-16 14:07:31 +11:00
Lucas Soriano del Pino
176b2195e3 Make ReceiveTransferProof async and take &mut self 2020-10-16 10:55:13 +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
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
rishflab
2c6bb8fa19 Remove redundant attribute 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
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
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
25edd90fb0 Remove empty lines between imports 2020-10-09 11:40:00 +11:00