autopilot/agent: call ChannelBudget on constrainsts
We let the agent call ChannelBudget on its constraints directly, and not go through the heuristic. This is needed since when we want to have multiple active heuristics concurrently, it won't make sense anymore to ask each of the heuristics. The mockConstraints are also updated to act as the mockHeuristic did before, by making it possible to control the responses it gives by sending them on the contained channels.
This commit is contained in:
parent
1d82e12fcf
commit
0e1713956b
@ -478,12 +478,13 @@ func (a *Agent) controller() {
|
|||||||
a.pendingMtx.Unlock()
|
a.pendingMtx.Unlock()
|
||||||
|
|
||||||
// Now that we've updated our internal state, we'll consult our
|
// Now that we've updated our internal state, we'll consult our
|
||||||
// channel attachment heuristic to determine if we should open
|
// channel attachment heuristic to determine if we can open
|
||||||
// up any additional channels or modify existing channels.
|
// up any additional channels while staying within our
|
||||||
availableFunds, numChans, needMore := a.cfg.Heuristic.NeedMoreChans(
|
// constraints.
|
||||||
|
availableFunds, numChans := a.cfg.Constraints.ChannelBudget(
|
||||||
totalChans, a.totalBalance,
|
totalChans, a.totalBalance,
|
||||||
)
|
)
|
||||||
if !needMore {
|
if numChans == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type moreChansResp struct {
|
type moreChansResp struct {
|
||||||
needMore bool
|
|
||||||
numMore uint32
|
numMore uint32
|
||||||
amt btcutil.Amount
|
amt btcutil.Amount
|
||||||
}
|
}
|
||||||
@ -26,11 +25,33 @@ type moreChanArg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type mockConstraints struct {
|
type mockConstraints struct {
|
||||||
|
moreChansResps chan moreChansResp
|
||||||
|
moreChanArgs chan moreChanArg
|
||||||
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockConstraints) ChannelBudget(chans []Channel,
|
func (m *mockConstraints) ChannelBudget(chans []Channel,
|
||||||
balance btcutil.Amount) (btcutil.Amount, uint32) {
|
balance btcutil.Amount) (btcutil.Amount, uint32) {
|
||||||
return 1e8, 10
|
|
||||||
|
if m.moreChanArgs != nil {
|
||||||
|
moreChan := moreChanArg{
|
||||||
|
chans: chans,
|
||||||
|
balance: balance,
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case m.moreChanArgs <- moreChan:
|
||||||
|
case <-m.quit:
|
||||||
|
return 0, 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case resp := <-m.moreChansResps:
|
||||||
|
return resp.amt, resp.numMore
|
||||||
|
case <-m.quit:
|
||||||
|
return 0, 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockConstraints) MaxPendingOpens() uint16 {
|
func (m *mockConstraints) MaxPendingOpens() uint16 {
|
||||||
@ -47,9 +68,6 @@ func (m *mockConstraints) MaxChanSize() btcutil.Amount {
|
|||||||
var _ AgentConstraints = (*mockConstraints)(nil)
|
var _ AgentConstraints = (*mockConstraints)(nil)
|
||||||
|
|
||||||
type mockHeuristic struct {
|
type mockHeuristic struct {
|
||||||
moreChansResps chan moreChansResp
|
|
||||||
moreChanArgs chan moreChanArg
|
|
||||||
|
|
||||||
nodeScoresResps chan map[NodeID]*AttachmentDirective
|
nodeScoresResps chan map[NodeID]*AttachmentDirective
|
||||||
nodeScoresArgs chan directiveArg
|
nodeScoresArgs chan directiveArg
|
||||||
|
|
||||||
@ -58,26 +76,7 @@ type mockHeuristic struct {
|
|||||||
|
|
||||||
func (m *mockHeuristic) NeedMoreChans(chans []Channel,
|
func (m *mockHeuristic) NeedMoreChans(chans []Channel,
|
||||||
balance btcutil.Amount) (btcutil.Amount, uint32, bool) {
|
balance btcutil.Amount) (btcutil.Amount, uint32, bool) {
|
||||||
|
|
||||||
if m.moreChanArgs != nil {
|
|
||||||
moreChan := moreChanArg{
|
|
||||||
chans: chans,
|
|
||||||
balance: balance,
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case m.moreChanArgs <- moreChan:
|
|
||||||
case <-m.quit:
|
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case resp := <-m.moreChansResps:
|
|
||||||
return resp.amt, resp.numMore, resp.needMore
|
|
||||||
case <-m.quit:
|
|
||||||
return 0, 0, false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type directiveArg struct {
|
type directiveArg struct {
|
||||||
@ -167,11 +166,13 @@ func TestAgentChannelOpenSignal(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent, 10),
|
openChanSignals: make(chan openChanIntent, 10),
|
||||||
@ -221,7 +222,7 @@ func TestAgentChannelOpenSignal(t *testing.T) {
|
|||||||
// We'll send an initial "no" response to advance the agent past its
|
// We'll send an initial "no" response to advance the agent past its
|
||||||
// initial check.
|
// initial check.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -237,7 +238,7 @@ func TestAgentChannelOpenSignal(t *testing.T) {
|
|||||||
// The agent should now query the heuristic in order to determine its
|
// The agent should now query the heuristic in order to determine its
|
||||||
// next action as it local state has now been modified.
|
// next action as it local state has now been modified.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
// At this point, the local state of the agent should
|
// At this point, the local state of the agent should
|
||||||
// have also been updated to reflect that the LN node
|
// have also been updated to reflect that the LN node
|
||||||
// now has an additional channel with one BTC.
|
// now has an additional channel with one BTC.
|
||||||
@ -300,11 +301,13 @@ func TestAgentChannelFailureSignal(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockFailingChanController{}
|
chanController := &mockFailingChanController{}
|
||||||
memGraph, _, _ := newMemChanGraph()
|
memGraph, _, _ := newMemChanGraph()
|
||||||
@ -353,7 +356,7 @@ func TestAgentChannelFailureSignal(t *testing.T) {
|
|||||||
// First ensure the agent will attempt to open a new channel. Return
|
// First ensure the agent will attempt to open a new channel. Return
|
||||||
// that we need more channels, and have 5BTC to use.
|
// that we need more channels, and have 5BTC to use.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{true, 1, 5 * btcutil.SatoshiPerBitcoin}:
|
case constraints.moreChansResps <- moreChansResp{1, 5 * btcutil.SatoshiPerBitcoin}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatal("heuristic wasn't queried in time")
|
t.Fatal("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -384,7 +387,7 @@ func TestAgentChannelFailureSignal(t *testing.T) {
|
|||||||
|
|
||||||
// Now ensure that the controller loop is re-executed.
|
// Now ensure that the controller loop is re-executed.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{true, 1, 5 * btcutil.SatoshiPerBitcoin}:
|
case constraints.moreChansResps <- moreChansResp{1, 5 * btcutil.SatoshiPerBitcoin}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatal("heuristic wasn't queried in time")
|
t.Fatal("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -411,11 +414,13 @@ func TestAgentChannelCloseSignal(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent),
|
openChanSignals: make(chan openChanIntent),
|
||||||
@ -476,7 +481,7 @@ func TestAgentChannelCloseSignal(t *testing.T) {
|
|||||||
// We'll send an initial "no" response to advance the agent past its
|
// We'll send an initial "no" response to advance the agent past its
|
||||||
// initial check.
|
// initial check.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -488,7 +493,7 @@ func TestAgentChannelCloseSignal(t *testing.T) {
|
|||||||
// The agent should now query the heuristic in order to determine its
|
// The agent should now query the heuristic in order to determine its
|
||||||
// next action as it local state has now been modified.
|
// next action as it local state has now been modified.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
// At this point, the local state of the agent should
|
// At this point, the local state of the agent should
|
||||||
// have also been updated to reflect that the LN node
|
// have also been updated to reflect that the LN node
|
||||||
// has no existing open channels.
|
// has no existing open channels.
|
||||||
@ -529,11 +534,13 @@ func TestAgentBalanceUpdate(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent),
|
openChanSignals: make(chan openChanIntent),
|
||||||
@ -589,7 +596,7 @@ func TestAgentBalanceUpdate(t *testing.T) {
|
|||||||
// We'll send an initial "no" response to advance the agent past its
|
// We'll send an initial "no" response to advance the agent past its
|
||||||
// initial check.
|
// initial check.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -605,7 +612,7 @@ func TestAgentBalanceUpdate(t *testing.T) {
|
|||||||
// The agent should now query the heuristic in order to determine its
|
// The agent should now query the heuristic in order to determine its
|
||||||
// next action as it local state has now been modified.
|
// next action as it local state has now been modified.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
// At this point, the local state of the agent should
|
// At this point, the local state of the agent should
|
||||||
// have also been updated to reflect that the LN node
|
// have also been updated to reflect that the LN node
|
||||||
// now has an additional 5BTC available.
|
// now has an additional 5BTC available.
|
||||||
@ -647,11 +654,13 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent),
|
openChanSignals: make(chan openChanIntent),
|
||||||
@ -711,8 +720,7 @@ func TestAgentImmediateAttach(t *testing.T) {
|
|||||||
// We'll send over a response indicating that it should
|
// We'll send over a response indicating that it should
|
||||||
// establish more channels, and give it a budget of 5 BTC to do
|
// establish more channels, and give it a budget of 5 BTC to do
|
||||||
// so.
|
// so.
|
||||||
case heuristic.moreChansResps <- moreChansResp{
|
case constraints.moreChansResps <- moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: numChans,
|
numMore: numChans,
|
||||||
amt: 5 * btcutil.SatoshiPerBitcoin,
|
amt: 5 * btcutil.SatoshiPerBitcoin,
|
||||||
}:
|
}:
|
||||||
@ -790,11 +798,13 @@ func TestAgentPrivateChannels(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
// The chanController should be initialized such that all of its open
|
// The chanController should be initialized such that all of its open
|
||||||
// channel requests are for private channels.
|
// channel requests are for private channels.
|
||||||
@ -854,12 +864,11 @@ func TestAgentPrivateChannels(t *testing.T) {
|
|||||||
// indicating that it should establish more channels, and give it a
|
// indicating that it should establish more channels, and give it a
|
||||||
// budget of 5 BTC to do so.
|
// budget of 5 BTC to do so.
|
||||||
resp := moreChansResp{
|
resp := moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: numChans,
|
numMore: numChans,
|
||||||
amt: 5 * btcutil.SatoshiPerBitcoin,
|
amt: 5 * btcutil.SatoshiPerBitcoin,
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- resp:
|
case constraints.moreChansResps <- resp:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -922,11 +931,13 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent),
|
openChanSignals: make(chan openChanIntent),
|
||||||
@ -985,8 +996,7 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
// attachment. We'll send over a response indicating that it should
|
// attachment. We'll send over a response indicating that it should
|
||||||
// establish more channels, and give it a budget of 1 BTC to do so.
|
// establish more channels, and give it a budget of 1 BTC to do so.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{
|
case constraints.moreChansResps <- moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: 1,
|
numMore: 1,
|
||||||
amt: btcutil.SatoshiPerBitcoin,
|
amt: btcutil.SatoshiPerBitcoin,
|
||||||
}:
|
}:
|
||||||
@ -994,7 +1004,7 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
|
|
||||||
heuristic.moreChanArgs = make(chan moreChanArg)
|
constraints.moreChanArgs = make(chan moreChanArg)
|
||||||
|
|
||||||
// Next, the agent should deliver a query to the Select method of the
|
// Next, the agent should deliver a query to the Select method of the
|
||||||
// heuristic. We'll only return a single directive for a pre-chosen
|
// heuristic. We'll only return a single directive for a pre-chosen
|
||||||
@ -1057,7 +1067,7 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
// The request that we get should include a pending channel for the
|
// The request that we get should include a pending channel for the
|
||||||
// one that we just created, otherwise the agent isn't properly
|
// one that we just created, otherwise the agent isn't properly
|
||||||
// updating its internal state.
|
// updating its internal state.
|
||||||
case req := <-heuristic.moreChanArgs:
|
case req := <-constraints.moreChanArgs:
|
||||||
if len(req.chans) != 1 {
|
if len(req.chans) != 1 {
|
||||||
t.Fatalf("should include pending chan in current "+
|
t.Fatalf("should include pending chan in current "+
|
||||||
"state, instead have %v chans", len(req.chans))
|
"state, instead have %v chans", len(req.chans))
|
||||||
@ -1077,7 +1087,7 @@ func TestAgentPendingChannelState(t *testing.T) {
|
|||||||
// We'll send across a response indicating that it *does* need more
|
// We'll send across a response indicating that it *does* need more
|
||||||
// channels.
|
// channels.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{true, 1, btcutil.SatoshiPerBitcoin}:
|
case constraints.moreChansResps <- moreChansResp{1, btcutil.SatoshiPerBitcoin}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("need more chans wasn't queried in time")
|
t.Fatalf("need more chans wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -1114,11 +1124,13 @@ func TestAgentPendingOpenChannel(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent),
|
openChanSignals: make(chan openChanIntent),
|
||||||
@ -1164,7 +1176,7 @@ func TestAgentPendingOpenChannel(t *testing.T) {
|
|||||||
// We'll send an initial "no" response to advance the agent past its
|
// We'll send an initial "no" response to advance the agent past its
|
||||||
// initial check.
|
// initial check.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -1176,7 +1188,7 @@ func TestAgentPendingOpenChannel(t *testing.T) {
|
|||||||
// The agent should now query the heuristic in order to determine its
|
// The agent should now query the heuristic in order to determine its
|
||||||
// next action as its local state has now been modified.
|
// next action as its local state has now been modified.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{false, 0, 0}:
|
case constraints.moreChansResps <- moreChansResp{0, 0}:
|
||||||
case <-time.After(time.Second * 10):
|
case <-time.After(time.Second * 10):
|
||||||
t.Fatalf("heuristic wasn't queried in time")
|
t.Fatalf("heuristic wasn't queried in time")
|
||||||
}
|
}
|
||||||
@ -1207,11 +1219,13 @@ func TestAgentOnNodeUpdates(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent),
|
openChanSignals: make(chan openChanIntent),
|
||||||
@ -1258,8 +1272,7 @@ func TestAgentOnNodeUpdates(t *testing.T) {
|
|||||||
// initial check. This will cause it to try to get directives from an
|
// initial check. This will cause it to try to get directives from an
|
||||||
// empty graph.
|
// empty graph.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{
|
case constraints.moreChansResps <- moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: 2,
|
numMore: 2,
|
||||||
amt: walletBalance,
|
amt: walletBalance,
|
||||||
}:
|
}:
|
||||||
@ -1283,8 +1296,7 @@ func TestAgentOnNodeUpdates(t *testing.T) {
|
|||||||
// channels. Since we haven't done anything, we will send the same
|
// channels. Since we haven't done anything, we will send the same
|
||||||
// response as before since we are still trying to open channels.
|
// response as before since we are still trying to open channels.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{
|
case constraints.moreChansResps <- moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: 2,
|
numMore: 2,
|
||||||
amt: walletBalance,
|
amt: walletBalance,
|
||||||
}:
|
}:
|
||||||
@ -1320,11 +1332,13 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||||||
|
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
heuristic := &mockHeuristic{
|
heuristic := &mockHeuristic{
|
||||||
moreChansResps: make(chan moreChansResp),
|
|
||||||
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
nodeScoresResps: make(chan map[NodeID]*AttachmentDirective),
|
||||||
quit: quit,
|
quit: quit,
|
||||||
}
|
}
|
||||||
constraints := &mockConstraints{}
|
constraints := &mockConstraints{
|
||||||
|
moreChansResps: make(chan moreChansResp),
|
||||||
|
quit: quit,
|
||||||
|
}
|
||||||
|
|
||||||
chanController := &mockChanController{
|
chanController := &mockChanController{
|
||||||
openChanSignals: make(chan openChanIntent),
|
openChanSignals: make(chan openChanIntent),
|
||||||
@ -1393,8 +1407,7 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||||||
// initial check. This will cause it to try to get directives from the
|
// initial check. This will cause it to try to get directives from the
|
||||||
// graph.
|
// graph.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{
|
case constraints.moreChansResps <- moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: 1,
|
numMore: 1,
|
||||||
amt: walletBalance,
|
amt: walletBalance,
|
||||||
}:
|
}:
|
||||||
@ -1440,8 +1453,7 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||||||
|
|
||||||
// The heuristic again informs the agent that we need more channels.
|
// The heuristic again informs the agent that we need more channels.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{
|
case constraints.moreChansResps <- moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: 1,
|
numMore: 1,
|
||||||
amt: walletBalance,
|
amt: walletBalance,
|
||||||
}:
|
}:
|
||||||
@ -1477,8 +1489,7 @@ func TestAgentSkipPendingConns(t *testing.T) {
|
|||||||
// The agent will now retry since the last connection attempt failed.
|
// The agent will now retry since the last connection attempt failed.
|
||||||
// The heuristic again informs the agent that we need more channels.
|
// The heuristic again informs the agent that we need more channels.
|
||||||
select {
|
select {
|
||||||
case heuristic.moreChansResps <- moreChansResp{
|
case constraints.moreChansResps <- moreChansResp{
|
||||||
needMore: true,
|
|
||||||
numMore: 1,
|
numMore: 1,
|
||||||
amt: walletBalance,
|
amt: walletBalance,
|
||||||
}:
|
}:
|
||||||
|
Loading…
Reference in New Issue
Block a user