From 606795b5a27af9299764f1b42595d52bde76a132 Mon Sep 17 00:00:00 2001 From: Goshawk Date: Fri, 6 Sep 2024 14:47:07 +0300 Subject: [PATCH] node: Return genesis when it's the only finalized state --- node/src/chain/acceptor.rs | 9 ++++++--- node/src/chain/fsm.rs | 1 - node/src/chain/stall_chain_fsm.rs | 7 +------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/node/src/chain/acceptor.rs b/node/src/chain/acceptor.rs index 1c5fc4ea9d..f60e1e6742 100644 --- a/node/src/chain/acceptor.rs +++ b/node/src/chain/acceptor.rs @@ -821,7 +821,7 @@ impl Acceptor { // The blockchain tip after reverting let (blk, (_, label)) = self.db.read().await.update(|t| { let mut height = curr_height; - while height != 0 { + loop { let b = Ledger::fetch_block_by_height(t, height)? .ok_or_else(|| anyhow::anyhow!("could not fetch block"))?; let h = b.header(); @@ -830,6 +830,11 @@ impl Acceptor { || anyhow::anyhow!("could not fetch block label"), )?; + // If we are at genesis block, we can stop here + if b.header().height == 0 { + return Ok((b, label)); + } + if h.state_hash == target_state_hash { return Ok((b, label)); } @@ -858,8 +863,6 @@ impl Acceptor { height -= 1; } - - Err(anyhow!("not found")) })?; if blk.header().state_hash != target_state_hash { diff --git a/node/src/chain/fsm.rs b/node/src/chain/fsm.rs index b10b904a4a..036db72a56 100644 --- a/node/src/chain/fsm.rs +++ b/node/src/chain/fsm.rs @@ -34,7 +34,6 @@ const DEFAULT_ATT_CACHE_EXPIRY: Duration = Duration::from_secs(60); /// Maximum number of hops between the requester and the node that contains the /// requested resource const DEFAULT_HOPS_LIMIT: u16 = 16; -pub(crate) const REDUNDANCY_PEER_FACTOR: usize = 5; type SharedHashSet = Arc>>; diff --git a/node/src/chain/stall_chain_fsm.rs b/node/src/chain/stall_chain_fsm.rs index 95e06c71fc..7d910a3688 100644 --- a/node/src/chain/stall_chain_fsm.rs +++ b/node/src/chain/stall_chain_fsm.rs @@ -6,10 +6,7 @@ use node_data::{ ledger::{to_str, Block}, - message::{ - payload::{GetBlocks, Inv}, - Message, - }, + message::payload::Inv, }; use std::{ collections::BTreeMap, @@ -27,8 +24,6 @@ use crate::{ use super::acceptor::Acceptor; -use super::fsm::REDUNDANCY_PEER_FACTOR; - const STALLED_TIMEOUT: u64 = 60; // seconds #[derive(Debug, Clone, Copy, PartialEq)]