Commit Graph

96 Commits (d8dacbdee99a8d951977e62db1c888cc9ed56ea8)

Author SHA1 Message Date
Daniel Karzel 47a31760c0 Bob can verify the Monero txs by tx-hash
Print tx-hashes for monero transactions to allow Bob to look the transaction up in block explorer.

The story of Bab:
Our famous actor Bob has a brother named Bab.
In school they were often mixed up, because their names were so similar.
Eventually Bab renamed himself into Barbara, but that was even more confusing for now he
carried a female name even though he was not female. Bob wanted to help his brother and told him he
could just go for Bub. But that did not solve anything. Fun fact: Bub is actually married to Alice.
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
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 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
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 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
Daniel Karzel 0945cee459 Remove traits in favour of public functions 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 babd1d7b60
Wait for refund if insufficient Monero is locked up 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 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 9ded728879
The first message is actually a quote or rate request 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 e82383bcf6
Avoid carrying rng 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 704a8e7b01
Add swap id to tracing context 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 d2a1937f51
Use `Message4` 3 years ago
Franck Royer f2a25ee49b
Move definitions out of lib.rs 3 years ago
Daniel Karzel 33a9057b1f Move run_until is_target_state comparison functions into testutils 3 years ago
Daniel Karzel 3593f5323a Bob saves lock proof after received so he can resume swap 3 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.
3 years ago
Franck Royer ae8134f04e
Replace amounts messages with swap res/req 3 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.
3 years ago
Daniel Karzel e91987e23f Fix rand import 3 years ago
Daniel Karzel 170e90ffed Rename do_run_until to _run_until_internal 3 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
3 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>
3 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>
3 years ago
Franck Royer 9a823dca4c
Do not introduced State6 3 years ago
Daniel Karzel 8615aaed6e Make lock-tx id available in redeem/punish state to be able to assert exact fees 3 years ago
rishflab f5cfe014be Fix imports 3 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
rishflab 5d7d72c826 Remove unused import 4 years ago
rishflab dcea54dbf1 Move protocol parent states into appropriate module 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