Skip to content

Commit de518f4

Browse files
authored
chore(deps): update go-da to v0.6.1 (#1852)
This PR updates the github.com/rollkit/go-da dependency to version v0.6.1. It refactors the test mocks by replacing `mockda.MockDA` with `mocks.DA` and deletes the old `da/mock/mock.go` file. The code and tests has been modified to use structured results from `GetIDs`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new command-line flag `--rollkit.da_submit_options` for enhanced control over data availability transaction submissions. - Added support for submitting options in the `DAClient` to improve submission flexibility. - **Improvements** - Enhanced mock functionality with a more flexible argument matching strategy in tests. - Updated the `DAClient` initialization process to accommodate additional configuration options. - Improved handling of block header IDs in the `RetrieveHeaders` method. - **Bug Fixes** - Adjusted test cases to reflect changes in mock implementations, ensuring accurate error handling and timeout management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8ae21f5 commit de518f4

16 files changed

Lines changed: 127 additions & 109 deletions

File tree

block/manager_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
seqGRPC "github.com/rollkit/go-sequencing/proxy/grpc"
3535
"github.com/rollkit/rollkit/config"
3636
"github.com/rollkit/rollkit/da"
37-
mockda "github.com/rollkit/rollkit/da/mock"
3837
"github.com/rollkit/rollkit/mempool"
3938
"github.com/rollkit/rollkit/state"
4039
"github.com/rollkit/rollkit/store"
@@ -62,7 +61,7 @@ func WithinDuration(t *testing.T, expected, actual, tolerance time.Duration) boo
6261
func getManager(t *testing.T, backend goDA.DA) *Manager {
6362
logger := test.NewLogger(t)
6463
return &Manager{
65-
dalc: da.NewDAClient(backend, -1, -1, nil, logger),
64+
dalc: da.NewDAClient(backend, -1, -1, nil, nil, logger),
6665
headerCache: NewHeaderCache(),
6766
logger: logger,
6867
}
@@ -227,7 +226,7 @@ func TestSubmitBlocksToMockDA(t *testing.T) {
227226

228227
for _, tc := range testCases {
229228
t.Run(tc.name, func(t *testing.T) {
230-
mockDA := &mockda.MockDA{}
229+
mockDA := &mocks.DA{}
231230
m := getManager(t, mockDA)
232231
m.conf.DABlockTime = time.Millisecond
233232
m.conf.DAMempoolTTL = 1
@@ -253,15 +252,15 @@ func TestSubmitBlocksToMockDA(t *testing.T) {
253252
// * wait for tx to drop from mempool exactly DABlockTime * DAMempoolTTL seconds
254253
// * retry with a higher gas price
255254
// * successfully submit
256-
mockDA.On("MaxBlobSize").Return(uint64(12345), nil)
255+
mockDA.On("MaxBlobSize", mock.Anything).Return(uint64(12345), nil)
257256
mockDA.
258-
On("Submit", blobs, tc.expectedGasPrices[0], []byte(nil)).
257+
On("Submit", mock.Anything, blobs, tc.expectedGasPrices[0], []byte(nil)).
259258
Return([][]byte{}, da.ErrTxTimedout).Once()
260259
mockDA.
261-
On("Submit", blobs, tc.expectedGasPrices[1], []byte(nil)).
260+
On("Submit", mock.Anything, blobs, tc.expectedGasPrices[1], []byte(nil)).
262261
Return([][]byte{}, da.ErrTxTimedout).Once()
263262
mockDA.
264-
On("Submit", blobs, tc.expectedGasPrices[2], []byte(nil)).
263+
On("Submit", mock.Anything, blobs, tc.expectedGasPrices[2], []byte(nil)).
265264
Return([][]byte{bytes.Repeat([]byte{0x00}, 8)}, nil)
266265

267266
m.pendingHeaders, err = NewPendingHeaders(m.store, m.logger)
@@ -572,7 +571,7 @@ func Test_isProposer(t *testing.T) {
572571

573572
func Test_publishBlock_ManagerNotProposer(t *testing.T) {
574573
require := require.New(t)
575-
m := getManager(t, &mockda.MockDA{})
574+
m := getManager(t, &mocks.DA{})
576575
m.isProposer = false
577576
err := m.publishBlock(context.Background())
578577
require.ErrorIs(err, ErrNotProposer)

cmd/rollkit/docs/rollkit_start.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ rollkit start [flags]
3939
--rollkit.da_mempool_ttl uint number of DA blocks until transaction is dropped from the mempool
4040
--rollkit.da_namespace string DA namespace to submit blob transactions
4141
--rollkit.da_start_height uint starting DA block height (for syncing)
42+
--rollkit.da_submit_options string DA submit options
4243
--rollkit.lazy_aggregator wait for transactions, don't build empty blocks
4344
--rollkit.lazy_block_time duration block time (for lazy mode) (default 1m0s)
4445
--rollkit.light run light client

config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const (
2828
FlagDAStartHeight = "rollkit.da_start_height"
2929
// FlagDANamespace is a flag for specifying the DA namespace ID
3030
FlagDANamespace = "rollkit.da_namespace"
31+
// FlagDASubmitOptions is a flag for data availability submit options
32+
FlagDASubmitOptions = "rollkit.da_submit_options"
3133
// FlagLight is a flag for running the node in light mode
3234
FlagLight = "rollkit.light"
3335
// FlagTrustedHash is a flag for specifying the trusted hash
@@ -61,6 +63,7 @@ type NodeConfig struct {
6163
Instrumentation *cmcfg.InstrumentationConfig `mapstructure:"instrumentation"`
6264
DAGasPrice float64 `mapstructure:"da_gas_price"`
6365
DAGasMultiplier float64 `mapstructure:"da_gas_multiplier"`
66+
DASubmitOptions string `mapstructure:"da_submit_options"`
6467

6568
// CLI flags
6669
DANamespace string `mapstructure:"da_namespace"`
@@ -131,6 +134,7 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
131134
nc.DANamespace = v.GetString(FlagDANamespace)
132135
nc.DAStartHeight = v.GetUint64(FlagDAStartHeight)
133136
nc.DABlockTime = v.GetDuration(FlagDABlockTime)
137+
nc.DASubmitOptions = v.GetString(FlagDASubmitOptions)
134138
nc.BlockTime = v.GetDuration(FlagBlockTime)
135139
nc.LazyAggregator = v.GetBool(FlagLazyAggregator)
136140
nc.Light = v.GetBool(FlagLight)
@@ -159,6 +163,7 @@ func AddFlags(cmd *cobra.Command) {
159163
cmd.Flags().Float64(FlagDAGasMultiplier, def.DAGasMultiplier, "DA gas price multiplier for retrying blob transactions")
160164
cmd.Flags().Uint64(FlagDAStartHeight, def.DAStartHeight, "starting DA block height (for syncing)")
161165
cmd.Flags().String(FlagDANamespace, def.DANamespace, "DA namespace to submit blob transactions")
166+
cmd.Flags().String(FlagDASubmitOptions, def.DASubmitOptions, "DA submit options")
162167
cmd.Flags().Bool(FlagLight, def.Light, "run light client")
163168
cmd.Flags().String(FlagTrustedHash, def.TrustedHash, "initial trusted hash to start the header exchange service")
164169
cmd.Flags().Uint64(FlagMaxPendingBlocks, def.MaxPendingBlocks, "limit of blocks pending DA submission (0 for no limit)")

da/da.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,20 @@ type DAClient struct {
102102
GasPrice float64
103103
GasMultiplier float64
104104
Namespace goDA.Namespace
105+
SubmitOptions []byte
105106
SubmitTimeout time.Duration
106107
RetrieveTimeout time.Duration
107108
Logger log.Logger
108109
}
109110

110111
// NewDAClient returns a new DA client.
111-
func NewDAClient(da goDA.DA, gasPrice, gasMultiplier float64, ns goDA.Namespace, logger log.Logger) *DAClient {
112+
func NewDAClient(da goDA.DA, gasPrice, gasMultiplier float64, ns goDA.Namespace, options []byte, logger log.Logger) *DAClient {
112113
return &DAClient{
113114
DA: da,
114115
GasPrice: gasPrice,
115116
GasMultiplier: gasMultiplier,
116117
Namespace: ns,
118+
SubmitOptions: options,
117119
SubmitTimeout: defaultSubmitTimeout,
118120
RetrieveTimeout: defaultRetrieveTimeout,
119121
Logger: logger,
@@ -153,7 +155,7 @@ func (dac *DAClient) SubmitHeaders(ctx context.Context, headers []*types.SignedH
153155

154156
ctx, cancel := context.WithTimeout(ctx, dac.SubmitTimeout)
155157
defer cancel()
156-
ids, err := dac.DA.Submit(ctx, blobs, gasPrice, dac.Namespace)
158+
ids, err := dac.submit(ctx, blobs, gasPrice, dac.Namespace)
157159
if err != nil {
158160
status := StatusError
159161
switch {
@@ -197,7 +199,7 @@ func (dac *DAClient) SubmitHeaders(ctx context.Context, headers []*types.SignedH
197199

198200
// RetrieveHeaders retrieves block headers from DA.
199201
func (dac *DAClient) RetrieveHeaders(ctx context.Context, dataLayerHeight uint64) ResultRetrieveHeaders {
200-
ids, err := dac.DA.GetIDs(ctx, dataLayerHeight, dac.Namespace)
202+
result, err := dac.DA.GetIDs(ctx, dataLayerHeight, dac.Namespace)
201203
if err != nil {
202204
return ResultRetrieveHeaders{
203205
BaseResult: BaseResult{
@@ -209,7 +211,7 @@ func (dac *DAClient) RetrieveHeaders(ctx context.Context, dataLayerHeight uint64
209211
}
210212

211213
// If no blocks are found, return a non-blocking error.
212-
if len(ids) == 0 {
214+
if len(result.IDs) == 0 {
213215
return ResultRetrieveHeaders{
214216
BaseResult: BaseResult{
215217
Code: StatusNotFound,
@@ -221,7 +223,7 @@ func (dac *DAClient) RetrieveHeaders(ctx context.Context, dataLayerHeight uint64
221223

222224
ctx, cancel := context.WithTimeout(ctx, dac.RetrieveTimeout)
223225
defer cancel()
224-
blobs, err := dac.DA.Get(ctx, ids, dac.Namespace)
226+
blobs, err := dac.DA.Get(ctx, result.IDs, dac.Namespace)
225227
if err != nil {
226228
return ResultRetrieveHeaders{
227229
BaseResult: BaseResult{
@@ -260,3 +262,10 @@ func (dac *DAClient) RetrieveHeaders(ctx context.Context, dataLayerHeight uint64
260262
Headers: headers,
261263
}
262264
}
265+
266+
func (dac *DAClient) submit(ctx context.Context, blobs []goDA.Blob, gasPrice float64, namespace goDA.Namespace) ([]goDA.ID, error) {
267+
if len(dac.SubmitOptions) == 0 {
268+
return dac.DA.Submit(ctx, blobs, gasPrice, namespace)
269+
}
270+
return dac.DA.SubmitWithOptions(ctx, blobs, gasPrice, namespace, dac.SubmitOptions)
271+
}

da/da_test.go

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package da
22

33
import (
4-
"bytes"
54
"context"
65
"errors"
76
"math/rand"
@@ -12,6 +11,7 @@ import (
1211

1312
"github.com/cometbft/cometbft/libs/log"
1413
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/mock"
1515
"github.com/stretchr/testify/require"
1616
"google.golang.org/grpc"
1717
"google.golang.org/grpc/credentials/insecure"
@@ -20,7 +20,7 @@ import (
2020
proxygrpc "github.com/rollkit/go-da/proxy/grpc"
2121
proxyjsonrpc "github.com/rollkit/go-da/proxy/jsonrpc"
2222
goDATest "github.com/rollkit/go-da/test"
23-
"github.com/rollkit/rollkit/da/mock"
23+
"github.com/rollkit/rollkit/test/mocks"
2424
testServer "github.com/rollkit/rollkit/test/server"
2525
"github.com/rollkit/rollkit/types"
2626
)
@@ -37,6 +37,8 @@ const (
3737

3838
// MockDANamespace is the mock namespace
3939
MockDANamespace = "00000000000000000000000000000000000000000000000000deadbeef"
40+
41+
submitTimeout = 50 * time.Millisecond
4042
)
4143

4244
// TestMain starts the mock gRPC and JSONRPC DA services
@@ -67,8 +69,8 @@ func TestMain(m *testing.M) {
6769

6870
func TestMockDAErrors(t *testing.T) {
6971
t.Run("submit_timeout", func(t *testing.T) {
70-
mockDA := &mock.MockDA{}
71-
dalc := NewDAClient(mockDA, -1, -1, nil, log.TestingLogger())
72+
mockDA := &mocks.DA{}
73+
dalc := NewDAClient(mockDA, -1, -1, nil, nil, log.TestingLogger())
7274
header, _ := types.GetRandomBlock(1, 0)
7375
headers := []*types.SignedHeader{header}
7476
var blobs []da.Blob
@@ -78,23 +80,23 @@ func TestMockDAErrors(t *testing.T) {
7880
blobs = append(blobs, headerBytes)
7981
}
8082
// Set up the mock to throw context deadline exceeded
81-
mockDA.On("MaxBlobSize").Return(uint64(1234), nil)
83+
mockDA.On("MaxBlobSize", mock.Anything).Return(uint64(1234), nil)
8284
mockDA.
83-
On("Submit", blobs, float64(-1), []byte(nil)).
84-
After(100*time.Millisecond).
85-
Return([]da.ID{bytes.Repeat([]byte{0x00}, 8)}, nil)
85+
On("Submit", mock.Anything, blobs, float64(-1), []byte(nil)).
86+
After(submitTimeout).
87+
Return(nil, context.DeadlineExceeded)
8688
doTestSubmitTimeout(t, dalc, headers)
8789
})
8890
t.Run("max_blob_size_error", func(t *testing.T) {
89-
mockDA := &mock.MockDA{}
90-
dalc := NewDAClient(mockDA, -1, -1, nil, log.TestingLogger())
91+
mockDA := &mocks.DA{}
92+
dalc := NewDAClient(mockDA, -1, -1, nil, nil, log.TestingLogger())
9193
// Set up the mock to return an error for MaxBlobSize
92-
mockDA.On("MaxBlobSize").Return(uint64(0), errors.New("unable to get DA max blob size"))
94+
mockDA.On("MaxBlobSize", mock.Anything).Return(uint64(0), errors.New("unable to get DA max blob size"))
9395
doTestMaxBlockSizeError(t, dalc)
9496
})
9597
t.Run("tx_too_large", func(t *testing.T) {
96-
mockDA := &mock.MockDA{}
97-
dalc := NewDAClient(mockDA, -1, -1, nil, log.TestingLogger())
98+
mockDA := &mocks.DA{}
99+
dalc := NewDAClient(mockDA, -1, -1, nil, nil, log.TestingLogger())
98100
header, _ := types.GetRandomBlock(1, 0)
99101
headers := []*types.SignedHeader{header}
100102
var blobs []da.Blob
@@ -104,9 +106,9 @@ func TestMockDAErrors(t *testing.T) {
104106
blobs = append(blobs, headerBytes)
105107
}
106108
// Set up the mock to throw tx too large
107-
mockDA.On("MaxBlobSize").Return(uint64(1234), nil)
109+
mockDA.On("MaxBlobSize", mock.Anything).Return(uint64(1234), nil)
108110
mockDA.
109-
On("Submit", blobs, float64(-1), []byte(nil)).
111+
On("Submit", mock.Anything, blobs, float64(-1), []byte(nil)).
110112
Return([]da.ID{}, errors.New("tx too large"))
111113
doTestTxTooLargeError(t, dalc, headers)
112114
})
@@ -115,7 +117,7 @@ func TestMockDAErrors(t *testing.T) {
115117
func TestSubmitRetrieve(t *testing.T) {
116118
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
117119
defer cancel()
118-
dummyClient := NewDAClient(goDATest.NewDummyDA(), -1, -1, nil, log.TestingLogger())
120+
dummyClient := NewDAClient(goDATest.NewDummyDA(), -1, -1, nil, nil, log.TestingLogger())
119121
jsonrpcClient, err := startMockDAClientJSONRPC(ctx)
120122
require.NoError(t, err)
121123
grpcClient := startMockDAClientGRPC()
@@ -151,15 +153,15 @@ func startMockDAClientGRPC() *DAClient {
151153
if err := client.Start(addr.Host, grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil {
152154
panic(err)
153155
}
154-
return NewDAClient(client, -1, -1, nil, log.TestingLogger())
156+
return NewDAClient(client, -1, -1, nil, nil, log.TestingLogger())
155157
}
156158

157159
func startMockDAClientJSONRPC(ctx context.Context) (*DAClient, error) {
158160
client, err := proxyjsonrpc.NewClient(ctx, MockDAAddressHTTP, "")
159161
if err != nil {
160162
return nil, err
161163
}
162-
return NewDAClient(&client.DA, -1, -1, nil, log.TestingLogger()), nil
164+
return NewDAClient(&client.DA, -1, -1, nil, nil, log.TestingLogger()), nil
163165
}
164166

165167
func doTestSubmitTimeout(t *testing.T, dalc *DAClient, headers []*types.SignedHeader) {
@@ -170,7 +172,7 @@ func doTestSubmitTimeout(t *testing.T, dalc *DAClient, headers []*types.SignedHe
170172
require.NoError(t, err)
171173

172174
assert := assert.New(t)
173-
dalc.SubmitTimeout = 50 * time.Millisecond
175+
dalc.SubmitTimeout = submitTimeout
174176
resp := dalc.SubmitHeaders(ctx, headers, maxBlobSize, -1)
175177
assert.Contains(resp.Message, "context deadline exceeded", "should return context timeout error")
176178
}
@@ -351,3 +353,31 @@ func doTestRetrieveNoBlocksFound(t *testing.T, dalc *DAClient) {
351353
// assert.Contains(result.Message, ErrBlobNotFound.Error())
352354
assert.Equal(StatusError, result.Code)
353355
}
356+
357+
func TestSubmitWithOptions(t *testing.T) {
358+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
359+
defer cancel()
360+
dummyClient := NewDAClient(goDATest.NewDummyDA(), -1, -1, nil, []byte("option=value"), log.TestingLogger())
361+
jsonrpcClient, err := startMockDAClientJSONRPC(ctx)
362+
require.NoError(t, err)
363+
grpcClient := startMockDAClientGRPC()
364+
require.NoError(t, err)
365+
clients := map[string]*DAClient{
366+
"dummy": dummyClient,
367+
"jsonrpc": jsonrpcClient,
368+
"grpc": grpcClient,
369+
}
370+
tests := []struct {
371+
name string
372+
f func(t *testing.T, dalc *DAClient)
373+
}{
374+
{"submit_retrieve", doTestSubmitRetrieve},
375+
}
376+
for name, dalc := range clients {
377+
for _, tc := range tests {
378+
t.Run(name+"_"+tc.name, func(t *testing.T) {
379+
tc.f(t, dalc)
380+
})
381+
}
382+
}
383+
}

da/mock/mock.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/multiformats/go-multiaddr v0.13.0
2323
github.com/pkg/errors v0.9.1
2424
github.com/prometheus/client_golang v1.20.3
25-
github.com/rollkit/go-da v0.5.2
25+
github.com/rollkit/go-da v0.6.1
2626
github.com/rs/cors v1.11.1
2727
github.com/spf13/cobra v1.8.1
2828
github.com/spf13/viper v1.19.0

0 commit comments

Comments
 (0)