From d36bb33c646a908ac1264416f8b49d54f62a33cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Wed, 21 Aug 2024 13:23:50 +0200 Subject: [PATCH] chore(node): Update rexie and related wasm dependencies (#358) --- Cargo.lock | 167 ++++++++++++++++++----------- node-wasm/Cargo.toml | 8 +- node-wasm/src/utils.rs | 6 +- node-wasm/src/worker/channel.rs | 6 +- node/Cargo.toml | 10 +- node/src/store/indexed_db_store.rs | 89 +++++++-------- 6 files changed, 169 insertions(+), 117 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7cc2b3b..ec9ee53f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -529,7 +529,7 @@ dependencies = [ "futures-core", "futures-timer", "futures-util", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "multihash-codetable", @@ -641,7 +641,7 @@ dependencies = [ "js-sys", "multihash", "redb", - "rexie 0.6.2", + "rexie", "thiserror", "tokio", "wasm-bindgen", @@ -2386,9 +2386,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -2584,7 +2584,7 @@ dependencies = [ "libp2p-allow-block-list", "libp2p-autonat", "libp2p-connection-limits", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-dns", "libp2p-gossipsub", "libp2p-identify", @@ -2600,7 +2600,7 @@ dependencies = [ "libp2p-tcp", "libp2p-upnp", "libp2p-websocket", - "libp2p-websocket-websys", + "libp2p-websocket-websys 0.4.0", "libp2p-webtransport-websys", "libp2p-yamux", "multiaddr", @@ -2615,7 +2615,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1027ccf8d70320ed77e984f273bc8ce952f623762cb9bf2d126df73caef8041" dependencies = [ - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "void", @@ -2634,7 +2634,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-request-response", "libp2p-swarm", @@ -2654,12 +2654,40 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d003540ee8baef0d254f7b6bfd79bac3ddf774662ca0abf69186d517ef82ad8" dependencies = [ - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "void", ] +[[package]] +name = "libp2p-core" +version = "0.41.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5a8920cbd8540059a01950c1e5c96ea8d89eb50c51cd366fc18bdf540a6e48f" +dependencies = [ + "either", + "fnv", + "futures", + "futures-timer", + "libp2p-identity", + "multiaddr", + "multihash", + "multistream-select", + "once_cell", + "parking_lot", + "pin-project", + "quick-protobuf", + "rand", + "rw-stream-sink", + "smallvec", + "thiserror", + "tracing", + "unsigned-varint 0.8.0", + "void", + "web-time", +] + [[package]] name = "libp2p-core" version = "0.42.0" @@ -2698,7 +2726,7 @@ dependencies = [ "async-trait", "futures", "hickory-resolver", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "parking_lot", "smallvec", @@ -2721,7 +2749,7 @@ dependencies = [ "futures-ticker", "getrandom", "hex_fmt", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "prometheus-client", @@ -2748,7 +2776,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "lru", @@ -2793,7 +2821,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "quick-protobuf", @@ -2819,7 +2847,7 @@ dependencies = [ "futures", "hickory-proto", "if-watch", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "rand", @@ -2837,7 +2865,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a70afa7692c81ee03e89c40d1e8638d634f18baef6aeeea30fd245edfae4d3fd" dependencies = [ "futures", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-gossipsub", "libp2p-identify", "libp2p-identity", @@ -2859,7 +2887,7 @@ dependencies = [ "bytes", "curve25519-dalek", "futures", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "multiaddr", "multihash", @@ -2884,7 +2912,7 @@ dependencies = [ "either", "futures", "futures-timer", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "rand", @@ -2903,7 +2931,7 @@ dependencies = [ "futures", "futures-timer", "if-watch", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-tls", "parking_lot", @@ -2927,7 +2955,7 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm", "rand", @@ -2948,7 +2976,7 @@ dependencies = [ "futures", "futures-timer", "getrandom", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-swarm-derive", "lru", @@ -2985,7 +3013,7 @@ dependencies = [ "futures-timer", "if-watch", "libc", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "socket2", "tokio", @@ -3000,7 +3028,7 @@ checksum = "47b23dddc2b9c355f73c1e36eb0c3ae86f7dc964a3715f0731cfad352db4d847" dependencies = [ "futures", "futures-rustls", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "rcgen", "ring 0.17.8", @@ -3020,7 +3048,7 @@ dependencies = [ "futures", "futures-timer", "igd-next", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-swarm", "tokio", "tracing", @@ -3036,7 +3064,7 @@ dependencies = [ "either", "futures", "futures-rustls", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "parking_lot", "pin-project-lite", @@ -3048,6 +3076,24 @@ dependencies = [ "webpki-roots 0.25.4", ] +[[package]] +name = "libp2p-websocket-websys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f95cd8a32fcf94ad1e5c2de37c2a05a5a4188d8358b005859a0fc9e63b6953bc" +dependencies = [ + "bytes", + "futures", + "js-sys", + "libp2p-core 0.41.3", + "parking_lot", + "send_wrapper 0.6.0", + "thiserror", + "tracing", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "libp2p-websocket-websys" version = "0.4.0" @@ -3057,7 +3103,7 @@ dependencies = [ "bytes", "futures", "js-sys", - "libp2p-core", + "libp2p-core 0.42.0", "parking_lot", "send_wrapper 0.6.0", "thiserror", @@ -3074,7 +3120,7 @@ checksum = "7734b77ba70a9e669f8dbfe17d866c06aef34e35e6ec8b307c4144f0f26ec369" dependencies = [ "futures", "js-sys", - "libp2p-core", + "libp2p-core 0.42.0", "libp2p-identity", "libp2p-noise", "multiaddr", @@ -3095,7 +3141,7 @@ checksum = "788b61c80789dba9760d8c669a5bedb642c8267555c803fabd8396e4ca5c5882" dependencies = [ "either", "futures", - "libp2p-core", + "libp2p-core 0.42.0", "thiserror", "tracing", "yamux 0.12.1", @@ -3210,14 +3256,16 @@ dependencies = [ "futures", "getrandom", "gloo-timers 0.3.0", + "idb", "js-sys", "libp2p", + "libp2p-websocket-websys 0.3.3", "lumina-node", "pin-project", "prost", "rand", "redb", - "rexie 0.5.0", + "rexie", "rstest", "rustls-pemfile", "rustls-pki-types", @@ -3311,6 +3359,16 @@ dependencies = [ "unicase", ] +[[package]] +name = "minicov" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c71e683cd655513b99affab7d317deb690528255a0d5f717f1024093c12b169" +dependencies = [ + "cc", + "walkdir", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -4246,21 +4304,6 @@ dependencies = [ "quick-error", ] -[[package]] -name = "rexie" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34618a20b14cebebc63f8b1c5228116e7379765e8f1b7a9f66b5920babd8595" -dependencies = [ - "js-sys", - "num-traits", - "thiserror", - "tokio", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "rexie" version = "0.6.2" @@ -5564,19 +5607,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -5589,9 +5633,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ "cfg-if", "js-sys", @@ -5601,9 +5645,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5611,9 +5655,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -5624,18 +5668,19 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasm-bindgen-test" -version = "0.3.42" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" +checksum = "68497a05fb21143a08a7d24fc81763384a3072ee43c44e86aad1744d6adef9d9" dependencies = [ "console_error_panic_hook", "js-sys", + "minicov", "scoped-tls", "wasm-bindgen", "wasm-bindgen-futures", @@ -5644,9 +5689,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.42" +version = "0.3.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" +checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" dependencies = [ "proc-macro2", "quote", @@ -5655,9 +5700,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/node-wasm/Cargo.toml b/node-wasm/Cargo.toml index c74fc2ca..a50145d5 100644 --- a/node-wasm/Cargo.toml +++ b/node-wasm/Cargo.toml @@ -35,7 +35,7 @@ enum-as-inner = "0.6.0" futures = "0.3.30" gloo-timers = "0.3.0" instant = "0.1.13" -js-sys = "0.3.69" +js-sys = "0.3.70" serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.120" serde-wasm-bindgen = "0.6.5" @@ -46,9 +46,9 @@ tokio = { version = "1.38.0", features = ["sync"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["time"] } tracing-web = "0.1.3" -wasm-bindgen = "0.2.92" -wasm-bindgen-futures = "0.4.42" -web-sys = { version = "0.3.69", features = [ +wasm-bindgen = "0.2.93" +wasm-bindgen-futures = "0.4.43" +web-sys = { version = "0.3.70", features = [ "BroadcastChannel", "DedicatedWorkerGlobalScope", "Headers", diff --git a/node-wasm/src/utils.rs b/node-wasm/src/utils.rs index 29e27818..e3bc04f2 100644 --- a/node-wasm/src/utils.rs +++ b/node-wasm/src/utils.rs @@ -290,9 +290,9 @@ pub(crate) async fn resolve_dnsaddr_multiaddress(ma: Multiaddr) -> Result for AnyWorker { impl AnyWorker { pub(crate) fn new(kind: NodeWorkerKind, url: &str, name: &str) -> Result { - let mut opts = WorkerOptions::new(); - opts.type_(WorkerType::Module); - opts.name(name); + let opts = WorkerOptions::new(); + opts.set_type(WorkerType::Module); + opts.set_name(name); Ok(match kind { NodeWorkerKind::Shared => { diff --git a/node/Cargo.toml b/node/Cargo.toml index 55442728..db683c12 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -76,6 +76,7 @@ blockstore = { workspace = true, features = ["indexeddb"] } celestia-types = { workspace = true, features = ["wasm-bindgen"] } getrandom = { version = "0.2.15", features = ["js"] } gloo-timers = { version = "0.3.0", features = ["futures"] } +idb = "0.6.3" js-sys = "0.3.69" libp2p = { workspace = true, features = [ "noise", @@ -85,15 +86,16 @@ libp2p = { workspace = true, features = [ "yamux", ] } pin-project = "1.1.5" -rexie = "0.5.0" +rexie = "0.6.2" send_wrapper = { version = "0.6.0", features = ["futures"] } serde-wasm-bindgen = "0.6.5" -wasm-bindgen = "0.2.92" -wasm-bindgen-futures = "0.4.42" +wasm-bindgen = "0.2.93" +wasm-bindgen-futures = "0.4.43" +libp2p-websocket-websys = "0.3.3" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] function_name = "0.3.0" -wasm-bindgen-test = "0.3.42" +wasm-bindgen-test = "0.3.43" [dev-dependencies] bytes = "1.6.0" diff --git a/node/src/store/indexed_db_store.rs b/node/src/store/indexed_db_store.rs index 658c061b..fcb56c6e 100644 --- a/node/src/store/indexed_db_store.rs +++ b/node/src/store/indexed_db_store.rs @@ -176,11 +176,9 @@ impl IndexedDbStore { let hash_index = header_store.index(HASH_INDEX_NAME)?; let hash_key = to_value(&hash)?; - let header_entry = hash_index.get(&hash_key).await?; - - if header_entry.is_falsy() { + let Some(header_entry) = hash_index.get(hash_key).await? else { return Err(StoreError::NotFound); - } + }; let serialized_header = from_value::(header_entry)?.header; ExtendedHeader::decode(serialized_header.as_ref()) @@ -243,7 +241,7 @@ impl IndexedDbStore { let hash_key = KeyRange::only(&to_value(&hash)?)?; - let hash_count = hash_index.count(Some(&hash_key)).await?; + let hash_count = hash_index.count(Some(hash_key)).await?; Ok(hash_count > 0) } @@ -282,11 +280,9 @@ impl IndexedDbStore { let store = tx.store(SAMPLING_STORE_NAME)?; let height_key = to_value(&height)?; - let sampling_entry = store.get(&height_key).await?; - - if sampling_entry.is_falsy() { + let Some(sampling_entry) = store.get(height_key).await? else { return Ok(None); - } + }; Ok(Some(from_value(sampling_entry)?)) } @@ -436,7 +432,17 @@ impl From for StoreError { fn from(error: rexie::Error) -> StoreError { use rexie::Error as E; match error { - e @ E::AsyncChannelError => StoreError::ExecutorError(e.to_string()), + E::IdbError(idb_error) => idb_error.into(), + other => StoreError::FatalDatabaseError(other.to_string()), + } + } +} + +impl From for StoreError { + fn from(error: idb::Error) -> Self { + use idb::Error as E; + match error { + e @ E::OneshotChannelReceiveError => StoreError::ExecutorError(e.to_string()), other => StoreError::FatalDatabaseError(other.to_string()), } } @@ -450,12 +456,10 @@ impl From for StoreError { async fn get_ranges(store: &rexie::Store, name: &str) -> Result { let key = JsValue::from_str(name); - let raw_ranges = store.get(&key).await?; - - if raw_ranges.is_falsy() { + let Some(raw_ranges) = store.get(key).await? else { // Ranges not set yet return Ok(BlockRanges::default()); - } + }; Ok(from_value(raw_ranges)?) } @@ -487,12 +491,9 @@ async fn get_by_height(header_store: &rexie::Store, height: u64) -> Result(header_entry)?.header; ExtendedHeader::decode(serialized_header.as_ref()) @@ -568,7 +569,7 @@ async fn detect_schema_version(db: &Rexie) -> Result> { // exists, then we assume we are in version 2. let height_key = to_value(&1)?; let height_index = header_store.index(HEIGHT_INDEX_NAME)?; - if height_index.get(&height_key).await?.is_truthy() { + if height_index.get(height_key).await?.is_some() { return Ok(Some(2)); } @@ -577,13 +578,15 @@ async fn detect_schema_version(db: &Rexie) -> Result> { } async fn store_is_empty(store: &rexie::Store) -> Result { - let vals = store.get_all(None, Some(1), None, None).await?; + let vals = store.get_all_keys(None, Some(1)).await?; Ok(vals.is_empty()) } async fn get_schema_version(store: &rexie::Store) -> Result { let key = to_value(VERSION_KEY)?; - let val = store.get(&key).await?; + let Some(val) = store.get(key).await? else { + return Err(StoreError::NotFound); + }; Ok(from_value(val)?) } @@ -624,7 +627,7 @@ async fn insert_tx_op( let hash_index = header_store.index(HASH_INDEX_NAME)?; let jsvalue_hash_key = KeyRange::only(&to_value(&hash)?)?; - if hash_index.count(Some(&jsvalue_hash_key)).await.unwrap_or(0) != 0 { + if hash_index.count(Some(jsvalue_hash_key)).await.unwrap_or(0) != 0 { // TODO: Replace this with `StoredDataError` when we implement // type-safe validation on insertion. return Err(StoreInsertionError::HashExists(hash).into()); @@ -668,22 +671,21 @@ async fn update_sampling_metadata_tx_op( } let height_key = to_value(&height)?; - let previous_entry = sampling_store.get(&height_key).await?; - - let new_entry = if previous_entry.is_falsy() { - SamplingMetadata { status, cids } - } else { - let mut value: SamplingMetadata = from_value(previous_entry)?; + let new_entry = match sampling_store.get(height_key.clone()).await? { + Some(previous_entry) => { + let mut value: SamplingMetadata = from_value(previous_entry)?; - value.status = status; + value.status = status; - for cid in cids { - if !value.cids.contains(&cid) { - value.cids.push(cid); + for cid in cids { + if !value.cids.contains(&cid) { + value.cids.push(cid); + } } - } - value + value + } + None => SamplingMetadata { status, cids }, }; let metadata_jsvalue = to_value(&new_entry)?; @@ -723,12 +725,16 @@ async fn remove_last_tx_op(tx: &Transaction, _: ()) -> Result { set_ranges(&ranges_store, HEADER_RANGES_KEY, &header_ranges).await?; let jsvalue_height = to_value(&height).expect("to create jsvalue"); - let header = height_index.get(&jsvalue_height).await?; + let Some(header) = height_index.get(jsvalue_height).await? else { + return Err(StoreError::StoredDataError( + "inconsistency between headers and ranges table".into(), + )); + }; let id = js_sys::Reflect::get(&header, &to_value("id")?) .map_err(|_| StoreError::StoredDataError("could not get header's DB id".into()))?; - header_store.delete(&id).await?; + header_store.delete(id).await?; Ok(height) } @@ -783,7 +789,7 @@ mod v2 { pub(super) async fn get_head_header(store: &rexie::Store) -> Result { let store_head = store - .get_all(None, Some(1), None, Some(Direction::Prev)) + .scan(None, Some(1), None, Some(Direction::Prev)) .await? .first() .ok_or(StoreError::NotFound)? @@ -803,10 +809,7 @@ mod v3 { pub(super) async fn get_header_ranges(store: &rexie::Store) -> Result { let mut ranges = BlockRanges::default(); - for (_, raw_range) in store - .get_all(None, None, None, Some(Direction::Next)) - .await? - { + for raw_range in store.get_all(None, None).await? { let (start, end) = from_value::<(u64, u64)>(raw_range)?; ranges .insert_relaxed(start..=end) @@ -973,6 +976,8 @@ pub mod tests { .await .unwrap(); } + + rexie.close(); } #[named]