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