Commit Graph

341 Commits (ada5acb2b5f4ea7844a85987e4a62c56bc539e10)

Author SHA1 Message Date
Daniel Karzel 529de8d5fd
ASB aborts if CLI does not lock BTC
Includes a new state that is used to await BTC lock tx finality. Upon starting the swap we initially only wait for the BTC lock tx to be seen in the mempool.
This is guarded by a short timeout (3 mins), because it is assumed that in the current setup (sport_price + execution_setup only triggered upon funds being available already) the lock transaction should be picked up almost instanly after the execution setup succeeded.
3 years ago
Daniel Karzel c4c798ea20
Timeout on `execution_setup` for ASB
Similar to the CLI the ASB has to ensure that the execution_setup is executed within a certain time.
Without a timeout the price (returned by `spot_price` would be guaranteed with the CLI indefinitely.
3 years ago
Daniel Karzel 1ae377ef24
Request timeout when swapping over Tor
It seems the current chosen channel timeouts are still not optimal.
I ran into issues with swapping over Tor and traced them down to the CLI timeout of the bmrng channel.
It appears that the ASB was not running as quick as the CLI, which caused a timeout on the CLI side (in addition to the delay when sending messages over Tor).
Only `execution_setup` caused the problem so far, but I would recommend changing all the channel timeouts to one minute to avoid this problem.
3 years ago
Thomas Eizinger ac0b0150e6
Upgrade to Rust 1.53
Also fix all clippy lints that came up.
3 years ago
Thomas Eizinger b7064578ca
Reduce level of indentation of match statements 3 years ago
Thomas Eizinger f1182f97c0
Simplify match statement
This code is unnecessarily complicated.
3 years ago
Thomas Eizinger 1ba186aa63
Make log message a proper statement
"Listening on" is only half a sentence.
3 years ago
bors[bot] baf5a0896e
Merge #536
536: Switch to using stable Rust instead of nightly r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Daniel Karzel c9064d5a37
Add ping protocol to ensure connection is alive
Adds the ping behaviour to both ASB and CLI behaviour that periodically pings a connected party to ensure that the underlying network connection is still alive.
This fixes problems with long-running connections that become dead without a connection closure being reported back to the swarm.
3 years ago
Thomas Eizinger 8f9d612af2
Change to stable Rust 1.52
Fix clippy warnings that are new in this version.
3 years ago
Daniel Karzel 01af9a5676
Bitcoin transaction published state
This improves the error handling on the ASB.
Once the Bitcoin redeem transaction is seen in mempool, the state machine cannot transition to a cancel scenario anymore because at that point the CLI will have redeemed the Monero.
The additional state then waits for transaction finality.
3 years ago
Daniel Karzel fb9fb21c2b
CLI log statements to be more JSON friendly
Values to be logged as fields.
Upon starting a swap we print the swap-id as well.
3 years ago
Daniel Karzel af60d3bb54
Network check upon spot price request 3 years ago
Philipp Hoenisch 316f95c65b
Always log whole causality chain for errors. 3 years ago
Philipp Hoenisch c011e95062
Improve logging by adding details as fields instead of into the msg. 3 years ago
Philipp Hoenisch 1706b36800
Log exchange rate at each state. 3 years ago
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.
3 years ago
Daniel Karzel 6d3cf0af91
Include too low balance into Alice's error 3 years ago
Daniel Karzel 23d9637a4b
Work in review comments 3 years ago
Daniel Karzel daa572e5bf
Move recovery commands in dedicated module
Less clutter in the folder structure.
3 years ago
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.
3 years ago
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.
3 years ago
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!
3 years ago
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.
3 years ago
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.
3 years ago
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`).
3 years ago
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.
3 years ago
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.
3 years ago
Philipp Hoenisch 59a55dcbdd
Remove todo for cleanup note. 3 years ago
Philipp Hoenisch 68ae47edf4
Log error message. 3 years ago
Philipp Hoenisch dc8dd5af28
Add relative and absolute max transaction fee. 3 years ago
Philipp Hoenisch dc6ab0fa52
Ensure that constant weights do not go out of sync with code. 3 years ago
Philipp Hoenisch 7fe9087bc2
Pull trait-bounds up one level for easier testing. 3 years ago
Philipp Hoenisch 77f6f11a7f
Pass address/fees into State0 instead of passing in the wallet. 3 years ago
Philipp Hoenisch 9e8b788aa9
Rename weight constants. 3 years ago
Philipp Hoenisch ee90c228b4
Dynamically calculate fees using electrum's estimate_fee.
Electrum has an estimate-fee feature which takes as input the block you want a tx to be included.
The result is a recommendation of BTC/vbyte.
Using this recommendation and the knowledge about the size of our transactions we compute an appropriate fee.
The size of the transactions were taken from real transactions as published on bitcoin testnet.
Note: in reality these sizes might fluctuate a bit but not for much.
3 years ago
Philipp Hoenisch 38540b4de5
Dynamically chose fee for TxCancel.
Bob chooses the fee for TxCancel because he is the one that cares.
3 years ago
Philipp Hoenisch 1012e39527
Dynamically chose fee for TxRefund and TxPunish.
Alice chooses the fee for TxPunish because she is the one that cares.
Bob chooses the fee for TxRefund because he is the one that cares.

Note must be taken here because if the fee is too low (e.g. < min tx fee) then she might not be able to publish TxRedeem at all.
3 years ago
Philipp Hoenisch d5c1b6693e
Dynamically chose fee for TxRedeem.
Alice chooses the fee for TxRedeem because she is the one that cares. Note must be taken here because if the fee is too low (e.g. < min tx fee) then she might not be able to publish TxRedeem at all.
3 years ago
Philipp Hoenisch 1db7586632
Increase timeout sending/receiving protocol messages. 3 years ago
Daniel Karzel 08fecb8fe3
Peer check for incoming transfer proofs
Bob validates that incoming transfer proof messages are coming from the peer-id of Alice.
Currently Bob will ignore any transfer proof message that is not coming from the counterparty peer-id associated to the current swap in execution.
Once we add support for trying to save received transfer proofs for swaps that are currently not in execution we can also adapy allowing this for different counterparty peer-ids. This requires access to the database in Bob's event loop.
3 years ago
Daniel Karzel 3c2dfa830a
Peer check for incoming encrypted signatures
Alice validates that incoming encsig messages are coming from the peer-id that is associated with the swap.
Encsig message from a peer-id different to the one associated with the swap are ignored.
3 years ago
Thomas Eizinger 22bdc08c83
Get rid of Bob's swap Builder
Doesn't serve any purpose. We are better of just having two
constructors.
3 years ago
Thomas Eizinger e266fb07ef
Don't stutter 3 years ago
Thomas Eizinger 7adeaae12d
Be smart about how we import Config
By saying env::Config, we can save a line of code in the imports
and make it clearer, what kind of `Config` this is.
3 years ago
Thomas Eizinger be5bf01ed4
Don't overqualify types that are already imported 3 years ago
Thomas Eizinger 325fcbdb8c
Introduce protocol::bob::behaviour to mimic structure from alice module 3 years ago
Thomas Eizinger 5b515d6fb2
Don't qualify with `alice::` if we are within a module of Alice 3 years ago
Thomas Eizinger 6d06db3259
Use macro-based JSON-RPC client 3 years ago
dependabot[bot] 19483c5ead
Bump libp2p from 0.36.0 to 0.37.1
Bumps [libp2p](https://github.com/libp2p/rust-libp2p) from 0.36.0 to 0.37.1.
- [Release notes](https://github.com/libp2p/rust-libp2p/releases)
- [Changelog](https://github.com/libp2p/rust-libp2p/blob/master/CHANGELOG.md)
- [Commits](https://github.com/libp2p/rust-libp2p/compare/v0.36.0...v0.37.1)

Signed-off-by: dependabot[bot] <support@github.com>
3 years ago