Skip to content

Commit ccdd1ee

Browse files
authored
feat(block): add submitting package (#2653)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> -->
1 parent 9bea455 commit ccdd1ee

23 files changed

Lines changed: 1390 additions & 860 deletions

block/internal/cache/bench_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/rs/zerolog"
88

9+
"github.com/evstack/ev-node/block/internal/common"
910
"github.com/evstack/ev-node/pkg/config"
1011
"github.com/evstack/ev-node/pkg/store"
1112
"github.com/evstack/ev-node/types"
@@ -101,7 +102,7 @@ func BenchmarkManager_PendingEventsSnapshot(b *testing.B) {
101102
m := benchNewManager(b, st)
102103
for i := 1; i <= 50_000; i++ {
103104
h, d := types.GetRandomBlock(uint64(i), 1, "bench-events")
104-
m.SetPendingEvent(uint64(i), &DAHeightEvent{Header: h, Data: d, DaHeight: uint64(i)})
105+
m.SetPendingEvent(uint64(i), &common.DAHeightEvent{Header: h, Data: d, DaHeight: uint64(i)})
105106
}
106107
b.ReportAllocs()
107108
b.ResetTimer()

block/internal/cache/manager.go

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/rs/zerolog"
1111

1212
"github.com/evstack/ev-node/block/internal/cache/pending"
13+
"github.com/evstack/ev-node/block/internal/common"
1314
"github.com/evstack/ev-node/pkg/config"
1415
"github.com/evstack/ev-node/pkg/store"
1516
"github.com/evstack/ev-node/types"
@@ -31,20 +32,10 @@ func registerGobTypes() {
3132
gobRegisterOnce.Do(func() {
3233
gob.Register(&types.SignedHeader{})
3334
gob.Register(&types.Data{})
34-
gob.Register(&DAHeightEvent{})
35+
gob.Register(&common.DAHeightEvent{})
3536
})
3637
}
3738

38-
// DAHeightEvent represents a DA event for caching
39-
type DAHeightEvent struct {
40-
Header *types.SignedHeader
41-
Data *types.Data
42-
// DaHeight corresponds to the highest DA included height between the Header and Data.
43-
DaHeight uint64
44-
// HeaderDaIncludedHeight corresponds to the DA height at which the Header was included.
45-
HeaderDaIncludedHeight uint64
46-
}
47-
4839
// Manager provides centralized cache management for both executing and syncing components
4940
type Manager interface {
5041
// Header operations
@@ -73,8 +64,8 @@ type Manager interface {
7364
NumPendingData() uint64
7465

7566
// Pending events for DA coordination
76-
SetPendingEvent(height uint64, event *DAHeightEvent)
77-
GetPendingEvents() map[uint64]*DAHeightEvent
67+
SetPendingEvent(height uint64, event *common.DAHeightEvent)
68+
GetPendingEvents() map[uint64]*common.DAHeightEvent
7869
DeletePendingEvent(height uint64)
7970

8071
// Cleanup operations
@@ -88,7 +79,7 @@ type Manager interface {
8879
type implementation struct {
8980
headerCache *Cache[types.SignedHeader]
9081
dataCache *Cache[types.Data]
91-
pendingEventsCache *Cache[DAHeightEvent]
82+
pendingEventsCache *Cache[common.DAHeightEvent]
9283
pendingHeaders *pending.PendingHeaders
9384
pendingData *pending.PendingData
9485
config config.Config
@@ -100,7 +91,7 @@ func NewManager(cfg config.Config, store store.Store, logger zerolog.Logger) (Ma
10091
// Initialize caches
10192
headerCache := NewCache[types.SignedHeader]()
10293
dataCache := NewCache[types.Data]()
103-
pendingEventsCache := NewCache[DAHeightEvent]()
94+
pendingEventsCache := NewCache[common.DAHeightEvent]()
10495

10596
// Initialize pending managers
10697
pendingHeaders, err := pending.NewPendingHeaders(store, logger)
@@ -228,14 +219,14 @@ func (m *implementation) NumPendingData() uint64 {
228219
}
229220

230221
// Pending events operations
231-
func (m *implementation) SetPendingEvent(height uint64, event *DAHeightEvent) {
222+
func (m *implementation) SetPendingEvent(height uint64, event *common.DAHeightEvent) {
232223
m.pendingEventsCache.SetItem(height, event)
233224
}
234225

235-
func (m *implementation) GetPendingEvents() map[uint64]*DAHeightEvent {
226+
func (m *implementation) GetPendingEvents() map[uint64]*common.DAHeightEvent {
236227

237-
events := make(map[uint64]*DAHeightEvent)
238-
m.pendingEventsCache.RangeByHeight(func(height uint64, event *DAHeightEvent) bool {
228+
events := make(map[uint64]*common.DAHeightEvent)
229+
m.pendingEventsCache.RangeByHeight(func(height uint64, event *common.DAHeightEvent) bool {
239230
events[height] = event
240231
return true
241232
})

block/internal/cache/manager_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212

13+
"github.com/evstack/ev-node/block/internal/common"
1314
"github.com/evstack/ev-node/pkg/config"
1415
"github.com/evstack/ev-node/pkg/store"
1516
"github.com/evstack/ev-node/types"
@@ -73,9 +74,9 @@ func TestManager_PendingEventsCRUD(t *testing.T) {
7374
m, err := NewManager(cfg, st, zerolog.Nop())
7475
require.NoError(t, err)
7576

76-
evt1 := &DAHeightEvent{Header: &types.SignedHeader{Header: types.Header{BaseHeader: types.BaseHeader{Height: 1}}}, DaHeight: 5}
77-
evt3 := &DAHeightEvent{Header: &types.SignedHeader{Header: types.Header{BaseHeader: types.BaseHeader{Height: 3}}}, DaHeight: 7}
78-
evt5 := &DAHeightEvent{Data: &types.Data{Metadata: &types.Metadata{Height: 5}}, DaHeight: 9}
77+
evt1 := &common.DAHeightEvent{Header: &types.SignedHeader{Header: types.Header{BaseHeader: types.BaseHeader{Height: 1}}}, DaHeight: 5}
78+
evt3 := &common.DAHeightEvent{Header: &types.SignedHeader{Header: types.Header{BaseHeader: types.BaseHeader{Height: 3}}}, DaHeight: 7}
79+
evt5 := &common.DAHeightEvent{Data: &types.Data{Metadata: &types.Metadata{Height: 5}}, DaHeight: 9}
7980

8081
m.SetPendingEvent(5, evt5)
8182
m.SetPendingEvent(1, evt1)
@@ -103,7 +104,7 @@ func TestManager_SaveAndLoadFromDisk(t *testing.T) {
103104
// must register for gob before saving
104105
gob.Register(&types.SignedHeader{})
105106
gob.Register(&types.Data{})
106-
gob.Register(&DAHeightEvent{})
107+
gob.Register(&common.DAHeightEvent{})
107108

108109
m1, err := NewManager(cfg, st, zerolog.Nop())
109110
require.NoError(t, err)
@@ -117,7 +118,7 @@ func TestManager_SaveAndLoadFromDisk(t *testing.T) {
117118
m1.SetDataSeen("D2")
118119
m1.SetHeaderDAIncluded("H2", 100)
119120
m1.SetDataDAIncluded("D2", 101)
120-
m1.SetPendingEvent(2, &DAHeightEvent{Header: hdr, Data: dat, DaHeight: 99})
121+
m1.SetPendingEvent(2, &common.DAHeightEvent{Header: hdr, Data: dat, DaHeight: 99})
121122

122123
// persist
123124
err = m1.SaveToDisk()

block/internal/cache/pending/pending_base_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,10 @@ import (
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111

12-
"github.com/evstack/ev-node/pkg/config"
1312
"github.com/evstack/ev-node/pkg/store"
1413
"github.com/evstack/ev-node/types"
1514
)
1615

17-
// helper to make a temp config rooted at t.TempDir()
18-
func tempConfig(t *testing.T) config.Config {
19-
cfg := config.DefaultConfig
20-
cfg.RootDir = t.TempDir()
21-
return cfg
22-
}
23-
2416
// helper to make an in-memory store
2517
func memStore(t *testing.T) store.Store {
2618
ds, err := store.NewDefaultInMemoryKVStore()

0 commit comments

Comments
 (0)