Commit Graph

38 Commits (c900d125938242c2ddd03e0bf0f3c8ceaed569b7)

Author SHA1 Message Date
rishflab c900d12593 Merge xmr_btc crate
Created network, storage and protocol modules. Organised
files into the modules where the belong.

xmr_btc crate moved into isolated modulein swap crate.

Remove the xmr_btc module and integrate into swap crate.

Consolidate message related code

Reorganise imports

Remove unused parent Message enum

Remove unused parent State enum

Remove unused dependencies from Cargo.toml
3 years ago
Franck Royer 2a778f5644
Remove overzealous clippy overrides
We have overridden a number of clippy warnings such as
"large enum variant".

Considering that we have a number of issues
 with the stack size in CI, it is more prudent to follow clippy's advice
 and box larger items so that the enum does not take larger space.

Do note that an instance of the enum always takes as much space as its
largest variant.
4 years ago
Franck Royer f0736d0906
Remove Refund timelock and T0/T1/T2
There are no refund timelock, only a cancellation timelock and punish
timelock.

Refund can be done as soon as the cancellation transaction is published.
4 years ago
rishflab 7af4b6980a Test Alice refunds after Bob refund
Reworked Alice XmrLocked state transition handler to handle the
scenario when Alice received the encsig but Bob refunds.
Previously Alice was trying to redeem after receiving the encsig
without checking if t1 had elapsed.
4 years ago
Franck Royer 765482b0aa
Implement `wait_for_transaction_finality` 4 years ago
Lucas Soriano del Pino 0dd01c3a3b Do not re-export curve25519_dalek
Anything that needs to be re-exported by this crate from
`curve25519_dalek` can be re-exported from the `monero` module. In
fact, the `Scalar` type was already being re-exported.
4 years ago
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.
4 years ago
rishflab ec71f98252 Revert re-imports to qualified paths 4 years ago
rishflab c781ee949d Move storage into application crate 4 years ago
Philipp Hoenisch 17b32fed90
Moving tor into swap 4 years ago
Tobin C. Harding ade0e08db6 Merge branch 'master' into on-chain-protocol 4 years ago
Tobin C. Harding f8adf6d7e0 Merge branch 'on-chain-protocol' of github.com:comit-network/xmr-btc-swap into on-chain-protocol 4 years ago
Lucas Soriano del Pino 5395303a99 Test on-chain protocol happy path 4 years ago
Tobin C. Harding 3e0b40c248 Merge branch 'db' into on-chain-protocol 4 years ago
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.
4 years ago
Philipp Hoenisch 295216a8ee
Add Tor feature flag and only run test if enabled 4 years ago
Philipp Hoenisch 5e19949d71
Add library to create a Tor service via Tor control port 4 years ago
Lucas Soriano del Pino 55629838f4 Implement test function that calls action_generator_alice 4 years ago
Lucas Soriano del Pino 7c99415cff Write action_generator_alice 4 years ago
Lucas Soriano del Pino 55ea8f23e2 s/{monero,bitcoin}_ledger/{monero,bitcoin}_client/g 4 years ago
Lucas Soriano del Pino 9d64f3fd29 Watch the blockchain during Bitcoin refund 4 years ago
Lucas Soriano del Pino 969ca63081 Split RefundBitcoin into CancelBitcoin and RefundBitcoin 4 years ago
Lucas Soriano del Pino d813957c5a Rename InsufficientXMR to InsufficientXmr 4 years ago
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.
4 years ago
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.
4 years ago
Lucas Soriano del Pino 369770488f Document Reason enum 4 years ago
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.
4 years ago
Lucas Soriano del Pino 9f1bf72c7b Only generate refund action after Bitcoin lock 4 years ago
Lucas Soriano del Pino c1f6adc8ed Refund if Alice takes too long to prove that Monero has been locked 4 years ago
Lucas Soriano del Pino 176b2195e3 Make ReceiveTransferProof async and take &mut self 4 years ago
Lucas Soriano del Pino f0ecc62748 Check expiry before emitting first action 4 years ago
Lucas Soriano del Pino df4ffb65c9 Make bitcoin::WatchForRawTransaction infallible
And trigger refund if Alice's redeem transaction takes too long.
4 years ago
Lucas Soriano del Pino ba3011a9c9 Trigger refund if the publication of Monero TxLock takes too long 4 years ago
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.
4 years ago
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).
4 years ago
rishflab 51760041f0 Remove duplicated macro definitions 4 years ago
rishflab 8754a9931b Execute Alice and Bob state machines concurrently
Previously we were testing the protocol by manually driving Alice and
Bob's state machines. This logic has now be moved to an async state
transition function that can take any possible state as input. The
state transition function is called in a loop until it returns the
desired state. This allows use to interrupt midway through the protocol
and perform refund and punish tests. This design was chosen over a
generator based implementation because the the generator based
implementation results in a impure state transition function that is
difficult to reason about and prone to bugs.

Test related code was extracted into the tests folder.

The 2b and 4b states were renamed to be consistent with the rest.

Macros were used to reduce code duplication when converting
child states to their parent states and vice versa.

Todos were added were neccessary.
4 years ago
Lucas Soriano del Pino 1f99cf001c Swap Monero for Bitcoin
Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
Co-authored-by: Tobin C. Harding <tobin@coblox.tech>
4 years ago