Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A minimal version of the RFQ system #767

Merged
merged 8 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion asset/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ func CompressedPubKeyEncoder(w io.Writer, val any, buf *[8]byte) error {
return tlv.NewTypeForEncodingErr(val, "*btcec.PublicKey")
}

func CompressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
func CompressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte,
l uint64) error {

if typ, ok := val.(**btcec.PublicKey); ok {
var keyBytes [btcec.PubKeyBytesLenCompressed]byte
err := tlv.DBytes33(r, &keyBytes, buf, btcec.PubKeyBytesLenCompressed)
if err != nil {
return err
}

var key *btcec.PublicKey
// Handle empty key, which is not on the curve.
if keyBytes == [btcec.PubKeyBytesLenCompressed]byte{} {
Expand All @@ -160,6 +163,7 @@ func CompressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error
*typ = key
return nil
}

return tlv.NewTypeForDecodingErr(
val, "*btcec.PublicKey", l, btcec.PubKeyBytesLenCompressed,
)
Expand Down
59 changes: 59 additions & 0 deletions chain_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/taproot-assets/rfq"
"github.com/lightninglabs/taproot-assets/tapgarden"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
Expand Down Expand Up @@ -203,3 +204,61 @@ func (l *LndRpcChainBridge) EstimateFee(ctx context.Context,
// A compile time assertion to ensure LndRpcChainBridge meets the
// tapgarden.ChainBridge interface.
var _ tapgarden.ChainBridge = (*LndRpcChainBridge)(nil)

// LndMsgTransportClient is an LND RPC message transport client.
type LndMsgTransportClient struct {
lnd *lndclient.LndServices
}

// NewLndMsgTransportClient creates a new message transport RPC client for a
// given LND service.
func NewLndMsgTransportClient(
lnd *lndclient.LndServices) *LndMsgTransportClient {

return &LndMsgTransportClient{
lnd: lnd,
}
}

// SubscribeCustomMessages creates a subscription to custom messages received
// from our peers.
func (l *LndMsgTransportClient) SubscribeCustomMessages(
ctx context.Context) (<-chan lndclient.CustomMessage,
<-chan error, error) {

return l.lnd.Client.SubscribeCustomMessages(ctx)
}

// SendCustomMessage sends a custom message to a peer.
func (l *LndMsgTransportClient) SendCustomMessage(ctx context.Context,
msg lndclient.CustomMessage) error {

return l.lnd.Client.SendCustomMessage(ctx, msg)
}

// Ensure LndMsgTransportClient implements the rfq.PeerMessenger interface.
var _ rfq.PeerMessenger = (*LndMsgTransportClient)(nil)

// LndRouterClient is an LND router RPC client.
type LndRouterClient struct {
lnd *lndclient.LndServices
}

// NewLndRouterClient creates a new LND router client for a given LND service.
func NewLndRouterClient(lnd *lndclient.LndServices) *LndRouterClient {
return &LndRouterClient{
lnd: lnd,
}
}

// InterceptHtlcs intercepts all incoming HTLCs and calls the given handler
// function with the HTLC details. The handler function can then decide whether
// to accept or reject the HTLC.
func (l *LndRouterClient) InterceptHtlcs(
ffranr marked this conversation as resolved.
Show resolved Hide resolved
ctx context.Context, handler lndclient.HtlcInterceptHandler) error {

return l.lnd.Router.InterceptHtlcs(ctx, handler)
}

// Ensure LndRouterClient implements the rfq.HtlcInterceptor interface.
var _ rfq.HtlcInterceptor = (*LndRouterClient)(nil)
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/lightninglabs/taproot-assets/address"
"github.com/lightninglabs/taproot-assets/monitoring"
"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightninglabs/taproot-assets/rfq"
"github.com/lightninglabs/taproot-assets/tapdb"
"github.com/lightninglabs/taproot-assets/tapfreighter"
"github.com/lightninglabs/taproot-assets/tapgarden"
Expand Down Expand Up @@ -122,6 +123,8 @@ type Config struct {

UniverseFederation *universe.FederationEnvoy

RfqManager *rfq.Manager

UniverseStats universe.Telemetry

// UniversePublicAccess is flag which, If true, and the Universe server
Expand Down
2 changes: 2 additions & 0 deletions itest/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
)

Expand All @@ -12,5 +13,6 @@ type TapdClient interface {
taprpc.TaprootAssetsClient
unirpc.UniverseClient
mintrpc.MintClient
rfqrpc.RfqClient
assetwalletrpc.AssetWalletClient
}
4 changes: 4 additions & 0 deletions itest/loadtest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
"github.com/lightninglabs/taproot-assets/taprpc/tapdevrpc"
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/lightningnetwork/lnd/macaroons"
Expand All @@ -38,6 +39,7 @@ type rpcClient struct {
assetwalletrpc.AssetWalletClient
tapdevrpc.TapDevClient
mintrpc.MintClient
rfqrpc.RfqClient
universerpc.UniverseClient
}

Expand Down Expand Up @@ -171,6 +173,7 @@ func getTapClient(t *testing.T, ctx context.Context,
assetWalletClient := assetwalletrpc.NewAssetWalletClient(conn)
devClient := tapdevrpc.NewTapDevClient(conn)
mintMintClient := mintrpc.NewMintClient(conn)
rfqClient := rfqrpc.NewRfqClient(conn)
universeClient := universerpc.NewUniverseClient(conn)

client := &rpcClient{
Expand All @@ -179,6 +182,7 @@ func getTapClient(t *testing.T, ctx context.Context,
AssetWalletClient: assetWalletClient,
TapDevClient: devClient,
MintClient: mintMintClient,
RfqClient: rfqClient,
UniverseClient: universeClient,
}

Expand Down
Loading
Loading