From 6bab96af5292a5d29a58a284df9fcac02597dc19 Mon Sep 17 00:00:00 2001 From: bruwbird Date: Fri, 2 Aug 2024 17:46:46 +0900 Subject: [PATCH] liquid: drop the flat fee for mempool policy patch elements releases have the mempool policy patch, so we should consider a minimum elements version. After applying the patch, the minimum fee is set to 0.01. --- go.mod | 2 +- go.sum | 2 ++ wallet/elementsrpcwallet.go | 22 ++++++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 90540f96..b343ab69 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.2 github.com/btcsuite/btcd/btcutil/psbt v1.1.5 github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 - github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a + github.com/elementsproject/glightning v0.0.0-20240802020216-b4e19b004ca4 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 github.com/jessevdk/go-flags v1.5.0 diff --git a/go.sum b/go.sum index f8289c28..71f3c6e2 100644 --- a/go.sum +++ b/go.sum @@ -190,6 +190,8 @@ github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6 h1:sE4tvxWw01v7K3M github.com/dvyukov/go-fuzz v0.0.0-20220726122315-1d375ef9f9f6/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw= github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a h1:xnVQmVqGmSs3m8zPQF4iYEYiUAmJx8MlT9vJ3lAaOjc= github.com/elementsproject/glightning v0.0.0-20240224063423-55240d61b52a/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo= +github.com/elementsproject/glightning v0.0.0-20240802020216-b4e19b004ca4 h1:7CXEOi0uTeMrwLfFmHsbBS5yRfpSAHALwa9k9Rtl1Vw= +github.com/elementsproject/glightning v0.0.0-20240802020216-b4e19b004ca4/go.mod h1:YAdIeSyx8VEhDCtEaGOJLmWNpPaQ3x4vYSAj9Vrppdo= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= diff --git a/wallet/elementsrpcwallet.go b/wallet/elementsrpcwallet.go index 624d6313..c9543e82 100644 --- a/wallet/elementsrpcwallet.go +++ b/wallet/elementsrpcwallet.go @@ -20,6 +20,11 @@ var ( AlreadyLoadedError = errors.New("wallet is already loaded") ) +const ( + // https://github.com/ElementsProject/elements/releases/tag/elements-23.2.2 + elementsdFeeDiscountedVersion = 230202 +) + type RpcClient interface { GetNewAddress(addrType int) (string, error) SendToAddress(address string, amount string) (string, error) @@ -35,6 +40,7 @@ type RpcClient interface { EstimateFee(blocks uint32, mode string) (*gelements.FeeResponse, error) SetLabel(address, label string) error Ping() (bool, error) + GetNetworkInfo() (*gelements.NetworkInfo, error) } // ElementsRpcWallet uses the elementsd rpc wallet @@ -196,13 +202,17 @@ func (r *ElementsRpcWallet) GetFee(txSize int64) (uint64, error) { if err != nil { return 0, err } - satPerByte := float64(feeRes.SatPerKb()) / float64(1000) - if satPerByte < 0.1 { - satPerByte = 0.1 + defaultSatPerByte := 0.1 + ni, err := r.rpcClient.GetNetworkInfo() + if err != nil { + return 0, err } - if len(feeRes.Errors) > 0 { - //todo sane default sat per byte - satPerByte = 0.1 + if ni.Version >= elementsdFeeDiscountedVersion { + defaultSatPerByte = 0.01 + } + satPerByte := float64(feeRes.SatPerKb()) / float64(1000) + if satPerByte < defaultSatPerByte || len(feeRes.Errors) > 0 { + satPerByte = defaultSatPerByte } // assume largest witness fee := satPerByte * float64(txSize)