Skip to content

Commit f04b887

Browse files
tac0turtletac0turtle
andauthored
chore: remove DAClient (#2221)
<!-- 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 This pr aims to simplify the amount of abstractions by removing DAclient as we are only supporting the da interface. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Simplified and unified Data Availability (DA) client usage by removing intermediate client wrappers and relying directly on the DA interface. - Centralized DA submission and retrieval logic into helper functions for consistent error handling and status reporting. - Removed blob size management and retry adjustments from submission logic, delegating these to the DA implementation. - Updated node, sequencer, and block manager initialization and configuration to use the updated DA interface. - Replaced namespace handling with a placeholder in proof verification to simplify DA interactions. - **Bug Fixes** - Improved error handling and logging for DA operations with more precise status codes and messages. - **Tests** - Updated and expanded test suites to align with the new DA interface, including concurrency and error scenario coverage. - **Chores** - Removed obsolete DA client implementation files and related mocks. - Cleaned up dependencies, import paths, and unused imports across modules. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: tac0turtle <you@example.com>
1 parent dcb40d1 commit f04b887

42 files changed

Lines changed: 1401 additions & 1674 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎block/aggregation_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ func TestAggregationLoop_Normal_BasicInterval(t *testing.T) {
3434

3535
mockExec := mocks.NewExecutor(t)
3636
mockSeq := mocks.NewSequencer(t)
37-
mockDAC := mocks.NewClient(t)
37+
mockDAC := mocks.NewDA(t)
3838
logger := log.NewTestLogger(t)
3939

4040
m := &Manager{
4141
store: mockStore,
4242
exec: mockExec,
4343
sequencer: mockSeq,
44-
dalc: mockDAC,
44+
da: mockDAC,
4545
logger: logger,
4646
config: config.Config{
4747
Node: config.NodeConfig{
@@ -129,7 +129,7 @@ func TestAggregationLoop_Normal_PublishBlockError(t *testing.T) {
129129

130130
mockExec := mocks.NewExecutor(t)
131131
mockSeq := mocks.NewSequencer(t)
132-
mockDAC := mocks.NewClient(t)
132+
mockDAC := mocks.NewDA(t)
133133

134134
mockLogger := log.NewTestLogger(t)
135135

@@ -138,7 +138,7 @@ func TestAggregationLoop_Normal_PublishBlockError(t *testing.T) {
138138
store: mockStore,
139139
exec: mockExec,
140140
sequencer: mockSeq,
141-
dalc: mockDAC,
141+
da: mockDAC,
142142
logger: mockLogger,
143143
config: config.Config{
144144
Node: config.NodeConfig{

‎block/manager.go‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ const (
4040
// defaultMempoolTTL is the number of blocks until transaction is dropped from mempool
4141
defaultMempoolTTL = 25
4242

43-
// blockProtocolOverhead is the protocol overhead when marshaling the block to blob
44-
// see: https://gist.github.com/tuxcanfly/80892dde9cdbe89bfb57a6cb3c27bae2
45-
blockProtocolOverhead = 1 << 16
46-
4743
// maxSubmitAttempts defines how many times Rollkit will re-try to publish block to DA layer.
4844
// This is temporary solution. It will be removed in future versions.
4945
maxSubmitAttempts = 30
@@ -142,7 +138,7 @@ type Manager struct {
142138
// daIncludedHeight is rollup height at which all blocks have been included
143139
// in the DA
144140
daIncludedHeight atomic.Uint64
145-
dalc coreda.Client
141+
da coreda.DA
146142
gasPrice float64
147143
gasMultiplier float64
148144

@@ -252,7 +248,7 @@ func NewManager(
252248
store store.Store,
253249
exec coreexecutor.Executor,
254250
sequencer coresequencer.Sequencer,
255-
dalc coreda.Client,
251+
da coreda.DA,
256252
logger log.Logger,
257253
headerStore goheader.Store[*types.SignedHeader],
258254
dataStore goheader.Store[*types.Data],
@@ -295,15 +291,6 @@ func NewManager(
295291
config.DA.MempoolTTL = defaultMempoolTTL
296292
}
297293

298-
maxBlobSize, err := dalc.MaxBlobSize(ctx)
299-
if err != nil {
300-
return nil, err
301-
}
302-
// allow buffer for the block header and protocol encoding
303-
// TODO: why is this needed?
304-
//nolint:ineffassign // This assignment is needed
305-
maxBlobSize -= blockProtocolOverhead
306-
307294
pendingHeaders, err := NewPendingHeaders(store, logger)
308295
if err != nil {
309296
return nil, err
@@ -329,7 +316,6 @@ func NewManager(
329316
genesis: genesis,
330317
lastState: s,
331318
store: store,
332-
dalc: dalc,
333319
daHeight: &daH,
334320
// channels are buffered to avoid blocking on input/output operations, buffer sizes are arbitrary
335321
HeaderCh: make(chan *types.SignedHeader, channelLength),
@@ -351,6 +337,7 @@ func NewManager(
351337
metrics: seqMetrics,
352338
sequencer: sequencer,
353339
exec: exec,
340+
da: da,
354341
gasPrice: gasPrice,
355342
gasMultiplier: gasMultiplier,
356343
}
@@ -360,11 +347,6 @@ func NewManager(
360347
return agg, nil
361348
}
362349

363-
// DALCInitialized returns true if DALC is initialized.
364-
func (m *Manager) DALCInitialized() bool {
365-
return m.dalc != nil
366-
}
367-
368350
// PendingHeaders returns the pending headers.
369351
func (m *Manager) PendingHeaders() *PendingHeaders {
370352
return m.pendingHeaders

‎block/manager_test.go‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func WithinDuration(t *testing.T, expected, actual, tolerance time.Duration) boo
3838
}
3939

4040
// Returns a minimalistic block manager using a mock DA Client
41-
func getManager(t *testing.T, dac da.Client, gasPrice float64, gasMultiplier float64) *Manager {
41+
func getManager(t *testing.T, da da.DA, gasPrice float64, gasMultiplier float64) *Manager {
4242
logger := log.NewTestLogger(t)
4343
m := &Manager{
44-
dalc: dac,
44+
da: da,
4545
headerCache: cache.NewCache[types.SignedHeader](),
4646
logger: logger,
4747
gasPrice: gasPrice,
@@ -143,8 +143,8 @@ func TestInitialStateUnexpectedHigherGenesis(t *testing.T) {
143143

144144
func TestSignVerifySignature(t *testing.T) {
145145
require := require.New(t)
146-
mockDAC := mocks.NewClient(t) // Use mock DA Client
147-
m := getManager(t, mockDAC, -1, -1) // Pass mock DA Client
146+
mockDAC := mocks.NewDA(t)
147+
m := getManager(t, mockDAC, -1, -1)
148148
payload := []byte("test")
149149
privKey, _, err := crypto.GenerateKeyPair(crypto.Ed25519, 256)
150150
require.NoError(err)
@@ -194,8 +194,8 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase1(t *testing.T) {
194194
require := require.New(t)
195195
ctx := context.Background()
196196

197-
mockDA := mocks.NewClient(t) // Use mock DA Client
198-
m := getManager(t, mockDA, -1, -1) // Pass mock DA Client
197+
mockDA := mocks.NewDA(t)
198+
m := getManager(t, mockDA, -1, -1)
199199

200200
header1, data1 := types.GetRandomBlock(uint64(1), 5, chainID)
201201
header2, data2 := types.GetRandomBlock(uint64(2), 5, chainID)
@@ -209,8 +209,6 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase1(t *testing.T) {
209209
store.On("GetBlockData", mock.Anything, uint64(3)).Return(header3, data3, nil)
210210
store.On("Height", mock.Anything).Return(uint64(3), nil)
211211

212-
mockDA.On("MaxBlobSize", mock.Anything).Return(uint64(100000), nil).Once()
213-
214212
m.store = store
215213

216214
var err error
@@ -231,15 +229,15 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase2(t *testing.T) {
231229
require := require.New(t)
232230
ctx := context.Background()
233231

234-
mockDA := mocks.NewClient(t) // Use mock DA Client
235-
m := getManager(t, mockDA, -1, -1) // Pass mock DA Client
232+
mockDA := mocks.NewDA(t)
233+
m := getManager(t, mockDA, -1, -1)
236234

237235
header1, data1 := types.GetRandomBlock(uint64(1), 5, chainID)
238236
header2, data2 := types.GetRandomBlock(uint64(2), 5, chainID)
239237
header3, data3 := types.GetRandomBlock(uint64(3), 5, chainID)
240238

241239
store := mocks.NewStore(t)
242-
invalidateBlockHeader(header3) // C fails marshal
240+
invalidateBlockHeader(header3)
243241
store.On("GetMetadata", mock.Anything, LastSubmittedHeightKey).Return(nil, ds.ErrNotFound)
244242
store.On("GetBlockData", mock.Anything, uint64(1)).Return(header1, data1, nil)
245243
store.On("GetBlockData", mock.Anything, uint64(2)).Return(header2, data2, nil)
@@ -248,14 +246,11 @@ func Test_submitBlocksToDA_BlockMarshalErrorCase2(t *testing.T) {
248246

249247
m.store = store
250248

251-
// Expect MaxBlobSize call (likely happens before marshalling loop)
252-
mockDA.On("MaxBlobSize", mock.Anything).Return(uint64(100000), nil).Once()
253-
254249
var err error
255250
m.pendingHeaders, err = NewPendingHeaders(store, m.logger)
256251
require.NoError(err)
257252
err = m.submitHeadersToDA(ctx)
258-
assert.ErrorContains(err, "failed to transform header to proto") // Error from C is expected
253+
assert.ErrorContains(err, "failed to transform header to proto")
259254
blocks, err := m.pendingHeaders.getPendingHeaders(ctx)
260255
assert.NoError(err)
261256
// Expect all blocks to remain pending because the batch submission was halted

‎block/retriever.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (m *Manager) fetchHeaders(ctx context.Context, daHeight uint64) (coreda.Res
161161
ctx, cancel := context.WithTimeout(ctx, dAefetcherTimeout)
162162
defer cancel()
163163
//TODO: we should maintain the original error instead of creating a new one as we lose context by creating a new error.
164-
headerRes := m.dalc.Retrieve(ctx, daHeight)
164+
headerRes := types.RetrieveWithHelpers(ctx, m.da, m.logger, daHeight)
165165
if headerRes.Code == coreda.StatusError {
166166
err = fmt.Errorf("failed to retrieve block: %s", headerRes.Message)
167167
}

0 commit comments

Comments
 (0)