Commit c4fe7e63 authored by Matthew Sykes's avatar Matthew Sykes Committed by Gari Singh
Browse files

[FAB-11055] add UpdateChannelAnchors to network



Change-Id: Iade2372bc4708277adb3979e50393331bf8cc378
Signed-off-by: default avatarMatthew Sykes <sykesmat@us.ibm.com>
parent 227113df
......@@ -226,14 +226,14 @@ func (n *Network) CryptoConfigPath() string {
// OutputBlockPath returns the path to the genesis block for the named system
// channel.
func (n *Network) OutputBlockPath(name string) string {
return filepath.Join(n.RootDir, fmt.Sprintf("%s_block.pb", name))
func (n *Network) OutputBlockPath(channelName string) string {
return filepath.Join(n.RootDir, fmt.Sprintf("%s_block.pb", channelName))
}
// CreateChannelTxPath returns the path to the create channel transaction for
// the named channel.
func (n *Network) CreateChannelTxPath(name string) string {
return filepath.Join(n.RootDir, fmt.Sprintf("%s_tx.pb", name))
func (n *Network) CreateChannelTxPath(channelName string) string {
return filepath.Join(n.RootDir, fmt.Sprintf("%s_tx.pb", channelName))
}
// OrdererDir returns the path to the configuration directory for the specified
......@@ -379,6 +379,17 @@ func (n *Network) OrdererLocalMSPDir(o *Orderer) string {
)
}
// ProfileForChannel gets the configtxgen profile name associated with the
// specified channel.
func (n *Network) ProfileForChannel(channelName string) string {
for _, ch := range n.Channels {
if ch.Name == channelName {
return ch.Profile
}
}
return ""
}
// GenerateConfigTree generates the configuration documents required to
// bootstrap a fabric network. A configuration file will be generated for
// cryptogen, configtxgen, and for each peer and orderer. The contents of the
......@@ -537,6 +548,42 @@ func (n *Network) CreateAndJoinChannel(o *Orderer, channelName string) {
}
}
// UpdateChannelAnchors determines the anchor peers for the specified channel,
// creates an anchor peer update transaction for each organization, and submits
// the update transactions to the orderer.
func (n *Network) UpdateChannelAnchors(o *Orderer, channelName string) {
tempFile, err := ioutil.TempFile("", "update-anchors")
Expect(err).NotTo(HaveOccurred())
tempFile.Close()
defer os.Remove(tempFile.Name())
peersByOrg := map[string]*Peer{}
for _, p := range n.AnchorsForChannel(channelName) {
peersByOrg[p.Organization] = p
}
for orgName, p := range peersByOrg {
anchorUpdate := commands.OutputAnchorPeersUpdate{
ChannelID: channelName,
Profile: n.ProfileForChannel(channelName),
ConfigPath: n.RootDir,
AsOrg: orgName,
OutputAnchorPeersUpdate: tempFile.Name(),
}
sess, err := n.ConfigTxGen(anchorUpdate)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(0))
sess, err = n.PeerAdminSession(p, commands.ChannelUpdate{
ChannelID: channelName,
Orderer: n.OrdererAddress(o, ListenPort),
File: tempFile.Name(),
})
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(0))
}
}
// CreateChannel will submit an existing create channel transaction to the
// specified orderer. The channel transaction must exist at the location
// returned by CreateChannelTxPath.
......@@ -874,7 +921,7 @@ func (n *Network) AnchorsForChannel(chanName string) []*Peer {
anchors := []*Peer{}
for _, p := range n.Peers {
for _, pc := range p.Channels {
if pc.Name == chanName {
if pc.Name == chanName && pc.Anchor {
anchors = append(anchors, p)
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment