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

Transaction fee calculation #126

Closed
Retamogordo opened this issue Jul 18, 2022 · 9 comments · Fixed by #127
Closed

Transaction fee calculation #126

Retamogordo opened this issue Jul 18, 2022 · 9 comments · Fixed by #127
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@Retamogordo
Copy link

Hi,
I noticed that on 18 Nov 2021 src/routes/transaction.ts was refactored in such a way that transaction fee is calculated
roughly by (data.data_size * 1965132).
My app airdrops winston relying on arweave.transaction.getPrice(...) which yields a value more than ten times smaller than calculated by arlocal, so my transaction fails with status 410.
There is also online arweave fee calculator that yields yet another value.
So I'm confused of what is going on.
Is there a source of truth or a paper I could consult regarding this question ?

@fuadop
Copy link
Contributor

fuadop commented Jul 18, 2022

Hey @Retamogordo 👋
This is currently outdated, the latest arlocal version uses calculation based on https://arweavefees.com

@fuadop fuadop self-assigned this Jul 18, 2022
@fuadop fuadop added question Further information is requested invalid This doesn't seem right labels Jul 18, 2022
@Retamogordo
Copy link
Author

Hi, thanks.
I'm still confused. This code is still there, I can see it on the latest version of transactions.ts.
And another thing (possibly not related to the former one) is that price requests return different values depending on what provider is queried, e.g.:
https://arweave.dev/price/400 => returns 65595508 (plain format)
http://localhost:1984/price/400 => returns 26238203 (json)

@Retamogordo
Copy link
Author

Retamogordo commented Jul 18, 2022

At first glance (I forked the repo today):
in app.ts:
quering price uses this:
this.router.get('/price/:bytes/:addy?', async (ctx) => (ctx.body = (+ctx.params.bytes / 1000) * 65595508));

while post transaction code uses another formula to check if balance is sufficient:
async function txPostRoute(ctx: Router.RouterContext) { .... const calculatedReward = +(data.data_size || '0') * 1965132; if (!wallet || wallet.balance < calculatedReward) { ctx.status = 410; ctx.body = { code: 410, msg: "You don't have enough tokens" }; return; }

So my tx fails due to insufficient balance, despite I airdrop winston according to price query.

}

@fuadop
Copy link
Contributor

fuadop commented Jul 18, 2022

I see @Retamogordo
This is a bug! Thank you very much for noticing this. A fix would be made for this soon!🙏

@fuadop fuadop added bug Something isn't working and removed invalid This doesn't seem right labels Jul 18, 2022
@Retamogordo
Copy link
Author

Ouch..
So could you somehow inform me as soon as it is fixed ? I mean when it is ready for install at npm.
Thanks a lot.

@fuadop
Copy link
Contributor

fuadop commented Jul 18, 2022

Sure !, A PR has been raised on #127. I'll be sure to notify you when npm gets updated with this change.

@Retamogordo
Copy link
Author

Retamogordo commented Jul 18, 2022

Hi, it's me again,
I see that the fix is merged, so query results must be consistent.
There is one thing I still do not catch, though.
On https://arweavefees.com/ I notice that they use a kind of step function for fee calculations,
namely I get the same results for data sizes of, let us say: 400 bytes and 1000 bytes or 4000 bytes, which is 64958659 winston.
Contrary to that ArLocal uses a linear function on data size for fee calc, so for 400 bytes I get 28402855 winston.
So I still observe a certain inconsistency of the two approaches.

@cedriking
Copy link
Contributor

Hey @Retamogordo , what @fuadop did here is to set the fee at the default from mainnet. Which will give the same fee calculation for 0 bytes.

On mainnet, after a couple of bytes, the fees are completely dynamic, based on many factors that we cannot recreate on arlocal since there's no competition while mining, limits of txs per blocks, etc.

Hope this helps answer why it's different. The fee should be calculated from the arlocal endpoint /price/:bytes.

@Retamogordo
Copy link
Author

Cool, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants