@@ -20,7 +20,7 @@ import (
20
20
"fmt"
21
21
"math"
22
22
23
- "github.com/hyperledger/fabric/common/configvalues/api "
23
+ api "github.com/hyperledger/fabric/common/configvalues"
24
24
"github.com/hyperledger/fabric/common/configvalues/channel/application"
25
25
"github.com/hyperledger/fabric/common/configvalues/channel/orderer"
26
26
"github.com/hyperledger/fabric/common/util"
@@ -45,7 +45,7 @@ var Schema = &cb.ConfigGroupSchema{
45
45
},
46
46
}
47
47
48
- // Chain config keys
48
+ // Channel config keys
49
49
const (
50
50
// HashingAlgorithmKey is the cb.ConfigItem type key name for the HashingAlgorithm message
51
51
HashingAlgorithmKey = "HashingAlgorithm"
@@ -63,87 +63,100 @@ const (
63
63
SHA3Shake256 = "SHAKE256"
64
64
)
65
65
66
- var logger = logging .MustGetLogger ("configtx/handlers/chainconfig " )
66
+ var logger = logging .MustGetLogger ("configvalues/channel " )
67
67
68
- type chainConfig struct {
68
+ type ConfigReader interface {
69
+ // HashingAlgorithm returns the default algorithm to be used when hashing
70
+ // such as computing block hashes, and CreationPolicy digests
71
+ HashingAlgorithm () func (input []byte ) []byte
72
+
73
+ // BlockDataHashingStructureWidth returns the width to use when constructing the
74
+ // Merkle tree to compute the BlockData hash
75
+ BlockDataHashingStructureWidth () uint32
76
+
77
+ // OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
78
+ OrdererAddresses () []string
79
+ }
80
+
81
+ type values struct {
69
82
hashingAlgorithm func (input []byte ) []byte
70
83
blockDataHashingStructureWidth uint32
71
84
ordererAddresses []string
72
85
}
73
86
74
87
// SharedConfigImpl is an implementation of Manager and configtx.ConfigHandler
75
88
// In general, it should only be referenced as an Impl for the configtx.Manager
76
- type SharedConfigImpl struct {
77
- pendingConfig * chainConfig
78
- config * chainConfig
89
+ type Config struct {
90
+ pending * values
91
+ current * values
79
92
80
93
ordererConfig * orderer.ManagerImpl
81
94
applicationConfig * application.SharedConfigImpl
82
95
}
83
96
84
97
// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
85
- func NewSharedConfigImpl (ordererConfig * orderer.ManagerImpl , applicationConfig * application.SharedConfigImpl ) * SharedConfigImpl {
86
- return & SharedConfigImpl {
87
- config : & chainConfig {},
98
+ func NewConfig (ordererConfig * orderer.ManagerImpl , applicationConfig * application.SharedConfigImpl ) * Config {
99
+ return & Config {
100
+ current : & values {},
88
101
ordererConfig : ordererConfig ,
89
102
applicationConfig : applicationConfig ,
90
103
}
91
104
}
92
105
93
106
// HashingAlgorithm returns a function pointer to the chain hashing algorihtm
94
- func (pm * SharedConfigImpl ) HashingAlgorithm () func (input []byte ) []byte {
95
- return pm . config .hashingAlgorithm
107
+ func (c * Config ) HashingAlgorithm () func (input []byte ) []byte {
108
+ return c . current .hashingAlgorithm
96
109
}
97
110
98
111
// BlockDataHashingStructure returns the width to use when forming the block data hashing structure
99
- func (pm * SharedConfigImpl ) BlockDataHashingStructureWidth () uint32 {
100
- return pm . config .blockDataHashingStructureWidth
112
+ func (c * Config ) BlockDataHashingStructureWidth () uint32 {
113
+ return c . current .blockDataHashingStructureWidth
101
114
}
102
115
103
116
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
104
- func (pm * SharedConfigImpl ) OrdererAddresses () []string {
105
- return pm . config .ordererAddresses
117
+ func (c * Config ) OrdererAddresses () []string {
118
+ return c . current .ordererAddresses
106
119
}
107
120
108
121
// BeginValueProposals is used to start a new config proposal
109
- func (pm * SharedConfigImpl ) BeginValueProposals (groups []string ) ([]api.ValueProposer , error ) {
122
+ func (c * Config ) BeginValueProposals (groups []string ) ([]api.ValueProposer , error ) {
110
123
handlers := make ([]api.ValueProposer , len (groups ))
111
124
112
125
for i , group := range groups {
113
126
switch group {
114
127
case application .GroupKey :
115
- handlers [i ] = pm .applicationConfig
128
+ handlers [i ] = c .applicationConfig
116
129
case orderer .GroupKey :
117
- handlers [i ] = pm .ordererConfig
130
+ handlers [i ] = c .ordererConfig
118
131
default :
119
132
return nil , fmt .Errorf ("Disallowed channel group: %s" , group )
120
133
}
121
134
}
122
135
123
- if pm . pendingConfig != nil {
136
+ if c . pending != nil {
124
137
logger .Panicf ("Programming error, cannot call begin in the middle of a proposal" )
125
138
}
126
139
127
- pm . pendingConfig = & chainConfig {}
140
+ c . pending = & values {}
128
141
return handlers , nil
129
142
}
130
143
131
144
// RollbackProposals is used to abandon a new config proposal
132
- func (pm * SharedConfigImpl ) RollbackProposals () {
133
- pm . pendingConfig = nil
145
+ func (c * Config ) RollbackProposals () {
146
+ c . pending = nil
134
147
}
135
148
136
149
// CommitProposals is used to commit a new config proposal
137
- func (pm * SharedConfigImpl ) CommitProposals () {
138
- if pm . pendingConfig == nil {
150
+ func (c * Config ) CommitProposals () {
151
+ if c . pending == nil {
139
152
logger .Panicf ("Programming error, cannot call commit without an existing proposal" )
140
153
}
141
- pm . config = pm . pendingConfig
142
- pm . pendingConfig = nil
154
+ c . current = c . pending
155
+ c . pending = nil
143
156
}
144
157
145
158
// ProposeValue is used to add new config to the config proposal
146
- func (pm * SharedConfigImpl ) ProposeValue (key string , configValue * cb.ConfigValue ) error {
159
+ func (c * Config ) ProposeValue (key string , configValue * cb.ConfigValue ) error {
147
160
switch key {
148
161
case HashingAlgorithmKey :
149
162
hashingAlgorithm := & cb.HashingAlgorithm {}
@@ -152,7 +165,7 @@ func (pm *SharedConfigImpl) ProposeValue(key string, configValue *cb.ConfigValue
152
165
}
153
166
switch hashingAlgorithm .Name {
154
167
case SHA3Shake256 :
155
- pm . pendingConfig .hashingAlgorithm = util .ComputeCryptoHash
168
+ c . pending .hashingAlgorithm = util .ComputeCryptoHash
156
169
default :
157
170
return fmt .Errorf ("Unknown hashing algorithm type: %s" , hashingAlgorithm .Name )
158
171
}
@@ -166,13 +179,13 @@ func (pm *SharedConfigImpl) ProposeValue(key string, configValue *cb.ConfigValue
166
179
return fmt .Errorf ("BlockDataHashStructure width only supported at MaxUint32 in this version" )
167
180
}
168
181
169
- pm . pendingConfig .blockDataHashingStructureWidth = blockDataHashingStructure .Width
182
+ c . pending .blockDataHashingStructureWidth = blockDataHashingStructure .Width
170
183
case OrdererAddressesKey :
171
184
ordererAddresses := & cb.OrdererAddresses {}
172
185
if err := proto .Unmarshal (configValue .Value , ordererAddresses ); err != nil {
173
186
return fmt .Errorf ("Unmarshaling error for HashingAlgorithm: %s" , err )
174
187
}
175
- pm . pendingConfig .ordererAddresses = ordererAddresses .Addresses
188
+ c . pending .ordererAddresses = ordererAddresses .Addresses
176
189
default :
177
190
logger .Warningf ("Uknown Chain config item with key %s" , key )
178
191
}
0 commit comments