Skip to content

Commit 1e92f78

Browse files
author
Jason Yellick
committed
[FAB-1710] Add orderer addresses to chain config
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]>
1 parent 522c040 commit 1e92f78

File tree

5 files changed

+115
-44
lines changed

5 files changed

+115
-44
lines changed

common/chainconfig/chainconfig.go

+18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ const (
3333

3434
// BlockDataHashingStructureKey is the cb.ConfigurationItem type key name for the BlockDataHashingStructure message
3535
BlockDataHashingStructureKey = "BlockDataHashingStructure"
36+
37+
// OrdererAddressesKey is the cb.ConfigurationItem type key name for the OrdererAddresses message
38+
OrdererAddressesKey = "OrdererAddresses"
3639
)
3740

3841
// Hashing algorithm types
@@ -55,11 +58,15 @@ type Descriptor interface {
5558
// BlockDataHashingStructureWidth returns the width to use when constructing the
5659
// Merkle tree to compute the BlockData hash
5760
BlockDatahashingStructureWidth() int
61+
62+
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
63+
OrdererAddresses() []string
5864
}
5965

6066
type chainConfig struct {
6167
hashingAlgorithm func(input []byte) []byte
6268
blockDataHashingStructureWidth uint32
69+
ordererAddresses []string
6370
}
6471

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

96+
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
97+
func (pm *DescriptorImpl) OrdererAddresses() []string {
98+
return pm.config.ordererAddresses
99+
}
100+
89101
// BeginConfig is used to start a new configuration proposal
90102
func (pm *DescriptorImpl) BeginConfig() {
91103
if pm.pendingConfig != nil {
@@ -137,6 +149,12 @@ func (pm *DescriptorImpl) ProposeConfig(configItem *cb.ConfigurationItem) error
137149
}
138150

139151
pm.pendingConfig.blockDataHashingStructureWidth = blockDataHashingStructure.Width
152+
case OrdererAddressesKey:
153+
ordererAddresses := &cb.OrdererAddresses{}
154+
if err := proto.Unmarshal(configItem.Value, ordererAddresses); err != nil {
155+
return fmt.Errorf("Unmarshaling error for HashingAlgorithm: %s", err)
156+
}
157+
pm.pendingConfig.ordererAddresses = ordererAddresses.Addresses
140158
default:
141159
logger.Warningf("Uknown Chain configuration item with key %s", configItem.Key)
142160
}

common/chainconfig/chainconfig_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package chainconfig
1818

1919
import (
20+
"reflect"
2021
"testing"
2122

2223
cb "github.com/hyperledger/fabric/protos/common"
@@ -145,3 +146,35 @@ func TestBlockDataHashingStructure(t *testing.T) {
145146
t.Fatalf("Unexpected width, got %d expected %d", newWidth, expectedWidth)
146147
}
147148
}
149+
150+
func TestOrdererAddresses(t *testing.T) {
151+
expectedResult := []string{"foo", "bar:1234"}
152+
invalidMessage := &cb.ConfigurationItem{
153+
Type: cb.ConfigurationItem_Chain,
154+
Key: BlockDataHashingStructureKey,
155+
Value: []byte("Garbage Data"),
156+
}
157+
validMessage := &cb.ConfigurationItem{
158+
Type: cb.ConfigurationItem_Chain,
159+
Key: OrdererAddressesKey,
160+
Value: utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: expectedResult}),
161+
}
162+
m := NewDescriptorImpl()
163+
m.BeginConfig()
164+
165+
err := m.ProposeConfig(invalidMessage)
166+
if err == nil {
167+
t.Fatalf("Should have failed on invalid message")
168+
}
169+
170+
err = m.ProposeConfig(validMessage)
171+
if err != nil {
172+
t.Fatalf("Error applying valid config: %s", err)
173+
}
174+
175+
m.CommitConfig()
176+
177+
if newAddrs := m.OrdererAddresses(); !reflect.DeepEqual(newAddrs, expectedResult) {
178+
t.Fatalf("Unexpected width, got %s expected %s", newAddrs, expectedResult)
179+
}
180+
}

protos/common/common.pb.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/common/configuration.pb.go

+57-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/common/configuration.proto

+6
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,9 @@ message BlockDataHashingStructure {
132132
// in order to replicate flat hashing, set this width to MAX_UINT32
133133
uint32 width = 1;
134134
}
135+
136+
// OrdererAddresses is encoded into the configuration transaction as a configuration item of type Chain
137+
// with a Key of "OrdererAddresses" and a Value of OrdererAddresses as marshaled protobuf bytes
138+
message OrdererAddresses {
139+
repeated string addresses = 1;
140+
}

0 commit comments

Comments
 (0)