Skip to content

Commit 387b43e

Browse files
committed
Sync store on new block
1 parent e5aa2c3 commit 387b43e

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

block/internal/executing/executor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ func (e *Executor) produceBlock() error {
413413
if err := batch.Commit(); err != nil {
414414
return fmt.Errorf("failed to commit batch: %w", err)
415415
}
416+
if err := e.store.Sync(context.Background()); err != nil {
417+
return fmt.Errorf("failed to sync store: %w", err)
418+
}
416419

417420
// Update in-memory state after successful commit
418421
e.setLastState(newState)

pkg/store/store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ func (s *DefaultStore) GetMetadata(ctx context.Context, key string) ([]byte, err
190190
return data, nil
191191
}
192192

193+
// Sync flushes the store state to disk
194+
func (s *DefaultStore) Sync(ctx context.Context) error {
195+
return s.db.Sync(ctx, ds.NewKey("/"))
196+
}
197+
193198
// Rollback rolls back block data until the given height from the store.
194199
// When aggregator is true, it will check the latest data included height and prevent rollback further than that.
195200
// NOTE: this function does not rollback metadata. Those should be handled separately if required.

pkg/store/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type Store interface {
4444

4545
// NewBatch creates a new batch for atomic operations.
4646
NewBatch(ctx context.Context) (Batch, error)
47+
48+
// Sync flushes the store state to disk
49+
Sync(ctx context.Context) error
4750
}
4851

4952
type Reader interface {

test/mocks/store.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)