mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
graph: export NewErrf and ErrorCode for upcoming gossiper unit tests
This commit is contained in:
parent
8e0d7774b2
commit
9380292a5a
@ -681,7 +681,7 @@ func (b *Builder) handleNetworkUpdate(vb *ValidationBarrier,
|
|||||||
update.err <- err
|
update.err <- err
|
||||||
|
|
||||||
case IsError(err, ErrParentValidationFailed):
|
case IsError(err, ErrParentValidationFailed):
|
||||||
update.err <- newErrf(ErrIgnored, err.Error()) //nolint
|
update.err <- NewErrf(ErrIgnored, err.Error()) //nolint
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Warnf("unexpected error during validation "+
|
log.Warnf("unexpected error during validation "+
|
||||||
@ -1053,7 +1053,7 @@ func (b *Builder) assertNodeAnnFreshness(node route.Vertex,
|
|||||||
"existence of node: %v", err)
|
"existence of node: %v", err)
|
||||||
}
|
}
|
||||||
if !exists {
|
if !exists {
|
||||||
return newErrf(ErrIgnored, "Ignoring node announcement"+
|
return NewErrf(ErrIgnored, "Ignoring node announcement"+
|
||||||
" for node not found in channel graph (%x)",
|
" for node not found in channel graph (%x)",
|
||||||
node[:])
|
node[:])
|
||||||
}
|
}
|
||||||
@ -1063,7 +1063,7 @@ func (b *Builder) assertNodeAnnFreshness(node route.Vertex,
|
|||||||
// if not then we won't accept the new data as it would override newer
|
// if not then we won't accept the new data as it would override newer
|
||||||
// data.
|
// data.
|
||||||
if !lastUpdate.Before(msgTimestamp) {
|
if !lastUpdate.Before(msgTimestamp) {
|
||||||
return newErrf(ErrOutdated, "Ignoring outdated "+
|
return NewErrf(ErrOutdated, "Ignoring outdated "+
|
||||||
"announcement for %x", node[:])
|
"announcement for %x", node[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1193,11 +1193,11 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
"existence: %v", err)
|
"existence: %v", err)
|
||||||
}
|
}
|
||||||
if isZombie {
|
if isZombie {
|
||||||
return newErrf(ErrIgnored, "ignoring msg for zombie "+
|
return NewErrf(ErrIgnored, "ignoring msg for zombie "+
|
||||||
"chan_id=%v", msg.ChannelID)
|
"chan_id=%v", msg.ChannelID)
|
||||||
}
|
}
|
||||||
if exists {
|
if exists {
|
||||||
return newErrf(ErrIgnored, "ignoring msg for known "+
|
return NewErrf(ErrIgnored, "ignoring msg for known "+
|
||||||
"chan_id=%v", msg.ChannelID)
|
"chan_id=%v", msg.ChannelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1259,7 +1259,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
return newErrf(ErrNoFundingTransaction, "unable to "+
|
return NewErrf(ErrNoFundingTransaction, "unable to "+
|
||||||
"locate funding tx: %v", err)
|
"locate funding tx: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1294,7 +1294,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return newErrf(ErrInvalidFundingOutput, "output "+
|
return NewErrf(ErrInvalidFundingOutput, "output "+
|
||||||
"failed validation: %w", err)
|
"failed validation: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1313,7 +1313,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newErrf(ErrChannelSpent, "unable to fetch utxo "+
|
return NewErrf(ErrChannelSpent, "unable to fetch utxo "+
|
||||||
"for chan_id=%v, chan_point=%v: %v",
|
"for chan_id=%v, chan_point=%v: %v",
|
||||||
msg.ChannelID, fundingPoint, err)
|
msg.ChannelID, fundingPoint, err)
|
||||||
}
|
}
|
||||||
@ -1378,7 +1378,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
b.cfg.ChannelPruneExpiry
|
b.cfg.ChannelPruneExpiry
|
||||||
|
|
||||||
if isZombie && isStaleUpdate {
|
if isZombie && isStaleUpdate {
|
||||||
return newErrf(ErrIgnored, "ignoring stale update "+
|
return NewErrf(ErrIgnored, "ignoring stale update "+
|
||||||
"(flags=%v|%v) for zombie chan_id=%v",
|
"(flags=%v|%v) for zombie chan_id=%v",
|
||||||
msg.MessageFlags, msg.ChannelFlags,
|
msg.MessageFlags, msg.ChannelFlags,
|
||||||
msg.ChannelID)
|
msg.ChannelID)
|
||||||
@ -1387,7 +1387,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
// If the channel doesn't exist in our database, we cannot
|
// If the channel doesn't exist in our database, we cannot
|
||||||
// apply the updated policy.
|
// apply the updated policy.
|
||||||
if !exists {
|
if !exists {
|
||||||
return newErrf(ErrIgnored, "ignoring update "+
|
return NewErrf(ErrIgnored, "ignoring update "+
|
||||||
"(flags=%v|%v) for unknown chan_id=%v",
|
"(flags=%v|%v) for unknown chan_id=%v",
|
||||||
msg.MessageFlags, msg.ChannelFlags,
|
msg.MessageFlags, msg.ChannelFlags,
|
||||||
msg.ChannelID)
|
msg.ChannelID)
|
||||||
@ -1405,7 +1405,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
|
|
||||||
// Ignore outdated message.
|
// Ignore outdated message.
|
||||||
if !edge1Timestamp.Before(msg.LastUpdate) {
|
if !edge1Timestamp.Before(msg.LastUpdate) {
|
||||||
return newErrf(ErrOutdated, "Ignoring "+
|
return NewErrf(ErrOutdated, "Ignoring "+
|
||||||
"outdated update (flags=%v|%v) for "+
|
"outdated update (flags=%v|%v) for "+
|
||||||
"known chan_id=%v", msg.MessageFlags,
|
"known chan_id=%v", msg.MessageFlags,
|
||||||
msg.ChannelFlags, msg.ChannelID)
|
msg.ChannelFlags, msg.ChannelID)
|
||||||
@ -1417,7 +1417,7 @@ func (b *Builder) processUpdate(msg interface{},
|
|||||||
|
|
||||||
// Ignore outdated message.
|
// Ignore outdated message.
|
||||||
if !edge2Timestamp.Before(msg.LastUpdate) {
|
if !edge2Timestamp.Before(msg.LastUpdate) {
|
||||||
return newErrf(ErrOutdated, "Ignoring "+
|
return NewErrf(ErrOutdated, "Ignoring "+
|
||||||
"outdated update (flags=%v|%v) for "+
|
"outdated update (flags=%v|%v) for "+
|
||||||
"known chan_id=%v", msg.MessageFlags,
|
"known chan_id=%v", msg.MessageFlags,
|
||||||
msg.ChannelFlags, msg.ChannelID)
|
msg.ChannelFlags, msg.ChannelID)
|
||||||
|
@ -1275,7 +1275,7 @@ func newChannelEdgeInfo(t *testing.T, ctx *testCtx, fundingHeight uint32,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertChanChainRejection(t *testing.T, ctx *testCtx,
|
func assertChanChainRejection(t *testing.T, ctx *testCtx,
|
||||||
edge *models.ChannelEdgeInfo, failCode errorCode) {
|
edge *models.ChannelEdgeInfo, failCode ErrorCode) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
@ -2,14 +2,14 @@ package graph
|
|||||||
|
|
||||||
import "github.com/go-errors/errors"
|
import "github.com/go-errors/errors"
|
||||||
|
|
||||||
// errorCode is used to represent the various errors that can occur within this
|
// ErrorCode is used to represent the various errors that can occur within this
|
||||||
// package.
|
// package.
|
||||||
type errorCode uint8
|
type ErrorCode uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ErrOutdated is returned when the routing update already have
|
// ErrOutdated is returned when the routing update already have
|
||||||
// been applied, or a newer update is already known.
|
// been applied, or a newer update is already known.
|
||||||
ErrOutdated errorCode = iota
|
ErrOutdated ErrorCode = iota
|
||||||
|
|
||||||
// ErrIgnored is returned when the update have been ignored because
|
// ErrIgnored is returned when the update have been ignored because
|
||||||
// this update can't bring us something new, or because a node
|
// this update can't bring us something new, or because a node
|
||||||
@ -39,27 +39,27 @@ const (
|
|||||||
ErrParentValidationFailed
|
ErrParentValidationFailed
|
||||||
)
|
)
|
||||||
|
|
||||||
// graphError is a structure that represent the error inside the graph package,
|
// Error is a structure that represent the error inside the graph package,
|
||||||
// this structure carries additional information about error code in order to
|
// this structure carries additional information about error code in order to
|
||||||
// be able distinguish errors outside of the current package.
|
// be able distinguish errors outside of the current package.
|
||||||
type graphError struct {
|
type Error struct {
|
||||||
err *errors.Error
|
err *errors.Error
|
||||||
code errorCode
|
code ErrorCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error represents errors as the string
|
// Error represents errors as the string
|
||||||
// NOTE: Part of the error interface.
|
// NOTE: Part of the error interface.
|
||||||
func (e *graphError) Error() string {
|
func (e *Error) Error() string {
|
||||||
return e.err.Error()
|
return e.err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
// A compile time check to ensure graphError implements the error interface.
|
// A compile time check to ensure Error implements the error interface.
|
||||||
var _ error = (*graphError)(nil)
|
var _ error = (*Error)(nil)
|
||||||
|
|
||||||
// newErrf creates a graphError by the given error formatted description and
|
// NewErrf creates a Error by the given error formatted description and
|
||||||
// its corresponding error code.
|
// its corresponding error code.
|
||||||
func newErrf(code errorCode, format string, a ...interface{}) *graphError {
|
func NewErrf(code ErrorCode, format string, a ...interface{}) *Error {
|
||||||
return &graphError{
|
return &Error{
|
||||||
code: code,
|
code: code,
|
||||||
err: errors.Errorf(format, a...),
|
err: errors.Errorf(format, a...),
|
||||||
}
|
}
|
||||||
@ -67,8 +67,8 @@ func newErrf(code errorCode, format string, a ...interface{}) *graphError {
|
|||||||
|
|
||||||
// IsError is a helper function which is needed to have ability to check that
|
// IsError is a helper function which is needed to have ability to check that
|
||||||
// returned error has specific error code.
|
// returned error has specific error code.
|
||||||
func IsError(e interface{}, codes ...errorCode) bool {
|
func IsError(e interface{}, codes ...ErrorCode) bool {
|
||||||
err, ok := e.(*graphError)
|
err, ok := e.(*Error)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -238,12 +238,12 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
|||||||
// is closed, or the set of jobs exits.
|
// is closed, or the set of jobs exits.
|
||||||
select {
|
select {
|
||||||
case <-v.quit:
|
case <-v.quit:
|
||||||
return newErrf(ErrVBarrierShuttingDown,
|
return NewErrf(ErrVBarrierShuttingDown,
|
||||||
"validation barrier shutting down")
|
"validation barrier shutting down")
|
||||||
|
|
||||||
case <-signals.deny:
|
case <-signals.deny:
|
||||||
log.Debugf("Signal deny for %s", jobDesc)
|
log.Debugf("Signal deny for %s", jobDesc)
|
||||||
return newErrf(ErrParentValidationFailed,
|
return NewErrf(ErrParentValidationFailed,
|
||||||
"parent validation failed")
|
"parent validation failed")
|
||||||
|
|
||||||
case <-signals.allow:
|
case <-signals.allow:
|
||||||
|
Loading…
Reference in New Issue
Block a user