From 1dfee6adc79521c86f5d44aaf68bc35914f05865 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Tue, 24 Dec 2024 09:31:09 +0100 Subject: [PATCH] feat(fraud): add "skip validation height" flag (#1294) --- block/block.go | 10 ++++++---- config/config.go | 2 ++ config/defaults.go | 1 + config/flags.go | 16 ++++++++++------ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/block/block.go b/block/block.go index a1d7b90e5..75f935322 100644 --- a/block/block.go +++ b/block/block.go @@ -14,10 +14,12 @@ import ( // applyBlockWithFraudHandling calls applyBlock and validateBlockBeforeApply with fraud handling. func (m *Manager) applyBlockWithFraudHandling(block *types.Block, commit *types.Commit, blockMetaData types.BlockMetaData) error { validateWithFraud := func() error { - if err := m.validateBlockBeforeApply(block, commit); err != nil { - m.blockCache.Delete(block.Header.Height) - // TODO: can we take an action here such as dropping the peer / reducing their reputation? - return fmt.Errorf("block not valid at height %d, dropping it: err:%w", block.Header.Height, err) + if m.Conf.SkipValidationHeight != block.Header.Height { + if err := m.validateBlockBeforeApply(block, commit); err != nil { + m.blockCache.Delete(block.Header.Height) + // TODO: can we take an action here such as dropping the peer / reducing their reputation? + return fmt.Errorf("block not valid at height %d, dropping it: err:%w", block.Header.Height, err) + } } if err := m.applyBlock(block, commit, blockMetaData); err != nil { diff --git a/config/config.go b/config/config.go index c19c58277..805200b09 100644 --- a/config/config.go +++ b/config/config.go @@ -61,6 +61,8 @@ type BlockManagerConfig struct { BatchSubmitBytes uint64 `mapstructure:"batch_submit_bytes"` // SequencerSetUpdateInterval defines the interval at which to fetch sequencer updates from the settlement layer SequencerSetUpdateInterval time.Duration `mapstructure:"sequencer_update_interval"` + // SkipValidationHeight can be used to skip fraud validation for a specific height (used to bypass backward compatibility issues between versions) + SkipValidationHeight uint64 `mapstructure:"skip_validation_height"` } // GetViperConfig reads configuration parameters from Viper instance. diff --git a/config/defaults.go b/config/defaults.go index b72ef3aac..fc4e4eb70 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -31,6 +31,7 @@ func DefaultConfig(home string) *NodeConfig { MaxSkewTime: 24 * 7 * time.Hour, BatchSubmitBytes: 500000, SequencerSetUpdateInterval: DefaultSequencerSetUpdateInterval, + SkipValidationHeight: 0, }, SettlementLayer: "mock", Instrumentation: &InstrumentationConfig{ diff --git a/config/flags.go b/config/flags.go index 1f1eaf83e..117f4a3ac 100644 --- a/config/flags.go +++ b/config/flags.go @@ -7,11 +7,12 @@ import ( ) const ( - FlagDAConfig = "dymint.da_config" - FlagBlockTime = "dymint.block_time" - FlagMaxIdleTime = "dymint.max_idle_time" - FlagBatchSubmitTime = "dymint.batch_submit_time" - FlagBatchSubmitBytes = "dymint.batch_submit_bytes" + FlagDAConfig = "dymint.da_config" + FlagBlockTime = "dymint.block_time" + FlagMaxIdleTime = "dymint.max_idle_time" + FlagBatchSubmitTime = "dymint.batch_submit_time" + FlagBatchSubmitBytes = "dymint.batch_submit_bytes" + FlagSkipValidationHeight = "dymint.skip_validation_height" ) const ( @@ -54,11 +55,11 @@ func AddNodeFlags(cmd *cobra.Command) { cmd.Flags().String(FlagSLGasFees, def.SettlementConfig.GasFees, "Settlement Layer gas fees") cmd.Flags().String(FlagSLGasPrices, def.SettlementConfig.GasPrices, "Settlement Layer gas prices") cmd.Flags().Uint64(FlagSLGasLimit, def.SettlementConfig.GasLimit, "Settlement Layer batch submit gas limit") - cmd.Flags().String(FlagP2PListenAddress, def.P2PConfig.ListenAddress, "P2P listen address") cmd.Flags().String(FlagP2PBootstrapNodes, def.P2PConfig.BootstrapNodes, "P2P bootstrap nodes") cmd.Flags().Duration(FlagP2PBootstrapRetryTime, def.P2PConfig.BootstrapRetryTime, "P2P bootstrap time") cmd.Flags().Uint64(FlagP2PGossipCacheSize, uint64(def.P2PConfig.GossipSubCacheSize), "P2P Gossiped blocks cache size") //nolint:gosec // GossipSubCacheSize should be always positive + cmd.Flags().Uint64(FlagSkipValidationHeight, def.SkipValidationHeight, "Full-node validation will be skipped for the specified height") } func BindDymintFlags(cmd *cobra.Command, v *viper.Viper) error { @@ -77,6 +78,9 @@ func BindDymintFlags(cmd *cobra.Command, v *viper.Viper) error { if err := v.BindPFlag("batch_submit_bytes", cmd.Flags().Lookup(FlagBatchSubmitBytes)); err != nil { return err } + if err := v.BindPFlag("skip_validation_height", cmd.Flags().Lookup(FlagSkipValidationHeight)); err != nil { + return err + } if err := v.BindPFlag("settlement_layer", cmd.Flags().Lookup(FlagSettlementLayer)); err != nil { return err }