Commit Graph

858 Commits (78480547d5c900c8f7b398c8c799bbd4a7781bb0)

Author SHA1 Message Date
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
Thomas Eizinger 601bf07255
Introduce `quote` protocol and display it to the user before they fund
Previously, the user neither knew the price nor the maximum quantity
they could trade. We now request a quote from the user and display
it to them.

Fixes #255.
3 years ago
Thomas Eizinger 3da01ea44a
Rename local variables according to new protocol name 3 years ago
Thomas Eizinger ead5db3f45
Re-order fields to group them semantically 3 years ago
Thomas Eizinger bc176bc4fb
Minor import optimizations 3 years ago
Thomas Eizinger 6d9b21cb47
Change `imports_granularity` to module
This reduces the overall amount of LoC that imports take up in our
codebase by almost 100.
It also makes merge-conflicts less likely because there is less
grouping together of imports that may lead to layout changes which
in turn can cause merge conflicts.
3 years ago
Thomas Eizinger 2c8200621d
Move `pub use` into pub use block 3 years ago
bors[bot] d1363d130c
Merge #265
265: Replace quote with spot-price protocol r=thomaseizinger a=thomaseizinger

This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Daniel Karzel 7504c6ceee Context for monero address parsing errors
Most of the errors are not user friendly, thus added context to tell the user the given address is incorrect.
3 years ago
Daniel Karzel 35d0e246d8 Monero address network check
Add a network check to ensure the given monero address is on the configured network.
3 years ago
bors[bot] cba9f119b6
Merge #261
261: Sweep xmr funds from generated temp wallet r=da-kami a=da-kami

Fixes #252

Please review by commit :)
Did a few cleanups before actually doing the feature.

Please note the comment that influenced this solution: https://github.com/comit-network/xmr-btc-swap/issues/252#issuecomment-789387074



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 2e3c2d8edf Remove Arcs in favour of references 3 years ago
Daniel Karzel 5d807e9647 Reorder: Move utility functionality to bottom 3 years ago
Daniel Karzel 862c29f1a8 Reorder: Move sweep_all after transfer 3 years ago
Daniel Karzel 5a43b3453e Reorder: Move create after open 3 years ago
Daniel Karzel b17e6cbd94 Reorder: Move open to top 3 years ago
Daniel Karzel d63790c2a6 Remove unnecessary monero wallet trait abstractions 3 years ago
Daniel Karzel 1041212a60 Work in review comments 3 years ago
Daniel Karzel 66c8401c95 Sweep all from generated wallet to user wallet
The default implementation for the command was removed because it does not
add additional value if we have a mandatory parameter anyway.
3 years ago
Thomas Eizinger 7042ed9441
Replace quote with spot-price protocol
This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.
3 years ago
Daniel Karzel 9f53dab3c6 Harmonize names to make more sense
The wallet is an instance of a wallet that has a name.
When we use `CreateWalletForOutputThenReloadWallet` we actually unload the wallet.
It would be cleaner to create a new instance that does that swap, but I did not go that far.
3 years ago
Daniel Karzel 70494fcb4f Create means creating the current wallet 3 years ago
Daniel Karzel 5b798217bc Open means opening the current wallet 3 years ago
Thomas Eizinger 2440964385
Allow ASB to be configured with max BTC buy amount
This will make it easier to also configure the CLI to display an appropriate max amount the user has to deal with.
3 years ago
Thomas Eizinger ce077a3ff5
Decouple Bob's EventLoop from the builder
Instead of instantiating the `EventLoop` within the builder, we only
pass in the necessary arguments (which is the `EventLoopHandle`) to
the Builder upon `new`.

This is work towards #255 which will require us to perform network
communication (which implies having the `EventLoop`) before starting
a swap.
3 years ago
Thomas Eizinger 54bc91581f
Don't unnecessarily create async blocks
If our expression directly evaluates to a future, we don't need to
create an async block.

This requires us to have `EventLoopRun::run` consume the instance
instead of just taking a mutable reference (otherwise we run into
lifetime issues). However, that is better anyway because `run` is
an endless loop so you never get to use the handle afterwards
anyway.
3 years ago
Thomas Eizinger a4c25080b6
Merge network::Seed into crate::Seed
This allows us to unify the way we derive new secret key material
and simplify the usage of seed by only having a single one.
3 years ago
Thomas Eizinger 089ac0806e
Simplify constructor of Bob's EventLoop
We never customize the behaviour or transport. Might as well hide
those details in the implementation.
3 years ago
Daniel Karzel 1b167f3eb6 Cleanup swap initialization for Alice and Bob 3 years ago
bors[bot] a8ebd4d16e
Merge #259
259: Upgrade bitcoin wallet to use BIP84 derivation scheme r=rishflab a=rishflab

Closes #258 

Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
rishflab a41b255dab Upgrade bitcoin wallet to use BIP84 derivation scheme
Explicitly specify the change descriptor because the behaviour when it
is not specified is unclear.
3 years ago
rishflab bcdde021eb Add windows support to monero rpc installer 3 years ago
rishflab 27df9128be Bail if monero wallet rpc is not found in downloaded archive
Previously we were ignoring if the monero wallet rpc was not found and
unpacked from archive leading to a failure down the line when trying to
run a non-existent executable. Bail when the executable is no found in
the archive.
3 years ago
Thomas Eizinger 3ad9516188
Reduce logging when signing transactions
1. We can generalize the signing interface by passing a PSBT in
instead of the `TxLock` transaction.
2. Knowing the transaction ID of a transaction that we are about
to sign is not very useful. Instead, it is much more useful to know
what failed. Hence we add a `.context` to the call of `sign_and_finalize`.
3. In case the signing succeeds, we will immediately broadcast it
afterwards. The new broadcasting interface will tell us that we broadcasted
the "lock" transaction.
3 years ago
Thomas Eizinger 8c9b087e39
Unify logging of broadcasted transactions
We eliminate unnecessary layers of indirection for broadcasting logic
and force our callers to provide us with the `kind` of transaction
that we are publishing.

Eventually, we can replace this string with some type-system magic
we can derive the name from the actual transaction. For now, we just
require the caller to duplicate this information because it is faster
and good enough TM.
3 years ago
Thomas Eizinger 3a503bf95f
Shorten function name
This struct is a wallet. The only thing it can meaningfully broadcast
are transactions. The fact that they have to be signed for that is
implied. You cannot broadcast unsigned transactions.
3 years ago
Thomas Eizinger 45cff81ea5
Remove traits in favor of using the wallet struct directly
Abstracting over the individual bits of functionality of the wallet
does have its place, especially if one wants to keep a separation
of an abstract protocol library that other people can use with their
own wallets.

However, at the moment, the traits only cause unnecessary friction.
We can always add such abstraction layers again once we need them.
3 years ago
Thomas Eizinger 8c0df23647
Only show _log_ output if the user passes `--debug`
If the user doesn't pass `--debug`, we only show `INFO` logs but
without time and level to make it clearer that it is meant to be
read by the user.

Without `--debug`, the user sees:

 Still got 0.00009235 BTC left in wallet, swapping ...

With `--debug`, they see:

2021-03-01 12:21:07  DEBUG Database and seed will be stored in /home/thomas/.local/share/xmr-btc-swap
2021-03-01 12:21:07  DEBUG Starting monero-wallet-rpc on port 40779
2021-03-01 12:21:11   INFO Still got 0.00009235 BTC left in wallet, swapping ...
2021-03-01 12:21:11  DEBUG Dialing alice at 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-01 12:21:12  DEBUG Requesting quote for 0.00008795 BTC
3 years ago
Thomas Eizinger cb4e2c041b
Rename `opt` to `args` 3 years ago
Thomas Eizinger f4827e3fa4
Improve time formatting of log output
Previously, the time was formatted as ISO8601 timestamps which is
barely readable by humans. Activating the `chrono` feature allows
us to format with a different format string. The output now looks
like this:

2021-03-01 11:59:52  DEBUG Database and seed will be stored in /home/thomas/.local/share/xmr-btc-swap
2021-03-01 11:59:52  DEBUG Starting monero-wallet-rpc on port 40673
2021-03-01 11:59:59  DEBUG Still got 0.00009235 BTC left in wallet, swapping ...
2021-03-01 11:59:59  DEBUG Dialing alice at 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-01 11:59:59  DEBUG Requesting quote for 0.00008795 BTC

There is a double space after the time which is already fixed in
tracing-subscriber but not yet released.

See https://github.com/tokio-rs/tracing/issues/1271.
3 years ago
Thomas Eizinger a82e82edd5
Tell the user about the monero-wallet-rpc download
Fixes #242.
3 years ago
Thomas Eizinger 06e3bccaa6
Don't print PeerId when requesting quote
Bob always just talks to one party, the PeerId is just noise.
3 years ago
Thomas Eizinger cbef577e2d
Inform user that we are going to swap the remainder of the balance 3 years ago
Thomas Eizinger b7c3524b4f
Abort the eventloop if the dialling fails 3 years ago
Thomas Eizinger 4e9e186462
Don't log things the user doesn't care about
The user configured neither a Bitcoin wallet backend nor the monero-wallet-rpc so let's not tell them about it.

Fixes #244.
3 years ago
Thomas Eizinger 6b74761e34
Remove tracing context
The swap_cli can only do one swap at a time, no need for the swap ID span.
3 years ago
Thomas Eizinger 3d2d447fba
Improve error message
YMMV but I think this sounds better.
3 years ago
Thomas Eizinger bbbe5f7ae8
Demote / promote log messages to their appropriate level 3 years ago
Thomas Eizinger 7387884e6d
Move log messages to the appropriate abstraction layer
Log messages are ideally as close to the functionality they are talking about, otherwise we might end up repeating ourselves on several callsites or the log messages gets outdated if the behaviour changes.
3 years ago
Thomas Eizinger b8df4a3145
Inline tracing configuration for swap_cli
This allows us to configure the presentation separately from the ASB.
3 years ago
Thomas Eizinger a0e7c6ecf7
Don't Arc the AtomicU32
We never clone this type, there is no need to wrap it in an `Arc`.
3 years ago
Thomas Eizinger 40dcf0355a
Simplify `Transfer::transfer` return type
We never use the fee returned from this function, remove it.
3 years ago
bors[bot] 1de3fa486e
Merge #247
247: Calculate max_giveable based on spending script size r=da-kami a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 9f0b1c5cbe
Calculate max_giveable based on spending script size 3 years ago
Daniel Karzel 8c40ee1da4 Change anyhow! to bail! in error scenarios 3 years ago
bors[bot] 7251588e79
Merge #233
233: ASB max sell amount r=thomaseizinger a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] 5ddf41721e
Merge #238
238: Bob error handling r=thomaseizinger a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
rishflab 975d604405 Test to ensure default alice peer id and multi addr is valid 3 years ago
rishflab 9a82b572ec Default to buy xmr using default trait 3 years ago
rishflab d6d67f62f1 Swap cli executes BuyXmr path if subcommand is not given 3 years ago
rishflab 60de6a9219 Remove intermediate structs in cli arguments
These intermediate structs were creating unnecessary noise. The peer id
and multiaddr fields are going to be removed in the future further
reducing the need to have seperate structs for cancel, resume and
refund.
3 years ago
bors[bot] 9a32f7d405
Merge #236
236: Some wallet cleanup + watch for deposit r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Daniel Karzel bb1537d6f2 Error feedback for the user upon communication errors
If communication with the other party fails the program should stop and the user should see the respective error.
Communication errors are handled in the event-loop. Upon a communication error the event loop is stopped.
Since the event loop is only stopped upon error the Result returned from the event loop is Infallible.

If one of the two futures, event loop and swap,  finishes (success/failure) the other future should be stopped as well.
We use tokio::selec! to stop either future if the other stops.
3 years ago
Daniel Karzel 019d6c725a Maximum sell amount for ASB that defaults to 0.5 XMR 3 years ago
bors[bot] bb0377c6c7
Merge #232
232: ASB only sends quote response if sufficient XMR balance r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel e66e84085b Rename Bob's Behavior Failure to CommunicationError
Failure does not express what the error represents. It is only used for communication
errors for quote requests, receiving the XMR transfer proof and sending the encryption signature.
3 years ago
Thomas Eizinger f472070546
Remove `--send-btc` in favor of swapping the available balance
If the current balance is 0, we wait until the user deposits money
to the given address. After that, we simply swap the full balance.

Not only does this simplify the interface by removing a parameter,
but it also integrates the `deposit` command into the `buy-xmr`
command.

Syncing a wallet that is backed by electrum includes transactions
that are part of the mempool when computing the balance.
As such, waiting for a deposit is a very quick action because it
allows us to build our lock transaction on top of the yet to be
confirmed deposit transactions.

This patch introduces another function to the `bitcoin::Wallet` that
relies on the currently statically encoded fee rate. To make sure
future developers don't forget to adjust both, we extract a function
that "selects" a fee rate and return the constant from there.

Fixes #196.
3 years ago
Thomas Eizinger 32cb0eb896
Rename `build_tx_lock_psbt` to `send_to_address`
Being defined on the wallet itself, a more generic name fits better
on what this function actually does.
3 years ago
Thomas Eizinger 67fe01a2ef
Remove `BuildTxLockPsbt` and `GetNetwork` traits
These traits were only used once within the `TxLock` constructor.
Looking at the rest of the codebase, we don't really seem to follow
any abstractions here where the protocol shouldn't know about the
exact types that is being passed in.

As such, these types are just noise and might as well be removed in
favor of simplicity.
3 years ago
Thomas Eizinger 6c38d66864
Remove `Tx` arguments from `add_signatures` functions
The only reason we need this argument is because we need to access
the output descriptor. We can save that one ahead of time at when
we construct the type.
3 years ago
Thomas Eizinger 0f8fbd087f
Make all fields of `bitcoin::Wallet` private
This reveals that the `network` field is actually unused.
3 years ago
Thomas Eizinger 1876d17ba4
Remove `map_err` in favor of `?`
`?` maps the error automatically.
3 years ago
Thomas Eizinger 7d324d966a
Remove `syncing` wallet log
BDK already has a log line for the sync that we could enable if we
wanted such a log.
Additionally, _we_ are not actually syncing the wallet, bdk is so our
log line was lying. It should have said "calling bdk to sync wallet".
3 years ago
bors[bot] 93d59398af
Merge #231
231: Error only on close message when fetching the rate r=thomaseizinger a=da-kami

Ping/Pong messages disturb the rate requests quite frequently resulting in failed swap setup because there is no rate available.

As a result messages Ping, Pong and Binary are now ignored and not reported as error.


Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 1f1b3a95bc Logging for different scenarios when reading from rate stream 3 years ago
rishflab abc9aaa327 Use default alice peer id and multiaddr if not specified in cli args 3 years ago
Daniel Karzel cad6a1c3a7 ABS only sends quote response if sufficient XMR balance 3 years ago
rishflab f52567155a Use default testnet config if config file path not specified 3 years ago
Daniel Karzel fc2c08c7c9 Error only on close message when fetching the rate
Messages Ping, Pong and Binary are ignored and not reported as error.
3 years ago
rishflab 51c16f23d8
Download and run monero wallet rpc on swap cli startup
If the monero wallet rpc has not already been downloaded we download the monero cli package and extract the wallet rpc. The unneeded files are cleaned up. The monero wallet rpc is started on a random port which is provided to the swap cli.

We added a fork of tokio-tar via a git subtree because we needed a tokio-tar version that was compatible with tokio 1.0. Remove this subtree in favor of a regular cargo dependency when this PR merges: https://github.com/vorot93/tokio-tar/pull/3.
3 years ago
Daniel Karzel 0945cee459 Remove traits in favour of public functions 3 years ago
Daniel Karzel 578d23d7fc Proper encapsulation of wallet boundaries through private fields 3 years ago
Daniel Karzel 947bcb6192 ASB reloads the default wallet after generate_from_keys atomically 3 years ago
Daniel Karzel 684cbe4d0b Remember monero wallet-height for Alice's refund scenario 3 years ago
Daniel Karzel fa04775188 Rename function explicit to cancellation to cancel
For transitioning to state4 we either go into a redeem or a cancellation scenario.
The function name state4 is misleading, because it is only used for cancellation scenarios.
3 years ago
Daniel Karzel 1404057dbe Remove misleading TODO
This TDOO is misleading, because - to our current knowledge - it is impossible for
Bob to retrieve the exact inclusion block-height of the lock transaction (send by Alice).
The wallet RPC is only capable of retrieving the inclusion block height of a transaction
through `get_payments` and `get_bulk_payments` which requires the `payment_id`.
The `payment_id` can be retrieved through `get_transfer_by_txid` which states
"Show information about a transfer to/from this address." - however the address that the
transfer goes to is not part of Bob's wallet yet! Thus, it is impossible for Bob to use
`get_transfer_by_txid` which in turn means Bob is unable to use `get_payments`.

The only possible way for Bob to know the exact inclusion block/height of the lock transaction
would be if Alice sends it over to Bob. But for that Alice would have to extract it she would have
to wait for confirmation - which she currently does not and might never do. Even if she does await
the first confirmation before sending the transfer proof the solution for retrieving the inclusion
block-height is not fleshed out on her side yet.
3 years ago
Daniel Karzel 9f1deb9fdc Wrap the Monero wallet client in a Mutex
In order to ensure that we can atomically generate_from_keys and then reload a wallet,
we have to wrap the client of the monero wallet RPC inside a mutex.
When introducing the Mutex I noticed that several inner RPC calls were leaking to the
swap crate monero wallet. As this is a violation of boundaries I introduced the traits
`GetAddress`, `WalletBlockHeight` and `Refresh`.

Note that the monero wallet could potentially know its own public view key and
public spend key. If we refactor the wallet to include this information upon wallet
creation we can also generate addresses using `monero::Address::standard`.
3 years ago
Daniel Karzel aed8358fb7 Remove dead code 3 years ago
bors[bot] 2654879ff3
Merge #218
218: Cleanup dependencies r=thomaseizinger a=thomaseizinger

Fixes https://github.com/comit-network/xmr-btc-swap/issues/208.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
bors[bot] fb2057453a
Merge #219 #221
219: Rename variables to add to understanding the code r=da-kami a=da-kami



221: Fix/improve comment explaining TxRefund encsigning r=thomaseizinger a=rishflab



Co-authored-by: Daniel Karzel <daniel@comit.network>
Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
Thomas Eizinger 66db8e1851
Remove unnecessary log dependency
By updating `tracing_log`, we can access the re-export. That we need
to initialize the `tracing_log` adaptor.

The usage of `log::LevelFilter` for the `init_tracing` function was
conceptually incorrect. We should be using a type from the `tracing`
library here.
3 years ago
Thomas Eizinger 03078f328c
Split monero-harness into harness and rpc
This allows us to move `monero-harness` and `bitcoin-harness` into
`[dev-dependencies]` of `swap`.
3 years ago
rishflab 8280072400 Fix/improve comment explaining TxRefund encsigning 3 years ago
Daniel Karzel 151f33ba10 Rename variables to add to understanding the code 3 years ago
bors[bot] 61a8282be1
Merge #203
203: Introduce dynamic rates r=da-kami a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel b4ceee49df Change monitoring to default wallet
The automated swap backend (asb) requires Monero funds, because Alice is selling Monero.
We use a hardcoded default wallet named asb-wallet. This wallet is opened upon startup.
If the default wallet does not exist it will be created.
3 years ago
Daniel Karzel 9496dce917 Skip heartbeat messages 3 years ago
Thomas Eizinger a8bfc1d686 Make LatestRate::Error require std::error::Error trait bound
This allows us to use .context instead of .map_err when calling
`latest_rate()`. For the static rate module, we simply fill in
`Infallible` which is actually better suited because it describes
that we are never using this error.
3 years ago
Thomas Eizinger b47b06aa23 Import anyhow::Result across the codebase
There is no need to fully qualify this type because it is a type
alias for std::Result. We can mix and match the two as we want.
3 years ago
Franck Royer 519d1a5701 Log rate and amounts for Alice when doing execution setup 3 years ago
Franck Royer 644f4c1732 Bubble up ws error to consumer
Note that because we are using `watch` channel, only a reference to the
channel value can be returned.
Hence, using custom Error that can be cloned to be able to
pass `Result` through the channel.
3 years ago
Franck Royer 92b3df4158 Introduce dynamic rates 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
bors[bot] 81228c9d5b
Merge #209
209: Upgrade to bdk 0.4 r=thomaseizinger a=thomaseizinger

Effectively, this also means:

- Upgrading to rust-bitcoin 0.26
- Upgrading to miniscript 5
- Upgrading monero to 0.10
- Upgrading curve25519-dalek to 3
- Upgrading bitcoin-harness to rust-bitcoin 0.26 (https://github.com/coblox/bitcoin-harness-rs/pull/21)
- Upgrade `ecdsa_fun` to latest version
- Replace `cross_curve_dleq` with `sigma_fun` (to avoid an upgrade dance on that library)

I refrained from specifying `rev`s in the Cargo.toml because we have a lock-file anyway. This should allow us to update those dependencies easier in the future by just running `cargo update -p <dependency>`.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Daniel Karzel fe3d6f1fef Rename nectar to asb (automated swap backend) 3 years ago
Daniel Karzel 164de3c524 Properly calculate the confirmations for Bitcoin tx
Once the transaction was included into a block it has one confirmation - before inclusion it has zero.
current-block-height - transaction-block-height = zero; but that means one confirmation.
Hence, the confirmation calculation was adapted to: Current-block-height - (transaction-block-height - 1).
3 years ago
Thomas Eizinger 2d8ede80e1
Use released version of backoff 3 years ago
Thomas Eizinger cabf0efb8c
Only construct proof system once
The proof system is a static element and can be reused several times.
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
bors[bot] b3f49cf83e
Merge #200
200: Wait for refund if insufficient Monero is locked up r=da-kami a=da-kami

In a scenario where Alice does not lock up sufficient funds Bob should properly transition to refunds. At the moment the CLI just panics. 
I noticed this when Alice accidentally had a different amount set than Bob. In the future this should not happen, because Alice provides the amount for Bob. However, in case Alice is malicious Bob should still transition correctly. 

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] 8537b88a68
Merge #201
201: Fix ASB - Prevent the future from being stopped in production r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel babd1d7b60
Wait for refund if insufficient Monero is locked up 3 years ago
Daniel Karzel ebb869e6f4 Distinguish transient and permanent Electrum errors 3 years ago
Daniel Karzel 9b93cabfdf Use context instead of map_error 3 years ago
rishflab fe362d765b Add sync wallet on nectar's startup 3 years ago
rishflab 00e2b257c4 Remove misplaced sync wallet call 3 years ago
Daniel Karzel 2ced9ddba4 Prevent future from being stopped by calling forget on handle 3 years ago
Daniel Karzel 77ec7e502f Distinguish permanent and transient error when watching tx 3 years ago
rishflab b66bb00c77 Remove stale code 3 years ago
rishflab bc1d2bda54 Test URL creation for default electrum HTTP API 3 years ago
rishflab d296c22ecf Log bitcoin deposit address on startup 3 years ago
rishflab 4768c79070 Derive bitcoin private key from seed 3 years ago
Thomas Eizinger a51194b9fa Instantiate electrum client with custom config with 2 retries
The default number of retries is 1. Unfortunately, the way this config
value is interpreted doesn't actually lead to a retry. We have to set
it to 2 to actually make it retry.

See https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
3 years ago
rishflab 180e778df9 Allow blockchain calls to fail
Prior to this change, functions could not fail early on permanent errors eg. parsing a url. Merged error enums.
3 years ago
rishflab a0ef1f96ec Replace bitcoind wallet with bdk wallet
The bitcoind wallet required the user to run a bitcoind node. It was replaced with a bdk wallet which allows the user to connect to an electrum instance hosted remotely. An electrum and bitcoind testcontainer were created to the test the bdk wallet. The electrum container reads the blockdata from the bitcoind testcontainer through a shared volume. bitcoind-harness was removed as bitcoind initialisation code was moved into test_utils. The bdk wallet differs from the bitcoind wallet in that it needs to be manually synced with an electrum node. We synchronise the wallet once upon initialisation to prevent a potentially long running blocking task from interrupting protocol execution. The electrum HTTP API was used to get the latest block height and the transaction block height as this functionality was not present in the bdk wallet API or it required the bdk wallet to be re-synced to get an up to date value.
3 years ago
bors[bot] 4d8e801c1e
Merge #190
190: Do not pass Monero amount to the CLI r=D4nte a=D4nte

The CLI user only pass the Bitcoin amount they want to sell.

The CLI then do a quote request to nectar which provides the Monero amount the taker can get.

Co-authored-by: Franck Royer <franck@coblox.tech>
3 years ago
bors[bot] 5d215caf35
Merge #188
188: Tor cleanup r=da-kami a=da-kami

We never removed Tor install from CI. I don't think it should be necessary given that Tor was removed in code.

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Franck Royer f36f5acaf1
Remove unnecessary async block 3 years ago
Franck Royer 73c52ffb61
Remove unused structs 3 years ago
Franck Royer 2dbd43e2c0
Only pass btc amount to CLI
The CLI requests a quote to nectar to know how much xmr it can get.
Also align terminology with the sequence diagram.
3 years ago
Franck Royer 144da75270
Remove redundant data 3 years ago
Franck Royer fb3b2aa546
Remove unnecessary pub qualifier 3 years ago
Franck Royer b4e2e11dde
Remove unnecessary fields 3 years ago
Franck Royer d6effb7d39
Remove unnecessary pub qualifiers 3 years ago
Franck Royer b8a84aa34b
Avoid possible mix up between timelocks
Introduce new type to ensure no mix up happens when ordering the fields
in function calls.
3 years ago
Franck Royer 9a321a4f09
Move transaction types in dedicated modules
To allow the related timelock to be defined with the
transaction that uses it. This will allow the access to the
timelock's struct inner field with defining `From` impl.
3 years ago
Franck Royer 65e0e5b731
Use Remote handle to access ongoing swaps on Alice 3 years ago
bors[bot] a0753e24dc
Merge #189
189: The first message is more of a quote request than a swap request r=D4nte a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
3 years ago
Franck Royer 5d78556665
Give a more specific name to the CLI binary: `swap-cli`
The current binary name is very generic `cli`. `swap-cli` better
describes what this binary does.
3 years ago
Franck Royer 8fada42074
Make `config` argument global
The `config` argument apply to all commands. It is now optional and
needs to be passed before a command.
E.g. `cli --config ./config.toml history`
3 years ago
Franck Royer 83dcf4ba3c
Add `nectar` binary 3 years ago
Daniel Karzel c166232daf Remove unnecessary mention of Tor in comment 3 years ago
Franck Royer 9ded728879
The first message is actually a quote or rate request 3 years ago
Franck Royer ee43125bdd
Add `nectar` binary 3 years ago
Franck Royer fac5b59d17
Remove unnecessary specification of the types 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 901c9e89c9
No evident added value of having separate `Seed` structs
Hence, reducing complexity of the codebase. Note that the seed will be
used by both nectar and the cli whereas the config mod will be different
so this changes helps with the next step of having a dedicated config
module for each binary.
3 years ago
Franck Royer 7d392c3086
This files contains `Command` and `Arguments` structs 3 years ago
Franck Royer 45dccb8be2
Rename the config struct `Config` 3 years ago
Franck Royer 6e6dc320b4
Alice event loop now handles the creation of new swaps 3 years ago
Franck Royer bfc19d5628
Remove acknowledgements processing
We are aware of issues of timeouts when waiting for acknowledgements.
Also, to properly supports acks in a multiple swap context, we need to
revert to doing event processing on the behaviour so that we can link
leverage the `RequestResponse` libp2p behaviour and link the messages
requests ids to swap ids when receiving an ack or response.

Acks are usefully for specific scenarios where we queue a message on the
behaviour to be sent, save as sent in the DB but crash before the
message is actually sent. With acks we are able to resume the swap,
without ack, the swap will abort (refund).
3 years ago
Franck Royer cc8b855117
Make it possible to clone a handle
This will be used for new swaps.
3 years ago
Franck Royer 1b2be804ed
Remove unnecessary channels
`alice::swap::run_until` will be called once the execution setup is
done. The steps before are directly handled by the event loop,
hence no channels are needed for said steps: connection established,
swap request/response & execution setup.
3 years ago
Franck Royer f5ca5faabf
Process execution setup failure similarly to other failures
By merging it in the failure event of the root behaviour.
3 years ago
Franck Royer 4ade5df0e5
Remove unnecessary impl block 3 years ago
Franck Royer 60e0b9382c
Introduced from float API for Monero quantities 3 years ago
Franck Royer b5b990257a
Move `Behaviour` in dedicated module 3 years ago
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).
3 years ago
Franck Royer 530b9b2ea8
Remove possible mix up of timelocks when using `State0::new` 3 years ago
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.
3 years ago
Franck Royer 39a46baa2c
Preemptively box cancel tx to avoid size difference in enum 3 years ago
Franck Royer 69363e43a3
Preemptively box encrypted signature to avoid size difference in enum 3 years ago
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.
3 years ago
Franck Royer 788445964a
Move main.rs to cli.rs to prepare for nectar binary 3 years ago
Franck Royer 311ba74cd6
Remove sell-xmr from CLI 3 years ago
Daniel Karzel 0a0bce1552 Rename temporary wallet to blockchain monitoring wallet 3 years ago
Daniel Karzel 1e29433bd2 Open or create temporary Monero wallet upon wallet initialization 3 years ago
Daniel Karzel dac4443bbd Add functionality to open monero wallet through rpc 3 years ago
Daniel Karzel 62605a318a Add CreateWallet trait to expose create_wallet 3 years ago
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.
3 years ago
Daniel Karzel 86290649e7 work in review comments 3 years ago
Daniel Karzel c930ad84a4 Add --force flag for cancel and refund 3 years ago
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.
3 years ago
Daniel Karzel ad2aefc2a5 Refund Command 3 years ago
Daniel Karzel 0600a7048e Cancel command 3 years ago
Franck Royer dee8c1e335
Remove scopes 3 years ago
Franck Royer a48823a665
Re-organise Alice state to be more coherent with the msg sequence 3 years ago
Franck Royer eefb1b3b16
Use event_process = false for Bob
As we do not process the event, we can just implement the needed `From`
traits.
3 years ago
Franck Royer a7b89e2fe4
Use event_process = false for Alice
As we do not process the event, we can just implement the needed `From`
traits.
3 years ago
Franck Royer 554ae6c00e
Remove Request Response types
These are actually not needed and forces us to cater for variants when
processing requests and responses.
3 years ago
Franck Royer 5a5a1c05f7
Set appropriate name to codec 3 years ago
Franck Royer a11e894b31
Prepend all libp2p protocols with "comit" 3 years ago
Franck Royer cfc5cb5206
Remove dead code and combine swap request & one shot codecs 3 years ago
Franck Royer fc2d8d3861
Rename alice::Message0 to Message0
There is now only one message0
3 years ago
Franck Royer 88bf080dc0
rename alice::Message0 to Message1 3 years ago
Franck Royer 18f326ddd1
Rename bob::Message1 to Message2
As per sequence diagram.
3 years ago
Franck Royer 0d1be52966
Rename alice::Message1 to Message3
As per sequence diagram.
3 years ago
Franck Royer e74efd38b5
Rename bob::Message2 to Message4
As per sequence diagram.
3 years ago
Franck Royer 081237bb6f
Remove unused behaviours 3 years ago
Franck Royer ecb54958ee
Preemptively Box few messages 3 years ago
Franck Royer 3fa4ffa82c
Implement new behaviour for execution setup 3 years ago
Franck Royer 9ae050abf8
Use correct variable name 3 years ago
Franck Royer c316ea5244
Upgrade toolchain
Needed to use libp2p-async-await
3 years ago
Franck Royer e82383bcf6
Avoid carrying rng 3 years ago
Philipp Hoenisch 25bf5df122
Merge pull request #172 from comit-network/dead-code
Remove dead code
3 years ago
Philipp Hoenisch 8743527df9
Remove dead code 3 years ago
Daniel Karzel b27363e386 Use correct default data directory 3 years ago
Daniel Karzel 5cb4f3c99d rename configuration to config 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 f1c07fbb6d
Remove incorrect todo 3 years ago
Franck Royer c25d5ff07e
Improve network logging 3 years ago
Franck Royer f9f17b0e23
Do not consider transfer proof sent until it's ack'd 3 years ago
Franck Royer b968c98805
remove unnecessary logs 3 years ago
Franck Royer cc76b201b5
Do not consider encrypted signature sent until it's ack'd 3 years ago
Franck Royer 5af3532cbf
Fix log messages 3 years ago
Franck Royer 704a8e7b01
Add swap id to tracing context 3 years ago
Franck Royer b8a9356d1b
Change expiries depending on the test goal 3 years ago
rishflab 0b69573129
Run tests on one thread, increase T1 3 years ago
rishflab 1597f5336b
Restart event loop in tests
Alice was attempting to create a new event loop using the same listen addr as the old one which was still running. This commit aborts the event loop before creating a new one.
3 years ago
rishflab 77fc5743a2
Upgrade tokio to 1.0
Upgrade bitcoin harness dependency to latest commit

Upgrade backoff to fix failing tests. The previous version of backoff had a broken version of the retry function. Upgraded to a newer comit which fixes this problem.

Upgrade hyper to 0.14 as the 0.13 was bringing in tokio 0.2.24

Upgraded bitcoin harness to version that uses tokio 1.0 and reqwest 0.11

Upgrade reqwest to 0.11. Reqwest 0.11 uses tokio 1.0

Upgrade libp2p to 0.34 in preparation for tokio 1.0 upgrade
3 years ago
Franck Royer 2073e88683
Remove wrapping if `ReadOneError` when unnecessary 3 years ago
Franck Royer 2929a8f101
Use the correct protocol support 3 years ago
Franck Royer b62ef9c2d9
Harmonizing naming 3 years ago
Franck Royer 8fd2620b83
Improve names for messages 4 and 5 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.
4 years ago
Franck Royer a910bc2046
Box all messages in enum
The messages are very different, best to box them and save size on the
stack as an enum takes as much space on the stack than its bigger
variant.
4 years ago
Franck Royer d2a1937f51
Use `Message4` 4 years ago
Franck Royer 124d6f1ebb
Introduced Message 4 sent by Alice to replace message 2 response 4 years ago
Franck Royer edb93624f3
Introduce one shot code
To allow alice to be the requester for message 4.
4 years ago
Franck Royer 9a5e35c1bd
Rename `bob::Message2` to `Message5`
As per the proposed changed in the sequence diagram.
The aim is to have a unique terminology per message instead of having
the same name for 2 consequent messages that share the same behaviour.

Note that the aim is to remove the shared `RequestResponse` behaviours.
4 years ago
Franck Royer 10eeecfe54
Remove dependency of main.rs on lib.rs 4 years ago
Franck Royer f2a25ee49b
Move definitions out of lib.rs 4 years ago
Franck Royer b88a777bae
Remove dead code 4 years ago
Daniel Karzel 33a9057b1f Move run_until is_target_state comparison functions into testutils 4 years ago
Daniel Karzel 3593f5323a Bob saves lock proof after received so he can resume swap 4 years ago
Daniel Karzel 433704e48c Top to bottom `pub mod` then `mod` then `pub use` then `use` (incl. `use crate` and `use self`) 4 years ago
Daniel Karzel 44c4b5dcea Remove newlines from import statements to avoid problems
Rust fmt automatically groups the imports (from top to bottom) as `pub use` `use crate` and `use`.
There is no need to introduce sections which cause annoyance when auto importing using the IDE.
4 years ago
bors[bot] 4e858197c9
Merge #149
149: Fix Alice redeem scenario r=da-kami a=da-kami

Follow up of #144, partial fix of https://github.com/comit-network/xmr-btc-swap/issues/137

 Fix Alice redeem scenario

- Properly check the timelocks before trying to redeem
- Distinguish different failure scenarios and reactions to it.
    - if we fail to construct the redeem transaction: wait for cancel.
    - if we fail to publish the redeem transaction: wait for cancel but let the user know that restarting the application will result in retrying to publish the tx.
    - if we succeed to publish the tx but then fail when waiting for finality, print error to the user (secreat already leaked, the user has to check manually if the tx was included)



Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Franck Royer 8c76abcd37
Remove TODO
This can be tackle when migrating to SQLite
4 years ago
Franck Royer 898b8bf8b0
Remove dead code 4 years ago
Franck Royer ae8134f04e
Replace amounts messages with swap res/req 4 years ago
Daniel Karzel 6a75c840b5 Fix Alice redeem scenario
- Properly check the timelocks before trying to redeem
- Distinguish different failure scenarios and reactions to it.
    - if we fail to construct the redeem transaction: wait for cancel.
    - if we fail to publish the redeem transaction: wait for cancel but let the user know that restarting the application will result in retrying to publish the tx.
    - if we succeed to publish the tx but then fail when waiting for finality, print error to the user (secreat already leaked, the user has to check manually if the tx was included)
4 years ago
Daniel Karzel 8a7d746e96 Wait for Bob's refund finality
For Alice we ensure to wait for redeem/punish finality, so it should be the same for Bob.
4 years ago
Franck Royer c44b867d01
Delay the wrapping in Arc 4 years ago
Franck Royer 83b72c0a45
Make `make_init_state` and `init_loop` associated to `alice::SwapFactory` 4 years ago
Franck Royer c11042ff0d
Use `builder` terminology instead of `factory`
This is not really a factory as a factory design pattern is about
producing several instances.

In the current usage, we are only interested in one swap instance. Once
the swap instance is created, the factory becomes useless. Hence, it is
more of a builder pattern.
4 years ago
Franck Royer 9148af2dbe
`bob::SwapFactory` should be consumed once a swap is returned 4 years ago
Franck Royer 652bfa14a9
Remove unnecessary `pub` qualifiers 4 years ago
Franck Royer b21dc03ed0
`alice::SwapFactory` should be consumed once a swap is returned 4 years ago
Franck Royer 9b32409b8d
Remove unnecessary `allow(clippy)` 4 years ago
Franck Royer 9e3ef7ea24
Remove `StartingBalances` from release code 4 years ago
Franck Royer 181999e04f
Remove unnecessary `alice` qualifiers in `alice::SwapFactor` 4 years ago
Franck Royer 3bc76a91c6
Make `init_state` associated to `bob::SwapFactory` 4 years ago
Franck Royer f0e6e45d56
Remove unecessary `bob` qualifier 4 years ago
Franck Royer dbc633ea06
Remove unecessary `connect` qualifier 4 years ago
Franck Royer e26629b593
Remove unecessary fields from `bob::SwapFactory` 4 years ago
Franck Royer 3c68026cfe
Move init event loop in `bob::SwapFactory` 4 years ago
Franck Royer 96b1b18037
Keep terminology consistent
Also avoid redundant qualifiers.
4 years ago
Daniel Karzel 28429fa9fe Revert log statement 4 years ago
Daniel Karzel 37f619dbfc Move StartingBalances into protocol module 4 years ago
Daniel Karzel 41e335fc2d Error messages instead of unreachable
Currently this code is actually not reachable, but that is semantically applied by the program's flow (the resume command includes the swap direction).
It is still preferred to have an error message rather than an unreachable statement.
4 years ago
Daniel Karzel 2dceab28a4 Derive Default 4 years ago
Daniel Karzel e91987e23f Fix rand import 4 years ago
Daniel Karzel 170e90ffed Rename do_run_until to _run_until_internal 4 years ago
Daniel Karzel 82974412b2 Remove roles from SwapFactory name as implied by module and cleanup 4 years ago
Daniel Karzel 75f89f3b25 Use Bob swap factory in production 4 years ago
Daniel Karzel e56c48ee23 Remove unused type 4 years ago
Daniel Karzel 3398ef8236 Use Alice swap factory in production 4 years ago
Daniel Karzel 67e925fe1f Refactor Bob's peer-id and identity to be handled on the outside
Doing this in the behaviour is a weird indirection that is not needed.
4 years ago
Daniel Karzel 0c19af9090 Refactor Alice's peer-id and identity to be handled on the outside
Doing this in the behaviour is a weird indirection that is not needed.
4 years ago
Daniel Karzel 8bf467b550 Make the factory code usable in production
- Introduce Test abstraction instead of tow harnesses, move test specific data into Test
- Change the abstraction from actors to swap, because we are creating swaps, not actors
- rename actor::swap  to run, because we are running a swap
4 years ago
Daniel Karzel e4795fa4ee Fix recursive call to swap by using run_until
We should call run_until instead of swap.
4 years ago
bors[bot] 35c42263df
Merge #145
145: Make lock-tx id available in redeem/punish state to be able to assert exact fees r=da-kami a=da-kami

We can do exact assertions for Bob's redeem as well, but have to store Bob's tx_lock id in the respective final state. Make tx_lock available in BtcRedeemed and BtcPunished to have better assertions / harmonize test behaviour.

Storing this information is strictly speaking not needed for the production environment. But it is static information that can be seen as additional information that can be handy for a user. We could potentially extract it inside the tests as well (for redeem without restart would be a bit tricky), but I think this solution is more elegant. 

Co-authored-by: Daniel Karzel <daniel@comit.network>
Co-authored-by: Franck Royer <franck@coblox.tech>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
4 years ago
bors[bot] a7f68e4aa1
Merge #144
144: Test refactor r=da-kami a=da-kami

This PR is pure refactoring, keeping the logic of the tests we had before. No production code is touched besides re-exports in early commits (no logic changes).

In the follow ups improvements will be introduced, that touch the production code as well.

All remaining tasks actioned since Friday: 

- [x] `happy_path_bob _restart` (trivial)
- [x] add refund assertions to harnesses (trivial)
- [x] convert all refund scenarios currently being tested (trivial)
- [x] remove dead test init code once all old tests are converted
- [ ] ~~(optional) move alice and bob harness code into separate files~~ -> might action this once re-using test code in production.

Out of scope, follow up:
- [x] https://github.com/comit-network/xmr-btc-swap/pull/145 - We can do exact assertions for Bob's redeem as well, but have to store Bob's `tx_lock` id in the respective final state. Make `tx_lock` available in `BtcRedeemed` and `BtcPunished` to have better assertions / harmonize test behaviour. 
- [ ] update the production code to use the `Alice` and `Bob` structs to bundle the params - update tests to use the production struct.
- [ ] Re-use test swap setup in production (i.e. `Alice-/BobHarness::new`) to setup the swap.
- [ ] add additional tests
- [ ] re-try moving the tests from `test` to `src` (if the peer_id was the only problem this should be trivial now - but should be done after the refactor is finished)
- [ ] creating new wallets upon restart
- [ ] aborting the old event loop after restart

Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Franck Royer 9a823dca4c
Do not introduced State6 4 years ago
bors[bot] 974b6ebf6f
Merge #136
136: Testnet resume fixes r=da-kami a=da-kami

Add a few log statements on Bob's side to make the user experience better.
Update / remove ToDos.

I set the log level to `Info` in main again, `Debug` heavily clutters the output. In order to make `Debug` more usable we might want to review printing all those `rpc` messages. But this goes beyond the scope of this PR.


Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Daniel Karzel d4316f0cfe Print each monero confirmation for Bob
This is to provide more context to the user.
4 years ago
Daniel Karzel 8615aaed6e Make lock-tx id available in redeem/punish state to be able to assert exact fees 4 years ago
Daniel Karzel b031bc5e42 Re-export run_until 4 years ago
rishflab 9cbf6e9774 Re-export event loop handles 4 years ago
rishflab 6040f2ae63 Re-export event loops 4 years ago
rishflab e8fdf62623 Re-export swap function 4 years ago
rishflab f5cfe014be Fix imports 4 years ago
Franck Royer 31c63f0c4d
Remove dead code 4 years ago
Franck Royer 0852f90473
Remove unused variant 4 years ago
Daniel Karzel f8848aca55 Describe additional state for ToDo that might cause trouble
If we wait for lock transaction confirmations immediately after sending the transaction without saving this state to the DB this might cause locking the money twice.
An additional state is needed for such a scenario.
4 years ago
Daniel Karzel 59f01ad680 Remove Todo that was already actioned
This ToDo does not add any value, I would not know what to do here.
4 years ago
Daniel Karzel 60f3923a63 Set tracing level to Info in production code
Trace / Debug should be used when there is a problem. They print way too much in production.
4 years ago
Daniel Karzel 00b4f3110f Remove ToDo that is already actioned
We already have a second watcher for the cancel timelock, so refund is already actioned.
4 years ago
Daniel Karzel ab9117aa4c Log Alice's lock tx proof receive on Bob's side 4 years ago
Daniel Karzel af45206fde Remember the block-height before XMR lock for generated monero wallet restore height
Speeds up wallet creation, because only the blocks after the recorded height will be scanned.
4 years ago
bors[bot] ca6ba78862
Merge #123
123: Small fixes after testnet usage r=da-kami a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
4 years ago
Daniel Karzel 664958939d Create network::Seed from swap::Seed instead of abstracting over byte array 4 years ago
Daniel Karzel f18d01dfaf Deterministic peer id from seed for bob 4 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`.
4 years ago
Franck Royer 6ffc66867c
Typo
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
4 years ago
Franck Royer 047f990d05
Improve error reporting on signature verification 4 years ago
Franck Royer ef906876a0
Increase timelocks on testnet
To allow time for stagenet Monero transaction to be mined.
4 years ago
Franck Royer 17356eaff9
Do not guard waiting for encrypted signature with arbitrary timeout
We already select waiting for this message with the cancellation expiry,
 we do not need add another guard that tries to guess how long it would
 for the Monero transaction to be finalised.
4 years ago
Franck Royer 95ecb02e7a
Small changes to make debugging easier and tests 4 years ago
Franck Royer 9d8f8b0a1f
P2p socket should be listening for external connections 4 years ago
rishflab 1c644cb377 Rename message behaviours 4 years ago
rishflab 5d7d72c826 Remove unused import 4 years ago
rishflab 387a4da2f6 Make modules private 4 years ago
rishflab dcea54dbf1 Move protocol parent states into appropriate module 4 years ago
rishflab f64eede5d8 Move monero ser/deser to monero module 4 years ago
rishflab e7c00d742e Re-export bitcoin and monero types 4 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
4 years ago
Daniel Karzel 487b880371 Cleanup unused config param that was accidentally introduced 4 years ago
Daniel Karzel e031681369 Add minimum monero confirmations to config use it for Bob 4 years ago
Daniel Karzel c6bc45e7a0 Wait for bitcoin tx finality before locking XMR 4 years ago
Daniel Karzel 30dd15774e Log Bitcoin and Monero transaction IDs on info instead of debug 4 years ago
Daniel Karzel 0977d36703 Set log level to info instead of trace 4 years ago
Daniel Karzel 8a2128e93a Correct monero-wallet-rpc parameter name 4 years ago
Daniel Karzel 4d9559fc2e Monero network settings and testnet 4 years ago
Daniel Karzel 1f7e72b230 Log bitcoin harness and monero harness 4 years ago
Franck Royer dd10e68db4
Merge pull request #113 from comit-network/clippy 4 years ago
Franck Royer bcbc54b569
Type timelock and block height
To ensure no mistake is made (and none were!)
4 years ago
Franck Royer 81cbc24c46
Use action to name trait 4 years ago
Franck Royer e1e8533862
Embed state mod in database mod
The `Swap` struct is now database specific, no need to have a 20 lines
 module.
4 years ago
Franck Royer 59708c57e6
Move Alice and Bob db states in separate modules 4 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 5ed18469e4
Move db state conversion with db type definition
Those conversion are specific to the database and should be defined with
in the database module.
4 years ago
Franck Royer 2a778f5644
Remove overzealous clippy overrides
We have overridden a number of clippy warnings such as
"large enum variant".

Considering that we have a number of issues
 with the stack size in CI, it is more prudent to follow clippy's advice
 and box larger items so that the enum does not take larger space.

Do note that an instance of the enum always takes as much space as its
largest variant.
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 ece689f5ca
There is only one binary, we should use `main.rs` naming convention 4 years ago
Franck Royer 4150e75488
Replace `Try_From` state conversion with `From` for Bob 4 years ago
Franck Royer 5d1b10cc58
Align Bob DB states with swap states 4 years ago
Franck Royer e541f7b83d
Replace `TryFrom` with `From` for Alice states 4 years ago
Franck Royer 69e1c2bb27
Align Alice DB states with swap states 4 years ago
Franck Royer a31db63e54
Improve state names and display 4 years ago
Franck Royer f0736d0906
Remove Refund timelock and T0/T1/T2
There are no refund timelock, only a cancellation timelock and punish
timelock.

Refund can be done as soon as the cancellation transaction is published.
4 years ago
Franck Royer 405e377f79
Rename `EncSign` to `EncSig`
`EncSig` means "encrypted signature", the item,
not be confused with "signing", the action
4 years ago
bors[bot] 9c83ca52ad
Merge #107
107: Ensure that Bob can cancel correctly if T1 expired and Alice did not … r=da-kami a=da-kami

Bob has to check for the possibility to cancel in every state after he locked the BTC.
Otherwise Bob will try to perform actions that don't have any point and it might be impossible to use the `resume` command because it will always fail in trying to go on with Alice even though that might not be possible.

Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Franck Royer 297b15e3ce
Remove async block when it is not needed 4 years ago
Franck Royer 1fa812b727
Separate Buy/Sell for resume command
To avoid confusing the user on whether person should enter a listen addr
or a connect peer id and address
4 years ago
Daniel Karzel a692cf9299 Remove all short-codes because they don't add value at the moment 4 years ago
Daniel Karzel c9d492d155 Only wait for xmr-lock until t1 expired 4 years ago
Daniel Karzel 83ce6f2c85 Ensure that Bob can cancel correctly if T1 expired and Alice did not move
Bob has to check for the possibility to cancel in every state after he locked the BTC.
Otherwise Bob will try to perform actions that don't have any point.
4 years ago
Daniel Karzel 8296490764
Merge pull request #111 from comit-network/trace-xmr-btc
Fix tracing subscribe filter for xmr-btc`
4 years ago
Daniel Karzel 5f8b7f2624 Fix tracing subscribe filter for xmr-btc` 4 years ago
Franck Royer 40a27a2438
Remove dead code 4 years ago
Franck Royer df237f82cf
Fix clippy warning 4 years ago
Franck Royer 49b84d84b9
Add address at the start
Do not carry peer id around as we currently only expect one peer.
4 years ago
Franck Royer 2abf65f3b6
Remove sleep that seems unnecessary 4 years ago
Franck Royer 4a4e23038b
Add logging to investigate add address race condition 4 years ago
Franck Royer 1a4bd0e2b4
Bob refunds swap after restart that requires communication
As Bob is dialing Alice, we now ensure that we are connected to Alice
at each step that needs communication.
If we are not connected, we proceed with dialing.

In an attempt to improve libp2p usage, we also add known address of
Alice first and only use peer_id to dial.
This ensures that we use the expected peer id.
4 years ago
bors[bot] 3db71997d3
Merge #99
99: Cleanup resume_from_database functions only used in tests r=da-kami a=da-kami

Follow up of https://github.com/comit-network/xmr-btc-swap/pull/88

Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
bors[bot] 4f631c0c9b
Merge #98
98: Remove tor module r=da-kami a=da-kami

This removes the currently unused `tor module`.
Different `tokio` versions have been causing issues with the `tor` module in the past (i.e. `Cargo.lock` broken problem...). It started causing issues again when adding a dependency to `jsonrpc_client` working on https://github.com/comit-network/xmr-btc-swap/pull/97

We don't support `tor` at the moment and are no planning to add this feature initially as it is not super important to users. 
The functionality can easily added again at a later point.

Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
bors[bot] 88c29dbce5
Merge #94
94: T1Expired state for Bob and check expiries in states after both locked r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Daniel Karzel 4046305474
Merge pull request #88 from comit-network/resume-swap-cli
Resume command and global database cl-parameter
4 years ago
Daniel Karzel 20893c1bb1 Cleanup Display for database states 4 years ago
Daniel Karzel e6493784bf Change `pin_mut!` to `select!` 4 years ago
Daniel Karzel 773eebc723 Cleanup resume_from_database functions only used in tests 4 years ago
Daniel Karzel e9681b6e2b Work in review comments 4 years ago
Daniel Karzel 43d05935e7 Remove tor module 4 years ago
Daniel Karzel 093cbaa4b4 Introduce T1Expired state for Bob properly and check expiries in states after both locked 4 years ago
Daniel Karzel 6d03d1bbff Resume command and global database cl-parameter 4 years ago
Franck Royer 71cf501c29
Delete `bob::negotiate`
This module was intended to contain helper functions for each step.

However, those are not needed except for the negotiate step.
A dedicated module is not needed for one function.
4 years ago
Franck Royer 19066200d1
Add a TODO to use existing helper functions
Helper functions already exist on the xmr-btc crate states, use them
like it is done in the bob module.
4 years ago
Franck Royer 84bec0631b
Rename alice::negotiate to steps
This module includes helper function for each state.
4 years ago
Franck Royer 53d13330c2
Remove dupe code 4 years ago
Franck Royer 5ba830f3bf
Replace swap `recover` terminology with `resume` 4 years ago
Franck Royer 8cc470a80e
Use `-ed` terminology for cancel state 4 years ago
Daniel Karzel 7cae6a9e4d
Add Bob restart test 4 years ago
Daniel Karzel 91d4d5da25
Cleanup swap execution to not return EventLoopHandle, refactor both_refund test 4 years ago
Daniel Karzel 3692046758
Bob's recover function 4 years ago
rishflab 143d8bc07d
Move message0 response handler out of NB 4 years ago
Daniel Karzel 4143394767
Add recovery function for Alice 4 years ago
rishflab 4b00141c29
Fix happy path test 4 years ago
Franck Royer 4ce8695dfc
Align with origin/database 4 years ago
Franck Royer 1a5b9f9fa9
Update tests after rebase 4 years ago
Franck Royer c4cdd098fd
Use from instead of try_from for Alice state conversion 4 years ago
Franck Royer caf903acda
wip: Add test for when bob restarts 4 years ago
Franck Royer 905fc6cf35
Save Bob state during swap 4 years ago
Franck Royer 64b021daf4
Save Alice states in db 4 years ago
Franck Royer 238f6a989d
Extract spend key as soon as possible 4 years ago
Franck Royer c095693a5f
Refund swap if resumed from a step that requires further communication 4 years ago
Franck Royer 11cea9ba69
Remove passing alice peer id
The usage of the peer id is incorrect as we do not even check it when
dialing. For now, we can ignore it.
We can then re-introduce it and use it properly at a later stage.
4 years ago
rishflab d8d6477ee9 Remove and fix comments 4 years ago
rishflab 7af4b6980a Test Alice refunds after Bob refund
Reworked Alice XmrLocked state transition handler to handle the
scenario when Alice received the encsig but Bob refunds.
Previously Alice was trying to redeem after receiving the encsig
without checking if t1 had elapsed.
4 years ago
rishflab 78c6a1a78f Add Bob refund execution 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
Franck Royer ef6e8fc723
Clean-up unused code 4 years ago
Franck Royer e71bf7d8e9
Add comment regarding processing in network behaviour 4 years ago
Franck Royer 2c9fb7b1da
Rename var to match type name 4 years ago
Franck Royer 91d28682ed
Remove comments 4 years ago
Franck Royer 53aae5cf5f
Use anyhow macro as intended 4 years ago
Franck Royer 51cc44484b
Remove unneeded pub qualifiers 4 years ago
rishflab 9ba89194b0 Rename swarm driver to event loop 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 27d1334726 Init Alice behaviour with state0
Previously state0 had to be set after creating Alice's behaviour.
With the event loop we no longer has access to the swarm so
set_state0() has to be called indirectly through a channel. This
means it is difficult to guarantee state0 is being set due to the
asynchronous nature of channels. This was solved by initialising
Alice with state0.
4 years ago
rishflab 3d8866f1a0 Convert event loop to use fused futures select
Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
rishflab 58da1df9dc Create SwarmDriverHandle to resolve ownership issues 4 years ago
rishflab 6f7408ecce Drive swarm in seperate async task
Previously the libp2p swarm had to be manually polled within the
protocol execution code to execute actions such as sending a
message. The swarm is now wrapped in SwarmDriver which polls the
swarm in a seperate task
4 years ago
rishflab f88ed9183b
Merge pull request #54 from comit-network/bob-unhappy-paths
Punish Test
4 years ago
rishflab 8592ef5f79 Address PR feedback
Add context to logging statements. Use amount type for monero in tests. Remove stale
code and comments.
4 years ago
Franck Royer 78674818c2
Upgrade bitcoin-harness 4 years ago
rishflab c91e9652aa Add alice punish test
Use reusable test init functions for happy path test

Extract tracing setup to reusable function

Move test initialization to seperate functions

Increase stack size in CI

Fix monero max finality time

Force Bob swarm polling to send message 2

Run Bob state to xmr_locked in punish test to force the sending of
message2. Previously Bob state was run until btc_locked. Although
this was the right thing to do, message2 was not being sent as the
swarm was not polled in btc_locked. Alice punish test passes.

Add info logging to executor
4 years ago
rishflab 5fef68322a Allow Alice to exit execution at a specified state 4 years ago
rishflab 584cc22024 Allow Bob to exit execution at a specified state 4 years ago
Franck Royer 624716d8a7
Upgrade rust-bitcoin to 0.25 4 years ago
Franck Royer 765482b0aa
Implement `wait_for_transaction_finality` 4 years ago
rishflab 1c401aad31 Fix clippy warnings and formatting 4 years ago
rishflab b06321a40f WIP: cleanup 4 years ago
rishflab 47c3ddc6f7 Fix happy path test
Poll bob swarm to send encsig after calling send message3. Comment
out unimplmented wait for transaction finality trait. Dial alice.
4 years ago
Franck Royer 2abeba17f9
Save state0 in the swarm to process message0 4 years ago