Repository navigation
Replies: 1 comment
|
I'm actually not sure myself if there's a standard answer. I performed some experiments w/the assistance of Opus: C is I believe what you were describing, and is indeed what the tapfreighter package does for fee estimation internally (the actual delta vs truth wouldn't be 0% in practice; this was under experimental/regtest conditions). You can recover the lock when finished, but if it's a dealbreaker, B seems to work well whilst being pretty simple and robust-looking. A quick proof-of-concept: // dummyP2TRScript returns a syntactically-valid P2TR output script.
// Only the script structure (op + 32-byte key) matters for size
// estimation; the key itself can be anything on the curve.
func dummyP2TRScript() []byte {
_, pub := btcec.PrivKeyFromBytes([]byte{0x01})
script, _ := txscript.PayToTaprootScript(pub)
return script
}
// We synthesize a representative input/output set: one P2TR input for
// the asset anchor + one P2TR input for the BTC fee, and `nOutputs`
// P2TR outputs (recipient + sender change + BTC change is the typical
// shape).
func estimateSynthetic(ctx context.Context,
lndWallet walletrpc.WalletKitClient, targetConf int32,
nOutputs int) (int64, error) {
resp, _ := lndWallet.EstimateFee(ctx, &walletrpc.EstimateFeeRequest{
ConfTarget: targetConf,
})
feeRate := chainfee.SatPerKWeight(resp.SatPerKw)
p2trScript := dummyP2TRScript()
inputScripts := [][]byte{p2trScript, p2trScript}
outputs := make([]*wire.TxOut, nOutputs)
for i := range outputs {
outputs[i] = &wire.TxOut{Value: 1000, PkScript: p2trScript}
}
_, fee := tapscript.EstimateFee(inputScripts, outputs, feeRate)
return int64(fee), nil
}Opus's B' is just the same thing with non-dummy p2tr scripts. Its PoC is a bit fragile-looking, but I think could be adapted so as to be more robust (you could just use the dummy script as a fallback). |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I believe there is no dedicated endpoint for estimating chain fee for asset sends? Is
LND.EstimateFeethe simplest option get fee estimation?LND.EstimateFeeonly computes for a plainp2trsend, which I believe is underestimating an actual asset send.The other option is getting to the step of an unsigned anchor PSBT, which gives us the final size and we can calculate the fee with it. However I believe UTXOs are locked up in the process right? If so, it’s a dealbreaker.
What is the recommended approach?
All reactions