Add more comments on public functions and extra logging during 'enterPrevote'

Signed-off-by: Adrian Brink <adrian@brink-holdings.com>
This commit is contained in:
Adrian Brink 2017-07-09 20:35:48 +02:00
parent eed3959749
commit b07d01f102
4 changed files with 23 additions and 19 deletions

View File

@ -60,6 +60,7 @@ func (conR *ConsensusReactor) OnStart() error {
return nil return nil
} }
// OnStop implements BaseService
func (conR *ConsensusReactor) OnStop() { func (conR *ConsensusReactor) OnStop() {
conR.BaseReactor.OnStop() conR.BaseReactor.OnStop()
conR.conS.Stop() conR.conS.Stop()
@ -77,7 +78,7 @@ func (conR *ConsensusReactor) SwitchToConsensus(state *sm.State) {
conR.conS.Start() conR.conS.Start()
} }
// Implements Reactor // GetChannels implements Reactor
func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor { func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor {
// TODO optimize // TODO optimize
return []*p2p.ChannelDescriptor{ return []*p2p.ChannelDescriptor{
@ -107,7 +108,7 @@ func (conR *ConsensusReactor) GetChannels() []*p2p.ChannelDescriptor {
} }
} }
// Implements Reactor // ConsensusReactor implements Reactor
func (conR *ConsensusReactor) AddPeer(peer *p2p.Peer) { func (conR *ConsensusReactor) AddPeer(peer *p2p.Peer) {
if !conR.IsRunning() { if !conR.IsRunning() {
return return
@ -129,7 +130,7 @@ func (conR *ConsensusReactor) AddPeer(peer *p2p.Peer) {
} }
} }
// Implements Reactor // RemovePeer implements Reactor
func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) { func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) {
if !conR.IsRunning() { if !conR.IsRunning() {
return return
@ -138,7 +139,7 @@ func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) {
//peer.Data.Get(PeerStateKey).(*PeerState).Disconnect() //peer.Data.Get(PeerStateKey).(*PeerState).Disconnect()
} }
// Implements Reactor // Receive implements Reactor
// NOTE: We process these messages even when we're fast_syncing. // NOTE: We process these messages even when we're fast_syncing.
// Messages affect either a peer state or the consensus state. // Messages affect either a peer state or the consensus state.
// Peer state updates can happen in parallel, but processing of // Peer state updates can happen in parallel, but processing of

View File

@ -939,6 +939,7 @@ func (cs *ConsensusState) defaultDoPrevote(height int, round int) {
// Prevote cs.ProposalBlock // Prevote cs.ProposalBlock
// NOTE: the proposal signature is validated when it is received, // NOTE: the proposal signature is validated when it is received,
// and the proposal block parts are validated as they are received (against the merkle hash in the proposal) // and the proposal block parts are validated as they are received (against the merkle hash in the proposal)
logger.Info("enterPrevote: ProposalBlock is valid and voted on")
cs.signAddVote(types.VoteTypePrevote, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header()) cs.signAddVote(types.VoteTypePrevote, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header())
} }

View File

@ -148,6 +148,7 @@ func NewMConnectionWithConfig(conn net.Conn, chDescs []*ChannelDescriptor, onRec
return mconn return mconn
} }
// OnStart implements BaseService
func (c *MConnection) OnStart() error { func (c *MConnection) OnStart() error {
c.BaseService.OnStart() c.BaseService.OnStart()
c.quit = make(chan struct{}) c.quit = make(chan struct{})
@ -159,6 +160,7 @@ func (c *MConnection) OnStart() error {
return nil return nil
} }
// OnStop implements BaseService
func (c *MConnection) OnStop() { func (c *MConnection) OnStop() {
c.BaseService.OnStop() c.BaseService.OnStop()
c.flushTimer.Stop() c.flushTimer.Stop()

View File

@ -95,7 +95,7 @@ func NewSwitch(config *cfg.P2PConfig) *Switch {
return sw return sw
} }
// Not goroutine safe. // AddReactor is not goroutine safe.
func (sw *Switch) AddReactor(name string, reactor Reactor) Reactor { func (sw *Switch) AddReactor(name string, reactor Reactor) Reactor {
// Validate the reactor. // Validate the reactor.
// No two reactors can share the same channel. // No two reactors can share the same channel.
@ -113,42 +113,42 @@ func (sw *Switch) AddReactor(name string, reactor Reactor) Reactor {
return reactor return reactor
} }
// Not goroutine safe. // Reactors is not goroutine safe.
func (sw *Switch) Reactors() map[string]Reactor { func (sw *Switch) Reactors() map[string]Reactor {
return sw.reactors return sw.reactors
} }
// Not goroutine safe. // Reactor is not goroutine safe.
func (sw *Switch) Reactor(name string) Reactor { func (sw *Switch) Reactor(name string) Reactor {
return sw.reactors[name] return sw.reactors[name]
} }
// Not goroutine safe. // AddListener is not goroutine safe.
func (sw *Switch) AddListener(l Listener) { func (sw *Switch) AddListener(l Listener) {
sw.listeners = append(sw.listeners, l) sw.listeners = append(sw.listeners, l)
} }
// Not goroutine safe. // Listeners is not goroutine safe.
func (sw *Switch) Listeners() []Listener { func (sw *Switch) Listeners() []Listener {
return sw.listeners return sw.listeners
} }
// Not goroutine safe. // IsListening is not goroutine safe.
func (sw *Switch) IsListening() bool { func (sw *Switch) IsListening() bool {
return len(sw.listeners) > 0 return len(sw.listeners) > 0
} }
// Not goroutine safe. // SetNodeInfo is not goroutine safe.
func (sw *Switch) SetNodeInfo(nodeInfo *NodeInfo) { func (sw *Switch) SetNodeInfo(nodeInfo *NodeInfo) {
sw.nodeInfo = nodeInfo sw.nodeInfo = nodeInfo
} }
// Not goroutine safe. // NodeInfo is not goroutine safe.
func (sw *Switch) NodeInfo() *NodeInfo { func (sw *Switch) NodeInfo() *NodeInfo {
return sw.nodeInfo return sw.nodeInfo
} }
// Not goroutine safe. // SetNodePrivKey is not goroutine safe.
// NOTE: Overwrites sw.nodeInfo.PubKey // NOTE: Overwrites sw.nodeInfo.PubKey
func (sw *Switch) SetNodePrivKey(nodePrivKey crypto.PrivKeyEd25519) { func (sw *Switch) SetNodePrivKey(nodePrivKey crypto.PrivKeyEd25519) {
sw.nodePrivKey = nodePrivKey sw.nodePrivKey = nodePrivKey
@ -273,7 +273,7 @@ func (sw *Switch) startInitPeer(peer *Peer) {
} }
} }
// Dial a list of seeds asynchronously in random order // DialSeeds dials a list of seeds asynchronously in random order
func (sw *Switch) DialSeeds(addrBook *AddrBook, seeds []string) error { func (sw *Switch) DialSeeds(addrBook *AddrBook, seeds []string) error {
netAddrs, err := NewNetAddressStrings(seeds) netAddrs, err := NewNetAddressStrings(seeds)
@ -360,7 +360,7 @@ func (sw *Switch) Broadcast(chID byte, msg interface{}) chan bool {
return successChan return successChan
} }
// Returns the count of outbound/inbound and outbound-dialing peers. // NumPeers returns the count of outbound/inbound and outbound-dialing peers.
func (sw *Switch) NumPeers() (outbound, inbound, dialing int) { func (sw *Switch) NumPeers() (outbound, inbound, dialing int) {
peers := sw.peers.List() peers := sw.peers.List()
for _, peer := range peers { for _, peer := range peers {
@ -378,7 +378,7 @@ func (sw *Switch) Peers() IPeerSet {
return sw.peers return sw.peers
} }
// Disconnect from a peer due to external error, retry if it is a persistent peer. // StopPeerForError disconnect from a peer due to external error, retry if it is a persistent peer.
// TODO: make record depending on reason. // TODO: make record depending on reason.
func (sw *Switch) StopPeerForError(peer *Peer, reason interface{}) { func (sw *Switch) StopPeerForError(peer *Peer, reason interface{}) {
addr := NewNetAddress(peer.Addr()) addr := NewNetAddress(peer.Addr())
@ -411,7 +411,7 @@ func (sw *Switch) StopPeerForError(peer *Peer, reason interface{}) {
} }
} }
// Disconnect from a peer gracefully. // StopPeerGracefully disconnect from a peer gracefully.
// TODO: handle graceful disconnects. // TODO: handle graceful disconnects.
func (sw *Switch) StopPeerGracefully(peer *Peer) { func (sw *Switch) StopPeerGracefully(peer *Peer) {
sw.Logger.Info("Stopping peer gracefully") sw.Logger.Info("Stopping peer gracefully")
@ -469,7 +469,7 @@ type SwitchEventDonePeer struct {
//------------------------------------------------------------------ //------------------------------------------------------------------
// Switches connected via arbitrary net.Conn; useful for testing // Switches connected via arbitrary net.Conn; useful for testing
// Returns n switches, connected according to the connect func. // MakeConnectedSwitches returns n switches, connected according to the connect func.
// If connect==Connect2Switches, the switches will be fully connected. // If connect==Connect2Switches, the switches will be fully connected.
// initSwitch defines how the ith switch should be initialized (ie. with what reactors). // initSwitch defines how the ith switch should be initialized (ie. with what reactors).
// NOTE: panics if any switch fails to start. // NOTE: panics if any switch fails to start.
@ -494,7 +494,7 @@ func MakeConnectedSwitches(cfg *cfg.P2PConfig, n int, initSwitch func(int, *Swit
var PanicOnAddPeerErr = false var PanicOnAddPeerErr = false
// Will connect switches i and j via net.Pipe() // Connect2Switches will connect switches i and j via net.Pipe()
// Blocks until a conection is established. // Blocks until a conection is established.
// NOTE: caller ensures i and j are within bounds // NOTE: caller ensures i and j are within bounds
func Connect2Switches(switches []*Switch, i, j int) { func Connect2Switches(switches []*Switch, i, j int) {