github.com/anjalikarhana/fabric@v2.1.1+incompatible/orderer/common/msgprocessor/msgprocessor.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  // Package msgprocessor provides the implementations for processing of the assorted message
     8  // types which may arrive in the system through Broadcast.
     9  package msgprocessor
    10  
    11  import (
    12  	"errors"
    13  
    14  	cb "github.com/hyperledger/fabric-protos-go/common"
    15  	"github.com/hyperledger/fabric/common/flogging"
    16  )
    17  
    18  const (
    19  	// These should eventually be derived from the channel support once enabled
    20  	msgVersion = int32(0)
    21  	epoch      = 0
    22  )
    23  
    24  var logger = flogging.MustGetLogger("orderer.common.msgprocessor")
    25  
    26  // ErrChannelDoesNotExist is returned by the system channel for transactions which
    27  // are not for the system channel ID and are not attempting to create a new channel
    28  var ErrChannelDoesNotExist = errors.New("channel does not exist")
    29  
    30  // ErrPermissionDenied is returned by errors which are caused by transactions
    31  // which are not permitted due to an authorization failure.
    32  var ErrPermissionDenied = errors.New("permission denied")
    33  
    34  // ErrMaintenanceMode is returned when transactions are rejected because the orderer is in "maintenance mode",
    35  // as defined by ConsensusType.State != NORMAL. This typically happens during consensus-type migration.
    36  var ErrMaintenanceMode = errors.New("maintenance mode")
    37  
    38  // Classification represents the possible message types for the system.
    39  type Classification int
    40  
    41  const (
    42  	// NormalMsg is the class of standard (endorser or otherwise non-config) messages.
    43  	// Messages of this type should be processed by ProcessNormalMsg.
    44  	NormalMsg Classification = iota
    45  
    46  	// ConfigUpdateMsg indicates messages of type CONFIG_UPDATE.
    47  	// Messages of this type should be processed by ProcessConfigUpdateMsg.
    48  	ConfigUpdateMsg
    49  
    50  	// ConfigMsg indicates message of type ORDERER_TRANSACTION or CONFIG.
    51  	// Messages of this type should be processed by ProcessConfigMsg
    52  	ConfigMsg
    53  )
    54  
    55  // Processor provides the methods necessary to classify and process any message which
    56  // arrives through the Broadcast interface.
    57  type Processor interface {
    58  	// ClassifyMsg inspects the message header to determine which type of processing is necessary
    59  	ClassifyMsg(chdr *cb.ChannelHeader) Classification
    60  
    61  	// ProcessNormalMsg will check the validity of a message based on the current configuration.  It returns the current
    62  	// configuration sequence number and nil on success, or an error if the message is not valid
    63  	ProcessNormalMsg(env *cb.Envelope) (configSeq uint64, err error)
    64  
    65  	// ProcessConfigUpdateMsg will attempt to apply the config update to the current configuration, and if successful
    66  	// return the resulting config message and the configSeq the config was computed from.  If the config update message
    67  	// is invalid, an error is returned.
    68  	ProcessConfigUpdateMsg(env *cb.Envelope) (config *cb.Envelope, configSeq uint64, err error)
    69  
    70  	// ProcessConfigMsg takes message of type `ORDERER_TX` or `CONFIG`, unpack the ConfigUpdate envelope embedded
    71  	// in it, and call `ProcessConfigUpdateMsg` to produce new Config message of the same type as original message.
    72  	// This method is used to re-validate and reproduce config message, if it's deemed not to be valid anymore.
    73  	ProcessConfigMsg(env *cb.Envelope) (*cb.Envelope, uint64, error)
    74  }