Skip to content

Commit

Permalink
BFT: SyncBuffer tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yoav Tock <tock@il.ibm.com>
Change-Id: I3a17506964e9886e62dbb5b3e8bf8713345e43f9
  • Loading branch information
tock-ibm committed Mar 4, 2024
1 parent 9fd9ea3 commit 864103c
Show file tree
Hide file tree
Showing 16 changed files with 2,618 additions and 191 deletions.
109 changes: 109 additions & 0 deletions orderer/consensus/smartbft/block_puller_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package smartbft

import (
"crypto/x509"
"encoding/pem"

"github.com/hyperledger/fabric-lib-go/bccsp"
"github.com/hyperledger/fabric-lib-go/common/flogging"
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/orderer/common/cluster"
"github.com/hyperledger/fabric/orderer/common/localconfig"
"github.com/hyperledger/fabric/orderer/consensus"
"github.com/hyperledger/fabric/orderer/consensus/etcdraft"
"github.com/pkg/errors"
)

//go:generate counterfeiter -o mocks/block_puller.go . BlockPuller

// BlockPuller is used to pull blocks from other OSN
type BlockPuller interface {
PullBlock(seq uint64) *cb.Block
HeightsByEndpoints() (map[string]uint64, string, error)
Close()
}

//go:generate counterfeiter -o mocks/block_puller_factory.go . BlockPullerFactory

type BlockPullerFactory interface {
// CreateBlockPuller creates a new block puller.
CreateBlockPuller(
support consensus.ConsenterSupport,
baseDialer *cluster.PredicateDialer,
clusterConfig localconfig.Cluster,
bccsp bccsp.BCCSP,
) (BlockPuller, error)
}

type blockPullerCreator struct{}

func (*blockPullerCreator) CreateBlockPuller(
support consensus.ConsenterSupport,
baseDialer *cluster.PredicateDialer,
clusterConfig localconfig.Cluster,
bccsp bccsp.BCCSP,
) (BlockPuller, error) {
return newBlockPuller(support, baseDialer, clusterConfig, bccsp)
}

// newBlockPuller creates a new block puller
func newBlockPuller(
support consensus.ConsenterSupport,
baseDialer *cluster.PredicateDialer,
clusterConfig localconfig.Cluster,
bccsp bccsp.BCCSP,
) (BlockPuller, error) {
verifyBlockSequence := func(blocks []*cb.Block, _ string) error {
vb := cluster.BlockVerifierBuilder(bccsp)
return cluster.VerifyBlocksBFT(blocks, support.SignatureVerifier(), vb)
}

stdDialer := &cluster.StandardDialer{
Config: baseDialer.Config.Clone(),
}
stdDialer.Config.AsyncConnect = false
stdDialer.Config.SecOpts.VerifyCertificate = nil

// Extract the TLS CA certs and endpoints from the configuration,
endpoints, err := etcdraft.EndpointconfigFromSupport(support, bccsp)
if err != nil {
return nil, err
}

logger := flogging.MustGetLogger("orderer.common.cluster.puller")

der, _ := pem.Decode(stdDialer.Config.SecOpts.Certificate)
if der == nil {
return nil, errors.Errorf("client certificate isn't in PEM format: %v",
string(stdDialer.Config.SecOpts.Certificate))
}

myCert, err := x509.ParseCertificate(der.Bytes)
if err != nil {
logger.Warnf("Failed parsing my own TLS certificate: %v, therefore we may connect to our own endpoint when pulling blocks", err)
}

bp := &cluster.BlockPuller{
MyOwnTLSCert: myCert,
VerifyBlockSequence: verifyBlockSequence,
Logger: logger,
RetryTimeout: clusterConfig.ReplicationRetryTimeout,
MaxTotalBufferBytes: clusterConfig.ReplicationBufferSize,
FetchTimeout: clusterConfig.ReplicationPullTimeout,
Endpoints: endpoints,
Signer: support,
TLSCert: der.Bytes,
Channel: support.ChannelID(),
Dialer: stdDialer,
}

logger.Infof("Built new block puller with cluster config: %+v, endpoints: %+v", clusterConfig, endpoints)

return bp, nil
}
22 changes: 8 additions & 14 deletions orderer/consensus/smartbft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ import (
"go.uber.org/zap"
)

//go:generate counterfeiter -o mocks/mock_blockpuller.go . BlockPuller

// BlockPuller is used to pull blocks from other OSN
type BlockPuller interface {
PullBlock(seq uint64) *cb.Block
HeightsByEndpoints() (map[string]uint64, string, error)
Close()
}

// WALConfig consensus specific configuration parameters from orderer.yaml; for SmartBFT only WALDir is relevant.
type WALConfig struct {
WALDir string // WAL data of <my-channel> is stored in WALDir/<my-channel>
Expand Down Expand Up @@ -224,11 +215,14 @@ func bftSmartConsensusBuild(
c.pruneCommittedRequests(block)
return c.updateRuntimeConfig(block)
},
Support: c.support,
CryptoProvider: c.bccsp,
clusterDialer: c.clusterDialer,
localConfigCluster: c.localConfigCluster,
Logger: c.Logger,
Support: c.support,
CryptoProvider: c.bccsp,
ClusterDialer: c.clusterDialer,
LocalConfigCluster: c.localConfigCluster,
BlockPullerFactory: &blockPullerCreator{},
VerifierFactory: &verifierCreator{},
BFTDelivererFactory: &bftDelivererCreator{},
Logger: c.Logger,
}
case "simple":
c.Logger.Debug("Creating simple Synchronizer")
Expand Down
139 changes: 139 additions & 0 deletions orderer/consensus/smartbft/mocks/bft_block_deliverer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 864103c

Please sign in to comment.