Skip to content

Commit 746b873

Browse files
author
Jason Yellick
committed
[FAB-814] Introduce ChainCreators orderer config
This changeset adds an orderer configuration item with key ChainCreators. This configuration item should only be set for the system chain, and will allow the specification of chain creation policies for an orderer. This changeset simply introduces the new configuration item but does not utilize it in any way (so as to simplify the diff). An additional changeset follows which utilizes this new config. This is the server side half of the FAB-814 item but does not complete it. Change-Id: Ia761d4a05d5a89875a99b30210744f31ad7112d5 Signed-off-by: Jason Yellick <[email protected]>
1 parent ce296d2 commit 746b873

File tree

8 files changed

+172
-64
lines changed

8 files changed

+172
-64
lines changed

orderer/common/bootstrap/static/static.go

+30
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ const (
4747

4848
// DefaultConsensusType is the default value of ConsensusTypeKey
4949
DefaultConsensusType = "solo"
50+
51+
// AcceptAllPolicyKey is the key of the AcceptAllPolicy
52+
AcceptAllPolicyKey = "AcceptAllPolicy"
53+
)
54+
55+
var (
56+
// DefaultChainCreators is the default value of ChainCreatorsKey
57+
DefaultChainCreators = []string{AcceptAllPolicyKey}
5058
)
5159

5260
// New returns a new static bootstrap helper.
@@ -78,6 +86,26 @@ func (b *bootstrapper) encodeBatchSize() *cb.SignedConfigurationItem {
7886
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
7987
}
8088

89+
func (b *bootstrapper) encodeChainCreators() *cb.SignedConfigurationItem {
90+
configItemKey := sharedconfig.ChainCreatorsKey
91+
configItemValue := utils.MarshalOrPanic(&ab.ChainCreators{Policies: DefaultChainCreators})
92+
modPolicy := configtx.DefaultModificationPolicyID
93+
94+
configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, b.chainID, b.epoch)
95+
configItem := utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, b.lastModified, modPolicy, configItemKey, configItemValue)
96+
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
97+
}
98+
99+
func (b *bootstrapper) encodeAcceptAllPolicy() *cb.SignedConfigurationItem {
100+
configItemKey := AcceptAllPolicyKey
101+
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.AcceptAllPolicy))
102+
modPolicy := configtx.DefaultModificationPolicyID
103+
104+
configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, b.chainID, b.epoch)
105+
configItem := utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, b.lastModified, modPolicy, configItemKey, configItemValue)
106+
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
107+
}
108+
81109
func (b *bootstrapper) lockDefaultModificationPolicy() *cb.SignedConfigurationItem {
82110
// Lock down the default modification policy to prevent any further policy modifications
83111
configItemKey := configtx.DefaultModificationPolicyID
@@ -96,6 +124,8 @@ func (b *bootstrapper) GenesisBlock() (*cb.Block, error) {
96124
configEnvelope := utils.MakeConfigurationEnvelope(
97125
b.encodeConsensusType(),
98126
b.encodeBatchSize(),
127+
b.encodeChainCreators(),
128+
b.encodeAcceptAllPolicy(),
99129
b.lockDefaultModificationPolicy(),
100130
)
101131
payloadChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, configItemChainHeader.Version, b.chainID, b.epoch)

orderer/common/bootstrap/static/static_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestGenesisBlockData(t *testing.T) {
5959
expectedPayloadChainHeaderType := int32(cb.HeaderType_CONFIGURATION_TRANSACTION)
6060
expectedChainHeaderVersion := msgVersion
6161
expectedChainHeaderEpoch := uint64(0)
62-
expectedConfigEnvelopeItemsLength := 3
62+
expectedConfigEnvelopeItemsLength := 5
6363
expectedConfigurationItemChainHeaderType := int32(cb.HeaderType_CONFIGURATION_ITEM)
6464
expectedConfigurationItemChainHeaderVersion := msgVersion
6565
expectedConfigurationItemType := cb.ConfigurationItem_Policy
@@ -110,7 +110,7 @@ func TestGenesisBlockData(t *testing.T) {
110110
t.Fatalf("Expected configuration envelope to have %d configuration item(s), got %d", expectedConfigEnvelopeItemsLength, len(configurationEnvelope.Items))
111111
}
112112

113-
signedConfigurationItem := configurationEnvelope.Items[2]
113+
signedConfigurationItem := configurationEnvelope.Items[4]
114114
marshaledConfigurationItem := signedConfigurationItem.ConfigurationItem
115115
configurationItem := &cb.ConfigurationItem{}
116116
if err := proto.Unmarshal(marshaledConfigurationItem, configurationItem); err != nil {

orderer/common/sharedconfig/sharedconfig.go

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const ConsensusTypeKey = "ConsensusType"
3232
// BatchSizeKey is the cb.ConfigurationItem type key name for the BatchSize message
3333
const BatchSizeKey = "BatchSize"
3434

35+
// ChainCreatorsKey is the cb.ConfigurationItem type key name for the ChainCreators message
36+
const ChainCreatorsKey = "ChainCreators"
37+
3538
var logger = logging.MustGetLogger("orderer/common/sharedconfig")
3639

3740
func init() {
@@ -48,11 +51,16 @@ type Manager interface {
4851

4952
// BatchSize returns the maximum number of messages to include in a block
5053
BatchSize() int
54+
55+
// ChainCreators returns the policy names which are allowed for chain creation
56+
// This field is only set for the system ordering chain
57+
ChainCreators() []string
5158
}
5259

5360
type ordererConfig struct {
5461
consensusType string
5562
batchSize int
63+
chainCreators []string
5664
}
5765

5866
// ManagerImpl is an implementation of Manager and configtx.ConfigHandler
@@ -79,6 +87,12 @@ func (pm *ManagerImpl) BatchSize() int {
7987
return pm.config.batchSize
8088
}
8189

90+
// ChainCreators returns the policy names which are allowed for chain creation
91+
// This field is only set for the system ordering chain
92+
func (pm *ManagerImpl) ChainCreators() []string {
93+
return pm.config.chainCreators
94+
}
95+
8296
// BeginConfig is used to start a new configuration proposal
8397
func (pm *ManagerImpl) BeginConfig() {
8498
if pm.pendingConfig != nil {
@@ -135,6 +149,14 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
135149
}
136150

137151
pm.pendingConfig.batchSize = int(batchSize.Messages)
152+
case ChainCreatorsKey:
153+
chainCreators := &ab.ChainCreators{}
154+
err := proto.Unmarshal(configItem.Value, chainCreators)
155+
if err != nil {
156+
return fmt.Errorf("Unmarshaling error for ChainCreator: %s", err)
157+
}
158+
159+
pm.pendingConfig.chainCreators = chainCreators.Policies
138160
}
139161

140162
return nil

protos/common/common.pb.go

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

protos/common/common.proto

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum HeaderType {
3939
CONFIGURATION_TRANSACTION = 1; // Used for messages which reconfigure the chain
4040
CONFIGURATION_ITEM = 2; // Used inside of the the reconfiguration message for signing over ConfigurationItems
4141
ENDORSER_TRANSACTION = 3; // Used by the SDK to submit endorser based transactions
42+
ORDERER_TRANSACTION = 4; // Used internally by the orderer for management
4243
}
4344

4445
// This enum enlist indexes of the block metadata array

protos/orderer/ab.pb.go

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

0 commit comments

Comments
 (0)