pull/839/head
Eugene Kim 6 years ago
parent 539ac01635
commit 3c1e7ce5b3
  1. 20
      internal/shardchain/shardchains.go
  2. 5
      node/node_genesis.go

@ -29,7 +29,9 @@ type Collection interface {
Close() error
}
type collection struct {
// CollectionImpl is the main implementation of the shard chain collection.
// See the Collection interface for details.
type CollectionImpl struct {
dbFactory DBFactory
dbInit DBInitializer
engine engine.Engine
@ -37,10 +39,16 @@ type collection struct {
pool map[uint32]*core.BlockChain
}
// NewCollection creates and returns a new shard chain collection.
//
// dbFactory is the shard chain database factory to use.
//
// dbInit is the shard chain initializer to use when the database returned by
// the factory is brand new (empty).
func NewCollection(
dbFactory DBFactory, dbInit DBInitializer, engine engine.Engine,
) *collection {
return &collection{
) *CollectionImpl {
return &CollectionImpl{
dbFactory: dbFactory,
dbInit: dbInit,
engine: engine,
@ -50,7 +58,7 @@ func NewCollection(
// ShardChain returns the blockchain for the given shard,
// opening one as necessary.
func (sc *collection) ShardChain(shardID uint32) (*core.BlockChain, error) {
func (sc *CollectionImpl) ShardChain(shardID uint32) (*core.BlockChain, error) {
sc.mtx.Lock()
defer sc.mtx.Unlock()
if bc, ok := sc.pool[shardID]; ok {
@ -96,7 +104,7 @@ func (sc *collection) ShardChain(shardID uint32) (*core.BlockChain, error) {
}
// CloseShardChain closes the given shard chain.
func (sc *collection) CloseShardChain(shardID uint32) error {
func (sc *CollectionImpl) CloseShardChain(shardID uint32) error {
sc.mtx.Lock()
defer sc.mtx.Unlock()
bc, ok := sc.pool[shardID]
@ -112,7 +120,7 @@ func (sc *collection) CloseShardChain(shardID uint32) error {
}
// Close closes all shard chains.
func (sc *collection) Close() error {
func (sc *CollectionImpl) Close() error {
newPool := make(map[uint32]*core.BlockChain)
sc.mtx.Lock()
oldPool := sc.pool

@ -41,9 +41,8 @@ func (gi *genesisInitializer) InitChainDB(db ethdb.Database, shardID uint32) err
// store only the local shard
if c := shardState.FindCommitteeByID(shardID); c == nil {
return errors.New("cannot find local shard in genesis")
} else {
shardState = types.ShardState{*c}
}
shardState = types.ShardState{*c}
}
if err := rawdb.WriteShardState(db, common.Big0, shardState); err != nil {
return ctxerror.New("cannot store epoch shard state").WithCause(err)
@ -54,7 +53,7 @@ func (gi *genesisInitializer) InitChainDB(db ethdb.Database, shardID uint32) err
return nil
}
// GenesisBlockSetup setups a genesis blockchain.
// SetupGenesisBlock sets up a genesis blockchain.
func (node *Node) SetupGenesisBlock(db ethdb.Database, shardID uint32) error {
utils.GetLogger().Info("setting up a brand new chain database",
"shardID", shardID)

Loading…
Cancel
Save