From 9765ad067ad9a6835070949d0af7d2b23e997ebd Mon Sep 17 00:00:00 2001 From: James Wilson Date: Mon, 15 Apr 2024 11:42:08 +0100 Subject: [PATCH] Remove dupe storage item if we get one back, to be compatible with Smoldot + legacy RPCs (#1534) * Remove dupe storage item if we get one back, to be compatibel with Smoldot + legacy RPCs * remove commented-out code --- subxt/src/backend/legacy/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/subxt/src/backend/legacy/mod.rs b/subxt/src/backend/legacy/mod.rs index 6c6520e0db..6c2a5a2563 100644 --- a/subxt/src/backend/legacy/mod.rs +++ b/subxt/src/backend/legacy/mod.rs @@ -405,7 +405,17 @@ impl Stream for StorageFetchDescendantKeysStream { }; match keys { - Ok(keys) => { + Ok(mut keys) => { + if this.pagination_start_key.is_some() + && keys.first() == this.pagination_start_key.as_ref() + { + // Currently, Smoldot returns the "start key" as the first key in the input + // (see https://github.com/smol-dot/smoldot/issues/1692), whereas Substrate doesn't. + // We don't expect the start key to be returned either (since it was the last key of prev + // iteration), so remove it if we see it. This `remove()` method isn't very efficient but + // this will be a non issue with the RPC V2 APIs or if Smoldot aligns with Substrate anyway. + keys.remove(0); + } if keys.is_empty() { // No keys left; we're done! this.done = true; @@ -428,7 +438,7 @@ impl Stream for StorageFetchDescendantKeysStream { let key = this.key.clone(); let at = this.at; let storage_page_size = this.storage_page_size; - let pagination_start_key = this.pagination_start_key.take(); + let pagination_start_key = this.pagination_start_key.clone(); let keys_fut = async move { methods .state_get_keys_paged(