do not fail on prune error

This commit is contained in:
Peter Zhang 2024-08-24 20:54:43 +08:00
parent b5cb0e0d58
commit c4816c3ecf
2 changed files with 46 additions and 28 deletions

View File

@ -15,7 +15,7 @@ use storage::log_store::log_manager::PORA_CHUNK_SIZE;
use storage_async::Store;
use task_executor::TaskExecutor;
use tokio::sync::{broadcast, mpsc};
use tracing::{debug, info};
use tracing::{debug, error, info};
use zgs_spec::SECTORS_PER_PRICING;
// Start pruning when the db directory size exceeds 0.9 * limit.
@ -58,7 +58,7 @@ pub struct Pruner {
sender: mpsc::UnboundedSender<PrunerMessage>,
miner_sender: Option<broadcast::Sender<MinerMessage>>,
reward_contract: ChunkLinearReward<Arc<Provider<RetryClient<Http>>>>,
reward_contract: ChunkLinearReward<Provider<RetryClient<Http>>>,
}
impl Pruner {
@ -75,6 +75,8 @@ impl Pruner {
.await?
.unwrap_or((0, 0));
info!(config.rpc_endpoint_url, "pruner config rpc");
let provider = Arc::new(Provider::new(
RetryClientBuilder::default()
.rate_limit_retries(config.rate_limit_retries)
@ -85,7 +87,7 @@ impl Pruner {
Box::new(HttpRateLimitRetryPolicy),
),
));
let reward_contract = ChunkLinearReward::new(config.reward_address, Arc::new(provider));
let reward_contract = ChunkLinearReward::new(config.reward_address, provider);
let (tx, rx) = mpsc::unbounded_channel();
let pruner = Pruner {
config,
@ -116,30 +118,36 @@ impl Pruner {
}
// Check no reward chunks and prune.
let new_first_rewardable = self.reward_contract.first_rewardable_chunk().call().await?;
if let Some(no_reward_list) = self
.maybe_forward_first_rewardable(new_first_rewardable)
.await?
{
info!(
?new_first_rewardable,
"first rewardable chunk moves forward, start pruning"
);
self.prune_tx(
self.first_rewardable_chunk * SECTORS_PER_PRICING as u64,
new_first_rewardable * SECTORS_PER_PRICING as u64,
)
.await?;
self.prune_in_batch(no_reward_list).await?;
match self.reward_contract.first_rewardable_chunk().call().await {
Ok(new_first_rewardable) => {
if let Some(no_reward_list) = self
.maybe_forward_first_rewardable(new_first_rewardable)
.await?
{
info!(
?new_first_rewardable,
"first rewardable chunk moves forward, start pruning"
);
self.prune_tx(
self.first_rewardable_chunk * SECTORS_PER_PRICING as u64,
new_first_rewardable * SECTORS_PER_PRICING as u64,
)
.await?;
self.prune_in_batch(no_reward_list).await?;
self.first_rewardable_chunk = new_first_rewardable;
self.put_first_rewardable_chunk_index(
self.first_rewardable_chunk,
self.first_tx_seq,
)
.await?;
}
tokio::time::sleep(self.config.check_time).await;
self.first_rewardable_chunk = new_first_rewardable;
self.put_first_rewardable_chunk_index(
self.first_rewardable_chunk,
self.first_tx_seq,
)
.await?;
}
tokio::time::sleep(self.config.check_time).await;
}
e => {
error!("handle reward contract read fails, e={:?}", e);
}
};
}
}

View File

@ -3,6 +3,7 @@
use crate::ZgsConfig;
use ethereum_types::{H256, U256};
use ethers::prelude::{Http, Middleware, Provider};
use ethers::providers::{HttpRateLimitRetryPolicy, RetryClientBuilder};
use log_entry_sync::{CacheConfig, ContractAddress, LogSyncConfig};
use miner::MinerConfig;
use network::NetworkConfig;
@ -10,6 +11,7 @@ use pruner::PrunerConfig;
use rpc::RPCConfig;
use shared_types::NetworkIdentity;
use std::net::IpAddr;
use std::str::FromStr;
use std::time::Duration;
use storage::config::ShardConfig;
use storage::StorageConfig;
@ -31,8 +33,16 @@ impl ZgsConfig {
.log_contract_address
.parse::<ContractAddress>()
.map_err(|e| format!("Unable to parse log_contract_address: {:?}", e))?;
let provider = Provider::<Http>::try_from(&self.blockchain_rpc_endpoint)
.map_err(|e| format!("Can not parse blockchain endpoint: {:?}", e))?;
let provider = Provider::new(
RetryClientBuilder::default()
.rate_limit_retries(10)
.timeout_retries(10)
.initial_backoff(Duration::from_millis(1000))
.build(
Http::from_str(&self.blockchain_rpc_endpoint).unwrap(),
Box::new(HttpRateLimitRetryPolicy),
),
);
let chain_id = provider
.get_chainid()
.await