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>
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.
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.
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>
143: Upgrade to tokio 1.0 r=D4nte a=rishflab
When we were refactoring tests we realised we probably want the ability to abort a `tokio::JoinHandle` to kill the `EventLoop` to simulate a real world crash. tokio 1.0 is needed for this. It is probably about time to upgrade tokio anyway.
In order to upgrade to tokio 1.0 the following dependencies were also upgraded in the swap crate and monero-harness-rs
* backoff
* libp2p
* request
UPDATE: This should be merged until the following dependencies are uprgraded to Tokio 1.0 or Tokio compat is used
- [x] bitcoin-harness-rs https://github.com/coblox/bitcoin-harness-rs/pull/20
Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Franck Royer <franck@coblox.tech>