@@ -7,19 +7,19 @@ SPDX-License-Identifier: Apache-2.0
7
7
package nwo
8
8
9
9
import (
10
+ "net/http"
10
11
"os"
11
12
"path/filepath"
12
- "strings"
13
-
14
- "github.com/hyperledger/fabric/common/channelconfig"
15
- "github.com/hyperledger/fabric/common/policies"
16
13
17
14
"github.com/hyperledger/fabric-protos-go-apiv2/common"
18
15
"github.com/hyperledger/fabric-protos-go-apiv2/msp"
19
16
protosorderer "github.com/hyperledger/fabric-protos-go-apiv2/orderer"
17
+ "github.com/hyperledger/fabric/common/channelconfig"
18
+ "github.com/hyperledger/fabric/common/policies"
20
19
"github.com/hyperledger/fabric/integration/nwo/commands"
21
20
"github.com/hyperledger/fabric/internal/configtxlator/update"
22
21
"github.com/hyperledger/fabric/protoutil"
22
+ . "github.com/onsi/ginkgo/v2"
23
23
. "github.com/onsi/gomega"
24
24
"github.com/onsi/gomega/gbytes"
25
25
"github.com/onsi/gomega/gexec"
@@ -126,6 +126,13 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated
126
126
Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
127
127
}
128
128
129
+ sess , err := n .PeerAdminSession (submitter , commands.SignConfigTx {
130
+ File : updateFile ,
131
+ ClientAuth : n .ClientAuthRequired ,
132
+ })
133
+ Expect (err ).NotTo (HaveOccurred ())
134
+ Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
135
+
129
136
var currentBlockNumber uint64
130
137
// get current configuration block number
131
138
if getConfigBlockFromOrderer {
@@ -134,15 +141,20 @@ func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated
134
141
currentBlockNumber = CurrentConfigBlockNumber (n , submitter , nil , channel )
135
142
}
136
143
137
- sess , err := n .PeerAdminSession (submitter , commands.ChannelUpdate {
138
- ChannelID : channel ,
139
- Orderer : n .OrdererAddress (orderer , ListenPort ),
140
- File : updateFile ,
141
- ClientAuth : n .ClientAuthRequired ,
142
- })
144
+ updateEnvelopeBytes , err := os .ReadFile (updateFile )
145
+ Expect (err ).NotTo (HaveOccurred ())
146
+
147
+ updateEnvelope := & common.Envelope {}
148
+ err = proto .Unmarshal (updateEnvelopeBytes , updateEnvelope )
143
149
Expect (err ).NotTo (HaveOccurred ())
144
- Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
145
- Expect (sess .Err ).To (gbytes .Say ("Successfully submitted channel update" ))
150
+
151
+ ready := make (chan struct {})
152
+ go func () {
153
+ defer GinkgoRecover ()
154
+ Update (n , orderer , channel , updateEnvelope )
155
+ close (ready )
156
+ }()
157
+ Eventually (ready , n .EventuallyTimeout ).Should (BeClosed ())
146
158
147
159
if getConfigBlockFromOrderer {
148
160
ccb := func () uint64 { return CurrentConfigBlockNumber (n , submitter , orderer , channel ) }
@@ -209,47 +221,57 @@ func UpdateOrdererConfig(n *Network, orderer *Orderer, channel string, current,
209
221
currentBlockNumber := CurrentConfigBlockNumber (n , submitter , orderer , channel )
210
222
ComputeUpdateOrdererConfig (updateFile , n , channel , current , updated , submitter , additionalSigners ... )
211
223
212
- Eventually (func () bool {
213
- sess , err := n .OrdererAdminSession (orderer , submitter , commands.ChannelUpdate {
214
- ChannelID : channel ,
215
- Orderer : n .OrdererAddress (orderer , ListenPort ),
216
- File : updateFile ,
217
- ClientAuth : n .ClientAuthRequired ,
218
- })
219
- Expect (err ).NotTo (HaveOccurred ())
224
+ updateEnvelopeBytes , err := os .ReadFile (updateFile )
225
+ Expect (err ).NotTo (HaveOccurred ())
220
226
221
- sess .Wait (n .EventuallyTimeout )
222
- if sess .ExitCode () != 0 {
223
- return false
224
- }
227
+ updateEnvelope := & common.Envelope {}
228
+ err = proto .Unmarshal (updateEnvelopeBytes , updateEnvelope )
229
+ Expect (err ).NotTo (HaveOccurred ())
225
230
226
- return strings .Contains (string (sess .Err .Contents ()), "Successfully submitted channel update" )
227
- }, n .EventuallyTimeout ).Should (BeTrue ())
231
+ ready := make (chan struct {})
232
+ go func () {
233
+ defer GinkgoRecover ()
234
+ Update (n , orderer , channel , updateEnvelope )
235
+ close (ready )
236
+ }()
237
+ Eventually (ready , n .EventuallyTimeout ).Should (BeClosed ())
228
238
229
239
// wait for the block to be committed
230
240
ccb := func () uint64 { return CurrentConfigBlockNumber (n , submitter , orderer , channel ) }
231
241
Eventually (ccb , n .EventuallyTimeout ).Should (BeNumerically (">" , currentBlockNumber ))
232
242
}
233
243
234
- // UpdateOrdererConfigSession computes, signs, and submits a configuration
244
+ // UpdateOrdererConfigFails computes, signs, and submits a configuration
235
245
// update which requires orderer signatures. The caller should wait on the
236
246
// returned seession retrieve the exit code.
237
- func UpdateOrdererConfigSession (n * Network , orderer * Orderer , channel string , current , updated * common.Config , submitter * Peer , additionalSigners ... * Orderer ) * gexec. Session {
247
+ func UpdateOrdererConfigFails (n * Network , orderer * Orderer , channel string , current , updated * common.Config , errStr string , submitter * Peer , additionalSigners ... * Orderer ) {
238
248
tempDir , err := os .MkdirTemp (n .RootDir , "updateConfig" )
239
249
Expect (err ).NotTo (HaveOccurred ())
240
250
updateFile := filepath .Join (tempDir , "update.pb" )
241
251
242
252
ComputeUpdateOrdererConfig (updateFile , n , channel , current , updated , submitter , additionalSigners ... )
243
253
244
- // session should not return with a zero exit code nor with a success response
245
- sess , err := n .OrdererAdminSession (orderer , submitter , commands.ChannelUpdate {
246
- ChannelID : channel ,
247
- Orderer : n .OrdererAddress (orderer , ListenPort ),
254
+ sess , err := n .OrdererAdminSession (orderer , submitter , commands.SignConfigTx {
248
255
File : updateFile ,
249
256
ClientAuth : n .ClientAuthRequired ,
250
257
})
251
258
Expect (err ).NotTo (HaveOccurred ())
252
- return sess
259
+ Eventually (sess , n .EventuallyTimeout ).Should (gexec .Exit (0 ))
260
+
261
+ updateEnvelopeBytes , err := os .ReadFile (updateFile )
262
+ Expect (err ).NotTo (HaveOccurred ())
263
+
264
+ updateEnvelope := & common.Envelope {}
265
+ err = proto .Unmarshal (updateEnvelopeBytes , updateEnvelope )
266
+ Expect (err ).NotTo (HaveOccurred ())
267
+
268
+ ready := make (chan struct {})
269
+ go func () {
270
+ defer GinkgoRecover ()
271
+ UpdateWithStatus (n , orderer , channel , updateEnvelope , http .StatusBadRequest , errStr )
272
+ close (ready )
273
+ }()
274
+ Eventually (ready , n .EventuallyTimeout ).Should (BeClosed ())
253
275
}
254
276
255
277
func ComputeUpdateOrdererConfig (updateFile string , n * Network , channel string , current , updated * common.Config , submitter * Peer , additionalSigners ... * Orderer ) {
0 commit comments