Skip to content

Commit

Permalink
rename startblock cfg option
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Jan 5, 2024
1 parent 39dd35b commit b28a3a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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"`
CatchUpBlockHeight uint64 `mapstructure:"catch-up-block-height" json:"catch-up-block-height"`
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
22 changes: 11 additions & 11 deletions relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ func NewRelayer(
}

if shouldProcessMissedBlocks {
// If CatchUpBlockHeight is not set in the config, then we process from height 0
catchUpHeight := big.NewInt(0).SetUint64(sourceSubnetInfo.CatchUpBlockHeight)
err = r.processMissedBlocks(sub, catchUpHeight)
// If StartBlockHeight is not set in the config, then we process from height 0
startHeight := big.NewInt(0).SetUint64(sourceSubnetInfo.StartBlockHeight)
err = r.processMissedBlocks(sub, startHeight)
if err != nil {
logger.Error(
"Failed to process historical blocks mined during relayer downtime",
Expand All @@ -162,7 +162,7 @@ func NewRelayer(

func (r *Relayer) processMissedBlocks(
sub vms.Subscriber,
catchUpBlockHeight *big.Int,
startBlockHeight *big.Int,
) error {
// Attempt to get the latest processed block height from the database.
// Note that the retrieved latest processed block may have already been partially (or fully) processed by the relayer on a previous run. When
Expand All @@ -172,23 +172,23 @@ func (r *Relayer) processMissedBlocks(

// First, determine the height to process from. There are two cases:
// 1) The database contains the latest processed block data for the chain
// - In this case, we process from the maximum of the latest processed block and the catch up block height to the latest block
// - In this case, we process from the maximum of the latest processed block and the configured start block height to the latest block
// 2) The database has been configured for the chain, but does not contain the latest processed block data
// - In this case, if a catch up block height is provided, we process from the catch up block height to the latest block
// - In this case, if a start block height is provided, we process from the start block height to the latest block
// - Otherwise, we save the current block height in the database, but do not process any historical warp logs
var height *big.Int = nil
if err == nil {
// Use the max of the latest processed block and the catch up block height
// Use the max of the latest processed block and the start block height
latestProcessedBlock, success := new(big.Int).SetString(string(latestProcessedBlockData), 10)
if !success {
r.logger.Error("failed to convert latest block to big.Int", zap.Error(err))
return err
}
height = utils.MaxBigInt(latestProcessedBlock, catchUpBlockHeight)
height = utils.MaxBigInt(latestProcessedBlock, startBlockHeight)
} else if errors.Is(err, database.ErrChainNotFound) || errors.Is(err, database.ErrKeyNotFound) {
// If the database does not contain the latest processed block data, then we check if a catch up block height is provided.
if catchUpBlockHeight != nil {
height = catchUpBlockHeight
// If the database does not contain the latest processed block data, then we check if a start block height is provided.
if startBlockHeight != nil {
height = startBlockHeight
}
} else {
// Otherwise, we've encountered an unknown database error
Expand Down
8 changes: 4 additions & 4 deletions tests/basic_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ func BasicRelay(network interfaces.LocalNetwork) {
_ = relayerCmd.Wait()

//
// Set CatchUpBlockHeight in config
// Set StartBlockHeight in config
//
log.Info("Test Setting CatchUpBlockHeight in config")
log.Info("Test Setting StartBlockHeight in config")

// Send three Teleporter messages from subnet A to subnet B
log.Info("Sending three Teleporter messages from subnet A to subnet B")
Expand All @@ -260,10 +260,10 @@ func BasicRelay(network interfaces.LocalNetwork) {

// Configure the relayer such that it will only process the last of the three messages sent above.
// The relayer DB stores the height of the block *before* the first message, so by setting the
// CatchUpBlockHeight to the block height of the *third* message, we expect the relayer to skip
// StartBlockHeight to the block height of the *third* message, we expect the relayer to skip
// the first two messages on startup, but process the third.
modifiedRelayerConfig := relayerConfig
modifiedRelayerConfig.SourceSubnets[0].CatchUpBlockHeight = currHeight
modifiedRelayerConfig.SourceSubnets[0].StartBlockHeight = currHeight
modifiedRelayerConfig.ProcessMissedBlocks = true
relayerConfigPath = writeRelayerConfig(modifiedRelayerConfig)

Expand Down

0 comments on commit b28a3a8

Please sign in to comment.