MCPcopy Create free account
hub / github.com/DNAProject/DNA / OpenBlockStore

Function OpenBlockStore

consensus/vbft/chain_store.go:48–68  ·  view source on GitHub ↗
(db *ledger.Ledger, serverPid *actor.PID)

Source from the content-addressed store, hash-verified

46}
47
48func OpenBlockStore(db *ledger.Ledger, serverPid *actor.PID) (*ChainStore, error) {
49 chainstore := &ChainStore{
50 db: db,
51 chainedBlockNum: db.GetCurrentBlockHeight(),
52 pendingBlocks: make(map[uint32]*PendingBlock),
53 pid: serverPid,
54 }
55 merkleRoot, err := db.GetStateMerkleRoot(chainstore.chainedBlockNum)
56 if err != nil {
57 log.Errorf("GetStateMerkleRoot blockNum:%d, error :%s", chainstore.chainedBlockNum, err)
58 return nil, fmt.Errorf("GetStateMerkleRoot blockNum:%d, error :%s", chainstore.chainedBlockNum, err)
59 }
60 writeSet := overlaydb.NewMemDB(1, 1)
61 block, err := chainstore.getBlock(chainstore.chainedBlockNum)
62 if err != nil {
63 return nil, err
64 }
65 log.Debugf("chainstore openblockstore pendingBlocks height:%d,", chainstore.chainedBlockNum)
66 chainstore.pendingBlocks[chainstore.chainedBlockNum] = &PendingBlock{block: block, execResult: &store.ExecuteResult{WriteSet: writeSet, MerkleRoot: merkleRoot}, hasSubmitted: true}
67 return chainstore, nil
68}
69
70func (self *ChainStore) close() {
71 // TODO: any action on ledger actor??

Callers 2

initializeMethod · 0.85
newTestChainStoreFunction · 0.85

Calls 7

getBlockMethod · 0.95
ErrorfFunction · 0.92
NewMemDBFunction · 0.92
DebugfFunction · 0.92
ErrorfMethod · 0.80
GetCurrentBlockHeightMethod · 0.65
GetStateMerkleRootMethod · 0.65

Tested by 1

newTestChainStoreFunction · 0.68