|
|
@ -243,13 +243,13 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, db ethdb.Database, is |
|
|
|
database := db |
|
|
|
database := db |
|
|
|
if database == nil { |
|
|
|
if database == nil { |
|
|
|
database = ethdb.NewMemDatabase() |
|
|
|
database = ethdb.NewMemDatabase() |
|
|
|
chain, err = node.GenesisBlockSetup(database, false) |
|
|
|
chain, err = node.GenesisBlockSetup(database, consensusObj.ShardID, false) |
|
|
|
isFirstTime = true |
|
|
|
isFirstTime = true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
chain, err = node.InitBlockChainFromDB(db, node.Consensus, isArchival) |
|
|
|
chain, err = node.InitBlockChainFromDB(db, node.Consensus, isArchival) |
|
|
|
isFirstTime = false |
|
|
|
isFirstTime = false |
|
|
|
if err != nil || chain == nil || chain.CurrentBlock().NumberU64() <= 0 { |
|
|
|
if err != nil || chain == nil || chain.CurrentBlock().NumberU64() <= 0 { |
|
|
|
chain, err = node.GenesisBlockSetup(database, isArchival) |
|
|
|
chain, err = node.GenesisBlockSetup(database, consensusObj.ShardID, isArchival) |
|
|
|
isFirstTime = true |
|
|
|
isFirstTime = true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -267,6 +267,8 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, db ethdb.Database, is |
|
|
|
|
|
|
|
|
|
|
|
node.Consensus.VerifiedNewBlock = make(chan *types.Block) |
|
|
|
node.Consensus.VerifiedNewBlock = make(chan *types.Block) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if node.Consensus.ShardID == 0 { |
|
|
|
|
|
|
|
// Contracts only exist in beacon chain
|
|
|
|
if isFirstTime { |
|
|
|
if isFirstTime { |
|
|
|
// Setup one time smart contracts
|
|
|
|
// Setup one time smart contracts
|
|
|
|
node.AddFaucetContractToPendingTransactions() |
|
|
|
node.AddFaucetContractToPendingTransactions() |
|
|
@ -278,7 +280,7 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, db ethdb.Database, is |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
node.AddContractKeyAndAddress() |
|
|
|
node.AddContractKeyAndAddress() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
node.ContractCaller = contracts.NewContractCaller(&db, node.blockchain, params.TestChainConfig) |
|
|
|
node.ContractCaller = contracts.NewContractCaller(&db, node.blockchain, params.TestChainConfig) |
|
|
@ -315,7 +317,14 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, db ethdb.Database, is |
|
|
|
// InitGenesisShardState initialize genesis shard state and update committee pub keys for consensus and drand
|
|
|
|
// InitGenesisShardState initialize genesis shard state and update committee pub keys for consensus and drand
|
|
|
|
func (node *Node) InitGenesisShardState() { |
|
|
|
func (node *Node) InitGenesisShardState() { |
|
|
|
// Store the genesis shard state into db.
|
|
|
|
// Store the genesis shard state into db.
|
|
|
|
shardState := node.blockchain.StoreNewShardState(node.blockchain.CurrentBlock(), nil) |
|
|
|
shardState := types.ShardState{} |
|
|
|
|
|
|
|
if node.Consensus != nil { |
|
|
|
|
|
|
|
if node.Consensus.ShardID == 0 { |
|
|
|
|
|
|
|
shardState = node.blockchain.StoreNewShardState(node.blockchain.CurrentBlock(), nil) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
shardState = node.beaconChain.StoreNewShardState(node.beaconChain.CurrentBlock(), nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// Update validator public keys
|
|
|
|
// Update validator public keys
|
|
|
|
for _, shard := range shardState { |
|
|
|
for _, shard := range shardState { |
|
|
|
if shard.ShardID == node.Consensus.ShardID { |
|
|
|
if shard.ShardID == node.Consensus.ShardID { |
|
|
@ -428,7 +437,7 @@ func (node *Node) AddBeaconChainDatabase(db ethdb.Database) { |
|
|
|
database = ethdb.NewMemDatabase() |
|
|
|
database = ethdb.NewMemDatabase() |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO (chao) currently we use the same genesis block as normal shard
|
|
|
|
// TODO (chao) currently we use the same genesis block as normal shard
|
|
|
|
chain, err := node.GenesisBlockSetup(database, false) |
|
|
|
chain, err := node.GenesisBlockSetup(database, 0, false) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
utils.GetLogInstance().Error("Error when doing genesis setup") |
|
|
|
utils.GetLogInstance().Error("Error when doing genesis setup") |
|
|
|
os.Exit(1) |
|
|
|
os.Exit(1) |
|
|
|