Skip to content

Commit

Permalink
Merge branch 'main' into signature-aggregation-api-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA authored Aug 16, 2024
2 parents aa631b6 + a49bb59 commit fb73eea
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 74 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Setup

To start developing on AWM Relayer, you'll need Golang v1.21.13.
To start developing on AWM Relayer, you'll need Golang v1.22.6.

## Issues

Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ See the [Building](#building) section for instructions on how to build the relay

## Requirements

[buf](github.com/bufbuild/buf/) is required to rebuild protobuf definitions if changes are made to any `.proto` files. See [Generate Protobuf Files](#generate-protobuf-files) for more information.

### System Requirements

- Ubuntu 22.04 or later
Expand Down Expand Up @@ -101,7 +103,7 @@ awm-relayer --help Display awm-relayer usag

### Building

Before building, be sure to install Go, which is required even if you're just building the Docker image. You'll also need to install [buf](github.com/bufbuild/buf/).
Before building, be sure to install Go, which is required even if you're just building the Docker image.

Build the relayer by running the script:

Expand Down Expand Up @@ -430,3 +432,19 @@ The E2E tests use the `TeleporterMessenger` contract deployment transaction spec
```bash
go generate ./...
```

### Generate Protobuf Files

[buf](github.com/bufbuild/buf/) is used to generate protobuf definitions for communication with the [Decider service](https://github.com/ava-labs/awm-relayer/blob/main/proto/decider/decider.proto). If you change any of the protobuf definitions you will have to regenerate the `.go` files. To generate these files, run the following command at the root of the project:

```bash
./scripts/protobuf_codegen.sh
```

### Generate Abi Bindings

[subnet-evm](github.com/ava-labs/subnet-evm/cmd/abigen/) is used to generate abi binding `.go` files for solidity contracts. If you change any of the smart contracts, you will have to update the abi bindings. To generate these files, run the following command at the root of the project:

```bash
./scripts/abi_bindings.sh
```
6 changes: 2 additions & 4 deletions database/json_file_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ func TestConcurrentWriteReadSingleChain(t *testing.T) {
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
idx := i
go func() {
defer wg.Done()
testWrite(jsonStorage, relayerIDs[0], uint64(idx))
testWrite(jsonStorage, relayerIDs[0], uint64(i))
}()
}
wg.Wait()
Expand Down Expand Up @@ -94,10 +93,9 @@ func TestConcurrentWriteReadMultipleChains(t *testing.T) {
wg := sync.WaitGroup{}
for i := 0; i < 3; i++ {
wg.Add(1)
index := i
go func() {
defer wg.Done()
testWrite(jsonStorage, relayerIDs[index], uint64(index))
testWrite(jsonStorage, relayerIDs[i], uint64(i))
}()
}
wg.Wait()
Expand Down
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/ava-labs/awm-relayer

go 1.21.13
go 1.22.6

require (
github.com/ava-labs/avalanchego v1.11.10
github.com/ava-labs/coreth v0.13.7
github.com/ava-labs/subnet-evm v0.6.8
github.com/ava-labs/teleporter v1.0.3
github.com/ava-labs/teleporter v1.0.4
github.com/aws/aws-sdk-go-v2 v1.30.3
github.com/aws/aws-sdk-go-v2/config v1.27.9
github.com/aws/aws-sdk-go-v2/service/kms v1.35.3
Expand All @@ -16,7 +16,7 @@ require (
github.com/onsi/gomega v1.34.1
github.com/pingcap/errors v0.11.4
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_golang v1.20.0
github.com/redis/go-redis/v9 v9.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
Expand Down Expand Up @@ -74,7 +74,7 @@ require (
github.com/huin/goupnp v1.3.0 // indirect
github.com/jackpal/gateway v1.0.6 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand All @@ -83,6 +83,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
Expand Down Expand Up @@ -133,9 +134,9 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pires/go-proxyproto v0.6.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
Expand Down
26 changes: 14 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/ava-labs/coreth v0.13.7 h1:k8T9u/ROifl8f7oXjHRc1KvSISRl9txvy7gGVmHEz6
github.com/ava-labs/coreth v0.13.7/go.mod h1:tXDujonxXFOF6oK5HS2EmgtSXJK3Gy6RpZxb5WzR9rM=
github.com/ava-labs/subnet-evm v0.6.8 h1:IrHGajBYWs692YIYdd5J0oVWWt88Q/XAZQq/dOtkHFw=
github.com/ava-labs/subnet-evm v0.6.8/go.mod h1:qt8DXyGm40CY9yffNOe1+4yUyL9mD3v5RPWqAuGj5u4=
github.com/ava-labs/teleporter v1.0.3 h1:5Kwso1yk5dtuIg7356MF+cJFRFge8nvun/JK0MDAUAM=
github.com/ava-labs/teleporter v1.0.3/go.mod h1:h8wp8x7531OLeyQUzC2M20S6AVXSuj598Hmo8QSUVOM=
github.com/ava-labs/teleporter v1.0.4 h1:+OAS3YyPc/LijR29qu3EqU6xAnQnjOgf4EtDlCMcDsc=
github.com/ava-labs/teleporter v1.0.4/go.mod h1:bUiOSIGjFktkYg01XDjeaZdgLEx0ZpUDfJXI6Z0rHY8=
github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=
github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc=
github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg=
Expand Down Expand Up @@ -414,8 +414,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw=
github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -472,6 +472,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
Expand Down Expand Up @@ -516,15 +518,15 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_golang v1.20.0 h1:jBzTZ7B099Rg24tny+qngoynol8LtVYlA2bqx3vEloI=
github.com/prometheus/client_golang v1.20.0/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
Expand Down
52 changes: 33 additions & 19 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ func main() {
*sourceBlockchain,
sourceClients[sourceBlockchain.GetBlockchainID()],
relayerHealth[sourceBlockchain.GetBlockchainID()],
cfg.ProcessMissedBlocks,
minHeights[sourceBlockchain.GetBlockchainID()],
messageCoordinator,
)
Expand Down Expand Up @@ -432,27 +431,42 @@ func createApplicationRelayersForSourceChain(
)
applicationRelayers := make(map[common.Hash]*relayer.ApplicationRelayer)

// Each ApplicationRelayer determines its starting height based on the database state.
// Each ApplicationRelayer determines its starting height based on the configuration and database state.
// The Listener begins processing messages starting from the minimum height across all the ApplicationRelayers
minHeight := uint64(0)
for _, relayerID := range database.GetSourceBlockchainRelayerIDs(&sourceBlockchain) {
height, err := database.CalculateStartingBlockHeight(
logger,
db,
relayerID,
sourceBlockchain.ProcessHistoricalBlocksFromHeight,
currentHeight,
// If catch up is disabled, the first block the ApplicationRelayer processes is the next block after the current height
var height, minHeight uint64
if !cfg.ProcessMissedBlocks {
logger.Info(
"processed-missed-blocks set to false, starting processing from chain head",
zap.String("blockchainID", sourceBlockchain.GetBlockchainID().String()),
)
if err != nil {
logger.Error(
"Failed to calculate starting block height",
zap.String("relayerID", relayerID.ID.String()),
zap.Error(err),
height = currentHeight + 1
minHeight = height
}
for _, relayerID := range database.GetSourceBlockchainRelayerIDs(&sourceBlockchain) {
// Calculate the catch-up starting block height, and update the min height if necessary
if cfg.ProcessMissedBlocks {
var err error
height, err = database.CalculateStartingBlockHeight(
logger,
db,
relayerID,
sourceBlockchain.ProcessHistoricalBlocksFromHeight,
currentHeight,
)
return nil, 0, err
}
if minHeight == 0 || height < minHeight {
minHeight = height
if err != nil {
logger.Error(
"Failed to calculate starting block height",
zap.String("relayerID", relayerID.ID.String()),
zap.Error(err),
)
return nil, 0, err
}

// Update the min height. This is the height that the listener will start processing from
if minHeight == 0 || height < minHeight {
minHeight = height
}
}

checkpointManager := checkpoint.NewCheckpointManager(
Expand Down
23 changes: 21 additions & 2 deletions messages/teleporter/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
"google.golang.org/grpc"
)

// 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.
const maxTeleporterGasLimit = 12_000_000

type factory struct {
messageConfig Config
protocolAddress common.Address
Expand Down Expand Up @@ -159,6 +163,19 @@ func (m *messageHandler) ShouldSendMessage(destinationClient vms.DestinationClie
return false, fmt.Errorf("failed to calculate Teleporter message ID: %w", err)
}

// Check if the specified gas limit is below the maximum threshold
if m.teleporterMessage.RequiredGasLimit.Uint64() > maxTeleporterGasLimit {
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),
)
return false, nil
}

// Check if the relayer is allowed to deliver this message
senderAddress := destinationClient.SenderAddress()
if !isAllowedRelayer(m.teleporterMessage.AllowedRelayerAddresses, senderAddress) {
m.logger.Info(
Expand Down Expand Up @@ -191,6 +208,7 @@ func (m *messageHandler) ShouldSendMessage(destinationClient vms.DestinationClie
)
return false, nil
}

// Dispatch to the external decider service. If the service is unavailable or returns
// an error, then use the decision that has already been made, i.e. return true
decision, err := m.getShouldSendMessageFromDecider()
Expand Down Expand Up @@ -388,7 +406,8 @@ func (f *factory) parseTeleporterMessage(
)
return nil, err
}
teleporterMessage, err := teleportermessenger.UnpackTeleporterMessage(addressedPayload.Payload)
var teleporterMessage teleportermessenger.TeleporterMessage
err = teleporterMessage.Unpack(addressedPayload.Payload)
if err != nil {
f.logger.Error(
"Failed unpacking teleporter message.",
Expand All @@ -397,7 +416,7 @@ func (f *factory) parseTeleporterMessage(
return nil, err
}

return teleporterMessage, nil
return &teleporterMessage, nil
}

// getTeleporterMessenger returns the Teleporter messenger instance for the destination chain.
Expand Down
26 changes: 25 additions & 1 deletion messages/teleporter/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func init() {
}

func TestShouldSendMessage(t *testing.T) {
validMessageBytes, err := teleportermessenger.PackTeleporterMessage(validTeleporterMessage)
validMessageBytes, err := validTeleporterMessage.Pack()
require.NoError(t, err)

validAddressedCall, err := warpPayload.NewAddressedCall(
Expand Down Expand Up @@ -116,6 +116,24 @@ func TestShouldSendMessage(t *testing.T) {
)
require.NoError(t, err)

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

gasLimitExceededAddressedCall, err := warpPayload.NewAddressedCall(
messageProtocolAddress.Bytes(),
gasLimitExceededTeleporterMessageBytes,
)
require.NoError(t, err)

gasLimitExceededWarpUnsignedMessage, err := warp.NewUnsignedMessage(
0,
sourceBlockchainID,
gasLimitExceededAddressedCall.Bytes(),
)
require.NoError(t, err)

testCases := []struct {
name string
destinationBlockchainID ids.ID
Expand Down Expand Up @@ -177,6 +195,12 @@ func TestShouldSendMessage(t *testing.T) {
},
expectedResult: false,
},
{
name: "gas limit exceeded",
destinationBlockchainID: destinationBlockchainID,
warpUnsignedMessage: gasLimitExceededWarpUnsignedMessage,
expectedResult: false,
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewNetwork(
cfg Config,
) (*AppRequestNetwork, error) {
logger := logging.NewLogger(
"awm-relayer-p2p",
"p2p-network",
logging.NewWrappedCore(
logLevel,
os.Stdout,
Expand Down
5 changes: 1 addition & 4 deletions relayer/application_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,8 @@ func (r *ApplicationRelayer) ProcessHeight(
) {
var eg errgroup.Group
for _, handler := range handlers {
// Copy the loop variable to a local variable to avoid the loop variable being captured by the
// goroutine. Once we upgrade to Go 1.22, we can use the loop variable directly in the goroutine.
h := handler
eg.Go(func() error {
_, err := r.ProcessMessage(h)
_, err := r.ProcessMessage(handler)
return err
})
}
Expand Down
Loading

0 comments on commit fb73eea

Please sign in to comment.