IntersectMBO / cardano-node

The core component that is used to participate in a Cardano decentralised blockchain.
https://cardano.org
Apache License 2.0
3.06k stars 720 forks source link

[BUG] - Unable to mint token with transaction build cmd - FeeTooSmallUTxO #3019

Closed catch-21 closed 3 years ago

catch-21 commented 3 years ago

Internal/External Internal if an IOHK staff member.

Area Native Tokens Related to Native Tokens (Mary).

Summary The transaction build cmd's fee calculation seems to always underestimate how much is needed for a minting transaction (Mary).

Steps to reproduce

  1. Have funds
    $ CARDANO_NODE_SOCKET_PATH=node/node.sock cardano-cli query utxo --address $(cat acct.addr) --testnet-magic $(cat node/db/protocolMagicId)
                           TxHash                                 TxIx        Amount
    --------------------------------------------------------------------------------------
    53aaa82f791b626cb1f20bd43fd4c845f0894105b9722a29228ce2e418805999     0        499999834103 lovelace + TxOutDatumHashNone
    53aaa82f791b626cb1f20bd43fd4c845f0894105b9722a29228ce2e418805999     1        500000000000 lovelace + TxOutDatumHashNone
  2. Have a minting policy
    $ cat MA/policy.script
    {"keyHash": "2b3e59bdf2cbbb8f9352e243f3e1426d28b110faa646d4d58c4b3b16", "type": "sig"}
  3. Use transaction build
    $ CARDANO_NODE_SOCKET_PATH=node/node.sock cardano-cli transaction build --tx-in 53aaa82f791b626cb1f20bd43fd4c845f0894105b9722a29228ce2e418805999#0 --tx-out "$(<acct.addr)+1000000000+1 $(<MA/policyId)" --mint="1 $(<MA/policyId)" --mint-script-file MA/policy.script --change-address $(<acct.addr) --out-file txbody --alonzo-era --testnet-magic $(<node/db/protocolMagicId)
  4. Sign and submit
    $ cardano-cli transaction sign --tx-body-file txbody --signing-key-file acct.skey --signing-key-file MA/policy.skey --testnet-magic $(<node/db/protocolMagicId) --tx-file tx
    $ CARDANO_NODE_SOCKET_PATH=node/node.sock cardano-cli transaction submit --tx-file tx --testnet-magic $(<node/db/protocolMagicId)
  5. Observe error
    Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 174741) (Coin 170297))))])

Expected behavior No error on submit. build cmd uses minimum amount of ada as fee.

System info (please complete the following information):

Screenshots and attachments None

Additional context None

dorin100 commented 3 years ago

I am also getting Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 176501) (Coin 172057))))])

Jimbo4350 commented 3 years ago

So the issue here is the build command assumes 1 key witness per tx input, withdrawal, certificate, update proposal or required signer (and in this case we have one tx input). However the native script requires an additional signature so we actually need two key witnesses. Because of this the tx fee is underestimated. We have decided to include an additional optional argument --override-witnesses that will override the internal witness estimation of the transaction build command. In this case you need to set --witness-override 2.