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

chore: Update helios #45

Merged
merged 2 commits into from
Aug 24, 2023
Merged
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
17 changes: 12 additions & 5 deletions Cargo.lock

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

15 changes: 11 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ ethers-contract = { version = "2.0.9", default-features = false, features = [
] }
ethers-core = "2.0.9"
eyre = "0.6.8"
helios_client = { package = "client", git = "https://github.com/eigerco/helios", rev = "07cc7af" }
helios_common = { package = "common", git = "https://github.com/eigerco/helios", rev = "07cc7af" }
helios_config = { package = "config", git = "https://github.com/eigerco/helios", rev = "07cc7af" }
helios_execution = { package = "execution", git = "https://github.com/eigerco/helios", rev = "07cc7af" }
helios_client = { package = "client", git = "https://github.com/eigerco/helios", rev = "62c7237" }
helios_common = { package = "common", git = "https://github.com/eigerco/helios", rev = "62c7237" }
helios_config = { package = "config", git = "https://github.com/eigerco/helios", rev = "62c7237" }
helios_execution = { package = "execution", git = "https://github.com/eigerco/helios", rev = "62c7237" }
interface = { path = "src/interface" }

[profile.release]
opt-level = "z"
lto = true
codegen-units = 1

# Uncomment to apply local changes of Helios
#[patch.'https://github.com/eigerco/helios']
#client = { path = "../helios/client" }
#common = { path = "../helios/common" }
#config = { path = "../helios/config" }
#execution = { path = "../helios/execution" }
4 changes: 2 additions & 2 deletions src/ethereum-canister/src/helios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ pub(crate) async fn start_client(
Ok(())
}

pub(crate) async fn get_last_checkpoint() -> Option<String> {
pub(crate) fn get_last_checkpoint() -> Option<String> {
match try_client() {
Some(client) => client.get_last_checkpoint().await,
Some(client) => client.get_last_checkpoint(),
None => None,
}
}
Expand Down
23 changes: 10 additions & 13 deletions src/ethereum-canister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,19 @@ async fn setup(request: SetupRequest) {
}

#[query]
async fn get_block_number() -> Nat {
fn get_block_number() -> Nat {
let helios = helios::client();

let head_block_num = helios
.get_block_number()
.await
.expect("get_block_number failed");
let head_block_num = helios.get_block_number().expect("get_block_number failed");

head_block_num.into()
}

#[query]
async fn get_gas_price() -> U256 {
fn get_gas_price() -> U256 {
let helios = helios::client();

let gas_price = helios.get_gas_price().await.expect("get_gas_price failed");
let gas_price = helios.get_gas_price().expect("get_gas_price failed");

gas_price.into()
}
Expand Down Expand Up @@ -114,7 +111,7 @@ async fn erc721_owner_of(request: Erc721OwnerOfRequest) -> Address {
async fn pre_upgrade() {
debug!("Stopping client");

let checkpoint = helios::get_last_checkpoint().await;
let checkpoint = helios::get_last_checkpoint();
save_static_string(&LAST_CHECKPOINT, checkpoint);

helios::shutdown().await;
Expand All @@ -123,28 +120,28 @@ async fn pre_upgrade() {
}

#[post_upgrade]
async fn post_upgrade() {
fn post_upgrade() {
let _ = ic_logger::init_with_level(log::Level::Trace);

// Workaround because cross-canister calls are not allowed in post_upgrade.
// Client will be started from a timer in a second.
set_timer(std::time::Duration::from_secs(1), || {
ic_cdk::spawn(async move {
let Some(network) = load_static_string(&LAST_NETWORK) else {
return
return;
};

let Ok(network) = network.parse::<Network>() else {
error!("Failed to parse network: {network}. Use `setup` to initalize canister.");
return
return;
};

let Some(consensus_rpc_url) = load_static_string(&LAST_CONSENSUS_RPC_URL) else {
return
return;
};

let Some(execution_rpc_url) = load_static_string(&LAST_EXECUTION_RPC_URL) else {
return
return;
};

let checkpoint = load_static_string(&LAST_CHECKPOINT);
Expand Down