Commit Graph

952 Commits

Author SHA1 Message Date
Franck Royer
b5b990257a
Move Behaviour in dedicated module 2021-02-10 16:42:54 +11:00
Franck Royer
87be9aeb2a
Prepare separation of event loop initialisation to swap initialisation
As for Alice, the event loop will be started with the program and will
be the one starting swaps (`run_until`) based on libp2p events (swap
request).
2021-02-10 16:42:54 +11:00
Franck Royer
530b9b2ea8
Remove possible mix up of timelocks when using State0::new 2021-02-10 16:42:53 +11:00
Franck Royer
f35ed436ce
Allow EventLoop to hold a database ready to pass to alice::Buider
The `EventLoop` will use the `Builder` interface to instantiate a
`Swap` upon receiving a `SwapRequest` and successfully doing an
execution setup.
Before this change, the `EventLoop` would have to hold the path to the
db and re-open the db everytime it wants to construct a swap.

With this change, we can open the DB once and then hold a
`Arc<Database>` in the `EventLoop` and pass it to new `Swap`s structs.
2021-02-10 16:42:53 +11:00
Franck Royer
39a46baa2c
Preemptively box cancel tx to avoid size difference in enum 2021-02-10 16:42:53 +11:00
Franck Royer
69363e43a3
Preemptively box encrypted signature to avoid size difference in enum 2021-02-10 16:42:53 +11:00
Franck Royer
fd084b764d
Move generation of keys inside State0::new
The event loop will now use this function so I want to simplify its
usage to avoid having to instantiate too many items to use it.
2021-02-10 16:42:53 +11:00
Franck Royer
788445964a
Move main.rs to cli.rs to prepare for nectar binary 2021-02-10 16:42:51 +11:00
Franck Royer
311ba74cd6
Remove sell-xmr from CLI 2021-02-10 16:41:38 +11:00
bors[bot]
639b3169d8
Merge #179
179: Watch only tmp monero wallet r=da-kami a=da-kami

When initializing Monero wallet, try to open temporary wallet, if opening errors then try to create it. If creating errors then fail with message asking the user to configure the wallet RPC.
If opening / creation succeeds get the block_height to verify that connection to wallet works, then proceed to swap. 

Note: RPC error handling is hacky, but I don't see the value of investing time into that at this point. The problem is, that we don't deal with the json rpc errors properly for calls were we don't serialize the result into an object (because the response is empty). Eventually we should switch to using https://github.com/thomaseizinger/rust-jsonrpc-client but that does not support parameters `by-name` yet, see: https://github.com/thomaseizinger/rust-jsonrpc-client/issues/20

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-10 04:09:11 +00:00
Daniel Karzel
56a59bc41c Remove newline in use statements 2021-02-10 15:07:37 +11:00
Daniel Karzel
0a0bce1552 Rename temporary wallet to blockchain monitoring wallet 2021-02-10 15:06:26 +11:00
Daniel Karzel
1e29433bd2 Open or create temporary Monero wallet upon wallet initialization 2021-02-09 16:34:50 +11:00
Daniel Karzel
dac4443bbd Add functionality to open monero wallet through rpc 2021-02-09 16:34:50 +11:00
Daniel Karzel
62605a318a Add CreateWallet trait to expose create_wallet 2021-02-09 16:34:50 +11:00
bors[bot]
27bb9498d5
Merge #170
170: Cancel and refund commands r=da-kami a=da-kami

I plugged the cancel and refund logic into the current state/state-machine logic of the swap.

## Follow ups  (out of scope)

We might want to record issues to be tackled later, since we are on a tight time budget :)
Please let me know what you think @D4nte @rishflab 

### Problems with `ack` after sending a message

Alice was waiting forever when awaiting the `ack` from bob when sending the lock proof in case she runs into a dial error. It seems the `acks` can cause the program to hang. This is a severe problem that we most probably will encountered in production at some point. For this PR I wrapped the `ack` of Alice upon sending the `encsig` in a timeout to work around this problem, see 7463081f88 - but **we might want to consider to remove all `ack` message. I don't see much value in them if we don't have a resilient retry strategy.**

### Do not require Monero wallet for cancel/refund

The cancel/refund commands don't require a monero wallet.
In this PR we re-uses the builder which requires the monero wallet as well - and we check for the monero balance upon wallet initialization, so the command will fail if no monero wallet is started.

### Save Alice connection info in Bob DB

Save Alice's peer-id/address in DB: It's cumbersome for the user to lookup those details again.




Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-09 02:40:47 +00:00
Daniel Karzel
53fcd9224c Give finding the refund tx priority over waiting for the punish transaction to be finalized.
This was introduced due to a CI run, where Bob included tx_refund, but Alice had waited until T2 had expired,
and then went for punishing Bob instead of refunding.
Weirdly, Alice's punich transaction did not fail in that scenario.
2021-02-09 12:13:43 +11:00
Daniel Karzel
86290649e7 work in review comments 2021-02-08 21:20:58 +11:00
Daniel Karzel
c930ad84a4 Add --force flag for cancel and refund 2021-02-08 21:19:38 +11:00
Daniel Karzel
02f8eb7f18 Add test for cancel/refund before timelock expired 2021-02-08 21:18:37 +11:00
Daniel Karzel
2d5d70d856 Timeout for Alice waiting for ack for sending transfer proof
If dialing Bob fails Alice waits for the acknowledgement of the transfer proof indefinitely.
The timout prevents her execution from hanging.
Added a ToDo to re-visit the ack receivers. They don't add value at the moment and should be removed.
2021-02-08 21:18:37 +11:00
Daniel Karzel
c9adbde5d5 Add test for Bob's manual cancel and refund 2021-02-08 21:17:56 +11:00
Daniel Karzel
ad2aefc2a5 Refund Command 2021-02-08 21:16:32 +11:00
Daniel Karzel
0600a7048e Cancel command 2021-02-08 21:11:39 +11:00
bors[bot]
ec661178f4
Merge #173
173: Use libp2p-async-await to improve API of execution setup phase r=D4nte a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
2021-02-07 22:17:11 +00:00
Franck Royer
dee8c1e335
Remove scopes 2021-02-08 09:16:31 +11:00
Franck Royer
a48823a665
Re-organise Alice state to be more coherent with the msg sequence 2021-02-08 09:16:31 +11:00
Franck Royer
eefb1b3b16
Use event_process = false for Bob
As we do not process the event, we can just implement the needed `From`
traits.
2021-02-08 09:16:31 +11:00
Franck Royer
a7b89e2fe4
Use event_process = false for Alice
As we do not process the event, we can just implement the needed `From`
traits.
2021-02-08 09:16:29 +11:00
Franck Royer
554ae6c00e
Remove Request Response types
These are actually not needed and forces us to cater for variants when
processing requests and responses.
2021-02-08 09:15:21 +11:00
Franck Royer
5a5a1c05f7
Set appropriate name to codec 2021-02-08 09:15:21 +11:00
Franck Royer
a11e894b31
Prepend all libp2p protocols with "comit" 2021-02-08 09:15:21 +11:00
Franck Royer
cfc5cb5206
Remove dead code and combine swap request & one shot codecs 2021-02-08 09:15:20 +11:00
Franck Royer
fc2d8d3861
Rename alice::Message0 to Message0
There is now only one message0
2021-02-08 09:15:20 +11:00
Franck Royer
88bf080dc0
rename alice::Message0 to Message1 2021-02-08 09:15:20 +11:00
Franck Royer
18f326ddd1
Rename bob::Message1 to Message2
As per sequence diagram.
2021-02-08 09:15:20 +11:00
Franck Royer
0d1be52966
Rename alice::Message1 to Message3
As per sequence diagram.
2021-02-08 09:15:20 +11:00
Franck Royer
e74efd38b5
Rename bob::Message2 to Message4
As per sequence diagram.
2021-02-08 09:15:20 +11:00
Franck Royer
081237bb6f
Remove unused behaviours 2021-02-08 09:15:20 +11:00
Franck Royer
ecb54958ee
Preemptively Box few messages 2021-02-08 09:15:19 +11:00
Franck Royer
3fa4ffa82c
Implement new behaviour for execution setup 2021-02-05 16:42:46 +11:00
Franck Royer
9ae050abf8
Use correct variable name 2021-02-05 16:42:33 +11:00
Franck Royer
c316ea5244
Upgrade toolchain
Needed to use libp2p-async-await
2021-02-04 15:18:33 +11:00
Franck Royer
e82383bcf6
Avoid carrying rng 2021-02-04 15:18:33 +11:00
Philipp Hoenisch
25bf5df122
Merge pull request #172 from comit-network/dead-code
Remove dead code
2021-02-04 13:55:02 +11:00
bors[bot]
f0bf294689
Merge #171
171: Use correct default data directory r=da-kami a=da-kami

Nasty copy-paster 😬

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-04 01:42:16 +00:00
Philipp Hoenisch
8743527df9
Remove dead code 2021-02-03 14:26:36 +11:00
Daniel Karzel
b27363e386 Use correct default data directory 2021-02-02 20:36:58 +11:00
bors[bot]
5fe8f3108a
Merge #161
161: Introduce configuration file and initial setup through CLI r=da-kami a=da-kami

PRs chained on top of this one:

- [x] https://github.com/comit-network/xmr-btc-swap/pull/163 Configurable config with `--config` option on CLI (we will need this for swaps with ourselves...)
- [x] ~~https://github.com/comit-network/xmr-btc-swap/pull/165 Reset config with `--reset-config` option on CLI (this makes it easier for the user to clean up)~~
- [x] https://github.com/comit-network/xmr-btc-swap/pull/166 data-dir, in accordance to config-dir, should be pointed to the appropriate default directory using `directory-next`

Looks n' feel:

Initial startup:

```
2021-01-28T01:35:45.000205Z  INFO swap::trace: Initialized tracing with level: INFO
2021-01-28T01:35:45.001286Z  INFO swap: Database and Seed will be stored in directory: /Users/dakami/CoBloX/TEMP/swap-data-dir/alice
2021-01-28T01:35:45.003391Z  INFO swap::config::seed: Read in seed from file: /Users/dakami/CoBloX/TEMP/swap-data-dir/alice/seed.pem
2021-01-28T01:35:45.003603Z  INFO swap::config: Config file not found, running initial setup...

? Enter Bitcoind URL (including username and password if applicable) or hit return to use default (http://127.0.0.1:18332) › http://dakami:xkz4nyywpKf3BigwKIRdVijmWzaHCOmUisepQpDlsXnhpNd6uO@127.0.0.1:18332/
✔ Enter Bitcoind URL (including username and password if applicable) or hit return to use default · http://dakami:xkz4nyywpKf3BigwKIRdVijmWzaHCOmUisepQpDlsXnhpNd6uO@127.0.0.1:18332/
? Enter Bitcoind wallet name › alice
✔ Enter Bitcoind wallet name · alice
? Enter Monero Wallet RPC URL or hit enter to use default (http://127.0.0.1:38083/json_rpc) › 
✔ Enter Monero Wallet RPC URL or hit enter to use default · http://127.0.0.1:38083/json_rpc

2021-01-28T01:35:58.553401Z  INFO swap::config: Initial setup complete, config file created at /Users/dakami/Library/Application Support/xmr-btc-swap/config.toml 
2021-01-28T01:35:58.647761Z  INFO swap: Connection to Bitcoin wallet succeeded, balance: 0.00744521 BTC
2021-01-28T01:35:58.650060Z  INFO swap: Connection to Monero wallet succeeded, balance: 29.095359550000 XMR
2021-01-28T01:35:58.650258Z  INFO swap: Swap sending 0.030000000000 XMR and receiving 0.00060000 BTC started with ID e07b2cc1-3749-48fd-931a-6cbaf57b8124
2021-01-28T01:35:59.004306Z  INFO swap::protocol::alice::swap: Current state:started
```

After:
```
2021-01-28T01:36:57.881654Z  INFO swap::trace: Initialized tracing with level: INFO
2021-01-28T01:36:57.882691Z  INFO swap: Database and Seed will be stored in directory: /Users/dakami/CoBloX/TEMP/swap-data-dir/alice
2021-01-28T01:36:57.884171Z  INFO swap::config::seed: Read in seed from file: /Users/dakami/CoBloX/TEMP/swap-data-dir/alice/seed.pem
2021-01-28T01:36:57.884353Z  INFO swap::config: Using config file at default path: /Users/dakami/Library/Application Support/xmr-btc-swap/config.toml
2021-01-28T01:36:57.996153Z  INFO swap: Connection to Bitcoin wallet succeeded, balance: 0.00744521 BTC
2021-01-28T01:36:57.998648Z  INFO swap: Connection to Monero wallet succeeded, balance: 29.095359550000 XMR
2021-01-28T01:36:57.998928Z  INFO swap: Swap sending 0.030000000000 XMR and receiving 0.00060000 BTC started with ID 08dd6dc1-9460-4c0a-91ef-a05df309b6ed
2021-01-28T01:36:58.353738Z  INFO swap::protocol::alice::swap: Current state:started
```

Command:

```
run --package swap --bin swap -- 
  --data-dir /Users/dakami/CoBloX/TEMP/swap-data-dir/alice 
  sell-xmr 
    --receive-btc 0.0006 
    --send-xmr 0.03
```

Co-authored-by: Daniel Karzel <daniel@comit.network>
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
2021-01-31 23:41:35 +00:00
Daniel Karzel
110fc9bbd7
Merge pull request #168 from comit-network/rename-config
Rename config
2021-02-01 10:41:03 +11:00