Skip to content

Commit

Permalink
Merge branch 'develop' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum authored Nov 15, 2024
2 parents 61d0376 + 60ea7ca commit 6e155d3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/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"
Expand All @@ -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 }
Expand Down
9 changes: 7 additions & 2 deletions src/client/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -436,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]]
);
}

Expand Down
11 changes: 6 additions & 5 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct AppClient<T, U, Transport, Symbol, Wallet> {
_pd: PhantomData<Symbol>,
transport: Transport,
wallet: Wallet,
sub: fn(T) -> U,
sub: fn(T) -> Result<U>,
}

impl<T, U, Transport, Symbol, Wallet> Client<U> for AppClient<T, U, Transport, Symbol, Wallet>
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<T, U, Transport, Symbol, Wallet> AppClient<T, U, Transport, Symbol, Wallet>
_pd: PhantomData,
transport: client,
wallet,
sub: Into::into,
sub: |x| Ok(Into::into(x)),
}
}

Expand All @@ -102,7 +102,7 @@ impl<T, U, Transport, Symbol, Wallet> AppClient<T, U, Transport, Symbol, Wallet>

/// Create a subclient of this one..
#[allow(clippy::should_implement_trait)]
pub fn sub<U2>(self, sub: fn(T) -> U2) -> AppClient<T, U2, Transport, Symbol, Wallet> {
pub fn sub<U2>(self, sub: fn(T) -> Result<U2>) -> AppClient<T, U2, Transport, Symbol, Wallet> {
AppClient {
_pd: PhantomData,
transport: self.transport,
Expand Down Expand Up @@ -194,7 +194,8 @@ where
.inner
.inner
.inner;
op((self.sub)(inner))
let substate = (self.sub)(inner)?;
op(substate)
})
.await?;
Ok(res)
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 27 additions & 9 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,11 @@ where
Eq,
Describe,
Serialize,
Deserialize,
)]
#[serde(transparent)]
pub struct LengthString<P>
where
P: Encode + Decode + TryInto<usize> + Terminated + Clone + 'static,
P: Encode + Decode + TryInto<usize> + TryFrom<usize> + Terminated + Clone + 'static,
{
#[serde(skip)]
len: P,
Expand All @@ -214,14 +213,31 @@ where
inner: String,
}

impl<'de, P> Deserialize<'de> for LengthString<P>
where
P: Encode + Decode + TryInto<usize> + TryFrom<usize> + Terminated + Clone + 'static,
{
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
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<P> Migrate for LengthString<P> where
P: Encode + Decode + TryInto<usize> + Terminated + Clone + 'static
P: Encode + Decode + TryInto<usize> + TryFrom<usize> + Terminated + Clone + 'static
{
}

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

impl<P> Decode for LengthString<P>
where
P: Encode + Decode + Terminated + TryInto<usize> + Clone,
P: Encode + Decode + Terminated + TryInto<usize> + TryFrom<usize> + Clone,
{
fn decode<R: std::io::Read>(mut input: R) -> Result<Self> {
let len = P::decode(&mut input)?;
Expand All @@ -252,7 +268,7 @@ where

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

impl<P> Terminated for LengthString<P> where P: Encode + Decode + TryInto<usize> + Terminated + Clone
{}
impl<P> Terminated for LengthString<P> where
P: Encode + Decode + TryInto<usize> + TryFrom<usize> + Terminated + Clone
{
}

impl<P> State for LengthString<P>
where
P: Encode + Decode + TryInto<usize> + Terminated + Clone + 'static,
P: Encode + Decode + TryInto<usize> + TryFrom<usize> + Terminated + Clone + 'static,
{
fn attach(&mut self, _store: Store) -> crate::Result<()> {
Ok(())
Expand Down
7 changes: 7 additions & 0 deletions src/merk/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ impl MerkStore {
}
}

pub fn initialized<P: AsRef<Path>>(home: P) -> bool {
let home = home.as_ref();
Merk::open_and_get_aux(home.join("db"), b"height")
.unwrap()
.is_some()
}

fn load_snapshots<P: AsRef<Path>>(path: P) -> snapshot::Snapshots {
snapshot::Snapshots::load(path.as_ref())
.expect("Failed to load snapshots")
Expand Down
6 changes: 3 additions & 3 deletions src/store/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ impl<S: Read> Read for Store<S> {
impl<S: Write> Write for Store<S> {
#[inline]
fn put(&mut self, key: Vec<u8>, value: Vec<u8>) -> 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() >= 256 {
return Err(Error::Store("Store keys must be < 256 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());
Expand Down

0 comments on commit 6e155d3

Please sign in to comment.