mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-18 13:08:28 +02:00
liquidity: gate static autoloop
Static-address loop-ins in autoloop are still experimental. Reject loop_in_source=static-address at the RPC boundary unless loopd was started with --experimental, and pass the same opt-in into the liquidity manager so persisted params cannot bypass the gate after restart. The existing static swap accounting remains wired through the manager; the gate only controls accepting and planning new static-address autoloops.
This commit is contained in:
parent
8d6df2bf20
commit
7fcc508193
11 changed files with 88 additions and 6 deletions
|
|
@ -192,7 +192,7 @@ type Config struct {
|
|||
MaxStaticAddrHtlcFeePercentage float64 `long:"maxstaticaddrhtlcfeepercentage" description:"The maximum fee percentage that the server can charge for the htlc tx."`
|
||||
MaxStaticAddrHtlcBackupFeePercentage float64 `long:"maxstaticaddrhtlcbackupfeepercentage" description:"The maximum fee percentage that the server can charge for the htlc backup tx. The backup transaction is only used in rare cases when the regular htlc tx is not confirmed on time. These backup transactions refer to high fee or extremely high fee transactions in the API."`
|
||||
|
||||
EnableExperimental bool `long:"experimental" description:"Enable experimental features: reservations"`
|
||||
EnableExperimental bool `long:"experimental" description:"Enable experimental features: reservations, static autoloop"`
|
||||
|
||||
MigrationRPCBatchSize int `long:"migrationrpcbatchsize" description:"The RPC batch size to use during migrations."`
|
||||
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
|
|||
}
|
||||
|
||||
liquidityMgr := getLiquidityManager(
|
||||
swapClient, staticLoopInManager,
|
||||
swapClient, staticLoopInManager, d.cfg.EnableExperimental,
|
||||
)
|
||||
|
||||
// Now finally fully initialize the swap client RPC server instance.
|
||||
|
|
|
|||
|
|
@ -1395,6 +1395,18 @@ func (s *swapClientServer) SetLiquidityParams(ctx context.Context,
|
|||
in *looprpc.SetLiquidityParamsRequest) (*looprpc.SetLiquidityParamsResponse,
|
||||
error) {
|
||||
|
||||
enableExperimental := s.config != nil && s.config.EnableExperimental
|
||||
params := in.GetParameters()
|
||||
if params.GetLoopInSource() ==
|
||||
looprpc.LoopInSource_LOOP_IN_SOURCE_STATIC_ADDRESS &&
|
||||
!enableExperimental {
|
||||
|
||||
return nil, status.Error(
|
||||
codes.FailedPrecondition,
|
||||
liquidity.ErrStaticAddressAutoloopExperimental.Error(),
|
||||
)
|
||||
}
|
||||
|
||||
err := s.liquidityMgr.SetParameters(ctx, in.Parameters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import (
|
|||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -281,6 +283,29 @@ func TestStaticAddressLoopInRejectsReservedLabel(t *testing.T) {
|
|||
require.ErrorContains(t, err, labels.ErrReservedPrefix.Error())
|
||||
}
|
||||
|
||||
// TestSetLiquidityParamsRejectsStaticAutoloopWithoutExperimental verifies that
|
||||
// users must restart loopd with --experimental before enabling static-address
|
||||
// autoloop.
|
||||
func TestSetLiquidityParamsRejectsStaticAutoloopWithoutExperimental(
|
||||
t *testing.T) {
|
||||
|
||||
server := &swapClientServer{
|
||||
config: &Config{},
|
||||
}
|
||||
|
||||
_, err := server.SetLiquidityParams(
|
||||
t.Context(), &looprpc.SetLiquidityParamsRequest{
|
||||
Parameters: &looprpc.LiquidityParameters{
|
||||
LoopInSource: looprpc.
|
||||
LoopInSource_LOOP_IN_SOURCE_STATIC_ADDRESS,
|
||||
},
|
||||
},
|
||||
)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, codes.FailedPrecondition, status.Code(err))
|
||||
require.ErrorContains(t, err, "--experimental")
|
||||
}
|
||||
|
||||
// TestRPCAutoloopReasonStaticLoopInNoCandidate verifies that the new planner
|
||||
// reason is exposed over rpc.
|
||||
func TestRPCAutoloopReasonStaticLoopInNoCandidate(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,8 @@ func openDatabase(cfg *Config, chainParams *chaincfg.Params) (loopdb.SwapStore,
|
|||
}
|
||||
|
||||
func getLiquidityManager(client *loop.Client,
|
||||
staticLoopInManager *loopin.Manager) *liquidity.Manager {
|
||||
staticLoopInManager *loopin.Manager,
|
||||
enableExperimental bool) *liquidity.Manager {
|
||||
|
||||
listStaticLoopIn := func(
|
||||
ctx context.Context) ([]*liquidity.StaticLoopInInfo, error) {
|
||||
|
|
@ -259,6 +260,7 @@ func getLiquidityManager(client *loop.Client,
|
|||
PutLiquidityParams: client.Store.PutLiquidityParams,
|
||||
FetchLiquidityParams: client.Store.FetchLiquidityParams,
|
||||
}
|
||||
mngrCfg.EnableStaticAddressAutoloop = enableExperimental
|
||||
|
||||
return liquidity.NewManager(mngrCfg)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue