github.com/iotexproject/iotex-core@v1.14.1-rc1/consensus/scheme/noop.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 "context" 10 11 "github.com/pkg/errors" 12 13 "github.com/iotexproject/iotex-core/blockchain/block" 14 "github.com/iotexproject/iotex-core/pkg/log" 15 "github.com/iotexproject/iotex-proto/golang/iotextypes" 16 ) 17 18 // Noop is the consensus scheme that does NOT create blocks 19 type Noop struct { 20 } 21 22 // NewNoop creates a Noop struct 23 func NewNoop() Scheme { 24 return &Noop{} 25 } 26 27 // Start does nothing here 28 func (n *Noop) Start(_ context.Context) error { return nil } 29 30 // Stop does nothing here 31 func (n *Noop) Stop(_ context.Context) error { return nil } 32 33 // HandleConsensusMsg handles incoming consensus message 34 func (n *Noop) HandleConsensusMsg(*iotextypes.ConsensusMessage) error { 35 log.Logger("consensus").Warn("Noop scheme does not handle incoming consensus message.") 36 return nil 37 } 38 39 // Calibrate triggers an event to calibrate consensus context 40 func (n *Noop) Calibrate(uint64) {} 41 42 // ValidateBlockFooter validates the block footer 43 func (n *Noop) ValidateBlockFooter(*block.Block) error { 44 log.Logger("consensus").Warn("Noop scheme could not calculate delegates by height") 45 return nil 46 } 47 48 // Metrics is not implemented for noop scheme 49 func (n *Noop) Metrics() (ConsensusMetrics, error) { 50 return ConsensusMetrics{}, errors.Wrapf( 51 ErrNotImplemented, 52 "noop scheme does not supported metrics yet", 53 ) 54 } 55 56 // Activate is not implemented for noop scheme 57 func (n *Noop) Activate(_ bool) { 58 log.S().Warn("Noop scheme could not support activate") 59 } 60 61 // Active is always true for noop scheme 62 func (n *Noop) Active() bool { return true }