Initialize sumtree if genesis isn't empty

This commit is contained in:
Ignotus Peverell 2018-03-01 03:08:35 +00:00
parent 9fa344383c
commit 07df881a72
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211

View file

@ -151,16 +151,24 @@ impl Chain {
) -> Result<Chain, Error> { ) -> Result<Chain, Error> {
let chain_store = store::ChainKVStore::new(db_root.clone())?; let chain_store = store::ChainKVStore::new(db_root.clone())?;
let store = Arc::new(chain_store);
let mut sumtrees = sumtree::SumTrees::open(db_root.clone(), store.clone())?;
// check if we have a head in store, otherwise the genesis block is it // check if we have a head in store, otherwise the genesis block is it
let head = match chain_store.head() { let head = match store.head() {
Ok(tip) => tip, Ok(tip) => tip,
Err(NotFoundErr) => { Err(NotFoundErr) => {
let tip = Tip::new(genesis.hash()); let tip = Tip::new(genesis.hash());
chain_store.save_block(&genesis)?; store.save_block(&genesis)?;
chain_store.setup_height(&genesis.header, &tip)?; store.setup_height(&genesis.header, &tip)?;
if genesis.kernels.len() > 0 {
sumtree::extending(&mut sumtrees, |extension| {
extension.apply_block(&genesis)
})?;
}
// saving a new tip based on genesis // saving a new tip based on genesis
chain_store.save_head(&tip)?; store.save_head(&tip)?;
info!( info!(
LOGGER, LOGGER,
"Saved genesis block: {:?}, nonce: {:?}, pow: {:?}", "Saved genesis block: {:?}, nonce: {:?}, pow: {:?}",
@ -175,16 +183,9 @@ impl Chain {
// Reset sync_head and header_head to head of current chain. // Reset sync_head and header_head to head of current chain.
// Make sure sync_head is available for later use when needed. // Make sure sync_head is available for later use when needed.
chain_store.reset_head()?; store.reset_head()?;
info!( debug!(LOGGER, "Chain init: {:?}", head);
LOGGER,
"Chain init: {:?}",
head,
);
let store = Arc::new(chain_store);
let sumtrees = sumtree::SumTrees::open(db_root.clone(), store.clone())?;
Ok(Chain { Ok(Chain {
db_root: db_root, db_root: db_root,