Skip to content

Commit

Permalink
Raft to BFT migration: draft
Browse files Browse the repository at this point in the history
Signed-off-by: May Rosenbaum <[email protected]>
  • Loading branch information
MayRosenbaum committed Dec 11, 2023
1 parent e2f1c5e commit f2ad291
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
13 changes: 12 additions & 1 deletion orderer/common/msgprocessor/maintenancefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
}
Expand Down
14 changes: 12 additions & 2 deletions orderer/consensus/etcdraft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
}

Expand All @@ -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())

}
}
Expand Down
9 changes: 9 additions & 0 deletions orderer/consensus/etcdraft/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)))
})
Expand Down
15 changes: 7 additions & 8 deletions orderer/consensus/etcdraft/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit f2ad291

Please sign in to comment.