From 91fe83f61ecf4f303a330a18a05dcd5331f3bec6 Mon Sep 17 00:00:00 2001 From: "Jieyi Long (THETA Network)" Date: Tue, 8 Oct 2024 01:58:02 +0800 Subject: [PATCH] Add option to force witness start scan height --- common/config.go | 2 ++ interchain/witness/metachain_witness.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common/config.go b/common/config.go index 1b24ee5..f4d7ec2 100644 --- a/common/config.go +++ b/common/config.go @@ -160,6 +160,7 @@ const ( CfgSubchainMainchainBlockIntervalInSeconds = "subchain.mainchainBlockIntervalInSeconds" CfgSubchainMainchainWitenessStartScanHeight = "subchain.mainchainWitenessStartScanHeight" CfgSubchainSubchainWitenessStartScanHeight = "subchain.subchainWitenessStartScanHeight" + CfgSubchainForceWitnessStartScanHeight = "subchain.forceWitenessStartScanHeight" // CfgSubchainID defines the subchainID CfgSubchainID = "subchain.chainID" @@ -240,6 +241,7 @@ func init() { viper.SetDefault(CfgSubchainEthRpcURL, "http://127.0.0.1:19888") viper.SetDefault(CfgSubchainMainchainWitenessStartScanHeight, -1) viper.SetDefault(CfgSubchainSubchainWitenessStartScanHeight, -1) + viper.SetDefault(CfgSubchainForceWitnessStartScanHeight, false) viper.SetDefault(CfgSubchainID, 360777) } diff --git a/interchain/witness/metachain_witness.go b/interchain/witness/metachain_witness.go index 565e00f..d03b119 100644 --- a/interchain/witness/metachain_witness.go +++ b/interchain/witness/metachain_witness.go @@ -314,7 +314,8 @@ func (mw *MetachainWitness) collectInterChainMessageEventsOnChain(queriedChainID // mw.getBlockScanStartingHeight(queriedChainID) // testing code fromBlock, err := mw.witnessState.getLastQueryedHeightForType(queriedChainID) - if err == store.ErrKeyNotFound { + forceWitnessStartScanHeight := viper.GetBool(scom.CfgSubchainForceWitnessStartScanHeight) + if forceWitnessStartScanHeight || err == store.ErrKeyNotFound { logger.Infof("Seting the initial block scanning height for chain %v", queriedChainID.String()) if queriedChainID.Cmp(mw.mainchainID) == 0 && viper.GetInt(scom.CfgSubchainMainchainWitenessStartScanHeight) >= 0 { // if the start scanning height is specified in the config, use the config value