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
|
||||
|
||||
case IsError(err, ErrParentValidationFailed):
|
||||
update.err <- newErrf(ErrIgnored, err.Error()) //nolint
|
||||
update.err <- NewErrf(ErrIgnored, err.Error()) //nolint
|
||||
|
||||
default:
|
||||
log.Warnf("unexpected error during validation "+
|
||||
@ -1053,7 +1053,7 @@ func (b *Builder) assertNodeAnnFreshness(node route.Vertex,
|
||||
"existence of node: %v", err)
|
||||
}
|
||||
if !exists {
|
||||
return newErrf(ErrIgnored, "Ignoring node announcement"+
|
||||
return NewErrf(ErrIgnored, "Ignoring node announcement"+
|
||||
" for node not found in channel graph (%x)",
|
||||
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
|
||||
// data.
|
||||
if !lastUpdate.Before(msgTimestamp) {
|
||||
return newErrf(ErrOutdated, "Ignoring outdated "+
|
||||
return NewErrf(ErrOutdated, "Ignoring outdated "+
|
||||
"announcement for %x", node[:])
|
||||
}
|
||||
|
||||
@ -1193,11 +1193,11 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
"existence: %v", err)
|
||||
}
|
||||
if isZombie {
|
||||
return newErrf(ErrIgnored, "ignoring msg for zombie "+
|
||||
return NewErrf(ErrIgnored, "ignoring msg for zombie "+
|
||||
"chan_id=%v", msg.ChannelID)
|
||||
}
|
||||
if exists {
|
||||
return newErrf(ErrIgnored, "ignoring msg for known "+
|
||||
return NewErrf(ErrIgnored, "ignoring msg for known "+
|
||||
"chan_id=%v", msg.ChannelID)
|
||||
}
|
||||
|
||||
@ -1259,7 +1259,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
default:
|
||||
}
|
||||
|
||||
return newErrf(ErrNoFundingTransaction, "unable to "+
|
||||
return NewErrf(ErrNoFundingTransaction, "unable to "+
|
||||
"locate funding tx: %v", err)
|
||||
}
|
||||
|
||||
@ -1294,7 +1294,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
return err
|
||||
}
|
||||
|
||||
return newErrf(ErrInvalidFundingOutput, "output "+
|
||||
return NewErrf(ErrInvalidFundingOutput, "output "+
|
||||
"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",
|
||||
msg.ChannelID, fundingPoint, err)
|
||||
}
|
||||
@ -1378,7 +1378,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
b.cfg.ChannelPruneExpiry
|
||||
|
||||
if isZombie && isStaleUpdate {
|
||||
return newErrf(ErrIgnored, "ignoring stale update "+
|
||||
return NewErrf(ErrIgnored, "ignoring stale update "+
|
||||
"(flags=%v|%v) for zombie chan_id=%v",
|
||||
msg.MessageFlags, msg.ChannelFlags,
|
||||
msg.ChannelID)
|
||||
@ -1387,7 +1387,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
// If the channel doesn't exist in our database, we cannot
|
||||
// apply the updated policy.
|
||||
if !exists {
|
||||
return newErrf(ErrIgnored, "ignoring update "+
|
||||
return NewErrf(ErrIgnored, "ignoring update "+
|
||||
"(flags=%v|%v) for unknown chan_id=%v",
|
||||
msg.MessageFlags, msg.ChannelFlags,
|
||||
msg.ChannelID)
|
||||
@ -1405,7 +1405,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
|
||||
// Ignore outdated message.
|
||||
if !edge1Timestamp.Before(msg.LastUpdate) {
|
||||
return newErrf(ErrOutdated, "Ignoring "+
|
||||
return NewErrf(ErrOutdated, "Ignoring "+
|
||||
"outdated update (flags=%v|%v) for "+
|
||||
"known chan_id=%v", msg.MessageFlags,
|
||||
msg.ChannelFlags, msg.ChannelID)
|
||||
@ -1417,7 +1417,7 @@ func (b *Builder) processUpdate(msg interface{},
|
||||
|
||||
// Ignore outdated message.
|
||||
if !edge2Timestamp.Before(msg.LastUpdate) {
|
||||
return newErrf(ErrOutdated, "Ignoring "+
|
||||
return NewErrf(ErrOutdated, "Ignoring "+
|
||||
"outdated update (flags=%v|%v) for "+
|
||||
"known chan_id=%v", msg.MessageFlags,
|
||||
msg.ChannelFlags, msg.ChannelID)
|
||||
|
@ -1275,7 +1275,7 @@ func newChannelEdgeInfo(t *testing.T, ctx *testCtx, fundingHeight uint32,
|
||||
}
|
||||
|
||||
func assertChanChainRejection(t *testing.T, ctx *testCtx,
|
||||
edge *models.ChannelEdgeInfo, failCode errorCode) {
|
||||
edge *models.ChannelEdgeInfo, failCode ErrorCode) {
|
||||
|
||||
t.Helper()
|
||||
|
||||
|
@ -2,14 +2,14 @@ package graph
|
||||
|
||||
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.
|
||||
type errorCode uint8
|
||||
type ErrorCode uint8
|
||||
|
||||
const (
|
||||
// ErrOutdated is returned when the routing update already have
|
||||
// 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
|
||||
// this update can't bring us something new, or because a node
|
||||
@ -39,27 +39,27 @@ const (
|
||||
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
|
||||
// be able distinguish errors outside of the current package.
|
||||
type graphError struct {
|
||||
type Error struct {
|
||||
err *errors.Error
|
||||
code errorCode
|
||||
code ErrorCode
|
||||
}
|
||||
|
||||
// Error represents errors as the string
|
||||
// NOTE: Part of the error interface.
|
||||
func (e *graphError) Error() string {
|
||||
func (e *Error) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// A compile time check to ensure graphError implements the error interface.
|
||||
var _ error = (*graphError)(nil)
|
||||
// A compile time check to ensure Error implements the error interface.
|
||||
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.
|
||||
func newErrf(code errorCode, format string, a ...interface{}) *graphError {
|
||||
return &graphError{
|
||||
func NewErrf(code ErrorCode, format string, a ...interface{}) *Error {
|
||||
return &Error{
|
||||
code: code,
|
||||
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
|
||||
// returned error has specific error code.
|
||||
func IsError(e interface{}, codes ...errorCode) bool {
|
||||
err, ok := e.(*graphError)
|
||||
func IsError(e interface{}, codes ...ErrorCode) bool {
|
||||
err, ok := e.(*Error)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
@ -238,12 +238,12 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
||||
// is closed, or the set of jobs exits.
|
||||
select {
|
||||
case <-v.quit:
|
||||
return newErrf(ErrVBarrierShuttingDown,
|
||||
return NewErrf(ErrVBarrierShuttingDown,
|
||||
"validation barrier shutting down")
|
||||
|
||||
case <-signals.deny:
|
||||
log.Debugf("Signal deny for %s", jobDesc)
|
||||
return newErrf(ErrParentValidationFailed,
|
||||
return NewErrf(ErrParentValidationFailed,
|
||||
"parent validation failed")
|
||||
|
||||
case <-signals.allow:
|
||||
|
Loading…
Reference in New Issue
Block a user