Commit Graph

66 Commits (master)

Author SHA1 Message Date
yamabiiko 5ff46be279
RPC server for API Interface (#1276)
* saving: implementing internal api shared by cli and rpc server

* writing async rpc methods and using arc for shared struct references

* cleaning up, renamed Init to Context

* saving: cleaning up and initial work for tests

* Respond with bitcoin withdraw txid

* Print RPC server address

* Cleanup, formatting, add `get_seller`, `get_swap_start_date` RPC endpoints

* fixing tests in cli module

* uncommenting and fixing more tests

* split api module and propagate errors with rpc server

* moving methods to api and validating addresses for rpc

* add broadcast channel to handle shutdowns gracefully and prepare for RPC server test

* added files

* Update rpc.rs

* adding new unfinished RPC tests

* updating rpc-server tests

* fixing warnings

* fixing formatting and cargo clippy warnings

* fix missing import in test

* fix: add data_dir to config to make config command work

* set server listen address manually and return file locations in JSON on Config

* Add called api method and swap_id to tracing for context, reduced boilerplate

* Pass server_address properly to RpcServer

* Update Cargo.lock

* dprint fmt

* Add cancel_refund RPC endpoint

* Combine Cmd and Params

* Disallow concurrent swaps

* Use RwLock instead of Mutex to allow for parallel reads and add get_current_swap endpoint

* Return wallet descriptor to RPC API caller

* Append all cli logs to single log file

After careful consideration, I've concluded that it's not practical/possible to ensure that the previous behaviour (one log file per swap) is preserved due to limitations of the tracing-subscriber crate and a big in the built in JSON formatter

* Add get_swap_expired_timelock timelock, other small refactoring

- Add get_swap_expired_timelock endpoint to return expired timelock if one exists. Fails if bitcoin lock tx has not yet published or if swap is already finished.
- Rename current_epoch to expired_timelock to enforce consistent method names
- Add blocks left until current expired timelock expires (next timelock expires) to ExpiredTimelock struct
- Change .expect() to .unwrap() in rpc server method register because those will only fail if we register the same method twice which will never happen

* initiating swaps in a separate task and handling shutdown signals with broadcast queues

* Replace get_swap_start_date, get_seller, get_expired_timelock with one get_swap_info rpc method

* WIP: Struct for concurrent swaps manager

* Ensure correct tracing spans

* Add note regarding Request, Method structs

* Update request.rs

* Add tracing span attribute log_reference_id to logs caused by rpc call

* Sync bitcoin wallet before initial max_giveable call

* use Span::current() to pass down to tracing span to spawned tasks

* Remove unused shutdown channel

* Add `get_monero_recovery_info` RPC endpoint

- Add `get_monero_recovery_info` RPC endpoint
- format PrivateViewKey using Display

* Rename `Method::RawHistory` to `Method::GetRawStates`

* Wait for swap to be suspended after sending signal

* Remove notes

* Add tracing span attribute log_reference_id to logs caused by rpc call

* Sync bitcoin wallet before initial max_giveable call

* use Span::current() to pass down to tracing span to spawned tasks

* Remove unused shutdown channel

* Add `get_monero_recovery_info` RPC endpoint

- Add `get_monero_recovery_info` RPC endpoint
- format PrivateViewKey using Display

* Rename `Method::RawHistory` to `Method::GetRawStates`

* Wait for swap to be suspended after sending signal

* Return additonal info on GetSwapInfo

* Update wallet.rs

* fix compile issues for tests and use serial_test crate

* fix rpc tests, only check for RPC errors and not returned values

* Rename `get_raw_history` tp `get_raw_states`

* Fix typo in rpc server stopped tracing log

* Remove unnecessary success property on suspend_current_swap response

* fixing test_cli_arguments and other tests

* WIP: RPC server integration tests

* WIP: Integration tests for RPC server

* Update rpc tests

* fix compile and warnings in tests/rpc.rs

* test: fix assert

* clippy --fix

* remove otp file

* cargo clippy fixes

* move resume swap initialization code out of spawned task

* Use `in_current_span` to pass down tracing span to spawned tasks

* moving buy_xmr initialization code out of spawned tasks

* cargo fmt

* Moving swap initialization code inside tokio select block to handle swap lock release logic

* Remove unnecessary swap suspension listener from determine_btc_to_swap call in BuyXmr

* Spawn event loop before requesting quote

* Release swap lock after receiving shutdown signal

* Remove inner tokio::select in BuyXmr and Resume

* Improve debug text for swap resume

* Return error to API caller if bid quote request fails

* Print error if one occurs during process invoked by API call

* Return bid quote to API caller

* Use type safe query! macro for database retrieval of states

* Return tx_lock_fee to API caller on GetSwapInfo call

Update request.rs

* Allow API caller to retrieve last synced bitcoin balane and avoid costly sync

* Return restore height on MoneroRecovery command to API Caller

* Include entire error cause-chain in API response

* Add span to bitcoin wallet logs

* Log event loop connection properties as tracing fields

* Wait for background tasks to complete before exiting CLI

* clippy

* specify sqlx patch version explicitly

* remove mem::forget and replace with _guard

* ci: add rpc test job

* test: wrap rpc test in #[cfg(test)]

* add missing tokio::test attribute

* fix and merge rpc tests, parse uuuid and multiaddr from serde_json value

* default Tor socks port to 9050, Cargo fmt

* Update swap/sqlite_dev_setup.sh: add version

Co-authored-by: Byron Hambly <byron@hambly.dev>

* ci: free up space on ubuntu test job

* Update swap/src/bitcoin/wallet.rs

Co-authored-by: Byron Hambly <byron@hambly.dev>

* Update swap/src/bitcoin/wallet.rs

Co-authored-by: Byron Hambly <byron@hambly.dev>

* fmt

---------

Co-authored-by: binarybaron <86064887+binarybaron@users.noreply.github.com>
Co-authored-by: Byron Hambly <byron@hambly.dev>
3 weeks ago
Byron Hambly 4b09ffd4df
refactor: check for latest release
DRYs up the code for checking latest release from github.
2 years ago
Thomas Eizinger 148fdb8d0a
Ensure the size of our locking script never changes 3 years ago
Thomas Eizinger 2eb7fab0c3
Make `capture_logs` available for the whole crate 3 years ago
Thomas Eizinger ec4234fbb9
Merge `--seller-addr` and `--seller-peer-id` into `--seller` parameter
This simplifies the CLI's interface.
3 years ago
Philipp Hoenisch 632293cf91
Add support for swapping through Tor.
This PR does a few things.
* It adds a TorTransport which either dials through Tor's socks5 proxy or via clearnet.
* It enables ASB to register hidden services for each network it is listening on. We assume that we only care about different ports and re-use the same onion-address for all of them. The ASB requires to have access to Tor's control port.
* It adds support to dial through a local Tor socks5 proxy. We assume that Tor is always available on localhost.  Swap cli only requires Tor to be running so that it can send messages via Tor's socks5 proxy.
* It adds a new e2e test which swaps through Tor. For this we assume that Tor is currently running on localhost. All other tests are running via clear net.
3 years ago
rishflab e517c5934e Move asb tracing initializer to asb module 3 years ago
bors[bot] 2c385ee7d9
Merge #321
321: Properly handle concurrent messages to and from peers r=thomaseizinger a=thomaseizinger

Previously, we were forwarding incoming messages from peers to all
swaps that were currently running. That is obviously wrong. The new
design scopes an `EventLoopHandle` to a specific PeerId to avoid
this problem.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger a57f88d1b4
Properly handle concurrent messages to and from peers
Previously, we were forwarding incoming messages from peers to all
swaps that were currently running. That is obviously wrong. The new
design scopes an `EventLoopHandle` to a specific PeerId to avoid
this problem.
3 years ago
Thomas Eizinger 09c41f89c4
Rename ExecutionParams to EnvironmentConfig 3 years ago
Thomas Eizinger 60d6d50246
Extract kraken websocket client into dedicated module 3 years ago
Thomas Eizinger 14dcd150af
Extract `determine_btc_to_swap` function and test it
We also instantiate tracing in to order to quickly validate, what
the output for the different scenarios looks like.
3 years ago
bors[bot] a6724f29af
Merge #214
214: Rename nectar to asb (automated swap backend) r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel fe3d6f1fef Rename nectar to asb (automated swap backend) 3 years ago
Thomas Eizinger 84bc2c82b7
Upgrade to bdk 4.0
To achieve this we also:

- upgrade rust-bitcoin to 0.26
- upgrade bitcoin-harness to latest version (which also depends bitcoin 0.26)
- upgrade to latest edcsa-fun
- replace cross_curve_dleq proof with sigma_fun (to avoid an upgrade dance over there)
3 years ago
Franck Royer fb3b2aa546
Remove unnecessary pub qualifier 3 years ago
Franck Royer ee43125bdd
Add `nectar` binary 3 years ago
Franck Royer 7805a6d684
Move cli specific modules under cli folder
nectar will also have its own folder with a separate config.
3 years ago
Franck Royer 7d392c3086
This files contains `Command` and `Arguments` structs 3 years ago
Franck Royer 788445964a
Move main.rs to cli.rs to prepare for nectar binary 3 years ago
Daniel Karzel 89b3775e05 Rename config to execution_params 3 years ago
Daniel Karzel 802dc61e7e Configuration for RPC urls and Bitcoin wallet name 3 years ago
Franck Royer 33db688e3a
Bob peer id can be retrieved from the DB
This remove branches where Alice resumes from the DB but cannot contact
Bob.
3 years ago
Franck Royer f2a25ee49b
Move definitions out of lib.rs 3 years ago
Franck Royer b88a777bae
Remove dead code 3 years ago
Daniel Karzel 433704e48c Top to bottom `pub mod` then `mod` then `pub use` then `use` (incl. `use crate` and `use self`) 3 years ago
Franck Royer 898b8bf8b0
Remove dead code 3 years ago
Franck Royer 31c63f0c4d
Remove dead code 3 years ago
Daniel Karzel 0a21040e08 Deterministic peer id from seed for alice
This includes the introduction of the --data-dir parameter instead of the --database.
Both the seed file and the database are stored in the data-dir, the database in sub-folder `database`.
3 years ago
rishflab f64eede5d8 Move monero ser/deser to monero module 3 years ago
rishflab c900d12593 Merge xmr_btc crate
Created network, storage and protocol modules. Organised
files into the modules where the belong.

xmr_btc crate moved into isolated modulein swap crate.

Remove the xmr_btc module and integrate into swap crate.

Consolidate message related code

Reorganise imports

Remove unused parent Message enum

Remove unused parent State enum

Remove unused dependencies from Cargo.toml
3 years ago
Franck Royer b410de01df
Move state.rs under database module
The types in state are only used for the database
4 years ago
Franck Royer 8c7964bfee
Rename storage.rs to database.rs to reduce terminology variants 4 years ago
Franck Royer cdf2800fa5
Align clippy lints
Lints in `main.rs` are not used if there is a `lib.rs` file.
4 years ago
Franck Royer 40a27a2438
Remove dead code 4 years ago
Daniel Karzel 43d05935e7 Remove tor module 4 years ago
rishflab 4b00141c29
Fix happy path test 4 years ago
Franck Royer 905fc6cf35
Save Bob state during swap 4 years ago
Daniel Karzel 03b8e5f52e Upgrade CLI for mainnet test 4 years ago
Franck Royer c0478d7191
Move expiries to config
So they can be different for mainnet and regtest
4 years ago
rishflab f5d3d54b13 Prevent premature Bob t1 timeout
Bob was hitting the t1 timeout and entering cancel
instead of redeem. This was resolved by increasing
the timeouts to 50.
4 years ago
rishflab 24631d464d Add test for recursive executor 4 years ago
rishflab 3b005bd15c Resolve rebase issues, restructure code and fix warnings 4 years ago
Franck Royer 58ca33dd04 Remove warnings 4 years ago
Franck Royer 8976a03b3d Implemented Alice transition from `BtcLocked` to `XmrLocked` 4 years ago
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
4 years ago
rishflab ff7daf16f3 WIP: Test simplified swap execution 4 years ago
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
4 years ago
Lucas Soriano del Pino 483c819e17 Correctly re-export types from bitcoin and monero modules 4 years ago
Lucas Soriano del Pino 28225f8643 Implement swap recover function for Alice
This introduces a lot of duplication between the binary and the
library, but it's okay because this module should only be a temporary
measure until we allow recovery to be handled by the original state
machine.

Also, fix a bug in `xmr_btc::alice::action_generator` caused by the
incorrect assumption that Alice's ability to punish Bob could be
determined before the cancel transaction hits the blockchain.
4 years ago