Skip to content

Commit

Permalink
feat(fraud): add "skip validation height" flag (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
srene authored Dec 24, 2024
1 parent bf83422 commit 1dfee6a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
10 changes: 6 additions & 4 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func DefaultConfig(home string) *NodeConfig {
MaxSkewTime: 24 * 7 * time.Hour,
BatchSubmitBytes: 500000,
SequencerSetUpdateInterval: DefaultSequencerSetUpdateInterval,
SkipValidationHeight: 0,
},
SettlementLayer: "mock",
Instrumentation: &InstrumentationConfig{
Expand Down
16 changes: 10 additions & 6 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 1dfee6a

Please sign in to comment.