discovery+routing: split 'routing' package on 'routing' and 'discovery'
In this commit the routing package was divided on two separete one, this was done because 'routing' package start take too much responsibily on themself, so with following commit: Routing pacakge: Enitites: * channeldb.ChannelEdge * channeldb.ChannelPolicy * channeldb.NodeLightning Responsibilities: * send topology notification * find payment paths * send payment * apply topology changes to the graph * prune graph * validate that funding point exist and corresponds to given one * to be the source of topology data Discovery package: Entities: * lnwire.AnnounceSignature * lnwire.ChannelAnnouncement * lnwire.NodeAnnouncement * lnwire.ChannelUpdateAnnouncement Responsibilities: * validate announcement signatures * sync topology with newly connected peers * handle the premature annoucement * redirect topology changes to the router susbsystem * broadcast announcement to the rest of the network * exchange channel announcement proofs Before that moment all that was in the 'routing' which is quite big for one subsystem. split
This commit is contained in:
1 parent
0e96d273d9
commit
b4ac7071ff
11 files changed
+1543
-683
No files matched your search
+70
-10
@@ -1,31 +1,91 @@
|
||||
package routing
|
||||
|
||||
import "errors"
|
||||
import "github.com/go-errors/errors"
|
||||
|
||||
var (
|
||||
// errorCode represent the error code and is used for compile time check.
|
||||
type errorCode uint8
|
||||
|
||||
const (
|
||||
// ErrNoPathFound is returned when a path to the target destination
|
||||
// does not exist in the graph.
|
||||
ErrNoPathFound = errors.New("unable to find a path to " +
|
||||
"destination")
|
||||
ErrNoPathFound errorCode = iota
|
||||
|
||||
// ErrNoRouteFound is returned when the router is unable to find a
|
||||
// valid route to the target destination after fees and time-lock
|
||||
// limitations are factored in.
|
||||
ErrNoRouteFound = errors.New("unable to find a eligible route to " +
|
||||
"the destination")
|
||||
ErrNoRouteFound
|
||||
|
||||
// ErrInsufficientCapacity is returned when a path if found, yet the
|
||||
// capacity of one of the channels in the path is insufficient to carry
|
||||
// the payment.
|
||||
ErrInsufficientCapacity = errors.New("channel graph has " +
|
||||
"insufficient capacity for the payment")
|
||||
ErrInsufficientCapacity
|
||||
|
||||
// ErrMaxHopsExceeded is returned when a candidate path is found, but
|
||||
// the length of that path exceeds HopLimit.
|
||||
ErrMaxHopsExceeded = errors.New("potential path has too many hops")
|
||||
ErrMaxHopsExceeded
|
||||
|
||||
// ErrTargetNotInNetwork is returned when the target of a path-finding
|
||||
// or payment attempt isn't known to be within the current version of
|
||||
// the channel graph.
|
||||
ErrTargetNotInNetwork = errors.New("target not found")
|
||||
ErrTargetNotInNetwork
|
||||
|
||||
// ErrOutdated is returned when the routing update already have
|
||||
// been applied.
|
||||
ErrOutdated
|
||||
|
||||
// ErrIgnored is returned when the update have been ignored because
|
||||
// this update can't bring us something new.
|
||||
ErrIgnored
|
||||
)
|
||||
|
||||
// routerError is a structure that represent the error inside the routing package,
|
||||
// this structure carries additional information about error code in order to
|
||||
// be able distinguish errors outside of the current package.
|
||||
type routerError struct {
|
||||
err *errors.Error
|
||||
code errorCode
|
||||
}
|
||||
|
||||
// Error represents errors as the string
|
||||
// NOTE: Part of the error interface.
|
||||
func (e *routerError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// A compile time check to ensure routerError implements the error interface.
|
||||
var _ error = (*routerError)(nil)
|
||||
|
||||
// newErr creates an routerError by the given error description and its
|
||||
// corresponding error code.
|
||||
func newErr(code errorCode, a interface{}) *routerError {
|
||||
return &routerError{
|
||||
code: code,
|
||||
err: errors.New(a),
|
||||
}
|
||||
}
|
||||
|
||||
// newErrf creates an routerError by the given error formatted description and
|
||||
// its corresponding error code.
|
||||
func newErrf(code errorCode, format string, a ...interface{}) *routerError {
|
||||
return &routerError{
|
||||
code: code,
|
||||
err: errors.Errorf(format, a...),
|
||||
}
|
||||
}
|
||||
|
||||
// IsError is a helper function which is needed to have ability to check that
|
||||
// returned error has specific error code.
|
||||
func IsError(e interface{}, codes ...errorCode) bool {
|
||||
err, ok := e.(*routerError)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, code := range codes {
|
||||
if err.code == code {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user