From 09555acfa6e92395bcda7f91291dbdc6af51239f Mon Sep 17 00:00:00 2001 From: Carl Date: Tue, 23 Jun 2020 01:10:00 -0700 Subject: [PATCH] Add blockstore generation from trees --- Cargo.lock | 1 + ledger/Cargo.toml | 1 + ledger/src/blockstore.rs | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6d6c5da087ee8a..62bb297442897a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4199,6 +4199,7 @@ dependencies = [ "solana-vote-program", "tempfile", "thiserror", + "trees", ] [[package]] diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index ecc83e175edcfb..a1ac7ec0797383 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -43,6 +43,7 @@ solana-stake-program = { path = "../programs/stake", version = "1.3.0" } solana-vote-program = { path = "../programs/vote", version = "1.3.0" } tempfile = "3.1.0" thiserror = "1.0" +trees = "0.2.1" [dependencies.rocksdb] # Avoid the vendored bzip2 within rocksdb-sys that can cause linker conflicts diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index d703a4efb547f4..e380cbbc2a3c02 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -55,6 +55,7 @@ use std::{ }, time::Duration, }; +use trees::{Tree, TreeWalk}; pub mod blockstore_purge; @@ -303,6 +304,23 @@ impl Blockstore { Ok((blockstore, signal_receiver, completed_slots_receiver)) } + pub fn add_tree(&self, forks: Tree, is_orphan: bool) { + let mut walk = TreeWalk::from(forks); + while let Some(visit) = walk.get() { + let slot = visit.node().data; + if self.meta(slot).unwrap().is_some() { + walk.forward(); + continue; + } + let parent = walk.get_parent().map(|n| n.data); + if parent.is_some() || !is_orphan { + let (shreds, _) = make_slot_entries(slot, parent.unwrap_or(slot), 1); + self.insert_shreds(shreds, None, false).unwrap(); + } + walk.forward(); + } + } + pub fn set_no_compaction(&mut self, no_compaction: bool) { self.no_compaction = no_compaction; }