Merge pull request #2633 from halseth/autpilot-chansize-allocation
[autopilot] distribute available funds among channels
This commit is contained in:
2 files changed
+515
-886
No files matched your search
+21
-3
@@ -567,10 +567,15 @@ func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32,
|
|||||||
|
|
||||||
// As channel size we'll use the maximum channel size available.
|
// As channel size we'll use the maximum channel size available.
|
||||||
chanSize := a.cfg.Constraints.MaxChanSize()
|
chanSize := a.cfg.Constraints.MaxChanSize()
|
||||||
if availableFunds-chanSize < 0 {
|
if availableFunds < chanSize {
|
||||||
chanSize = availableFunds
|
chanSize = availableFunds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if chanSize < a.cfg.Constraints.MinChanSize() {
|
||||||
|
return fmt.Errorf("not enough funds available to open a " +
|
||||||
|
"single channel")
|
||||||
|
}
|
||||||
|
|
||||||
// Use the heuristic to calculate a score for each node in the
|
// Use the heuristic to calculate a score for each node in the
|
||||||
// graph.
|
// graph.
|
||||||
scores, err := a.cfg.Heuristic.NodeScores(
|
scores, err := a.cfg.Heuristic.NodeScores(
|
||||||
@@ -601,6 +606,17 @@ func (a *Agent) openChans(availableFunds btcutil.Amount, numChans uint32,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Track the available funds we have left.
|
||||||
|
if availableFunds < chanSize {
|
||||||
|
chanSize = availableFunds
|
||||||
|
}
|
||||||
|
availableFunds -= chanSize
|
||||||
|
|
||||||
|
// If we run out of funds, we can break early.
|
||||||
|
if chanSize < a.cfg.Constraints.MinChanSize() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
chanCandidates[nID] = &AttachmentDirective{
|
chanCandidates[nID] = &AttachmentDirective{
|
||||||
NodeID: nID,
|
NodeID: nID,
|
||||||
ChanAmt: chanSize,
|
ChanAmt: chanSize,
|
||||||
@@ -725,8 +741,7 @@ func (a *Agent) executeDirective(directive AttachmentDirective) {
|
|||||||
// fewer slots were available, and other successful attempts finished
|
// fewer slots were available, and other successful attempts finished
|
||||||
// first.
|
// first.
|
||||||
a.pendingMtx.Lock()
|
a.pendingMtx.Lock()
|
||||||
if uint16(len(a.pendingOpens)) >=
|
if uint16(len(a.pendingOpens)) >= a.cfg.Constraints.MaxPendingOpens() {
|
||||||
a.cfg.Constraints.MaxPendingOpens() {
|
|
||||||
// Since we've reached our max number of pending opens, we'll
|
// Since we've reached our max number of pending opens, we'll
|
||||||
// disconnect this peer and exit. However, if we were
|
// disconnect this peer and exit. However, if we were
|
||||||
// previously connected to them, then we'll make sure to
|
// previously connected to them, then we'll make sure to
|
||||||
@@ -799,6 +814,9 @@ func (a *Agent) executeDirective(directive AttachmentDirective) {
|
|||||||
|
|
||||||
// Since the channel open was successful and is currently pending,
|
// Since the channel open was successful and is currently pending,
|
||||||
// we'll trigger the autopilot agent to query for more peers.
|
// we'll trigger the autopilot agent to query for more peers.
|
||||||
|
// TODO(halseth): this triggers a new loop before all the new channels
|
||||||
|
// are added to the pending channels map. Should add before executing
|
||||||
|
// directive in goroutine?
|
||||||
a.OnChannelPendingOpen()
|
a.OnChannelPendingOpen()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+494
-883
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user