mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-01-24 05:55:17 +00:00
ef82f64393
* Implement Pruner. * Put pruner in a crate. * Fix clippy. * Add rpc zgs_getShardConfig. * Fix. * Increase wait time. * Add pruner_test and use max_num_chunks instead of size_limit. * Add back shard config and fix test. * fix: serde format * Remove unneeded PORA_CHUNK_SIZE. * Fix tests. --------- Co-authored-by: MiniFrenchBread <103425574+MiniFrenchBread@users.noreply.github.com>
65 lines
2.1 KiB
Rust
65 lines
2.1 KiB
Rust
use ethereum_types::{Address, H256, U256};
|
|
use ethers::core::k256::SecretKey;
|
|
use ethers::middleware::SignerMiddleware;
|
|
use ethers::providers::Http;
|
|
use ethers::providers::Middleware;
|
|
use ethers::providers::Provider;
|
|
use ethers::signers::LocalWallet;
|
|
use ethers::signers::Signer;
|
|
use storage::config::ShardConfig;
|
|
|
|
pub struct MinerConfig {
|
|
pub(crate) miner_id: Option<H256>,
|
|
pub(crate) miner_key: H256,
|
|
pub(crate) rpc_endpoint_url: String,
|
|
pub(crate) mine_address: Address,
|
|
pub(crate) flow_address: Address,
|
|
pub(crate) submission_gas: Option<U256>,
|
|
pub(crate) cpu_percentage: u64,
|
|
pub(crate) iter_batch: usize,
|
|
pub(crate) shard_config: ShardConfig,
|
|
}
|
|
|
|
pub type MineServiceMiddleware = SignerMiddleware<Provider<Http>, LocalWallet>;
|
|
|
|
impl MinerConfig {
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub fn new(
|
|
miner_id: Option<H256>,
|
|
miner_key: Option<H256>,
|
|
rpc_endpoint_url: String,
|
|
mine_address: Address,
|
|
flow_address: Address,
|
|
submission_gas: Option<U256>,
|
|
cpu_percentage: u64,
|
|
iter_batch: usize,
|
|
shard_config: ShardConfig,
|
|
) -> Option<MinerConfig> {
|
|
miner_key.map(|miner_key| MinerConfig {
|
|
miner_id,
|
|
miner_key,
|
|
rpc_endpoint_url,
|
|
mine_address,
|
|
flow_address,
|
|
submission_gas,
|
|
cpu_percentage,
|
|
iter_batch,
|
|
shard_config,
|
|
})
|
|
}
|
|
|
|
pub(crate) async fn make_provider(&self) -> Result<MineServiceMiddleware, String> {
|
|
let provider = Provider::<Http>::try_from(&self.rpc_endpoint_url)
|
|
.map_err(|e| format!("Can not parse blockchain endpoint: {:?}", e))?;
|
|
let chain_id = provider
|
|
.get_chainid()
|
|
.await
|
|
.map_err(|e| format!("Unable to get chain_id: {:?}", e))?;
|
|
let secret_key = SecretKey::from_bytes(self.miner_key.as_ref().into())
|
|
.map_err(|e| format!("Cannot parse private key: {:?}", e))?;
|
|
let signer = LocalWallet::from(secret_key).with_chain_id(chain_id.as_u64());
|
|
let middleware = SignerMiddleware::new(provider, signer);
|
|
Ok(middleware)
|
|
}
|
|
}
|