Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad fee estimation on multiple assets tx #473

Open
bordalix opened this issue Apr 17, 2023 · 1 comment
Open

Bad fee estimation on multiple assets tx #473

bordalix opened this issue Apr 17, 2023 · 1 comment

Comments

@bordalix
Copy link
Contributor

How to replicate:

  • Create 3 borrow contracts on fuji.money
  • Aggregate FUSD Utxos:
    • Marina > Receive > FUSD > Get address
    • Marina > Send > FUSD > Put address and send all
    • Pay tx fee with LBTC
  • This tx will fail when broadcasting, with electrumx returning the following error:
{
    "error": "sendrawtransaction RPC error: {\"code\":-26,\"message\":\"min relay fee not met, 216 < 272\"}",
    "id": 75711,
    "jsonrpc": "2.0"
}
@bordalix
Copy link
Contributor Author

I guess the problem exists because fee estimation is made before adding the LBTC utxos and inputs to pay the fee and respective change outputs:

marina/src/domain/pset.ts

Lines 243 to 298 in 8e6c90c

const feeAmount = Math.ceil(estimatedSize * (sats1000Bytes / 1000));
if (feeAssetHash === asset) {
updater.addOutputs([
{
amount: feeAmount,
asset: feeAssetHash,
},
]);
updater.pset.outputs[0].value -= feeAmount;
} else {
// coinselect some L-BTC to pay the fees
const coinSelection = await this.walletRepository.selectUtxos(network, [
{ asset: feeAssetHash, amount: feeAmount },
]);
const witnessUtxos = await Promise.all(
coinSelection.utxos.map((utxo) =>
this.walletRepository.getWitnessUtxo(utxo.txID, utxo.vout)
)
);
updater.addInputs(
coinSelection.utxos.map((utxo, i) => ({
txid: utxo.txID,
txIndex: utxo.vout,
sighashType: Transaction.SIGHASH_ALL,
witnessUtxo: witnessUtxos[i],
}))
);
if (coinSelection.changeOutputs && coinSelection.changeOutputs.length > 0) {
const accountFactory = await AccountFactory.create(this.walletRepository);
const accountName = network === 'liquid' ? MainAccount : MainAccountTest;
const mainAccount = await accountFactory.make(network, accountName);
const changeAddress = await mainAccount.getNextAddress(true);
updater.addOutputs(
coinSelection.changeOutputs.map((change) => ({
amount: change.amount,
asset: change.asset,
script: address.toOutputScript(changeAddress.confidentialAddress),
blinderIndex: 0,
blindingPublicKey: address.fromConfidential(changeAddress.confidentialAddress)
.blindingKey,
}))
);
}
updater.addOutputs([
{
amount: feeAmount,
asset: feeAssetHash,
},
]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant