8
8
"github.com/hyperledger/fabric-config/configtx/membership"
9
9
"github.com/hyperledger/fabric-config/configtx/orderer"
10
10
cb "github.com/hyperledger/fabric-protos-go/common"
11
+ sb "github.com/hyperledger/fabric-protos-go/orderer/smartbft"
12
+ "github.com/kfsoftware/hlf-operator/controllers/utils"
13
+ hlfv1alpha1 "github.com/kfsoftware/hlf-operator/pkg/apis/hlf.kungfusoftware.es/v1alpha1"
11
14
"github.com/pkg/errors"
12
15
"time"
13
16
)
@@ -25,9 +28,11 @@ type PeerOrg struct {
25
28
}
26
29
27
30
type Consenter struct {
28
- host string
29
- port int
30
- tlsCert * x509.Certificate
31
+ host string
32
+ port int
33
+ tlsCert * x509.Certificate
34
+ signCert * x509.Certificate
35
+ mspId string
31
36
}
32
37
type channelStore struct {
33
38
}
@@ -38,6 +43,7 @@ type CreateChannelOptions struct {
38
43
name string
39
44
batchSize * orderer.BatchSize
40
45
batchDuration * time.Duration
46
+ consensus hlfv1alpha1.OrdererConsensusType
41
47
}
42
48
43
49
func (o CreateChannelOptions ) validate () error {
@@ -87,11 +93,18 @@ func WithPeerOrgs(peerOrgs ...PeerOrg) ChannelOption {
87
93
o .peerOrgs = peerOrgs
88
94
}
89
95
}
90
- func CreateConsenter (host string , port int , tlsCert * x509.Certificate ) Consenter {
96
+ func WithConsensus (consensus hlfv1alpha1.OrdererConsensusType ) ChannelOption {
97
+ return func (o * CreateChannelOptions ) {
98
+ o .consensus = consensus
99
+ }
100
+ }
101
+ func CreateConsenter (host string , port int , tlsCert , signCert * x509.Certificate , mspId string ) Consenter {
91
102
return Consenter {
92
- host : host ,
93
- port : port ,
94
- tlsCert : tlsCert ,
103
+ host : host ,
104
+ port : port ,
105
+ tlsCert : tlsCert ,
106
+ signCert : signCert ,
107
+ mspId : mspId ,
95
108
}
96
109
}
97
110
func CreateOrdererOrg (mspID string , tlsRootCert * x509.Certificate , signRootCert * x509.Certificate , ordererUrls []string ) OrdererOrg {
@@ -145,32 +158,75 @@ func (s channelStore) GetApplicationChannelBlock(ctx context.Context, opts ...Ch
145
158
}
146
159
peerOrgs = append (peerOrgs , genesisOrdererOrg )
147
160
}
148
- var consenters []orderer.Consenter
149
- for _ , consenter := range o .consenters {
150
- genesisConsenter := orderer.Consenter {
151
- Address : orderer.EtcdAddress {
152
- Host : consenter .host ,
153
- Port : consenter .port ,
161
+ var consenters []orderer.Consenter // raft consenter
162
+ consenterMapping := []cb.Consenter {} // bft consenter
163
+ var etcdRaft orderer.EtcdRaft
164
+ var smartBFTOptions * sb.Options
165
+ var ordererType string
166
+ channelCapabilities := []string {"V2_0" }
167
+ if o .consensus == hlfv1alpha1 .OrdererConsensusEtcdraft {
168
+ ordererType = orderer .ConsensusTypeEtcdRaft
169
+ for _ , consenter := range o .consenters {
170
+ genesisConsenter := orderer.Consenter {
171
+ Address : orderer.EtcdAddress {
172
+ Host : consenter .host ,
173
+ Port : consenter .port ,
174
+ },
175
+ ClientTLSCert : consenter .tlsCert ,
176
+ ServerTLSCert : consenter .tlsCert ,
177
+ }
178
+ consenters = append (consenters , genesisConsenter )
179
+ }
180
+ etcdRaft = orderer.EtcdRaft {
181
+ Consenters : consenters ,
182
+ Options : orderer.EtcdRaftOptions {
183
+ TickInterval : "500ms" ,
184
+ ElectionTick : 10 ,
185
+ HeartbeatTick : 1 ,
186
+ MaxInflightBlocks : 5 ,
187
+ SnapshotIntervalSize : 16 * 1024 * 1024 , // 16 MB
154
188
},
155
- ClientTLSCert : consenter .tlsCert ,
156
- ServerTLSCert : consenter .tlsCert ,
157
189
}
158
- consenters = append (consenters , genesisConsenter )
190
+ } else if o .consensus == hlfv1alpha1 .OrdererConsensusBFT {
191
+ ordererType = orderer .ConsensusTypeBFT
192
+ channelCapabilities = append (channelCapabilities , "V3_0" )
193
+ for i , consenter := range o .consenters {
194
+ consenterMapping = append (consenterMapping , cb.Consenter {
195
+ Host : consenter .host ,
196
+ Port : uint32 (consenter .port ),
197
+ MspId : consenter .mspId ,
198
+ Id : uint32 (i + 1 ),
199
+ Identity : utils .EncodeX509Certificate (consenter .signCert ),
200
+ ClientTlsCert : utils .EncodeX509Certificate (consenter .tlsCert ),
201
+ ServerTlsCert : utils .EncodeX509Certificate (consenter .tlsCert ),
202
+ })
203
+ }
204
+ smartBFTOptions = & sb.Options {
205
+ RequestBatchMaxCount : 100 ,
206
+ RequestBatchMaxInterval : "50ms" ,
207
+ RequestForwardTimeout : "2s" ,
208
+ RequestComplainTimeout : "20s" ,
209
+ RequestAutoRemoveTimeout : "3m0s" ,
210
+ ViewChangeResendInterval : "5s" ,
211
+ ViewChangeTimeout : "20s" ,
212
+ LeaderHeartbeatTimeout : "1m0s" ,
213
+ CollectTimeout : "1s" ,
214
+ RequestBatchMaxBytes : 10485760 ,
215
+ IncomingMessageBufferSize : 200 ,
216
+ RequestPoolSize : 100000 ,
217
+ LeaderHeartbeatCount : 10 ,
218
+ }
219
+ } else {
220
+ return nil , fmt .Errorf ("orderer type %s not supported" , ordererType )
159
221
}
222
+
160
223
channelConfig := configtx.Channel {
161
224
Orderer : configtx.Orderer {
162
- OrdererType : "etcdraft" ,
163
- Organizations : ordererOrgs ,
164
- EtcdRaft : orderer.EtcdRaft {
165
- Consenters : consenters ,
166
- Options : orderer.EtcdRaftOptions {
167
- TickInterval : "500ms" ,
168
- ElectionTick : 10 ,
169
- HeartbeatTick : 1 ,
170
- MaxInflightBlocks : 5 ,
171
- SnapshotIntervalSize : 16 * 1024 * 1024 , // 16 MB
172
- },
173
- },
225
+ ConsenterMapping : consenterMapping ,
226
+ OrdererType : ordererType ,
227
+ Organizations : ordererOrgs ,
228
+ EtcdRaft : etcdRaft ,
229
+ SmartBFT : smartBFTOptions ,
174
230
Policies : map [string ]configtx.Policy {
175
231
"Readers" : {
176
232
Type : "ImplicitMeta" ,
@@ -196,7 +252,7 @@ func (s channelStore) GetApplicationChannelBlock(ctx context.Context, opts ...Ch
196
252
PreferredMaxBytes : 512 * 1024 ,
197
253
},
198
254
BatchTimeout : 2 * time .Second ,
199
- State : "STATE_NORMAL" ,
255
+ State : orderer . ConsensusStateNormal ,
200
256
},
201
257
Application : configtx.Application {
202
258
Organizations : peerOrgs ,
@@ -225,7 +281,7 @@ func (s channelStore) GetApplicationChannelBlock(ctx context.Context, opts ...Ch
225
281
},
226
282
ACLs : defaultACLs (),
227
283
},
228
- Capabilities : [] string { "V2_0" } ,
284
+ Capabilities : channelCapabilities ,
229
285
Policies : map [string ]configtx.Policy {
230
286
"Readers" : {
231
287
Type : "ImplicitMeta" ,
0 commit comments