Skip to content

Commit 05bffce

Browse files
committed
staticaddr: remove GetStaticAddress and GetStaticAddressParameters
1 parent 4b48954 commit 05bffce

23 files changed

+443
-458
lines changed

loopd/daemon.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
662662
LndClient: d.lnd.Client,
663663
InvoicesClient: d.lnd.Invoices,
664664
NodePubkey: d.lnd.NodePubkey,
665-
AddressManager: staticAddressManager,
666665
DepositManager: depositManager,
667666
Store: staticAddressLoopInStore,
668667
WalletKit: d.lnd.WalletKit,

loopd/swapclient_server.go

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -921,24 +921,13 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
921921
"deposits: %w", err)
922922
}
923923

924-
// TODO(hieblmi): add params to deposit for multi-address
925-
// support.
926-
params, err := s.staticAddressManager.GetStaticAddressParameters(
927-
ctx,
928-
)
929-
if err != nil {
930-
return nil, fmt.Errorf("unable to retrieve static "+
931-
"address parameters: %w", err)
932-
}
933-
934924
info, err := s.lnd.Client.GetInfo(ctx)
935925
if err != nil {
936926
return nil, fmt.Errorf("unable to get lnd info: %w",
937927
err)
938928
}
939929
selectedDeposits, err := loopin.SelectDeposits(
940-
selectedAmount, deposits, params.Expiry,
941-
info.BlockHeight,
930+
selectedAmount, deposits, info.BlockHeight,
942931
)
943932
if err != nil {
944933
return nil, fmt.Errorf("unable to select deposits: %w",
@@ -1780,6 +1769,11 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
17801769
return nil, err
17811770
}
17821771

1772+
lndInfo, err := s.lnd.Client.GetInfo(ctx)
1773+
if err != nil {
1774+
return nil, err
1775+
}
1776+
17831777
// Deposits filtered by state or outpoints.
17841778
var filteredDeposits []*looprpc.Deposit
17851779
if len(outpoints) > 0 {
@@ -1791,7 +1785,7 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
17911785
}
17921786
return false
17931787
}
1794-
filteredDeposits = filter(allDeposits, network, f)
1788+
filteredDeposits = filter(allDeposits, network, lndInfo, f)
17951789

17961790
if len(outpoints) != len(filteredDeposits) {
17971791
return nil, fmt.Errorf("not all outpoints found in " +
@@ -1807,24 +1801,7 @@ func (s *swapClientServer) ListStaticAddressDeposits(ctx context.Context,
18071801

18081802
return d.IsInState(toServerState(req.StateFilter))
18091803
}
1810-
filteredDeposits = filter(allDeposits, network, f)
1811-
}
1812-
1813-
// Calculate the blocks until expiry for each deposit.
1814-
lndInfo, err := s.lnd.Client.GetInfo(ctx)
1815-
if err != nil {
1816-
return nil, err
1817-
}
1818-
1819-
bestBlockHeight := int64(lndInfo.BlockHeight)
1820-
params, err := s.staticAddressManager.GetStaticAddressParameters(ctx)
1821-
if err != nil {
1822-
return nil, err
1823-
}
1824-
for i := 0; i < len(filteredDeposits); i++ {
1825-
filteredDeposits[i].BlocksUntilExpiry =
1826-
filteredDeposits[i].ConfirmationHeight +
1827-
int64(params.Expiry) - bestBlockHeight
1804+
filteredDeposits = filter(allDeposits, network, lndInfo, f)
18281805
}
18291806

18301807
return &looprpc.ListStaticAddressDepositsResponse{
@@ -1911,13 +1888,6 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
19111888
return nil, err
19121889
}
19131890

1914-
addrParams, err := s.staticAddressManager.GetStaticAddressParameters(
1915-
ctx,
1916-
)
1917-
if err != nil {
1918-
return nil, err
1919-
}
1920-
19211891
// Fetch all deposits at once and index them by swap hash for a quick
19221892
// lookup.
19231893
allDeposits, err := s.depositManager.GetAllDeposits(ctx)
@@ -1956,7 +1926,7 @@ func (s *swapClientServer) ListStaticAddressSwaps(ctx context.Context,
19561926
for _, d := range ds {
19571927
state := toClientDepositState(d.GetState())
19581928
blocksUntilExpiry := d.ConfirmationHeight +
1959-
int64(addrParams.Expiry) -
1929+
int64(d.AddressParams.Expiry) -
19601930
int64(lndInfo.BlockHeight)
19611931

19621932
pd := &looprpc.Deposit{
@@ -2098,7 +2068,7 @@ func (s *swapClientServer) GetStaticAddressSummary(ctx context.Context,
20982068
}
20992069
}
21002070

2101-
deprecatedParams, err := s.staticAddressManager.GetStaticAddressParameters(ctx)
2071+
deprecatedParams, err := s.staticAddressManager.GetLegacyParameters(ctx)
21022072
if err != nil {
21032073
return nil, err
21042074
}
@@ -2196,7 +2166,7 @@ func (s *swapClientServer) StaticAddressLoopIn(ctx context.Context,
21962166
type filterFunc func(deposits *deposit.Deposit) bool
21972167

21982168
func filter(deposits []*deposit.Deposit, network *chaincfg.Params,
2199-
f filterFunc) []*looprpc.Deposit {
2169+
lndInfo *lndclient.Info, f filterFunc) []*looprpc.Deposit {
22002170

22012171
var clientDeposits []*looprpc.Deposit
22022172
for _, d := range deposits {
@@ -2222,6 +2192,9 @@ func filter(deposits []*deposit.Deposit, network *chaincfg.Params,
22222192
ConfirmationHeight: d.ConfirmationHeight,
22232193
SwapHash: swapHash,
22242194
StaticAddress: staticAddr,
2195+
BlocksUntilExpiry: d.ConfirmationHeight +
2196+
int64(d.AddressParams.Expiry) -
2197+
int64(lndInfo.BlockHeight),
22252198
}
22262199

22272200
clientDeposits = append(clientDeposits, deposit)

loopd/swapclient_server_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,12 @@ func (s *mockAddressStore) GetAllStaticAddresses(_ context.Context) (
957957
return s.params, nil
958958
}
959959

960+
func (s *mockAddressStore) GetLegacyParameters(_ context.Context) (
961+
*address.Parameters, error) {
962+
963+
return s.params[0], nil
964+
}
965+
960966
// mockDepositStore implements deposit.Store minimally for DepositsForOutpoints.
961967
type mockDepositStore struct {
962968
byOutpoint map[string]*deposit.Deposit

loopdb/sqlc/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loopdb/sqlc/queries/static_addresses.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ INSERT INTO static_addresses (
2424
$6,
2525
$7,
2626
$8
27-
);
27+
);
28+
29+
-- name: GetLegacyAddress :one
30+
SELECT * FROM static_addresses
31+
ORDER BY id ASC
32+
LIMIT 1;
33+

loopdb/sqlc/static_addresses.sql.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staticaddr/address/interface.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ type Store interface {
2525
GetStaticAddressID(ctx context.Context, pkScript []byte) (int32, error)
2626

2727
// GetAllStaticAddresses retrieves all static addresses from the store.
28-
GetAllStaticAddresses(ctx context.Context) ([]*Parameters,
29-
error)
28+
GetAllStaticAddresses(ctx context.Context) ([]*Parameters, error)
29+
30+
// GetLegacyParameters retrieves the parameters of the legacy static
31+
// address.
32+
GetLegacyParameters(ctx context.Context) (*Parameters, error)
3033
}
3134

3235
// Parameters hold all the necessary information for the 2-of-2 multisig

staticaddr/address/manager.go

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package address
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"sync/atomic"
87

98
"github.com/btcsuite/btcd/btcec/v2"
@@ -348,20 +347,17 @@ func (m *Manager) ListUnspentRaw(ctx context.Context, minConfs,
348347
return resultList, nil
349348
}
350349

351-
// GetStaticAddressParameters returns the parameters of the static address.
352-
func (m *Manager) GetStaticAddressParameters(ctx context.Context) (*Parameters,
350+
// GetLegacyParameters returns the first address parameters that were created
351+
// under this L402.
352+
func (m *Manager) GetLegacyParameters(ctx context.Context) (*Parameters,
353353
error) {
354354

355-
params, err := m.cfg.Store.GetAllStaticAddresses(ctx)
355+
params, err := m.cfg.Store.GetLegacyParameters(ctx)
356356
if err != nil {
357357
return nil, err
358358
}
359359

360-
if len(params) == 0 {
361-
return nil, fmt.Errorf("no static address parameters found")
362-
}
363-
364-
return params[0], nil
360+
return params, nil
365361
}
366362

367363
func (m *Manager) GetParameters(pkScript []byte) *Parameters {
@@ -374,25 +370,11 @@ func (m *Manager) GetStaticAddressID(ctx context.Context,
374370
return m.cfg.Store.GetStaticAddressID(ctx, pkScript)
375371
}
376372

377-
// GetStaticAddress returns a taproot address for the given client and server
378-
// public keys and expiry.
379-
func (m *Manager) GetStaticAddress(ctx context.Context) (*script.StaticAddress,
380-
error) {
381-
382-
params, err := m.GetStaticAddressParameters(ctx)
383-
if err != nil {
384-
return nil, err
385-
}
386-
387-
address, err := script.NewStaticAddress(
388-
input.MuSig2Version100RC2, int64(params.Expiry),
389-
params.ClientPubkey, params.ServerPubkey,
390-
)
391-
if err != nil {
392-
return nil, err
393-
}
394-
395-
return address, nil
373+
// IsOurPkScript returns true if the given pkScript is one of our active
374+
// static addresses.
375+
func (m *Manager) IsOurPkScript(pkScript []byte) bool {
376+
_, ok := m.activeStaticAddresses[string(pkScript)]
377+
return ok
396378
}
397379

398380
// ListUnspent returns a list of utxos at the static address.

staticaddr/address/sql_store.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ func (s *SqlStore) GetAllStaticAddresses(ctx context.Context) ([]*Parameters,
7474
return result, nil
7575
}
7676

77+
// GetLegacyParameters returns all address known to the server.
78+
func (s *SqlStore) GetLegacyParameters(ctx context.Context) (*Parameters,
79+
error) {
80+
81+
legacyAddress, err := s.baseDB.Queries.GetLegacyAddress(ctx)
82+
if err != nil {
83+
return nil, err
84+
}
85+
86+
res, err := s.toAddressParameters(legacyAddress)
87+
if err != nil {
88+
return nil, err
89+
}
90+
return res, nil
91+
}
92+
7793
// Close closes the database connection.
7894
func (s *SqlStore) Close() {
7995
s.baseDB.DB.Close()

staticaddr/deposit/actions.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,25 @@ func (f *FSM) PublishDepositExpirySweepAction(ctx context.Context,
6565

6666
prevOut := []*wire.TxOut{txOut}
6767

68-
signDesc, err := f.SignDescriptor(ctx)
68+
addressScript, err := f.deposit.GetStaticAddressScript()
6969
if err != nil {
7070
return f.HandleError(err)
7171
}
7272

73-
rawSigs, err := f.cfg.Signer.SignOutputRaw(
74-
ctx, msgTx, []*lndclient.SignDescriptor{signDesc}, prevOut,
75-
)
73+
signDesc, err := f.SignDescriptor(addressScript)
7674
if err != nil {
7775
return f.HandleError(err)
7876
}
7977

80-
address, err := f.cfg.AddressManager.GetStaticAddress(ctx)
78+
rawSigs, err := f.cfg.Signer.SignOutputRaw(
79+
ctx, msgTx, []*lndclient.SignDescriptor{signDesc}, prevOut,
80+
)
8181
if err != nil {
8282
return f.HandleError(err)
8383
}
8484

8585
sig := rawSigs[0]
86-
msgTx.TxIn[0].Witness, err = address.GenTimeoutWitness(sig)
86+
msgTx.TxIn[0].Witness, err = addressScript.GenTimeoutWitness(sig)
8787
if err != nil {
8888
return f.HandleError(err)
8989
}

0 commit comments

Comments
 (0)