Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO error reported on "fetch-offers" #375

Closed
AdamISZ opened this issue Jan 11, 2025 · 40 comments · Fixed by #380
Closed

IO error reported on "fetch-offers" #375

AdamISZ opened this issue Jan 11, 2025 · 40 comments · Fixed by #380

Comments

@AdamISZ
Copy link

AdamISZ commented Jan 11, 2025

Running 84862cf on ubuntu 22.04

When running

taker -a u:p -r 127.0.0.1:48332 fetch-offers

I get, the first couple of times I try:

Fetching offerdata from the market. use `tail -f <data-dir>/debug.log` to see progress.
Error: IO(Os { code: 2, kind: NotFound, message: "No such file or directory" })

I'm guessing (seems it must be) simply an initial failure to connect over Tor to the directory server in the config.toml. The third time I tried I got an OfferBook struct returned.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 11, 2025

Further to this, I've tried maybe 15 times now over about 15 minutes and get the same error repeated, when trying the coinswap command:

taker -a u:p -r 127.0.0.1:48332 coinswap
Starting coinswap with swap params : SwapParams { send_amount: 20000 SAT, maker_count: 2, tx_count: 1, required_confirms: 1 }. use `tail -f <data-dir>/debug.log` to see progress.
Error: IO(Os { code: 2, kind: NotFound, message: "No such file or directory" })

I guess if there's an actionable item here it might be to give the users a more informative error for this one, if, as I suspect, this is about flaky Tor connections. I don't think it's anything else because of the situation I recorded above, where it worked 3rd try.

@mojoX911
Copy link

mojoX911 commented Jan 12, 2025

Thank you sir for trying the app and taking a look. Your work on coinswap before has been foundational for us to start this project. Can you please you share the taker log file?

It should be in ~/.coinswap/taker/debug.log.

I guess if there's an actionable item here it might be to give the users a more informative error for this one

Yes, I agree. The software is in early beta, and we have many errors we need to cover manually for more helpful messaging.

The error seems to indicate some kind of i/o problem with files, not necessarily tor-related or fatal, although should not happen in regular ubuntu systems. Looking at the log file will give more clarity.

We will have much more polish the logs and user interface in the coming releases.

@mojoX911
Copy link

As a swap takes quite some time (2 confs for now) it's also intended to look into the log file. Thus the message to tail -f <datadir>/debug.log.

We will do a better job at displaying logs in future.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

Thanks. I will post a log in a minute. I noticed something interesting though, while reviewing it myself:

2025-01-11T15:02:59.579048660-06:00 WARN coinswap::taker::api - Fidelity Proof Verification failed with error: Rpc(JsonRpc(Rpc(RpcError { code: -5, message: "No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions.", data: None }))). Adding this to bad maker list : hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102

I don't think you require txindex for fidelity bond verification, no? Just access the utxo and have the maker provide the information to reconstruct the scriptPubKey? I think that's right, but it's a been a while and I might have forgotten something.

@mojoX911
Copy link

I don't think you require txindex for fidelity bond verification, no?

You are probably right. Although many of our current sync logic requires -txindex. We can potentially do that without it also, but that's planned for later. We will modify the sync code a lot later, by adding more syncing backends, like 3rd party APIs, compact block filters, block streaming via zmq, etc. So the current sync code is not very polished.

This seems to be happening because the taker is trying to assert that the fidelity utxo exists, and that call right now requires a -txindex.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

OK, currently I have the following situation: whenever I run coinswap (so same command line as above) I get:

2025-01-12T08:50:29.943027505-06:00 INFO coinswap::taker::api - Wallet file at "/home/waxwing/.coinswap/taker/wallets/taker-wallet" successfully loaded.
2025-01-12T08:50:29.943193118-06:00 INFO coinswap::taker::api - Wallet file at "/home/waxwing/.coinswap/taker/wallets/taker-wallet" successfully loaded.
2025-01-12T08:50:29.943294634-06:00 INFO coinswap::taker::config - Successfully loaded config file from : /home/waxwing/.coinswap/taker/config.toml
2025-01-12T08:50:29.943333142-06:00 INFO coinswap::taker::config - Successfully loaded config file from : /home/waxwing/.coinswap/taker/config.toml
2025-01-12T08:50:29.944314875-06:00 INFO coinswap::taker::api - Succesfully loaded offerbook at : "/home/waxwing/.coinswap/taker/offerbook.dat"
2025-01-12T08:50:29.944348309-06:00 INFO coinswap::taker::api - Succesfully loaded offerbook at : "/home/waxwing/.coinswap/taker/offerbook.dat"
2025-01-12T08:50:29.944370953-06:00 INFO coinswap::taker::api - Initializing wallet sync
2025-01-12T08:50:29.944383736-06:00 INFO coinswap::taker::api - Initializing wallet sync
2025-01-12T08:50:30.245507852-06:00 INFO coinswap::taker::api - Completed wallet sync
2025-01-12T08:50:30.245552078-06:00 INFO coinswap::taker::api - Completed wallet sync
2025-01-12T08:50:30.245836236-06:00 INFO coinswap::taker::api - Shutting down taker.
2025-01-12T08:50:30.245853470-06:00 INFO coinswap::taker::api - Shutting down taker.
2025-01-12T08:50:30.245922677-06:00 INFO coinswap::taker::api - offerbook data saved to disk.
2025-01-12T08:50:30.245934518-06:00 INFO coinswap::taker::api - offerbook data saved to disk.
2025-01-12T08:50:30.246093039-06:00 INFO coinswap::taker::api - Wallet data saved to disk.
2025-01-12T08:50:30.246103472-06:00 INFO coinswap::taker::api - Wallet data saved to disk.

I notice "shutting down taker" immediately after "completed wallet sync". Hypothesis: is it possible that because each of the 2 makers were reported "bad" as per above, that it concludes there are no available makers, from the offer book, and gives up?

This would make sense because yesterday, when trying to fetch-offers, I did see tor setup:

2025-01-11T15:02:43.906528793-06:00 INFO coinswap::utill - Jan 11 15:02:43.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
2025-01-11T15:02:43.906560916-06:00 INFO coinswap::utill - Jan 11 15:02:43.000 [notice] Bootstrapped 100% (done): Done
2025-01-11T15:02:43.906605-06:00 INFO coinswap::taker::api - tor is ready!
2025-01-11T15:02:43.906623331-06:00 INFO coinswap::taker::api - tor is ready!
2025-01-11T15:02:43.906651182-06:00 INFO coinswap::taker::api - Fetching addresses from DNS: bhbzkndgad52ojm75w4goii7xsi6ou73fzyvorxas7swg2snlto4c4ad.onion:8080
2025-01-11T15:02:43.906668791-06:00 INFO coinswap::taker::api - Fetching addresses from DNS: bhbzkndgad52ojm75w4goii7xsi6ou73fzyvorxas7swg2snlto4c4ad.onion:8080
2025-01-11T15:02:51.958494186-06:00 INFO coinswap::taker::routines - Attempting to download Offer from hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-11T15:02:51.958763400-06:00 INFO coinswap::taker::routines - Attempting to download Offer from 2uzkhckocxu47slrshdxaxl5zvgpk62pieu37ce2bjgfm3yc4nmsahqd.onion:6102
2025-01-11T15:02:51.958899347-06:00 INFO coinswap::taker::routines - Attempting to download Offer from 2uzkhckocxu47slrshdxaxl5zvgpk62pieu37ce2bjgfm3yc4nmsahqd.onion:6102
2025-01-11T15:02:51.958939332-06:00 INFO coinswap::taker::routines - Attempting to download Offer from hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-11T15:02:51.958983020-06:00 INFO coinswap::taker::routines - Attempting to download Offer from 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102
2025-01-11T15:02:51.959237574-06:00 INFO coinswap::taker::routines - Attempting to download Offer from 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102
2025-01-11T15:02:55.767564422-06:00 INFO coinswap::taker::routines - Got offer from : hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102 | Offer { base_fee: 100, amount_relative_fee_pct: 0.1, time_relative_fee_pct: 0.005, required_confirms: 1, minimum_locktime: 20, max_size: 449700, min_size: 10000, tweakable_point: PublicKey { compressed: true, inner: PublicKey(f1aa89502f733f044de915a14990d33749e06d3b851835d1896ad02ae5755fb3f10e96204c8001112f4ada07c195e32e6e02be7491f69c19d7d90711e084b24e) }, fidelity: FidelityProof { bond: FidelityBond { outpoint: OutPoint { txid: 22cd02975e5ac394e51573c14c0f2abd0d9568de56192d54fcbab22fa925c06d, vout: 0 }, amount: 50000 SAT, lock_time: 65712 blocks, pubkey: PublicKey { compressed: true, inner: PublicKey(5be2b5677aea8efff886077d5854ea2f7bee65aa64284f6b27d931a1a73a0d9037744874202eeccca7819513ee823f27818e86a8c260f7bcb042f707a536f6b4) }, conf_height: 63553, cert_expiry: 36 }, cert_hash: 0x415d75ee8c756752e30349e3995c432a4611f016354d7100e76816537826ad96, cert_sig: 3044022056381932242c4a0baf5efa5c5dfc632357c217ed4f20aba59b0eec5c26e89eeb02201cc4f79a9822a2caa070fe87180e097069c0b55bf3343af6d9e6f85c0ac0c670 } }

(as per the first message, this was the successful attempt after three/two previous attempts failed to bootstrap tor all the way)

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

This seems to be happening because the taker is trying to assert that the fidelity utxo exists, and that call right now requires a -txindex.

Ah I see. So I'll resync testnet4 with txindex enabled. Did I miss that requirement in the setup instructions? Probably I did?

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

Is there a way I can change the log level from INFO to DEBUG or similar? Now even after enabling the txindex, I'm still just always getting that "start up, shut down" pattern I showed in the logs above.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

OK I found the issue:

let mut tor_process = Command::new("./target/debug/tor")

This assumes you are running from the repo root directory.
I was assuming you didn't need to because taker was installed to /usr/local/bin

@mojoX911
Copy link

mojoX911 commented Jan 12, 2025

Ah I see. So I'll resync testnet4 with txindex enabled. Did I miss that requirement in the setup instructions? Probably I did?

We have a bitcoind reference conf file here that tells what flags are needed. https://github.com/citadel-tech/coinswap/blob/master/docs/app%20demos/bitcoind.md#2-setting-up-a-bitcoinconf-file

But yes these requirements can be made more clear in the readme instructions too.

This assumes you are running from the repo root directory.

Ah this is a hack we had to use to get libtor working with the apps. Thats probably where the file not found error is coming from. We should mention this in the readme instructions. Currently there is no good way to determine where this binary will be without this assumption. But ya this makes it a hard requirement to run the apps in the project root directory only.

Just from your local repo running the app with ./target/debug/taker or cargo run taker should do. We will either find a good solution for this or find replacement of libtor, or find a way to do libtor without this extra tor binary.

Also if you get a NotEnoughMakers error because of the previous failed fidelity, just remove the datadir/taker/offerbook.dat and start again. That will make it start from a fresh offerbook.

Pasisng a -v debug flag to taker will add the debug logs too. But currently most of the logs in the crate are in info and not much in debug mode.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

Yes, I should have added, it's running fine after moving to the repo root.

Pasisng a -v debug flag to taker will add the debug logs too. But currently most of the logs in the crate are in info and not much in debug mode.

OK good to know.

@mojoX911
Copy link

Great. Did the swap complete? it should print a Successfully Completed Coinswap. in the log when done.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

Seems not, though I'm not sure in detail:

2025-01-12T10:13:31.978086513-06:00 INFO coinswap::taker::api - Contract transactions were broadcasted : [ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, fe8f456783a152dc910ae16793c9768cb2237010aebeb9660d95cced442af01c]
2025-01-12T10:13:31.978228124-06:00 INFO coinswap::taker::api - Contract transactions were broadcasted : [ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, fe8f456783a152dc910ae16793c9768cb2237010aebeb9660d95cced442af01c]
2025-01-12T10:13:31.978296095-06:00 ERROR coinswap::taker::api - Error: ContractsBroadcasted([ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, fe8f456783a152dc910ae16793c9768cb2237010aebeb9660d95cced442af01c])
2025-01-12T10:13:31.978346939-06:00 ERROR coinswap::taker::api - Error: ContractsBroadcasted([ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, fe8f456783a152dc910ae16793c9768cb2237010aebeb9660d95cced442af01c])
2025-01-12T10:13:31.978401442-06:00 WARN coinswap::taker::api - Starting recovery from existing swap
2025-01-12T10:13:31.978423458-06:00 WARN coinswap::taker::api - Starting recovery from existing swap
2025-01-12T10:13:31.982199708-06:00 INFO coinswap::taker::api - Outgoing Contract already broadcasted
2025-01-12T10:13:31.982253852-06:00 INFO coinswap::taker::api - Outgoing Contract already broadcasted
2025-01-12T10:13:32.485169545-06:00 INFO coinswap::taker::api - Wallet file synced and saved.
2025-01-12T10:13:32.485215444-06:00 INFO coinswap::taker::api - Wallet file synced and saved.
2025-01-12T10:13:32.487648386-06:00 INFO coinswap::taker::api - Contract Tx : ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, reached confirmation : None, required : 60
2025-01-12T10:13:32.487716861-06:00 INFO coinswap::taker::api - Contract Tx : ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, reached confirmation : None, required : 60
2025-01-12T10:23:32.491822501-06:00 INFO coinswap::taker::api - Contract Tx : ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, reached confirmation : Some(1), required : 60
2025-01-12T10:23:32.491990047-06:00 INFO coinswap::taker::api - Contract Tx : ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, reached confirmation : Some(1), required : 60
2025-01-12T10:33:32.496044140-06:00 INFO coinswap::taker::api - Contract Tx : ab05bd338e1034f9bc0416ee4f5029b522f9c8e0b5a55fdc5abf5815dce88045, reached confirmation : Some(1), required : 60

obviously that will be ongoing for a while

@mojoX911
Copy link

Huh. That's a recovery being triggered. Did the funding transaction took more than 30 mins to confirm?

I will look into the maker logs to see what went wrong. Ya this will take some time, and once recovered you will see the coins again with list-utxo. In the meantime let us debug deeper to see what's going on.

If possible if you can share the whole log from the start of the coinswap that will be helpful. Every swap has a unique id printed at the start of the log, that will help us identify this particular swap in the makers.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

coinswaplog1.txt

attached is the log up till now.

@mojoX911
Copy link

It's safe to ctrl+c the taker and not wait for the full recovery. When you start taker next time, do taker recover which will resume the recovery. If the contracts are already confirmed by that time it will reclaim them with the timelock path.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 12, 2025

Yes, it's finished. Please feel free to close this whenever, of course, but I'd appreciate it if you drop a note in here if/when you figure out why it failed; I'm curious to know.

@mojoX911
Copy link

mojoX911 commented Jan 13, 2025

It seemed like everything was normally going. Then the 2nd funding tx took more than 30 mins to confirm. This doesn't usually happen, but can happen in testnet due to unpredictable block issuance.

2025-01-12T16:13:28.151422470+00:00 ERROR coinswap::maker::api - [6102] Potential Dropped Connection from taker. No response since : 1800 secs. Recovering from swap
2025-01-12T16:13:28.166075992+00:00 INFO coinswap::maker::api - [6102] Spawning recovery thread after Taker dropped

We will release a patch to increase this timeout by more than 30 minutes. In the meantime, can you try the swap again? Most of the time blocks come within 30 minutes, so this was an unfortunate event.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 13, 2025

It seemed like everything was normally going. Then the 2nd funding tx took more than 30 mins to confirm. This doesn't usually happen, but can happen in testnet due to unpredictable block issuance.

2025-01-12T16:13:28.151422470+00:00 ERROR coinswap::maker::api - [6102] Potential Dropped Connection from taker. No response since : 1800 secs. Recovering from swap
2025-01-12T16:13:28.166075992+00:00 INFO coinswap::maker::api - [6102] Spawning recovery thread after Taker dropped

We will release a patch to increase this timeout by more than 30 minutes. In the meantime, can you try the swap again? Most of the time blocks come within 30 minutes, so this was an unfortunate event.

Are you sure? In my log I see 2 funding/transactions waiting for confirmation before the "Error" part near the end. The first is about 13 minutes, the second is 20 minutes. Is it perhaps the fact that both together are more than 30? Or maybe just connection issues?

Oh well, either way, no problem just trying it again. Will do.

@mojoX911
Copy link

It could have been a connection issue but in this case seems like not. The maker log shows that it didn't receive any communication from taker, while the taker seems to be waiting for confirmation. Also, connection errors would have created some more logs and taker would tried more aggressively to reconnect.

We are working on a patch to decouple this confirmation wait time from the actual connection dropping wait. And also adding logging in taker to more clearly show how long it is waiting for confirmation.

If the plan goes well then we should be able to wait as long as it needs for confirmation without timing out at the maker. Keeping this issue open till this is fixed and will update here.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 13, 2025

Here is a log of my second try. The coinswap was successful but just in case it's of interest:

coinswaplog2.txt

@mojoX911
Copy link

mojoX911 commented Jan 14, 2025

Awesome. Yes thats a succeful swap. Please let us know if any major gaps or potential improvements you can see in the protocol.

We also have implemented our own fidelity bond concept here, which is slightly different from joinmarket's fidelity. Would love to hear your feedback on that too.

Thanks for trying out and the feedbacks. We will keep continuously improving the systems.

@mojoX911 mojoX911 reopened this Jan 14, 2025
@mojoX911 mojoX911 linked a pull request Jan 15, 2025 that will close this issue
@AdamISZ
Copy link
Author

AdamISZ commented Jan 15, 2025

Rather embarrassingly, I realise I didn't actually check whether the coinswap had worked, and now I look, I seem to be missing funds. I've probably just missed a step.

Before I started the swap, my balance was 201953 SAT as reported by get-balance. Now it is 180797 SAT (a couple of days later). The discrepancy is not strange, of course it is roughly the amount of the swap, and moreover list-utxos shows after that the initial funding transaction 598d0daabbac7821c8044616fb775fcd0368212fcea569fb791b994151ab83d8 (as you can see in the logs), I have no further utxos at higher block heights, so basically I did not "receive back" the coins. Is it a matter of me having to do some kind of extra step? "recover" seems to be not correct according to the help message. And list-utxos-contract shows nothing as does get-balance-contract.

I could investigate more but running out of time, and I'm sure you can diagnose this way quicker.

@mojoX911
Copy link

mojoX911 commented Jan 16, 2025

Thats weird and it should not happen. There is no extra step to do if the swap completes.

We currently have a calculation problem at get-balance that adds the balances locked in contract transactions too. All of these problems are being addressed in this PR: #380

But in any case it should not be missing any funds and its working as expected in our manual tests.

An example:
Initial get-balance: 54420
After swap balance: get-balance: 53220

The difference is 1200 sats. This is distributed as 1200 = 900 (miner fees of 3 funding txs) + 160 (first maker's fee) + 140 (second maker's fee).

Even with the current bug at get-balance it should show a difference of 1200 sats between before and after.

Can you check get-balance-swap and list-utxo-swap? That should have your swap utxo (it would be 2-of-2 multisig script pubkey) and the balance.

It also might happen that taker missed a sync call in last run and the new addresses to watch for was not imported in bitcoin core. Running a taker recover and shutting down after some time (30 secs) should fix that.

You can also check at list-utxo-contract if there is any live contract txs floating around. If so then run recover to claim them via timelock.

If the balance is still discrepant, please wait for the above PR merge and try again.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 16, 2025

OK, indeed recover did fix it (the balance is now 200497 SAT as expected); it seems the final tx of the swap was not previously broadcast. This is what I saw in the log:

2025-01-16T09:39:27.805503019-06:00 INFO coinswap::taker::api - Initializing wallet sync
2025-01-16T09:39:27.805518346-06:00 INFO coinswap::taker::api - Initializing wallet sync
2025-01-16T09:39:28.231220295-06:00 INFO coinswap::taker::api - Completed wallet sync
2025-01-16T09:39:28.231251269-06:00 INFO coinswap::taker::api - Completed wallet sync
2025-01-16T09:39:28.253632467-06:00 INFO coinswap::taker::api - Broadcasted Outgoing Contract, Contract txid : e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b
2025-01-16T09:39:28.253679418-06:00 INFO coinswap::taker::api - Broadcasted Outgoing Contract, Contract txid : e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b
2025-01-16T09:39:28.712318348-06:00 INFO coinswap::taker::api - Wallet file synced and saved.
2025-01-16T09:39:28.712341632-06:00 INFO coinswap::taker::api - Wallet file synced and saved.
2025-01-16T09:39:28.713832018-06:00 INFO coinswap::taker::api - Contract Tx : e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b, reached confirmation : None, required : 60
...

I didn't quit the "coinswap" command early, I waited for it to finish, and the command line showed "successfully completed coinswap!!":

waxwing@here:~/code/coinswap$ taker -a u:p -r 127.0.0.1:48332 coinswap
Starting coinswap with swap params : SwapParams { send_amount: 20000 SAT, maker_count: 2, tx_count: 1, required_confirms: 1 }. use `tail -f <data-dir>/debug.log` to see progress.
succesfully completed coinswap!! Check `list-utxo` to see the new coins

so it seems something is definitely wrong.

@mojoX911
Copy link

mojoX911 commented Jan 16, 2025

Ah I see, it actually hit recovery routine and the swap didn't complete. And because the recovery was triggered within the swap process itself so the swap process returned as normal printing that line succesfully completed coinswap!!

The recovery routine would have sent the timelock tx after the contract tx gets confirmed. But probably that didn't happen for some reason. You can search for Recovery completed. message in the log. If that doesn't exists, that means taker app exited before recovery was complete and just gave the usual swap completion log.

Next time when you ran recover it identified the contract and resumed from where it left off. By that time the contract was already confirmed, so it sent the timelock and claimed back the funds.

We should bifurcate the log of these two outcomes well. Noting down in our todo.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 16, 2025

The recovery routine would have sent the timelock tx after the contract tx gets confirmed. But probably that didn't happen for some reason. You can search for Recovery completed. message in the log. If that doesn't exists, that means taker app exited before recovery was complete and just gave the usual swap completion log.

I gave the whole log of the coinswap operation above (see coinswaplog2.txt). But I didn't see anything in it indicating a failure or a recovery.

@mojoX911
Copy link

mojoX911 commented Jan 16, 2025

Yeah thats true. No sign of failed swap in the log. Then maybe it was the swap before that which went to recovery?

What do you see when you do list-utxo-swap? if this swap completed, that should give you one utxo in that list.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 16, 2025

list-utxo-swap still returns [].

@mojoX911
Copy link

Thats very weird. Is list-utxo-contract is also null?

@AdamISZ
Copy link
Author

AdamISZ commented Jan 16, 2025

No:

waxwing@here:~/code/coinswap$ taker -a u:p -r 127.0.0.1:48332 list-utxo-contract
[
    ListUnspentResultEntry {
        txid: e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b,
        vout: 0,
        address: Some(
            Address<NetworkUnchecked>(TB1QFYQK2TCGXUGD689F5J2753X35WVFL0HF8HS88FWX4NJZHJNK3Z0QFRZRUT),
        ),
        label: Some(
            "f6851d64",
        ),
        redeem_script: None,
        witness_script: None,
        script_pub_key: Script(OP_0 OP_PUSHBYTES_32 4901652f083710dd1ca9a495ea44d1a3989fbee93de073a5c6ace42bca76889e),
        amount: 19700 SAT,
        confirmations: 18,
        spendable: true,
        solvable: false,
        descriptor: None,
        safe: true,
    },
]

@mojoX911
Copy link

Okay so thats a contract that is still floating around. Once its matured it can be claimed back with recover. So I was wrong, the recovery is not complete.

But it still doesn't match with the log. Its clearly showing privkeys have been handed over, but no swap-utxos.

Problem is I cannot reproduce this as its not happening in my local or in the live network, or in our functional tests. I will keep trying more swaps and see if I hit a situation like this. There is no obvious error trails in the log to debug also. I can see some transient connection errors but they should be fine.

I will keep you posted if I find the root cause.

In the mean time, if you fancy, you can try a swap with #380 PR head. We have already updated the live makers with the patches. The PR head will give you latest taker where swap won't fail due to network, or blockchain latency or any transient errors, with some extra helpful logs. We will merge it soon.

@mojoX911
Copy link

Update: we have been able to hone in on the root cause. It's probably happening due to a bug in our recovery code that falsely identifies completed swap utxos as unfinished and attempting to recover from it.

This is not observable directly, but after the timelock is spent the incoming swap utxo from the taker would disappear. We are working on a fix and checking if there are more underlying bugs.

@mojoX911
Copy link

@AdamISZ All of the issues listed here should be solved with the merge of #380 .

Can you try it and see if the swaps are going as expected?

@AdamISZ
Copy link
Author

AdamISZ commented Jan 25, 2025

@AdamISZ All of the issues listed here should be solved with the merge of #380 .

Can you try it and see if the swaps are going as expected?

I should be able to test it tomorrow. Thanks!

@AdamISZ
Copy link
Author

AdamISZ commented Jan 26, 2025

First attempt today: everything's set up right but I couldn't access the offers; tor onion services being their usual reliable selves!

end of log looks like:

2025-01-26T09:53:56.116432234-06:00 WARN coinswap::taker::routines - Failed to request offer from maker hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102, with error: Net(IO(Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" })) reattempting 4 of 5
2025-01-26T09:53:57.117020114-06:00 INFO coinswap::taker::routines - Attempting to download Offer from hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-26T09:54:26.324595245-06:00 WARN coinswap::taker::routines - Failed to request offer from maker 2uzkhckocxu47slrshdxaxl5zvgpk62pieu37ce2bjgfm3yc4nmsahqd.onion:6102, with error: Net(IO(Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" })) reattempting 5 of 5
2025-01-26T09:54:27.325203129-06:00 INFO coinswap::taker::routines - Attempting to download Offer from 2uzkhckocxu47slrshdxaxl5zvgpk62pieu37ce2bjgfm3yc4nmsahqd.onion:6102
2025-01-26T09:54:27.348122873-06:00 WARN coinswap::taker::routines - Failed to request offer from maker 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102, with error: Net(IO(Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" })) reattempting 5 of 5
2025-01-26T09:54:27.860441780-06:00 WARN coinswap::taker::routines - Failed to request offer from maker hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102, with error: Net(IO(Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" })) reattempting 5 of 5
2025-01-26T09:54:28.348684552-06:00 INFO coinswap::taker::routines - Attempting to download Offer from 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102
2025-01-26T09:54:28.861141049-06:00 INFO coinswap::taker::routines - Attempting to download Offer from hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-26T09:54:58.580476084-06:00 ERROR coinswap::taker::routines - Connection attempt exceeded for request offer from maker 2uzkhckocxu47slrshdxaxl5zvgpk62pieu37ce2bjgfm3yc4nmsahqd.onion:6102
2025-01-26T09:54:59.604309685-06:00 ERROR coinswap::taker::routines - Connection attempt exceeded for request offer from maker hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-26T09:54:59.604441576-06:00 ERROR coinswap::taker::routines - Connection attempt exceeded for request offer from maker 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102
2025-01-26T09:54:59.604962056-06:00 ERROR coinswap::taker::api - Not enough makers in the offerbook. Required 2, avaialable 0
2025-01-26T09:54:59.605060859-06:00 INFO coinswap::taker::api - Shutting down taker.
2025-01-26T09:54:59.605234936-06:00 INFO coinswap::taker::api - offerbook data saved to disk.
2025-01-26T09:54:59.605879322-06:00 INFO coinswap::taker::api - Wallet data saved to disk.
2025-01-26T09:54:59.612093773-06:00 INFO coinswap::tor - Tor instance terminated successfully
Error: NotEnoughMakersInOfferBook

@mojoX911
Copy link

Our makers were temporarily down. All systems up now. Can you try again?

@AdamISZ
Copy link
Author

AdamISZ commented Jan 27, 2025

Sorry for delay. Here is my report. I ran this about 15 hours ago but just got back to my terminal to look at it.

Running 8cec81bf20c547787d348a11c674f3c12d8ec532

Log file:

coinswaplog3.txt

I now have:

waxwing@here:~/code/coinswap$ ./target/debug/taker get-balance
179597 SAT

which I presume is still wrong? I'm even more confused though by reading the output of list-utxo; it seems to add up to more than 220K!

then running list-utxo-contract I get:

[
    ListUnspentResultEntry {
        txid: e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b,
        vout: 0,
        address: Some(
            Address<NetworkUnchecked>(TB1QFYQK2TCGXUGD689F5J2753X35WVFL0HF8HS88FWX4NJZHJNK3Z0QFRZRUT),
        ),
        label: Some(
            "f6851d64",
        ),
        redeem_script: None,
        witness_script: None,
        script_pub_key: Script(OP_0 OP_PUSHBYTES_32 4901652f083710dd1ca9a495ea44d1a3989fbee93de073a5c6ace42bca76889e),
        amount: 19700 SAT,
        confirmations: 2010,
        spendable: true,
        solvable: false,
        descriptor: None,
        safe: true,
    },
]

so my best guess is we have a similar issue to last time? Note the commit I'm running on is current master.

So I tried recover, I got this:

waxwing@here:~/code/coinswap$ ./target/debug/taker recover
2025-01-27T09:10:53.439258011-06:00 INFO coinswap::taker::api - Wallet file at "/home/waxwing/.coinswap/taker/wallets/taker-wallet" successfully loaded.
2025-01-27T09:10:53.439424126-06:00 INFO coinswap::taker::config - Successfully loaded config file from : /home/waxwing/.coinswap/taker/config.toml
2025-01-27T09:10:53.440760997-06:00 INFO coinswap::taker::offers - Offerbook has trailing data, trying to restore
2025-01-27T09:10:53.529937203-06:00 INFO coinswap::taker::api - Succesfully loaded offerbook at : "/home/waxwing/.coinswap/taker/offerbook.dat"
2025-01-27T09:10:53.529954797-06:00 INFO coinswap::taker::api - Initializing wallet sync
2025-01-27T09:10:54.061837816-06:00 INFO coinswap::taker::api - Completed wallet sync
2025-01-27T09:10:54.061899692-06:00 INFO coinswap::wallet::api - Unfinished incoming txids: []
2025-01-27T09:10:54.061926734-06:00 INFO coinswap::wallet::api - Unfinished outgoing txids: [e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b]
2025-01-27T09:10:54.064874147-06:00 INFO coinswap::taker::api - Outgoing Contract already broadcasted | Txid: e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b
2025-01-27T09:10:54.605742704-06:00 INFO coinswap::taker::api - Wallet file synced and saved.
2025-01-27T09:10:54.606819464-06:00 INFO coinswap::taker::api - Contract Tx : e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b, reached confirmation : Some(2010), required : 60
2025-01-27T09:10:54.606869429-06:00 INFO coinswap::taker::api - Timelock maturity of 60 blocks for Contract Tx is reached : e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b
2025-01-27T09:10:54.606908631-06:00 INFO coinswap::taker::api - Broadcasting timelocked tx: 54959fd2faff8da18c0ca2eb1117062abfe663537e43e3a57e2fd6b792706dd6
2025-01-27T09:10:54.627494160-06:00 INFO coinswap::taker::api - Removed Outgoing Swapcoin from Wallet, Contract Txid: e0f5c3a9c7a5742e46c4ae2e4f4b6b2e6e78a999d4aab0701a2c6cd6a21b0e7b
2025-01-27T09:10:54.627566074-06:00 INFO coinswap::taker::api - Initializing Wallet sync and save
2025-01-27T09:10:55.112252501-06:00 INFO coinswap::taker::api - Completed wallet sync and save
2025-01-27T09:10:55.112280706-06:00 INFO coinswap::taker::api - 1 outgoing contracts detected | 1 timelock txs broadcasted.
2025-01-27T09:10:55.112296124-06:00 INFO coinswap::taker::api - All outgoing contracts reedemed. Cleared ongoing swap state
2025-01-27T09:10:55.112315470-06:00 INFO coinswap::taker::api - Recovery completed.
2025-01-27T09:10:55.112333406-06:00 INFO coinswap::taker::api - Shutting down taker.
2025-01-27T09:10:55.112385089-06:00 INFO coinswap::taker::api - offerbook data saved to disk.
2025-01-27T09:10:55.112558838-06:00 INFO coinswap::taker::api - Wallet data saved to disk.

After that, the balance is where we expect. Afaict from looking at the transaction, there is nothing "wrong" here, it's just the second leg of the coinswap right? So maybe there is still some bug that has the taker shut down early? Well either way, hope that helps.

(Btw are you interested in migrating to taproot at some point? The 2 of 2 multisig anon set is a bit limited I guess.)

@mojoX911
Copy link

mojoX911 commented Jan 27, 2025

The log says the the swap went smoothly. This is the typical log that signals succesful settlement.

2025-01-26T17:39:15.450974328-06:00 INFO coinswap::taker::api - ===> HashPreimage | 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102
2025-01-26T17:39:15.960608935-06:00 INFO coinswap::taker::api - <=== PrivateKeyHandover | 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102
2025-01-26T17:39:15.962098335-06:00 INFO coinswap::taker::api - ===> PrivateKeyHandover | 2myny4m5ehmcevx7iypq6v527i6syn7qaifvtxdru2mtobo36mhkhcid.onion:6102
2025-01-26T17:39:18.725556015-06:00 INFO coinswap::taker::api - ===> HashPreimage | hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-26T17:39:19.205928657-06:00 INFO coinswap::taker::api - <=== PrivateKeyHandover | hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-26T17:39:19.207218010-06:00 INFO coinswap::taker::api - ===> PrivateKeyHandover | hay55mcjfz4f23gaxvq3hh25dwrjxo3oyef4sai2u6csinafo27ihuqd.onion:6102
2025-01-26T17:39:19.207449513-06:00 INFO coinswap::taker::api - Initializing Sync and Save.
2025-01-26T17:39:19.817511438-06:00 INFO coinswap::taker::api - Completed Sync and Save.
2025-01-26T17:39:19.817523002-06:00 INFO coinswap::taker::api - Successfully Completed Coinswap.

The recovery you observed could be a recovery due to the previous bug. The maker's were broadcasting contracts out, so there was a contract that taker identified. The confirmation on the contract tx is 2010 blocks, so the contract was broadcasted long ago and definitely from a previous swap.

This bug is fixed, so no more contracts should be seen here on, unless the swap fails.

Check the balance, swap balance, and contract balance. You should see only one swap coin in balance and utxo list, as the previous bug made thge makers claim back all swaps after an unknown amount of time.

We are working on making the utxos lists more clean, that will be helpful in identifying different types of utxos.

If you make more swaps, balance, utxo list and swap process will be as per expected from now on. Thank you so much for testing and reporting, this helped us a lot to streamline the flow.

(Btw are you interested in migrating to taproot at some point? The 2 of 2 multisig anon set is a bit limited I guess.)

ETA v0.1.2. We will be using Taproot+Musig2 and compress the funding and contract tx together. That will change the current protocol a lot, but we are definitely going down that road.

@AdamISZ
Copy link
Author

AdamISZ commented Jan 27, 2025

The recovery you observed could be a recovery due to the previous bug. The maker's were broadcasting contracts out, so there was a contract that taker identified. The confirmation on the contract tx is 2010 blocks, so the contract was broadcasted long ago and definitely from a previous swap.

Ah yes, I see. Looks good then 👍

ETA v0.1.2. We will be using Taproot+Musig2 and compress the funding and contract tx together. That will change the current protocol a lot, but we are definitely going down that road.

Yeah, makes sense. Thanks for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants