itest: refactor createThreeHopNetwork to open channels async
This will save us 6 blocks each time we call this function.
This commit is contained in:
1 file changed
+32
-28
+32
-28
@@ -1779,31 +1779,15 @@ func createThreeHopNetwork(ht *lntest.HarnessTest,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// Prepare params for Alice.
|
||||||
cancel context.CancelFunc
|
|
||||||
acceptStream rpc.AcceptorClient
|
|
||||||
)
|
|
||||||
// If a zero-conf channel is being opened, the nodes are signalling the
|
|
||||||
// zero-conf feature bit. Setup a ChannelAcceptor for the fundee.
|
|
||||||
if zeroConf {
|
|
||||||
acceptStream, cancel = bob.RPC.ChannelAcceptor()
|
|
||||||
go acceptChannel(ht.T, true, acceptStream)
|
|
||||||
}
|
|
||||||
|
|
||||||
aliceParams := lntest.OpenChannelParams{
|
aliceParams := lntest.OpenChannelParams{
|
||||||
Amt: chanAmt,
|
Amt: chanAmt,
|
||||||
CommitmentType: c,
|
CommitmentType: c,
|
||||||
FundingShim: aliceFundingShim,
|
FundingShim: aliceFundingShim,
|
||||||
ZeroConf: zeroConf,
|
ZeroConf: zeroConf,
|
||||||
}
|
}
|
||||||
aliceChanPoint := ht.OpenChannel(alice, bob, aliceParams)
|
|
||||||
|
|
||||||
// Remove the ChannelAcceptor for Bob.
|
// We'll create a channel from Bob to Carol. After this channel is
|
||||||
if zeroConf {
|
|
||||||
cancel()
|
|
||||||
}
|
|
||||||
|
|
||||||
// We'll then create a channel from Bob to Carol. After this channel is
|
|
||||||
// open, our topology looks like: A -> B -> C.
|
// open, our topology looks like: A -> B -> C.
|
||||||
var bobFundingShim *lnrpc.FundingShim
|
var bobFundingShim *lnrpc.FundingShim
|
||||||
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
if c == lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE {
|
||||||
@@ -1812,24 +1796,44 @@ func createThreeHopNetwork(ht *lntest.HarnessTest,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup a ChannelAcceptor for Carol if a zero-conf channel open is
|
// Prepare params for Bob.
|
||||||
// being attempted.
|
|
||||||
if zeroConf {
|
|
||||||
acceptStream, cancel = carol.RPC.ChannelAcceptor()
|
|
||||||
go acceptChannel(ht.T, true, acceptStream)
|
|
||||||
}
|
|
||||||
|
|
||||||
bobParams := lntest.OpenChannelParams{
|
bobParams := lntest.OpenChannelParams{
|
||||||
Amt: chanAmt,
|
Amt: chanAmt,
|
||||||
CommitmentType: c,
|
CommitmentType: c,
|
||||||
FundingShim: bobFundingShim,
|
FundingShim: bobFundingShim,
|
||||||
ZeroConf: zeroConf,
|
ZeroConf: zeroConf,
|
||||||
}
|
}
|
||||||
bobChanPoint := ht.OpenChannel(bob, carol, bobParams)
|
|
||||||
|
|
||||||
// Remove the ChannelAcceptor for Carol.
|
var (
|
||||||
|
acceptStreamBob rpc.AcceptorClient
|
||||||
|
acceptStreamCarol rpc.AcceptorClient
|
||||||
|
cancelBob context.CancelFunc
|
||||||
|
cancelCarol context.CancelFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
// If a zero-conf channel is being opened, the nodes are signalling the
|
||||||
|
// zero-conf feature bit. Setup a ChannelAcceptor for the fundee.
|
||||||
if zeroConf {
|
if zeroConf {
|
||||||
cancel()
|
acceptStreamBob, cancelBob = bob.RPC.ChannelAcceptor()
|
||||||
|
go acceptChannel(ht.T, true, acceptStreamBob)
|
||||||
|
|
||||||
|
acceptStreamCarol, cancelCarol = carol.RPC.ChannelAcceptor()
|
||||||
|
go acceptChannel(ht.T, true, acceptStreamCarol)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open channels in batch to save blocks mined.
|
||||||
|
reqs := []*lntest.OpenChannelRequest{
|
||||||
|
{Local: alice, Remote: bob, Param: aliceParams},
|
||||||
|
{Local: bob, Remote: carol, Param: bobParams},
|
||||||
|
}
|
||||||
|
resp := ht.OpenMultiChannelsAsync(reqs)
|
||||||
|
aliceChanPoint := resp[0]
|
||||||
|
bobChanPoint := resp[1]
|
||||||
|
|
||||||
|
// Remove the ChannelAcceptor for Bob and Carol.
|
||||||
|
if zeroConf {
|
||||||
|
cancelBob()
|
||||||
|
cancelCarol()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure alice and carol know each other's channels.
|
// Make sure alice and carol know each other's channels.
|
||||||
|
|||||||
Reference in new issue
Block a user