Skip to content

Do not send transaction if new head is <= current head. #14

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion script/bin/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use helios_ethereum::consensus::Inner;
use helios_ethereum::rpc::http_rpc::HttpRpc;
use helios_ethereum::rpc::ConsensusRpc;

use alloy::sol_types::SolValue;
use alloy_primitives::hex;
use alloy_primitives::hex::ToHexExt;
use avail_rust::avail::babe::storage::types::current_slot::CurrentSlot;
use avail_rust::avail::runtime_types::bounded_collections::bounded_vec::BoundedVec;
use avail_rust::avail_core::currency::AVAIL;
use avail_rust::sp_core::{twox_128, Decode};
Expand All @@ -20,7 +22,7 @@ use jsonrpsee::{
http_client::{HttpClient, HttpClientBuilder},
rpc_params,
};
use sp1_helios_primitives::types::ProofInputs;
use sp1_helios_primitives::types::{ProofInputs, ProofOutputs};
use sp1_helios_script::*;
use sp1_sdk::{
NetworkProver, Prover, ProverClient, SP1ProofWithPublicValues, SP1ProvingKey, SP1Stdin,
Expand Down Expand Up @@ -185,6 +187,20 @@ impl SP1AvailLightClientOperator {
.timeout(Duration::from_secs(900))
.run()?;
info!("Generate proof end");

let proof_outputs: ProofOutputs =
SolValue::abi_decode(&proof.public_values.as_slice(), true)
.context("Cannot decode public values")?;
let new_slot = proof_outputs.newHead.to();
if new_slot <= head {
tracing::warn!(
message = "New slot slot is <= from the current, skipping update",
current_slot = head,
new_slot = new_slot
);
return Ok(None);
}

info!("Attempting to update to new head block: {:?}", latest_block);
Ok(Some(proof))
}
Expand Down
Loading