From 0207578ab3c393174f8299d43570c6b34b1ec3e0 Mon Sep 17 00:00:00 2001 From: May Rosenbaum Date: Mon, 11 Dec 2023 20:48:22 +0200 Subject: [PATCH] Raft to BFT migration: draft Signed-off-by: May Rosenbaum --- orderer/common/msgprocessor/maintenancefilter.go | 13 ++++++++++++- orderer/consensus/etcdraft/chain.go | 14 ++++++++++++-- orderer/consensus/etcdraft/chain_test.go | 9 +++++++++ orderer/consensus/etcdraft/util.go | 15 +++++++-------- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/orderer/common/msgprocessor/maintenancefilter.go b/orderer/common/msgprocessor/maintenancefilter.go index 23f5eb617ab..0ac81de69ec 100644 --- a/orderer/common/msgprocessor/maintenancefilter.go +++ b/orderer/common/msgprocessor/maintenancefilter.go @@ -8,6 +8,9 @@ package msgprocessor import ( "bytes" + "fmt" + + "github.com/hyperledger/fabric-protos-go/orderer/smartbft" "github.com/golang/protobuf/proto" cb "github.com/hyperledger/fabric-protos-go/common" @@ -45,7 +48,7 @@ func NewMaintenanceFilter(support MaintenanceFilterSupport, bccsp bccsp.BCCSP) * permittedTargetConsensusTypes: make(map[string]bool), bccsp: bccsp, } - mf.permittedTargetConsensusTypes["etcdraft"] = true + //mf.permittedTargetConsensusTypes["etcdraft"] = true mf.permittedTargetConsensusTypes["BFT"] = true return mf } @@ -140,6 +143,14 @@ func (mf *MaintenanceFilter) inspect(configEnvelope *cb.ConfigEnvelope, ordererC } } + if nextOrdererConfig.ConsensusType() == "BFT" { + updatedMetadata := &smartbft.Options{} + if err := proto.Unmarshal(nextOrdererConfig.ConsensusMetadata(), updatedMetadata); err != nil { + return errors.Wrap(err, "failed to unmarshal BFT metadata configuration") + } + fmt.Printf("##########the bft metadata is: %+v########\n", updatedMetadata) + } + logger.Infof("[channel: %s] consensus-type migration: about to change from %s to %s", mf.support.ChannelID(), ordererConfig.ConsensusType(), nextOrdererConfig.ConsensusType()) } diff --git a/orderer/consensus/etcdraft/chain.go b/orderer/consensus/etcdraft/chain.go index 7dd4da6ce7a..bad0e134496 100644 --- a/orderer/consensus/etcdraft/chain.go +++ b/orderer/consensus/etcdraft/chain.go @@ -1119,7 +1119,13 @@ func (c *Chain) detectConfChange(block *common.Block) *MembershipChanges { // if the consensusType is bft, then configMetadata which represents the raft metadata should be nil configMetadata, consensusType := c.newConfigMetadata(block) - c.logger.Infof("Detected configuration change: consensusType is: %s, configMetadata is: %v", consensusType.Type, configMetadata) + c.logger.Infof("Detected configuration change: consensusType is: %s, configMetadata is: %v", consensusType, configMetadata) + + if consensusType == nil { + fmt.Printf("Hi May - you got it! the consensus type is nil.\n") + c.logger.Infof("ConsensusType is %v", consensusType) + return nil + } if consensusType.Type != "etcdraft" { if consensusType.Type == "BFT" { @@ -1442,9 +1448,13 @@ func (c *Chain) getInFlightConfChange() *raftpb.ConfChange { func (c *Chain) newConfigMetadata(block *common.Block) (*etcdraft.ConfigMetadata, *orderer.ConsensusType) { c.logger.Infof("Extract config metadata from the configuration block") metadata, consensusType, err := ConsensusMetadataFromConfigBlock(block) + fmt.Printf("-------newConfigMetadata: the metadata is: %v-------\n", metadata) + fmt.Printf("-------newConfigMetadata: the consensusType is: %v-------\n", consensusType) + fmt.Printf("-------newConfigMetadata: the err is: %v-------\n", err) if err != nil { c.logger.Panicf("error reading consensus metadata: %s", err) } + // c.logger.Infof("Extracted config metadata from the configuration block: metadata is: %v, consensusType is: %s", metadata, consensusType.Type) return metadata, consensusType } @@ -1467,7 +1477,7 @@ func (c *Chain) ValidateConsensusMetadata(oldOrdererConfig, newOrdererConfig cha return nil } else { c.logger.Panicf("illegal consensus type detected during consensus metadata validation: %s", newOrdererConfig.ConsensusType()) - panic("illegal consensus type detected during consensus metadata validation") + return errors.Errorf("illegal consensus type detected during consensus metadata validation: %s", newOrdererConfig.ConsensusType()) } } diff --git a/orderer/consensus/etcdraft/chain_test.go b/orderer/consensus/etcdraft/chain_test.go index bc1ea8a4e16..8f7b93fa05f 100644 --- a/orderer/consensus/etcdraft/chain_test.go +++ b/orderer/consensus/etcdraft/chain_test.go @@ -552,11 +552,17 @@ var _ = Describe("Chain", func() { }, "ConsensusType": { Version: 4, + Value: marshalOrPanic(&orderer.ConsensusType{ + Type: "etcdraft", + }), }, } oldValues := map[string]*common.ConfigValue{ "ConsensusType": { Version: 4, + Value: marshalOrPanic(&orderer.ConsensusType{ + Type: "etcdraft", + }), }, } configEnv = newConfigEnv(channelID, @@ -569,12 +575,15 @@ var _ = Describe("Chain", func() { Context("without revalidation (i.e. correct config sequence)", func() { Context("without pending normal envelope", func() { It("should create a config block and no normal block", func() { + fmt.Printf("$$$$$$$$$$$$$$$$$$$$$-line1-$$$$$$$$$$$$\n") err := chain.Configure(configEnv, configSeq) Expect(err).NotTo(HaveOccurred()) Expect(fakeFields.fakeConfigProposalsReceived.AddCallCount()).To(Equal(1)) Expect(fakeFields.fakeConfigProposalsReceived.AddArgsForCall(0)).To(Equal(float64(1))) + fmt.Printf("$$$$$$$$$$$$$$$$$$$$$-line2-$$$$$$$$$$$$\n") Eventually(support.WriteConfigBlockCallCount, LongEventualTimeout).Should(Equal(1)) Consistently(support.WriteBlockCallCount).Should(Equal(0)) + fmt.Printf("$$$$$$$$$$$$$$$$$$$$$-line3-$$$$$$$$$$$$\n") Expect(fakeFields.fakeCommittedBlockNumber.SetCallCount()).Should(Equal(2)) // incl. initial call Expect(fakeFields.fakeCommittedBlockNumber.SetArgsForCall(1)).Should(Equal(float64(1))) }) diff --git a/orderer/consensus/etcdraft/util.go b/orderer/consensus/etcdraft/util.go index 327b9d8f8ac..a898e0dc1fe 100644 --- a/orderer/consensus/etcdraft/util.go +++ b/orderer/consensus/etcdraft/util.go @@ -9,10 +9,9 @@ package etcdraft import ( "crypto/x509" "encoding/pem" + "fmt" "time" - "github.com/hyperledger/fabric-protos-go/orderer/smartbft" - "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric-protos-go/common" "github.com/hyperledger/fabric-protos-go/orderer" @@ -94,12 +93,8 @@ func MetadataFromConfigValue(configValue *common.ConfigValue) (*etcdraft.ConfigM if consensusTypeValue.Type != "etcdraft" { if consensusTypeValue.Type == "BFT" { - updatedBftMetadata := &smartbft.Options{} - if err := proto.Unmarshal(consensusTypeValue.Metadata, updatedBftMetadata); err != nil { - return nil, nil, errors.Wrap(err, "failed to unmarshal updated (new) bft metadata configuration") - } + return nil, consensusTypeValue, nil } - return nil, consensusTypeValue, nil } updatedMetadata := &etcdraft.ConfigMetadata{} @@ -120,7 +115,6 @@ func MetadataFromConfigUpdate(update *common.ConfigUpdate) (*etcdraft.ConfigMeta } } } - if update.WriteSet != nil && update.WriteSet.Groups != nil { if ordererConfigGroup, ok := update.WriteSet.Groups["Orderer"]; ok { if val, ok := ordererConfigGroup.Values["ConsensusType"]; ok { @@ -204,6 +198,11 @@ func ConsensusMetadataFromConfigBlock(block *common.Block) (*etcdraft.ConfigMeta return nil, nil, errors.Wrap(err, "could not read config update") } + fmt.Printf("----------IM HERE 1-------------") + metadata, consensusType, err := MetadataFromConfigUpdate(configUpdate) + fmt.Printf("-------ConsensusMetadataFromConfigBlock: the metadata is: %v-------\n", metadata) + fmt.Printf("-------ConsensusMetadataFromConfigBlock: the consensusType is: %v-------\n", consensusType) + fmt.Printf("-------ConsensusMetadataFromConfigBlock: the err is: %v-------\n", err) return MetadataFromConfigUpdate(configUpdate) }