Skip to content

Commit

Permalink
feat(advance-runner): get on-chain machine hash
Browse files Browse the repository at this point in the history
  • Loading branch information
torives committed Aug 23, 2023
1 parent ae4f90a commit 9931c76
Show file tree
Hide file tree
Showing 12 changed files with 3,726 additions and 1 deletion.
13 changes: 13 additions & 0 deletions offchain/Cargo.lock

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

1 change: 1 addition & 0 deletions offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"http-server",
"indexer",
"inspect-server",
"machine-hash",
"redacted",
"rollups-events",
"rollups-http-client",
Expand Down
1 change: 1 addition & 0 deletions offchain/advance-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rollups-events = { path = "../rollups-events" }
async-trait.workspace = true
backoff = { workspace = true, features = ["tokio"] }
clap = { workspace = true, features = ["derive", "env"] }
contracts = { path = "../contracts" }
hex.workspace = true
sha3 = { workspace = true, features = ["std"] }
snafu.workspace = true
Expand Down
38 changes: 38 additions & 0 deletions offchain/advance-runner/src/checker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::snapshot::SnapshotManager;
use rollups_events::Address;
use snafu::Snafu;

#[derive(Debug, Snafu)]
#[allow(clippy::enum_variant_names)]
pub enum TemplateHashError {
#[snafu(display("off-chain hash does not match on-chain hash"))]
MismatchError,
}

pub struct TemplateHashChecker<'a, Snap> {
provider_http_endpoint: String,
dapp_address: Address,
snapshot_manager: &'a Snap,
}

impl<'a, Snap: SnapshotManager + std::fmt::Debug + 'static>
TemplateHashChecker<'a, Snap>
{
pub fn new(
provider_http_endpoint: String,
dapp_address: Address,
snapshot_manager: &'a Snap,
) -> Self {
Self {
provider_http_endpoint,
dapp_address,
snapshot_manager,
}
}

pub async fn validate_template_hash(
&self,
) -> Result<bool, TemplateHashError> {
todo!()
}
}
7 changes: 7 additions & 0 deletions offchain/advance-runner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct AdvanceRunnerConfig {
pub snapshot_config: SnapshotConfig,
pub backoff_max_elapsed_duration: Duration,
pub healthcheck_port: u16,
pub provider_http_endpoint: String,
}

impl AdvanceRunnerConfig {
Expand All @@ -36,13 +37,15 @@ impl AdvanceRunnerConfig {
let backoff_max_elapsed_duration =
Duration::from_millis(cli_config.backoff_max_elapsed_duration);
let healthcheck_port = cli_config.healthcheck_port;
let provider_http_endpoint = cli_config.provider_http_endpoint;
Ok(Self {
server_manager_config,
broker_config,
dapp_metadata,
snapshot_config,
backoff_max_elapsed_duration,
healthcheck_port,
provider_http_endpoint,
})
}
}
Expand Down Expand Up @@ -78,4 +81,8 @@ struct CLIConfig {
default_value_t = 8080
)]
pub healthcheck_port: u16,

/// Blockchain provider http endpoint url
#[arg(long, env)]
provider_http_endpoint: String,
}
11 changes: 11 additions & 0 deletions offchain/advance-runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use crate::{checker::TemplateHashChecker, snapshot::SnapshotManager};
use backoff::ExponentialBackoffBuilder;
use broker::BrokerFacade;
use config::AdvanceRunnerConfig;
use rollups_events::Address;
use runner::Runner;
use server_manager::ServerManagerFacade;
use snafu::ResultExt;
Expand All @@ -15,6 +17,7 @@ use snapshot::{
pub use error::AdvanceRunnerError;

mod broker;
pub mod checker;
pub mod config;
mod error;
pub mod runner;
Expand Down Expand Up @@ -61,12 +64,20 @@ async fn start_advance_runner(
match config.snapshot_config {
SnapshotConfig::FileSystem(fs_manager_config) => {
let snapshot_manager = FSSnapshotManager::new(fs_manager_config);
let checker = TemplateHashChecker::new(
String::from("value"),
Address::default(),
&snapshot_manager,
);
checker.validate_template_hash().await.unwrap();
Runner::start(server_manager, broker, snapshot_manager)
.await
.context(error::RunnerFSSnapshotSnafu)
}
SnapshotConfig::Disabled => {
let snapshot_manager = SnapshotDisabled {};
// Since there's no Snapshot, there's nothing to check
// TODO: should log something in this case?
Runner::start(server_manager, broker, snapshot_manager)
.await
.context(error::RunnerSnapshotDisabledSnafu)
Expand Down
2 changes: 1 addition & 1 deletion offchain/contracts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
("InputBox", "inputs/InputBox", "input_box.rs"),
("Authority", "consensus/authority/Authority", "authority.rs"),
("History", "history/History", "history.rs"),
// ("CartesiDApp", "dapp/CartesiDApp", "cartesi_dapp.rs"),
("CartesiDApp", "dapp/CartesiDApp", "cartesi_dapp.rs"),
// (
// "CartesiDAppFactory",
// "dapp/CartesiDAppFactory",
Expand Down
1 change: 1 addition & 0 deletions offchain/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ macro_rules! contract {
contract!(input_box);
contract!(authority);
contract!(history);
contract!(cartesi_dapp);
Loading

0 comments on commit 9931c76

Please sign in to comment.