Skip to content

Commit

Permalink
[FAB-814] Introduce ChainCreators orderer config
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Dec 12, 2016
1 parent ce296d2 commit 746b873
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 64 deletions.
30 changes: 30 additions & 0 deletions orderer/common/bootstrap/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ const (

// DefaultConsensusType is the default value of ConsensusTypeKey
DefaultConsensusType = "solo"

// AcceptAllPolicyKey is the key of the AcceptAllPolicy
AcceptAllPolicyKey = "AcceptAllPolicy"
)

var (
// DefaultChainCreators is the default value of ChainCreatorsKey
DefaultChainCreators = []string{AcceptAllPolicyKey}
)

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

func (b *bootstrapper) encodeChainCreators() *cb.SignedConfigurationItem {
configItemKey := sharedconfig.ChainCreatorsKey
configItemValue := utils.MarshalOrPanic(&ab.ChainCreators{Policies: DefaultChainCreators})
modPolicy := configtx.DefaultModificationPolicyID

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, b.chainID, b.epoch)
configItem := utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, b.lastModified, modPolicy, configItemKey, configItemValue)
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
}

func (b *bootstrapper) encodeAcceptAllPolicy() *cb.SignedConfigurationItem {
configItemKey := AcceptAllPolicyKey
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.AcceptAllPolicy))
modPolicy := configtx.DefaultModificationPolicyID

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, b.chainID, b.epoch)
configItem := utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, b.lastModified, modPolicy, configItemKey, configItemValue)
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
}

func (b *bootstrapper) lockDefaultModificationPolicy() *cb.SignedConfigurationItem {
// Lock down the default modification policy to prevent any further policy modifications
configItemKey := configtx.DefaultModificationPolicyID
Expand All @@ -96,6 +124,8 @@ func (b *bootstrapper) GenesisBlock() (*cb.Block, error) {
configEnvelope := utils.MakeConfigurationEnvelope(
b.encodeConsensusType(),
b.encodeBatchSize(),
b.encodeChainCreators(),
b.encodeAcceptAllPolicy(),
b.lockDefaultModificationPolicy(),
)
payloadChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, configItemChainHeader.Version, b.chainID, b.epoch)
Expand Down
4 changes: 2 additions & 2 deletions orderer/common/bootstrap/static/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestGenesisBlockData(t *testing.T) {
expectedPayloadChainHeaderType := int32(cb.HeaderType_CONFIGURATION_TRANSACTION)
expectedChainHeaderVersion := msgVersion
expectedChainHeaderEpoch := uint64(0)
expectedConfigEnvelopeItemsLength := 3
expectedConfigEnvelopeItemsLength := 5
expectedConfigurationItemChainHeaderType := int32(cb.HeaderType_CONFIGURATION_ITEM)
expectedConfigurationItemChainHeaderVersion := msgVersion
expectedConfigurationItemType := cb.ConfigurationItem_Policy
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestGenesisBlockData(t *testing.T) {
t.Fatalf("Expected configuration envelope to have %d configuration item(s), got %d", expectedConfigEnvelopeItemsLength, len(configurationEnvelope.Items))
}

signedConfigurationItem := configurationEnvelope.Items[2]
signedConfigurationItem := configurationEnvelope.Items[4]
marshaledConfigurationItem := signedConfigurationItem.ConfigurationItem
configurationItem := &cb.ConfigurationItem{}
if err := proto.Unmarshal(marshaledConfigurationItem, configurationItem); err != nil {
Expand Down
22 changes: 22 additions & 0 deletions orderer/common/sharedconfig/sharedconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const ConsensusTypeKey = "ConsensusType"
// BatchSizeKey is the cb.ConfigurationItem type key name for the BatchSize message
const BatchSizeKey = "BatchSize"

// ChainCreatorsKey is the cb.ConfigurationItem type key name for the ChainCreators message
const ChainCreatorsKey = "ChainCreators"

var logger = logging.MustGetLogger("orderer/common/sharedconfig")

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

// BatchSize returns the maximum number of messages to include in a block
BatchSize() int

// ChainCreators returns the policy names which are allowed for chain creation
// This field is only set for the system ordering chain
ChainCreators() []string
}

type ordererConfig struct {
consensusType string
batchSize int
chainCreators []string
}

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

// ChainCreators returns the policy names which are allowed for chain creation
// This field is only set for the system ordering chain
func (pm *ManagerImpl) ChainCreators() []string {
return pm.config.chainCreators
}

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

pm.pendingConfig.batchSize = int(batchSize.Messages)
case ChainCreatorsKey:
chainCreators := &ab.ChainCreators{}
err := proto.Unmarshal(configItem.Value, chainCreators)
if err != nil {
return fmt.Errorf("Unmarshaling error for ChainCreator: %s", err)
}

pm.pendingConfig.chainCreators = chainCreators.Policies
}

return nil
Expand Down
102 changes: 53 additions & 49 deletions protos/common/common.pb.go

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

1 change: 1 addition & 0 deletions protos/common/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum HeaderType {
CONFIGURATION_TRANSACTION = 1; // Used for messages which reconfigure the chain
CONFIGURATION_ITEM = 2; // Used inside of the the reconfiguration message for signing over ConfigurationItems
ENDORSER_TRANSACTION = 3; // Used by the SDK to submit endorser based transactions
ORDERER_TRANSACTION = 4; // Used internally by the orderer for management
}

// This enum enlist indexes of the block metadata array
Expand Down
2 changes: 2 additions & 0 deletions protos/orderer/ab.pb.go

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

Loading

0 comments on commit 746b873

Please sign in to comment.