-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable teleporter-max-gas-limit #621
Changes from 4 commits
107bca1
6cfeb07
50cb709
5cc0762
268aba7
d9040bb
98082dc
3ab8bbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
package vms | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/warp" | ||
"github.com/ava-labs/icm-services/peers" | ||
"github.com/ava-labs/icm-services/relayer/config" | ||
"github.com/ava-labs/icm-services/vms/evm" | ||
"github.com/ethereum/go-ethereum/common" | ||
|
@@ -34,12 +36,17 @@ type DestinationClient interface { | |
|
||
// DestinationBlockchainID returns the ID of the destination chain | ||
DestinationBlockchainID() ids.ID | ||
|
||
// MaxGasLimit returns destination blockchain max gas limit | ||
TeleporterMaxGasLimit() uint64 | ||
} | ||
|
||
func NewDestinationClient(logger logging.Logger, subnetInfo *config.DestinationBlockchain) (DestinationClient, error) { | ||
func NewDestinationClient( | ||
logger logging.Logger, subnetInfo *config.DestinationBlockchain, cChainID ids.ID, | ||
) (DestinationClient, error) { | ||
switch config.ParseVM(subnetInfo.VM) { | ||
case config.EVM: | ||
return evm.NewDestinationClient(logger, subnetInfo) | ||
return evm.NewDestinationClient(logger, subnetInfo, cChainID) | ||
default: | ||
return nil, fmt.Errorf("invalid vm") | ||
} | ||
|
@@ -51,6 +58,16 @@ func CreateDestinationClients( | |
relayerConfig config.Config, | ||
) (map[ids.ID]DestinationClient, error) { | ||
destinationClients := make(map[ids.ID]DestinationClient) | ||
infoClient, err := peers.NewInfoAPI(relayerConfig.InfoAPI) | ||
if err != nil { | ||
logger.Error("Failed to create info API", zap.Error(err)) | ||
return nil, err | ||
} | ||
cChainID, err := infoClient.GetBlockchainID(context.Background(), "C") | ||
if err != nil { | ||
logger.Error("Failed to get C-Chain ID", zap.Error(err)) | ||
return nil, err | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't need this either if we move the C-Chain gas limit validation to the config package, as I suggested in another comment. |
||
for _, subnetInfo := range relayerConfig.DestinationBlockchains { | ||
blockchainID, err := ids.FromString(subnetInfo.BlockchainID) | ||
if err != nil { | ||
|
@@ -69,7 +86,7 @@ func CreateDestinationClients( | |
continue | ||
} | ||
|
||
destinationClient, err := NewDestinationClient(logger, subnetInfo) | ||
destinationClient, err := NewDestinationClient(logger, subnetInfo, cChainID) | ||
if err != nil { | ||
logger.Error( | ||
"Could not create destination client", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package evm | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
"sync" | ||
|
||
|
@@ -44,41 +45,55 @@ type destinationClient struct { | |
signer signer.Signer | ||
evmChainID *big.Int | ||
currentNonce uint64 | ||
teleporterMaxGasLimit uint64 | ||
logger logging.Logger | ||
} | ||
|
||
func NewDestinationClient( | ||
logger logging.Logger, | ||
destinationBlockchain *config.DestinationBlockchain, | ||
cChainID ids.ID, | ||
) (*destinationClient, error) { | ||
// Dial the destination RPC endpoint | ||
client, err := utils.NewEthClientWithConfig( | ||
context.Background(), | ||
destinationBlockchain.RPCEndpoint.BaseURL, | ||
destinationBlockchain.RPCEndpoint.HTTPHeaders, | ||
destinationBlockchain.RPCEndpoint.QueryParams, | ||
) | ||
destinationID, err := ids.FromString(destinationBlockchain.BlockchainID) | ||
if err != nil { | ||
logger.Error( | ||
"Failed to dial rpc endpoint", | ||
"Could not decode destination chain ID from string", | ||
zap.Error(err), | ||
) | ||
return nil, err | ||
} | ||
|
||
destinationID, err := ids.FromString(destinationBlockchain.BlockchainID) | ||
maxGasLimit := destinationBlockchain.TeleporterMaxGasLimit | ||
isCChain := destinationID == cChainID | ||
if isCChain && maxGasLimit > config.DefaultTeleporterMaxGasLimit { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this validation in |
||
logger.Error("C-Chain max-gas-limit exceeded", | ||
zap.Uint64("value", maxGasLimit), | ||
zap.Uint64("cChainMaxValue", config.DefaultTeleporterMaxGasLimit), | ||
) | ||
return nil, fmt.Errorf( | ||
"C-Chain max-gas-limit max gas limit %d exceeded", config.DefaultTeleporterMaxGasLimit, | ||
) | ||
} | ||
|
||
sgnr, err := signer.NewSigner(destinationBlockchain) | ||
if err != nil { | ||
logger.Error( | ||
"Could not decode destination chain ID from string", | ||
"Failed to create signer", | ||
zap.Error(err), | ||
) | ||
return nil, err | ||
} | ||
|
||
sgnr, err := signer.NewSigner(destinationBlockchain) | ||
// Dial the destination RPC endpoint | ||
client, err := utils.NewEthClientWithConfig( | ||
context.Background(), | ||
destinationBlockchain.RPCEndpoint.BaseURL, | ||
destinationBlockchain.RPCEndpoint.HTTPHeaders, | ||
destinationBlockchain.RPCEndpoint.QueryParams, | ||
) | ||
if err != nil { | ||
logger.Error( | ||
"Failed to create signer", | ||
"Failed to dial rpc endpoint", | ||
zap.Error(err), | ||
) | ||
return nil, err | ||
|
@@ -117,6 +132,7 @@ func NewDestinationClient( | |
evmChainID: evmChainID, | ||
currentNonce: nonce, | ||
logger: logger, | ||
teleporterMaxGasLimit: maxGasLimit, | ||
}, nil | ||
} | ||
|
||
|
@@ -210,3 +226,7 @@ func (c *destinationClient) SenderAddress() common.Address { | |
func (c *destinationClient) DestinationBlockchainID() ids.ID { | ||
return c.destinationBlockchainID | ||
} | ||
|
||
func (c *destinationClient) TeleporterMaxGasLimit() uint64 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename |
||
return c.teleporterMaxGasLimit | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the validation is moved to this package as I suggested in another comment, let's not export this const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to make it
unexported
?We use it in two places :
icm-services/messages/teleporter/message_handler_test.go
Line 120 in d9040bb
icm-services/messages/teleporter/message_handler_test.go
Line 236 in d9040bb
It would require to switch these with hardcoded values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That unit test doesn't need the value of
DefaultTeleporterMaxGasLimit
specifically. Instead, we can define a gas limit const in the test itself.Not a huge deal either way, but I'd prefer to not export application variables for unit tests as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I will make the change 👍