Skip to content

Commit

Permalink
Merge pull request #133 from ava-labs/specify-block-height-exit
Browse files Browse the repository at this point in the history
Exit if no start block is found
  • Loading branch information
cam-schultz authored Jan 18, 2024
2 parents 7d0c274 + f9b5001 commit 2c071a1
Show file tree
Hide file tree
Showing 15 changed files with 405 additions and 137 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The relayer is configured via a JSON file, the path to which is passed in via th
`"log-level": "debug" | "info" | "warn" | "error" | "fatal" | "panic"`
- The log level for the relayer. Defaults to `info`.

`"network-id": integer`
`"network-id": unsigned integer`
- The ID of the Avalanche network to which the relayer will connect. Defaults to `1` (Mainnet).

`"p-chain-api-url": string`
Expand Down Expand Up @@ -65,7 +65,7 @@ The relayer is configured via a JSON file, the path to which is passed in via th
`"api-node-host": string`
- The host of the source subnet's API node.

`"api-node-port": integer`
`"api-node-port": unsigned integer`
- The port of the source subnet's API node.

`"encrypt-connection": boolean`
Expand All @@ -83,6 +83,9 @@ The relayer is configured via a JSON file, the path to which is passed in via th
`"supported-destinations": []string`
- List of destination subnet IDs that the source subnet supports. If empty, then all destinations are supported.

`"start-block-height": unsigned integer`
- The block height at which to back-process transactions from the source subnet. If the database already contains a later block height for the source subnet, then that will be used instead. Must be non-zero.

`"destination-subnets": []DestinationSubnets`
- The list of destination subnets to support. Each `DestinationSubnet` has the following configuration:

Expand All @@ -98,7 +101,7 @@ The relayer is configured via a JSON file, the path to which is passed in via th
`"api-node-host": string`
- The host of the source subnet's API node.

`"api-node-port": integer`
`"api-node-port": unsigned integer`
- The port of the source subnet's API node.

`"encrypt-connection": boolean`
Expand Down
6 changes: 5 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type SourceSubnet struct {
WSEndpoint string `mapstructure:"ws-endpoint" json:"ws-endpoint"`
MessageContracts map[string]MessageProtocolConfig `mapstructure:"message-contracts" json:"message-contracts"`
SupportedDestinations []string `mapstructure:"supported-destinations" json:"supported-destinations"`
StartBlockHeight uint64 `mapstructure:"start-block-height" json:"start-block-height"`

// convenience field to access the supported destinations after initialization
supportedDestinations set.Set[ids.ID]
Expand Down Expand Up @@ -187,7 +188,7 @@ func (c *Config) Validate() error {
sourceBlockchains := set.NewSet[string](len(c.SourceSubnets))
var sourceSubnetIDs []ids.ID
var sourceBlockchainIDs []ids.ID
for _, s := range c.SourceSubnets {
for i, s := range c.SourceSubnets {
// Validate configuration
if err := s.Validate(&destinationChains); err != nil {
return err
Expand All @@ -210,6 +211,9 @@ func (c *Config) Validate() error {
return fmt.Errorf("invalid subnetID in configuration. error: %v", err)
}
sourceBlockchainIDs = append(sourceBlockchainIDs, blockchainID)

// Write back to the config
c.SourceSubnets[i] = s
}

c.sourceSubnetIDs = sourceSubnetIDs
Expand Down
2 changes: 2 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

//go:generate mockgen -source=$GOFILE -destination=./mocks/mock_database.go -package=mocks

package database

import (
Expand Down
68 changes: 68 additions & 0 deletions database/mocks/mock_database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ func main() {
return
}

// Initialize the global app request network
logger.Info("Initializing app request network")
sourceSubnetIDs, sourceBlockchainIDs := cfg.GetSourceIDs()

// Initialize metrics gathered through prometheus
gatherer, registerer, err := initMetrics()
if err != nil {
Expand All @@ -95,7 +91,17 @@ func main() {
panic(err)
}

network, responseChans, err := peers.NewNetwork(logger, registerer, cfg.NetworkID, sourceSubnetIDs, sourceBlockchainIDs, cfg.PChainAPIURL)
// Initialize the global app request network
logger.Info("Initializing app request network")
sourceSubnetIDs, sourceBlockchainIDs := cfg.GetSourceIDs()

// The app request network generates P2P networking logs that are verbose at the info level.
// Unless the log level is debug or lower, set the network log level to error to avoid spamming the logs.
networkLogLevel := logging.Error
if logLevel <= logging.Debug {
networkLogLevel = logLevel
}
network, responseChans, err := peers.NewNetwork(networkLogLevel, registerer, cfg.NetworkID, sourceSubnetIDs, sourceBlockchainIDs, cfg.PChainAPIURL)
if err != nil {
logger.Error(
"Failed to create app request network",
Expand Down
1 change: 0 additions & 1 deletion messages/mocks/mock_message_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"math/rand"
"os"
"sync"
"time"

Expand Down Expand Up @@ -41,13 +42,22 @@ type AppRequestNetwork struct {

// NewNetwork connects to a peers at the app request level.
func NewNetwork(
logger logging.Logger,
logLevel logging.Level,
registerer prometheus.Registerer,
networkID uint32,
subnetIDs []ids.ID,
blockchainIDs []ids.ID,
APINodeURL string,
) (*AppRequestNetwork, map[ids.ID]chan message.InboundMessage, error) {
logger := logging.NewLogger(
"awm-relayer-p2p",
logging.NewWrappedCore(
logLevel,
os.Stdout,
logging.JSON.ConsoleEncoder(),
),
)

if networkID != constants.MainnetID &&
networkID != constants.FujiID &&
len(APINodeURL) == 0 {
Expand Down
Loading

0 comments on commit 2c071a1

Please sign in to comment.