Merge pull request #9072 from lightningnetwork/extract-part3-from-staging-branch

[custom channels 3/5]: Extract PART3 from mega staging branch
This commit is contained in:
Oliver Gugger authored and GitHub committed 2024-09-19 01:20:55 -06:00
commit cdad5d988d
40 files changed
+1926 -162

No files matched your search

+32 -5
View File
@@ -2192,10 +2192,20 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
// We just received a new updates to our local commitment
// chain, validate this new commitment, closing the link if
// invalid.
auxSigBlob, err := msg.CustomRecords.Serialize()
if err != nil {
l.failf(
LinkFailureError{code: ErrInvalidCommitment},
"unable to serialize custom records: %v", err,
)
return
}
err = l.channel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: msg.CommitSig,
HtlcSigs: msg.HtlcSigs,
PartialSig: msg.PartialSig,
AuxSigBlob: auxSigBlob,
})
if err != nil {
// If we were unable to reconstruct their proposed
@@ -2622,11 +2632,17 @@ func (l *channelLink) updateCommitTx() error {
default:
}
auxBlobRecords, err := lnwire.ParseCustomRecords(newCommit.AuxSigBlob)
if err != nil {
return fmt.Errorf("error parsing aux sigs: %w", err)
}
commitSig := &lnwire.CommitSig{
ChanID: l.ChanID(),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
ChanID: l.ChanID(),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
CustomRecords: auxBlobRecords,
}
l.cfg.Peer.SendMessage(false, commitSig)
@@ -3778,7 +3794,18 @@ func (l *channelLink) processExitHop(add lnwire.UpdateAddHTLC,
// As we're the exit hop, we'll double check the hop-payload included in
// the HTLC to ensure that it was crafted correctly by the sender and
// is compatible with the HTLC we were extended.
if add.Amount < fwdInfo.AmountToForward {
//
// For a special case, if the fwdInfo doesn't have any blinded path
// information, and the incoming HTLC had special extra data, then
// we'll skip this amount check. The invoice acceptor will make sure we
// reject the HTLC if it's not containing the correct amount after
// examining the custom data.
hasBlindedPath := fwdInfo.NextBlinding.IsSome()
customHTLC := len(add.CustomRecords) > 0 && !hasBlindedPath
log.Tracef("Exit hop has_blinded_path=%v custom_htlc_bypass=%v",
hasBlindedPath, customHTLC)
if !customHTLC && add.Amount < fwdInfo.AmountToForward {
l.log.Errorf("onion payload of incoming htlc(%x) has "+
"incompatible value: expected <=%v, got %v",
add.PaymentHash, add.Amount, fwdInfo.AmountToForward)
+6
View File
@@ -268,9 +268,12 @@ func TestChannelLinkRevThenSig(t *testing.T) {
// Restart Bob as well by calling NewLightningChannel.
bobSigner := harness.bobChannel.Signer
signerMock := lnwallet.NewDefaultAuxSignerMock(t)
bobPool := lnwallet.NewSigPool(runtime.NumCPU(), bobSigner)
bobChannel, err := lnwallet.NewLightningChannel(
bobSigner, harness.bobChannel.State(), bobPool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
require.NoError(t, err)
err = bobPool.Start()
@@ -403,9 +406,12 @@ func TestChannelLinkSigThenRev(t *testing.T) {
// Restart Bob as well by calling NewLightningChannel.
bobSigner := harness.bobChannel.Signer
signerMock := lnwallet.NewDefaultAuxSignerMock(t)
bobPool := lnwallet.NewSigPool(runtime.NumCPU(), bobSigner)
bobChannel, err := lnwallet.NewLightningChannel(
bobSigner, harness.bobChannel.State(), bobPool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
require.NoError(t, err)
err = bobPool.Start()
+9
View File
@@ -353,8 +353,11 @@ func createTestChannel(t *testing.T, alicePrivKey, bobPrivKey []byte,
)
alicePool := lnwallet.NewSigPool(runtime.NumCPU(), aliceSigner)
signerMock := lnwallet.NewDefaultAuxSignerMock(t)
channelAlice, err := lnwallet.NewLightningChannel(
aliceSigner, aliceChannelState, alicePool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
if err != nil {
return nil, nil, err
@@ -364,6 +367,8 @@ func createTestChannel(t *testing.T, alicePrivKey, bobPrivKey []byte,
bobPool := lnwallet.NewSigPool(runtime.NumCPU(), bobSigner)
channelBob, err := lnwallet.NewLightningChannel(
bobSigner, bobChannelState, bobPool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
if err != nil {
return nil, nil, err
@@ -425,6 +430,8 @@ func createTestChannel(t *testing.T, alicePrivKey, bobPrivKey []byte,
newAliceChannel, err := lnwallet.NewLightningChannel(
aliceSigner, aliceStoredChannel, alicePool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
if err != nil {
return nil, errors.Errorf("unable to create new channel: %v",
@@ -471,6 +478,8 @@ func createTestChannel(t *testing.T, alicePrivKey, bobPrivKey []byte,
newBobChannel, err := lnwallet.NewLightningChannel(
bobSigner, bobStoredChannel, bobPool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
if err != nil {
return nil, errors.Errorf("unable to create new channel: %v",