-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FAB-16286 Split raft Broadcast/Deliver IT tool out
The Raft tests utilize direct Broadcast/Deliver to the orderers. This is useful for other tests, particularly ones which need to bypass peers and send directly to ordering (like, the forthcoming instantiation policy test). This CR simply splits the core function out of Raft and into nwo. Further refactoring may be done in the future. Signed-off-by: Jason Yellick <jyellick@us.ibm.com> Change-Id: I7aec7028a37570248b612d2ce53f99a27670ea9e
- Loading branch information
Jason Yellick
committed
Nov 15, 2019
1 parent
59bad46
commit 7b19faa
Showing
4 changed files
with
129 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
Copyright IBM Corp All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package nwo | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"path" | ||
"time" | ||
|
||
"github.com/hyperledger/fabric-protos-go/common" | ||
"github.com/hyperledger/fabric-protos-go/orderer" | ||
"github.com/hyperledger/fabric/core/comm" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// Broadcast sends given env to Broadcast API of specified orderer. | ||
func Broadcast(n *Network, o *Orderer, env *common.Envelope) (*orderer.BroadcastResponse, error) { | ||
gRPCclient, err := CreateGRPCClient(n, o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
addr := n.OrdererAddress(o, ListenPort) | ||
conn, err := gRPCclient.NewConnection(addr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer conn.Close() | ||
|
||
broadcaster, err := orderer.NewAtomicBroadcastClient(conn).Broadcast(context.Background()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = broadcaster.Send(env) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := broadcaster.Recv() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
// Deliver sends given env to Deliver API of specified orderer. | ||
func Deliver(n *Network, o *Orderer, env *common.Envelope) (*common.Block, error) { | ||
gRPCclient, err := CreateGRPCClient(n, o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
addr := n.OrdererAddress(o, ListenPort) | ||
conn, err := gRPCclient.NewConnection(addr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer conn.Close() | ||
|
||
deliverer, err := orderer.NewAtomicBroadcastClient(conn).Deliver(context.Background()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = deliverer.Send(env) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := deliverer.Recv() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
blk := resp.GetBlock() | ||
if blk == nil { | ||
return nil, errors.Errorf("block not found") | ||
} | ||
|
||
return blk, nil | ||
} | ||
|
||
func CreateGRPCClient(n *Network, o *Orderer) (*comm.GRPCClient, error) { | ||
config := comm.ClientConfig{} | ||
config.Timeout = 5 * time.Second | ||
|
||
secOpts := comm.SecureOptions{ | ||
UseTLS: true, | ||
RequireClientCert: false, | ||
} | ||
|
||
caPEM, err := ioutil.ReadFile(path.Join(n.OrdererLocalTLSDir(o), "ca.crt")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
secOpts.ServerRootCAs = [][]byte{caPEM} | ||
config.SecOpts = secOpts | ||
|
||
grpcClient, err := comm.NewGRPCClient(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return grpcClient, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters