github.com/annchain/OG@v0.0.9/consensus/annsensus/interface.go (about) 1 package annsensus 2 3 import ( 4 "github.com/annchain/OG/consensus/bft" 5 "github.com/annchain/OG/consensus/dkg" 6 "github.com/annchain/OG/consensus/term" 7 "time" 8 ) 9 10 // TermIdProvider provide Dkg term that will be changed every term switching. 11 // TermIdProvider maintains historic Sender info that can be retrieved by height. 12 // Once a new term is started, the term info will be sent through TermChangeEventChannel 13 type TermIdProvider interface { 14 // HeightTerm maps height to dkg term 15 HeightTerm(height uint64) (termId uint32) 16 CurrentTerm() (termId uint32) 17 GetTermChangeEventChannel() chan ConsensusContext 18 } 19 20 // HistoricalTermsHolder saves all historical term handlers(bft, dkg) and term info. 21 // In case of some slow messages are coming. 22 type HistoricalTermsHolder interface { 23 GetTermByHeight(heightInfoCarrier HeightInfoCarrier) (msgTerm *TermCollection, ok bool) 24 GetTermById(termId uint32) (msgTerm *TermCollection, ok bool) 25 SetTerm(termId uint32, composer *TermCollection) 26 DebugMyId() int 27 } 28 29 // ConsensusContext provides not only term info but also the character the node play in this term. 30 type ConsensusContext interface { 31 GetTerm() *term.Term 32 GetMyBftId() int 33 GetMyPartSec() dkg.PartSec 34 GetBlockTime() time.Duration 35 } 36 37 type ConsensusContextProvider interface { 38 GetConsensusContext(newTerm *term.Term) ConsensusContext 39 } 40 41 // HeightProvider is called when a height is needed. 42 // It is usually implemented by the chain info 43 type HeightProvider interface { 44 CurrentHeight() uint64 45 } 46 47 //type SequencerProducer interface { 48 // GenerateSequencer(issuer common.Address, height uint64, accountNonce uint64, 49 // privateKey *ogcrypto.PrivateKey, blsPubKey []byte) (seq *types.Sequencer, err error, genAgain bool) 50 // ValidateSequencer(seq types.Sequencer) error 51 //} 52 53 // BftMessageAdapter converts messages. 54 // During the converting process there may be some validation and signing operations. 55 type BftMessageAdapter interface { 56 AdaptAnnsensusMessage(incomingMsg AnnsensusMessage) (bft.BftMessage, error) 57 AdaptAnnsensusPeer(AnnsensusPeer) (bft.BftPeer, error) 58 59 AdaptBftMessage(outgoingMsg bft.BftMessage) (AnnsensusMessage, error) 60 AdaptBftPeer(bftPeer bft.BftPeer) (AnnsensusPeer, error) 61 } 62 63 type DkgMessageAdapter interface { 64 AdaptAnnsensusMessage(incomingMsg AnnsensusMessage) (dkg.DkgMessage, error) 65 AdaptAnnsensusPeer(AnnsensusPeer) (dkg.DkgPeer, error) 66 67 AdaptDkgMessage(outgoingMsg dkg.DkgMessage) (AnnsensusMessage, error) 68 AdaptDkgPeer(dkgPeer dkg.DkgPeer) (AnnsensusPeer, error) 69 } 70 71 type AnnsensusMessage interface { 72 GetType() AnnsensusMessageType 73 GetBytes() []byte 74 String() string 75 } 76 77 type AnnsensusPeerCommunicatorOutgoing interface { 78 Broadcast(msg AnnsensusMessage, peers []AnnsensusPeer) 79 Unicast(msg AnnsensusMessage, peer AnnsensusPeer) 80 } 81 82 type AnnsensusPeerCommunicatorIncoming interface { 83 GetPipeIn() chan *AnnsensusMessageEvent 84 GetPipeOut() chan *AnnsensusMessageEvent 85 } 86 87 type AnnsensusMessageHandler interface { 88 HandleMessage(msg AnnsensusMessage, peer AnnsensusPeer) 89 //GetPipeIn() chan AnnsensusMessage 90 //GetPipeOut() chan AnnsensusMessage 91 }