mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-12-24 07:15:17 +00:00
Configurable mine submission gas limit (#41)
* Configurable mine submission gas limit * cargo fmt * More log * update * cargo clippy
This commit is contained in:
parent
4151375316
commit
163f843581
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4425,6 +4425,7 @@ dependencies = [
|
||||
"contract-interface",
|
||||
"ethereum-types 0.14.1",
|
||||
"ethers",
|
||||
"hex",
|
||||
"lazy_static",
|
||||
"network",
|
||||
"rand 0.8.5",
|
||||
|
@ -20,3 +20,4 @@ ethers = "^2"
|
||||
lazy_static = "1.4"
|
||||
async-trait = "0.1.56"
|
||||
shared_types = { path = "../shared_types" }
|
||||
hex = "0.4"
|
@ -1,4 +1,4 @@
|
||||
use ethereum_types::{Address, H256};
|
||||
use ethereum_types::{Address, H256, U256};
|
||||
use ethers::core::k256::SecretKey;
|
||||
use ethers::middleware::SignerMiddleware;
|
||||
use ethers::providers::Http;
|
||||
@ -13,6 +13,7 @@ pub struct MinerConfig {
|
||||
pub(crate) rpc_endpoint_url: String,
|
||||
pub(crate) mine_address: Address,
|
||||
pub(crate) flow_address: Address,
|
||||
pub(crate) submission_gas: Option<U256>,
|
||||
}
|
||||
|
||||
pub type MineServiceMiddleware = SignerMiddleware<Provider<Http>, LocalWallet>;
|
||||
@ -24,6 +25,7 @@ impl MinerConfig {
|
||||
rpc_endpoint_url: String,
|
||||
mine_address: Address,
|
||||
flow_address: Address,
|
||||
submission_gas: Option<U256>,
|
||||
) -> Option<MinerConfig> {
|
||||
match (miner_id, miner_key) {
|
||||
(Some(miner_id), Some(miner_key)) => Some(MinerConfig {
|
||||
@ -32,6 +34,7 @@ impl MinerConfig {
|
||||
rpc_endpoint_url,
|
||||
mine_address,
|
||||
flow_address,
|
||||
submission_gas,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
use contract_interface::PoraAnswer;
|
||||
use contract_interface::{PoraMine, ZgsFlow};
|
||||
use ethereum_types::U256;
|
||||
use ethers::contract::ContractCall;
|
||||
use ethers::providers::PendingTransaction;
|
||||
use hex::ToHex;
|
||||
use shared_types::FlowRangeProof;
|
||||
use std::sync::Arc;
|
||||
use storage::log_store::Store;
|
||||
@ -18,6 +21,7 @@ pub struct Submitter {
|
||||
mine_answer_receiver: mpsc::UnboundedReceiver<AnswerWithoutProof>,
|
||||
mine_contract: PoraMine<MineServiceMiddleware>,
|
||||
flow_contract: ZgsFlow<MineServiceMiddleware>,
|
||||
default_gas_limit: Option<U256>,
|
||||
store: Arc<RwLock<dyn Store>>,
|
||||
}
|
||||
|
||||
@ -31,12 +35,14 @@ impl Submitter {
|
||||
) {
|
||||
let mine_contract = PoraMine::new(config.mine_address, provider.clone());
|
||||
let flow_contract = ZgsFlow::new(config.flow_address, provider);
|
||||
let default_gas_limit = config.submission_gas;
|
||||
|
||||
let submitter = Submitter {
|
||||
mine_answer_receiver,
|
||||
mine_contract,
|
||||
flow_contract,
|
||||
store,
|
||||
default_gas_limit,
|
||||
};
|
||||
executor.spawn(
|
||||
async move { Box::pin(submitter.start()).await },
|
||||
@ -97,12 +103,35 @@ impl Submitter {
|
||||
};
|
||||
trace!("submit_answer: answer={:?}", answer);
|
||||
|
||||
let submission_call = self.mine_contract.submit(answer).legacy();
|
||||
let mut submission_call: ContractCall<_, _> = self.mine_contract.submit(answer).legacy();
|
||||
|
||||
if let Some(gas_limit) = self.default_gas_limit {
|
||||
submission_call = submission_call.gas(gas_limit);
|
||||
}
|
||||
|
||||
if let Some(calldata) = submission_call.calldata() {
|
||||
debug!(
|
||||
"Submission transaction calldata: {}",
|
||||
calldata.encode_hex::<String>()
|
||||
);
|
||||
}
|
||||
|
||||
debug!("Local construct tx: {:?}", &submission_call.tx);
|
||||
debug!(
|
||||
"Estimate gas result: {:?}",
|
||||
submission_call.estimate_gas().await
|
||||
);
|
||||
|
||||
let pending_transaction: PendingTransaction<'_, _> = submission_call
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("Fail to send mine answer transaction: {:?}", e))?;
|
||||
|
||||
debug!(
|
||||
"Signed submission transaction hash: {:?}",
|
||||
pending_transaction.tx_hash()
|
||||
);
|
||||
|
||||
let receipt = pending_transaction
|
||||
.retries(SUBMISSION_RETIES)
|
||||
.await
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![allow(clippy::field_reassign_with_default)]
|
||||
|
||||
use crate::ZgsConfig;
|
||||
use ethereum_types::H256;
|
||||
use ethereum_types::{H256, U256};
|
||||
use log_entry_sync::{CacheConfig, ContractAddress, LogSyncConfig};
|
||||
use miner::MinerConfig;
|
||||
use network::NetworkConfig;
|
||||
@ -139,12 +139,14 @@ impl ZgsConfig {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let submission_gas = self.miner_submission_gas.map(U256::from);
|
||||
Ok(MinerConfig::new(
|
||||
miner_id,
|
||||
miner_key,
|
||||
self.blockchain_rpc_endpoint.clone(),
|
||||
mine_address,
|
||||
flow_address,
|
||||
submission_gas,
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ build_config! {
|
||||
(mine_contract_address, (String), "".to_string())
|
||||
(miner_id, (Option<String>), None)
|
||||
(miner_key, (Option<String>), None)
|
||||
(miner_submission_gas, (Option<u64>), None)
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
|
Loading…
Reference in New Issue
Block a user