Skip to content

Commit 2cc34f9

Browse files
authored
chore(test): fix helios test (#34)
* feat: fix helios test * fix * clippy * fix: test * fix
1 parent 6bc5469 commit 2cc34f9

File tree

7 files changed

+60
-23
lines changed

7 files changed

+60
-23
lines changed

.github/workflows/run_program.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ concurrency:
1515
jobs:
1616
run_program:
1717
name: Test SP1 Helios Program
18-
runs-on: [runs-on, runner=4cpu-linux-arm64 , "run-id=${{ github.run_id }}"]
19-
env:
20-
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
18+
runs-on: [runs-on, runner=32cpu-linux-x64, "run-id=${{ github.run_id }}"]
2119
steps:
2220
- name: Checkout sources
2321
uses: actions/checkout@v4

elf/sp1-helios-elf

-236 Bytes
Binary file not shown.

program/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ pub fn main() {
5555
)
5656
.expect("Finality update failed to verify.");
5757

58-
apply_finality_update(&mut store, &finality_update)
59-
.expect("A valid finality update should always apply.");
58+
apply_finality_update(&mut store, &finality_update);
6059

6160
// Ensure the new head is greater than the previous head. This guarantees that the finality
6261
// update was correctly applied.

script/bin/genesis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub async fn main() -> Result<()> {
6363

6464
let checkpoint;
6565
if let Some(temp_slot) = args.slot {
66-
checkpoint = get_checkpoint(temp_slot).await;
66+
checkpoint = get_checkpoint(temp_slot).await?;
6767
} else {
6868
checkpoint = get_latest_checkpoint().await;
6969
}
@@ -74,7 +74,7 @@ pub async fn main() -> Result<()> {
7474
verifier = env::var("SP1_VERIFIER_ADDRESS").unwrap().parse().unwrap();
7575
}
7676

77-
let helios_client = get_client(checkpoint).await;
77+
let helios_client = get_client(checkpoint).await?;
7878
let finalized_header = helios_client
7979
.store
8080
.finalized_header

script/bin/operator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ impl SP1HeliosOperator {
238238
.unwrap();
239239

240240
// Fetch the checkpoint at that slot
241-
let checkpoint = get_checkpoint(slot).await;
241+
let checkpoint = get_checkpoint(slot).await?;
242242

243243
// Get the client from the checkpoint
244-
let client = get_client(checkpoint).await;
244+
let client = get_client(checkpoint).await?;
245245

246246
// Request an update
247247
match self.request_update(client).await {

script/bin/test.rs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloy_primitives::B256;
12
use anyhow::Result;
23
use clap::{command, Parser};
34
use helios_ethereum::rpc::ConsensusRpc;
@@ -19,19 +20,47 @@ async fn main() -> Result<()> {
1920
setup_logger();
2021
let args = GenesisArgs::parse();
2122

22-
// Get the current slot from the contract or fetch the latest checkpoint
23-
let checkpoint = if let Some(slot) = args.slot {
24-
get_checkpoint(slot).await
25-
} else {
26-
get_latest_checkpoint().await
23+
// Get the latest checkpoint.
24+
let slot = match args.slot {
25+
Some(s) => s,
26+
None => {
27+
// Get latest checkpoint and use it to determine current slot
28+
let latest_checkpoint = get_latest_checkpoint().await;
29+
let client = get_client(latest_checkpoint).await?;
30+
client.expected_current_slot()
31+
}
2732
};
2833

29-
// Setup client.
30-
let helios_client = get_client(checkpoint).await;
34+
// Find a valid checkpoint by searching backwards from the slot
35+
let mut checkpoint = B256::ZERO;
36+
let mut checkpoint_slot: u64 = 0;
37+
for i in slot.saturating_sub(8000)..slot {
38+
if let Ok(cp) = get_checkpoint(i).await {
39+
if get_client(cp).await.is_ok() {
40+
checkpoint = cp;
41+
checkpoint_slot = i;
42+
break;
43+
}
44+
}
45+
}
46+
47+
// Setup client with the found checkpoint
48+
let helios_client = get_client(checkpoint).await?;
49+
3150
let updates = get_updates(&helios_client).await;
3251
let finality_update = helios_client.rpc.get_finality_update().await.unwrap();
33-
3452
let expected_current_slot = helios_client.expected_current_slot();
53+
54+
println!("Checkpoint slot: {}", checkpoint_slot);
55+
println!(
56+
"Finality update slot: {}",
57+
finality_update.attested_header().beacon().slot
58+
);
59+
println!(
60+
"Finality update signature slot: {}",
61+
finality_update.signature_slot()
62+
);
63+
3564
let inputs = ProofInputs {
3665
updates,
3766
finality_update,
@@ -46,7 +75,10 @@ async fn main() -> Result<()> {
4675
stdin.write_slice(&serde_cbor::to_vec(&inputs)?);
4776

4877
let prover_client = ProverClient::builder().cpu().build();
49-
let (_, report) = prover_client.execute(ELF, &stdin).run()?;
78+
let (_, report) = prover_client
79+
.execute(ELF, &stdin)
80+
.calculate_gas(false)
81+
.run()?;
5082
println!("Execution Report: {:?}", report);
5183

5284
Ok(())

script/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use helios_ethereum::{
1111
rpc::http_rpc::HttpRpc,
1212
};
1313

14+
use anyhow::{anyhow, Result};
1415
use std::sync::Arc;
1516
use tokio::sync::{mpsc::channel, watch};
1617
use tree_hash::TreeHash;
@@ -47,7 +48,7 @@ pub async fn get_latest_checkpoint() -> B256 {
4748
}
4849

4950
/// Fetch checkpoint from a slot number.
50-
pub async fn get_checkpoint(slot: u64) -> B256 {
51+
pub async fn get_checkpoint(slot: u64) -> Result<B256> {
5152
let consensus_rpc = std::env::var("SOURCE_CONSENSUS_RPC_URL").unwrap();
5253
let chain_id = std::env::var("SOURCE_CHAIN_ID").unwrap();
5354
let network = Network::from_chain_id(chain_id.parse().unwrap()).unwrap();
@@ -73,13 +74,17 @@ pub async fn get_checkpoint(slot: u64) -> B256 {
7374
Arc::new(config),
7475
);
7576

76-
let block: BeaconBlock<MainnetConsensusSpec> = client.rpc.get_block(slot).await.unwrap();
77+
let block: BeaconBlock<MainnetConsensusSpec> = client
78+
.rpc
79+
.get_block(slot)
80+
.await
81+
.map_err(|e| anyhow!("error getting block: {}", e.to_string()))?;
7782

78-
B256::from_slice(block.tree_hash_root().as_ref())
83+
Ok(B256::from_slice(block.tree_hash_root().as_ref()))
7984
}
8085

8186
/// Setup a client from a checkpoint.
82-
pub async fn get_client(checkpoint: B256) -> Inner<MainnetConsensusSpec, HttpRpc> {
87+
pub async fn get_client(checkpoint: B256) -> Result<Inner<MainnetConsensusSpec, HttpRpc>> {
8388
let consensus_rpc = std::env::var("SOURCE_CONSENSUS_RPC_URL").unwrap();
8489
let chain_id = std::env::var("SOURCE_CHAIN_ID").unwrap();
8590
let network = Network::from_chain_id(chain_id.parse().unwrap()).unwrap();
@@ -106,6 +111,9 @@ pub async fn get_client(checkpoint: B256) -> Inner<MainnetConsensusSpec, HttpRpc
106111
Arc::new(config),
107112
);
108113

109-
client.bootstrap(checkpoint).await.unwrap();
110114
client
115+
.bootstrap(checkpoint)
116+
.await
117+
.map_err(|e| anyhow!("error bootstrapping client: {}", e.to_string()))?;
118+
Ok(client)
111119
}

0 commit comments

Comments
 (0)