Commit Graph

888 Commits

Author SHA1 Message Date
Daniel Karzel
af60d3bb54
Network check upon spot price request 2021-05-20 13:03:29 +10:00
Daniel Karzel
02974811ad
Activate mainnet for the ASB
To run the ASB on testnet, one actively has to provide the `--testnet` flag.
Mainnet and testnet data and config are separated into sub-folders, i.e. `{data/config-dir}/asb/testnet` and `{data-dir}/asb/mainnet`.
The initial setup is also per network. If (default) config for the network cannot be found the initial setup is triggered.
Startup includes network check to ensure the bitcoin/monero network in config file is the same as the one in the `env::Config`.

Note: Wallet initialization is done with the network set in the `env::Config`, the network saved in the config file is just to indicate what network the config file is for.
2021-05-20 12:58:39 +10:00
Daniel Karzel
9ac5b635d7
Introduce own de-/serializable monero::Network 2021-05-20 12:58:30 +10:00
Daniel Karzel
69cf12620d
Activate mainnet for the CLI
This includes testing CLI commandline args
Clap's `default_value_with` actually did not work on `Subcommand`s because the parent's flags were not picked up.
This was fixed by changing parameters dependent on testnet/mainnet to options.
This problem should have been detected by tests, that's why the command line parameter tests were finally (re-)added.

Thanks to @rishflab for some pre-work for this.
2021-05-20 12:57:58 +10:00
Daniel Karzel
1cdc23de32
Explicitly specify monero-wallet-rpc deamon port
In order to allow people to plug into public nodes / be more flexible with their own setup we now enforce specifying the monero daemon port to be used by the `monero-wallet-rpc`.
2021-05-14 09:50:52 +10:00
Daniel Karzel
343badbb4b
Remove duplication and cleanup
In the past we had problems with flags/parameter changes several times, where on instance was changed, buy another one was missed. This should mitigate this problem.
This patch introduces structs for all duplicated parameters and uses flatten to only have one point for changes.

Additionally removes all mentions of `alice` from the commands / variables. This code is on an application level and should not be concerned with swap protocol roles.
2021-05-14 09:50:50 +10:00
Daniel Karzel
4e1f3f82bd
Remove param from names
Did not add any value, more readable with just bitcoin and monero.
2021-05-14 09:50:49 +10:00
Daniel Karzel
657ac1e2e4
Bitcoin parameters that can be reused
Get rid of parameter duplication.
2021-05-14 09:50:47 +10:00
Daniel Karzel
a489564857
Remove unused Electrum HTTP default URL 2021-05-14 09:50:44 +10:00
Philipp Hoenisch
493545d07f
Improve logging for Swap Cli. 2021-05-12 16:31:32 +10:00
Philipp Hoenisch
4f45a26a83
Move check for max_giveable into the function. 2021-05-12 16:31:32 +10:00
Philipp Hoenisch
7fc5a47619
Add checks to max_giveable amount.
We need to check two things:
- balance to be higher than dust amount (546).
- balance to be higher than min-relay fee.

Additionally, the tx_builder might fail if not enough funds are in the wallet to pay for the overall transaction fees.
2021-05-12 16:31:32 +10:00
Philipp Hoenisch
26e0383e17
Apply suggestions from code review
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
2021-05-11 16:06:44 +10:00
Philipp Hoenisch
fc0cceb180
Toggle json logs using commandline flag. 2021-05-11 15:28:25 +10:00
Philipp Hoenisch
316f95c65b
Always log whole causality chain for errors. 2021-05-11 15:27:53 +10:00
Philipp Hoenisch
c011e95062
Improve logging by adding details as fields instead of into the msg. 2021-05-11 15:27:53 +10:00
Philipp Hoenisch
1706b36800
Log exchange rate at each state. 2021-05-11 15:27:49 +10:00
bors[bot]
227c383d76
Merge #481
481: Min buy amount r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-05-11 04:08:59 +00:00
Daniel Karzel
652aae9590
Introduce a minimum buy amount
Introduces a minimum buy Bitcoin amount similar to the maximum amount already present.
For the CLI the minimum amount is enforced by waiting until at least the minimum is available as max-giveable amount.
2021-05-11 12:03:02 +10:00
Daniel Karzel
6d3cf0af91
Include too low balance into Alice's error 2021-05-11 12:03:02 +10:00
Daniel Karzel
1d62f4916c
Move max_buy and ask_spread into config
Max-buy and spread is not something that one would configure on every run.
More convenient to keep this in the config.

The max-buy Bitcoin value was adapted to `0.02` which is more reasonable for mainnet.
Activated feature `serde-float` to serialize the spread (Decimal) as float instead of string.

```
...

[maker]
max_buy_btc = 0.02
ask_spread = 0.02
```
2021-05-11 12:02:57 +10:00
Philipp Hoenisch
330269a1e9
Update assert_weight test to account for a range up to 8 bytes.
Weights fluctuate because of the length of the signatures. Valid ecdsa signatures can have 68, 69, 70, 71, or 72 bytes. Since most of our transactions have 2 signatures the weight can be up to 8 bytes less than the static weight (4 bytes per signature).
2021-05-11 10:50:24 +10:00
Daniel Karzel
538b25a6dd
Only create config-directory on init success
We should only create the file if the user finished the initial setup correctly.
2021-05-11 10:32:25 +10:00
bors[bot]
d96e20a5b0
Merge #479
479: Use rust_decimal in estimate_fee function. r=bonomat a=bonomat

Follow-up PR from #466 

Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
2021-05-10 23:00:12 +00:00
Philipp Hoenisch
b5073e3052
Use rust_decimal in estimate_fee function. 2021-05-10 10:53:43 +10:00
Daniel Karzel
23d9637a4b
Work in review comments 2021-05-07 16:21:02 +10:00
Daniel Karzel
daa572e5bf
Move recovery commands in dedicated module
Less clutter in the folder structure.
2021-05-07 16:21:02 +10:00
Daniel Karzel
4deb96a3c5
ASB manual recovery commands
Adds `cancel`, `refund`, `punish`, `redeem` and `safely-abort` commands to the ASB that can be used to trigger the specific scenario for the swap by ID.
2021-05-07 16:19:11 +10:00
Daniel Karzel
efcd39eeef
Add info messages to each subcommand
`asb --help` :

(...)

SUBCOMMANDS:
    balance         Prints the Bitcoin and Monero balance. Requires the monero-wallet-rpc to be running.
    help            Prints this message or the help of the given subcommand(s)
    history         Prints swap-id and the state of each swap ever made.
    start           Main command to run the ASB.
    withdraw-btc    Allows withdrawing BTC from the internal Bitcoin wallet.
2021-05-07 16:12:50 +10:00
Daniel Karzel
0c616c7437
Move loading the state into the function
In the production code it is a weird indirection that we load the state and then pass in the state and the database.
In the tests we have one additional load by doing it inside the command, but loading from the db is not expensive.
2021-05-07 16:12:49 +10:00
Daniel Karzel
89b3d07eba
Network protocol tests for spot_price behaviour
Each test spawns swarm for Alice and Bob that only contains the spot_price behaviours and uses a memory transport.
Tests cover happy path (i.e. expected price is returned) and error scenarios.
Implementation of `TestRate` on `LatestRate` allows testing rate fetch error and quote calculation error behaviour.

Thanks to @thomaseizinger for ramping up the test framework for comit-rs in the past!
2021-05-07 15:00:29 +10:00
Daniel Karzel
03a0dc73cd
Alice's spot_price Behaviour reports back Error
Instead of handling all errors on the inside spot_price errors are bubbled up (as `SwapRequestDeclined`).
This allows us to test both Alice's and Bob's behaviour for all scenarios.
2021-05-07 15:00:29 +10:00
Daniel Karzel
5aac76598d
Decouple ASB/CLI Errors from Error sent over wire
What goes over the wire should not be coupled to the errors being printed.
For the CLI and ASB we introduce a separate error enum that is used for logging.
When sending over the wire the errors are mapped to and from the `network::spot_price::Error`.

As part of Bob-specific spot_price code was moved from the network into bob.
Clearly separation of the network API from bob/alice.
2021-05-07 15:00:29 +10:00
Daniel Karzel
52f648e1de
Alice's spot price logic into dedicated behaviour
Move Alice's spot price logic into a dedicated network behaviour that handles all the logic.
The new behaviour encapsulates the complete state necessary for spot price request decision making.
The network behaviour cannot handle asynchronous calls, thus the balance is managed inside the spot price and has to updated regularly from the outside to ensure the spot price balance check has up to date data.
At the moment the balance is updated upon an incoming quote requests.

Code that is relevant for both ASB and CLI remains in the `network::spot_price` module (e.g. `network::spot_price::Error`).
2021-05-07 15:00:29 +10:00
Daniel Karzel
ea76ae5821
Return proper error to CLI for all expected scenarios
When a CLI requests a spot price have some errors that are expected, where we can provide a proper error message for the CLI:
- Balance of ASB too low
- Buy amount sent by CLI exceeds maximum buy amount accepted by ASB
- ASB is running in maintenance mode and does not accept incoming swap requests

All of these errors returns a proper error to the CLI and prints a warning in the ASB logs.
Any other unexpected error will result in closing the channel with the CLI and printing an error in the ASB logs.
2021-05-07 14:52:51 +10:00
Daniel Karzel
f6497778ed
Add resume-only mode for the ASB
Resume-only is a maintenance mode where no swaps are accepted but unfinished swaps are resumed.
This is achieve by ignoring incoming spot-price requests (that would lead to execution setup) in the event-loop.
2021-05-07 14:52:51 +10:00
Philipp Hoenisch
0090e3b48e
Typo 2021-05-07 10:35:22 +10:00
Philipp Hoenisch
59a55dcbdd
Remove todo for cleanup note. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
e93eeb81a2
Added some proptests. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
040cce1eb6
Format all the files 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
68ae47edf4
Log error message. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
aebdb063f1
Remove TODO 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
9fb1a43f29
Rename variable. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
cfdbacfbb5
Add comment.
The weight of our transactions can fluctuate by +-2 wu because our transactions have 2 signatures
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
e69a2c9111
Apply suggestions from code review
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
dc8dd5af28
Add relative and absolute max transaction fee. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
dc6ab0fa52
Ensure that constant weights do not go out of sync with code. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
7fe9087bc2
Pull trait-bounds up one level for easier testing. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
77f6f11a7f
Pass address/fees into State0 instead of passing in the wallet. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
14c5a4f025
Add upper bound for bitcoin fees of 100,000 satoshi.
Fees are hard to compute and it is too easy to get wrong and lose a lot of money. Hence, a hardcoded maximum of 100,000 satoshi for a single transaction is in place.
2021-05-07 10:24:41 +10:00