1
1
package graph
2
2
3
3
import (
4
- "bytes"
5
4
"fmt"
6
5
"strings"
7
6
"sync"
@@ -10,15 +9,12 @@ import (
10
9
11
10
"github.com/btcsuite/btcd/btcec/v2"
12
11
"github.com/btcsuite/btcd/btcutil"
13
- "github.com/btcsuite/btcd/chaincfg/chainhash"
14
12
"github.com/btcsuite/btcd/wire"
15
13
"github.com/go-errors/errors"
16
14
"github.com/lightningnetwork/lnd/batch"
17
15
"github.com/lightningnetwork/lnd/chainntnfs"
18
- "github.com/lightningnetwork/lnd/fn/v2"
19
16
graphdb "github.com/lightningnetwork/lnd/graph/db"
20
17
"github.com/lightningnetwork/lnd/graph/db/models"
21
- "github.com/lightningnetwork/lnd/input"
22
18
"github.com/lightningnetwork/lnd/kvdb"
23
19
"github.com/lightningnetwork/lnd/lnutils"
24
20
"github.com/lightningnetwork/lnd/lnwallet"
@@ -1024,72 +1020,6 @@ func (b *Builder) MarkZombieEdge(chanID uint64) error {
1024
1020
return nil
1025
1021
}
1026
1022
1027
- // makeFundingScript is used to make the funding script for both segwit v0 and
1028
- // segwit v1 (taproot) channels.
1029
- //
1030
- // TODO(roasbeef: export and use elsewhere?
1031
- func makeFundingScript (bitcoinKey1 , bitcoinKey2 []byte , chanFeatures []byte ,
1032
- tapscriptRoot fn.Option [chainhash.Hash ]) ([]byte , error ) {
1033
-
1034
- legacyFundingScript := func () ([]byte , error ) {
1035
- witnessScript , err := input .GenMultiSigScript (
1036
- bitcoinKey1 , bitcoinKey2 ,
1037
- )
1038
- if err != nil {
1039
- return nil , err
1040
- }
1041
- pkScript , err := input .WitnessScriptHash (witnessScript )
1042
- if err != nil {
1043
- return nil , err
1044
- }
1045
-
1046
- return pkScript , nil
1047
- }
1048
-
1049
- if len (chanFeatures ) == 0 {
1050
- return legacyFundingScript ()
1051
- }
1052
-
1053
- // In order to make the correct funding script, we'll need to parse the
1054
- // chanFeatures bytes into a feature vector we can interact with.
1055
- rawFeatures := lnwire .NewRawFeatureVector ()
1056
- err := rawFeatures .Decode (bytes .NewReader (chanFeatures ))
1057
- if err != nil {
1058
- return nil , fmt .Errorf ("unable to parse chan feature " +
1059
- "bits: %w" , err )
1060
- }
1061
-
1062
- chanFeatureBits := lnwire .NewFeatureVector (
1063
- rawFeatures , lnwire .Features ,
1064
- )
1065
- if chanFeatureBits .HasFeature (
1066
- lnwire .SimpleTaprootChannelsOptionalStaging ,
1067
- ) {
1068
-
1069
- pubKey1 , err := btcec .ParsePubKey (bitcoinKey1 )
1070
- if err != nil {
1071
- return nil , err
1072
- }
1073
- pubKey2 , err := btcec .ParsePubKey (bitcoinKey2 )
1074
- if err != nil {
1075
- return nil , err
1076
- }
1077
-
1078
- fundingScript , _ , err := input .GenTaprootFundingScript (
1079
- pubKey1 , pubKey2 , 0 , tapscriptRoot ,
1080
- )
1081
- if err != nil {
1082
- return nil , err
1083
- }
1084
-
1085
- // TODO(roasbeef): add tapscript root to gossip v1.5
1086
-
1087
- return fundingScript , nil
1088
- }
1089
-
1090
- return legacyFundingScript ()
1091
- }
1092
-
1093
1023
// routingMsg couples a routing related routing topology update to the
1094
1024
// error channel.
1095
1025
type routingMsg struct {
@@ -1278,6 +1208,16 @@ func (b *Builder) addEdge(edge *models.ChannelEdgeInfo,
1278
1208
return nil
1279
1209
}
1280
1210
1211
+ // If AssumeChannelValid is false, then we expect the funding script to
1212
+ // be present on the edge since it would have been fetched when the
1213
+ // gossiper validated the announcement.
1214
+ fundingPkScript , err := edge .FundingScript .UnwrapOrErr (fmt .Errorf (
1215
+ "expected the funding transaction script to be set" ,
1216
+ ))
1217
+ if err != nil {
1218
+ return err
1219
+ }
1220
+
1281
1221
// Before we can add the channel to the channel graph, we need to obtain
1282
1222
// the full funding outpoint that's encoded within the channel ID.
1283
1223
channelID := lnwire .NewShortChanIDFromInt (edge .ChannelID )
@@ -1317,16 +1257,6 @@ func (b *Builder) addEdge(edge *models.ChannelEdgeInfo,
1317
1257
return fmt .Errorf ("%w: %w" , ErrNoFundingTransaction , err )
1318
1258
}
1319
1259
1320
- // Recreate witness output to be sure that declared in channel edge
1321
- // bitcoin keys and channel value corresponds to the reality.
1322
- fundingPkScript , err := makeFundingScript (
1323
- edge .BitcoinKey1Bytes [:], edge .BitcoinKey2Bytes [:],
1324
- edge .Features , edge .TapscriptRoot ,
1325
- )
1326
- if err != nil {
1327
- return err
1328
- }
1329
-
1330
1260
// Next we'll validate that this channel is actually well formed. If
1331
1261
// this check fails, then this channel either doesn't exist, or isn't
1332
1262
// the one that was meant to be created according to the passed channel
0 commit comments