discovery/gossiper: apply TimeLockDelta to edge when processing policy update
Also rename various instances of "FeeUpdate" to "PolicyUpdate"
This commit is contained in:
parent
0b8e7ff836
commit
8370fa2cde
@ -42,13 +42,13 @@ type networkMsg struct {
|
|||||||
err chan error
|
err chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
// feeUpdateRequest is a request that is sent to the server when a caller
|
// chanPolicyUpdateRequest is a request that is sent to the server when a caller
|
||||||
// wishes to update the fees for a particular set of channels. New UpdateFee
|
// wishes to update the channel policy (fees e.g.) for a particular set of
|
||||||
// messages will be crafted to be sent out during the next broadcast epoch and
|
// channels. New ChannelUpdate messages will be crafted to be sent out during
|
||||||
// the fee updates committed to the lower layer.
|
// the next broadcast epoch and the fee updates committed to the lower layer.
|
||||||
type feeUpdateRequest struct {
|
type chanPolicyUpdateRequest struct {
|
||||||
targetChans []wire.OutPoint
|
targetChans []wire.OutPoint
|
||||||
newSchema routing.FeeSchema
|
newSchema routing.ChannelPolicy
|
||||||
|
|
||||||
errResp chan error
|
errResp chan error
|
||||||
}
|
}
|
||||||
@ -175,9 +175,9 @@ type AuthenticatedGossiper struct {
|
|||||||
// networkHandler.
|
// networkHandler.
|
||||||
networkMsgs chan *networkMsg
|
networkMsgs chan *networkMsg
|
||||||
|
|
||||||
// feeUpdates is a channel that requests to update the fee schedule of
|
// chanPolicyUpdates is a channel that requests to update the forwarding
|
||||||
// a set of channels is sent over.
|
// policy of a set of channels is sent over.
|
||||||
feeUpdates chan *feeUpdateRequest
|
chanPolicyUpdates chan *chanPolicyUpdateRequest
|
||||||
|
|
||||||
// bestHeight is the height of the block at the tip of the main chain
|
// bestHeight is the height of the block at the tip of the main chain
|
||||||
// as we know it.
|
// as we know it.
|
||||||
@ -202,7 +202,7 @@ func New(cfg Config, selfKey *btcec.PublicKey) (*AuthenticatedGossiper, error) {
|
|||||||
cfg: &cfg,
|
cfg: &cfg,
|
||||||
networkMsgs: make(chan *networkMsg),
|
networkMsgs: make(chan *networkMsg),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
feeUpdates: make(chan *feeUpdateRequest),
|
chanPolicyUpdates: make(chan *chanPolicyUpdateRequest),
|
||||||
prematureAnnouncements: make(map[uint32][]*networkMsg),
|
prematureAnnouncements: make(map[uint32][]*networkMsg),
|
||||||
prematureChannelUpdates: make(map[uint64][]*networkMsg),
|
prematureChannelUpdates: make(map[uint64][]*networkMsg),
|
||||||
waitingProofs: storage,
|
waitingProofs: storage,
|
||||||
@ -296,24 +296,24 @@ func (d *AuthenticatedGossiper) SynchronizeNode(pub *btcec.PublicKey) error {
|
|||||||
return d.cfg.SendToPeer(pub, announceMessages...)
|
return d.cfg.SendToPeer(pub, announceMessages...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PropagateFeeUpdate signals the AuthenticatedGossiper to update the fee
|
// PropagateChanPolicyUpdate signals the AuthenticatedGossiper to update the
|
||||||
// schema for the specified channels. If no channels are specified, then the
|
// channel forwarding policies for the specified channels. If no channels are
|
||||||
// fee update will be applied to all outgoing channels from the source node.
|
// specified, then the update will be applied to all outgoing channels from the
|
||||||
// Fee updates are done in two stages: first, the AuthenticatedGossiper ensures
|
// source node. Policy updates are done in two stages: first, the
|
||||||
// the updated has been committed by dependant sub-systems, then it signs and
|
// AuthenticatedGossiper ensures the update has been committed by dependant
|
||||||
// broadcasts new updates to the network.
|
// sub-systems, then it signs and broadcasts new updates to the network.
|
||||||
func (d *AuthenticatedGossiper) PropagateFeeUpdate(newSchema routing.FeeSchema,
|
func (d *AuthenticatedGossiper) PropagateChanPolicyUpdate(
|
||||||
chanPoints ...wire.OutPoint) error {
|
newSchema routing.ChannelPolicy, chanPoints ...wire.OutPoint) error {
|
||||||
|
|
||||||
errChan := make(chan error, 1)
|
errChan := make(chan error, 1)
|
||||||
feeUpdate := &feeUpdateRequest{
|
policyUpdate := &chanPolicyUpdateRequest{
|
||||||
targetChans: chanPoints,
|
targetChans: chanPoints,
|
||||||
newSchema: newSchema,
|
newSchema: newSchema,
|
||||||
errResp: errChan,
|
errResp: errChan,
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case d.feeUpdates <- feeUpdate:
|
case d.chanPolicyUpdates <- policyUpdate:
|
||||||
return <-errChan
|
return <-errChan
|
||||||
case <-d.quit:
|
case <-d.quit:
|
||||||
return fmt.Errorf("AuthenticatedGossiper shutting down")
|
return fmt.Errorf("AuthenticatedGossiper shutting down")
|
||||||
@ -823,17 +823,18 @@ func (d *AuthenticatedGossiper) networkHandler() {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
// A new fee update has arrived. We'll commit it to the
|
// A new policy update has arrived. We'll commit it to the
|
||||||
// sub-systems below us, then craft, sign, and broadcast a new
|
// sub-systems below us, then craft, sign, and broadcast a new
|
||||||
// ChannelUpdate for the set of affected clients.
|
// ChannelUpdate for the set of affected clients.
|
||||||
case feeUpdate := <-d.feeUpdates:
|
case policyUpdate := <-d.chanPolicyUpdates:
|
||||||
// First, we'll now create new fully signed updates for
|
// First, we'll now create new fully signed updates for
|
||||||
// the affected channels and also update the underlying
|
// the affected channels and also update the underlying
|
||||||
// graph with the new state.
|
// graph with the new state.
|
||||||
newChanUpdates, err := d.processFeeChanUpdate(feeUpdate)
|
newChanUpdates, err := d.processChanPolicyUpdate(policyUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unable to craft fee updates: %v", err)
|
log.Errorf("Unable to craft policy updates: %v",
|
||||||
feeUpdate.errResp <- err
|
err)
|
||||||
|
policyUpdate.errResp <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -842,7 +843,7 @@ func (d *AuthenticatedGossiper) networkHandler() {
|
|||||||
// start of the next epoch.
|
// start of the next epoch.
|
||||||
announcements.AddMsgs(newChanUpdates...)
|
announcements.AddMsgs(newChanUpdates...)
|
||||||
|
|
||||||
feeUpdate.errResp <- nil
|
policyUpdate.errResp <- nil
|
||||||
|
|
||||||
case announcement := <-d.networkMsgs:
|
case announcement := <-d.networkMsgs:
|
||||||
// Channel annoucnement signatures are the only message
|
// Channel annoucnement signatures are the only message
|
||||||
@ -1072,18 +1073,19 @@ func (d *AuthenticatedGossiper) retransmitStaleChannels() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// processFeeChanUpdate generates a new set of channel updates with the new fee
|
// processChanPolicyUpdate generates a new set of channel updates with the new
|
||||||
// schema applied for each specified channel identified by its channel point.
|
// channel policy applied for each specified channel identified by its channel
|
||||||
// In the case that no channel points are specified, then the fee update will
|
// point. In the case that no channel points are specified, then the update will
|
||||||
// be applied to all channels. Finally, the backing ChannelGraphSource is
|
// be applied to all channels. Finally, the backing ChannelGraphSource is
|
||||||
// updated with the latest information reflecting the applied fee updates.
|
// updated with the latest information reflecting the applied updates.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): generalize into generic for any channel update
|
// TODO(roasbeef): generalize into generic for any channel update
|
||||||
func (d *AuthenticatedGossiper) processFeeChanUpdate(feeUpdate *feeUpdateRequest) ([]networkMsg, error) {
|
func (d *AuthenticatedGossiper) processChanPolicyUpdate(
|
||||||
|
policyUpdate *chanPolicyUpdateRequest) ([]networkMsg, error) {
|
||||||
// First, we'll construct a set of all the channels that need to be
|
// First, we'll construct a set of all the channels that need to be
|
||||||
// updated.
|
// updated.
|
||||||
chansToUpdate := make(map[wire.OutPoint]struct{})
|
chansToUpdate := make(map[wire.OutPoint]struct{})
|
||||||
for _, chanPoint := range feeUpdate.targetChans {
|
for _, chanPoint := range policyUpdate.targetChans {
|
||||||
chansToUpdate[chanPoint] = struct{}{}
|
chansToUpdate[chanPoint] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,11 +1106,14 @@ func (d *AuthenticatedGossiper) processFeeChanUpdate(feeUpdate *feeUpdateRequest
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply the new fee schema to the edge.
|
// Apply the new fee schema to the edge.
|
||||||
edge.FeeBaseMSat = feeUpdate.newSchema.BaseFee
|
edge.FeeBaseMSat = policyUpdate.newSchema.BaseFee
|
||||||
edge.FeeProportionalMillionths = lnwire.MilliSatoshi(
|
edge.FeeProportionalMillionths = lnwire.MilliSatoshi(
|
||||||
feeUpdate.newSchema.FeeRate,
|
policyUpdate.newSchema.FeeRate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Apply the new TimeLockDelta.
|
||||||
|
edge.TimeLockDelta = uint16(policyUpdate.newSchema.TimeLockDelta)
|
||||||
|
|
||||||
// Re-sign and update the backing ChannelGraphSource, and
|
// Re-sign and update the backing ChannelGraphSource, and
|
||||||
// retrieve our ChannelUpdate to broadcast.
|
// retrieve our ChannelUpdate to broadcast.
|
||||||
_, chanUpdate, err := d.updateChannel(info, edge)
|
_, chanUpdate, err := d.updateChannel(info, edge)
|
||||||
|
Loading…
Reference in New Issue
Block a user