Skip to content

Commit

Permalink
feat(jstzd): add jstz rollup to config
Browse files Browse the repository at this point in the history
  • Loading branch information
ryutamago committed Dec 5, 2024
1 parent eb284fa commit 30a052e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 47 deletions.
110 changes: 77 additions & 33 deletions crates/jstzd/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use rust_embed::Embed;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use crate::task::jstzd::JstzdConfig;
use crate::{EXCHANGER_ADDRESS, JSTZ_NATIVE_BRIDGE_ADDRESS, JSTZ_ROLLUP_ADDRESS};
use crate::{
jstz_rollup_path, EXCHANGER_ADDRESS, JSTZ_NATIVE_BRIDGE_ADDRESS, JSTZ_ROLLUP_ADDRESS,
};
use anyhow::{Context, Result};
use jstz_node::config::JstzNodeConfig;
use octez::r#async::endpoint::Endpoint;
Expand All @@ -19,13 +21,22 @@ use tezos_crypto_rs::hash::SmartRollupHash;
use tokio::io::AsyncReadExt;

const DEFAULT_JSTZD_SERVER_PORT: u16 = 55555;
const ACTIVATOR_PUBLIC_KEY: &str =
"edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2";
const KERNEL_DEBUG_FILE: &str = "kernel.log";
const ACTIVATOR_PK: &str = "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2";
pub const BOOTSTRAP_CONTRACT_NAMES: [(&str, &str); 2] = [
("exchanger", EXCHANGER_ADDRESS),
("jstz_native_bridge", JSTZ_NATIVE_BRIDGE_ADDRESS),
];

pub(crate) const ACTIVATOR_ACCOUNT_SK: &str =
"unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6";
pub(crate) const ACTIVATOR_ACCOUNT_ALIAS: &str = "activator";
pub(crate) const ROLLUP_OPERATOR_ACCOUNT_SK: &str =
"unencrypted:edsk3gUfUPyBSfrS9CCgmCiQsTCHGkviBDusMxDJstFtojtc1zcpsh";
pub(crate) const ROLLUP_OPERATOR_PK: &str =
"edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav";
pub(crate) const ROLLUP_OPERATOR_ACCOUNT_ALIAS: &str = "bootstrap1";

#[derive(Embed)]
#[folder = "$CARGO_MANIFEST_DIR/resources/bootstrap_contract/"]
pub struct BootstrapContractFile;
Expand Down Expand Up @@ -72,18 +83,18 @@ pub(crate) async fn build_config(
&octez_client_config,
)?;

// TODO: https://linear.app/tezos/issue/JSTZ-238/deserialize-rollup-config
// Dummy rollup config for now
let octez_node_endpoint = octez_node_config.rpc_endpoint.clone();
let octez_rollup_config = OctezRollupConfigBuilder::new(
octez_node_endpoint,
octez_client_config.base_dir().into(),
SmartRollupHash::from_base58_check(JSTZ_ROLLUP_ADDRESS).unwrap(),
"bootstrap1".to_string(),
"dummy-kernel".into(),
ROLLUP_OPERATOR_ACCOUNT_ALIAS.to_string(),
jstz_rollup_path::kernel_installer_path(),
)
.set_data_dir(RollupDataDir::Temp)
.set_rpc_endpoint(&Endpoint::localhost(8000))
.set_data_dir(RollupDataDir::TempWithPreImages {
preimages_dir: jstz_rollup_path::preimages_path(),
})
.set_kernel_debug_file(Path::new(KERNEL_DEBUG_FILE))
.build()
.unwrap();

Expand Down Expand Up @@ -111,15 +122,10 @@ pub(crate) async fn build_config(

fn default_config() -> Config {
let mut config = Config::default();
config
.protocol
.set_bootstrap_accounts([BootstrapAccount::new(
// add activator to bootstrap accounts in default config so that
// at least baker has an account to run with
ACTIVATOR_PUBLIC_KEY,
40_000_000_000,
)
.unwrap()]);
config.protocol.set_bootstrap_accounts([
BootstrapAccount::new(ROLLUP_OPERATOR_PK, 60_000_000_000).unwrap(),
BootstrapAccount::new(ACTIVATOR_PK, 40_000_000_000).unwrap(),
]);
config
}

Expand Down Expand Up @@ -195,11 +201,14 @@ mod tests {
BootstrapAccount, BootstrapContract, BootstrapSmartRollup, Protocol,
ProtocolConstants, ProtocolParameterBuilder, SmartRollupPvmKind,
},
rollup::RollupDataDir,
};
use tempfile::{tempdir, NamedTempFile};
use tezos_crypto_rs::hash::ContractKt1Hash;
use tokio::io::AsyncReadExt;

use super::{jstz_rollup_path, JSTZ_ROLLUP_ADDRESS, KERNEL_DEBUG_FILE};

use super::Config;

async fn read_bootstrap_contracts_from_param_file(
Expand Down Expand Up @@ -408,11 +417,14 @@ mod tests {
fn default_config() {
let config = super::default_config();
let accounts = config.protocol.bootstrap_accounts();
assert_eq!(accounts.len(), 1);
assert_eq!(
**accounts.first().unwrap(),
BootstrapAccount::new(super::ACTIVATOR_PUBLIC_KEY, 40_000_000_000).unwrap()
);
assert_eq!(accounts.len(), 2);
let expected_accounts = [
BootstrapAccount::new(super::ROLLUP_OPERATOR_PK, 60_000_000_000).unwrap(),
BootstrapAccount::new(super::ACTIVATOR_PK, 40_000_000_000).unwrap(),
];
assert!(expected_accounts
.iter()
.all(|expected| { accounts.iter().any(|account| **account == *expected) }));
}

#[tokio::test]
Expand Down Expand Up @@ -451,6 +463,31 @@ mod tests {
)
.await;
assert_eq!(contracts.len(), 2);

assert_eq!(
config.octez_rollup_config().address.to_base58_check(),
JSTZ_ROLLUP_ADDRESS
);
assert_eq!(
config
.octez_rollup_config()
.kernel_debug_file
.as_ref()
.unwrap()
.to_str()
.unwrap(),
KERNEL_DEBUG_FILE,
);
assert_eq!(
config.octez_rollup_config().data_dir,
RollupDataDir::TempWithPreImages {
preimages_dir: jstz_rollup_path::preimages_path(),
}
);
assert_eq!(
config.octez_rollup_config().boot_sector_file,
jstz_rollup_path::kernel_installer_path()
);
}

#[tokio::test]
Expand All @@ -464,20 +501,27 @@ mod tests {
.unwrap();
let params = serde_json::from_str::<serde_json::Value>(&buf).unwrap();

// one bootstrap account should have been inserted: the activator account
// two bootstrap account should have been inserted: the activator account and the rollup operator account
let accounts = params
.as_object()
.unwrap()
.get("bootstrap_accounts")
.unwrap()
.as_array()
.unwrap();
assert_eq!(accounts.len(), 1);
assert_eq!(
serde_json::from_value::<BootstrapAccount>(accounts.first().unwrap().clone())
.unwrap(),
BootstrapAccount::new(super::ACTIVATOR_PUBLIC_KEY, 40_000_000_000).unwrap()
);
assert_eq!(accounts.len(), 2);

let bootstrap_accounts = accounts
.iter()
.map(|acc| serde_json::from_value::<BootstrapAccount>(acc.clone()).unwrap())
.collect::<Vec<_>>();

assert!(bootstrap_accounts.contains(
&BootstrapAccount::new(super::ACTIVATOR_PK, 40_000_000_000).unwrap()
));
assert!(bootstrap_accounts.contains(
&BootstrapAccount::new(super::ROLLUP_OPERATOR_PK, 60_000_000_000).unwrap()
));
}

#[tokio::test]
Expand Down Expand Up @@ -530,7 +574,7 @@ mod tests {
async fn build_protocol_params() {
let mut builder = ProtocolParameterBuilder::new();
builder.set_bootstrap_accounts([BootstrapAccount::new(
super::ACTIVATOR_PUBLIC_KEY,
super::ACTIVATOR_PK,
40_000_000_000,
)
.unwrap()]);
Expand Down Expand Up @@ -560,7 +604,7 @@ mod tests {
let mut builder = ProtocolParameterBuilder::new();
builder
.set_bootstrap_accounts([BootstrapAccount::new(
super::ACTIVATOR_PUBLIC_KEY,
super::ACTIVATOR_PK,
40_000_000_000,
)
.unwrap()])
Expand Down
27 changes: 13 additions & 14 deletions crates/jstzd/src/task/jstzd.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use crate::config::{
ACTIVATOR_ACCOUNT_ALIAS, ACTIVATOR_ACCOUNT_SK, ROLLUP_OPERATOR_ACCOUNT_ALIAS,
ROLLUP_OPERATOR_ACCOUNT_SK,
};

use super::{
child_wrapper::Shared,
jstz_node::JstzNode,
Expand Down Expand Up @@ -97,6 +102,10 @@ impl JstzdConfig {
&self.baker_config
}

pub fn octez_rollup_config(&self) -> &OctezRollupConfig {
&self.octez_rollup_config
}

pub fn protocol_params(&self) -> &ProtocolParameter {
&self.protocol_params
}
Expand Down Expand Up @@ -176,33 +185,23 @@ impl Task for Jstzd {
}

impl Jstzd {
const ACTIVATOR_ACCOUNT_SK: &'static str =
"unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6";
const ACTIVATOR_ACCOUNT_ALIAS: &'static str = "activator";
const ROLLUP_OPERATOR_ACCOUNT_SK: &'static str =
"unencrypted:edsk3gUfUPyBSfrS9CCgmCiQsTCHGkviBDusMxDJstFtojtc1zcpsh";
const ROLLUP_OPERATOR_ACCOUNT_ALIAS: &'static str = "bootstrap1";

async fn import_activator(octez_client: &OctezClient) -> Result<()> {
octez_client
.import_secret_key(Self::ACTIVATOR_ACCOUNT_ALIAS, Self::ACTIVATOR_ACCOUNT_SK)
.import_secret_key(ACTIVATOR_ACCOUNT_ALIAS, ACTIVATOR_ACCOUNT_SK)
.await
.context(format!(
"Failed to import account '{}'",
Self::ACTIVATOR_ACCOUNT_ALIAS
ACTIVATOR_ACCOUNT_ALIAS
))
}

async fn import_rollup_operator(octez_client: &OctezClient) -> Result<()> {
octez_client
.import_secret_key(
Self::ROLLUP_OPERATOR_ACCOUNT_ALIAS,
Self::ROLLUP_OPERATOR_ACCOUNT_SK,
)
.import_secret_key(ROLLUP_OPERATOR_ACCOUNT_ALIAS, ROLLUP_OPERATOR_ACCOUNT_SK)
.await
.context(format!(
"Failed to import account '{}'",
Self::ROLLUP_OPERATOR_ACCOUNT_ALIAS
ROLLUP_OPERATOR_ACCOUNT_ALIAS
))
}

Expand Down

0 comments on commit 30a052e

Please sign in to comment.