Skip to content

Commit

Permalink
save StorageConfiguration in Store
Browse files Browse the repository at this point in the history
  • Loading branch information
ciripel committed Jun 19, 2024
1 parent a9f9c02 commit 0b8691f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewEngine(ctx context.Context, config *configuration.Runtime) (*Engine, err
logger: slog.Default(), // TODO: replace with custom logger
}

go result.fetchAutomatically(config)
go result.fetchAutomatically()

return result, nil
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func (e *Engine) GetLastFetchedCycle() (int64, error) {
return e.store.GetLastFetchedCycle()
}

func (e *Engine) fetchAutomatically(config *configuration.Runtime) {
func (e *Engine) fetchAutomatically() {
go func() {
for {
select {
Expand Down Expand Up @@ -194,7 +194,7 @@ func (e *Engine) fetchAutomatically(config *configuration.Runtime) {
if err = e.FetchCycleDelegationStates(e.ctx, cycle, nil); err != nil {
e.logger.Error("failed to fetch cycle delegation states", "cycle", cycle, "error", err.Error())
}
if err = e.store.PruneDelegationState(cycle, config); err != nil {
if err = e.store.PruneDelegationState(cycle); err != nil {
e.logger.Error("failed to prune cycles out", "error", err.Error())
}
}
Expand Down
12 changes: 7 additions & 5 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
)

type Store struct {
db *gorm.DB
db *gorm.DB
config configuration.StorageConfiguration
}

func NewStore(config *configuration.Runtime) (*Store, error) {
Expand All @@ -38,7 +39,8 @@ func NewStore(config *configuration.Runtime) (*Store, error) {
}
db.AutoMigrate(&StoredDelegationState{})
return &Store{
db: db,
db: db,
config: config.Storage,
}, nil
}

Expand Down Expand Up @@ -66,12 +68,12 @@ func (s *Store) StoreDelegationState(state *StoredDelegationState) error {
return nil
}

func (s *Store) PruneDelegationState(cycle int64, config *configuration.Runtime) error {
if config.Storage.Mode != constants.Rolling {
func (s *Store) PruneDelegationState(cycle int64) error {
if s.config.Mode != constants.Rolling {
return nil
}

prunedCycle := cycle - int64(config.Storage.StoredCycles)
prunedCycle := cycle - int64(s.config.StoredCycles)
state := &StoredDelegationState{}
slog.Debug("pruning delegation states smaller than", "cycle", prunedCycle)
return s.db.Model(&StoredDelegationState{}).Where("cycle < ?", prunedCycle).Delete(state).Error
Expand Down

0 comments on commit 0b8691f

Please sign in to comment.