mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
Initialize sumtree if genesis isn't empty
This commit is contained in:
parent
9fa344383c
commit
07df881a72
1 changed files with 14 additions and 13 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue