@@ -20,7 +20,6 @@ import (
20
20
"fmt"
21
21
22
22
"github.com/hyperledger/fabric/common/configtx"
23
- "github.com/hyperledger/fabric/common/policies"
24
23
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
25
24
ordererledger "github.com/hyperledger/fabric/orderer/ledger"
26
25
cb "github.com/hyperledger/fabric/protos/common"
@@ -60,6 +59,20 @@ type Manager interface {
60
59
ProposeChain (env * cb.Envelope ) cb.Status
61
60
}
62
61
62
+ type configResources struct {
63
+ configtx.Manager
64
+ sharedConfig sharedconfig.Manager
65
+ }
66
+
67
+ func (cr * configResources ) SharedConfig () sharedconfig.Manager {
68
+ return cr .sharedConfig
69
+ }
70
+
71
+ type ledgerResources struct {
72
+ * configResources
73
+ ledger ordererledger.ReadWriter
74
+ }
75
+
63
76
type multiLedger struct {
64
77
chains map [string ]* chainSupport
65
78
consenters map [string ]Consenter
@@ -101,19 +114,16 @@ func NewManagerImpl(ledgerFactory ordererledger.Factory, consenters map[string]C
101
114
if configTx == nil {
102
115
logger .Fatalf ("Could not find configuration transaction for chain %s" , chainID )
103
116
}
104
- configManager , policyManager , backingLedger , sharedConfigManager := ml .newResources (configTx )
105
- chainID := configManager .ChainID ()
117
+ ledgerResources := ml .newLedgerResources (configTx )
118
+ chainID := ledgerResources .ChainID ()
106
119
107
- if sharedConfigManager .ChainCreationPolicyNames () != nil {
120
+ if ledgerResources . SharedConfig () .ChainCreationPolicyNames () != nil {
108
121
if ml .sysChain != nil {
109
122
logger .Fatalf ("There appear to be two system chains %s and %s" , ml .sysChain .support .ChainID (), chainID )
110
123
}
111
124
logger .Debugf ("Starting with system chain: %x" , chainID )
112
- chain := newChainSupport (createSystemChainFilters (ml , configManager , policyManager , sharedConfigManager ),
113
- configManager ,
114
- policyManager ,
115
- backingLedger ,
116
- sharedConfigManager ,
125
+ chain := newChainSupport (createSystemChainFilters (ml , ledgerResources ),
126
+ ledgerResources ,
117
127
consenters ,
118
128
signer )
119
129
ml .chains [string (chainID )] = chain
@@ -122,11 +132,8 @@ func NewManagerImpl(ledgerFactory ordererledger.Factory, consenters map[string]C
122
132
defer chain .start ()
123
133
} else {
124
134
logger .Debugf ("Starting chain: %x" , chainID )
125
- chain := newChainSupport (createStandardFilters (configManager , policyManager , sharedConfigManager ),
126
- configManager ,
127
- policyManager ,
128
- backingLedger ,
129
- sharedConfigManager ,
135
+ chain := newChainSupport (createStandardFilters (ledgerResources ),
136
+ ledgerResources ,
130
137
consenters ,
131
138
signer )
132
139
ml .chains [string (chainID )] = chain
@@ -151,19 +158,23 @@ func (ml *multiLedger) GetChain(chainID string) (ChainSupport, bool) {
151
158
return cs , ok
152
159
}
153
160
154
- func newConfigTxManagerAndHandlers (configEnvelope * cb.ConfigurationEnvelope ) (configtx.Manager , policies.Manager , sharedconfig.Manager , error ) {
155
- initializer := configtx .NewInitializer ()
161
+ func newConfigResources (configEnvelope * cb.ConfigurationEnvelope ) (* configResources , error ) {
156
162
sharedConfigManager := sharedconfig .NewManagerImpl ()
163
+ initializer := configtx .NewInitializer ()
157
164
initializer .Handlers ()[cb .ConfigurationItem_Orderer ] = sharedConfigManager
165
+
158
166
configManager , err := configtx .NewManagerImpl (configEnvelope , initializer )
159
167
if err != nil {
160
- return nil , nil , nil , fmt .Errorf ("Error unpacking configuration transaction: %s" , err )
168
+ return nil , fmt .Errorf ("Error unpacking configuration transaction: %s" , err )
161
169
}
162
170
163
- return configManager , initializer .PolicyManager (), sharedConfigManager , nil
171
+ return & configResources {
172
+ Manager : configManager ,
173
+ sharedConfig : sharedConfigManager ,
174
+ }, nil
164
175
}
165
176
166
- func (ml * multiLedger ) newResources (configTx * cb.Envelope ) (configtx. Manager , policies. Manager , ordererledger. ReadWriter , sharedconfig. Manager ) {
177
+ func (ml * multiLedger ) newLedgerResources (configTx * cb.Envelope ) * ledgerResources {
167
178
payload := & cb.Payload {}
168
179
err := proto .Unmarshal (configTx .Payload , payload )
169
180
if err != nil {
@@ -176,38 +187,41 @@ func (ml *multiLedger) newResources(configTx *cb.Envelope) (configtx.Manager, po
176
187
logger .Fatalf ("Error unmarshaling a config transaction to config envelope: %s" , err )
177
188
}
178
189
179
- configManager , policyManager , sharedConfigManager , err := newConfigTxManagerAndHandlers (configEnvelope )
190
+ configResources , err := newConfigResources (configEnvelope )
180
191
181
192
if err != nil {
182
193
logger .Fatalf ("Error creating configtx manager and handlers: %s" , err )
183
194
}
184
195
185
- chainID := configManager .ChainID ()
196
+ chainID := configResources .ChainID ()
186
197
187
198
ledger , err := ml .ledgerFactory .GetOrCreate (chainID )
188
199
if err != nil {
189
200
logger .Fatalf ("Error getting ledger for %s" , chainID )
190
201
}
191
202
192
- return configManager , policyManager , ledger , sharedConfigManager
203
+ return & ledgerResources {
204
+ configResources : configResources ,
205
+ ledger : ledger ,
206
+ }
193
207
}
194
208
195
209
func (ml * multiLedger ) systemChain () * systemChain {
196
210
return ml .sysChain
197
211
}
198
212
199
213
func (ml * multiLedger ) newChain (configtx * cb.Envelope ) {
200
- configManager , policyManager , backingLedger , sharedConfig := ml .newResources (configtx )
201
- backingLedger . Append (ordererledger .CreateNextBlock (backingLedger , []* cb.Envelope {configtx }))
214
+ ledgerResources := ml .newLedgerResources (configtx )
215
+ ledgerResources . ledger . Append (ordererledger .CreateNextBlock (ledgerResources . ledger , []* cb.Envelope {configtx }))
202
216
203
217
// Copy the map to allow concurrent reads from broadcast/deliver while the new chainSupport is
204
218
newChains := make (map [string ]* chainSupport )
205
219
for key , value := range ml .chains {
206
220
newChains [key ] = value
207
221
}
208
222
209
- cs := newChainSupport (createStandardFilters (configManager , policyManager , sharedConfig ), configManager , policyManager , backingLedger , sharedConfig , ml .consenters , ml .signer )
210
- chainID := configManager .ChainID ()
223
+ cs := newChainSupport (createStandardFilters (ledgerResources ), ledgerResources , ml .consenters , ml .signer )
224
+ chainID := ledgerResources .ChainID ()
211
225
212
226
logger .Debugf ("Created and starting new chain %s" , chainID )
213
227
0 commit comments