From b28a3a89a15df4a9f28b4ab1ecaec244171086b8 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Fri, 5 Jan 2024 17:17:13 +0000 Subject: [PATCH] rename startblock cfg option --- config/config.go | 2 +- relayer/relayer.go | 22 +++++++++++----------- tests/basic_relay.go | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/config/config.go b/config/config.go index 6b3d24f6..efd0b480 100644 --- a/config/config.go +++ b/config/config.go @@ -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] diff --git a/relayer/relayer.go b/relayer/relayer.go index 81cec7b3..26c8b9da 100644 --- a/relayer/relayer.go +++ b/relayer/relayer.go @@ -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", @@ -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 @@ -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 diff --git a/tests/basic_relay.go b/tests/basic_relay.go index 7d5c1e25..9569ed5f 100644 --- a/tests/basic_relay.go +++ b/tests/basic_relay.go @@ -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") @@ -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)