Skip to content

Commit

Permalink
Do not try to prune for genesis block
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 6, 2023
1 parent e53a7df commit ce064cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (*nodeBuilder) initNode(cfg *Config) error {
LogLevel: cfg.Global.LogLvl,
PrunerCfg: state.PrunerConfig{
Enabled: cfg.Global.Pruning,
RetainBlocks: uint32(cfg.Global.RetainBlocks),
RetainBlocks: cfg.Global.RetainBlocks,
},
Telemetry: telemetryMailer,
Metrics: metrics.NewIntervalConfig(cfg.Global.PublishMetrics),
Expand Down
2 changes: 1 addition & 1 deletion dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (nodeBuilder) createStateService(cfg *Config) (*state.Service, error) {
LogLevel: cfg.Log.StateLvl,
PrunerCfg: state.PrunerConfig{
Enabled: cfg.Global.Pruning,
RetainBlocks: uint32(cfg.Global.RetainBlocks),
RetainBlocks: cfg.Global.RetainBlocks,
},
Metrics: metrics.NewIntervalConfig(cfg.Global.PublishMetrics),
}
Expand Down
5 changes: 5 additions & 0 deletions internal/pruner/full/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (p *Pruner) pruneAll(journalDBBatch PutDeleter) (err error) {

func prune(blockNumberToPrune uint32, journalDB Getter, journalDBBatch Deleter,
storageBatch Deleter) (err error) {
if blockNumberToPrune == 0 {
// There is no deletion in the first block, so nothing can be pruned.
return nil
}

blockHashes, err := loadBlockHashes(blockNumberToPrune, journalDB)
if err != nil {
return fmt.Errorf("loading block hashes for block number to prune: %w", err)
Expand Down
6 changes: 6 additions & 0 deletions internal/pruner/full/pruning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ func Test_prune(t *testing.T) {
errWrapped error
errMessage string
}{
"nothing to do for block number 0": {
blockNumberToPrune: 0,
journalDBBuilder: func(ctrl *gomock.Controller) Getter { return nil },
journalBatchBuilder: func(_ *gomock.Controller) Deleter { return nil },
storageBatchBuilder: func(_ *gomock.Controller) Deleter { return nil },
},
"load block hashes error": {
blockNumberToPrune: 1,
journalDBBuilder: func(ctrl *gomock.Controller) Getter {
Expand Down

0 comments on commit ce064cf

Please sign in to comment.