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

Method initialize

consensus/vbft/service.go:428–517  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

426}
427
428func (self *Server) initialize() error {
429 // TODO: load config from chain
430
431 // TODO: configurable log
432 selfNodeId := vconfig.PubkeyID(self.account.PublicKey)
433 log.Infof("server: %s starting", selfNodeId)
434
435 store, err := OpenBlockStore(self.ledger, self.pid)
436 if err != nil {
437 log.Errorf("failed to open block store: %s", err)
438 return fmt.Errorf("failed to open block store: %s", err)
439 }
440 self.chainStore = store
441 log.Info("block store opened")
442
443 self.blockPool, err = newBlockPool(self, self.msgHistoryDuration, store)
444 if err != nil {
445 log.Errorf("init blockpool: %s", err)
446 return fmt.Errorf("init blockpool: %s", err)
447 }
448 self.msgPool = newMsgPool(self, self.msgHistoryDuration)
449 self.peerPool = NewPeerPool(0, self) // FIXME: maxSize
450 self.timer = NewEventTimer(self)
451 self.syncer = newSyncer(self)
452
453 self.msgRecvC = make(map[uint32]chan *p2pMsgPayload)
454 self.msgC = make(chan ConsensusMsg, CAP_MESSAGE_CHANNEL)
455 self.bftActionC = make(chan *BftAction, CAP_ACTION_CHANNEL)
456 self.msgSendC = make(chan *SendMsgEvent, CAP_MSG_SEND_CHANNEL)
457
458 self.quitC = make(chan struct{})
459 if err := self.LoadChainConfig(store.GetChainedBlockNum()); err != nil {
460 log.Errorf("failed to load config: %s", err)
461 return fmt.Errorf("failed to load config: %s", err)
462 }
463 log.Infof("chain config loaded from local, current blockNum: %d", self.GetCurrentBlockNo())
464
465 // add all consensus peers to peer_pool
466 for _, p := range self.config.Peers {
467 // check if peer pubkey support VRF
468 if pk, err := vconfig.Pubkey(p.ID); err != nil {
469 return fmt.Errorf("failed to parse peer %d PeerID: %s", p.Index, err)
470 } else if !vrf.ValidatePublicKey(pk) {
471 return fmt.Errorf("peer %d: invalid peer pubkey for VRF", p.Index)
472 }
473
474 if err := self.peerPool.addPeer(p); err != nil {
475 return fmt.Errorf("failed to add peer %d: %s", p.Index, err)
476 }
477 log.Infof("added peer: %s", p.ID)
478 }
479
480 //index equal math.MaxUint32 is noconsensus node
481 id := vconfig.PubkeyID(self.account.PublicKey)
482 index, present := self.peerPool.GetPeerIndex(id)
483 if present {
484 self.Index = index
485 } else {

Callers 1

NewVbftServerFunction · 0.95

Calls 15

LoadChainConfigMethod · 0.95
GetCurrentBlockNoMethod · 0.95
msgSendLoopMethod · 0.95
timerLoopMethod · 0.95
actionLoopMethod · 0.95
processMsgEventMethod · 0.95
InfofFunction · 0.92
ErrorfFunction · 0.92
InfoFunction · 0.92
OpenBlockStoreFunction · 0.85
newBlockPoolFunction · 0.85
newMsgPoolFunction · 0.85

Tested by

no test coverage detected