Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions node/consensus/consensus_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
"google.golang.org/protobuf/proto"
)

func CreateConsensus(nodeConfig *node_config.ConsenterNodeConfig, config *ord_config.Configuration, lastConfigBlock *common.Block, logger *flogging.FabricLogger, mainExitChan chan struct{}, signer Signer, configUpdateProposer policy.ConfigUpdateProposer) *Consensus {
func CreateConsensus(nodeConfig *node_config.ConsenterNodeConfig, config *ord_config.Configuration, joinConfigBlock *common.Block, logger *flogging.FabricLogger, mainExitChan chan struct{}, signer Signer, configUpdateProposer policy.ConfigUpdateProposer) *Consensus {
c := &Consensus{
MainExitChan: mainExitChan,
status: node_utils.NodeStatus{
Expand All @@ -57,21 +57,21 @@ func CreateConsensus(nodeConfig *node_config.ConsenterNodeConfig, config *ord_co
PartyID: nodeConfig.PartyId,
}

c.configureConsensus(nodeConfig, config, lastConfigBlock, configUpdateProposer)
c.configureConsensus(nodeConfig, config, joinConfigBlock, configUpdateProposer)

return c
}

func (c *Consensus) configureConsensus(nodeConfig *node_config.ConsenterNodeConfig, config *ord_config.Configuration, lastConfigBlock *common.Block, configUpdateProposer policy.ConfigUpdateProposer) {
if lastConfigBlock == nil {
c.Logger.Panicf("Error creating Consensus%d, last config block is nil", nodeConfig.PartyId)
func (c *Consensus) configureConsensus(nodeConfig *node_config.ConsenterNodeConfig, config *ord_config.Configuration, joinConfigBlock *common.Block, configUpdateProposer policy.ConfigUpdateProposer) {
if joinConfigBlock == nil {
c.Logger.Panicf("Error creating Consensus%d, join config block is nil", nodeConfig.PartyId)
}

if lastConfigBlock.Header == nil {
c.Logger.Panicf("Error creating Consensus%d, last config block header is nil", nodeConfig.PartyId)
if joinConfigBlock.Header == nil {
c.Logger.Panicf("Error creating Consensus%d, join config block header is nil", nodeConfig.PartyId)
}

c.Logger.Infof("Creating consensus, party: %d, address: %s, with last config block number: %d", nodeConfig.PartyId, nodeConfig.ListenAddress, lastConfigBlock.Header.Number)
c.Logger.Infof("Creating consensus, party: %d, address: %s, with join config block number: %d", nodeConfig.PartyId, nodeConfig.ListenAddress, joinConfigBlock.Header.Number)

var currentNodes []uint64
for _, node := range nodeConfig.Consenters {
Expand All @@ -83,10 +83,10 @@ func (c *Consensus) configureConsensus(nodeConfig *node_config.ConsenterNodeConf
c.Logger.Panicf("Failed creating consensus ledger: %s", err)
}

initialState, metadata, lastProposal, lastSigs, decisionNumOfLastConfigBlock, prevHash := getInitialStateAndMetadata(c.Logger, nodeConfig, lastConfigBlock, consLedger)
initialState, metadata, lastProposal, lastSigs, decisionNumOfLastConfigBlock, prevHash := getInitialStateAndMetadata(c.Logger, nodeConfig, joinConfigBlock, consLedger)
txCount := getTxCount(consLedger)
// indicate that sync is required on startup when new consensus node joins the cluster
if consLedger.Height() == 0 && lastConfigBlock.Header.Number > 0 {
if consLedger.Height() == 0 && joinConfigBlock.Header.Number > 0 {
nodeConfig.BFTConfig.SyncOnStart = true
}

Expand All @@ -109,7 +109,7 @@ func (c *Consensus) configureConsensus(nodeConfig *node_config.ConsenterNodeConf
}
c.BADB = badb
c.State = initialState
c.lastConfigBlockNum = lastConfigBlock.Header.Number
c.lastConfigBlockNum = joinConfigBlock.Header.Number
c.decisionNumOfLastConfigBlock = decisionNumOfLastConfigBlock
c.CurrentNodes = currentNodes
c.Storage = consLedger
Expand Down Expand Up @@ -149,6 +149,7 @@ func (c *Consensus) configureConsensus(nodeConfig *node_config.ConsenterNodeConf
&ConsenterSupportAdapter{consensus: c}, // support ConsenterSupport,
nodeConfig.BCCSP,
&comm.PredicateDialer{Config: c.clientConfig()},
joinConfigBlock, // joinConfigBlock is the config block that was used to join the cluster
)
c.Logger.Info("Created a BFT Synchronizer")

Expand Down
6 changes: 0 additions & 6 deletions node/consensus/synchronizer/mocks/bft_block_deliverer.go

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

2 changes: 0 additions & 2 deletions node/consensus/synchronizer/mocks/bft_deliverer_factory.go

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

22 changes: 0 additions & 22 deletions node/consensus/synchronizer/mocks/consenter_support.go

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

6 changes: 0 additions & 6 deletions node/consensus/synchronizer/mocks/height_detector.go

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

2 changes: 0 additions & 2 deletions node/consensus/synchronizer/mocks/height_detector_factory.go

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

18 changes: 0 additions & 18 deletions node/consensus/synchronizer/mocks/orderer_config.go

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

10 changes: 0 additions & 10 deletions node/consensus/synchronizer/mocks/updatable_block_verifier.go

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

2 changes: 0 additions & 2 deletions node/consensus/synchronizer/mocks/verifier_factory.go

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

26 changes: 20 additions & 6 deletions node/consensus/synchronizer/synchronizer_bft.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type BFTSynchronizer struct {
VerifierFactory VerifierFactory
BFTDelivererFactory BFTDelivererFactory
Logger *flogging.FabricLogger
JoinConfigBlock *common.Block // JoinConfigBlock is the config block that was used to join the cluster.

mutex sync.Mutex
syncBuff *SyncBuffer
Expand Down Expand Up @@ -242,18 +243,31 @@ func (s *BFTSynchronizer) computeTargetHeight(heights []uint64) uint64 {

// createBFTDeliverer creates and initializes the BFT block deliverer.
func (s *BFTSynchronizer) createBFTDeliverer(startHeight uint64, myParty arma_types.PartyID) (BFTBlockDeliverer, error) {
lastBlock := s.Support.Block(startHeight - 1)
lastConfigBlock, err := s.Support.LastConfigBlock(lastBlock)
ledgerLastBlock := s.Support.Block(startHeight - 1)
ledgerLastConfigBlock, err := s.Support.LastConfigBlock(ledgerLastBlock)
if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve last config block")
}
if s.JoinConfigBlock == nil {
return nil, errors.New("join config block is nil")
}

s.Logger.Infof("Creating BFTDeliverer, last block in ledger: %d, last config block in ledger: %d, join config block: %d", ledgerLastBlock.Header.Number, ledgerLastConfigBlock.Header.Number, s.JoinConfigBlock.Header.Number)

var delivererInitializationBlock *common.Block
if s.JoinConfigBlock.Header.Number > ledgerLastConfigBlock.Header.Number {
delivererInitializationBlock = s.JoinConfigBlock
} else {
delivererInitializationBlock = ledgerLastConfigBlock
}

blockOps := &utils.CommonConfigBlockOperations{}
lastConfigEnv, err := blockOps.ConfigFromBlock(lastConfigBlock)
currentConfigEnv, err := blockOps.ConfigFromBlock(delivererInitializationBlock)
if err != nil {
return nil, errors.Wrapf(err, "failed to retrieve last config envelope")
return nil, errors.Wrapf(err, "failed to retrieve envelope from config block")
}
Comment thread
DorKatzelnick marked this conversation as resolved.

updatableVerifier, err := s.VerifierFactory.CreateBlockVerifier(lastConfigBlock, lastBlock, s.CryptoProvider, s.Logger)
updatableVerifier, err := s.VerifierFactory.CreateBlockVerifier(ledgerLastConfigBlock, ledgerLastBlock, s.CryptoProvider, s.Logger)
if err != nil {
return nil, errors.Wrapf(err, "failed to create BlockVerificationAssistant")
}
Expand Down Expand Up @@ -296,7 +310,7 @@ func (s *BFTSynchronizer) createBFTDeliverer(startHeight uint64, myParty arma_ty
)

s.Logger.Infof("Created a BFTDeliverer on channel: %s", s.Support.ChannelID())
bftDeliverer.Initialize(lastConfigEnv.GetConfig(), myParty)
bftDeliverer.Initialize(currentConfigEnv.GetConfig(), myParty)

return bftDeliverer, nil
}
Expand Down
13 changes: 13 additions & 0 deletions node/consensus/synchronizer/synchronizer_bft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: b42,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -158,6 +159,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: b42,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -206,6 +208,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: b42,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -266,6 +269,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: b42,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -401,6 +405,7 @@ func TestBFTSynchronizer(t *testing.T) {
BlockPullerFactory: bpf,
VerifierFactory: fakeVerifierFactory,
BFTDelivererFactory: fakeBFTDelivererFactory,
JoinConfigBlock: genesisBlock,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -522,6 +527,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: genesisBlock1,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -604,6 +610,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: genesisBlock,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -681,6 +688,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: goodConfigBlock,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -765,6 +773,7 @@ func TestBFTSynchronizer(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: genesisBlock,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -896,6 +905,7 @@ func TestBFTSynchronizer(t *testing.T) {
BlockPullerFactory: bpf,
VerifierFactory: fakeVerifierFactory,
BFTDelivererFactory: fakeBFTDelivererFactory,
JoinConfigBlock: b42,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down Expand Up @@ -1048,6 +1058,7 @@ func TestBFTSynchronizer(t *testing.T) {
BlockPullerFactory: bpf,
VerifierFactory: fakeVerifierFactory,
BFTDelivererFactory: fakeBFTDelivererFactory,
JoinConfigBlock: b42,
Logger: flogging.MustGetLogger("test.smartbft"),
}
require.NotNil(t, bftSynchronizer)
Expand Down Expand Up @@ -1211,6 +1222,7 @@ func TestBFTSynchronizer(t *testing.T) {
BlockPullerFactory: bpf,
VerifierFactory: fakeVerifierFactory,
BFTDelivererFactory: fakeBFTDelivererFactory,
JoinConfigBlock: b42,
Logger: flogging.MustGetLogger("test.smartbft"),
}
require.NotNil(t, bftSynchronizer)
Expand Down Expand Up @@ -1330,6 +1342,7 @@ func TestBFTSynchronizer_Stop(t *testing.T) {
Support: fakeCS,
LocalConfigCluster: config.Cluster{},
BlockPullerFactory: bpf,
JoinConfigBlock: goodConfigBlock,
Logger: flogging.MustGetLogger("test.smartbft"),
}

Expand Down
6 changes: 5 additions & 1 deletion node/consensus/synchronizer/synchronizer_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type SynchronizerFactory interface {
support ConsenterSupport,
bccsp bccsp.BCCSP,
clusterDialer *comm.PredicateDialer,
joinConfigBlock *cb.Block,
) SynchronizerWithStop
}

Expand All @@ -93,8 +94,9 @@ func (*SynchronizerCreator) CreateSynchronizer(
support ConsenterSupport,
bccsp bccsp.BCCSP,
clusterDialer *comm.PredicateDialer,
joinConfigBlock *cb.Block,
) SynchronizerWithStop {
return newSynchronizer(logger, selfID, localConfigCluster, rtc, blockToDecision, pruneCommittedRequests, updateRuntimeConfig, support, bccsp, clusterDialer)
return newSynchronizer(logger, selfID, localConfigCluster, rtc, blockToDecision, pruneCommittedRequests, updateRuntimeConfig, support, bccsp, clusterDialer, joinConfigBlock)
}

// newSynchronizer creates a new synchronizer
Expand All @@ -109,6 +111,7 @@ func newSynchronizer(
support ConsenterSupport,
bccsp bccsp.BCCSP,
clusterDialer *comm.PredicateDialer,
joinConfigBlock *cb.Block,
) SynchronizerWithStop {
switch localConfigCluster.ReplicationPolicy {
case "consensus", "":
Expand All @@ -129,6 +132,7 @@ func newSynchronizer(
VerifierFactory: &ConsenterBlockVerifierCreator{},
BFTDelivererFactory: &bftDelivererCreator{},
Logger: logger,
JoinConfigBlock: joinConfigBlock,
}

default:
Expand Down
Loading