RGB-Tools / rgb-lib

MIT License
44 stars 25 forks source link

`Internal(Unexpected)` in `Wallet.create_utxos()`. #17

Closed monaka closed 1 year ago

monaka commented 1 year ago

Hello,

I got a panicked message in my test. The value of Err is Internal(Unexpected) so it's hard to see the root cause for me. Could you give me any hints to shooting this issue?

Best,


The short log is here:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Internal(Unexpected)', src/wallet/utxos.rs:30:89

The line 29-31 of src/wallet/utxos.rs is:

                return HttpResponse::Ok().json(UtxosResult {
                   num_utxos_created: _utxos(wallet, online, params.into_inner()).await.unwrap(),
                })

The funtion _utxos is:

async fn _utxos(mut wallet: Wallet, online: Online, params: UtxosParams) -> Result<u8, rgb_lib::Error> {
    println!("{:?}", online);
    actix_web::rt::task::spawn_blocking(move || {
        wallet.create_utxos(online, params.up_to, params.num, params.size)
    }).await.unwrap()
}

The value of arguments are:

Containers for debugging are:

208b8ae4cbd4   registry.gitlab.com/hashbeam/docker/electrs:0.9.9   "/usr/local/bin/star…"   2 hours ago   Up 2 hours   24224/tcp, 0.0.0.0:50001->50001/tcp                                rgb-electrs
4aad24fc28f2   registry.gitlab.com/hashbeam/docker/bitcoind:23.0   "/usr/local/bin/star…"   2 hours ago   Up 2 hours   8332-8333/tcp, 18332-18333/tcp, 18443-18444/tcp, 28332-28333/tcp   rgb-bitcoind
m
monaka commented 1 year ago

I tried to shoot this issue. And it works well auto-magically. This may be a flaky test. I'm not sure but I think bdk_wallet inside may be related to this issue.

I'll re-open this if I cloud find how to reproduce.

monaka commented 1 year ago

Same issue again.

I patched my fork like this.

diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs
index eeb9b22..68a5572 100644
--- a/src/wallet/mod.rs
+++ b/src/wallet/mod.rs
@@ -1085,11 +1085,25 @@ impl Wallet {

         let unsigned_psbt = self.create_utxos_begin(online.clone(), up_to, num, size)?;

-        let mut psbt =
+        /*
+         * let mut psbt =
             PartiallySignedTransaction::from_str(&unsigned_psbt).map_err(InternalError::from)?;
+
         self.bdk_wallet
             .sign(&mut psbt, SignOptions::default())
             .map_err(InternalError::from)?;
+*/
+        let mut psbt =
+            match PartiallySignedTransaction::from_str(&unsigned_psbt) {
+                Ok(psbt) => psbt,
+                Err(err) => panic!("{}", err),
+            };
+
+        match self.bdk_wallet
+            .sign(&mut psbt, SignOptions::default()) {
+            Ok(_) => (),
+            Err(err) => panic!("{}", err),
+        }

         self.create_utxos_end(online, psbt.to_string())
     }
@@ -1185,10 +1199,17 @@ impl Wallet {
         let tx = self._broadcast_psbt(signed_psbt)?;

         let mut num_utxos_created = 0;
-        let bdk_utxos: Vec<LocalUtxo> = self
+        /*let bdk_utxos: Vec<LocalUtxo> = self
             .bdk_wallet
             .list_unspent()
             .map_err(InternalError::from)?;
+        */
+        let bdk_utxos: Vec<LocalUtxo> = match self
+            .bdk_wallet
+            .list_unspent() {
+                Ok(bdk_utxos) => bdk_utxos,
+                Err(err) => panic!("{}", err),
+            };
         for utxo in bdk_utxos.into_iter() {
             let db_txo = self
                 .database

The log was unchanged. Even though I expected the panic was raised in similar places that call .map_err.

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Internal(Unexpected)', src/wallet/utxos.rs:29:89
monaka commented 1 year ago

The log from rgb-lib is this:

2022-12-16T09:54:31.318+00 INFO[/home/monaka/.cargo/git/checkouts/rgb-lib-f556c579d2c2f978/e3bdee1/src/wallet/mod.rs:697:9] Creating wallet in '"/tmp/shiro-wallet/60ec7707"'
2022-12-16T09:54:31.424+00 INFO[/home/monaka/.cargo/git/checkouts/rgb-lib-f556c579d2c2f978/e3bdee1/src/wallet/mod.rs:1083:9] Creating UTXOs...
2022-12-16T09:54:31.424+00 INFO[/home/monaka/.cargo/git/checkouts/rgb-lib-f556c579d2c2f978/e3bdee1/src/wallet/mod.rs:1136:9] Creating UTXOs (begin)...
2022-12-16T09:54:31.425+00 DEBG[/home/monaka/.cargo/git/checkouts/rgb-lib-f556c579d2c2f978/e3bdee1/src/wallet/mod.rs:813:9] Syncing TXOs...

An unexpected something happens in create_utxos_begin() before "Will try to create {} UTXOs".

monaka commented 1 year ago

Ah, I see. I'm not using the library as expected. And the Wallet object doesn't provide a feature that I expected now... Hmm...

I close this issue and will submit another feature request with short sample code.

Thanks,