Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pleasew8t committed Dec 9, 2024
1 parent c711b03 commit 8661aea
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
19 changes: 13 additions & 6 deletions node/cmd/transfer-verifier/transfer-verifier-evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var TransferVerifierCmdEvm = &cobra.Command{
var (
// RPC endpoint URL for interacting with an EVM node.
evmRpc *string
// Contract address of the EVM core bridge contract.
// Contract address of the EVM core bridge.
evmCoreContract *string
// Contract address of the token bridge contract.
// Contract address of the EVM token bridge.
evmTokenBridgeContract *string
// Height difference between pruning windows (in blocks).
pruneHeightDelta *uint64
Expand All @@ -34,9 +34,9 @@ var (
// Function to initialize the configuration for the TransferVerifierCmdEvm flags.
func init() {
// default URL connection for anvil
evmRpc = TransferVerifierCmdEvm.Flags().String("ethRPC", "ws://localhost:8545", "Ethereum RPC url")
evmCoreContract = TransferVerifierCmdEvm.Flags().String("ethContract", "", "Ethereum core bridge address for verifying VAAs (required if ethRPC is specified)")
evmTokenBridgeContract = TransferVerifierCmdEvm.Flags().String("tokenContract", "", "token bridge contract deployed on Ethereum")
evmRpc = TransferVerifierCmdEvm.Flags().String("evmRPC", "ws://localhost:8545", "EVM RPC url")
evmCoreContract = TransferVerifierCmdEvm.Flags().String("evmContract", "", "EVM core bridge address for verifying VAAs")
evmTokenBridgeContract = TransferVerifierCmdEvm.Flags().String("tokenContract", "", "EVM token bridge address")

pruneHeightDelta = TransferVerifierCmdEvm.Flags().Uint64("pruneHeightDelta", 10, "The number of blocks for which to retain transaction receipts. Defaults to 10 blocks.")
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func runTransferVerifierEvm(cmd *cobra.Command, args []string) {
}

// Create main configuration for Transfer Verification
transferVerifier := txverifier.NewTransferVerifier(
transferVerifier, err := txverifier.NewTransferVerifier(
ethConnector,
&txverifier.TVAddresses{
CoreBridgeAddr: common.HexToAddress(*evmCoreContract),
Expand All @@ -97,6 +97,10 @@ func runTransferVerifierEvm(cmd *cobra.Command, args []string) {
logger,
)

if err != nil {
logger.Fatal("could not create new transfer verifier", zap.Error(err))
}

// Set-up for main processing loop

// Subscription for LogMessagePublished events
Expand All @@ -109,6 +113,9 @@ func runTransferVerifierEvm(cmd *cobra.Command, args []string) {
// - process the events through the transfer verifier.
for {
select {
case <-ctx.Done():
logger.Info("context cancelled, exiting")
return
case subErr := <-sub.Errors():
logger.Warn("error on subscription", zap.Error(subErr))

Expand Down
9 changes: 7 additions & 2 deletions node/cmd/transfer-verifier/transfer-verifier-sui.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"go.uber.org/zap"
)

const (
INITIAL_EVENT_FETCH_LIMIT = 25
)

// CLI args
var (
suiRPC *string
Expand All @@ -33,7 +37,7 @@ var TransferVerifierCmdSui = &cobra.Command{
// CLI parameters
func init() {
suiRPC = TransferVerifierCmdSui.Flags().String("suiRPC", "", "Sui RPC url")
suiCoreContract = TransferVerifierCmdSui.Flags().String("suiCoreContract", "", "Event to listen to in Sui")
suiCoreContract = TransferVerifierCmdSui.Flags().String("suiCoreContract", "", "Sui core contract address")
suiTokenBridgeEmitter = TransferVerifierCmdSui.Flags().String("suiTokenBridgeEmitter", "", "Token bridge emitter on Sui")
suiTokenBridgeContract = TransferVerifierCmdSui.Flags().String("suiTokenBridgeContract", "", "Token bridge contract on Sui")
suiProcessInitialEvents = TransferVerifierCmdSui.Flags().Bool("suiProcessInitialEvents", false, "Indicate whether the Sui transfer verifier should process the initial events it fetches")
Expand All @@ -58,6 +62,7 @@ func runTransferVerifierSui(cmd *cobra.Command, args []string) {
logger.Debug("Sui core contract", zap.String("address", *suiCoreContract))
logger.Debug("Sui token bridge contract", zap.String("address", *suiTokenBridgeContract))
logger.Debug("token bridge event emitter", zap.String("object id", *suiTokenBridgeEmitter))
logger.Debug("process initial events", zap.Bool("processInitialEvents", *suiProcessInitialEvents))

// Verify CLI parameters
if *suiRPC == "" || *suiCoreContract == "" || *suiTokenBridgeEmitter == "" || *suiTokenBridgeContract == "" {
Expand All @@ -77,7 +82,7 @@ func runTransferVerifierSui(cmd *cobra.Command, args []string) {
suiApiConnection := txverifier.NewSuiApiConnection(*suiRPC)

// Initial event fetching
resp, err := suiApiConnection.QueryEvents(eventFilter, "null", 25, true)
resp, err := suiApiConnection.QueryEvents(eventFilter, "null", INITIAL_EVENT_FETCH_LIMIT, true)
if err != nil {
logger.Fatal("Error in querying initial events", zap.Error(err))
}
Expand Down
21 changes: 14 additions & 7 deletions node/pkg/transfer-verifier/transfer-verifier-evm-structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ var (
// Fixed addresses
var (
// https://etherscan.io/token/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
WETH_ADDRESS = common.HexToAddress("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")
ZERO_ADDRESS = common.BytesToAddress([]byte{0x00})
ZERO_ADDRESS_VAA = VAAAddrFrom(ZERO_ADDRESS)
WETH_ADDRESS = common.HexToAddress("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")
ZERO_ADDRESS = common.BytesToAddress([]byte{0x00})
ZERO_ADDRESS_VAA = VAAAddrFrom(ZERO_ADDRESS)
NATIVE_CHAIN_ID vaa.ChainID = 2
)

// EVM chain constants
const (
// The Wormhole Chain ID for the chain being monitored
NATIVE_CHAIN_ID = 2
// EVM uses 32 bytes for words. Note that vaa.Address is an alias for a slice of 32 bytes
EVM_WORD_LENGTH = 32
// The expected total number of indexed topics for an ERC20 Transfer event
Expand Down Expand Up @@ -113,7 +112,15 @@ type TransferVerifier[E evmClient, C connector] struct {
nativeChainCache map[string]vaa.ChainID
}

func NewTransferVerifier(connector connectors.Connector, tvAddrs *TVAddresses, pruneHeightDelta uint64, logger *zap.Logger) *TransferVerifier[*ethClient.Client, connectors.Connector] {
func NewTransferVerifier(connector connectors.Connector, tvAddrs *TVAddresses, pruneHeightDelta uint64, logger *zap.Logger) (*TransferVerifier[*ethClient.Client, connectors.Connector], error) {
// Retrieve the NATIVE_CHAIN_ID from the connector.
chainId, err := connector.Client().ChainID(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to get chain ID: %w", err)
}

NATIVE_CHAIN_ID = vaa.ChainID(chainId.Uint64())

return &TransferVerifier[*ethClient.Client, connectors.Connector]{
Addresses: tvAddrs,
logger: *logger,
Expand All @@ -126,7 +133,7 @@ func NewTransferVerifier(connector connectors.Connector, tvAddrs *TVAddresses, p
isWrappedCache: make(map[string]bool),
wrappedCache: make(map[string]common.Address),
nativeChainCache: make(map[string]vaa.ChainID),
}
}, nil
}

type connector interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type ObjectChange struct {
}

// Validate the type information of the object change. The following checks are performed:
// - pass the object through a regex that extractts the package ID, coin type, and asset type
// - pass the object through a regex that extracts the package ID, coin type, and asset type
// - ensure that the asset type is wrapped or native
// - ensure that the package IDs match the expected package ID
// - ensure that the coin types match
Expand Down

0 comments on commit 8661aea

Please sign in to comment.