From 39efb721c5207ca7601eaff7cd7b46da31f43243 Mon Sep 17 00:00:00 2001 From: peilun-conflux <48905552+peilun-conflux@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:58:50 +0800 Subject: [PATCH] Remove sender from contract call. (#242) This allows the RPC services to cache the results. --- node/miner/src/config.rs | 10 +++++++--- node/miner/src/sealer.rs | 7 ++++--- node/miner/src/service.rs | 7 +++++-- node/miner/src/submitter.rs | 8 +++++--- node/miner/src/watcher.rs | 12 ++++++------ 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/node/miner/src/config.rs b/node/miner/src/config.rs index 847d4a8..e9dcb71 100644 --- a/node/miner/src/config.rs +++ b/node/miner/src/config.rs @@ -67,8 +67,8 @@ impl MinerConfig { }) } - pub(crate) async fn make_provider(&self) -> Result { - let provider = Arc::new(Provider::new( + pub(crate) fn make_provider(&self) -> Result>>, String> { + Ok(Arc::new(Provider::new( RetryClientBuilder::default() .rate_limit_retries(self.rate_limit_retries) .timeout_retries(self.timeout_retries) @@ -78,7 +78,11 @@ impl MinerConfig { .map_err(|e| format!("Cannot parse blockchain endpoint: {:?}", e))?, Box::new(HttpRateLimitRetryPolicy), ), - )); + ))) + } + + pub(crate) async fn make_signing_provider(&self) -> Result { + let provider = self.make_provider()?; let chain_id = provider .get_chainid() .await diff --git a/node/miner/src/sealer.rs b/node/miner/src/sealer.rs index aed65a0..eb630d5 100644 --- a/node/miner/src/sealer.rs +++ b/node/miner/src/sealer.rs @@ -1,6 +1,7 @@ use std::{collections::BTreeMap, sync::Arc}; use ethereum_types::H256; +use ethers::prelude::{Http, Provider, RetryClient}; use tokio::time::{sleep, Duration, Instant}; use contract_interface::{EpochRangeWithContextDigest, ZgsFlow}; @@ -12,14 +13,14 @@ use storage_async::Store; use task_executor::TaskExecutor; use zgs_spec::SECTORS_PER_SEAL; -use crate::config::{MineServiceMiddleware, MinerConfig}; +use crate::config::MinerConfig; const DB_QUERY_PERIOD_ON_NO_TASK: u64 = 1; const DB_QUERY_PERIOD_ON_ERROR: u64 = 5; const CHAIN_STATUS_QUERY_PERIOD: u64 = 5; pub struct Sealer { - flow_contract: ZgsFlow, + flow_contract: ZgsFlow>>, store: Arc, context_cache: BTreeMap, last_context_flow_length: u64, @@ -29,7 +30,7 @@ pub struct Sealer { impl Sealer { pub fn spawn( executor: TaskExecutor, - provider: Arc, + provider: Arc>>, store: Arc, config: &MinerConfig, miner_id: H256, diff --git a/node/miner/src/service.rs b/node/miner/src/service.rs index 6966b67..c5b0b3b 100644 --- a/node/miner/src/service.rs +++ b/node/miner/src/service.rs @@ -33,11 +33,13 @@ impl MineService { config: MinerConfig, store: Arc, ) -> Result, String> { - let provider = Arc::new(config.make_provider().await?); + let provider = config.make_provider()?; + let signing_provider = Arc::new(config.make_signing_provider().await?); let (msg_send, msg_recv) = broadcast::channel(1024); - let miner_id = check_and_request_miner_id(&config, store.as_ref(), &provider).await?; + let miner_id = + check_and_request_miner_id(&config, store.as_ref(), &signing_provider).await?; debug!("miner id setting complete."); let mine_context_receiver = MineContextWatcher::spawn( @@ -61,6 +63,7 @@ impl MineService { mine_answer_receiver, mine_context_receiver, provider.clone(), + signing_provider, store.clone(), &config, ); diff --git a/node/miner/src/submitter.rs b/node/miner/src/submitter.rs index 014f42e..5c3779d 100644 --- a/node/miner/src/submitter.rs +++ b/node/miner/src/submitter.rs @@ -2,6 +2,7 @@ use contract_interface::PoraAnswer; use contract_interface::{PoraMine, ZgsFlow}; use ethereum_types::U256; use ethers::contract::ContractCall; +use ethers::prelude::{Http, Provider, RetryClient}; use ethers::providers::PendingTransaction; use hex::ToHex; use shared_types::FlowRangeProof; @@ -24,7 +25,7 @@ pub struct Submitter { mine_answer_receiver: mpsc::UnboundedReceiver, mine_context_receiver: broadcast::Receiver, mine_contract: PoraMine, - flow_contract: ZgsFlow, + flow_contract: ZgsFlow>>, default_gas_limit: Option, store: Arc, } @@ -34,11 +35,12 @@ impl Submitter { executor: TaskExecutor, mine_answer_receiver: mpsc::UnboundedReceiver, mine_context_receiver: broadcast::Receiver, - provider: Arc, + provider: Arc>>, + signing_provider: Arc, store: Arc, config: &MinerConfig, ) { - let mine_contract = PoraMine::new(config.mine_address, provider.clone()); + let mine_contract = PoraMine::new(config.mine_address, signing_provider); let flow_contract = ZgsFlow::new(config.flow_address, provider); let default_gas_limit = config.submission_gas; diff --git a/node/miner/src/watcher.rs b/node/miner/src/watcher.rs index c4db8cb..dbfd66b 100644 --- a/node/miner/src/watcher.rs +++ b/node/miner/src/watcher.rs @@ -14,13 +14,13 @@ use tokio::{ try_join, }; +use crate::{config::MineServiceMiddleware, mine::PoraPuzzle, MinerConfig, MinerMessage}; +use ethers::prelude::{Http, RetryClient}; use std::pin::Pin; use std::sync::Arc; use std::time::Duration; use std::{ops::DerefMut, str::FromStr}; -use crate::{config::MineServiceMiddleware, mine::PoraPuzzle, MinerConfig, MinerMessage}; - pub type MineContextMessage = Option; lazy_static! { @@ -29,9 +29,9 @@ lazy_static! { } pub struct MineContextWatcher { - provider: Arc, - flow_contract: ZgsFlow, - mine_contract: PoraMine, + provider: Arc>>, + flow_contract: ZgsFlow>>, + mine_contract: PoraMine>>, mine_context_sender: broadcast::Sender, last_report: MineContextMessage, @@ -44,7 +44,7 @@ impl MineContextWatcher { pub fn spawn( executor: TaskExecutor, msg_recv: broadcast::Receiver, - provider: Arc, + provider: Arc>>, config: &MinerConfig, ) -> broadcast::Receiver { let mine_contract = PoraMine::new(config.mine_address, provider.clone());