From 35988d76b58008e37794064c41f3d0ba102ca0c8 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Fri, 5 Apr 2024 15:41:07 -0500 Subject: [PATCH 1/9] Change subclient accessor function signature to return Result so that complex state descendants can be returned --- src/client/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index b0e45dd6..b6d8b92b 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -46,7 +46,7 @@ pub struct AppClient { _pd: PhantomData, transport: Transport, wallet: Wallet, - sub: fn(T) -> U, + sub: fn(T) -> Result, } impl Client for AppClient @@ -86,7 +86,7 @@ impl AppClient _pd: PhantomData, transport: client, wallet, - sub: Into::into, + sub: |x| Ok(Into::into(x)), } } @@ -102,7 +102,7 @@ impl AppClient /// Create a subclient of this one.. #[allow(clippy::should_implement_trait)] - pub fn sub(self, sub: fn(T) -> U2) -> AppClient { + pub fn sub(self, sub: fn(T) -> Result) -> AppClient { AppClient { _pd: PhantomData, transport: self.transport, @@ -194,7 +194,8 @@ where .inner .inner .inner; - op((self.sub)(inner)) + let substate = (self.sub)(inner)?; + op(substate) }) .await?; Ok(res) @@ -435,7 +436,7 @@ mod tests { DerivedKey::new(b"alice").unwrap(), ); - let bar_client = client.sub(|app| app.bar); + let bar_client = client.sub(|app| Ok(app.bar)); let bar_b = bar_client.query(|bar| Ok(bar.b)).await?; assert_eq!(bar_b, 8); From b7259fdbcfc4ed44a61fd304c6f6a63cd8fd4704 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 15 Oct 2024 16:38:18 -0500 Subject: [PATCH 2/9] Temporarily replace client tracing for GetNextUnknown with fallback to FetchNext --- src/client/exec.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client/exec.rs b/src/client/exec.rs index 3cea1aff..9e2360b7 100644 --- a/src/client/exec.rs +++ b/src/client/exec.rs @@ -143,7 +143,11 @@ where (key.clone(), StepResult::FetchKey(key)) } Err(Error::StoreErr(store::Error::GetNextUnknown(key))) => { - (key.clone(), StepResult::FetchNext(key)) + // (key.clone(), StepResult::FetchNext(key)) + // TODO: optimistically attempt to trace and only use fetchnext as fallback. we + // only do this because unwrapping a collections::Map::Iter entry + // does not push a trace yet + return Ok(StepResult::FetchNext(key)); } Err(Error::StoreErr(store::Error::GetPrevUnknown(maybe_key))) => { if let Some(key) = maybe_key { From 38ed559d7a0de631da27e7e4053cfe2432f6368a Mon Sep 17 00:00:00 2001 From: Charlie Little Date: Mon, 21 Oct 2024 20:07:34 -0500 Subject: [PATCH 3/9] Add support for longer store keys --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/store/store.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2dddd39..bd1269b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2250,7 +2250,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "merk" version = "2.0.0" -source = "git+https://github.com/nomic-io/merk?rev=cc496300bff8a9223e5589cdc2f2e0db3ae14208#cc496300bff8a9223e5589cdc2f2e0db3ae14208" +source = "git+https://github.com/nomic-io/merk?rev=d6f0490993bcf88f786c5271091aa9a84ff2fe69#d6f0490993bcf88f786c5271091aa9a84ff2fe69" dependencies = [ "colored", "ed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 56f3c1b9..55836221 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ tendermint-rpc = { version = "0.38.0", features = [ ], optional = true } tendermint = { version = "0.38.0", optional = true } tendermint-proto = { version = "0.38.0" } -merk = { git = "https://github.com/nomic-io/merk", rev = "cc496300bff8a9223e5589cdc2f2e0db3ae14208", optional = true, default-features = false } +merk = { git = "https://github.com/nomic-io/merk", rev = "d6f0490993bcf88f786c5271091aa9a84ff2fe69", optional = true, default-features = false } orga-macros = { path = "macros", version = "0.3.1" } log = "0.4.17" hex-literal = "0.4.1" diff --git a/src/store/store.rs b/src/store/store.rs index e9b63d99..919cde45 100644 --- a/src/store/store.rs +++ b/src/store/store.rs @@ -244,8 +244,8 @@ impl Write for Store { // assertion can be removed if the merk key length limit is removed, or // if we instead check this statically using known encoding lengths via // ed. - if key.len() + self.prefix.len() >= 256 { - return Err(Error::Store("Store keys must be < 256 bytes".into())); + if key.len() + self.prefix.len() >= 65535 { + return Err(Error::Store("Store keys must be < 65535 bytes".into())); } let prefixed = concat(self.prefix.as_slice(), key.as_slice()); From e09a8170d5fdf07bbce4b14f3110f6ec53e5c932 Mon Sep 17 00:00:00 2001 From: Judd Date: Fri, 1 Nov 2024 16:53:05 -0500 Subject: [PATCH 4/9] Update deps --- Cargo.lock | 10 +++++----- Cargo.toml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd1269b3..15d99a5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -751,9 +751,9 @@ dependencies = [ [[package]] name = "ed" version = "0.3.0" -source = "git+https://github.com/nomic-io/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc#a657be856792039ff60c2f67e7920e38cd3acffc" +source = "git+https://github.com/turbofish-org/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc#a657be856792039ff60c2f67e7920e38cd3acffc" dependencies = [ - "ed-derive 0.3.0 (git+https://github.com/nomic-io/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc)", + "ed-derive 0.3.0 (git+https://github.com/turbofish-org/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc)", "thiserror", ] @@ -771,7 +771,7 @@ dependencies = [ [[package]] name = "ed-derive" version = "0.3.0" -source = "git+https://github.com/nomic-io/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc#a657be856792039ff60c2f67e7920e38cd3acffc" +source = "git+https://github.com/turbofish-org/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc#a657be856792039ff60c2f67e7920e38cd3acffc" dependencies = [ "proc-macro2", "quote", @@ -2250,7 +2250,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "merk" version = "2.0.0" -source = "git+https://github.com/nomic-io/merk?rev=d6f0490993bcf88f786c5271091aa9a84ff2fe69#d6f0490993bcf88f786c5271091aa9a84ff2fe69" +source = "git+https://github.com/turbofish-org/merk?rev=058839b813bb373e724b7c9826030e6df1aec2cb#058839b813bb373e724b7c9826030e6df1aec2cb" dependencies = [ "colored", "ed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2426,7 +2426,7 @@ dependencies = [ "borsh", "cosmrs", "derive_more", - "ed 0.3.0 (git+https://github.com/nomic-io/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc)", + "ed 0.3.0 (git+https://github.com/turbofish-org/ed?rev=a657be856792039ff60c2f67e7920e38cd3acffc)", "ed25519-dalek", "educe", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 55836221..856be5a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ tendermint-rpc = { version = "0.38.0", features = [ ], optional = true } tendermint = { version = "0.38.0", optional = true } tendermint-proto = { version = "0.38.0" } -merk = { git = "https://github.com/nomic-io/merk", rev = "d6f0490993bcf88f786c5271091aa9a84ff2fe69", optional = true, default-features = false } +merk = { git = "https://github.com/turbofish-org/merk", rev = "058839b813bb373e724b7c9826030e6df1aec2cb", optional = true, default-features = false } orga-macros = { path = "macros", version = "0.3.1" } log = "0.4.17" hex-literal = "0.4.1" @@ -22,7 +22,7 @@ is_executable = { version = "1.0.1", optional = true } reqwest = { version = "0.11.16", features = ["blocking"], optional = true } flate2 = "1.0.22" tar = "0.4.38" -ed = { git = "https://github.com/nomic-io/ed", rev = "a657be856792039ff60c2f67e7920e38cd3acffc" } +ed = { git = "https://github.com/turbofish-org/ed", rev = "a657be856792039ff60c2f67e7920e38cd3acffc" } toml_edit = "0.22.9" prost = { version = "0.13.1" } home = { version = "0.5.4", optional = true } From 13e52b67b415691383baddf4f7b9f321103ab2ae Mon Sep 17 00:00:00 2001 From: Judd Date: Fri, 1 Nov 2024 17:23:08 -0500 Subject: [PATCH 5/9] Fix key length limit --- src/store/store.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/store/store.rs b/src/store/store.rs index 919cde45..5848611f 100644 --- a/src/store/store.rs +++ b/src/store/store.rs @@ -238,14 +238,14 @@ impl Read for Store { impl Write for Store { #[inline] fn put(&mut self, key: Vec, value: Vec) -> Result<()> { - // merk has a hard limit of 256 bytes for keys, but it does not create + // merk has a hard limit of 65535 bytes for keys, but it does not create // an error until comitting. we assert the key length here so that // writes will fail early rather than making the entire block fail. this // assertion can be removed if the merk key length limit is removed, or // if we instead check this statically using known encoding lengths via // ed. - if key.len() + self.prefix.len() >= 65535 { - return Err(Error::Store("Store keys must be < 65535 bytes".into())); + if key.len() + self.prefix.len() >= 65536 { + return Err(Error::Store("Store keys must be < 65536 bytes".into())); } let prefixed = concat(self.prefix.as_slice(), key.as_slice()); From 296a691cb3796f3fb0f85d2e56b65dd0d9a05291 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 4 Nov 2024 18:25:48 -0600 Subject: [PATCH 6/9] Properly set length field when Serde-deserializing LengthString --- src/encoding.rs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/encoding.rs b/src/encoding.rs index 71ba5905..a61af031 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -198,12 +198,11 @@ where Eq, Describe, Serialize, - Deserialize, )] #[serde(transparent)] pub struct LengthString

where - P: Encode + Decode + TryInto + Terminated + Clone + 'static, + P: Encode + Decode + TryInto + TryFrom + Terminated + Clone + 'static, { #[serde(skip)] len: P, @@ -214,14 +213,31 @@ where inner: String, } +impl<'de, P> Deserialize<'de> for LengthString

+where + P: Encode + Decode + TryInto + TryFrom + Terminated + Clone + 'static, +{ + fn deserialize(deserializer: D) -> std::result::Result + where + D: serde::Deserializer<'de>, + { + let inner = String::deserialize(deserializer)?; + let len = inner + .len() + .try_into() + .map_err(|_| serde::de::Error::custom("overflow"))?; + Ok(LengthString { len, inner }) + } +} + impl

Migrate for LengthString

where - P: Encode + Decode + TryInto + Terminated + Clone + 'static + P: Encode + Decode + TryInto + TryFrom + Terminated + Clone + 'static { } impl

LengthString

where - P: Encode + Decode + TryInto + Terminated + Clone, + P: Encode + Decode + TryInto + TryFrom + Terminated + Clone, { pub fn new(len: P, inner: String) -> Self { LengthString { len, inner } @@ -230,7 +246,7 @@ where impl

Decode for LengthString

where - P: Encode + Decode + Terminated + TryInto + Clone, + P: Encode + Decode + Terminated + TryInto + TryFrom + Clone, { fn decode(mut input: R) -> Result { let len = P::decode(&mut input)?; @@ -252,7 +268,7 @@ where impl

Encode for LengthString

where - P: Encode + Decode + TryInto + Terminated + Clone, + P: Encode + Decode + TryInto + TryFrom + Terminated + Clone, { fn encode_into(&self, mut out: &mut W) -> Result<()> { self.len.encode_into(&mut out)?; @@ -273,12 +289,14 @@ where } } -impl

Terminated for LengthString

where P: Encode + Decode + TryInto + Terminated + Clone -{} +impl

Terminated for LengthString

where + P: Encode + Decode + TryInto + TryFrom + Terminated + Clone +{ +} impl

State for LengthString

where - P: Encode + Decode + TryInto + Terminated + Clone + 'static, + P: Encode + Decode + TryInto + TryFrom + Terminated + Clone + 'static, { fn attach(&mut self, _store: Store) -> crate::Result<()> { Ok(()) From 5f95826046dd82634439b88d5b48e6c391d1952f Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 14 Nov 2024 17:33:58 -0600 Subject: [PATCH 7/9] Update merk dependency --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15d99a5a..f126871c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2250,7 +2250,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "merk" version = "2.0.0" -source = "git+https://github.com/turbofish-org/merk?rev=058839b813bb373e724b7c9826030e6df1aec2cb#058839b813bb373e724b7c9826030e6df1aec2cb" +source = "git+https://github.com/turbofish-org/merk?rev=84261c2c0fdcc09792cede6b21ba72b6d008fea6#84261c2c0fdcc09792cede6b21ba72b6d008fea6" dependencies = [ "colored", "ed 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 856be5a7..fa9442d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ tendermint-rpc = { version = "0.38.0", features = [ ], optional = true } tendermint = { version = "0.38.0", optional = true } tendermint-proto = { version = "0.38.0" } -merk = { git = "https://github.com/turbofish-org/merk", rev = "058839b813bb373e724b7c9826030e6df1aec2cb", optional = true, default-features = false } +merk = { git = "https://github.com/turbofish-org/merk", rev = "84261c2c0fdcc09792cede6b21ba72b6d008fea6", optional = true, default-features = false } orga-macros = { path = "macros", version = "0.3.1" } log = "0.4.17" hex-literal = "0.4.1" From dc6f1e7ba4083e2722d82f770ec5e85b78eeb774 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 14 Nov 2024 17:34:19 -0600 Subject: [PATCH 8/9] Add method to check if a MerkStore has been initialized without fully opening --- src/merk/store.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/merk/store.rs b/src/merk/store.rs index 35cc4cfc..753a5f08 100644 --- a/src/merk/store.rs +++ b/src/merk/store.rs @@ -71,6 +71,13 @@ impl MerkStore { } } + pub fn initialized>(home: P) -> bool { + let home = home.as_ref(); + Merk::open_and_get_aux(home.join("db"), b"height") + .unwrap() + .is_some() + } + fn load_snapshots>(path: P) -> snapshot::Snapshots { snapshot::Snapshots::load(path.as_ref()) .expect("Failed to load snapshots") From a031be5c31de4ae54f335d6a9048afa158230c0b Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 14 Nov 2024 18:25:57 -0600 Subject: [PATCH 9/9] Update test --- src/client/exec.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/exec.rs b/src/client/exec.rs index 9e2360b7..ea5b6101 100644 --- a/src/client/exec.rs +++ b/src/client/exec.rs @@ -440,7 +440,8 @@ mod tests { assert_eq!(res, 3); assert_eq!( client.queries.into_inner().unwrap(), - vec![vec![2], vec![0, 128]] + // TODO: 2nd query shouldn't be necessary + vec![vec![2], vec![3, 0, 1], vec![0, 128]] ); }