Skip to content

Commit

Permalink
EVM-735: Gas limit estimation is not precise (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal authored Jul 13, 2023
1 parent 1d3b0da commit 6c47248
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
29 changes: 17 additions & 12 deletions consensus/polybft/checkpoint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := &ethgo.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 {
Expand Down Expand Up @@ -181,6 +176,11 @@ func (c *checkpointManager) submitCheckpoint(latestHeader *types.Header, isEndOf
continue
}

txn := &ethgo.Transaction{
To: &checkpointManagerAddr,
From: c.key.Address(),
}

if err = c.encodeAndSendCheckpoint(txn, parentHeader, parentExtra, true); err != nil {
return err
}
Expand All @@ -199,6 +199,11 @@ func (c *checkpointManager) submitCheckpoint(latestHeader *types.Header, isEndOf
}
}

txn := &ethgo.Transaction{
To: &checkpointManagerAddr,
From: c.key.Address(),
}

return c.encodeAndSendCheckpoint(txn, latestHeader, currentExtra, isEndOfEpoch)
}

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion consensus/polybft/consensus_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions txrelayer/txrelayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
DefaultGasLimit = 5242880 // 0x500000
DefaultRPCAddress = "http://127.0.0.1:8545"
numRetries = 1000
gasLimitPercent = 100
gasPricePercent = 20
)

var (
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit 6c47248

Please sign in to comment.