-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(advance-runner)!: validate snapshot hash
The snapshot's template hash gets compared with its counterpart in the blockchain, causing the advance-runner to stop if it does not match. BREAKING CHANGE: adds the PROVIDER_HTTP_ENDPOINT parameter, which is required to validate snapshots. Validation is enabled by default, but can be disabled by setting SNAPSHOT_VALIDATION_ENABLED to false
- Loading branch information
Showing
14 changed files
with
186 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
use contracts::cartesi_dapp::CartesiDApp; | ||
use rollups_events::{Address, Hash}; | ||
use snafu::{ResultExt, Snafu}; | ||
use state_fold_types::ethers::{ | ||
prelude::ContractError, | ||
providers::{Http, HttpRateLimitRetryPolicy, Provider, RetryClient}, | ||
}; | ||
use std::sync::Arc; | ||
use url::Url; | ||
|
||
const MAX_RETRIES: u32 = 10; | ||
const INITIAL_BACKOFF: u64 = 1000; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub enum DappContractError { | ||
#[snafu(display("failed to obtain hash from dapp contract"))] | ||
ContractError { | ||
source: ContractError<Provider<RetryClient<Http>>>, | ||
}, | ||
} | ||
|
||
pub async fn get_template_hash( | ||
dapp_address: Address, | ||
provider_http_endpoint: Url, | ||
) -> Result<Hash, DappContractError> { | ||
let provider = Provider::new(RetryClient::new( | ||
Http::new(provider_http_endpoint), | ||
Box::new(HttpRateLimitRetryPolicy), | ||
MAX_RETRIES, | ||
INITIAL_BACKOFF, | ||
)); | ||
|
||
let cartesi_dapp = | ||
CartesiDApp::new(dapp_address.inner(), Arc::new(provider)); | ||
|
||
let template_hash = cartesi_dapp | ||
.get_template_hash() | ||
.call() | ||
.await | ||
.context(ContractSnafu)?; | ||
|
||
Ok(Hash::new(template_hash)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.