mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-22 19:49:33 +00:00
add method to init the hard fork struct at a certain height.
This commit is contained in:
parent
a56d8ea87f
commit
367ea1a837
2 changed files with 32 additions and 11 deletions
|
@ -7,14 +7,13 @@ use std::pin::Pin;
|
|||
use std::task::{Context, Poll};
|
||||
use tower::balance::p2c::Balance;
|
||||
use tower::discover::Change;
|
||||
use tower::util::{BoxService};
|
||||
use tower::util::BoxService;
|
||||
|
||||
use tracing::level_filters::LevelFilter;
|
||||
|
||||
use monero_consensus::hardforks::{HardForkConfig, HardForks};
|
||||
use monero_consensus::rpc::Rpc;
|
||||
|
||||
|
||||
struct RpcDiscoverer(Vec<String>, u64);
|
||||
|
||||
impl Stream for RpcDiscoverer {
|
||||
|
@ -80,7 +79,7 @@ async fn main() {
|
|||
let rpc_buffer = tower::buffer::Buffer::new(BoxService::new(rpc_balance), 3);
|
||||
let rpc = tower::retry::Retry::new(Attempts(3), rpc_buffer);
|
||||
|
||||
let _hfs = HardForks::init(HardForkConfig::default(), rpc.clone())
|
||||
let _hfs = HardForks::init_at_chain_height(HardForkConfig::default(), 1009827, rpc.clone())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -230,6 +230,27 @@ impl HardForks {
|
|||
panic!("Database sent incorrect response")
|
||||
};
|
||||
|
||||
let mut hfs =
|
||||
HardForks::init_at_chain_height(config, chain_height, database.clone()).await?;
|
||||
|
||||
// This is only needed if the database moves independently of the HardFork class aka if we are checking a node instead of keeping state ourself.
|
||||
hfs.resync(&mut database).await?;
|
||||
|
||||
hfs.check_set_new_hf();
|
||||
|
||||
tracing::info!("HardFork state: {:?}", hfs);
|
||||
|
||||
Ok(hfs)
|
||||
}
|
||||
|
||||
pub async fn init_at_chain_height<D: Database + Clone>(
|
||||
config: HardForkConfig,
|
||||
chain_height: u64,
|
||||
mut database: D,
|
||||
) -> Result<Self, Error>
|
||||
where
|
||||
D::Future: Send + 'static,
|
||||
{
|
||||
let block_heights = if chain_height > config.window {
|
||||
chain_height - config.window..chain_height
|
||||
} else {
|
||||
|
@ -257,8 +278,6 @@ impl HardForks {
|
|||
last_height: chain_height - 1,
|
||||
};
|
||||
|
||||
hfs.resync(&mut database).await?;
|
||||
|
||||
hfs.check_set_new_hf();
|
||||
|
||||
tracing::info!("HardFork state: {:?}", hfs);
|
||||
|
@ -285,7 +304,7 @@ impl HardForks {
|
|||
loop {
|
||||
while chain_height > self.last_height + 1 {
|
||||
self.get_and_account_new_block(self.last_height + 1, &mut database)
|
||||
.await;
|
||||
.await?;
|
||||
}
|
||||
|
||||
let DatabaseResponse::ChainHeight(c_h) = database
|
||||
|
@ -309,13 +328,16 @@ impl HardForks {
|
|||
}
|
||||
}
|
||||
|
||||
async fn get_and_account_new_block<D: Database>(&mut self, height: u64, mut database: D) {
|
||||
let header = get_block_header(&mut database, height)
|
||||
.await
|
||||
.expect("Error retrieving block we should have in database");
|
||||
async fn get_and_account_new_block<D: Database>(
|
||||
&mut self,
|
||||
height: u64,
|
||||
mut database: D,
|
||||
) -> Result<(), Error> {
|
||||
let header = get_block_header(&mut database, height).await?;
|
||||
|
||||
self.new_block(HardFork::from_vote(&header.minor_version), height, database)
|
||||
.await
|
||||
.await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn check_block_version_vote(&self, version: &HardFork, vote: &HardFork) -> bool {
|
||||
|
|
Loading…
Reference in a new issue