discovery+graph: convert errors from codes to variables

In preparation for moving funding transaction validiation from the
Builder to the Gossiper in later commit, we first convert these graph
Error Codes to normal error variables. This will help make the later
commit a pure code move.
This commit is contained in:
Elle Mouton committed 2025-02-07 15:26:16 +02:00
1 parent 3c0350e481
commit b117daaa3c
5 files changed
+49 -59

No files matched your search

+4 -6
View File
@@ -1314,8 +1314,7 @@ func (b *Builder) addEdge(edge *models.ChannelEdgeInfo,
default:
}
return NewErrf(ErrNoFundingTransaction, "unable to "+
"locate funding tx: %v", err)
return fmt.Errorf("%w: %w", ErrNoFundingTransaction, err)
}
// Recreate witness output to be sure that declared in channel edge
@@ -1348,8 +1347,7 @@ func (b *Builder) addEdge(edge *models.ChannelEdgeInfo,
return err
}
return NewErrf(ErrInvalidFundingOutput, "output failed "+
"validation: %w", err)
return fmt.Errorf("%w: %w", ErrInvalidFundingOutput, err)
}
// Now that we have the funding outpoint of the channel, ensure
@@ -1366,8 +1364,8 @@ func (b *Builder) addEdge(edge *models.ChannelEdgeInfo,
}
}
return NewErrf(ErrChannelSpent, "unable to fetch utxo for "+
"chan_id=%v, chan_point=%v: %v", edge.ChannelID,
return fmt.Errorf("%w: unable to fetch utxo for chan_id=%v, "+
"chan_point=%v: %w", ErrChannelSpent, scid.ToUint64(),
fundingPoint, err)
}
+2 -4
View File
@@ -1275,14 +1275,12 @@ func newChannelEdgeInfo(t *testing.T, ctx *testCtx, fundingHeight uint32,
}
func assertChanChainRejection(t *testing.T, ctx *testCtx,
edge *models.ChannelEdgeInfo, failCode ErrorCode) {
edge *models.ChannelEdgeInfo, expectedErr error) {
t.Helper()
err := ctx.builder.AddEdge(edge)
if !IsError(err, failCode) {
t.Fatalf("validation should have failed: %v", err)
}
require.ErrorIs(t, err, expectedErr)
// This channel should now be present in the zombie channel index.
_, _, _, isZombie, err := ctx.graph.HasChannelEdge(
+19 -13
View File
@@ -2,6 +2,25 @@ package graph
import "github.com/go-errors/errors"
var (
// ErrNoFundingTransaction is returned when we are unable to find the
// funding transaction described by the short channel ID on chain.
ErrNoFundingTransaction = errors.New(
"unable to find the funding transaction",
)
// ErrInvalidFundingOutput is returned if the channel funding output
// fails validation.
ErrInvalidFundingOutput = errors.New(
"channel funding output validation failed",
)
// ErrChannelSpent is returned when we go to validate a channel, but
// the purported funding output has actually already been spent on
// chain.
ErrChannelSpent = errors.New("channel output has been spent")
)
// ErrorCode is used to represent the various errors that can occur within this
// package.
type ErrorCode uint8
@@ -15,19 +34,6 @@ const (
// this update can't bring us something new, or because a node
// announcement was given for node not found in any channel.
ErrIgnored
// ErrChannelSpent is returned when we go to validate a channel, but
// the purported funding output has actually already been spent on
// chain.
ErrChannelSpent
// ErrNoFundingTransaction is returned when we are unable to find the
// funding transaction described by the short channel ID on chain.
ErrNoFundingTransaction
// ErrInvalidFundingOutput is returned if the channel funding output
// fails validation.
ErrInvalidFundingOutput
)
// Error is a structure that represent the error inside the graph package,