Skip to content

Commit

Permalink
feat: change DApp deployment block config
Browse files Browse the repository at this point in the history
Replaced DAPP_DEPLOY_BLOCK_HASH with DAPP_DEPLOYMENT_BLOCK_NUMBER.
  • Loading branch information
gligneul committed Dec 3, 2023
1 parent 47d47df commit 477342a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added unified configuration for the Node with a new set of environment variables.
- Added `cartesi-rollups-cli` binary to help develop and debug the Cartesi Rollups node

### Changed

- Change from `DAPP_DEPLOY_BLOCK_HASH` to `DAPP_DEPLOYMENT_BLOCK_NUMBER`.

## [1.2.0]

### Added
Expand Down
13 changes: 4 additions & 9 deletions offchain/dispatcher/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use eth_state_client_lib::{
config::SCConfig, error::StateServerError, BlockServer,
GrpcStateFoldClient, StateServer,
};
use eth_state_fold_types::{ethereum_types::H256, BlockStreamItem};
use eth_state_fold_types::{ethereum_types::U64, BlockStreamItem};
use rollups_events::DAppMetadata;
use snafu::ResultExt;
use tokio_stream::{Stream, StreamExt};
Expand Down Expand Up @@ -80,15 +80,10 @@ pub async fn create_context(
dapp_metadata: DAppMetadata,
metrics: DispatcherMetrics,
) -> Result<Context, DispatcherError> {
let dapp_deploy_block_hash = H256(
config
.blockchain_config
.dapp_deploy_block_hash
.clone()
.into_inner(),
);
let dapp_deployment_block_number =
U64::from(config.blockchain_config.dapp_deployment_block_number);
let genesis_timestamp: u64 = block_server
.query_block(dapp_deploy_block_hash)
.query_block(dapp_deployment_block_number)
.await
.context(StateServerSnafu)?
.timestamp
Expand Down
24 changes: 12 additions & 12 deletions offchain/types/src/blockchain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use clap::{command, Parser};
use rollups_events::{Address, Hash};
use rollups_events::Address;
use serde::{de::DeserializeOwned, Deserialize};
use snafu::{ResultExt, Snafu};
use std::{fs::File, io::BufReader, path::PathBuf};
Expand Down Expand Up @@ -35,9 +35,9 @@ pub struct BlockchainCLIConfig {
#[arg(long, env)]
pub dapp_address: Option<String>,

/// DApp deploy block hash
/// DApp deployment block number
#[arg(long, env)]
pub dapp_deploy_block_hash: Option<String>,
pub dapp_deployment_block_number: Option<u64>,

/// History contract address
#[arg(long, env)]
Expand All @@ -63,7 +63,7 @@ pub struct BlockchainCLIConfig {
#[derive(Clone, Debug)]
pub struct BlockchainConfig {
pub dapp_address: Address,
pub dapp_deploy_block_hash: Hash,
pub dapp_deployment_block_number: u64,
pub history_address: Address,
pub authority_address: Address,
pub input_box_address: Address,
Expand Down Expand Up @@ -96,10 +96,7 @@ impl TryFrom<BlockchainCLIConfig> for BlockchainConfig {
// try to get the values from the environment values
let mut dapp_address =
cli.dapp_address.map(deserialize::<Address>).transpose()?;
let mut dapp_deploy_block_hash = cli
.dapp_deploy_block_hash
.map(deserialize::<Hash>)
.transpose()?;
let mut dapp_deployment_block_number = cli.dapp_deployment_block_number;
let mut history_address = cli
.history_address
.map(deserialize::<Address>)
Expand All @@ -118,7 +115,8 @@ impl TryFrom<BlockchainCLIConfig> for BlockchainConfig {
cli.dapp_deployment_file.map(read::<Contract>).transpose()?
{
dapp_address = dapp_address.or(file.address);
dapp_deploy_block_hash = dapp_deploy_block_hash.or(file.block_hash);
dapp_deployment_block_number =
dapp_deployment_block_number.or(file.block_number);
}
if let Some(file) = cli
.rollups_deployment_file
Expand All @@ -144,7 +142,9 @@ impl TryFrom<BlockchainCLIConfig> for BlockchainConfig {

Ok(BlockchainConfig {
dapp_address: check_missing!(dapp_address),
dapp_deploy_block_hash: check_missing!(dapp_deploy_block_hash),
dapp_deployment_block_number: check_missing!(
dapp_deployment_block_number
),
history_address: check_missing!(history_address),
authority_address: check_missing!(authority_address),
input_box_address: check_missing!(input_box_address),
Expand All @@ -157,8 +157,8 @@ struct Contract {
#[serde(rename = "address")]
address: Option<Address>,

#[serde(rename = "blockHash")]
block_hash: Option<Hash>,
#[serde(rename = "blockNumber")]
block_number: Option<u64>,
}

#[derive(Clone, Debug, Deserialize)]
Expand Down

0 comments on commit 477342a

Please sign in to comment.