Skip to content

Commit

Permalink
messages/teleporter: teleporter-max-gas-limit checks are done over ea…
Browse files Browse the repository at this point in the history
…ch configured destination_client instead of hardcoded const
  • Loading branch information
najeal committed Jan 9, 2025
1 parent 6cfeb07 commit 50cb709
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 4 additions & 6 deletions messages/teleporter/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ import (
)

const (
// The maximum gas limit that can be specified for a Teleporter message
// Based on the C-Chain 15_000_000 gas limit per block, with other Warp message gas overhead conservatively estimated.
maxTeleporterGasLimit = 12_000_000
defaultBlockAcceptanceTimeout = 30 * time.Second
)

Expand Down Expand Up @@ -165,15 +162,16 @@ func (m *messageHandler) ShouldSendMessage(destinationClient vms.DestinationClie
if err != nil {
return false, fmt.Errorf("failed to calculate Teleporter message ID: %w", err)
}

requiredGasLimit := m.teleporterMessage.RequiredGasLimit.Uint64()
maxGasLimit := destinationClient.TeleporterMaxGasLimit()
// Check if the specified gas limit is below the maximum threshold
if m.teleporterMessage.RequiredGasLimit.Uint64() > maxTeleporterGasLimit {
if requiredGasLimit > maxGasLimit {
m.logger.Info(
"Gas limit exceeds maximum threshold",
zap.String("destinationBlockchainID", destinationBlockchainID.String()),
zap.String("teleporterMessageID", teleporterMessageID.String()),
zap.Uint64("requiredGasLimit", m.teleporterMessage.RequiredGasLimit.Uint64()),
zap.Uint64("maxGasLimit", maxTeleporterGasLimit),
zap.Uint64("maxGasLimit", maxGasLimit),
)
return false, nil
}
Expand Down
3 changes: 2 additions & 1 deletion messages/teleporter/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestShouldSendMessage(t *testing.T) {
require.NoError(t, err)

gasLimitExceededTeleporterMessage := validTeleporterMessage
gasLimitExceededTeleporterMessage.RequiredGasLimit = big.NewInt(maxTeleporterGasLimit + 1)
gasLimitExceededTeleporterMessage.RequiredGasLimit = big.NewInt(config.DefaultTeleporterMaxGasLimit + 1)
gasLimitExceededTeleporterMessageBytes, err := gasLimitExceededTeleporterMessage.Pack()
require.NoError(t, err)

Expand Down Expand Up @@ -233,6 +233,7 @@ func TestShouldSendMessage(t *testing.T) {
SenderAddress().
Return(test.senderAddressResult).
Times(test.senderAddressTimes)
mockClient.EXPECT().TeleporterMaxGasLimit().Return(uint64(config.DefaultTeleporterMaxGasLimit)).AnyTimes()
mockClient.EXPECT().DestinationBlockchainID().Return(destinationBlockchainID).AnyTimes()
if test.messageReceivedCall != nil {
messageReceivedInput := interfaces.CallMsg{
Expand Down

0 comments on commit 50cb709

Please sign in to comment.