Skip to content

Commit

Permalink
[FAB-18048] Implement addition and removal of consenters from etcdraft (
Browse files Browse the repository at this point in the history
#32)

orderer configuration

Signed-off-by: Tiffany Harris <[email protected]>
  • Loading branch information
stephyee authored Jul 8, 2020
1 parent 4bcdec8 commit 26dfec1
Show file tree
Hide file tree
Showing 2 changed files with 878 additions and 0 deletions.
77 changes: 77 additions & 0 deletions configtx/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"errors"
"fmt"
"math"
"reflect"
"time"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -246,6 +247,82 @@ func (o *OrdererGroup) SetConfiguration(ord Orderer) error {
return nil
}

// AddConsenter adds a consenter to an etcdraft configuration.
func (o *OrdererGroup) AddConsenter(consenter orderer.Consenter) error {
cfg, err := o.Configuration()
if err != nil {
return err
}

if cfg.OrdererType != orderer.ConsensusTypeEtcdRaft {
return fmt.Errorf("consensus type %s is not etcdraft", cfg.OrdererType)
}

for _, c := range cfg.EtcdRaft.Consenters {
if reflect.DeepEqual(c, consenter) {
return nil
}
}

cfg.EtcdRaft.Consenters = append(cfg.EtcdRaft.Consenters, consenter)

consensusMetadata, err := marshalEtcdRaftMetadata(cfg.EtcdRaft)
if err != nil {
return fmt.Errorf("marshaling etcdraft metadata: %v", err)
}

consensusState, ok := ob.ConsensusType_State_value[string(cfg.State)]
if !ok {
return fmt.Errorf("unknown consensus state '%s'", cfg.State)
}

err = setValue(o.ordererGroup, consensusTypeValue(cfg.OrdererType, consensusMetadata, consensusState), AdminsPolicyKey)
if err != nil {
return err
}

return nil
}

// RemoveConsenter removes a consenter from an etcdraft configuration.
func (o *OrdererGroup) RemoveConsenter(consenter orderer.Consenter) error {
cfg, err := o.Configuration()
if err != nil {
return err
}

if cfg.OrdererType != orderer.ConsensusTypeEtcdRaft {
return fmt.Errorf("consensus type %s is not etcdraft", cfg.OrdererType)
}

consenters := cfg.EtcdRaft.Consenters[:]
for i, c := range cfg.EtcdRaft.Consenters {
if reflect.DeepEqual(c, consenter) {
consenters = append(consenters[:i], consenters[i+1:]...)
break
}
}

cfg.EtcdRaft.Consenters = consenters

consensusMetadata, err := marshalEtcdRaftMetadata(cfg.EtcdRaft)
if err != nil {
return fmt.Errorf("marshaling etcdraft metadata: %v", err)
}

consensusState, ok := ob.ConsensusType_State_value[string(cfg.State)]
if !ok {
return fmt.Errorf("unknown consensus state '%s'", cfg.State)
}

err = setValue(o.ordererGroup, consensusTypeValue(cfg.OrdererType, consensusMetadata, consensusState), AdminsPolicyKey)
if err != nil {
return err
}

return nil
}

// Capabilities returns a map of enabled orderer capabilities
// from the updated config.
func (o *OrdererGroup) Capabilities() ([]string, error) {
Expand Down
Loading

0 comments on commit 26dfec1

Please sign in to comment.