Skip to content

Commit

Permalink
node: Return genesis when it's the only finalized state
Browse files Browse the repository at this point in the history
  • Loading branch information
Goshawk committed Sep 6, 2024
1 parent eccb4e3 commit 606795b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
9 changes: 6 additions & 3 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
// 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();
Expand All @@ -830,6 +830,11 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
|| 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));
}
Expand Down Expand Up @@ -858,8 +863,6 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {

height -= 1;
}

Err(anyhow!("not found"))
})?;

if blk.header().state_hash != target_state_hash {
Expand Down
1 change: 0 additions & 1 deletion node/src/chain/fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<HashSet<[u8; 32]>>>;

Expand Down
7 changes: 1 addition & 6 deletions node/src/chain/stall_chain_fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

use node_data::{
ledger::{to_str, Block},
message::{
payload::{GetBlocks, Inv},
Message,
},
message::payload::Inv,
};
use std::{
collections::BTreeMap,
Expand All @@ -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)]
Expand Down

0 comments on commit 606795b

Please sign in to comment.