Skip to content

[5/7]: multi: thread ChannelUpdate through codebase #8254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: elle-g175-thread-interfaces-2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions channeldb/models/channel_edge_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,36 @@ func (c *ChannelEdgePolicy2) GetToNode() [33]byte {
// A compile-time check to ensure that ChannelEdgePolicy2 implements the
// ChannelEdgePolicy interface.
var _ ChannelEdgePolicy = (*ChannelEdgePolicy2)(nil)

// EdgePolicyFromUpdate converts the given lnwire.ChannelUpdate into the
// corresponding ChannelEdgePolicy type.
func EdgePolicyFromUpdate(update lnwire.ChannelUpdate) (
ChannelEdgePolicy, error) {

switch upd := update.(type) {
case *lnwire.ChannelUpdate1:
//nolint:lll
return &ChannelEdgePolicy1{
SigBytes: upd.Signature.ToSignatureBytes(),
ChannelID: upd.ShortChannelID.ToUint64(),
LastUpdate: time.Unix(int64(upd.Timestamp), 0),
MessageFlags: upd.MessageFlags,
ChannelFlags: upd.ChannelFlags,
TimeLockDelta: upd.TimeLockDelta,
MinHTLC: upd.HtlcMinimumMsat,
MaxHTLC: upd.HtlcMaximumMsat,
FeeBaseMSat: lnwire.MilliSatoshi(upd.BaseFee),
FeeProportionalMillionths: lnwire.MilliSatoshi(upd.FeeRate),
ExtraOpaqueData: upd.ExtraOpaqueData,
}, nil

case *lnwire.ChannelUpdate2:
return &ChannelEdgePolicy2{
ChannelUpdate2: *upd,
}, nil

default:
return nil, fmt.Errorf("unhandled implementation of "+
"lnwire.ChannelUpdate: %T", update)
}
}
6 changes: 3 additions & 3 deletions discovery/chan_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ChannelGraphTimeSeries interface {
// specified short channel ID. If no channel updates are known for the
// channel, then an empty slice will be returned.
FetchChanUpdates(chain chainhash.Hash,
shortChanID lnwire.ShortChannelID) ([]*lnwire.ChannelUpdate1,
shortChanID lnwire.ShortChannelID) ([]lnwire.ChannelUpdate,
error)
}

Expand Down Expand Up @@ -332,7 +332,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
//
// NOTE: This is part of the ChannelGraphTimeSeries interface.
func (c *ChanSeries) FetchChanUpdates(chain chainhash.Hash,
shortChanID lnwire.ShortChannelID) ([]*lnwire.ChannelUpdate1, error) {
shortChanID lnwire.ShortChannelID) ([]lnwire.ChannelUpdate, error) {

chanInfo, e1, e2, err := c.graph.FetchChannelEdgesByID(
shortChanID.ToUint64(),
Expand All @@ -341,7 +341,7 @@ func (c *ChanSeries) FetchChanUpdates(chain chainhash.Hash,
return nil, err
}

chanUpdates := make([]*lnwire.ChannelUpdate1, 0, 2)
chanUpdates := make([]lnwire.ChannelUpdate, 0, 2)
if e1 != nil {
chanUpdate, err := netann.ChannelUpdateFromEdge(chanInfo, e1)
if err != nil {
Expand Down
Loading