Skip to content

Commit 3c916f5

Browse files
author
Jason Yellick
committed
[FAB-5808] Add configtx.Manager to immutable bndl
The immutable bundle does not need the configtx manager to actually parse the config or policies, but it does need a way authorize new configurations. Therefore, the channel config needs to be fed to the configtx.Manager, but without injecting a new dependency onto the mutable logic. This CR introduces a noop value and policy proposer so that the configtx.Manager code can continue to authorize configuration updates without injecting this new mutability dependency. Once there are no more dependencies on the configtx value/policy proposals, this noop implementation will be deleted. Change-Id: I4880602d9865fa6d38d136ea9562b4943ae2a41f Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 297d393 commit 3c916f5

File tree

1 file changed

+91
-6
lines changed

1 file changed

+91
-6
lines changed

common/channelconfig/channelconfig.go

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ package channelconfig
88

99
import (
1010
"github.com/hyperledger/fabric/common/cauthdsl"
11+
"github.com/hyperledger/fabric/common/config"
1112
oldchannelconfig "github.com/hyperledger/fabric/common/config/channel"
1213
oldmspconfig "github.com/hyperledger/fabric/common/config/channel/msp"
14+
"github.com/hyperledger/fabric/common/configtx"
15+
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
1316
"github.com/hyperledger/fabric/common/flogging"
1417
"github.com/hyperledger/fabric/common/policies"
1518
"github.com/hyperledger/fabric/msp"
1619
cb "github.com/hyperledger/fabric/protos/common"
20+
"github.com/hyperledger/fabric/protos/utils"
1721

22+
"github.com/golang/protobuf/proto"
1823
"github.com/pkg/errors"
1924
)
2025

@@ -30,9 +35,10 @@ const RootGroupKey = "Channel"
3035
// same value. The Bundle structure is immutable and will always be replaced in its
3136
// entirety, with new backing memory.
3237
type Bundle struct {
33-
policyManager policies.Manager
34-
mspManager msp.MSPManager
35-
rootConfig *oldchannelconfig.Root
38+
policyManager policies.Manager
39+
mspManager msp.MSPManager
40+
rootConfig *oldchannelconfig.Root
41+
configtxManager configtxapi.Manager
3642
}
3743

3844
// PolicyManager returns the policy manager constructed for this config
@@ -71,6 +77,74 @@ func (b *Bundle) ApplicationConfig() (oldchannelconfig.Application, bool) {
7177
return result, result != nil
7278
}
7379

80+
// ConfigtxManager returns the configtx.Manager for the channel
81+
func (b *Bundle) ConfigtxManager() configtxapi.Manager {
82+
return b.configtxManager
83+
}
84+
85+
type noopDeserializer struct{}
86+
87+
// Deserializer returns nil, nil
88+
func (nd noopDeserializer) Deserialize(key string, value []byte) (proto.Message, error) {
89+
return nil, nil
90+
}
91+
92+
type noopProposer struct {
93+
policyManager policies.Manager
94+
}
95+
96+
// BeginValueProposals returns a noop deserializer, and noop proposers for subgroups
97+
func (np noopProposer) BeginValueProposals(tx interface{}, groups []string) (config.ValueDeserializer, []config.ValueProposer, error) {
98+
proposers := make([]config.ValueProposer, len(groups))
99+
for i := range proposers {
100+
proposers[i] = noopProposer{}
101+
}
102+
return noopDeserializer{}, proposers, nil
103+
}
104+
105+
// BeginValueProposals returns a noop deserializer, and noop proposers for subgroups
106+
func (np noopProposer) BeginPolicyProposals(tx interface{}, groups []string) ([]policies.Proposer, error) {
107+
proposers := make([]policies.Proposer, len(groups))
108+
for i := range proposers {
109+
proposers[i] = noopProposer{}
110+
}
111+
return proposers, nil
112+
}
113+
114+
// ProposePolicy returns nil, nil
115+
func (np noopProposer) ProposePolicy(tx interface{}, name string, policy *cb.ConfigPolicy) (proto.Message, error) {
116+
return nil, nil
117+
}
118+
119+
// RollbackProposals is a no-op
120+
func (np noopProposer) RollbackProposals(tx interface{}) {}
121+
122+
// PreCommit returns nil
123+
func (np noopProposer) PreCommit(tx interface{}) error { return nil }
124+
125+
// CommitProposals is a no-op
126+
func (np noopProposer) CommitProposals(tx interface{}) {}
127+
128+
// ValueProposer returns noopProposer
129+
func (np noopProposer) ValueProposer() config.ValueProposer {
130+
return np
131+
}
132+
133+
// PolicyProposer returns noopProposer
134+
func (np noopProposer) PolicyProposer() policies.Proposer {
135+
return np
136+
}
137+
138+
// RootGroupKey returns RootGroupKey constant
139+
func (np noopProposer) RootGroupKey() string {
140+
return RootGroupKey
141+
}
142+
143+
// PolicyManager() returns the policy manager for considering config changes
144+
func (np noopProposer) PolicyManager() policies.Manager {
145+
return np.policyManager
146+
}
147+
74148
// NewBundle creates a new immutable bundle of configuration
75149
func NewBundle(config *cb.Config) (*Bundle, error) {
76150
mspConfigHandler := oldmspconfig.NewMSPConfigHandler()
@@ -100,9 +174,20 @@ func NewBundle(config *cb.Config) (*Bundle, error) {
100174
return nil, errors.Wrap(err, "initializing policymanager failed")
101175
}
102176

177+
env, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, "sanitycheck", nil, &cb.ConfigEnvelope{Config: config}, 0, 0)
178+
if err != nil {
179+
return nil, errors.Wrap(err, "creating envelope for configtx manager failed")
180+
}
181+
182+
configtxManager, err := configtx.NewManagerImpl(env, noopProposer{}, nil)
183+
if err != nil {
184+
return nil, errors.Wrap(err, "initializing configtx manager failed")
185+
}
186+
103187
return &Bundle{
104-
mspManager: mspConfigHandler,
105-
policyManager: policyManager,
106-
rootConfig: rootConfig,
188+
mspManager: mspConfigHandler,
189+
policyManager: policyManager,
190+
rootConfig: rootConfig,
191+
configtxManager: configtxManager,
107192
}, nil
108193
}

0 commit comments

Comments
 (0)