Skip to content

Commit

Permalink
Dynamic min-relay-fee and dust amount (#280)
Browse files Browse the repository at this point in the history
* [btc-embedded] add chainfee.Estimator and extraAPI interfaces

* dynamic fee amount

* dynamic dust amount

* [client] fix linter errors

* [domain] fix unit tests

* [server] return dust amount in GetInfo RPC

* [sdk] fix lnd dependencie

* go work sync

* fix witness stack size forfeit tx size estimator

* remove hardcoded fee values in covenant txbuilder

* lower liquid feerate

* fix after reviews

* go work sync
  • Loading branch information
louisinger authored Sep 10, 2024
1 parent a8cf0ed commit 0fb34cb
Show file tree
Hide file tree
Showing 75 changed files with 2,061 additions and 594 deletions.
5 changes: 4 additions & 1 deletion api-spec/openapi/swagger/ark/v1/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@
"network": {
"type": "string"
},
"minRelayFee": {
"dust": {
"type": "string",
"format": "int64"
},
Expand Down Expand Up @@ -880,6 +880,9 @@
},
"unsignedTree": {
"$ref": "#/definitions/v1Tree"
},
"unsignedRoundTx": {
"type": "string"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion api-spec/protobuf/ark/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ message GetInfoResponse {
int64 unilateral_exit_delay = 3;
int64 round_interval = 4;
string network = 5;
int64 min_relay_fee = 6;
int64 dust = 6;
string boarding_descriptor_template = 7;
}

Expand Down Expand Up @@ -215,6 +215,7 @@ message RoundSigningEvent {
string id = 1;
repeated string cosigners_pubkeys = 2;
Tree unsigned_tree = 3;
string unsigned_round_tx = 4;
}

message RoundSigningNoncesGeneratedEvent {
Expand Down
449 changes: 229 additions & 220 deletions api-spec/protobuf/gen/ark/v1/service.pb.go

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions client/covenant/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/vulpemventures/go-elements/psetv2"
)

const dust = 450

type covenantLiquidCLI struct{}

func (c *covenantLiquidCLI) SendAsync(ctx *cli.Context) error {
Expand Down Expand Up @@ -97,6 +95,11 @@ func sendOnchain(ctx *cli.Context, receivers []receiver) (string, error) {
return "", err
}

dust, err := utils.GetDust(ctx)
if err != nil {
return "", err
}

liquidNet := toElementsNetwork(net)

targetAmount := uint64(0)
Expand Down
1 change: 1 addition & 0 deletions client/covenant/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func connectToAsp(ctx *cli.Context, net, url, explorer string) error {
utils.ROUND_LIFETIME: strconv.Itoa(int(resp.GetRoundLifetime())),
utils.UNILATERAL_EXIT_DELAY: strconv.Itoa(int(resp.GetUnilateralExitDelay())),
utils.EXPLORER: explorer,
utils.DUST: strconv.Itoa(int(resp.GetDust())),
utils.BOARDING_TEMPLATE: resp.GetBoardingDescriptorTemplate(),
})
}
Expand Down
7 changes: 6 additions & 1 deletion client/covenant/redeem.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func collaborativeRedeem(
return err
}

dust, err := utils.GetDust(ctx)
if err != nil {
return err
}

liquidNet := toElementsNetwork(netinstate)

if net.Name != liquidNet.Name {
Expand Down Expand Up @@ -62,7 +67,7 @@ func collaborativeRedeem(
return err
}

selectedCoins, changeAmount, err := coinSelect(vtxos, amount, withExpiryCoinselect)
selectedCoins, changeAmount, err := coinSelect(vtxos, amount, withExpiryCoinselect, dust)
if err != nil {
return err
}
Expand Down
9 changes: 7 additions & 2 deletions client/covenant/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func sendOffchain(ctx *cli.Context, receivers []receiver) error {
return err
}

dust, err := utils.GetDust(ctx)
if err != nil {
return err
}

receiversOutput := make([]*arkv1.Output, 0)
sumOfReceivers := uint64(0)

Expand Down Expand Up @@ -126,7 +131,7 @@ func sendOffchain(ctx *cli.Context, receivers []receiver) error {
if err != nil {
return err
}
selectedCoins, changeAmount, err := coinSelect(vtxos, sumOfReceivers, withExpiryCoinselect)
selectedCoins, changeAmount, err := coinSelect(vtxos, sumOfReceivers, withExpiryCoinselect, dust)
if err != nil {
return err
}
Expand Down Expand Up @@ -185,7 +190,7 @@ func sendOffchain(ctx *cli.Context, receivers []receiver) error {
})
}

func coinSelect(vtxos []vtxo, amount uint64, sortByExpirationTime bool) ([]vtxo, uint64, error) {
func coinSelect(vtxos []vtxo, amount uint64, sortByExpirationTime bool, dust uint64) ([]vtxo, uint64, error) {
selected := make([]vtxo, 0)
notSelected := make([]vtxo, 0)
selectedAmount := uint64(0)
Expand Down
7 changes: 5 additions & 2 deletions client/covenantless/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"github.com/urfave/cli/v2"
)

const dust = 450

type clArkBitcoinCLI struct{}

func (c *clArkBitcoinCLI) Receive(ctx *cli.Context) error {
Expand Down Expand Up @@ -95,6 +93,11 @@ func sendOnchain(ctx *cli.Context, receivers []receiver) (string, error) {
return "", err
}

dust, err := utils.GetDust(ctx)
if err != nil {
return "", err
}

netParams := toChainParams(net)

targetAmount := uint64(0)
Expand Down
22 changes: 10 additions & 12 deletions client/covenantless/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ func handleRoundStream(
return "", err
}

minRelayFee, err := utils.GetMinRelayFee(ctx)
if err != nil {
return "", err
}

aspPubkey, err := utils.GetAspPublicKey(ctx)
if err != nil {
return "", err
Expand All @@ -292,8 +287,16 @@ func handleRoundStream(
sweepTapTree := txscript.AssembleTaprootScriptTree(*sweepTapLeaf)
root := sweepTapTree.RootNode.TapHash()

roundTx, err := psbt.NewFromRawBytes(strings.NewReader(e.GetUnsignedRoundTx()), true)
if err != nil {
return "", err
}

sharedOutput := roundTx.UnsignedTx.TxOut[0]
sharedOutputValue := sharedOutput.Value

treeSignerSession = bitcointree.NewTreeSignerSession(
ephemeralKey, congestionTree, int64(minRelayFee), root.CloneBytes(),
ephemeralKey, sharedOutputValue, congestionTree, root.CloneBytes(),
)

nonces, err := treeSignerSession.GetNonces()
Expand Down Expand Up @@ -401,14 +404,9 @@ func handleRoundStream(
return "", err
}

minRelayFee, err := utils.GetMinRelayFee(ctx)
if err != nil {
return "", err
}

if !isOnchainOnly(receivers) {
if err := bitcointree.ValidateCongestionTree(
congestionTree, roundTx, aspPubkey, int64(roundLifetime), int64(minRelayFee),
congestionTree, roundTx, aspPubkey, int64(roundLifetime),
); err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion client/covenantless/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func connectToAsp(ctx *cli.Context, net, url, explorer string) error {
utils.ASP_PUBKEY: resp.Pubkey,
utils.ROUND_LIFETIME: strconv.Itoa(int(resp.GetRoundLifetime())),
utils.UNILATERAL_EXIT_DELAY: strconv.Itoa(int(resp.GetUnilateralExitDelay())),
utils.MIN_RELAY_FEE: strconv.Itoa(int(resp.MinRelayFee)),
utils.EXPLORER: explorer,
utils.DUST: strconv.Itoa(int(resp.GetDust())),
utils.BOARDING_TEMPLATE: resp.GetBoardingDescriptorTemplate(),
})
}
Expand Down
7 changes: 6 additions & 1 deletion client/covenantless/redeem.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func collaborativeRedeem(
return err
}

dust, err := utils.GetDust(ctx)
if err != nil {
return err
}

netParams := toChainParams(netinstate)

if netinstate.Name != netParams.Name {
Expand All @@ -56,7 +61,7 @@ func collaborativeRedeem(
return err
}

selectedCoins, changeAmount, err := coinSelect(vtxos, amount, withExpiryCoinselect)
selectedCoins, changeAmount, err := coinSelect(vtxos, amount, withExpiryCoinselect, dust)
if err != nil {
return err
}
Expand Down
9 changes: 7 additions & 2 deletions client/covenantless/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func (c *clArkBitcoinCLI) SendAsync(ctx *cli.Context) error {
amount := ctx.Uint64("amount")
withExpiryCoinselect := ctx.Bool("enable-expiry-coinselect")

dust, err := utils.GetDust(ctx)
if err != nil {
return err
}

if amount < dust {
return fmt.Errorf("invalid amount (%d), must be greater than dust %d", amount, dust)
}
Expand Down Expand Up @@ -78,7 +83,7 @@ func (c *clArkBitcoinCLI) SendAsync(ctx *cli.Context) error {
if err != nil {
return err
}
selectedCoins, changeAmount, err := coinSelect(vtxos, sumOfReceivers, withExpiryCoinselect)
selectedCoins, changeAmount, err := coinSelect(vtxos, sumOfReceivers, withExpiryCoinselect, dust)
if err != nil {
return err
}
Expand Down Expand Up @@ -166,7 +171,7 @@ func (c *clArkBitcoinCLI) SendAsync(ctx *cli.Context) error {
return nil
}

func coinSelect(vtxos []vtxo, amount uint64, sortByExpirationTime bool) ([]vtxo, uint64, error) {
func coinSelect(vtxos []vtxo, amount uint64, sortByExpirationTime bool, dust uint64) ([]vtxo, uint64, error) {
selected := make([]vtxo, 0)
notSelected := make([]vtxo, 0)
selectedAmount := uint64(0)
Expand Down
49 changes: 49 additions & 0 deletions client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,58 @@ require (
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/aead/siphash v1.0.1 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/btcsuite/btcwallet v0.16.10-0.20240718224643-db3a4a2543bd // indirect
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.4 // indirect
github.com/btcsuite/btcwallet/wallet/txrules v1.2.1 // indirect
github.com/btcsuite/btcwallet/wallet/txsizes v1.2.4 // indirect
github.com/btcsuite/btcwallet/walletdb v1.4.2 // indirect
github.com/btcsuite/btcwallet/wtxmgr v1.5.3 // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/lru v1.1.3 // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kkdai/bstream v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd // indirect
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
github.com/lightningnetwork/lnd v0.18.2-beta // indirect
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
github.com/lightningnetwork/lnd/fn v1.2.1 // indirect
github.com/lightningnetwork/lnd/queue v1.1.1 // indirect
github.com/lightningnetwork/lnd/ticker v1.1.1 // indirect
github.com/lightningnetwork/lnd/tlv v1.2.6 // indirect
github.com/ltcsuite/ltcd/chaincfg/chainhash v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runc v1.1.13 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
go.etcd.io/etcd/client/v2 v2.305.15 // indirect
go.etcd.io/etcd/pkg/v3 v3.5.15 // indirect
go.etcd.io/etcd/raft/v3 v3.5.15 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/sync v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
Expand Down
Loading

0 comments on commit 0fb34cb

Please sign in to comment.