From 5bd275ca1afadcbefd867ba5d0ecab2747bbce1a Mon Sep 17 00:00:00 2001 From: benthecarman Date: Thu, 11 Jul 2024 18:51:13 -0500 Subject: [PATCH] Fedimint resync --- Cargo.lock | 356 +++++++++++++++++++++++++++++----- Cargo.toml | 16 +- mutiny-core/Cargo.toml | 16 +- mutiny-core/src/federation.rs | 110 ++++++++++- mutiny-core/src/lib.rs | 45 ++++- mutiny-wasm/Cargo.toml | 2 +- mutiny-wasm/src/indexed_db.rs | 5 +- mutiny-wasm/src/lib.rs | 17 ++ 8 files changed, 496 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58431221c..8ac6cc0cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -249,6 +249,18 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backon" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c491fa80d69c03084223a4e73c378dd9f9a1e612eb54051213f88b2d5249b458" +dependencies = [ + "fastrand", + "futures-core", + "pin-project", + "tokio", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -944,7 +956,7 @@ checksum = "d3e11244e7fd8b0beee0a3c62137c4bd9f756fe2c492ccf93171f81467b59200" dependencies = [ "bitcoin 0.29.2", "log", - "reqwest", + "reqwest 0.11.27", "serde", ] @@ -957,7 +969,7 @@ dependencies = [ "bitcoin 0.30.2", "bitcoin-internals 0.1.0", "log", - "reqwest", + "reqwest 0.11.27", "serde", ] @@ -990,8 +1002,8 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fedimint-aead" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "argon2", @@ -1002,8 +1014,8 @@ dependencies = [ [[package]] name = "fedimint-bip39" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "bip39", "fedimint-client", @@ -1013,8 +1025,8 @@ dependencies = [ [[package]] name = "fedimint-bitcoind" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "async-trait", @@ -1034,16 +1046,16 @@ dependencies = [ [[package]] name = "fedimint-build" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "serde_json", ] [[package]] name = "fedimint-client" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "aquamarine", @@ -1059,6 +1071,7 @@ dependencies = [ "futures", "itertools 0.12.1", "rand", + "reqwest 0.12.5", "ring 0.17.8", "secp256k1-zkp", "serde", @@ -1073,13 +1086,14 @@ dependencies = [ [[package]] name = "fedimint-core" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "async-lock", "async-recursion", "async-trait", + "backon", "backtrace", "bech32", "bincode", @@ -1093,6 +1107,7 @@ dependencies = [ "fedimint-tbs", "fedimint-threshold-crypto", "futures", + "futures-util", "getrandom", "gloo-timers 0.3.0", "hex", @@ -1126,8 +1141,8 @@ dependencies = [ [[package]] name = "fedimint-derive" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "itertools 0.12.1", "proc-macro2", @@ -1137,8 +1152,8 @@ dependencies = [ [[package]] name = "fedimint-derive-secret" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "fedimint-core", @@ -1150,16 +1165,16 @@ dependencies = [ [[package]] name = "fedimint-hkdf" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "bitcoin_hashes 0.11.0", ] [[package]] name = "fedimint-ln-client" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "aquamarine", @@ -1177,7 +1192,7 @@ dependencies = [ "itertools 0.12.1", "lightning-invoice 0.26.0", "rand", - "reqwest", + "reqwest 0.11.27", "secp256k1 0.24.3", "secp256k1-zkp", "serde", @@ -1192,8 +1207,8 @@ dependencies = [ [[package]] name = "fedimint-ln-common" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "aquamarine", @@ -1222,8 +1237,8 @@ dependencies = [ [[package]] name = "fedimint-logging" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "tracing-subscriber", @@ -1231,8 +1246,8 @@ dependencies = [ [[package]] name = "fedimint-mint-client" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "aquamarine", @@ -1266,8 +1281,8 @@ dependencies = [ [[package]] name = "fedimint-mint-common" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "async-trait", @@ -1290,8 +1305,8 @@ dependencies = [ [[package]] name = "fedimint-tbs" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "bitcoin_hashes 0.11.0", "bls12_381", @@ -1327,8 +1342,8 @@ dependencies = [ [[package]] name = "fedimint-wallet-client" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "aquamarine", @@ -1358,8 +1373,8 @@ dependencies = [ [[package]] name = "fedimint-wallet-common" -version = "0.3.0" -source = "git+https://github.com/MutinyWallet/fedimint.git?rev=450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf#450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" +version = "0.3.2" +source = "git+https://github.com/MutinyWallet/fedimint.git?rev=ae2503ed4e9fb8d80dd34271455bf3b31c4fe139#ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" dependencies = [ "anyhow", "async-trait", @@ -1807,6 +1822,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.0.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.8.0" @@ -1831,7 +1869,7 @@ dependencies = [ "futures-util", "h2", "http 0.2.11", - "http-body", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -1843,6 +1881,25 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -1851,12 +1908,30 @@ checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http 0.2.11", - "hyper", + "hyper 0.14.28", "rustls 0.21.10", "tokio", "tokio-rustls 0.24.1", ] +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http 1.0.0", + "hyper 1.4.1", + "hyper-util", + "rustls 0.23.7", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", + "webpki-roots 0.26.1", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -1864,12 +1939,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper", + "hyper 0.14.28", "native-tls", "tokio", "tokio-native-tls", ] +[[package]] +name = "hyper-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.4.1", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -2340,7 +2435,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b628658116d331c9567f6cb22415d726125ff6e328d1fb1b422b1b58afeaec21" dependencies = [ "bech32", - "reqwest", + "reqwest 0.11.27", "serde", "serde_json", ] @@ -2358,7 +2453,7 @@ dependencies = [ "bitcoin 0.30.2", "cbc", "email_address", - "reqwest", + "reqwest 0.11.27", "serde", "serde_json", "url", @@ -2589,7 +2684,7 @@ dependencies = [ "nostr-sdk", "payjoin", "pbkdf2 0.11.0", - "reqwest", + "reqwest 0.11.27", "serde", "serde_json", "thiserror", @@ -2689,7 +2784,7 @@ dependencies = [ "js-sys", "negentropy", "once_cell", - "reqwest", + "reqwest 0.11.27", "scrypt", "serde", "serde_json", @@ -3188,6 +3283,53 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ceeeeabace7857413798eb1ffa1e9c905a9946a57d81fb69b4b71c4d8eb3ad" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls 0.23.7", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddf517c03a109db8100448a4be38d498df8a210a99fe0e1b9eaf39e78c640efe" +dependencies = [ + "bytes", + "rand", + "ring 0.17.8", + "rustc-hash", + "rustls 0.23.7", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9096629c45860fc7fb143e125eb826b5e721e10be3263160c7d60ca832cf8c46" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.35" @@ -3308,9 +3450,9 @@ dependencies = [ "futures-util", "h2", "http 0.2.11", - "http-body", - "hyper", - "hyper-rustls", + "http-body 0.4.6", + "hyper 0.14.28", + "hyper-rustls 0.24.2", "hyper-tls", "ipnet", "js-sys", @@ -3322,11 +3464,11 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls 0.21.10", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 0.1.2", "system-configuration", "tokio", "tokio-native-tls", @@ -3338,7 +3480,49 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "webpki-roots 0.25.4", - "winreg", + "winreg 0.50.0", +] + +[[package]] +name = "reqwest" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +dependencies = [ + "base64 0.22.0", + "bytes", + "futures-core", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.4.1", + "hyper-rustls 0.27.2", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls 0.23.7", + "rustls-pemfile 2.1.2", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 0.26.1", + "winreg 0.52.0", ] [[package]] @@ -3458,6 +3642,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustls" +version = "0.23.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebbbdb961df0ad3f2652da8f3fdc4b36122f568f968f45ad3316f26c025c677b" +dependencies = [ + "once_cell", + "ring 0.17.8", + "rustls-pki-types", + "rustls-webpki 0.102.2", + "subtle", + "zeroize", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -3467,6 +3665,16 @@ dependencies = [ "base64 0.21.7", ] +[[package]] +name = "rustls-pemfile" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +dependencies = [ + "base64 0.22.0", + "rustls-pki-types", +] + [[package]] name = "rustls-pki-types" version = "1.3.0" @@ -3940,6 +4148,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "system-configuration" version = "0.5.1" @@ -4144,6 +4358,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls 0.23.7", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-socks" version = "0.5.1" @@ -4230,6 +4455,27 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -4858,6 +5104,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 661bb2612..4c2c4906e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,11 +22,11 @@ lightning-background-processor = { git = 'https://github.com/MutinyWallet/rust-l lightning-transaction-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e660e068f6f93b13dc782b2d607795716b48ed15" } lightning-net-tokio = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "e660e068f6f93b13dc782b2d607795716b48ed15" } -fedimint-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } -fedimint-core = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } -fedimint-wallet-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } -fedimint-mint-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } -fedimint-ln-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } -fedimint-bip39 = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } -fedimint-ln-common = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } -fedimint-tbs = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "450d9f6d3b6252ad3d80f2e96717722cbb6dd9cf" } +fedimint-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } +fedimint-core = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } +fedimint-wallet-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } +fedimint-mint-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } +fedimint-ln-client = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } +fedimint-bip39 = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } +fedimint-ln-common = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } +fedimint-tbs = { git = 'https://github.com/MutinyWallet/fedimint.git', rev = "ae2503ed4e9fb8d80dd34271455bf3b31c4fe139" } diff --git a/mutiny-core/Cargo.toml b/mutiny-core/Cargo.toml index e69b602cd..480377a4f 100644 --- a/mutiny-core/Cargo.toml +++ b/mutiny-core/Cargo.toml @@ -50,14 +50,14 @@ hex-conservative = "0.1.1" async-lock = "3.2.0" bitcoin-waila = "0.5.0" -fedimint-client = "0.3.0" -fedimint-core = "0.3.0" -fedimint-wallet-client = "0.3.0" -fedimint-mint-client = "0.3.0" -fedimint-ln-client = "0.3.0" -fedimint-bip39 = "0.3.0" -fedimint-ln-common = "0.3.0" -fedimint-tbs = "0.3.0" +fedimint-client = "0.3.2" +fedimint-core = "0.3.2" +fedimint-wallet-client = "0.3.2" +fedimint-mint-client = "0.3.2" +fedimint-ln-client = "0.3.2" +fedimint-bip39 = "0.3.2" +fedimint-ln-common = "0.3.2" +fedimint-tbs = "0.3.2" moksha-core = "0.2.1" base64 = "0.13.0" diff --git a/mutiny-core/src/federation.rs b/mutiny-core/src/federation.rs index 4f7595136..dca8750cd 100644 --- a/mutiny-core/src/federation.rs +++ b/mutiny-core/src/federation.rs @@ -38,6 +38,7 @@ use fedimint_client::{ }; use fedimint_core::bitcoin_migration::bitcoin30_to_bitcoin29_address; use fedimint_core::config::ClientConfig; +use fedimint_core::core::LEGACY_HARDCODED_INSTANCE_ID_MINT; use fedimint_core::{ api::InviteCode, config::FederationId, @@ -143,6 +144,13 @@ impl From for HTLCStatus { } } +#[derive(Debug, Serialize, Deserialize, Clone, Default)] +pub struct ResyncProgress { + pub total: u32, + pub complete: u32, + pub done: bool, +} + // This is the FederationStorage object saved to the DB #[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct FederationStorage { @@ -262,6 +270,7 @@ impl FederationClient { network: Network, stop: Arc, logger: Arc, + safe_mode: bool, ) -> Result { log_info!(logger, "initializing a new federation client: {uuid}"); @@ -282,6 +291,10 @@ impl FederationClient { client_builder.with_primary_module(1); + if safe_mode { + client_builder.stopped(); + } + log_trace!(logger, "Building fedimint client db"); let secret = create_federation_secret(xprivkey, network)?; @@ -349,7 +362,7 @@ impl FederationClient { let mut gateway_lock = gateway_clone.write().await; let lightning_module = client_clone.get_first_module::(); - match lightning_module.update_gateway_cache(true).await { + match lightning_module.update_gateway_cache().await { Ok(_) => { log_trace!(logger_clone, "Updated lightning gateway cache"); } @@ -482,6 +495,101 @@ impl FederationClient { ); } + /// Starts a resync of the federation + pub async fn start_resync( + federation_code: InviteCode, + xprivkey: ExtendedPrivKey, + storage: S, + network: Network, + logger: Arc, + ) -> Result<(), MutinyError> { + let federation_id = federation_code.federation_id(); + + let storage_key = format!("resync_state/{federation_id}"); + storage.set_data(storage_key.clone(), ResyncProgress::default(), None)?; + + log_trace!(logger, "Building fedimint client db"); + let fedimint_storage = + FedimintStorage::new(storage.clone(), federation_id.to_string(), logger.clone()) + .await?; + let db = fedimint_storage.clone().into(); + + let mut client_builder = fedimint_client::Client::builder(db); + client_builder.with_module(WalletClientInit(None)); + client_builder.with_module(MintClientInit); + client_builder.with_module(LightningClientInit); + + client_builder.with_primary_module(1); + + log_trace!(logger, "Building fedimint client db"); + let secret = create_federation_secret(xprivkey, network)?; + + // need to use a fresh database for resync + fedimint_storage.delete_store().await?; + + let config = ClientConfig::download_from_invite_code(&federation_code) + .await + .map_err(|e| { + log_error!(logger, "Could not download federation info: {e}"); + e + })?; + + let fedimint_client = client_builder + .recover( + get_default_client_secret(&secret, &federation_id), + config, + None, + ) + .await + .map_err(|e| { + log_error!(logger, "Could not open federation client: {e}"); + MutinyError::FederationConnectionFailed + })?; + let fedimint_client = Arc::new(fedimint_client); + + log_debug!(logger, "Built fedimint resync client"); + + spawn(async move { + let mut stream = fedimint_client.subscribe_to_recovery_progress(); + + while let Some((id, progress)) = stream.next().await { + // only can rescan mint client, don't care about sync progress of others + if id != LEGACY_HARDCODED_INSTANCE_ID_MINT || progress.is_none() { + continue; + } + + log_debug!(logger, "Got recovery progress: {progress:?}"); + + // save progress state to storage so frontend can show progress + if let Err(e) = storage.set_data( + storage_key.clone(), + ResyncProgress { + total: progress.total, + complete: progress.complete, + done: progress.is_done(), + }, + None, + ) { + log_error!(logger, "Error saving resync progress: {e}"); + } + } + + log_debug!(logger, "No more progress, waiting for recoveries"); + + // wait for all recoveries to complete just to be sure + if let Err(e) = fedimint_client.wait_for_all_recoveries().await { + log_error!(logger, "Error waiting for recoveries: {e}"); + } + + // can now delete the progress state + if let Err(e) = storage.delete(&[storage_key]) { + log_error!(logger, "Error deleting resync progress state: {e}"); + } + }); + + Ok(()) + } + pub(crate) async fn gateway_fee(&self) -> Result { let gateway = self.gateway.read().await; Ok(gateway.as_ref().map(|x| x.fees.into()).unwrap_or_default()) diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 9c9bcf943..288f8cdfd 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -43,7 +43,7 @@ pub mod vss; #[cfg(test)] mod test_utils; -use crate::federation::get_federation_identity; +use crate::federation::{get_federation_identity, ResyncProgress}; pub use crate::gossip::{GOSSIP_SYNC_TIME_KEY, NETWORK_GRAPH_KEY, PROB_SCORER_KEY}; pub use crate::keymanager::generate_seed; pub use crate::ldkstorage::{CHANNEL_CLOSURE_PREFIX, CHANNEL_MANAGER_KEY, MONITORS_PREFIX_KEY}; @@ -1004,6 +1004,7 @@ impl MutinyWalletBuilder { esplora.clone(), stop.clone(), &logger, + self.safe_mode, ) .await?; log_debug!( @@ -2982,6 +2983,7 @@ impl MutinyWallet { self.esplora.clone(), federation_code, self.stop.clone(), + self.safe_mode, ) .await; log_trace!(self.logger, "finished calling new_federation"); @@ -3111,6 +3113,43 @@ impl MutinyWallet { Ok(FederationBalances { balances }) } + pub async fn resync_federation(&self, federation_id: FederationId) -> Result<(), MutinyError> { + if !self.safe_mode { + // cannot safely run unless in safe mode + return Err(MutinyError::AlreadyRunning); + } + + let invite_code = self + .federation_storage + .read() + .await + .federations + .values() + .find(|f| f.federation_code.federation_id() == federation_id) + .ok_or(MutinyError::NotFound)? + .federation_code + .clone(); + + FederationClient::start_resync( + invite_code, + self.xprivkey, + self.storage.clone(), + self.network, + self.logger.clone(), + ) + .await?; + + Ok(()) + } + + pub fn get_federation_resync_progress( + &self, + federation_id: FederationId, + ) -> Result, MutinyError> { + let storage_key = format!("resync_state/{federation_id}"); + self.storage.get_data(storage_key) + } + /// Starts a background process that will check pending fedimint operations pub(crate) async fn start_fedimint_background_checker(&self) { log_trace!(self.logger, "calling start_fedimint_background_checker"); @@ -3734,6 +3773,7 @@ async fn create_federations( esplora: Arc, stop: Arc, logger: &Arc, + safe_mode: bool, ) -> Result>>>>, MutinyError> { let mut federation_map = HashMap::with_capacity(federation_storage.federations.len()); for (uuid, federation_index) in federation_storage.federations { @@ -3746,6 +3786,7 @@ async fn create_federations( c.network, stop.clone(), logger.clone(), + safe_mode, ) .await?; @@ -3770,6 +3811,7 @@ pub(crate) async fn create_new_federation( esplora: Arc, federation_code: InviteCode, stop: Arc, + safe_mode: bool, ) -> Result { // Begin with a mutex lock so that nothing else can // save or alter the federation list while it is about to @@ -3801,6 +3843,7 @@ pub(crate) async fn create_new_federation( network, stop.clone(), logger.clone(), + safe_mode, ) .await?; diff --git a/mutiny-wasm/Cargo.toml b/mutiny-wasm/Cargo.toml index c6886e180..2a76be0df 100644 --- a/mutiny-wasm/Cargo.toml +++ b/mutiny-wasm/Cargo.toml @@ -43,7 +43,7 @@ urlencoding = "2.1.2" once_cell = "1.18.0" hex-conservative = "0.1.1" payjoin = { version = "0.13.0", features = ["send", "base64"] } -fedimint-core = "0.3.0" +fedimint-core = "0.3.2" moksha-core = "0.2.1" bitcoin-waila = "0.5.0" diff --git a/mutiny-wasm/src/indexed_db.rs b/mutiny-wasm/src/indexed_db.rs index 793d5cf37..278ed6d91 100644 --- a/mutiny-wasm/src/indexed_db.rs +++ b/mutiny-wasm/src/indexed_db.rs @@ -4,7 +4,7 @@ use bip39::Mnemonic; use futures::lock::Mutex; use gloo_utils::format::JsValueSerdeExt; use lightning::util::logger::Logger; -use lightning::{log_debug, log_error, log_trace}; +use lightning::{log_debug, log_error, log_info, log_trace}; use log::error; use mutiny_core::blindauth::TokenStorage; use mutiny_core::logging::LOGGING_KEY; @@ -346,11 +346,12 @@ impl IndexedDbStorage { match vss { None => { + log_info!(logger, "No VSS configured"); let final_map = map.memory.read().unwrap(); Ok(final_map.clone()) } Some(vss) => { - log_trace!(logger, "Reading from vss"); + log_info!(logger, "Reading from vss"); let start = instant::Instant::now(); let keys = vss.list_key_versions(None).await?; let mut futs = Vec::with_capacity(keys.len()); diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index 8d22c263a..902d20f26 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -2103,6 +2103,23 @@ impl MutinyWallet { Ok(()) } + pub async fn resync_federation(&self, federation_id: String) -> Result<(), MutinyJsError> { + let federation_id = FederationId::from_str(&federation_id) + .map_err(|_| MutinyJsError::InvalidArgumentsError)?; + self.inner.resync_federation(federation_id).await?; + Ok(()) + } + + pub fn get_federation_resync_progress( + &self, + federation_id: String, + ) -> Result { + let federation_id = FederationId::from_str(&federation_id) + .map_err(|_| MutinyJsError::InvalidArgumentsError)?; + let res = self.inner.get_federation_resync_progress(federation_id)?; + Ok(JsValue::from_serde(&res)?) + } + /// Restore's the mnemonic after deleting the previous state. /// /// Backup the state beforehand. Does not restore lightning data.