Skip to content

Commit

Permalink
[FAB-1710] Add orderer addresses to chain config
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1710

This adds the proto support for listing the orderer addresses as
a configuration item of type Chain.  It also implements the chainconfig
Handler for this type to expose it to consumers.

This changeset does not actually set or utilize the type, simply adds
it.

Change-Id: I225d859b4b31df8bde9afec72e1f9d22c7cfe174
Signed-off-by: Jason Yellick <[email protected]>
  • Loading branch information
Jason Yellick committed Jan 17, 2017
1 parent 522c040 commit 1e92f78
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 44 deletions.
18 changes: 18 additions & 0 deletions common/chainconfig/chainconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (

// BlockDataHashingStructureKey is the cb.ConfigurationItem type key name for the BlockDataHashingStructure message
BlockDataHashingStructureKey = "BlockDataHashingStructure"

// OrdererAddressesKey is the cb.ConfigurationItem type key name for the OrdererAddresses message
OrdererAddressesKey = "OrdererAddresses"
)

// Hashing algorithm types
Expand All @@ -55,11 +58,15 @@ type Descriptor interface {
// BlockDataHashingStructureWidth returns the width to use when constructing the
// Merkle tree to compute the BlockData hash
BlockDatahashingStructureWidth() int

// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
OrdererAddresses() []string
}

type chainConfig struct {
hashingAlgorithm func(input []byte) []byte
blockDataHashingStructureWidth uint32
ordererAddresses []string
}

// DescriptorImpl is an implementation of Manager and configtx.ConfigHandler
Expand All @@ -86,6 +93,11 @@ func (pm *DescriptorImpl) BlockDataHashingStructureWidth() uint32 {
return pm.config.blockDataHashingStructureWidth
}

// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
func (pm *DescriptorImpl) OrdererAddresses() []string {
return pm.config.ordererAddresses
}

// BeginConfig is used to start a new configuration proposal
func (pm *DescriptorImpl) BeginConfig() {
if pm.pendingConfig != nil {
Expand Down Expand Up @@ -137,6 +149,12 @@ func (pm *DescriptorImpl) ProposeConfig(configItem *cb.ConfigurationItem) error
}

pm.pendingConfig.blockDataHashingStructureWidth = blockDataHashingStructure.Width
case OrdererAddressesKey:
ordererAddresses := &cb.OrdererAddresses{}
if err := proto.Unmarshal(configItem.Value, ordererAddresses); err != nil {
return fmt.Errorf("Unmarshaling error for HashingAlgorithm: %s", err)
}
pm.pendingConfig.ordererAddresses = ordererAddresses.Addresses
default:
logger.Warningf("Uknown Chain configuration item with key %s", configItem.Key)
}
Expand Down
33 changes: 33 additions & 0 deletions common/chainconfig/chainconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package chainconfig

import (
"reflect"
"testing"

cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -145,3 +146,35 @@ func TestBlockDataHashingStructure(t *testing.T) {
t.Fatalf("Unexpected width, got %d expected %d", newWidth, expectedWidth)
}
}

func TestOrdererAddresses(t *testing.T) {
expectedResult := []string{"foo", "bar:1234"}
invalidMessage := &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Chain,
Key: BlockDataHashingStructureKey,
Value: []byte("Garbage Data"),
}
validMessage := &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Chain,
Key: OrdererAddressesKey,
Value: utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: expectedResult}),
}
m := NewDescriptorImpl()
m.BeginConfig()

err := m.ProposeConfig(invalidMessage)
if err == nil {
t.Fatalf("Should have failed on invalid message")
}

err = m.ProposeConfig(validMessage)
if err != nil {
t.Fatalf("Error applying valid config: %s", err)
}

m.CommitConfig()

if newAddrs := m.OrdererAddresses(); !reflect.DeepEqual(newAddrs, expectedResult) {
t.Fatalf("Unexpected width, got %s expected %s", newAddrs, expectedResult)
}
}
1 change: 1 addition & 0 deletions protos/common/common.pb.go

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

101 changes: 57 additions & 44 deletions protos/common/configuration.pb.go

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

6 changes: 6 additions & 0 deletions protos/common/configuration.proto
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ message BlockDataHashingStructure {
// in order to replicate flat hashing, set this width to MAX_UINT32
uint32 width = 1;
}

// OrdererAddresses is encoded into the configuration transaction as a configuration item of type Chain
// with a Key of "OrdererAddresses" and a Value of OrdererAddresses as marshaled protobuf bytes
message OrdererAddresses {
repeated string addresses = 1;
}

0 comments on commit 1e92f78

Please sign in to comment.