mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Calculate ForgeBatch gasLimit with parametrized formula
Add the following config parameters at `Coordinator.EthClient.ForgeBatchGasCost`: - `Fixed` - `L1UserTx` - `L1CoordTx` - `L2Tx` Which are the costs associated to a ForgeBatch transaction, split into different parts to be used in the formula to compute the gasLimit.
This commit is contained in:
@@ -104,6 +104,12 @@ GasPriceIncPerc = 10
|
|||||||
Path = "/tmp/iden3-test/hermez/ethkeystore"
|
Path = "/tmp/iden3-test/hermez/ethkeystore"
|
||||||
Password = "yourpasswordhere"
|
Password = "yourpasswordhere"
|
||||||
|
|
||||||
|
[Coordinator.EthClient.ForgeBatchGasCost]
|
||||||
|
Fixed = 500000
|
||||||
|
L1UserTx = 8000
|
||||||
|
L1CoordTx = 9000
|
||||||
|
L2Tx = 1
|
||||||
|
|
||||||
[Coordinator.API]
|
[Coordinator.API]
|
||||||
Coordinator = true
|
Coordinator = true
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,15 @@ type ServerProof struct {
|
|||||||
URL string `validate:"required"`
|
URL string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ForgeBatchGasCost is the costs associated to a ForgeBatch transaction, split
|
||||||
|
// into different parts to be used in a formula.
|
||||||
|
type ForgeBatchGasCost struct {
|
||||||
|
Fixed uint64 `validate:"required"`
|
||||||
|
L1UserTx uint64 `validate:"required"`
|
||||||
|
L1CoordTx uint64 `validate:"required"`
|
||||||
|
L2Tx uint64 `validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// Coordinator is the coordinator specific configuration.
|
// Coordinator is the coordinator specific configuration.
|
||||||
type Coordinator struct {
|
type Coordinator struct {
|
||||||
// ForgerAddress is the address under which this coordinator is forging
|
// ForgerAddress is the address under which this coordinator is forging
|
||||||
@@ -180,6 +189,9 @@ type Coordinator struct {
|
|||||||
// Password used to decrypt the keys in the keystore
|
// Password used to decrypt the keys in the keystore
|
||||||
Password string `validate:"required"`
|
Password string `validate:"required"`
|
||||||
} `validate:"required"`
|
} `validate:"required"`
|
||||||
|
// ForgeBatchGasCost contains the cost of each action in the
|
||||||
|
// ForgeBatch transaction.
|
||||||
|
ForgeBatchGasCost ForgeBatchGasCost `validate:"required"`
|
||||||
} `validate:"required"`
|
} `validate:"required"`
|
||||||
API struct {
|
API struct {
|
||||||
// Coordinator enables the coordinator API endpoints
|
// Coordinator enables the coordinator API endpoints
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/hermeznetwork/hermez-node/batchbuilder"
|
"github.com/hermeznetwork/hermez-node/batchbuilder"
|
||||||
"github.com/hermeznetwork/hermez-node/common"
|
"github.com/hermeznetwork/hermez-node/common"
|
||||||
|
"github.com/hermeznetwork/hermez-node/config"
|
||||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||||
"github.com/hermeznetwork/hermez-node/db/l2db"
|
"github.com/hermeznetwork/hermez-node/db/l2db"
|
||||||
"github.com/hermeznetwork/hermez-node/eth"
|
"github.com/hermeznetwork/hermez-node/eth"
|
||||||
@@ -115,7 +116,10 @@ type Config struct {
|
|||||||
Purger PurgerCfg
|
Purger PurgerCfg
|
||||||
// VerifierIdx is the index of the verifier contract registered in the
|
// VerifierIdx is the index of the verifier contract registered in the
|
||||||
// smart contract
|
// smart contract
|
||||||
VerifierIdx uint8
|
VerifierIdx uint8
|
||||||
|
// ForgeBatchGasCost contains the cost of each action in the
|
||||||
|
// ForgeBatch transaction.
|
||||||
|
ForgeBatchGasCost config.ForgeBatchGasCost
|
||||||
TxProcessorConfig txprocessor.Config
|
TxProcessorConfig txprocessor.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ func (t *TxManager) syncSCVars(vars synchronizer.SCVariablesPtr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewAuth generates a new auth object for an ethereum transaction
|
// NewAuth generates a new auth object for an ethereum transaction
|
||||||
func (t *TxManager) NewAuth(ctx context.Context) (*bind.TransactOpts, error) {
|
func (t *TxManager) NewAuth(ctx context.Context, batchInfo *BatchInfo) (*bind.TransactOpts, error) {
|
||||||
gasPrice, err := t.ethClient.EthSuggestGasPrice(ctx)
|
gasPrice, err := t.ethClient.EthSuggestGasPrice(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, tracerr.Wrap(err)
|
return nil, tracerr.Wrap(err)
|
||||||
@@ -143,15 +143,12 @@ func (t *TxManager) NewAuth(ctx context.Context) (*bind.TransactOpts, error) {
|
|||||||
return nil, tracerr.Wrap(err)
|
return nil, tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
auth.Value = big.NewInt(0) // in wei
|
auth.Value = big.NewInt(0) // in wei
|
||||||
// TODO: Calculate GasLimit based on the contents of the ForgeBatchArgs
|
|
||||||
// This requires a function that estimates the gas usage of the
|
gasLimit := t.cfg.ForgeBatchGasCost.Fixed +
|
||||||
// forgeBatch call based on the contents of the ForgeBatch args:
|
uint64(len(batchInfo.L1UserTxsExtra))*t.cfg.ForgeBatchGasCost.L1UserTx +
|
||||||
// - length of l2txs
|
uint64(len(batchInfo.L1CoordTxs))*t.cfg.ForgeBatchGasCost.L1CoordTx +
|
||||||
// - length of l1Usertxs
|
uint64(len(batchInfo.L2Txs))*t.cfg.ForgeBatchGasCost.L2Tx
|
||||||
// - length of l1CoordTxs with authorization signature
|
auth.GasLimit = gasLimit
|
||||||
// - length of l1CoordTxs without authoriation signature
|
|
||||||
// - etc.
|
|
||||||
auth.GasLimit = 1000000
|
|
||||||
auth.GasPrice = gasPrice
|
auth.GasPrice = gasPrice
|
||||||
auth.Nonce = nil
|
auth.Nonce = nil
|
||||||
|
|
||||||
@@ -191,7 +188,7 @@ func addPerc(v *big.Int, p int64) *big.Int {
|
|||||||
func (t *TxManager) sendRollupForgeBatch(ctx context.Context, batchInfo *BatchInfo, resend bool) error {
|
func (t *TxManager) sendRollupForgeBatch(ctx context.Context, batchInfo *BatchInfo, resend bool) error {
|
||||||
var ethTx *types.Transaction
|
var ethTx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
auth, err := t.NewAuth(ctx)
|
auth, err := t.NewAuth(ctx, batchInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tracerr.Wrap(err)
|
return tracerr.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,6 +336,7 @@ func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
|||||||
PurgeBlockDelay: cfg.Coordinator.L2DB.PurgeBlockDelay,
|
PurgeBlockDelay: cfg.Coordinator.L2DB.PurgeBlockDelay,
|
||||||
InvalidateBlockDelay: cfg.Coordinator.L2DB.InvalidateBlockDelay,
|
InvalidateBlockDelay: cfg.Coordinator.L2DB.InvalidateBlockDelay,
|
||||||
},
|
},
|
||||||
|
ForgeBatchGasCost: cfg.Coordinator.EthClient.ForgeBatchGasCost,
|
||||||
VerifierIdx: uint8(verifierIdx),
|
VerifierIdx: uint8(verifierIdx),
|
||||||
TxProcessorConfig: txProcessorCfg,
|
TxProcessorConfig: txProcessorCfg,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user