Skip to content

Commit c9e42ab

Browse files
committed
fix: wallet signers populator from field
1 parent b8a596e commit c9e42ab

File tree

2 files changed

+32
-73
lines changed

2 files changed

+32
-73
lines changed

script/bin/operator.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloy::{
2-
network::{EthereumWallet, Network, ReceiptResponse},
2+
network::{Network, ReceiptResponse},
33
primitives::{Address, B256},
44
providers::{Provider, ProviderBuilder},
55
signers::local::PrivateKeySigner,
@@ -21,8 +21,6 @@ use tendermint_light_client_verifier::Verdict;
2121
use tracing::{error, info, Instrument};
2222
use tracing_subscriber::EnvFilter;
2323

24-
use sp1_blobstream_script::util::signer::MaybeWallet;
25-
2624
/////// Contract ///////
2725

2826
sol! {
@@ -621,31 +619,29 @@ async fn main() {
621619

622620
// Succinct deployments use the `CHAINS` environment variable.
623621
let config = ChainConfig::fetch().expect("Failed to fetch chain config");
624-
let maybe_private_key: Option<PrivateKeySigner> = env::var("PRIVATE_KEY")
625-
.ok()
626-
.map(|s| s.parse().expect("Failed to parse PRIVATE_KEY"));
627622

628623
// Set up the KMS relayer config.
629624
let signer_mode = env::var("SIGNER_MODE")
630625
.map(|s| s.parse().expect("SIGNER_MODE failed to parse"))
631626
.unwrap_or(SignerMode::Kms);
632627

633-
// Ensure a signer is set if KMS relayer is false.
634-
if matches!(signer_mode, SignerMode::Local) && maybe_private_key.is_none() {
635-
panic!("PRIVATE_KEY is not set but signer mode is local.");
628+
match signer_mode {
629+
SignerMode::Local => run_with_wallet(config).await,
630+
SignerMode::Kms => run_with_kms_relayer(config).await,
636631
}
632+
}
637633

638-
// Set up the signer.
639-
let signer = MaybeWallet::new(maybe_private_key.map(EthereumWallet::new));
634+
async fn run_with_wallet(config: Vec<ChainConfig>) {
635+
let key = env::var("PRIVATE_KEY").expect("PRIVATE_KEY not set");
636+
let signer: PrivateKeySigner = key.parse().expect("Failed to parse PRIVATE_KEY");
640637

641-
// Set up the prover and program keys.
642638
let prover = ProverClient::builder().network().build();
643639
let (pk, vk) = prover.setup(TENDERMINT_ELF);
644640

645641
let client = TendermintRPCClient::default();
646642

647-
let mut operator = SP1BlobstreamOperator::new(pk, vk, client, signer_mode, Arc::new(prover));
648-
643+
let mut operator =
644+
SP1BlobstreamOperator::new(pk, vk, client, SignerMode::Local, Arc::new(prover));
649645
for (i, c) in config.iter().enumerate() {
650646
let url: Url = c.rpc_url.parse().expect("Failed to parse RPC URL");
651647
tracing::info!("Adding chain {:?} to operator", url.domain());
@@ -660,3 +656,25 @@ async fn main() {
660656

661657
operator.run().await;
662658
}
659+
660+
async fn run_with_kms_relayer(config: Vec<ChainConfig>) {
661+
let prover = ProverClient::builder().network().build();
662+
let (pk, vk) = prover.setup(TENDERMINT_ELF);
663+
664+
let client = TendermintRPCClient::default();
665+
666+
let mut operator =
667+
SP1BlobstreamOperator::new(pk, vk, client, SignerMode::Kms, Arc::new(prover));
668+
669+
for (i, c) in config.iter().enumerate() {
670+
let url: Url = c.rpc_url.parse().expect("Failed to parse RPC URL");
671+
tracing::info!("Adding chain {:?} to operator", url.domain());
672+
tracing::info!("Chain {} of {}", i + 1, config.len());
673+
674+
let provider = ProviderBuilder::new().connect_http(url);
675+
676+
operator = operator.with_chain(provider, c.blobstream_address).await;
677+
}
678+
679+
operator.run().await;
680+
}

script/src/util.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -319,62 +319,3 @@ pub async fn fetch_header_hash(
319319
light_block.signed_header.header.hash().as_bytes(),
320320
))
321321
}
322-
323-
/// Implement a signer that may or may not actually be set.
324-
///
325-
/// This is useful to dynamically choose to use the KMS relayer in the operator,
326-
/// without having to change the actual provider type, since the provider is generic over a signer.
327-
pub mod signer {
328-
use alloy::{
329-
consensus::{TxEnvelope, TypedTransaction},
330-
network::{Network, NetworkWallet},
331-
primitives::Address,
332-
};
333-
334-
/// A signer than panics if called and not set.
335-
#[derive(Clone, Debug)]
336-
pub struct MaybeWallet<W>(Option<W>);
337-
338-
impl<W> MaybeWallet<W> {
339-
pub fn new(signer: Option<W>) -> Self {
340-
Self(signer)
341-
}
342-
}
343-
344-
impl<W, N> NetworkWallet<N> for MaybeWallet<W>
345-
where
346-
W: NetworkWallet<N>,
347-
N: Network<UnsignedTx = TypedTransaction, TxEnvelope = TxEnvelope>,
348-
{
349-
fn default_signer_address(&self) -> Address {
350-
self.0
351-
.as_ref()
352-
.expect("No signer set")
353-
.default_signer_address()
354-
}
355-
356-
fn has_signer_for(&self, address: &Address) -> bool {
357-
self.0
358-
.as_ref()
359-
.expect("No signer set")
360-
.has_signer_for(address)
361-
}
362-
363-
fn signer_addresses(&self) -> impl Iterator<Item = Address> {
364-
self.0.as_ref().expect("No signer set").signer_addresses()
365-
}
366-
367-
#[doc(alias = "sign_tx_from")]
368-
async fn sign_transaction_from(
369-
&self,
370-
sender: Address,
371-
tx: TypedTransaction,
372-
) -> alloy::signers::Result<TxEnvelope> {
373-
self.0
374-
.as_ref()
375-
.expect("No signer set")
376-
.sign_transaction_from(sender, tx)
377-
.await
378-
}
379-
}
380-
}

0 commit comments

Comments
 (0)