smartbft

package
v0.0.0-...-579b097 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LastBlockFromLedgerOrPanic

func LastBlockFromLedgerOrPanic(ledger Ledger, logger Logger) *cb.Block

LastBlockFromLedgerOrPanic returns the last block from the ledger

func LastConfigBlockFromLedgerOrPanic

func LastConfigBlockFromLedgerOrPanic(ledger Ledger, logger Logger) *cb.Block

LastConfigBlockFromLedgerOrPanic returns the last config block from the ledger

func PreviousConfigBlockFromLedgerOrPanic

func PreviousConfigBlockFromLedgerOrPanic(ledger Ledger, logger Logger) *cb.Block

func ProposalToBlock

func ProposalToBlock(proposal types.Proposal) (*cb.Block, error)

ProposalToBlock marshals the proposal the the block

func RemoteNodesFromConfigBlock

func RemoteNodesFromConfigBlock(block *cb.Block, logger *flogging.FabricLogger, bccsp bccsp.BCCSP) (*nodeConfig, error)

RemoteNodesFromConfigBlock unmarshals the node config from the block metadata

Types

type AccessController

type AccessController interface {
	// Evaluate takes a set of SignedData and evaluates whether this set of signatures satisfies the policy
	Evaluate(signatureSet []*protoutil.SignedData) error
}

AccessController is used to determine if a signature of a certain client is valid

type Assembler

type Assembler struct {
	RuntimeConfig   *atomic.Value
	Logger          *flogging.FabricLogger
	VerificationSeq func() uint64
}

Assembler is the proposal assembler

func (*Assembler) AssembleProposal

func (a *Assembler) AssembleProposal(metadata []byte, requests [][]byte) (nextProp types.Proposal)

AssembleProposal assembles a proposal from the metadata and the request

type BFTChain

type BFTChain struct {
	RuntimeConfig    *atomic.Value
	Channel          string
	Config           types.Configuration
	BlockPuller      BlockPuller
	Comm             cluster.Communicator
	SignerSerializer signerSerializer
	PolicyManager    policies.Manager
	Logger           *flogging.FabricLogger
	WALDir           string

	Metrics       *Metrics
	MetricsBFT    *api.Metrics
	MetricsWalBFT *wal.Metrics
	// contains filtered or unexported fields
}

BFTChain implements Chain interface to wire with BFT smart library

func NewChain

func NewChain(
	cv ConfigValidator,
	selfID uint64,
	config types.Configuration,
	walDir string,
	blockPuller BlockPuller,
	comm cluster.Communicator,
	signerSerializer signerSerializer,
	policyManager policies.Manager,
	support consensus.ConsenterSupport,
	metrics *Metrics,
	metricsBFT *api.Metrics,
	metricsWalBFT *wal.Metrics,
	bccsp bccsp.BCCSP,
) (*BFTChain, error)

NewChain creates new BFT Smart chain

func (*BFTChain) Configure

func (c *BFTChain) Configure(config *cb.Envelope, configSeq uint64) error

Configure accepts a message which reconfigures the channel and will trigger an update to the configSeq if committed. The configuration must have been triggered by a ConfigUpdate message. If the config sequence advances, it is the responsibility of the consenter to recompute the resulting config, discarding the message if the reconfiguration is no longer valid. The consenter may return an error, indicating the message was not accepted

func (*BFTChain) Deliver

func (c *BFTChain) Deliver(proposal types.Proposal, signatures []types.Signature) types.Reconfig

Deliver delivers proposal, writes block with transactions and metadata

func (*BFTChain) Errored

func (c *BFTChain) Errored() <-chan struct{}

Errored returns a channel which will close when an error has occurred. This is especially useful for the Deliver client, who must terminate waiting clients when the consenter is not up to date.

func (*BFTChain) Halt

func (c *BFTChain) Halt()

Halt frees the resources which were allocated for this Chain.

func (*BFTChain) HandleMessage

func (c *BFTChain) HandleMessage(sender uint64, m *smartbftprotos.Message)

HandleMessage handles the message from the sender

func (*BFTChain) HandleRequest

func (c *BFTChain) HandleRequest(sender uint64, req []byte)

HandleRequest handles the request from the sender

func (*BFTChain) Order

func (c *BFTChain) Order(env *cb.Envelope, configSeq uint64) error

Order accepts a message which has been processed at a given configSeq. If the configSeq advances, it is the responsibility of the consenter to revalidate and potentially discard the message The consenter may return an error, indicating the message was not accepted

func (*BFTChain) Start

func (c *BFTChain) Start()

Start should allocate whatever resources are needed for staying up to date with the chain. Typically, this involves creating a thread which reads from the ordering source, passes those messages to a block cutter, and writes the resulting blocks to the ledger.

func (*BFTChain) StatusReport

func (c *BFTChain) StatusReport() (types2.ConsensusRelation, types2.Status)

StatusReport returns the ConsensusRelation & Status

func (*BFTChain) WaitReady

func (c *BFTChain) WaitReady() error

WaitReady blocks waiting for consenter to be ready for accepting new messages. This is useful when consenter needs to temporarily block ingress messages so that in-flight messages can be consumed. It could return error if consenter is in erroneous states. If this blocking behavior is not desired, consenter could simply return nil.

type BlockPuller

type BlockPuller interface {
	PullBlock(seq uint64) *cb.Block
	HeightsByEndpoints() (map[string]uint64, error)
	Close()
}

BlockPuller is used to pull blocks from other OSN

type Bundle

type Bundle interface {
	channelconfig.Resources
}

Bundle defines the channelconfig resources interface

type ByteBufferTuple

type ByteBufferTuple struct {
	A []byte
	B []byte
}

ByteBufferTuple is the byte slice tuple

func (*ByteBufferTuple) FromBytes

func (bbt *ByteBufferTuple) FromBytes(bytes []byte) error

FromBytes unmarshals bytes to a buffer tuple

func (*ByteBufferTuple) ToBytes

func (bbt *ByteBufferTuple) ToBytes() []byte

ToBytes marshals the buffer tuple to bytes

type ChainGetter

type ChainGetter interface {
	// GetChain obtains the ChainSupport for the given channel.
	// Returns nil, false when the ChainSupport for the given channel
	// isn't found.
	GetChain(chainID string) *multichannel.ChainSupport
}

ChainGetter obtains instances of ChainSupport for the given channel

type ConfigBlockValidator

type ConfigBlockValidator struct {
	ConfigUpdateProposer ConfigUpdateProposer
	ValidatingChannel    string
	Filters              Filters
	Logger               *flogging.FabricLogger
}

ConfigBlockValidator struct

func (*ConfigBlockValidator) ValidateConfig

func (cbv *ConfigBlockValidator) ValidateConfig(envelope *cb.Envelope) error

ValidateConfig validates config from envelope

type ConfigTxValidator

type ConfigTxValidator interface {
	configtx.Validator
}

ConfigTxValidator defines the configtx validator interface

type ConfigUpdateProposer

type ConfigUpdateProposer interface {
	ProposeConfigUpdate(channel string, configtx *cb.Envelope) (*cb.ConfigEnvelope, error)
}

ConfigUpdateProposer produces a ConfigEnvelope

type ConfigValidator

type ConfigValidator interface {
	ValidateConfig(env *cb.Envelope) error
}

ConfigValidator interface

type Consenter

type Consenter struct {
	CreateChain      func(chainName string)
	GetPolicyManager PolicyManagerRetriever
	Logger           *flogging.FabricLogger
	Identity         []byte
	Comm             *cluster.AuthCommMgr
	Chains           ChainGetter
	SignerSerializer SignerSerializer
	Registrar        *multichannel.Registrar
	WALBaseDir       string
	ClusterDialer    *cluster.PredicateDialer
	Conf             *localconfig.TopLevel
	Metrics          *Metrics
	MetricsBFT       *api.Metrics
	MetricsWalBFT    *wal.Metrics
	BCCSP            bccsp.BCCSP
	ClusterService   *cluster.ClusterService
}

Consenter implementation of the BFT smart based consenter

func New

func New(
	pmr PolicyManagerRetriever,
	signerSerializer SignerSerializer,
	clusterDialer *cluster.PredicateDialer,
	conf *localconfig.TopLevel,
	srvConf comm.ServerConfig,
	srv *comm.GRPCServer,
	r *multichannel.Registrar,
	metricsProvider metrics.Provider,
	clusterMetrics *cluster.Metrics,
	BCCSP bccsp.BCCSP,
) *Consenter

New creates Consenter of type smart bft

func (*Consenter) HandleChain

func (c *Consenter) HandleChain(support consensus.ConsenterSupport, metadata *cb.Metadata) (consensus.Chain, error)

HandleChain returns a new Chain instance or an error upon failure

func (*Consenter) IsChannelMember

func (c *Consenter) IsChannelMember(joinBlock *cb.Block) (bool, error)

func (*Consenter) ReceiverByChain

func (c *Consenter) ReceiverByChain(channelID string) MessageReceiver

ReceiverByChain returns the MessageReceiver for the given channelID or nil if not found.

func (*Consenter) TargetChannel

func (c *Consenter) TargetChannel(message proto.Message) string

TargetChannel extracts the channel from the given proto.Message. Returns an empty string on failure.

type ConsenterCertificate

type ConsenterCertificate struct {
	ConsenterCertificate []byte
	CryptoProvider       bccsp.BCCSP
}

ConsenterCertificate denotes a TLS certificate of a consenter

func (ConsenterCertificate) IsConsenterOfChannel

func (conCert ConsenterCertificate) IsConsenterOfChannel(configBlock *cb.Block) error

IsConsenterOfChannel returns whether the caller is a consenter of a channel by inspecting the given configuration block. It returns nil if true, else returns an error.

type ConsenterVerifier

type ConsenterVerifier interface {
	// Evaluate takes a set of SignedData and evaluates whether this set of signatures satisfies the policy
	Evaluate(signatureSet []*protoutil.SignedData) error
}

ConsenterVerifier is used to determine whether a signature from one of the consenters is valid

type CounterConverter

type CounterConverter struct {
	// contains filtered or unexported fields
}

func (*CounterConverter) Add

func (c *CounterConverter) Add(delta float64)

func (*CounterConverter) With

func (c *CounterConverter) With(labelValues ...string) api.Counter

type CreateChainCallback

type CreateChainCallback func()

CreateChainCallback creates a new chain

type Egress

type Egress struct {
	Channel       string
	RPC           RPC
	Logger        Logger
	RuntimeConfig *atomic.Value
}

Egress implementation

func (*Egress) Nodes

func (e *Egress) Nodes() []uint64

Nodes returns nodes from the runtime config

func (*Egress) SendConsensus

func (e *Egress) SendConsensus(targetID uint64, m *protos.Message)

SendConsensus sends the BFT message to the cluster

func (*Egress) SendTransaction

func (e *Egress) SendTransaction(targetID uint64, request []byte)

SendTransaction sends the transaction to the cluster

type Filters

type Filters interface {
	ApplyFilters(channel string, env *cb.Envelope) error
}

Filters applies the filters on the outer envelope

type GaugeConverter

type GaugeConverter struct {
	// contains filtered or unexported fields
}

func (*GaugeConverter) Add

func (g *GaugeConverter) Add(delta float64)

func (*GaugeConverter) Set

func (g *GaugeConverter) Set(value float64)

func (*GaugeConverter) With

func (g *GaugeConverter) With(labelValues ...string) api.Gauge

type HistogramConverter

type HistogramConverter struct {
	// contains filtered or unexported fields
}

func (*HistogramConverter) Observe

func (h *HistogramConverter) Observe(value float64)

func (*HistogramConverter) With

func (h *HistogramConverter) With(labelValues ...string) api.Histogram

type Ingress

type Ingress struct {
	Logger        WarningLogger
	ChainSelector ReceiverGetter
}

Ingress dispatches Submit and Step requests to the designated per chain instances

func (*Ingress) OnConsensus

func (in *Ingress) OnConsensus(channel string, sender uint64, request *ab.ConsensusRequest) error

OnConsensus notifies the Ingress for a reception of a StepRequest from a given sender on a given channel

func (*Ingress) OnSubmit

func (in *Ingress) OnSubmit(channel string, sender uint64, request *ab.SubmitRequest) error

OnSubmit notifies the Ingress for a reception of a SubmitRequest from a given sender on a given channel

type Ledger

type Ledger interface {
	// Height returns the number of blocks in the ledger this channel is associated with.
	Height() uint64

	// Block returns a block with the given number,
	// or nil if such a block doesn't exist.
	Block(number uint64) *cb.Block
}

Ledger returns the height and a block with the given number

type Logger

type Logger interface {
	Warnf(template string, args ...interface{})
	Panicf(template string, args ...interface{})
}

Logger specifies the logger

type MessageReceiver

type MessageReceiver interface {
	HandleMessage(sender uint64, m *protos.Message)
	HandleRequest(sender uint64, req []byte)
}

MessageReceiver receives messages

type MetricProviderConverter

type MetricProviderConverter struct {
	// contains filtered or unexported fields
}

func (*MetricProviderConverter) NewCounter

func (m *MetricProviderConverter) NewCounter(opts api.CounterOpts) api.Counter

func (*MetricProviderConverter) NewGauge

func (m *MetricProviderConverter) NewGauge(opts api.GaugeOpts) api.Gauge

func (*MetricProviderConverter) NewHistogram

func (m *MetricProviderConverter) NewHistogram(opts api.HistogramOpts) api.Histogram

type Metrics

type Metrics struct {
	ClusterSize          metrics.Gauge
	CommittedBlockNumber metrics.Gauge
	IsLeader             metrics.Gauge
	LeaderID             metrics.Gauge
}

Metrics defines the metrics for the cluster.

func NewMetrics

func NewMetrics(p metrics.Provider) *Metrics

NewMetrics creates the Metrics

type NodeIdentitiesByID

type NodeIdentitiesByID map[uint64][]byte

NodeIdentitiesByID stores Identities by id

func (NodeIdentitiesByID) IdentityToID

func (nibd NodeIdentitiesByID) IdentityToID(identity []byte) (uint64, bool)

IdentityToID looks up the Identity in NodeIdentitiesByID and returns id and flag true if found

type PolicyManagerRetriever

type PolicyManagerRetriever func(channel string) policies.Manager

PolicyManagerRetriever is the policy manager retriever function

type RPC

type RPC interface {
	SendConsensus(dest uint64, msg *ab.ConsensusRequest) error
	// SendSubmit(dest uint64, request *ab.SubmitRequest) error
	SendSubmit(destination uint64, request *ab.SubmitRequest, report func(error)) error
}

RPC sends a consensus and submits a request

type ReceiverGetter

type ReceiverGetter interface {
	// ReceiverByChain returns the MessageReceiver if it exists, or nil if it doesn't
	ReceiverByChain(channelID string) MessageReceiver
}

ReceiverGetter obtains instances of MessageReceiver given a channel ID

type RequestInspector

type RequestInspector struct {
	ValidateIdentityStructure func(identity *msp.SerializedIdentity) error
	Logger                    *flogging.FabricLogger
}

RequestInspector inspects incomming requests and validates serialized identity

func (*RequestInspector) RequestID

func (ri *RequestInspector) RequestID(rawReq []byte) types.RequestInfo

RequestID unwraps the request info from the raw request

type RuntimeConfig

type RuntimeConfig struct {
	BFTConfig types.Configuration

	LastCommittedBlockHash string
	RemoteNodes            []cluster.RemoteNode
	ID2Identities          NodeIdentitiesByID
	LastBlock              *cb.Block
	LastConfigBlock        *cb.Block
	Nodes                  []uint64
	// contains filtered or unexported fields
}

RuntimeConfig defines the configuration of the consensus that is related to runtime.

func (RuntimeConfig) BlockCommitted

func (rtc RuntimeConfig) BlockCommitted(block *cb.Block, bccsp bccsp.BCCSP) (RuntimeConfig, error)

BlockCommitted updates the config from the block

type Sequencer

type Sequencer interface {
	Sequence() uint64
}

Sequencer returns sequences

type Signature

type Signature struct {
	IdentifierHeader     []byte
	BlockHeader          []byte
	OrdererBlockMetadata []byte
}

Signature implementation

func (Signature) AsBytes

func (sig Signature) AsBytes() []byte

AsBytes returns the message to sign

func (*Signature) Marshal

func (sig *Signature) Marshal() []byte

Marshal the signature

func (*Signature) Unmarshal

func (sig *Signature) Unmarshal(bytes []byte) error

Unmarshal the signature

type Signer

type Signer struct {
	ID                 uint64
	SignerSerializer   SignerSerializer
	Logger             Logger
	LastConfigBlockNum func(*cb.Block) uint64
}

Signer implementation

func (*Signer) Sign

func (s *Signer) Sign(msg []byte) []byte

Sign signs the message

func (*Signer) SignProposal

func (s *Signer) SignProposal(proposal types.Proposal, _ []byte) *types.Signature

SignProposal signs the proposal

type SignerSerializer

type SignerSerializer interface {
	identity.SignerSerializer
}

SignerSerializer signs messages and serializes identities

type Synchronizer

type Synchronizer struct {
	LatestConfig    func() (types.Configuration, []uint64)
	BlockToDecision func(*cb.Block) *types.Decision
	OnCommit        func(*cb.Block) types.Reconfig
	Support         consensus.ConsenterSupport
	BlockPuller     BlockPuller
	ClusterSize     uint64
	Logger          *flogging.FabricLogger
	// contains filtered or unexported fields
}

Synchronizer implementation

func (*Synchronizer) Close

func (s *Synchronizer) Close()

Close closes the block puller connection

func (*Synchronizer) Sync

func (s *Synchronizer) Sync() types.SyncResponse

Sync synchronizes blocks and returns the response

type Verifier

type Verifier struct {
	Channel               string
	RuntimeConfig         *atomic.Value
	ReqInspector          *RequestInspector
	ConsenterVerifier     ConsenterVerifier
	AccessController      AccessController
	VerificationSequencer Sequencer
	Ledger                Ledger
	Logger                *flogging.FabricLogger
	ConfigValidator       ConfigValidator
}

Verifier verifies proposals and signatures

func (*Verifier) AuxiliaryData

func (v *Verifier) AuxiliaryData(msg []byte) []byte

AuxiliaryData unmarshals and returns auxiliary data from signature

func (*Verifier) RequestsFromProposal

func (v *Verifier) RequestsFromProposal(proposal types.Proposal) []types.RequestInfo

RequestsFromProposal converts proposal to []RequestInfo

func (*Verifier) VerificationSequence

func (v *Verifier) VerificationSequence() uint64

VerificationSequence returns verification sequence

func (*Verifier) VerifyConsenterSig

func (v *Verifier) VerifyConsenterSig(signature types.Signature, prop types.Proposal) ([]byte, error)

VerifyConsenterSig verifies consenter signature

func (*Verifier) VerifyProposal

func (v *Verifier) VerifyProposal(proposal types.Proposal) ([]types.RequestInfo, error)

VerifyProposal verifies proposal and returns []RequestInfo

func (*Verifier) VerifyRequest

func (v *Verifier) VerifyRequest(rawRequest []byte) (types.RequestInfo, error)

VerifyRequest verifies raw request

func (*Verifier) VerifySignature

func (v *Verifier) VerifySignature(signature types.Signature) error

VerifySignature verifies signature

type WALConfig

type WALConfig struct {
	WALDir            string // WAL data of <my-channel> is stored in WALDir/<my-channel>
	SnapDir           string // Snapshots of <my-channel> are stored in SnapDir/<my-channel>
	EvictionSuspicion string // Duration threshold that the node samples in order to suspect its eviction from the channel.
}

WALConfig consensus specific configuration parameters from orderer.yaml; for SmartBFT only WALDir is relevant.

type WarningLogger

type WarningLogger interface {
	Warningf(template string, args ...interface{})
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL