Commit Graph

46 Commits

Author SHA1 Message Date
Franck Royer
1a4bd0e2b4
Bob refunds swap after restart that requires communication
As Bob is dialing Alice, we now ensure that we are connected to Alice
at each step that needs communication.
If we are not connected, we proceed with dialing.

In an attempt to improve libp2p usage, we also add known address of
Alice first and only use peer_id to dial.
This ensures that we use the expected peer id.
2020-12-21 08:31:21 +11:00
Franck Royer
71cf501c29
Delete bob::negotiate
This module was intended to contain helper functions for each step.

However, those are not needed except for the negotiate step.
A dedicated module is not needed for one function.
2020-12-15 16:53:50 +11:00
rishflab
143d8bc07d
Move message0 response handler out of NB 2020-12-15 11:43:24 +11:00
Franck Royer
ef6e8fc723
Clean-up unused code 2020-12-10 14:28:54 +11:00
rishflab
9ba89194b0 Rename swarm driver to event loop 2020-12-10 13:29:53 +11:00
rishflab
6f7408ecce Drive swarm in seperate async task
Previously the libp2p swarm had to be manually polled within the
protocol execution code to execute actions such as sending a
message. The swarm is now wrapped in SwarmDriver which polls the
swarm in a seperate task
2020-12-10 11:24:05 +11:00
rishflab
24631d464d Add test for recursive executor 2020-11-30 15:13:20 +11:00
rishflab
3b005bd15c Resolve rebase issues, restructure code and fix warnings 2020-11-30 15:13:20 +11:00
Franck Royer
c4cd64d134 Implemented Alice transition from Started to Negotiated 2020-11-27 09:34:35 +11:00
rishflab
ae94b170fd Cleanup
Move state machine executors into seperate files

Remove check for ack message from Alice. Seems like a bad idea to
rely on an acknowledgement message instead of looking at the
blockchain.

Fix warnings
2020-11-27 09:34:35 +11:00
rishflab
ff7daf16f3 WIP: Test simplified swap execution 2020-11-27 09:21:21 +11:00
rishflab
dd07e2f882 Add Alice execution path
Consolidate and simplify swap execution. Generators are no longer
needed. Consolidate recovery and swap data structures. The
recursive calls can be replaced with a loop if returning prior to
completion is desired for testing purposes.

Fill out alice abort path

Move state machine executors into seperate files

Not compiling due to recursion/async issues

Fix async recursion compilation errors

Fix Bob swap execution

Remove check for ack message from Alice. Seems like a bad idea to
rely on an acknowledgement message instead of looking at the
blockchain.

Fix Bob abort

Fix warnings

Xmr lock complete

Add TxCancel submit to XmrLocked

Bob swap completed

Remove alice
2020-11-27 09:21:21 +11:00
Lucas Soriano del Pino
f5ff50157e Some more fixes and comments after testing Alice's recovery 2020-11-12 13:49:07 +11:00
Lucas Soriano del Pino
33a111d879 Move Swap state out of storage 2020-11-12 13:49:07 +11:00
Lucas Soriano del Pino
f9cfc2abe3 Remove generics from Database 2020-11-12 13:49:07 +11:00
Lucas Soriano del Pino
02075c2a1d Support saving multiple swaps
By replacing `LAST_STATE_KEY` with a swap ID passed as an argument to
inserting and reading from the database.
2020-11-12 13:49:07 +11:00
Lucas Soriano del Pino
934ddb366a Save state for Alice at specific points in the swap 2020-11-12 13:49:07 +11:00
rishflab
ea08778b2f Save state for Bob at specific points in the swap 2020-11-12 13:49:07 +11:00
rishflab
a44303f839 Add monerod to config
Fixed rebase issues
2020-11-03 16:08:46 +11:00
rishflab
5971ef1f28 Fix clippy warnings 2020-11-03 15:13:23 +11:00
rishflab
796d0b3439 Extract transport creation and remove tor conditional compile
The numerous tor conditional compile flags were removed by
extracting transport creation to the main statement. A tor
transport is created if Alice specifies a tor port using the CLI.
2020-11-03 15:12:52 +11:00
Lucas Soriano del Pino
7fa7641feb Clean up some logs and comments 2020-10-30 15:51:46 +11:00
Tobin C. Harding
4d4acde476 Bubble up an event when Bob receives message 3 response
Before this patch Bob is not sending message 3. This is because we are not
polling Bob's swarm correctly. To fix it we can just mimic the other NB's and
bubble up an event when Bob receives message 3 response from Alice, this way we
can `await` upon this event which triggers polling, making Bob's swarm send the
message.
2020-10-30 14:07:15 +11:00
Lucas Soriano del Pino
a37f43a1ba wip: Provide enough funds to both parties
Also use cosntant backoff retry strategy as opposed to exponential
backoff. This is in case retrying several times quickly causes the
retry intervals to become large enough that the test is very slow
and/or the Bitcoin lock transaction expires.

The current problem occurs on the last message i.e. Bob sending
tx_redeem_encsig to Alice. The action is yielded for Bob to do it, but
Alice appears to never receive it (unconfirmed claim, requires more
logging).
2020-10-30 14:07:15 +11:00
Lucas Soriano del Pino
eb6bbe6180 wip: Fix bug where bob was sending two amount request 2020-10-30 14:05:45 +11:00
Lucas Soriano del Pino
ae87c10cae wip: fixed message0 2020-10-30 14:05:45 +11:00
Tobin C. Harding
c464555f5e Enable trace output 2020-10-30 14:04:27 +11:00
Lucas Soriano del Pino
9384b0cf3c [WIP] Swap app e2e test 2020-10-30 14:04:27 +11:00
Lucas Soriano del Pino
9e30bd5151 Generate addresses as late as possible 2020-10-30 14:04:27 +11:00
Lucas Soriano del Pino
3f43581da7 Implement traits Receive{BitcoinRedeemEncsig, TransferProof}
Unfortunately, I had to put the wrap the swarm in Alice's `Network`
struct in an `Arc<Mutex<T>>` in order to be able to use `backoff` to
control the retry mechanism. This is because the stream of events
cannot be turned into a `SharedFuture` (unlike Bob's).

It would be good to find an alternative solution.
2020-10-30 14:03:27 +11:00
Lucas Soriano del Pino
a4e4c27bee Execute Bob's on-chain protocol after handshake
Co-authored-by: Tobin C. Harding <tobin@coblox.tech>
2020-10-30 14:03:27 +11:00
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
Philipp Hoenisch
8811a0a205
Add Tor to main 2020-10-27 15:03:59 +11:00
Tobin C. Harding
b22f265cf3 Send back an empty response to Message2
Alice does not respond with anything when receiving message 2 from Bob. We don't
want to leave Bob's request/response protocol waiting so send an empty response
back.
2020-10-27 10:26:54 +11:00
Tobin C. Harding
194a19cf1d Add todos 2020-10-27 10:26:51 +11:00
Tobin C. Harding
6be5d64c1c Remove stale, ugly, type conversion 2020-10-27 10:26:46 +11:00
Tobin C. Harding
cbccc282ef Send Message2 from Bob to Alice
In order for Alice to complete the handshake she needs to transition to state 3,
for this she needs message 2 from Bob.

Send `bob::Message2` to Alice and transition to `State3` - completing the
handshake.
2020-10-26 14:30:41 +11:00
Tobin C. Harding
6e34f9c978 Use const TIMEOUT instead of an argument 2020-10-22 14:12:49 +11:00
Tobin C. Harding
ad006fae6a Do a bunch of cleanups 2020-10-22 13:35:55 +11:00
Tobin C. Harding
0f17ec076c Add message1 2020-10-22 13:23:12 +11:00
Tobin C. Harding
ad0d8d5713 Emit message0 out of NB (both parties) 2020-10-22 11:04:49 +11:00
Tobin C. Harding
bb94643943 Remove data from message until Message0 impl serde 2020-10-22 09:58:22 +11:00
Tobin C. Harding
e7504de76c Add state0 -> state1 messages 2020-10-21 15:02:52 +11:00
Tobin C. Harding
aaf1363c05 Refine peer tracker and amounts protocol
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
2020-10-21 10:11:24 +11:00
Tobin C. Harding
47eaa44f76 Remove unneeded From<Never> impl 2020-10-21 10:11:24 +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