Skip to content

Commit 178b4fe

Browse files
authored
refactor!: create da client and split cache interface (#2878)
Extract some logic from #2797. Those refactors were done to ease force inclusion integration but they can be extracted to be merged sooner
1 parent a465969 commit 178b4fe

31 files changed

+1144
-816
lines changed

.mockery.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ packages:
4848
filename: external/hstore.go
4949
github.com/evstack/ev-node/block/internal/syncing:
5050
interfaces:
51-
daRetriever:
51+
DARetriever:
5252
config:
5353
dir: ./block/internal/syncing
5454
pkgname: syncing
55-
filename: syncer_mock.go
55+
filename: da_retriever_mock.go
5656
p2pHandler:
5757
config:
5858
dir: ./block/internal/syncing

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
- Rename `evm-single` to `evm` and `grpc-single` to `evgrpc` for clarity. [#2839](https://github.com/evstack/ev-node/pull/2839)
15+
- Split cache interface in `CacheManager` and `PendingManager` and create `da` client to easy DA handling. [#2878](https://github.com/evstack/ev-node/pull/2878)
1516

1617
## v1.0.0-beta.10
1718

apps/evm/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
760760
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
761761
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
762762
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
763+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
764+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
763765
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
764766
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
765767
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

apps/grpc/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
654654
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
655655
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
656656
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
657+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
658+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
657659
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
658660
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
659661
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

apps/testapp/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
653653
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
654654
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
655655
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
656+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
657+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
656658
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
657659
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
658660
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

block/components.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ func NewSyncComponents(
144144
return nil, fmt.Errorf("failed to create cache manager: %w", err)
145145
}
146146

147+
daClient := NewDAClient(da, config, logger)
148+
147149
// error channel for critical failures
148150
errorCh := make(chan error, 1)
149151

150152
syncer := syncing.NewSyncer(
151153
store,
152154
exec,
153-
da,
155+
daClient,
154156
cacheManager,
155157
metrics,
156158
config,
@@ -162,8 +164,8 @@ func NewSyncComponents(
162164
errorCh,
163165
)
164166

165-
// Create DA submitter for sync nodes (no signer, only DA inclusion processing)
166-
daSubmitter := submitting.NewDASubmitter(da, config, genesis, blockOpts, metrics, logger)
167+
// Create submitter for sync nodes (no signer, only DA inclusion processing)
168+
daSubmitter := submitting.NewDASubmitter(daClient, config, genesis, blockOpts, metrics, logger)
167169
submitter := submitting.NewSubmitter(
168170
store,
169171
exec,
@@ -243,8 +245,9 @@ func NewAggregatorComponents(
243245
return nil, fmt.Errorf("failed to create reaper: %w", err)
244246
}
245247

246-
// Create DA submitter for aggregator nodes (with signer for submission)
247-
daSubmitter := submitting.NewDASubmitter(da, config, genesis, blockOpts, metrics, logger)
248+
// Create DA client and submitter for aggregator nodes (with signer for submission)
249+
daClient := NewDAClient(da, config, logger)
250+
daSubmitter := submitting.NewDASubmitter(daClient, config, genesis, blockOpts, metrics, logger)
248251
submitter := submitting.NewSubmitter(
249252
store,
250253
exec,

block/internal/cache/manager.go

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ func registerGobTypes() {
4141
})
4242
}
4343

44-
// Manager provides centralized cache management for both executing and syncing components
45-
type Manager interface {
44+
// CacheManager provides thread-safe cache operations for tracking seen blocks
45+
// and DA inclusion status during block execution and syncing.
46+
type CacheManager interface {
4647
// Header operations
4748
IsHeaderSeen(hash string) bool
4849
SetHeaderSeen(hash string, blockHeight uint64)
@@ -62,14 +63,6 @@ type Manager interface {
6263
SetTxSeen(hash string)
6364
CleanupOldTxs(olderThan time.Duration) int
6465

65-
// Pending operations
66-
GetPendingHeaders(ctx context.Context) ([]*types.SignedHeader, error)
67-
GetPendingData(ctx context.Context) ([]*types.SignedData, error)
68-
SetLastSubmittedHeaderHeight(ctx context.Context, height uint64)
69-
SetLastSubmittedDataHeight(ctx context.Context, height uint64)
70-
NumPendingHeaders() uint64
71-
NumPendingData() uint64
72-
7366
// Pending events syncing coordination
7467
GetNextPendingEvent(blockHeight uint64) *common.DAHeightEvent
7568
SetPendingEvent(blockHeight uint64, event *common.DAHeightEvent)
@@ -83,6 +76,22 @@ type Manager interface {
8376
DeleteHeight(blockHeight uint64)
8477
}
8578

79+
// PendingManager provides operations for managing pending headers and data
80+
type PendingManager interface {
81+
GetPendingHeaders(ctx context.Context) ([]*types.SignedHeader, error)
82+
GetPendingData(ctx context.Context) ([]*types.SignedData, error)
83+
SetLastSubmittedHeaderHeight(ctx context.Context, height uint64)
84+
SetLastSubmittedDataHeight(ctx context.Context, height uint64)
85+
NumPendingHeaders() uint64
86+
NumPendingData() uint64
87+
}
88+
89+
// Manager provides centralized cache management for both executing and syncing components
90+
type Manager interface {
91+
CacheManager
92+
PendingManager
93+
}
94+
8695
var _ Manager = (*implementation)(nil)
8796

8897
// implementation provides the concrete implementation of cache Manager
@@ -98,6 +107,59 @@ type implementation struct {
98107
logger zerolog.Logger
99108
}
100109

110+
// NewPendingManager creates a new pending manager instance
111+
func NewPendingManager(store store.Store, logger zerolog.Logger) (PendingManager, error) {
112+
pendingHeaders, err := NewPendingHeaders(store, logger)
113+
if err != nil {
114+
return nil, fmt.Errorf("failed to create pending headers: %w", err)
115+
}
116+
117+
pendingData, err := NewPendingData(store, logger)
118+
if err != nil {
119+
return nil, fmt.Errorf("failed to create pending data: %w", err)
120+
}
121+
122+
return &implementation{
123+
pendingHeaders: pendingHeaders,
124+
pendingData: pendingData,
125+
logger: logger,
126+
}, nil
127+
}
128+
129+
// NewCacheManager creates a new cache manager instance
130+
func NewCacheManager(cfg config.Config, logger zerolog.Logger) (CacheManager, error) {
131+
// Initialize caches
132+
headerCache := NewCache[types.SignedHeader]()
133+
dataCache := NewCache[types.Data]()
134+
txCache := NewCache[struct{}]()
135+
pendingEventsCache := NewCache[common.DAHeightEvent]()
136+
137+
registerGobTypes()
138+
impl := &implementation{
139+
headerCache: headerCache,
140+
dataCache: dataCache,
141+
txCache: txCache,
142+
txTimestamps: new(sync.Map),
143+
pendingEventsCache: pendingEventsCache,
144+
config: cfg,
145+
logger: logger,
146+
}
147+
148+
if cfg.ClearCache {
149+
// Clear the cache from disk
150+
if err := impl.ClearFromDisk(); err != nil {
151+
logger.Warn().Err(err).Msg("failed to clear cache from disk, starting with empty cache")
152+
}
153+
} else {
154+
// Load existing cache from disk
155+
if err := impl.LoadFromDisk(); err != nil {
156+
logger.Warn().Err(err).Msg("failed to load cache from disk, starting with empty cache")
157+
}
158+
}
159+
160+
return impl, nil
161+
}
162+
101163
// NewManager creates a new cache manager instance
102164
func NewManager(cfg config.Config, store store.Store, logger zerolog.Logger) (Manager, error) {
103165
// Initialize caches

0 commit comments

Comments
 (0)