Closed VenkataRoundSqr closed 2 years ago
Thank you to open this issue. It is bug in some situations especially when the address contains lots of small utxos.
We should start to solve it on classic Neblio transactions and then we can add token transactions and finally we will implement it for Dogecoin too. When we will have more blockchains integrated, we will design new more common function/core for this.
We can also explore how the NBitcoin library solve this (they have the functions for this too), but it creates new dependency to NBitcoin.
Example: You need to send 10 NEBL and you have two basic situations:
you have some utxo with value bigger than this so the transaction will contains just one utxo.
you have lots of small utxos and transaction will need lots of inputs = bigger size = it could require bigger fee than the basic one.
Common fee on Neblio blockchain is just 0.0001 NEBL. It is for one 1kB so when the transaction will have 1kB-2kB you need to add another 0.0001 NEBL = total fee will be 0.0002 NEBL...When you will have 2kB-3kB it will be 0.0003 NEBL, etc. up to 4kB.
For the token transactions the basic fee is 0.0002 NEBL and then same logic based on the kB (up to 4kB size).
The function should assembly the transaction or based on standardized structure it should calculated expected size and then fee. Then NeblioAccount class provides the list of already loaded utxos which should be available for the transaction. So it can happen that after you will create tx and you will see that you need the bigger fee, you will need to add another utox as input to be able cover the fee. This can be prevent if we will set some minimal amount which is required for send transactions (for example you must have on you address: amount to send + 0.1 NEBL (not token txs) for cover fees.
The best next steps will be to add some basic new logic into NeblioTransactionsHelpers class. It can be shared between all the functions.
We need to consider:
After some exploring of this issue we agreed to me explore this too. Today I have commit first part of the solution. This can be improved, but now it should solve the bugs:
I have created function which takes the constant length of the signed inputs, outputs, etc. and calculate some expected length (with some reserve). Then it will return some expected fee based on specific logic for the network. It was added for both Neblio and Dogecoin. It should be considered like common function for both because they are both based on utxo protocol (same logic can be used for Bitcoin, ReddCoin, etc.).
Function is here:
Here you can find the example use:
Use of the CalcFee for Neblio Classic Payment
Here it is for the Token transaction (this one is little more complicated because it sends both Neblio and Tokens, for example airdrop):
Use of the CalcFee for Neblio and Tokens
Next steps should be some tests and refactoring. Then do some common function for all utxo based blockchains.
I think we can close this issue now. For Neblio we do not have this issues anymore. There is still some issue during calculation of the dogecoin. We should open separated issue for this if it will happen again.
The current logic for calculating fee is based on length of metadata which needs to be removed and a new logic is to be written. The idea is to use NBitcoin library to calculate the length of the transactions and assess the fee for it.
more details and workflow diagram to be followed.