naive: fix gas limit for l2 batch transaction

This commit is contained in:
yosoyubik 2021-06-14 17:21:57 +02:00
parent 066795c32c
commit 4c4e0e70b8

View File

@ -3,7 +3,6 @@
/- rpc=json-rpc, *aggregator /- rpc=json-rpc, *aggregator
/+ naive, ethereum, ethio, strandio /+ naive, ethereum, ethio, strandio
:: ::
=/ gas-limit=@ud 30.000 ::TODO verify, maybe scale with roll size
:: ::
|= args=vase |= args=vase
=+ !<(rpc-send-roll args) =+ !<(rpc-send-roll args)
@ -24,6 +23,20 @@
;< use-gas-price=@ud bind:m ;< use-gas-price=@ud bind:m
?: =(0 next-gas-price) fetch-gas-price ?: =(0 next-gas-price) fetch-gas-price
(pure:(strand:strandio @ud) next-gas-price) (pure:(strand:strandio @ud) next-gas-price)
:: TODO: verify, it seems to be slightly bigger when (lent txs) > 1 ?
::
:: each signed l2 tx is 65 bytes
:: from the ethereum yellow paper:
:: gasLimit = G_transaction + G_txdatanonzero × dataByteLength x batch_length
:: where
:: G_transaction = 21000 gas
:: + G_txdatanonzero = 68 gas
:: * dataByteLength = 65 bytes
:: == 25.420 gas/l2-tx
::
:: TODO: enforce max number of tx in batch?
::
=/ gas-limit=@ud (add 21.000 :(mul 68 65 (lent txs)))
:: if we cannot pay for the transaction, don't bother sending it out :: if we cannot pay for the transaction, don't bother sending it out
:: ::
=/ max-cost=@ud (mul gas-limit use-gas-price) =/ max-cost=@ud (mul gas-limit use-gas-price)
@ -41,9 +54,7 @@
(sign-transaction:key:ethereum tx pk) (sign-transaction:key:ethereum tx pk)
:* nonce :* nonce
use-gas-price use-gas-price
:: TODO: scale properly gas-limit
::
(mul gas-limit (lent txs))
contract contract
0 0
:: ::