discovery/gossiper: use netann pkg for signing channel updates
This commit is contained in:
parent
5147a6d63d
commit
5c2fc4a2d6
@ -2462,32 +2462,14 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
|
|||||||
edge *channeldb.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement,
|
edge *channeldb.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement,
|
||||||
*lnwire.ChannelUpdate, error) {
|
*lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
// Make sure timestamp is always increased, such that our update gets
|
// Parse the unsigned edge into a channel update.
|
||||||
// propagated.
|
chanUpdate := netann.UnsignedChannelUpdateFromEdge(info, edge)
|
||||||
timestamp := time.Now().Unix()
|
|
||||||
if timestamp <= edge.LastUpdate.Unix() {
|
|
||||||
timestamp = edge.LastUpdate.Unix() + 1
|
|
||||||
}
|
|
||||||
edge.LastUpdate = time.Unix(timestamp, 0)
|
|
||||||
|
|
||||||
chanUpdate := &lnwire.ChannelUpdate{
|
// We'll generate a new signature over a digest of the channel
|
||||||
ChainHash: info.ChainHash,
|
// announcement itself and update the timestamp to ensure it propagate.
|
||||||
ShortChannelID: lnwire.NewShortChanIDFromInt(edge.ChannelID),
|
err := netann.SignChannelUpdate(
|
||||||
Timestamp: uint32(timestamp),
|
|
||||||
MessageFlags: edge.MessageFlags,
|
|
||||||
ChannelFlags: edge.ChannelFlags,
|
|
||||||
TimeLockDelta: edge.TimeLockDelta,
|
|
||||||
HtlcMinimumMsat: edge.MinHTLC,
|
|
||||||
HtlcMaximumMsat: edge.MaxHTLC,
|
|
||||||
BaseFee: uint32(edge.FeeBaseMSat),
|
|
||||||
FeeRate: uint32(edge.FeeProportionalMillionths),
|
|
||||||
ExtraOpaqueData: edge.ExtraOpaqueData,
|
|
||||||
}
|
|
||||||
|
|
||||||
// With the update applied, we'll generate a new signature over a
|
|
||||||
// digest of the channel announcement itself.
|
|
||||||
sig, err := netann.SignAnnouncement(
|
|
||||||
d.cfg.AnnSigner, d.selfKey, chanUpdate,
|
d.cfg.AnnSigner, d.selfKey, chanUpdate,
|
||||||
|
netann.ChanUpdSetTimestamp,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -2495,11 +2477,8 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
|
|||||||
|
|
||||||
// Next, we'll set the new signature in place, and update the reference
|
// Next, we'll set the new signature in place, and update the reference
|
||||||
// in the backing slice.
|
// in the backing slice.
|
||||||
edge.SetSigBytes(sig.Serialize())
|
edge.LastUpdate = time.Unix(int64(chanUpdate.Timestamp), 0)
|
||||||
chanUpdate.Signature, err = lnwire.NewSigFromSignature(sig)
|
edge.SigBytes = chanUpdate.Signature.ToSignatureBytes()
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// To ensure that our signature is valid, we'll verify it ourself
|
// To ensure that our signature is valid, we'll verify it ourself
|
||||||
// before committing it to the slice returned.
|
// before committing it to the slice returned.
|
||||||
|
@ -111,12 +111,12 @@ func ExtractChannelUpdate(ownerPubKey []byte,
|
|||||||
info.ChannelPoint)
|
info.ChannelPoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge
|
// UnsignedChannelUpdateFromEdge reconstructs an unsigned ChannelUpdate from the
|
||||||
// info and policy.
|
// given edge info and policy.
|
||||||
func ChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
|
func UnsignedChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
|
||||||
policy *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) {
|
policy *channeldb.ChannelEdgePolicy) *lnwire.ChannelUpdate {
|
||||||
|
|
||||||
update := &lnwire.ChannelUpdate{
|
return &lnwire.ChannelUpdate{
|
||||||
ChainHash: info.ChainHash,
|
ChainHash: info.ChainHash,
|
||||||
ShortChannelID: lnwire.NewShortChanIDFromInt(policy.ChannelID),
|
ShortChannelID: lnwire.NewShortChanIDFromInt(policy.ChannelID),
|
||||||
Timestamp: uint32(policy.LastUpdate.Unix()),
|
Timestamp: uint32(policy.LastUpdate.Unix()),
|
||||||
@ -129,6 +129,14 @@ func ChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
|
|||||||
FeeRate: uint32(policy.FeeProportionalMillionths),
|
FeeRate: uint32(policy.FeeProportionalMillionths),
|
||||||
ExtraOpaqueData: policy.ExtraOpaqueData,
|
ExtraOpaqueData: policy.ExtraOpaqueData,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge
|
||||||
|
// info and policy.
|
||||||
|
func ChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
|
||||||
|
policy *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
|
update := UnsignedChannelUpdateFromEdge(info, policy)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
update.Signature, err = lnwire.NewSigFromRawSignature(policy.SigBytes)
|
update.Signature, err = lnwire.NewSigFromRawSignature(policy.SigBytes)
|
||||||
|
Loading…
Reference in New Issue
Block a user