github.com/iotexproject/iotex-core@v1.14.1-rc1/consensus/scheme/scheme.go (about) 1 // Copyright (c) 2019 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package scheme 7 8 import ( 9 "google.golang.org/protobuf/proto" 10 11 "github.com/iotexproject/iotex-core/blockchain/block" 12 "github.com/iotexproject/iotex-core/pkg/lifecycle" 13 "github.com/iotexproject/iotex-proto/golang/iotextypes" 14 ) 15 16 // CreateBlockCB defines the callback to create a new block 17 type CreateBlockCB func() (*block.Block, error) 18 19 // TellPeerCB defines the callback to tell (which is a unicast) message to peers on P2P network 20 type TellPeerCB func(proto.Message) error 21 22 // ConsensusDoneCB defines the callback when consensus is reached 23 type ConsensusDoneCB func(*block.Block) error 24 25 // BroadcastCB defines the callback to publish the consensus result 26 type BroadcastCB func(*block.Block) error 27 28 // Broadcast sends a broadcast message to the whole network 29 type Broadcast func(msg proto.Message) error 30 31 // Scheme is the interface that consensus schemes should implement 32 type Scheme interface { 33 lifecycle.StartStopper 34 35 HandleConsensusMsg(msg *iotextypes.ConsensusMessage) error 36 Calibrate(uint64) 37 ValidateBlockFooter(*block.Block) error 38 Metrics() (ConsensusMetrics, error) 39 Activate(bool) 40 Active() bool 41 } 42 43 // ConsensusMetrics contains consensus metrics to expose 44 type ConsensusMetrics struct { 45 LatestEpoch uint64 46 LatestHeight uint64 47 LatestDelegates []string 48 LatestBlockProducer string 49 }