From 6c4724829e3cdf766f670b55d75111e9aff721c7 Mon Sep 17 00:00:00 2001 From: Goran Rojovic <100121253+goran-ethernal@users.noreply.github.com> Date: Thu, 13 Jul 2023 13:11:25 +0200 Subject: [PATCH] EVM-735: Gas limit estimation is not precise (#1718) --- consensus/polybft/checkpoint_manager.go | 29 +++++++++++++++---------- consensus/polybft/consensus_runtime.go | 4 +++- txrelayer/txrelayer.go | 6 +++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/consensus/polybft/checkpoint_manager.go b/consensus/polybft/checkpoint_manager.go index bf69f93d05..83474526e0 100644 --- a/consensus/polybft/checkpoint_manager.go +++ b/consensus/polybft/checkpoint_manager.go @@ -133,18 +133,13 @@ func (c *checkpointManager) submitCheckpoint(latestHeader *types.Header, isEndOf "latest checkpoint block", lastCheckpointBlockNumber, "checkpoint block", latestHeader.Number) - checkpointManagerAddr := ethgo.Address(c.checkpointManagerAddr) - txn := ðgo.Transaction{ - To: &checkpointManagerAddr, - From: c.key.Address(), - } - initialBlockNumber := lastCheckpointBlockNumber + 1 - var ( - parentExtra *Extra - parentHeader *types.Header - currentExtra *Extra - found bool + checkpointManagerAddr = ethgo.Address(c.checkpointManagerAddr) + initialBlockNumber = lastCheckpointBlockNumber + 1 + parentExtra *Extra + parentHeader *types.Header + currentExtra *Extra + found bool ) if initialBlockNumber < latestHeader.Number { @@ -181,6 +176,11 @@ func (c *checkpointManager) submitCheckpoint(latestHeader *types.Header, isEndOf continue } + txn := ðgo.Transaction{ + To: &checkpointManagerAddr, + From: c.key.Address(), + } + if err = c.encodeAndSendCheckpoint(txn, parentHeader, parentExtra, true); err != nil { return err } @@ -199,6 +199,11 @@ func (c *checkpointManager) submitCheckpoint(latestHeader *types.Header, isEndOf } } + txn := ðgo.Transaction{ + To: &checkpointManagerAddr, + From: c.key.Address(), + } + return c.encodeAndSendCheckpoint(txn, latestHeader, currentExtra, isEndOfEpoch) } @@ -237,7 +242,7 @@ func (c *checkpointManager) encodeAndSendCheckpoint(txn *ethgo.Transaction, // update checkpoint block number metrics metrics.SetGauge([]string{"bridge", "checkpoint_block_number"}, float32(header.Number)) - c.logger.Debug("send checkpoint txn success", "block number", header.Number) + c.logger.Debug("send checkpoint txn success", "block number", header.Number, "gasUsed", receipt.GasUsed) return nil } diff --git a/consensus/polybft/consensus_runtime.go b/consensus/polybft/consensus_runtime.go index 8c5770fc9d..a52e3b4f8a 100644 --- a/consensus/polybft/consensus_runtime.go +++ b/consensus/polybft/consensus_runtime.go @@ -196,7 +196,9 @@ func (c *consensusRuntime) initStateSyncManager(logger hcf.Logger) error { func (c *consensusRuntime) initCheckpointManager(logger hcf.Logger) error { if c.IsBridgeEnabled() { // enable checkpoint manager - txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(c.config.PolyBFTConfig.Bridge.JSONRPCEndpoint)) + txRelayer, err := txrelayer.NewTxRelayer( + txrelayer.WithIPAddress(c.config.PolyBFTConfig.Bridge.JSONRPCEndpoint), + txrelayer.WithWriter(logger.StandardWriter(&hcf.StandardLoggerOptions{}))) if err != nil { return err } diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index aa4fe1983f..8c233999b7 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -18,6 +18,8 @@ const ( DefaultGasLimit = 5242880 // 0x500000 DefaultRPCAddress = "http://127.0.0.1:8545" numRetries = 1000 + gasLimitPercent = 100 + gasPricePercent = 20 ) var ( @@ -116,7 +118,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. return ethgo.ZeroHash, err } - txn.GasPrice = gasPrice + txn.GasPrice = gasPrice + (gasPrice * gasPricePercent / 100) } if txn.Gas == 0 { @@ -125,7 +127,7 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. return ethgo.ZeroHash, err } - txn.Gas = gasLimit + txn.Gas = gasLimit + (gasLimit * gasLimitPercent / 100) } chainID, err := t.client.Eth().ChainID()