Initiate the Nodes
Each function module needs to be initialized in turn when the nodes are started. Ordinary nodes and DPoS nodes can be configured through configuration files. The initialization sequence of main function modules at startup is as follows:
  1. 1.
    Initialize the trading pits and block pits.
1
txMemPool := mempool.NewTxPool(st.Params())
2
blockMemPool := mempool.NewBlockPool(st.Params())
Copied!
2. Initialize the Committee, which is mainly used to maintain the related affairs of CR members.
1
committee := crstate.NewCommittee(st.Params())
Copied!
3. Initialize Arbitrators, which is mainly used to handle DPoS consensus-related affairs.
1
arbiters, err := state.NewArbitrators(st.Params(), committee,
2
func(programHash common.Uint168) (common.Fixed64,
3
error) {
4
amount := common.Fixed64(0)
5
utxos, err := blockchain.DefaultLedger.Store.
6
GetFFLDB().GetUTXO(&programHash)
7
if err != nil {
8
return amount, err
9
}
10
for _, utxo := range utxos {
11
amount += utxo.Value
12
}
13
return amount, nil
14
},
15
committee.TryUpdateCRMemberInactivity,
16
committee.TryRevertCRMemberInactivity,
17
committee.TryUpdateCRMemberIllegal,
18
committee.TryRevertCRMemberIllegal)
19
if err != nil {
20
printErrorAndExit(err)
21
}
Copied!
4. Initialize blockchain, which is mainly used to handle block-related affairs.
1
chain, err := blockchain.New(chainStore, st.Params(), arbiters.State, committee)
2
if err != nil {
3
printErrorAndExit(err)
4
}
5
if err := chain.Init(interrupt.C); err != nil {
6
printErrorAndExit(err)
7
}
8
if err := chain.MigrateOldDB(interrupt.C, pgBar.Start,
9
pgBar.Increase, dataDir, st.Params()); err != nil {
10
printErrorAndExit(err)
11
}
12
pgBar.Stop()
Copied!
5. Initialize P2P network services.
1
netServer, err := elanet.NewServer(dataDir, &elanet.Config{
2
Chain: chain,
3
ChainParams: st.Params(),
4
PermanentPeers: st.Params().PermanentPeers,
5
TxMemPool: txMemPool,
6
BlockMemPool: blockMemPool,
7
Routes: route,
8
}, nodePrefix+Version)
9
if err != nil {
10
printErrorAndExit(err)
11
}
Copied!
6. Initialize the PoW module, which is used to process the related affairs of PoW block.
1
servers.Pow = pow.NewService(&pow.Config{
2
PayToAddr: st.Config().PowConfiguration.PayToAddr,
3
MinerInfo: st.Config().PowConfiguration.MinerInfo,
4
Chain: chain,
5
ChainParams: st.Params(),
6
TxMemPool: txMemPool,
7
BlkMemPool: blockMemPool,
8
BroadcastBlock: func(block *types.Block) {
9
hash := block.Hash()
10
netServer.RelayInventory(msg.NewInvVect(msg.InvTypeBlock, &hash), block)
11
},
12
Arbitrators: arbiters,
13
})
Copied!
7. Initialize CheckPoint, which is used for quickly initiating the nodes.
1
// initialize producer state after arbiters has initialized.
2
if err = chain.InitCheckpoint(interrupt.C, pgBar.Start,
3
pgBar.Increase); err != nil {
4
printErrorAndExit(err)
5
}
6
pgBar.Stop()
Copied!
8. Open services such as RPC, Resutful, and Websocket.
1
log.Info("Start services")
2
if st.Config().EnableRPC {
3
go httpjsonrpc.StartRPCServer()
4
}
5
if st.Config().HttpRestStart {
6
go httprestful.StartServer()
7
}
8
if st.Config().HttpWsStart {
9
go httpwebsocket.Start()
10
}
11
if st.Config().HttpInfoStart {
12
go httpnodeinfo.StartServer()
13
}
Copied!
After each functional module is initiated, the ELA nodes can start to establish P2P connection with other network nodes and access to the ELA network.
Copy link