UpdateConfig computes, signs, and submits a configuration update and waits for the update to complete.
(n *Network, orderer *Orderer, channel string, current, updated *common.Config, getConfigBlockFromOrderer bool, submitter *Peer, ordererSigners []*Orderer, additionalSigners ...*Peer)
| 81 | // UpdateConfig computes, signs, and submits a configuration update and waits |
| 82 | // for the update to complete. |
| 83 | func UpdateConfig(n *Network, orderer *Orderer, channel string, current, updated *common.Config, getConfigBlockFromOrderer bool, submitter *Peer, ordererSigners []*Orderer, additionalSigners ...*Peer) { |
| 84 | tempDir, err := os.MkdirTemp("", "updateConfig") |
| 85 | Expect(err).NotTo(HaveOccurred()) |
| 86 | defer os.RemoveAll(tempDir) |
| 87 | |
| 88 | // compute update |
| 89 | configUpdate, err := update.Compute(current, updated) |
| 90 | Expect(err).NotTo(HaveOccurred()) |
| 91 | configUpdate.ChannelId = channel |
| 92 | |
| 93 | signedEnvelope, err := protoutil.CreateSignedEnvelope( |
| 94 | common.HeaderType_CONFIG_UPDATE, |
| 95 | channel, |
| 96 | nil, // local signer |
| 97 | &common.ConfigUpdateEnvelope{ConfigUpdate: protoutil.MarshalOrPanic(configUpdate)}, |
| 98 | 0, // message version |
| 99 | 0, // epoch |
| 100 | ) |
| 101 | Expect(err).NotTo(HaveOccurred()) |
| 102 | Expect(signedEnvelope).NotTo(BeNil()) |
| 103 | |
| 104 | updateFile := filepath.Join(tempDir, "update.pb") |
| 105 | err = os.WriteFile(updateFile, protoutil.MarshalOrPanic(signedEnvelope), 0o600) |
| 106 | Expect(err).NotTo(HaveOccurred()) |
| 107 | |
| 108 | for _, signer := range additionalSigners { |
| 109 | sess, err := n.PeerAdminSession(signer, commands.SignConfigTx{ |
| 110 | File: updateFile, |
| 111 | ClientAuth: n.ClientAuthRequired, |
| 112 | }) |
| 113 | Expect(err).NotTo(HaveOccurred()) |
| 114 | Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) |
| 115 | } |
| 116 | |
| 117 | for _, signer := range ordererSigners { |
| 118 | sess, err := n.OrdererAdminSession(signer, submitter, commands.SignConfigTx{ |
| 119 | File: updateFile, |
| 120 | ClientAuth: n.ClientAuthRequired, |
| 121 | }) |
| 122 | Expect(err).NotTo(HaveOccurred()) |
| 123 | Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) |
| 124 | } |
| 125 | |
| 126 | sess, err := n.PeerAdminSession(submitter, commands.SignConfigTx{ |
| 127 | File: updateFile, |
| 128 | ClientAuth: n.ClientAuthRequired, |
| 129 | }) |
| 130 | Expect(err).NotTo(HaveOccurred()) |
| 131 | Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0)) |
| 132 | |
| 133 | var currentBlockNumber uint64 |
| 134 | // get current configuration block number |
| 135 | if getConfigBlockFromOrderer { |
| 136 | currentBlockNumber = CurrentConfigBlockNumber(n, submitter, orderer, channel) |
| 137 | } else { |
| 138 | currentBlockNumber = CurrentConfigBlockNumber(n, submitter, nil, channel) |
| 139 | } |
| 140 |