From 429b28b110fb3286dfc7803b0ba5458ee1379543 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 21 Sep 2021 13:23:30 +0200 Subject: [PATCH] multi: prepare for upcoming lnd v0.14.0-beta release --- auctioneer/client.go | 2 +- clientdb/account.go | 2 +- clientdb/batch_snapshot.go | 8 ++++---- clientdb/codec.go | 4 ++-- clientdb/order.go | 2 +- clientdb/order_event.go | 7 ++++--- cmd/pool/main.go | 6 +++++- event/event.go | 2 +- funding/manager.go | 2 +- internal/test/lightning_mock.go | 4 ++-- macaroons.go | 25 ++++++++++++++++--------- server.go | 4 ++-- 12 files changed, 40 insertions(+), 28 deletions(-) diff --git a/auctioneer/client.go b/auctioneer/client.go index b7d39e1..d4091c9 100644 --- a/auctioneer/client.go +++ b/auctioneer/client.go @@ -220,7 +220,7 @@ func getAuctionServerDialOpts(insecure bool, proxyAddress, tlsPath string, proxyAddress) torDialer := func(_ context.Context, addr string) (net.Conn, error) { return tor.Dial( - addr, proxyAddress, false, + addr, proxyAddress, false, false, tor.DefaultConnTimeout, ) } diff --git a/clientdb/account.go b/clientdb/account.go index 105691c..4565c5a 100644 --- a/clientdb/account.go +++ b/clientdb/account.go @@ -155,7 +155,7 @@ func readAccount(sourceBucket *bbolt.Bucket, return deserializeAccount(bytes.NewReader(accountBytes)) } -func serializeAccount(w io.Writer, a *account.Account) error { +func serializeAccount(w *bytes.Buffer, a *account.Account) error { err := WriteElements( w, a.Value, a.Expiry, a.TraderKey, a.AuctioneerKey, a.BatchKey, a.Secret, a.State, a.HeightHint, a.OutPoint, diff --git a/clientdb/batch_snapshot.go b/clientdb/batch_snapshot.go index 57f1317..a9591a9 100644 --- a/clientdb/batch_snapshot.go +++ b/clientdb/batch_snapshot.go @@ -406,7 +406,7 @@ func getSnapshotBuckets(tx *bbolt.Tx) (*bbolt.Bucket, *bbolt.Bucket, return topBucket, seqBucket, indexBucket, nil } -func serializeLocalBatchSnapshot(w io.Writer, b *LocalBatchSnapshot) error { +func serializeLocalBatchSnapshot(w *bytes.Buffer, b *LocalBatchSnapshot) error { // The previous batch versions had a single clearing price but because // we now always store the price map afterwards, we signal a new batch // by storing an explicit zero price. @@ -543,7 +543,7 @@ func deserializeLocalBatchSnapshot(r io.Reader) (*LocalBatchSnapshot, error) { return b, nil } -func serializeAccounts(w io.Writer, +func serializeAccounts(w *bytes.Buffer, accounts map[[33]byte]*account.Account) error { err := WriteElements(w, uint32(len(accounts))) @@ -594,7 +594,7 @@ func deserializeAccounts(r io.Reader) (map[[33]byte]*account.Account, error) { return accs, nil } -func serializeOrders(w io.Writer, orders map[order.Nonce]order.Order) error { +func serializeOrders(w *bytes.Buffer, orders map[order.Nonce]order.Order) error { err := WriteElements(w, uint32(len(orders))) if err != nil { return err @@ -641,7 +641,7 @@ func deserializeOrders(r io.Reader) (map[order.Nonce]order.Order, error) { return orders, nil } -func serializeMatchedOrder(w io.Writer, ourNonce order.Nonce, +func serializeMatchedOrder(w *bytes.Buffer, ourNonce order.Nonce, m *order.MatchedOrder) error { err := WriteElements(w, ourNonce, m.Order.Nonce()) diff --git a/clientdb/codec.go b/clientdb/codec.go index 1cc6829..64c6dca 100644 --- a/clientdb/codec.go +++ b/clientdb/codec.go @@ -34,7 +34,7 @@ var ( // WriteElements is writes each element in the elements slice to the passed // io.Writer using WriteElement. -func WriteElements(w io.Writer, elements ...interface{}) error { +func WriteElements(w *bytes.Buffer, elements ...interface{}) error { for _, element := range elements { err := WriteElement(w, element) if err != nil { @@ -48,7 +48,7 @@ func WriteElements(w io.Writer, elements ...interface{}) error { // any element which is to be serialized. The passed io.Writer should be backed // by an appropriately sized byte slice, or be able to dynamically expand to // accommodate additional data. -func WriteElement(w io.Writer, element interface{}) error { +func WriteElement(w *bytes.Buffer, element interface{}) error { switch e := element.(type) { case order.NodeTier: return lnwire.WriteElement(w, uint32(e)) diff --git a/clientdb/order.go b/clientdb/order.go index 115b503..e675c74 100644 --- a/clientdb/order.go +++ b/clientdb/order.go @@ -582,7 +582,7 @@ func copyOrder(src, dst *bbolt.Bucket, nonce order.Nonce) error { // SerializeOrder binary serializes an order to a writer using the common LN // wire format. -func SerializeOrder(o order.Order, w io.Writer) error { +func SerializeOrder(o order.Order, w *bytes.Buffer) error { kit := o.Details() // We don't have to deserialize the nonce as it's the sub bucket name. diff --git a/clientdb/order_event.go b/clientdb/order_event.go index 7645506..c8af92c 100644 --- a/clientdb/order_event.go +++ b/clientdb/order_event.go @@ -1,6 +1,7 @@ package clientdb import ( + "bytes" "fmt" "io" "time" @@ -77,7 +78,7 @@ func (e *CreatedEvent) String() string { // filtering. // // NOTE: This is part of the event.Event interface. -func (e *CreatedEvent) Serialize(w io.Writer) error { +func (e *CreatedEvent) Serialize(w *bytes.Buffer) error { return WriteElements(w, e.nonce) } @@ -175,7 +176,7 @@ func (e *UpdatedEvent) String() string { // filtering. // // NOTE: This is part of the event.Event interface. -func (e *UpdatedEvent) Serialize(w io.Writer) error { +func (e *UpdatedEvent) Serialize(w *bytes.Buffer) error { return WriteElements(w, e.nonce, e.PrevState, e.NewState, e.UnitsFilled) } @@ -282,7 +283,7 @@ func (e *MatchEvent) String() string { // filtering. // // NOTE: This is part of the event.Event interface. -func (e *MatchEvent) Serialize(w io.Writer) error { +func (e *MatchEvent) Serialize(w *bytes.Buffer) error { return WriteElements( w, e.nonce, e.MatchState, e.UnitsFilled, e.MatchedOrder, e.RejectReason, diff --git a/cmd/pool/main.go b/cmd/pool/main.go index 902fbec..a3cb62c 100644 --- a/cmd/pool/main.go +++ b/cmd/pool/main.go @@ -328,6 +328,10 @@ func readMacaroon(macPath string) (grpc.DialOption, error) { } // Now we append the macaroon credentials to the dial options. - cred := macaroons.NewMacaroonCredential(constrainedMac) + cred, err := macaroons.NewMacaroonCredential(constrainedMac) + if err != nil { + return nil, fmt.Errorf("error creating macaroon credential: %v", + err) + } return grpc.WithPerRPCCredentials(cred), nil } diff --git a/event/event.go b/event/event.go index 1eead45..7b23c5b 100644 --- a/event/event.go +++ b/event/event.go @@ -71,7 +71,7 @@ type Event interface { // Serialize writes the event data to a binary storage format. This does // not serialize the event type as that's handled generically to allow // for easy filtering. - Serialize(io.Writer) error + Serialize(*bytes.Buffer) error // Deserialize reads the event data from a binary storage format. This // does not deserialize the event type as that's handled generically to diff --git a/funding/manager.go b/funding/manager.go index bc36519..bbd556a 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -1188,7 +1188,7 @@ func (m *Manager) rejectDuplicateChannels( // We gather all peers from the open and pending channels. ctxb := context.Background() peers := make(map[route.Vertex]struct{}) - openChans, err := m.cfg.LightningClient.ListChannels(ctxb) + openChans, err := m.cfg.LightningClient.ListChannels(ctxb, false, false) if err != nil { return nil, fmt.Errorf("error listing open channels: %v", err) } diff --git a/internal/test/lightning_mock.go b/internal/test/lightning_mock.go index c0d465a..09fbf72 100644 --- a/internal/test/lightning_mock.go +++ b/internal/test/lightning_mock.go @@ -233,8 +233,8 @@ func (m *MockLightning) ListTransactions(context.Context, int32, } // ListChannels retrieves all channels of the backing lnd node. -func (m *MockLightning) ListChannels(context.Context) ([]lndclient.ChannelInfo, - error) { +func (m *MockLightning) ListChannels(context.Context, bool, + bool) ([]lndclient.ChannelInfo, error) { return m.Channels, nil } diff --git a/macaroons.go b/macaroons.go index e511013..9058750 100644 --- a/macaroons.go +++ b/macaroons.go @@ -7,6 +7,7 @@ import ( "os" "github.com/lightninglabs/pool/clientdb" + "github.com/lightningnetwork/lnd/kvdb" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/macaroons" "github.com/lightningnetwork/lnd/rpcperms" @@ -193,12 +194,11 @@ var ( // exist yet. If macaroons are disabled in general in the configuration, none of // these actions are taken. func (s *Server) startMacaroonService() error { - // Create the macaroon authentication/authorization service. - var err error - s.macaroonService, err = macaroons.NewService( - s.cfg.BaseDir, poolMacaroonLocation, false, - clientdb.DefaultPoolDBTimeout, macaroons.IPLockChecker, - ) + backend, err := kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{ + DBPath: s.cfg.BaseDir, + DBFileName: "macaroons.db", + DBTimeout: clientdb.DefaultPoolDBTimeout, + }) if err == bbolt.ErrTimeout { return fmt.Errorf("error while trying to open %s/%s: "+ "timed out after %v when trying to obtain exclusive "+ @@ -208,8 +208,15 @@ func (s *Server) startMacaroonService() error { clientdb.DefaultPoolDBTimeout) } if err != nil { - return fmt.Errorf("unable to set up macaroon authentication: "+ - "%v", err) + return fmt.Errorf("unable to load macaroon db: %v", err) + } + + // Create the macaroon authentication/authorization service. + s.macaroonService, err = macaroons.NewService( + backend, poolMacaroonLocation, false, macaroons.IPLockChecker, + ) + if err != nil { + return fmt.Errorf("unable to set up macaroon service: %v", err) } // Try to unlock the macaroon store with the private password. @@ -264,7 +271,7 @@ func (s *Server) stopMacaroonService() error { func (s *Server) macaroonInterceptor() (grpc.UnaryServerInterceptor, grpc.StreamServerInterceptor, error) { - interceptor := rpcperms.NewInterceptorChain(log, false) + interceptor := rpcperms.NewInterceptorChain(log, false, nil) err := interceptor.Start() if err != nil { return nil, nil, err diff --git a/server.go b/server.go index 8287584..5feea74 100644 --- a/server.go +++ b/server.go @@ -133,8 +133,8 @@ func (s *Server) Start() error { // what we need s.lndClient, err = lndclient.NewBasicClient( s.cfg.Lnd.Host, s.cfg.Lnd.TLSPath, - path.Dir(s.cfg.Lnd.MacaroonPath), s.cfg.Network, - lndclient.MacFilename(path.Base(s.cfg.Lnd.MacaroonPath)), + path.Dir(s.cfg.Lnd.MacaroonPath), "", "", s.cfg.Network, false, + false, lndclient.MacFilename(path.Base(s.cfg.Lnd.MacaroonPath)), ) if err != nil { return err