Skip to content

Commit db8f681

Browse files
authored
Merge pull request #904 from lightninglabs/rfq-poc-modifications
RFQ modifications derived from the tap channels proof-of-concept
2 parents 057880e + 2219033 commit db8f681

30 files changed

+1449
-402
lines changed

cmd/tapd/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/jessevdk/go-flags"
1010
"github.com/lightninglabs/taproot-assets/fn"
11+
"github.com/lightninglabs/taproot-assets/rfq"
1112
"github.com/lightninglabs/taproot-assets/tapcfg"
1213
"github.com/lightningnetwork/lnd/signal"
1314
)
@@ -66,8 +67,15 @@ func main() {
6667
errQueue.Start()
6768
defer errQueue.Stop()
6869

70+
// Use a no-op SCID alias manager temporarily. This will be replaced
71+
// with a real SCID alias manager when the server configuration is
72+
// generated. Passing in the manager at this point facilitates mocking
73+
// in tests.
74+
scidAliasManager := fn.None[rfq.ScidAliasManager]()
75+
6976
server, err := tapcfg.CreateServerFromConfig(
70-
cfg, cfgLogger, shutdownInterceptor, errQueue.ChanIn(),
77+
cfg, cfgLogger, scidAliasManager, shutdownInterceptor,
78+
errQueue.ChanIn(),
7179
)
7280
if err != nil {
7381
err := fmt.Errorf("error creating server: %w", err)

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ require (
2828
github.com/lib/pq v1.10.9
2929
github.com/lightninglabs/aperture v0.1.21-beta.0.20230705004936-87bb996a4030
3030
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
31-
github.com/lightninglabs/lndclient v1.0.1-0.20240301093332-e39221e5a641
31+
github.com/lightninglabs/lndclient v1.0.1-0.20240517142031-cd497ef62933
3232
github.com/lightninglabs/neutrino/cache v1.1.2
33-
github.com/lightningnetwork/lnd v0.17.0-beta.rc6.0.20240423171224-7fb233326eec
33+
github.com/lightningnetwork/lnd v0.17.0-beta.rc6.0.20240514180557-7953d67dbc28
3434
github.com/lightningnetwork/lnd/cert v1.2.2
3535
github.com/lightningnetwork/lnd/clock v1.1.1
36-
github.com/lightningnetwork/lnd/tlv v1.2.3
36+
github.com/lightningnetwork/lnd/fn v1.0.5
37+
github.com/lightningnetwork/lnd/tlv v1.2.6
3738
github.com/lightningnetwork/lnd/tor v1.1.2
3839
github.com/ory/dockertest/v3 v3.10.0
3940
github.com/prometheus/client_golang v1.14.0
@@ -121,7 +122,6 @@ require (
121122
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha // indirect
122123
github.com/lightninglabs/neutrino v0.16.0 // indirect
123124
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f // indirect
124-
github.com/lightningnetwork/lnd/fn v1.0.5 // indirect
125125
github.com/lightningnetwork/lnd/healthcheck v1.2.4 // indirect
126126
github.com/lightningnetwork/lnd/kvdb v1.4.6 // indirect
127127
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ github.com/lightninglabs/lightning-node-connect v0.2.5-alpha h1:ZRVChwczFXK0CEbx
477477
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha/go.mod h1:A9Pof9fETkH+F67BnOmrBDThPKstqp73wlImWOZvTXQ=
478478
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
479479
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
480-
github.com/lightninglabs/lndclient v1.0.1-0.20240301093332-e39221e5a641 h1:gOzlAcE1EL8prHCISjDpFD1tvb9HDxtLEdTVD+ebuc0=
481-
github.com/lightninglabs/lndclient v1.0.1-0.20240301093332-e39221e5a641/go.mod h1:FuD4SXEL3t4J5bu04O+N+k4UcPjsUvGAaT9csWfovbw=
480+
github.com/lightninglabs/lndclient v1.0.1-0.20240517142031-cd497ef62933 h1:lI2pgYoCxvADkf3T5zqBogjiUNo3sdWZgQOnxDDcUVg=
481+
github.com/lightninglabs/lndclient v1.0.1-0.20240517142031-cd497ef62933/go.mod h1:BfM5v3NkYq+RaZuEmTgffsHIqBBHn1szarWj6th75oM=
482482
github.com/lightninglabs/neutrino v0.16.0 h1:YNTQG32fPR/Zg0vvJVI65OBH8l3U18LSXXtX91hx0q0=
483483
github.com/lightninglabs/neutrino v0.16.0/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
484484
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=
@@ -487,8 +487,8 @@ github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display h1:pRdza2wl
487487
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
488488
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f h1:Pua7+5TcFEJXIIZ1I2YAUapmbcttmLj4TTi786bIi3s=
489489
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
490-
github.com/lightningnetwork/lnd v0.17.0-beta.rc6.0.20240423171224-7fb233326eec h1:nLB831P63UL5syyBF6N+tiM5fe0kyy0quppIMazFl04=
491-
github.com/lightningnetwork/lnd v0.17.0-beta.rc6.0.20240423171224-7fb233326eec/go.mod h1:ScU5uVqH+KgPHquZZMCJO5RHVfMMnreLk0t89L4TfD4=
490+
github.com/lightningnetwork/lnd v0.17.0-beta.rc6.0.20240514180557-7953d67dbc28 h1:vS+pP+VAqTXeOElI0kFbzZgR07SLo1Wzh6ECcAa6z1Y=
491+
github.com/lightningnetwork/lnd v0.17.0-beta.rc6.0.20240514180557-7953d67dbc28/go.mod h1:ScU5uVqH+KgPHquZZMCJO5RHVfMMnreLk0t89L4TfD4=
492492
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
493493
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
494494
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
@@ -505,8 +505,8 @@ github.com/lightningnetwork/lnd/sqldb v1.0.1 h1:lpNoJ6qRh3D02oeIUsKQLZUzjcgZ9ppM
505505
github.com/lightningnetwork/lnd/sqldb v1.0.1/go.mod h1:nSovU1U+gTPDWhfwmXu/kW8l8EJpwbvZQ05ijnkQzkA=
506506
github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM=
507507
github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA=
508-
github.com/lightningnetwork/lnd/tlv v1.2.3 h1:If5ibokA/UoCBGuCKaY6Vn2SJU0l9uAbehCnhTZjEP8=
509-
github.com/lightningnetwork/lnd/tlv v1.2.3/go.mod h1:zDkmqxOczP6LaLTvSFDQ1SJUfHcQRCMKFj93dn3eMB8=
508+
github.com/lightningnetwork/lnd/tlv v1.2.6 h1:icvQG2yDr6k3ZuZzfRdG3EJp6pHurcuh3R6dg0gv/Mw=
509+
github.com/lightningnetwork/lnd/tlv v1.2.6/go.mod h1:/CmY4VbItpOldksocmGT4lxiJqRP9oLxwSZOda2kzNQ=
510510
github.com/lightningnetwork/lnd/tor v1.1.2 h1:3zv9z/EivNFaMF89v3ciBjCS7kvCj4ZFG7XvD2Qq0/k=
511511
github.com/lightningnetwork/lnd/tor v1.1.2/go.mod h1:j7T9uJ2NLMaHwE7GiBGnpYLn4f7NRoTM6qj+ul6/ycA=
512512
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=

itest/mock.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package itest
2+
3+
import (
4+
"github.com/lightninglabs/taproot-assets/rfq"
5+
"github.com/lightningnetwork/lnd/lnwire"
6+
)
7+
8+
// MockAliasManager is a mock implementation of the AliasManager interface.
9+
type MockAliasManager struct {
10+
}
11+
12+
// AddLocalAlias is a mock implementation of the AliasManager interface.
13+
func (m *MockAliasManager) AddLocalAlias(_ lnwire.ShortChannelID,
14+
_ lnwire.ShortChannelID, _ bool, _ bool) error {
15+
16+
return nil
17+
}
18+
19+
// DeleteLocalAlias is a mock implementation of the AliasManager interface.
20+
func (m *MockAliasManager) DeleteLocalAlias(_ lnwire.ShortChannelID,
21+
_ lnwire.ShortChannelID) error {
22+
23+
return nil
24+
}
25+
26+
// Ensure MockAliasManager implements the AliasAdder interface.
27+
var _ rfq.ScidAliasManager = (*MockAliasManager)(nil)

itest/rfq_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
7474
require.NoError(t.t, err)
7575

7676
// Carol sends a buy order to Bob for some amount of the newly minted
77-
// asset.
78-
purchaseAssetAmt := uint64(200)
79-
bidAmt := uint64(42000)
77+
// asset. These quantities were selected to work with the price oracle
78+
// mock.
79+
purchaseAssetAmt := uint64(5)
80+
bidAmt := uint64(90000)
8081
buyOrderExpiry := uint64(time.Now().Add(24 * time.Hour).Unix())
8182

8283
_, err = ts.CarolTapd.AddAssetBuyOrder(
@@ -95,6 +96,8 @@ func testRfqAssetBuyHtlcIntercept(t *harnessTest) {
9596
// node to send a request for quote message to Bob's
9697
// node.
9798
PeerPubKey: ts.BobLnd.PubKey[:],
99+
100+
TimeoutSeconds: 5,
98101
},
99102
)
100103
require.NoError(t.t, err, "unable to upsert asset buy order")
@@ -333,7 +336,8 @@ func testRfqAssetSellHtlcIntercept(t *harnessTest) {
333336
aliceBobHop.CustomRecords = make(map[uint64][]byte)
334337
}
335338

336-
aliceBobHop.CustomRecords[rfq.LnCustomRecordType] =
339+
var htlcRfqIDTlvType rfq.HtlcRfqIDTlvType
340+
aliceBobHop.CustomRecords[uint64(htlcRfqIDTlvType.TypeVal())] =
337341
acceptedQuote.Id[:]
338342

339343
// Update the route with the modified first hop.

itest/tapd_harness.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515

1616
"github.com/btcsuite/btcd/chaincfg"
1717
tap "github.com/lightninglabs/taproot-assets"
18+
"github.com/lightninglabs/taproot-assets/fn"
1819
"github.com/lightninglabs/taproot-assets/proof"
20+
"github.com/lightninglabs/taproot-assets/rfq"
1921
"github.com/lightninglabs/taproot-assets/tapcfg"
2022
"github.com/lightninglabs/taproot-assets/tapdb"
2123
"github.com/lightninglabs/taproot-assets/taprpc"
@@ -290,11 +292,21 @@ func (hs *tapdHarness) start(expectErrExit bool) error {
290292
cfgLogger := hs.ht.logWriter.GenSubLogger("CONF", func() {})
291293

292294
var (
295+
// mockScidAliasManager is a mock implementation of the SCID
296+
// alias manager. The SCID alias manager is responsible for
297+
// registering SCID aliases with LND and mapping them to their
298+
// corresponding real channel SCIDs.
299+
mockScidAliasManager = fn.Some[rfq.ScidAliasManager](
300+
&MockAliasManager{},
301+
)
302+
293303
err error
294304
mainErrChan = make(chan error, 10)
295305
)
306+
296307
hs.server, err = tapcfg.CreateServerFromConfig(
297-
hs.clientCfg, cfgLogger, hs.ht.interceptor, mainErrChan,
308+
hs.clientCfg, cfgLogger, mockScidAliasManager,
309+
hs.ht.interceptor, mainErrChan,
298310
)
299311
if err != nil {
300312
return fmt.Errorf("could not create tapd server: %w", err)

itest/test_list_on_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,14 @@ var testCases = []*testCase{
255255
name: "rfq asset buy htlc intercept",
256256
test: testRfqAssetBuyHtlcIntercept,
257257
},
258-
{
259-
name: "rfq asset sell htlc intercept",
260-
test: testRfqAssetSellHtlcIntercept,
261-
},
258+
259+
// TODO(ffranr): Re-enable this test once we have a way to set the
260+
// `WireCustomRecords` field in the first hop `UpdateAddHtlc` p2p
261+
// message
262+
//{
263+
// name: "rfq asset sell htlc intercept",
264+
// test: testRfqAssetSellHtlcIntercept,
265+
//},
262266

263267
{
264268
name: "multi signature on all levels",

rfq/custom_channel_data.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package rfq
2+
3+
// TODO(guggero): De-duplicate by putting into same shared package as the other
4+
// custom channel data structs.
5+
6+
// JsonAssetBalance is a struct that represents the balance of a single asset ID
7+
// within a channel.
8+
type JsonAssetBalance struct {
9+
AssetID string `json:"asset_id"`
10+
Name string `json:"name"`
11+
LocalBalance uint64 `json:"local_balance"`
12+
RemoteBalance uint64 `json:"remote_balance"`
13+
}
14+
15+
// JsonAssetGenesis is a struct that represents the genesis information of an
16+
// asset.
17+
type JsonAssetGenesis struct {
18+
GenesisPoint string `json:"genesis_point"`
19+
Name string `json:"name"`
20+
MetaHash string `json:"meta_hash"`
21+
AssetID string `json:"asset_id"`
22+
}
23+
24+
// JsonAssetUtxo is a struct that represents the UTXO information of an asset
25+
// within a channel.
26+
type JsonAssetUtxo struct {
27+
Version int64 `json:"version"`
28+
AssetGenesis JsonAssetGenesis `json:"asset_genesis"`
29+
Amount uint64 `json:"amount"`
30+
ScriptKey string `json:"script_key"`
31+
}
32+
33+
// JsonAssetChanInfo is a struct that represents the channel information of a
34+
// single asset within a channel.
35+
type JsonAssetChanInfo struct {
36+
AssetInfo JsonAssetUtxo `json:"asset_utxo"`
37+
Capacity uint64 `json:"capacity"`
38+
LocalBalance uint64 `json:"local_balance"`
39+
RemoteBalance uint64 `json:"remote_balance"`
40+
}
41+
42+
// JsonAssetChannel is a struct that represents the channel information of all
43+
// assets within a channel.
44+
type JsonAssetChannel struct {
45+
Assets []JsonAssetChanInfo `json:"assets"`
46+
}

0 commit comments

Comments
 (0)