mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
multi: update linter, fix issues
This commit is contained in:
parent
bac1416636
commit
08026dab93
25 changed files with 525 additions and 346 deletions
|
|
@ -76,6 +76,9 @@ linters:
|
|||
- golint
|
||||
- maligned
|
||||
- scopelint
|
||||
- varcheck
|
||||
- structcheck
|
||||
- deadcode
|
||||
|
||||
# New linters that need a code adjustment first.
|
||||
- wrapcheck
|
||||
|
|
@ -107,6 +110,10 @@ linters:
|
|||
- stylecheck
|
||||
- thelper
|
||||
- revive
|
||||
- tagalign
|
||||
- depguard
|
||||
- nosnakecase
|
||||
- interfacebloat
|
||||
|
||||
# Additions compared to LND
|
||||
- exhaustruct
|
||||
|
|
@ -122,6 +129,10 @@ issues:
|
|||
linters:
|
||||
- forbidigo
|
||||
- unparam
|
||||
- gosec
|
||||
- path: _mock\.go
|
||||
linters:
|
||||
- gosec
|
||||
|
||||
# Allow fmt.Printf() in loopd
|
||||
- path: cmd/loopd/*
|
||||
|
|
|
|||
|
|
@ -204,6 +204,8 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
|
|||
swaps := make([]*SwapInfo, 0, len(loopInSwaps)+len(loopOutSwaps))
|
||||
|
||||
for _, swp := range loopOutSwaps {
|
||||
swp := swp
|
||||
|
||||
swapInfo := &SwapInfo{
|
||||
SwapType: swap.TypeOut,
|
||||
SwapContract: swp.Contract.SwapContract,
|
||||
|
|
@ -235,6 +237,8 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
|
|||
}
|
||||
|
||||
for _, swp := range loopInSwaps {
|
||||
swp := swp
|
||||
|
||||
swapInfo := &SwapInfo{
|
||||
SwapType: swap.TypeIn,
|
||||
SwapContract: swp.Contract.SwapContract,
|
||||
|
|
|
|||
|
|
@ -88,8 +88,9 @@ func TestStateMachine_ActionError(t *testing.T) {
|
|||
|
||||
// Add a Transition to State2 if the Action on Stat2 fails.
|
||||
// The new StateMap looks like this:
|
||||
// State1 -> Event1 -> State2
|
||||
// State2 -> OnError -> ErrorState
|
||||
// State1 -> Event1 -> State2
|
||||
//
|
||||
// State2 -> OnError -> ErrorState
|
||||
states["State2"] = State{
|
||||
Action: ctx.errorAction,
|
||||
Transitions: Transitions{
|
||||
|
|
|
|||
|
|
@ -984,7 +984,7 @@ func TestAutoloopBothTypes(t *testing.T) {
|
|||
Events: []*loopdb.LoopEvent{
|
||||
{
|
||||
SwapStateData: loopdb.SwapStateData{
|
||||
State: loopdb.SwapState(loopdb.StateSuccess),
|
||||
State: loopdb.StateSuccess,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -1168,7 +1168,7 @@ func TestAutoLoopRecurringBudget(t *testing.T) {
|
|||
Events: []*loopdb.LoopEvent{
|
||||
{
|
||||
SwapStateData: loopdb.SwapStateData{
|
||||
State: loopdb.SwapState(loopdb.StateSuccess),
|
||||
State: loopdb.StateSuccess,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ func (f *FeePortion) loopOutLimits(swapAmt btcutil.Amount,
|
|||
// multiplier from the miner fees. We do this because we want to
|
||||
// consider the average case for our budget calculations and not the
|
||||
// severe edge-case miner fees.
|
||||
miner = miner / maxMinerMultiplier
|
||||
miner /= maxMinerMultiplier
|
||||
|
||||
// Calculate the worst case fees that we could pay for this swap,
|
||||
// ensuring that we are within our fee limit even if the swap fails.
|
||||
|
|
|
|||
|
|
@ -536,10 +536,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
|
|||
|
||||
// Get a summary of our existing swaps so that we can check our autoloop
|
||||
// budget.
|
||||
summary, err := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
summary := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
|
||||
|
||||
err = m.checkSummaryBudget(summary)
|
||||
if err != nil {
|
||||
|
|
@ -581,7 +578,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
|
|||
// allowed clamp it to max.
|
||||
amount := localTotal - m.params.EasyAutoloopTarget
|
||||
if amount > restrictions.Maximum {
|
||||
amount = btcutil.Amount(restrictions.Maximum)
|
||||
amount = restrictions.Maximum
|
||||
}
|
||||
|
||||
// If the amount we want to loop out is less than the minimum we can't
|
||||
|
|
@ -601,7 +598,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
|
|||
builder := newLoopOutBuilder(m.cfg)
|
||||
|
||||
channel := m.pickEasyAutoloopChannel(
|
||||
channels, restrictions, loopOut, loopIn, amount,
|
||||
channels, restrictions, loopOut, loopIn,
|
||||
)
|
||||
if channel == nil {
|
||||
return fmt.Errorf("no eligible channel for easy autoloop")
|
||||
|
|
@ -624,12 +621,12 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
|
|||
switch feeLimit := easyParams.FeeLimit.(type) {
|
||||
case *FeePortion:
|
||||
if feeLimit.PartsPerMillion == 0 {
|
||||
feeLimit = &FeePortion{
|
||||
easyParams.FeeLimit = &FeePortion{
|
||||
PartsPerMillion: defaultFeePPM,
|
||||
}
|
||||
}
|
||||
default:
|
||||
feeLimit = &FeePortion{
|
||||
easyParams.FeeLimit = &FeePortion{
|
||||
PartsPerMillion: defaultFeePPM,
|
||||
}
|
||||
}
|
||||
|
|
@ -646,16 +643,16 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
swap := loop.OutRequest{}
|
||||
var swp loop.OutRequest
|
||||
if t, ok := suggestion.(*loopOutSwapSuggestion); ok {
|
||||
swap = t.OutRequest
|
||||
swp = t.OutRequest
|
||||
} else {
|
||||
return fmt.Errorf("unexpected swap suggestion type: %T", t)
|
||||
}
|
||||
|
||||
// Dispatch a sticky loop out.
|
||||
go m.dispatchStickyLoopOut(
|
||||
ctx, swap, defaultAmountBackoffRetry, defaultAmountBackoff,
|
||||
ctx, swp, defaultAmountBackoffRetry, defaultAmountBackoff,
|
||||
)
|
||||
|
||||
return nil
|
||||
|
|
@ -762,10 +759,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
|
|||
|
||||
// Get a summary of our existing swaps so that we can check our autoloop
|
||||
// budget.
|
||||
summary, err := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
summary := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
|
||||
|
||||
err = m.checkSummaryBudget(summary)
|
||||
if err != nil {
|
||||
|
|
@ -1074,9 +1068,9 @@ func (e *existingAutoLoopSummary) totalFees() btcutil.Amount {
|
|||
// automatically dispatched swaps that have completed, and the worst-case fee
|
||||
// total for our set of ongoing, automatically dispatched swaps as well as a
|
||||
// current in-flight count.
|
||||
func (m *Manager) checkExistingAutoLoops(ctx context.Context,
|
||||
loopOuts []*loopdb.LoopOut, loopIns []*loopdb.LoopIn) (
|
||||
*existingAutoLoopSummary, error) {
|
||||
func (m *Manager) checkExistingAutoLoops(_ context.Context,
|
||||
loopOuts []*loopdb.LoopOut,
|
||||
loopIns []*loopdb.LoopIn) *existingAutoLoopSummary {
|
||||
|
||||
var summary existingAutoLoopSummary
|
||||
|
||||
|
|
@ -1133,7 +1127,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
|
|||
}
|
||||
}
|
||||
|
||||
return &summary, nil
|
||||
return &summary
|
||||
}
|
||||
|
||||
// currentSwapTraffic examines our existing swaps and returns a summary of the
|
||||
|
|
@ -1416,7 +1410,7 @@ func (m *Manager) waitForSwapPayment(ctx context.Context, swapHash lntypes.Hash,
|
|||
// swap conflicts.
|
||||
func (m *Manager) pickEasyAutoloopChannel(channels []lndclient.ChannelInfo,
|
||||
restrictions *Restrictions, loopOut []*loopdb.LoopOut,
|
||||
loopIn []*loopdb.LoopIn, amount btcutil.Amount) *lndclient.ChannelInfo {
|
||||
loopIn []*loopdb.LoopIn) *lndclient.ChannelInfo {
|
||||
|
||||
traffic := m.currentSwapTraffic(loopOut, loopIn)
|
||||
|
||||
|
|
@ -1472,7 +1466,6 @@ func (m *Manager) numActiveStickyLoops() int {
|
|||
defer m.activeStickyLock.Unlock()
|
||||
|
||||
return m.activeStickyLoops
|
||||
|
||||
}
|
||||
|
||||
func (m *Manager) checkSummaryBudget(summary *existingAutoLoopSummary) error {
|
||||
|
|
@ -1482,7 +1475,6 @@ func (m *Manager) checkSummaryBudget(summary *existingAutoLoopSummary) error {
|
|||
"(upper limit)",
|
||||
m.params.AutoFeeBudget, summary.spentFees,
|
||||
summary.pendingFees)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -1556,7 +1548,3 @@ func satPerKwToSatPerVByte(satPerKw chainfee.SatPerKWeight) int64 {
|
|||
func ppmToSat(amount btcutil.Amount, ppm uint64) btcutil.Amount {
|
||||
return btcutil.Amount(uint64(amount) * ppm / FeeBase)
|
||||
}
|
||||
|
||||
func mSatToSatoshis(amount lnwire.MilliSatoshi) btcutil.Amount {
|
||||
return btcutil.Amount(amount / 1000)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ package liquidity
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightninglabs/lndclient"
|
||||
"github.com/lightninglabs/loop/swap"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
|
|
@ -527,7 +527,6 @@ func ParametersToRpc(cfg Parameters) (*clientrpc.LiquidityParameters,
|
|||
|
||||
default:
|
||||
addrType = clientrpc.AddressType_ADDRESS_TYPE_UNKNOWN
|
||||
|
||||
}
|
||||
|
||||
rpcCfg := &clientrpc.LiquidityParameters{
|
||||
|
|
|
|||
|
|
@ -127,10 +127,10 @@ func (r *ThresholdRule) swapAmount(channel *balances,
|
|||
// This function can be used for loop out or loop in, but the concept is the
|
||||
// same - we want liquidity in one (target) direction, while preserving some
|
||||
// minimum in the other (reserve) direction.
|
||||
// * target: this is the side of the channel(s) where we want to acquire some
|
||||
// liquidity. We aim for this liquidity to reach the threshold amount set.
|
||||
// * reserve: this is the side of the channel(s) that we will move liquidity
|
||||
// away from. This may not drop below a certain reserve threshold.
|
||||
// - target: this is the side of the channel(s) where we want to acquire some
|
||||
// liquidity. We aim for this liquidity to reach the threshold amount set.
|
||||
// - reserve: this is the side of the channel(s) that we will move liquidity
|
||||
// away from. This may not drop below a certain reserve threshold.
|
||||
func calculateSwapAmount(targetAmount, reserveAmount,
|
||||
capacity btcutil.Amount, targetThresholdPercentage,
|
||||
reserveThresholdPercentage uint64) btcutil.Amount {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
|
|
@ -302,7 +303,10 @@ func (d *Daemon) startWebServers() error {
|
|||
if d.restListener != nil {
|
||||
log.Infof("Starting REST proxy listener")
|
||||
|
||||
d.restServer = &http.Server{Handler: restHandler}
|
||||
d.restServer = &http.Server{
|
||||
Handler: restHandler,
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
d.wg.Add(1)
|
||||
go func() {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func migrateBoltdb(ctx context.Context, cfg *Config) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// If the migration was successfull we'll rename the bolt db to
|
||||
// If the migration was successful we'll rename the bolt db to
|
||||
// loop.db.bk.
|
||||
err = os.Rename(
|
||||
filepath.Join(cfg.DataDir, "loop.db"),
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
|
|||
}
|
||||
|
||||
for _, s := range swaps {
|
||||
s := s
|
||||
|
||||
htlc, err := loop.GetHtlc(
|
||||
s.Hash, &s.Contract.SwapContract, chainParams,
|
||||
)
|
||||
|
|
@ -98,6 +100,8 @@ func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {
|
|||
}
|
||||
|
||||
for _, s := range swaps {
|
||||
s := s
|
||||
|
||||
htlc, err := loop.GetHtlc(
|
||||
s.Hash, &s.Contract.SwapContract, chainParams,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ func (m *MigratorManager) migrateLoopIns(ctx context.Context) error {
|
|||
swapMap := make(map[lntypes.Hash]*LoopInContract)
|
||||
updateMap := make(map[lntypes.Hash][]BatchInsertUpdateData)
|
||||
|
||||
// For each loop in, create a new loop in in the toStore.
|
||||
// For each loop in, create a new loop in the toStore.
|
||||
for _, loopIn := range loopIns {
|
||||
swapMap[loopIn.Hash] = loopIn.Contract
|
||||
|
||||
|
|
@ -311,6 +311,7 @@ func (m *MigratorManager) checkLiquidityParams(ctx context.Context) error {
|
|||
func equalizeLoopOut(fromLoopOut, toLoopOut *LoopOut) error {
|
||||
if fromLoopOut.Contract.InitiationTime.Unix() !=
|
||||
toLoopOut.Contract.InitiationTime.Unix() {
|
||||
|
||||
return fmt.Errorf("initiation time mismatch")
|
||||
}
|
||||
|
||||
|
|
@ -318,6 +319,7 @@ func equalizeLoopOut(fromLoopOut, toLoopOut *LoopOut) error {
|
|||
|
||||
if fromLoopOut.Contract.SwapPublicationDeadline.Unix() !=
|
||||
toLoopOut.Contract.SwapPublicationDeadline.Unix() {
|
||||
|
||||
return fmt.Errorf("swap publication deadline mismatch")
|
||||
}
|
||||
|
||||
|
|
@ -337,6 +339,7 @@ func equalizeLoopOut(fromLoopOut, toLoopOut *LoopOut) error {
|
|||
func equalizeLoopIns(fromLoopIn, toLoopIn *LoopIn) error {
|
||||
if fromLoopIn.Contract.InitiationTime.Unix() !=
|
||||
toLoopIn.Contract.InitiationTime.Unix() {
|
||||
|
||||
return fmt.Errorf("initiation time mismatch")
|
||||
}
|
||||
|
||||
|
|
@ -398,17 +401,6 @@ func equalValues(src interface{}, dst interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func elementsMatch(src interface{}, dst interface{}) error {
|
||||
mt := &mockTesting{}
|
||||
|
||||
require.ElementsMatch(mt, src, dst)
|
||||
if mt.fail || mt.failNow {
|
||||
return fmt.Errorf(mt.format, mt.args)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockTesting struct {
|
||||
failNow bool
|
||||
fail bool
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ func newReplacerFile(parent fs.File, replaces map[string]string) (*replacerFile,
|
|||
|
||||
contentStr := string(content)
|
||||
for from, to := range replaces {
|
||||
contentStr = strings.Replace(contentStr, from, to, -1)
|
||||
contentStr = strings.ReplaceAll(contentStr, from, to)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@ import (
|
|||
//
|
||||
// Example output:
|
||||
//
|
||||
// map[string]interface{}{
|
||||
// Hex("1234"): map[string]interface{}{
|
||||
// "human-readable": Hex("102030"),
|
||||
// Hex("1111"): Hex("5783492373"),
|
||||
// },
|
||||
// } .
|
||||
// map[string]interface{}{
|
||||
// Hex("1234"): map[string]interface{}{
|
||||
// "human-readable": Hex("102030"),
|
||||
// Hex("1111"): Hex("5783492373"),
|
||||
// },
|
||||
// } .
|
||||
func DumpDB(tx *bbolt.Tx) error { // nolint: unused
|
||||
return tx.ForEach(func(k []byte, bucket *bbolt.Bucket) error {
|
||||
key := toString(k)
|
||||
|
|
|
|||
|
|
@ -133,6 +133,8 @@ func (s *BaseDB) BatchCreateLoopOut(ctx context.Context,
|
|||
writeOpts := &SqliteTxOptions{}
|
||||
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
|
||||
for swapHash, swap := range swaps {
|
||||
swap := swap
|
||||
|
||||
insertArgs := loopToInsertArgs(
|
||||
swapHash, &swap.SwapContract,
|
||||
)
|
||||
|
|
@ -250,13 +252,15 @@ func (s *BaseDB) CreateLoopIn(ctx context.Context, hash lntypes.Hash,
|
|||
})
|
||||
}
|
||||
|
||||
// BatchCreateLoopOut adds multiple initiated swaps to the store.
|
||||
// BatchCreateLoopIn adds multiple initiated swaps to the store.
|
||||
func (s *BaseDB) BatchCreateLoopIn(ctx context.Context,
|
||||
swaps map[lntypes.Hash]*LoopInContract) error {
|
||||
|
||||
writeOpts := &SqliteTxOptions{}
|
||||
return s.ExecTx(ctx, writeOpts, func(tx *sqlc.Queries) error {
|
||||
for swapHash, swap := range swaps {
|
||||
swap := swap
|
||||
|
||||
insertArgs := loopToInsertArgs(
|
||||
swapHash, &swap.SwapContract,
|
||||
)
|
||||
|
|
@ -422,6 +426,7 @@ func loopToInsertArgs(hash lntypes.Hash,
|
|||
// needed to insert it into the database.
|
||||
func loopOutToInsertArgs(hash lntypes.Hash,
|
||||
loopOut *LoopOutContract) sqlc.InsertLoopOutParams {
|
||||
|
||||
return sqlc.InsertLoopOutParams{
|
||||
SwapHash: hash[:],
|
||||
DestAddress: loopOut.DestAddr.String(),
|
||||
|
|
@ -458,6 +463,7 @@ func loopInToInsertArgs(hash lntypes.Hash,
|
|||
// and converts them to the arguments needed to insert them into the database.
|
||||
func swapToHtlcKeysInsertArgs(hash lntypes.Hash,
|
||||
swap *SwapContract) sqlc.InsertHtlcKeysParams {
|
||||
|
||||
return sqlc.InsertHtlcKeysParams{
|
||||
SwapHash: hash[:],
|
||||
SenderScriptPubkey: swap.HtlcKeys.SenderScriptKey[:],
|
||||
|
|
|
|||
|
|
@ -17,9 +17,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
testTime1 = time.Date(2018, time.January, 9, 14, 54, 32, 3, time.UTC)
|
||||
testTime2 = time.Date(2018, time.January, 9, 15, 02, 03, 5, time.UTC)
|
||||
const (
|
||||
testLabel = "test label"
|
||||
)
|
||||
|
||||
// TestSqliteLoopOutStore tests all the basic functionality of the current
|
||||
|
|
@ -75,7 +74,7 @@ func TestSqliteLoopOutStore(t *testing.T) {
|
|||
})
|
||||
|
||||
labelledSwap := unrestrictedSwap
|
||||
labelledSwap.Label = "test label"
|
||||
labelledSwap.Label = testLabel
|
||||
t.Run("labelled swap", func(t *testing.T) {
|
||||
testSqliteLoopOutStore(t, &labelledSwap)
|
||||
})
|
||||
|
|
@ -206,7 +205,7 @@ func TestSQLliteLoopInStore(t *testing.T) {
|
|||
})
|
||||
|
||||
labelledSwap := pendingSwap
|
||||
labelledSwap.Label = "test label"
|
||||
labelledSwap.Label = testLabel
|
||||
t.Run("loop in with label", func(t *testing.T) {
|
||||
testSqliteLoopInStore(t, labelledSwap)
|
||||
})
|
||||
|
|
@ -310,12 +309,12 @@ func TestSqliteLiquidityParams(t *testing.T) {
|
|||
// convert between the :one and :many types from sqlc.
|
||||
func TestSqliteTypeConversion(t *testing.T) {
|
||||
loopOutSwapRow := sqlc.GetLoopOutSwapRow{}
|
||||
randomStruct(&loopOutSwapRow)
|
||||
err := randomStruct(&loopOutSwapRow)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, loopOutSwapRow.DestAddress)
|
||||
|
||||
loopOutSwapsRow := sqlc.GetLoopOutSwapsRow(loopOutSwapRow)
|
||||
require.EqualValues(t, loopOutSwapRow, loopOutSwapsRow)
|
||||
|
||||
}
|
||||
|
||||
// TestIssue615 tests that on faulty timestamps, the database will be fixed.
|
||||
|
|
|
|||
|
|
@ -211,7 +211,6 @@ func (db *BaseDB) ExecTx(ctx context.Context, txOptions TxOptions,
|
|||
// FixFaultyTimestamps fixes faulty timestamps in the database, caused
|
||||
// by using milliseconds instead of seconds as the publication deadline.
|
||||
func (b *BaseDB) FixFaultyTimestamps(ctx context.Context) error {
|
||||
|
||||
// Manually fetch all the loop out swaps.
|
||||
rows, err := b.DB.QueryContext(
|
||||
ctx, "SELECT swap_hash, publication_deadline FROM loopout_swaps",
|
||||
|
|
@ -219,6 +218,9 @@ func (b *BaseDB) FixFaultyTimestamps(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = rows.Close()
|
||||
}()
|
||||
|
||||
// Parse the rows into a struct. We need to do this manually because
|
||||
// the sqlite driver will fail on faulty timestamps.
|
||||
|
|
@ -241,14 +243,19 @@ func (b *BaseDB) FixFaultyTimestamps(ctx context.Context) error {
|
|||
loopOutSwaps = append(loopOutSwaps, swap)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tx, err := b.BeginTx(ctx, &SqliteTxOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback() //nolint: errcheck
|
||||
defer func() {
|
||||
_ = tx.Rollback()
|
||||
}()
|
||||
|
||||
for _, swap := range loopOutSwaps {
|
||||
|
||||
// Get the year of the timestamp.
|
||||
year, err := getTimeStampYear(swap.PublicationDeadline)
|
||||
if err != nil {
|
||||
|
|
@ -300,7 +307,7 @@ type SqliteTxOptions struct {
|
|||
readOnly bool
|
||||
}
|
||||
|
||||
// NewKeyStoreReadOpts returns a new KeyStoreTxOptions instance triggers a read
|
||||
// NewSqlReadOpts returns a new KeyStoreTxOptions instance triggers a read
|
||||
// transaction.
|
||||
func NewSqlReadOpts() *SqliteTxOptions {
|
||||
return &SqliteTxOptions{
|
||||
|
|
@ -310,7 +317,7 @@ func NewSqlReadOpts() *SqliteTxOptions {
|
|||
|
||||
// ReadOnly returns true if the transaction should be read only.
|
||||
//
|
||||
// NOTE: This implements the TxOptions
|
||||
// NOTE: This implements the TxOptions interface.
|
||||
func (r *SqliteTxOptions) ReadOnly() bool {
|
||||
return r.readOnly
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ func TestLoopOutStore(t *testing.T) {
|
|||
})
|
||||
|
||||
labelledSwap := unrestrictedSwap
|
||||
labelledSwap.Label = "test label"
|
||||
labelledSwap.Label = testLabel
|
||||
t.Run("labelled swap", func(t *testing.T) {
|
||||
testLoopOutStore(t, &labelledSwap)
|
||||
})
|
||||
|
|
@ -249,7 +249,7 @@ func TestLoopInStore(t *testing.T) {
|
|||
})
|
||||
|
||||
labelledSwap := pendingSwap
|
||||
labelledSwap.Label = "test label"
|
||||
labelledSwap.Label = testLabel
|
||||
t.Run("loop in with label", func(t *testing.T) {
|
||||
testLoopInStore(t, labelledSwap)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -682,7 +682,7 @@ func testPreimagePush(t *testing.T) {
|
|||
sweepTx := ctx.ReceiveTx()
|
||||
|
||||
// Finally, we put this swap out of its misery and notify a successful
|
||||
// spend our our sweepTx and assert that the swap succeeds.
|
||||
// spend our sweepTx and assert that the swap succeeds.
|
||||
ctx.NotifySpend(sweepTx, 0)
|
||||
|
||||
cfg.store.(*storeMock).assertLoopOutState(loopdb.StateSuccess)
|
||||
|
|
@ -1007,7 +1007,7 @@ func TestLoopOutMuSig2Sweep(t *testing.T) {
|
|||
require.Len(t, sweepTx.TxIn[0].Witness, 1)
|
||||
|
||||
// Finally, we put this swap out of its misery and notify a successful
|
||||
// spend our our sweepTx and assert that the swap succeeds.
|
||||
// spend our sweepTx and assert that the swap succeeds.
|
||||
ctx.NotifySpend(sweepTx, 0)
|
||||
|
||||
cfg.store.(*storeMock).assertLoopOutState(loopdb.StateSuccess)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ func (s *PrefixLog) Infof(format string, params ...interface{}) {
|
|||
)
|
||||
}
|
||||
|
||||
// Warnf formats message according to format specifier and writes to
|
||||
// to log with LevelError.
|
||||
// Warnf formats message according to format specifier and writes to log with
|
||||
// LevelError.
|
||||
func (s *PrefixLog) Warnf(format string, params ...interface{}) {
|
||||
s.Logger.Warnf(
|
||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||
|
|
@ -34,8 +34,8 @@ func (s *PrefixLog) Warnf(format string, params ...interface{}) {
|
|||
)
|
||||
}
|
||||
|
||||
// Errorf formats message according to format specifier and writes to
|
||||
// to log with LevelError.
|
||||
// Errorf formats message according to format specifier and writes to log with
|
||||
// LevelError.
|
||||
func (s *PrefixLog) Errorf(format string, params ...interface{}) {
|
||||
s.Logger.Errorf(
|
||||
fmt.Sprintf("%v %s", ShortHash(&s.Hash), format),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ var (
|
|||
// the write-end pipe of an initialized log rotator.
|
||||
type logWriter struct{}
|
||||
|
||||
func (logWriter) Write(p []byte) (n int, err error) {
|
||||
func (logWriter) Write(p []byte) (int, error) {
|
||||
os.Stdout.Write(p)
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
FROM golang:1.18
|
||||
FROM golang:1.21
|
||||
|
||||
RUN apt-get update && apt-get install -y git
|
||||
ENV GOCACHE=/tmp/build/.cache
|
||||
ENV GOMODCACHE=/tmp/build/.modcache
|
||||
ENV GOFLAGS="-buildvcs=false"
|
||||
|
||||
COPY . /tmp/tools
|
||||
|
||||
|
|
@ -10,8 +11,6 @@ RUN cd /tmp \
|
|||
&& mkdir -p /tmp/build/.cache \
|
||||
&& mkdir -p /tmp/build/.modcache \
|
||||
&& cd /tmp/tools \
|
||||
&& go install -trimpath -tags=tools github.com/golangci/golangci-lint/cmd/golangci-lint \
|
||||
&& chmod -R 777 /tmp/build/ \
|
||||
&& git config --global --add safe.directory /build
|
||||
|
||||
&& go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint \
|
||||
&& chmod -R 777 /tmp/build/
|
||||
WORKDIR /build
|
||||
|
|
@ -3,6 +3,6 @@ module github.com/lightninglabs/loop/tools
|
|||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/golangci/golangci-lint v1.46.2 // indirect
|
||||
github.com/rinchsan/gosimports v0.1.5 // indirect
|
||||
github.com/golangci/golangci-lint v1.54.2
|
||||
github.com/rinchsan/gosimports v0.1.5
|
||||
)
|
||||
|
|
|
|||
681
tools/go.sum
681
tools/go.sum
File diff suppressed because it is too large
Load diff
2
utils.go
2
utils.go
|
|
@ -387,6 +387,8 @@ func invoicesrpcSelectHopHints(amtMSat lnwire.MilliSatoshi, cfg *SelectHopHintsC
|
|||
hopHintChans := make(map[wire.OutPoint]struct{})
|
||||
hopHints := make([][]zpay32.HopHint, 0, numMaxHophints)
|
||||
for _, channel := range openChannels {
|
||||
channel := channel
|
||||
|
||||
enoughHopHints := sufficientHints(
|
||||
len(hopHints), numMaxHophints, hopHintFactor, amtMSat,
|
||||
totalHintBandwidth,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue