Skip to content

Commit

Permalink
wip: simple outer circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed Jan 30, 2024
1 parent dc7b740 commit 079e2eb
Show file tree
Hide file tree
Showing 38 changed files with 2,982 additions and 1,728 deletions.
434 changes: 268 additions & 166 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ resolver = "2"
anyhow = "1.0"
async-trait = "0.1"
config = "0.13"
derive_more = "0.99"
either = { version = "1.9", features = [ "serde" ] }
itertools = "0.12"
log = "0.4"
pretty_assertions = "1.4"
pretty_env_logger = "0.5"
sled = "0.34" # TODO: maybe heavy
thiserror = "1.0"
Expand All @@ -40,5 +42,9 @@ near-jsonrpc-primitives = "0.19"
near-primitives = "0.19"
near-primitives-core = "0.19"

near-light-client-protocol = { path = "crates/protocol" }
near-light-client-rpc = { path = "crates/rpc" }
near-light-clientx = { path = "circuits/plonky2x" }
test-utils = { path = "crates/test-utils" }
# [patch."https://github.com/succinctlabs/succinctx.git"]
# plonky2x = { path = "./vendor/succinctx/plonky2x/core" }
1 change: 1 addition & 0 deletions bin/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pretty_env_logger.workspace = true
protobuf.workspace = true
protocol = { path = "../../crates/protocol", package = "near-light-client-protocol" }
reqwest.workspace = true
rpc = { path = "../../crates/rpc", package = "near-light-client-rpc" }
serde.workspace = true
serde_json.workspace = true
sled.workspace = true
Expand Down
18 changes: 13 additions & 5 deletions bin/client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use coerce::actor::{context::ActorContext, message::Handler, Actor};
use message::{Archive, GetProof, Head, Shutdown, VerifyProof};
use near_primitives::views::validator_stake_view::ValidatorStakeView;
use protocol::{Proof, Protocol};
use rpc::LightClientRpc;
use std::{str::FromStr, sync::Arc};
use tokio::time;

pub mod message;
pub mod rpc;
mod store;

pub struct LightClient {
Expand Down Expand Up @@ -132,7 +132,7 @@ impl LightClient {
let starting_head = self
.client
.fetch_latest_header(&sync_from)
.await
.await?
.ok_or_else(|| anyhow::anyhow!("We need a starting header"))?;

log::info!("starting head: {:?}", starting_head.inner_lite.height);
Expand Down Expand Up @@ -202,14 +202,14 @@ impl LightClient {
client: rpc::NearRpcClient,
) -> Result<bool> {
let head = store.head().await?;
log::debug!("Current head: {:#?}", head.inner_lite);
log::debug!("Current head: {:#?}", head);

let next_header = client
.fetch_latest_header(
&CryptoHash::from_str(&format!("{}", head.hash()))
.map_err(|e| anyhow!("Failed to parse hash: {:?}", e))?,
)
.await
.await?
.ok_or_else(|| anyhow!("Failed to fetch latest header"))?;
log::trace!("Got new header: {:#?}", next_header.inner_lite);

Expand Down Expand Up @@ -252,7 +252,7 @@ impl LightClient {
for req in p.0 {
let proof = self
.client
.fetch_light_client_proof(req, *last_verified_hash);
.fetch_light_client_proof(req.0, *last_verified_hash);
futs.push(proof);
}
let unpin_futs: Vec<_> = futs.into_iter().map(Box::pin).collect();
Expand Down Expand Up @@ -306,3 +306,11 @@ impl LightClient {
Ok((p, errors))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn t() {}
}
2 changes: 1 addition & 1 deletion bin/client/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::client::rpc::Network;
use crate::prelude::*;
use config::{Config as ConfigTrait, ConfigError, Environment, File};
use rpc::Network;
use std::{env, path::PathBuf};

#[derive(Debug, Deserialize, Clone)]
Expand Down
15 changes: 15 additions & 0 deletions bin/operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
edition.workspace = true
license.workspace = true
name = "near-light-client-succint-operator"
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cfg-if = "*"
near-light-clientx.workspace = true

[features]
default = [ "sync" ]
sync = [ ]
11 changes: 11 additions & 0 deletions bin/operator/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use near_light_clientx::{plonky2x::backend::function::Plonky2xFunction, SyncCircuit};

fn main() {
cfg_if::cfg_if! {
if #[cfg(feature = "sync")] {
SyncCircuit::<1>::entrypoint();
} else {
panic!("No circuit feature enabled");
}
}
}
23 changes: 16 additions & 7 deletions circuits/plonky2x/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
[package]
edition = "2021"
name = "near-light-client-circuits"
name = "near-light-clientx"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
borsh.workspace = true
ethers = "2.0.11"
pretty_assertions = "1.4.0"
serde.workspace = true

async-trait.workspace = true
borsh.workspace = true
ethers = "2.0.11"
log.workspace = true
pretty_assertions = "1.4.0"
serde.workspace = true
# Circuits
plonky2 = { git = "https://github.com/mir-protocol/plonky2.git" }
plonky2x = { git = "https://github.com/succinctlabs/succinctx.git" }

near-light-client-protocol = { path = "../../crates/protocol" }
near-light-client-protocol.workspace = true
near-light-client-rpc.workspace = true

[dev-dependencies]
borsh.workspace = true
hex.workspace = true
near-primitives.workspace = true
pretty_env_logger.workspace = true
serde_json.workspace = true
serial_test = "3"
test-utils.workspace = true
tokio.workspace = true

[features]
beefy-tests = [ ]
default = [ "beefy-tests" ]
Loading

0 comments on commit 079e2eb

Please sign in to comment.