We model the getting of amounts as a network behaviour even though conceptually
it is a protocol. Refine/refactor the code a bit to make this more obvious.
- Use `Amounts` instead of `Messenger`
We only ever connect to a single peer, update peer tracker to reflect this. This
is a single patch because the handling of the two network behaviours is a
intertwined.
- Only track one peer connection
- Track the peer id and the multiaddr of the counterparty
- Emit an event for connection established on Alice's side as well as Bob's side
- 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.
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.
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.
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.
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)
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.
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.
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).
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.
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.