Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:all new handover code and fixed some handover error situations #358

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"pallets/mq/runtime-api",
"standalone/chain/*",
"standalone/teeworker/cifrost",
"scripts/docker/ceseal/gramine/handover",
]

resolver = "2"
Expand Down Expand Up @@ -407,6 +408,7 @@ webpki = { git = "https://github.com/rustls/webpki", version = "=0.102.0-alpha.3
"alloc",
"ring",
], rev = "2ed9a4324f48c2c46ffdd7dc9d3eb315af25fce2" } # Release version no-std has bug
walkdir = "2.5.0"
# webpki = { version = "0.102.0", package = "rustls-webpki", default-features = false, features = ["alloc", "ring"] }
# ---- Generic crates end ----

Expand Down
5 changes: 3 additions & 2 deletions crates/cestory/src/ceseal_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> CesealApi for RpcSe
.get_ceseal_bin_added_at(&runtime_hash)
.ok_or_else(|| from_display("Client ceseal not allowed on chain"))?;

if my_runtime_timestamp >= req_runtime_timestamp {
return Err(Status::internal("No handover for old ceseal"))
if my_runtime_timestamp >= req_runtime_timestamp {
return Err(Status::internal("Same ceseal version or rollback ,No local handover provided"))
}
} else {
info!("Skip ceseal timestamp check in dev mode");
Expand Down Expand Up @@ -684,6 +684,7 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> Ceseal<Platform> {
Ok(pb::SyncedTo { synced_to: last_block })
}

//Check whether checkpoint file is used and save it regularly
fn maybe_take_checkpoint(&mut self) -> anyhow::Result<()> {
if !self.args.enable_checkpoint {
return Ok(())
Expand Down
4 changes: 2 additions & 2 deletions scripts/docker/ceseal/gramine/handover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ if (await exists(path.join(currentPath, "data/protected_files/runtime-data.seal"
}

let previousVersion: number | undefined = await confirmPreviousVersion();

//Otherwise, confirm whether a previous version exists. If there is no previous version, no handover is required, back up the current version to the backup directory and exit.
if (previousVersion === undefined) {
log("No previous version, no need to handover!");

Expand All @@ -135,7 +135,7 @@ if (previousVersion === undefined) {

Deno.exit(0);
}

//If the current version is the same as the previous version, there is no need to hand over and exit directly.
if (currentVersion == previousVersion) {
log("same version, no need to handover")
Deno.exit(0);
Expand Down
11 changes: 11 additions & 0 deletions scripts/docker/ceseal/gramine/handover/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "handover"
version = "0.1.0"
edition = "2021"

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

[dependencies]
clap = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["full"] }
walkdir = { workspace = true }
65 changes: 65 additions & 0 deletions scripts/docker/ceseal/gramine/handover/src/arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use clap::Parser;

#[derive(Parser, Debug)]
#[command(
about = "xxx",
version,
author
)]
pub struct Args {
#[arg(
long,
help = "The backup path of the each version of ceseal",
default_value = "/opt/ceseal/backups"
)]
pub previous_version_ceseal_path: String,

#[arg(
long,
help = "The backup path of the current version of ceseal",
default_value = "/opt/ceseal/releases/current"
)]
pub current_version_ceseal_path: String,

#[arg(
long,
help = "ceseal home",
default_value = "/opt/ceseal/data"
)]
pub ceseal_data_path: String,

#[arg(
long,
help = "Ceseal log path for detect the status of previous ceseal",
default_value = "/tmp/pre_ceseal.log"
)]
pub previous_ceseal_log_path: String,

#[arg(
long,
help = "Ceseal log path for detect the status of new ceseal",
default_value = "/tmp/new_ceseal.log"
)]
pub new_ceseal_log_path: String,

#[arg(
long,
help = "The relative path where each version of ceseal stores protected files",
default_value = "data/protected_files"
)]
pub ceseal_protected_files_path: String,

#[arg(
long,
help = "the relative path where each version of ceseal stores checkpoint file",
default_value = "data/storage_files"
)]
pub ceseal_storage_files_path: String,

#[arg(
long,
help = "old ceseal start on this port",
default_value = "1888"
)]
pub previous_ceseal_port: u64,
}
24 changes: 24 additions & 0 deletions scripts/docker/ceseal/gramine/handover/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::{error, fmt};

#[derive(Debug)]
pub enum Error {
StartCesealFailed(String),
RedirectCesealLogFailed(String),
DetectCesealRunningStatueFailed(String),
PreviousVersionFailed(String),
CopyDirectory(String)
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::StartCesealFailed(e) => write!(f, "{:?}", e),
Error::RedirectCesealLogFailed(e) => write!(f, "{:?}", e),
Error::DetectCesealRunningStatueFailed(e) => write!(f, "{:?}", e),
Error::PreviousVersionFailed(e) => write!(f, "{:?}", e),
Error::CopyDirectory(e) => write!(f, "{:?}", e),
}
}
}

impl error::Error for Error {}
Loading
Loading