o1-labs / o1js

TypeScript framework for zk-SNARKs and zkApps
https://docs.minaprotocol.com/en/zkapps/how-to-write-a-zkapp
Apache License 2.0
475 stars 105 forks source link

Specify fee per weight unit #1626

Open mitschabaude opened 2 months ago

mitschabaude commented 2 months ago

https://discord.com/channels/484437221055922177/1234429008427618387/1234765711298007071

can we add to Mina.transaction the possibility to specify the fee per weight unit instead of fee per transaction? According to the explanation above, the market fee will be fee/wu, and to get the tx fee right, we need to know the number of account updates, which is finally known only after the tx is created.

dfstio commented 1 month ago

Given that market conditions can change fast, there should also be a way to resend the tx with an increased fee, something like:

const txSent = await tx.send();
const json = txSent.toJSON();

// 10 min later, if tx is not included in the book due to fee fluctuations
const tx1 = Mina.Transaction.fromJSON(
    JSON.parse(json)
  ) as Mina.Transaction;
tx1.setFee(increasedFeePerWU) // tx1.feePayer.body.fee = increasedFeePerWU * accountUpdatesNum;
const txSent1 = await tx1.sign([privateKey]).send();