Skip to content

Commit

Permalink
Raft to BFT migration: functions + tests updates
Browse files Browse the repository at this point in the history
Signed-off-by: May Rosenbaum <mayro1595@gmail.com>
  • Loading branch information
MayRosenbaum committed Jan 8, 2024
1 parent 2b1cd0e commit b3d82c2
Show file tree
Hide file tree
Showing 8 changed files with 508 additions and 360 deletions.
487 changes: 187 additions & 300 deletions integration/raft/migration_test.go

Large diffs are not rendered by default.

75 changes: 69 additions & 6 deletions orderer/common/msgprocessor/maintenancefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ package msgprocessor

import (
"bytes"
"time"

"github.com/SmartBFT-Go/consensus/pkg/types"

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/orderer"
protoetcdraft "github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
"github.com/hyperledger/fabric-protos-go/orderer/smartbft"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/configtx"
Expand Down Expand Up @@ -45,7 +48,6 @@ func NewMaintenanceFilter(support MaintenanceFilterSupport, bccsp bccsp.BCCSP) *
permittedTargetConsensusTypes: make(map[string]bool),
bccsp: bccsp,
}
mf.permittedTargetConsensusTypes["etcdraft"] = true
mf.permittedTargetConsensusTypes["BFT"] = true
return mf
}
Expand Down Expand Up @@ -117,7 +119,7 @@ func (mf *MaintenanceFilter) inspect(configEnvelope *cb.ConfigEnvelope, ordererC
}

// ConsensusType.Type can only change in maintenance-mode, and only within the set of permitted types.
// Note: only solo to etcdraft transitions are supported.
// Note: only etcdraft to BFT transitions are supported.
if ordererConfig.ConsensusType() != nextOrdererConfig.ConsensusType() {
if ordererConfig.ConsensusState() == orderer.ConsensusType_STATE_NORMAL {
return errors.Errorf("attempted to change consensus type from %s to %s, but current config ConsensusType.State is not in maintenance mode",
Expand All @@ -133,10 +135,15 @@ func (mf *MaintenanceFilter) inspect(configEnvelope *cb.ConfigEnvelope, ordererC
ordererConfig.ConsensusType(), nextOrdererConfig.ConsensusType())
}

if nextOrdererConfig.ConsensusType() == "etcdraft" {
updatedMetadata := &protoetcdraft.ConfigMetadata{}
if nextOrdererConfig.ConsensusType() == "BFT" {
updatedMetadata := &smartbft.Options{}
if err := proto.Unmarshal(nextOrdererConfig.ConsensusMetadata(), updatedMetadata); err != nil {
return errors.Wrap(err, "failed to unmarshal etcdraft metadata configuration")
return errors.Wrap(err, "failed to unmarshal BFT metadata configuration")
}

_, err := validateBFTMetadataOptions(1, updatedMetadata)
if updatedMetadata.XXX_unrecognized != nil || err != nil {
return errors.New("invalid BFT metadata configuration")
}
}

Expand Down Expand Up @@ -197,3 +204,59 @@ func (mf *MaintenanceFilter) ensureConsensusTypeChangeOnly(configEnvelope *cb.Co

return nil
}

func validateBFTMetadataOptions(selfID uint64, options *smartbft.Options) (types.Configuration, error) {
var err error

config := types.DefaultConfig
config.SelfID = selfID

if options == nil {
return config, errors.New("config metadata options field is nil")
}

config.RequestBatchMaxCount = options.RequestBatchMaxCount
config.RequestBatchMaxBytes = options.RequestBatchMaxBytes
if config.RequestBatchMaxInterval, err = time.ParseDuration(options.RequestBatchMaxInterval); err != nil {
return config, errors.Wrap(err, "bad config metadata option RequestBatchMaxInterval")
}
config.IncomingMessageBufferSize = options.IncomingMessageBufferSize
config.RequestPoolSize = options.RequestPoolSize
if config.RequestForwardTimeout, err = time.ParseDuration(options.RequestForwardTimeout); err != nil {
return config, errors.Wrap(err, "bad config metadata option RequestForwardTimeout")
}
if config.RequestComplainTimeout, err = time.ParseDuration(options.RequestComplainTimeout); err != nil {
return config, errors.Wrap(err, "bad config metadata option RequestComplainTimeout")
}
if config.RequestAutoRemoveTimeout, err = time.ParseDuration(options.RequestAutoRemoveTimeout); err != nil {
return config, errors.Wrap(err, "bad config metadata option RequestAutoRemoveTimeout")
}
if config.ViewChangeResendInterval, err = time.ParseDuration(options.ViewChangeResendInterval); err != nil {
return config, errors.Wrap(err, "bad config metadata option ViewChangeResendInterval")
}
if config.ViewChangeTimeout, err = time.ParseDuration(options.ViewChangeTimeout); err != nil {
return config, errors.Wrap(err, "bad config metadata option ViewChangeTimeout")
}
if config.LeaderHeartbeatTimeout, err = time.ParseDuration(options.LeaderHeartbeatTimeout); err != nil {
return config, errors.Wrap(err, "bad config metadata option LeaderHeartbeatTimeout")
}
config.LeaderHeartbeatCount = options.LeaderHeartbeatCount
if config.CollectTimeout, err = time.ParseDuration(options.CollectTimeout); err != nil {
return config, errors.Wrap(err, "bad config metadata option CollectTimeout")
}
config.SyncOnStart = options.SyncOnStart
config.SpeedUpViewChange = options.SpeedUpViewChange

config.LeaderRotation = false
config.DecisionsPerLeader = 0

if err = config.Validate(); err != nil {
return config, errors.Wrap(err, "config validation failed")
}

if options.RequestMaxBytes == 0 {
config.RequestMaxBytes = config.RequestBatchMaxBytes
}

return config, nil
}
Loading

0 comments on commit b3d82c2

Please sign in to comment.