htlcswitch: handle update_fee message received from peer.
This commit makes the channellink update a channel's fee if an update_fee message is received from the peer.
This commit is contained in:
parent
ebe05f6568
commit
f4db249cb8
@ -638,6 +638,15 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
case *lnwire.UpdateFee:
|
||||||
|
// We received fee update from peer. If we are the initator we will fail the
|
||||||
|
// channel, if not we will apply the update.
|
||||||
|
fee := msg.FeePerKw
|
||||||
|
if err := l.channel.ReceiveUpdateFee(fee); err != nil {
|
||||||
|
log.Errorf("error receiving fee update: %v", err)
|
||||||
|
l.cfg.Peer.Disconnect()
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -810,6 +819,19 @@ func (l *channelLink) HandleChannelUpdate(message lnwire.Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateChannelFee updates the commitment fee-per-kw on this channel by
|
||||||
|
// committing to an update_fee message.
|
||||||
|
func (l *channelLink) updateChannelFee(feePerKw btcutil.Amount) error {
|
||||||
|
// Update local fee.
|
||||||
|
if err := l.channel.UpdateFee(feePerKw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send fee update to remote.
|
||||||
|
msg := lnwire.NewUpdateFee(l.ChanID(), feePerKw)
|
||||||
|
return l.cfg.Peer.SendMessage(msg)
|
||||||
|
}
|
||||||
|
|
||||||
// processLockedInHtlcs serially processes each of the log updates which have
|
// processLockedInHtlcs serially processes each of the log updates which have
|
||||||
// been "locked-in". An HTLC is considered locked-in once it has been fully
|
// been "locked-in". An HTLC is considered locked-in once it has been fully
|
||||||
// committed to in both the remote and local commitment state. Once a channel
|
// committed to in both the remote and local commitment state. Once a channel
|
||||||
|
@ -252,7 +252,7 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TestChannelLinkMultiHopPayment checks the ability to send payment over two
|
// TestChannelLinkMultiHopPayment checks the ability to send payment over two
|
||||||
// hopes. In this test we send the payment from Carol to Alice over Bob peer.
|
// hops. In this test we send the payment from Carol to Alice over Bob peer.
|
||||||
// (Carol -> Bob -> Alice) and checking that HTLC was settled properly and
|
// (Carol -> Bob -> Alice) and checking that HTLC was settled properly and
|
||||||
// balances were changed in two channels.
|
// balances were changed in two channels.
|
||||||
func TestChannelLinkMultiHopPayment(t *testing.T) {
|
func TestChannelLinkMultiHopPayment(t *testing.T) {
|
||||||
|
@ -46,8 +46,8 @@ func generateRandomBytes(n int) ([]byte, error) {
|
|||||||
|
|
||||||
// createTestChannel creates the channel and returns our and remote channels
|
// createTestChannel creates the channel and returns our and remote channels
|
||||||
// representations.
|
// representations.
|
||||||
func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
func createTestChannel(alicePrivKey, bobPrivKey []byte, aliceAmount, bobAmount,
|
||||||
aliceAmount, bobAmount btcutil.Amount, chanID lnwire.ShortChannelID) (
|
feePerKw btcutil.Amount, chanID lnwire.ShortChannelID) (
|
||||||
*lnwallet.LightningChannel, *lnwallet.LightningChannel, func(), error) {
|
*lnwallet.LightningChannel, *lnwallet.LightningChannel, func(), error) {
|
||||||
|
|
||||||
aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes(btcec.S256(), alicePrivKey)
|
aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes(btcec.S256(), alicePrivKey)
|
||||||
@ -58,6 +58,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
bobDustLimit := btcutil.Amount(800)
|
bobDustLimit := btcutil.Amount(800)
|
||||||
csvTimeoutAlice := uint32(5)
|
csvTimeoutAlice := uint32(5)
|
||||||
csvTimeoutBob := uint32(4)
|
csvTimeoutBob := uint32(4)
|
||||||
|
commitFee := (feePerKw * btcutil.Amount(724)) / 1000
|
||||||
|
|
||||||
witnessScript, _, err := lnwallet.GenFundingPkScript(
|
witnessScript, _, err := lnwallet.GenFundingPkScript(
|
||||||
aliceKeyPub.SerializeCompressed(),
|
aliceKeyPub.SerializeCompressed(),
|
||||||
@ -107,7 +108,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
bobKeyPub,
|
bobKeyPub,
|
||||||
aliceRevokeKey,
|
aliceRevokeKey,
|
||||||
csvTimeoutAlice,
|
csvTimeoutAlice,
|
||||||
aliceAmount,
|
aliceAmount-commitFee,
|
||||||
bobAmount,
|
bobAmount,
|
||||||
lnwallet.DefaultDustLimit(),
|
lnwallet.DefaultDustLimit(),
|
||||||
)
|
)
|
||||||
@ -121,7 +122,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
bobRevokeKey,
|
bobRevokeKey,
|
||||||
csvTimeoutBob,
|
csvTimeoutBob,
|
||||||
bobAmount,
|
bobAmount,
|
||||||
aliceAmount,
|
aliceAmount-commitFee,
|
||||||
lnwallet.DefaultDustLimit(),
|
lnwallet.DefaultDustLimit(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -146,13 +147,15 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
aliceChannelState := &channeldb.OpenChannel{
|
aliceChannelState := &channeldb.OpenChannel{
|
||||||
IdentityPub: aliceKeyPub,
|
IdentityPub: aliceKeyPub,
|
||||||
ChanID: prevOut,
|
ChanID: prevOut,
|
||||||
|
CommitFee: commitFee,
|
||||||
|
FeePerKw: feePerKw,
|
||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
IsInitiator: true,
|
IsInitiator: true,
|
||||||
StateHintObsfucator: obsfucator,
|
StateHintObsfucator: obsfucator,
|
||||||
OurCommitKey: aliceKeyPub,
|
OurCommitKey: aliceKeyPub,
|
||||||
TheirCommitKey: bobKeyPub,
|
TheirCommitKey: bobKeyPub,
|
||||||
Capacity: channelCapacity,
|
Capacity: channelCapacity,
|
||||||
OurBalance: aliceAmount,
|
OurBalance: aliceAmount - commitFee,
|
||||||
TheirBalance: bobAmount,
|
TheirBalance: bobAmount,
|
||||||
OurCommitTx: aliceCommitTx,
|
OurCommitTx: aliceCommitTx,
|
||||||
OurCommitSig: bytes.Repeat([]byte{1}, 71),
|
OurCommitSig: bytes.Repeat([]byte{1}, 71),
|
||||||
@ -173,6 +176,8 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
bobChannelState := &channeldb.OpenChannel{
|
bobChannelState := &channeldb.OpenChannel{
|
||||||
IdentityPub: bobKeyPub,
|
IdentityPub: bobKeyPub,
|
||||||
ChanID: prevOut,
|
ChanID: prevOut,
|
||||||
|
CommitFee: commitFee,
|
||||||
|
FeePerKw: feePerKw,
|
||||||
ChanType: channeldb.SingleFunder,
|
ChanType: channeldb.SingleFunder,
|
||||||
IsInitiator: false,
|
IsInitiator: false,
|
||||||
StateHintObsfucator: obsfucator,
|
StateHintObsfucator: obsfucator,
|
||||||
@ -180,7 +185,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
|||||||
TheirCommitKey: aliceKeyPub,
|
TheirCommitKey: aliceKeyPub,
|
||||||
Capacity: channelCapacity,
|
Capacity: channelCapacity,
|
||||||
OurBalance: bobAmount,
|
OurBalance: bobAmount,
|
||||||
TheirBalance: aliceAmount,
|
TheirBalance: aliceAmount - commitFee,
|
||||||
OurCommitTx: bobCommitTx,
|
OurCommitTx: bobCommitTx,
|
||||||
OurCommitSig: bytes.Repeat([]byte{1}, 71),
|
OurCommitSig: bytes.Repeat([]byte{1}, 71),
|
||||||
FundingOutpoint: prevOut,
|
FundingOutpoint: prevOut,
|
||||||
@ -502,13 +507,13 @@ func newThreeHopNetwork(t *testing.T, aliceToBob,
|
|||||||
|
|
||||||
// Create lightning channels between Alice<->Bob and Bob<->Carol
|
// Create lightning channels between Alice<->Bob and Bob<->Carol
|
||||||
aliceChannel, firstBobChannel, fCleanUp, err := createTestChannel(
|
aliceChannel, firstBobChannel, fCleanUp, err := createTestChannel(
|
||||||
alicePrivKey, bobPrivKey, aliceToBob, aliceToBob, firstChanID)
|
alicePrivKey, bobPrivKey, aliceToBob, aliceToBob, 0, firstChanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create alice<->bob channel: %v", err)
|
t.Fatalf("unable to create alice<->bob channel: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
secondBobChannel, carolChannel, sCleanUp, err := createTestChannel(
|
secondBobChannel, carolChannel, sCleanUp, err := createTestChannel(
|
||||||
bobPrivKey, carolPrivKey, bobToCarol, bobToCarol, secondChanID)
|
bobPrivKey, carolPrivKey, bobToCarol, bobToCarol, 0, secondChanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create bob<->carol channel: %v", err)
|
t.Fatalf("unable to create bob<->carol channel: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user