diff --git a/block/manager.go b/block/manager.go index 78375d567a..727a7f1d7d 100644 --- a/block/manager.go +++ b/block/manager.go @@ -35,6 +35,9 @@ const defaultDABlockTime = 15 * time.Second // defaultBlockTime is used only if BlockTime is not configured for manager const defaultBlockTime = 1 * time.Second +// defaultMempoolTTL is the number of blocks until transaction is dropped from mempool +const defaultMempoolTTL = 25 + // maxSubmitAttempts defines how many times Rollkit will re-try to publish block to DA layer. // This is temporary solution. It will be removed in future versions. const maxSubmitAttempts = 30 @@ -164,6 +167,11 @@ func NewManager( conf.BlockTime = defaultBlockTime } + if conf.DAMempoolTTL == 0 { + logger.Info("Using default mempool ttl", "MempoolTTL", defaultMempoolTTL) + conf.DAMempoolTTL = defaultMempoolTTL + } + proposerAddress, err := getAddress(proposerKey) if err != nil { return nil, err @@ -835,8 +843,15 @@ func (m *Manager) submitBlocksToDA(ctx context.Context) error { blocksToSubmit := m.pendingBlocks.getPendingBlocks() numSubmittedBlocks := 0 attempt := 0 + maxBlobSize, err := m.dalc.DA.MaxBlobSize(ctx) + if err != nil { + return err + } + initialMaxBlobSize := maxBlobSize + initialGasPrice := m.dalc.GasPrice + gasPrice := m.dalc.GasPrice for ctx.Err() == nil && !submittedAllBlocks && attempt < maxSubmitAttempts { - res := m.dalc.SubmitBlocks(ctx, blocksToSubmit) + res := m.dalc.SubmitBlocks(ctx, blocksToSubmit, maxBlobSize, gasPrice) switch res.Code { case da.StatusSuccess: m.logger.Info("successfully submitted Rollkit blocks to DA layer", "daHeight", res.DAHeight, "count", res.SubmittedCount) @@ -850,6 +865,29 @@ func (m *Manager) submitBlocksToDA(ctx context.Context) error { } m.pendingBlocks.removeSubmittedBlocks(submittedBlocks) blocksToSubmit = notSubmittedBlocks + // reset submission options when successful + // scale back gasPrice gradually + backoff = initialBackoff + maxBlobSize = initialMaxBlobSize + gasPrice = gasPrice / m.dalc.GasMultiplier + if gasPrice < initialGasPrice { + gasPrice = initialGasPrice + } + m.logger.Debug("resetting DA layer submission options", "backoff", backoff, "gasPrice", gasPrice, "maxBlobSize", maxBlobSize) + case da.StatusNotIncludedInBlock, da.StatusAlreadyInMempool: + m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt) + backoff = m.conf.DABlockTime * time.Duration(m.conf.DAMempoolTTL) + if m.dalc.GasMultiplier != -1 && gasPrice != -1 { + gasPrice = gasPrice * m.dalc.GasMultiplier + } + m.logger.Info("retrying DA layer submission with", "backoff", backoff, "gasPrice", gasPrice, "maxBlobSize", maxBlobSize) + time.Sleep(backoff) + backoff = m.exponentialBackoff(backoff) + case da.StatusTooBig: + m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt) + maxBlobSize = maxBlobSize / 4 + time.Sleep(backoff) + backoff = m.exponentialBackoff(backoff) default: m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt) time.Sleep(backoff) diff --git a/block/manager_test.go b/block/manager_test.go index b7db58824d..589397e0aa 100644 --- a/block/manager_test.go +++ b/block/manager_test.go @@ -1,26 +1,30 @@ package block import ( + "bytes" "context" "testing" + "time" cmtypes "github.com/cometbft/cometbft/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + goDA "github.com/rollkit/go-da" goDATest "github.com/rollkit/go-da/test" "github.com/rollkit/rollkit/da" + "github.com/rollkit/rollkit/da/mock" "github.com/rollkit/rollkit/store" test "github.com/rollkit/rollkit/test/log" "github.com/rollkit/rollkit/types" ) // Returns a minimalistic block manager -func getManager(t *testing.T) *Manager { +func getManager(t *testing.T, backend goDA.DA) *Manager { logger := test.NewFileLoggerCustom(t, test.TempLogFileName(t, t.Name())) return &Manager{ - dalc: &da.DAClient{DA: goDATest.NewDummyDA(), GasPrice: -1, Logger: logger}, + dalc: &da.DAClient{DA: backend, GasPrice: -1, GasMultiplier: -1, Logger: logger}, blockCache: NewBlockCache(), logger: logger, } @@ -125,11 +129,52 @@ func TestIsDAIncluded(t *testing.T) { require.True(m.IsDAIncluded(hash)) } +func TestSubmitBlocksToMockDA(t *testing.T) { + ctx := context.Background() + + mockDA := &mock.MockDA{} + m := getManager(t, mockDA) + m.conf.DABlockTime = time.Millisecond + m.conf.DAMempoolTTL = 1 + m.dalc.GasPrice = 1.0 + m.dalc.GasMultiplier = 1.2 + + t.Run("handle_tx_already_in_mempool", func(t *testing.T) { + var blobs [][]byte + block := types.GetRandomBlock(1, 5) + blob, err := block.MarshalBinary() + + require.NoError(t, err) + blobs = append(blobs, blob) + // Set up the mock to + // * throw timeout waiting for tx to be included exactly once + // * wait for tx to drop from mempool exactly DABlockTime * DAMempoolTTL seconds + // * retry with a higher gas price + // * successfully submit + mockDA.On("MaxBlobSize").Return(uint64(12345), nil) + mockDA. + On("Submit", blobs, 1.0, []byte(nil)). + Return([][]byte{}, da.ErrTxTimedout).Once() + mockDA. + On("Submit", blobs, 1.0*1.2, []byte(nil)). + Return([][]byte{}, da.ErrTxAlreadyInMempool).Times(int(m.conf.DAMempoolTTL)) + mockDA. + On("Submit", blobs, 1.0*1.2*1.2, []byte(nil)). + Return([][]byte{bytes.Repeat([]byte{0x00}, 8)}, nil) + + m.pendingBlocks = NewPendingBlocks() + m.pendingBlocks.addPendingBlock(block) + err = m.submitBlocksToDA(ctx) + require.NoError(t, err) + mockDA.AssertExpectations(t) + }) +} + func TestSubmitBlocksToDA(t *testing.T) { require := require.New(t) ctx := context.Background() - m := getManager(t) + m := getManager(t, goDATest.NewDummyDA()) maxDABlobSizeLimit, err := m.dalc.DA.MaxBlobSize(ctx) require.NoError(err) diff --git a/cmd/rollkit/docs/rollkit_start.md b/cmd/rollkit/docs/rollkit_start.md index 31516e8121..2f7473e62f 100644 --- a/cmd/rollkit/docs/rollkit_start.md +++ b/cmd/rollkit/docs/rollkit_start.md @@ -32,6 +32,7 @@ rollkit start [flags] --rollkit.block_time duration block time (for aggregator mode) (default 1s) --rollkit.da_address string DA address (host:port) (default ":26650") --rollkit.da_block_time duration DA chain block time (for syncing) (default 15s) + --rollkit.da_gas_multiplier float DA gas price multiplier for retrying blob transactions (default -1) --rollkit.da_gas_price float DA gas price for blob transactions (default -1) --rollkit.da_namespace string DA namespace to submit blob transactions --rollkit.da_start_height uint starting DA block height (for syncing) diff --git a/config/config.go b/config/config.go index 8de2112cb6..e14da5faf3 100644 --- a/config/config.go +++ b/config/config.go @@ -20,6 +20,8 @@ const ( FlagDABlockTime = "rollkit.da_block_time" // FlagDAGasPrice is a flag for specifying the data availability layer gas price FlagDAGasPrice = "rollkit.da_gas_price" + // FlagDAGasMultiplier is a flag for specifying the data availability layer gas price retry multiplier + FlagDAGasMultiplier = "rollkit.da_gas_multiplier" // FlagDAStartHeight is a flag for specifying the data availability layer start height FlagDAStartHeight = "rollkit.da_start_height" // FlagDANamespace is a flag for specifying the DA namespace ID @@ -48,6 +50,7 @@ type NodeConfig struct { LazyAggregator bool `mapstructure:"lazy_aggregator"` Instrumentation *cmcfg.InstrumentationConfig `mapstructure:"instrumentation"` DAGasPrice float64 `mapstructure:"da_gas_price"` + DAGasMultiplier float64 `mapstructure:"da_gas_multiplier"` // CLI flags DANamespace string `mapstructure:"da_namespace"` @@ -66,6 +69,8 @@ type BlockManagerConfig struct { DABlockTime time.Duration `mapstructure:"da_block_time"` // DAStartHeight allows skipping first DAStartHeight-1 blocks when querying for blocks. DAStartHeight uint64 `mapstructure:"da_start_height"` + // DAMempoolTTL is the number of DA blocks until transaction is dropped from the mempool. + DAMempoolTTL uint64 `mapstructure:"da_mempool_ttl"` } // GetNodeConfig translates Tendermint's configuration into Rollkit configuration. @@ -102,6 +107,7 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error { nc.Aggregator = v.GetBool(FlagAggregator) nc.DAAddress = v.GetString(FlagDAAddress) nc.DAGasPrice = v.GetFloat64(FlagDAGasPrice) + nc.DAGasMultiplier = v.GetFloat64(FlagDAGasMultiplier) nc.DANamespace = v.GetString(FlagDANamespace) nc.DAStartHeight = v.GetUint64(FlagDAStartHeight) nc.DABlockTime = v.GetDuration(FlagDABlockTime) @@ -124,6 +130,7 @@ func AddFlags(cmd *cobra.Command) { cmd.Flags().Duration(FlagBlockTime, def.BlockTime, "block time (for aggregator mode)") cmd.Flags().Duration(FlagDABlockTime, def.DABlockTime, "DA chain block time (for syncing)") cmd.Flags().Float64(FlagDAGasPrice, def.DAGasPrice, "DA gas price for blob transactions") + cmd.Flags().Float64(FlagDAGasMultiplier, def.DAGasMultiplier, "DA gas price multiplier for retrying blob transactions") cmd.Flags().Uint64(FlagDAStartHeight, def.DAStartHeight, "starting DA block height (for syncing)") cmd.Flags().String(FlagDANamespace, def.DANamespace, "DA namespace to submit blob transactions") cmd.Flags().Bool(FlagLight, def.Light, "run light client") diff --git a/config/defaults.go b/config/defaults.go index 44e5e5fe38..9bed356d36 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -26,9 +26,10 @@ var DefaultNodeConfig = NodeConfig{ BlockTime: 1 * time.Second, DABlockTime: 15 * time.Second, }, - DAAddress: ":26650", - DAGasPrice: -1, - Light: false, + DAAddress: ":26650", + DAGasPrice: -1, + DAGasMultiplier: -1, + Light: false, HeaderConfig: HeaderConfig{ TrustedHash: "", }, diff --git a/da/da.go b/da/da.go index e91375fb6d..96a50ef778 100644 --- a/da/da.go +++ b/da/da.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "errors" "fmt" + "strings" "time" "github.com/gogo/protobuf/proto" @@ -29,6 +30,21 @@ var ( // ErrBlobSizeOverLimit is used to indicate that the blob size is over limit ErrBlobSizeOverLimit = errors.New("blob: over size limit") + + // ErrTxTimedout is the error message returned by the DA when mempool is congested + ErrTxTimedout = errors.New("timed out waiting for tx to be included in a block") + + // ErrTxAlreadyInMempool is the error message returned by the DA when tx is already in mempool + ErrTxAlreadyInMempool = errors.New("tx already in mempool") + + // ErrTxIncorrectAccountSequence is the error message returned by the DA when tx has incorrect sequence + ErrTxIncorrectAccountSequence = errors.New("incorrect account sequence") + + // ErrTxSizeTooBig is the error message returned by the DA when tx size is too big + ErrTxSizeTooBig = errors.New("tx size is too big") + + // ErrContextDeadline is the error message returned by the DA when context deadline exceeds + ErrContextDeadline = errors.New("context deadline") ) // StatusCode is a type for DA layer return status. @@ -42,6 +58,10 @@ const ( StatusUnknown StatusCode = iota StatusSuccess StatusNotFound + StatusNotIncludedInBlock + StatusAlreadyInMempool + StatusTooBig + StatusContextDeadline StatusError ) @@ -75,25 +95,17 @@ type ResultRetrieveBlocks struct { // DAClient is a new DA implementation. type DAClient struct { - DA goDA.DA - Namespace goDA.Namespace - GasPrice float64 - Logger log.Logger + DA goDA.DA + GasPrice float64 + GasMultiplier float64 + Namespace goDA.Namespace + Logger log.Logger } // SubmitBlocks submits blocks to DA. -func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block) ResultSubmitBlocks { +func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block, maxBlobSize uint64, gasPrice float64) ResultSubmitBlocks { var blobs [][]byte var blobSize uint64 - maxBlobSize, err := dac.DA.MaxBlobSize(ctx) - if err != nil { - return ResultSubmitBlocks{ - BaseResult: BaseResult{ - Code: StatusError, - Message: "unable to get DA max blob size", - }, - } - } var submitted uint64 for i := range blocks { blob, err := blocks[i].MarshalBinary() @@ -123,11 +135,24 @@ func (dac *DAClient) SubmitBlocks(ctx context.Context, blocks []*types.Block) Re } ctx, cancel := context.WithTimeout(ctx, submitTimeout) defer cancel() - ids, err := dac.DA.Submit(ctx, blobs, dac.GasPrice, dac.Namespace) + ids, err := dac.DA.Submit(ctx, blobs, gasPrice, dac.Namespace) if err != nil { + status := StatusError + switch { + case strings.Contains(err.Error(), ErrTxTimedout.Error()): + status = StatusNotIncludedInBlock + case strings.Contains(err.Error(), ErrTxAlreadyInMempool.Error()): + status = StatusAlreadyInMempool + case strings.Contains(err.Error(), ErrTxIncorrectAccountSequence.Error()): + status = StatusAlreadyInMempool + case strings.Contains(err.Error(), ErrTxSizeTooBig.Error()): + status = StatusTooBig + case strings.Contains(err.Error(), ErrContextDeadline.Error()): + status = StatusContextDeadline + } return ResultSubmitBlocks{ BaseResult: BaseResult{ - Code: StatusError, + Code: status, Message: "failed to submit blocks: " + err.Error(), }, } diff --git a/da/da_test.go b/da/da_test.go index 09d693c6df..7387fed57c 100644 --- a/da/da_test.go +++ b/da/da_test.go @@ -14,7 +14,6 @@ import ( "github.com/cometbft/cometbft/libs/log" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -23,6 +22,7 @@ import ( "github.com/rollkit/go-da" "github.com/rollkit/go-da/proxy" goDATest "github.com/rollkit/go-da/test" + "github.com/rollkit/rollkit/da/mock" "github.com/rollkit/rollkit/types" ) @@ -41,55 +41,10 @@ func TestMain(m *testing.M) { os.Exit(exitCode) } -// MockDA is a mock for the DA interface -type MockDA struct { - mock.Mock -} - -func (m *MockDA) MaxBlobSize(ctx context.Context) (uint64, error) { - args := m.Called() - return args.Get(0).(uint64), args.Error(1) -} - -func (m *MockDA) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) { - args := m.Called(ids) - return args.Get(0).([]da.Blob), args.Error(1) -} - -func (m *MockDA) GetIDs(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) { - args := m.Called(height) - return args.Get(0).([]da.ID), args.Error(1) -} - -func (m *MockDA) Commit(ctx context.Context, blobs []da.Blob, ns da.Namespace) ([]da.Commitment, error) { - args := m.Called(blobs) - return args.Get(0).([]da.Commitment), args.Error(1) -} - -func (m *MockDA) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, ns da.Namespace) ([]da.ID, error) { - args := m.Called(blobs, gasPrice) - select { - case <-ctx.Done(): - return nil, ctx.Err() - default: - return args.Get(0).([]da.ID), args.Error(1) - } -} - -func (m *MockDA) GetProofs(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Proof, error) { - args := m.Called(ids) - return args.Get(0).([]da.Proof), args.Error(1) -} - -func (m *MockDA) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, ns da.Namespace) ([]bool, error) { - args := m.Called(ids, proofs) - return args.Get(0).([]bool), args.Error(1) -} - func TestMockDAErrors(t *testing.T) { t.Run("submit_timeout", func(t *testing.T) { - mockDA := &MockDA{} - dalc := &DAClient{DA: mockDA, GasPrice: -1, Logger: log.TestingLogger()} + mockDA := &mock.MockDA{} + dalc := &DAClient{DA: mockDA, GasPrice: -1, GasMultiplier: -1, Logger: log.TestingLogger()} blocks := []*types.Block{types.GetRandomBlock(1, 0)} var blobs []da.Blob for _, block := range blocks { @@ -100,16 +55,16 @@ func TestMockDAErrors(t *testing.T) { // Set up the mock to throw context deadline exceeded mockDA.On("MaxBlobSize").Return(uint64(1234), nil) mockDA. - On("Submit", blobs, float64(-1)). + On("Submit", blobs, float64(-1), []byte(nil)). After(100*time.Millisecond). - Return([]da.ID{bytes.Repeat([]byte{0x00}, 8)}, []da.Proof{[]byte("proof")}, nil) + Return([]da.ID{bytes.Repeat([]byte{0x00}, 8)}, nil) doTestSubmitTimeout(t, dalc, blocks) }) t.Run("max_blob_size_error", func(t *testing.T) { - mockDA := &MockDA{} - dalc := &DAClient{DA: mockDA, GasPrice: -1, Logger: log.TestingLogger()} + mockDA := &mock.MockDA{} + dalc := &DAClient{DA: mockDA, GasPrice: -1, GasMultiplier: -1, Logger: log.TestingLogger()} // Set up the mock to return an error for MaxBlobSize - mockDA.On("MaxBlobSize").Return(uint64(0), errors.New("mock error")) + mockDA.On("MaxBlobSize").Return(uint64(0), errors.New("unable to get DA max blob size")) doTestMaxBlockSizeError(t, dalc) }) } @@ -161,16 +116,19 @@ func startMockGRPCClient() (*DAClient, error) { if err != nil { return nil, err } - return &DAClient{DA: client, GasPrice: -1, Logger: log.TestingLogger()}, nil + return &DAClient{DA: client, GasPrice: -1, GasMultiplier: -1, Logger: log.TestingLogger()}, nil } func doTestSubmitTimeout(t *testing.T, dalc *DAClient, blocks []*types.Block) { ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() + maxBlobSize, err := dalc.DA.MaxBlobSize(ctx) + require.NoError(t, err) + assert := assert.New(t) submitTimeout = 50 * time.Millisecond - resp := dalc.SubmitBlocks(ctx, blocks) + resp := dalc.SubmitBlocks(ctx, blocks, maxBlobSize, -1) assert.Contains(resp.Message, "context deadline exceeded", "should return context timeout error") } @@ -179,8 +137,8 @@ func doTestMaxBlockSizeError(t *testing.T, dalc *DAClient) { defer cancel() assert := assert.New(t) - resp := dalc.SubmitBlocks(ctx, []*types.Block{}) - assert.Contains(resp.Message, "unable to get DA max blob size", "should return max blob size error") + _, err := dalc.DA.MaxBlobSize(ctx) + assert.ErrorContains(err, "unable to get DA max blob size", "should return max blob size error") } func doTestSubmitRetrieve(t *testing.T, dalc *DAClient) { @@ -196,9 +154,12 @@ func doTestSubmitRetrieve(t *testing.T, dalc *DAClient) { blockToDAHeight := make(map[*types.Block]uint64) countAtHeight := make(map[uint64]int) + maxBlobSize, err := dalc.DA.MaxBlobSize(ctx) + require.NoError(err) + submitAndRecordBlocks := func(blocks []*types.Block) { for len(blocks) > 0 { - resp := dalc.SubmitBlocks(ctx, blocks) + resp := dalc.SubmitBlocks(ctx, blocks, maxBlobSize, -1) assert.Equal(StatusSuccess, resp.Code, resp.Message) for _, block := range blocks[:resp.SubmittedCount] { @@ -242,11 +203,14 @@ func doTestSubmitEmptyBlocks(t *testing.T, dalc *DAClient) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() + maxBlobSize, err := dalc.DA.MaxBlobSize(ctx) + require.NoError(t, err) + assert := assert.New(t) block1 := types.GetRandomBlock(1, 0) block2 := types.GetRandomBlock(1, 0) - resp := dalc.SubmitBlocks(ctx, []*types.Block{block1, block2}) + resp := dalc.SubmitBlocks(ctx, []*types.Block{block1, block2}, maxBlobSize, -1) assert.Equal(StatusSuccess, resp.Code, "empty blocks should submit") assert.EqualValues(resp.SubmittedCount, 2, "empty blocks should batch") } @@ -261,7 +225,7 @@ func doTestSubmitOversizedBlock(t *testing.T, dalc *DAClient) { limit, err := dalc.DA.MaxBlobSize(ctx) require.NoError(err) oversizedBlock := types.GetRandomBlock(1, int(limit)) - resp := dalc.SubmitBlocks(ctx, []*types.Block{oversizedBlock}) + resp := dalc.SubmitBlocks(ctx, []*types.Block{oversizedBlock}, limit, -1) assert.Equal(StatusError, resp.Code, "oversized block should throw error") assert.Contains(resp.Message, "failed to submit blocks: oversized block: blob: over size limit") } @@ -270,11 +234,14 @@ func doTestSubmitSmallBlocksBatch(t *testing.T, dalc *DAClient) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() + maxBlobSize, err := dalc.DA.MaxBlobSize(ctx) + require.NoError(t, err) + assert := assert.New(t) block1 := types.GetRandomBlock(1, 1) block2 := types.GetRandomBlock(1, 2) - resp := dalc.SubmitBlocks(ctx, []*types.Block{block1, block2}) + resp := dalc.SubmitBlocks(ctx, []*types.Block{block1, block2}, maxBlobSize, -1) assert.Equal(StatusSuccess, resp.Code, "small blocks should submit") assert.EqualValues(resp.SubmittedCount, 2, "small blocks should batch") } @@ -306,12 +273,12 @@ func doTestSubmitLargeBlocksOverflow(t *testing.T, dalc *DAClient) { } // overflowing blocks submit partially - resp := dalc.SubmitBlocks(ctx, []*types.Block{block1, block2}) + resp := dalc.SubmitBlocks(ctx, []*types.Block{block1, block2}, limit, -1) assert.Equal(StatusSuccess, resp.Code, "overflowing blocks should submit partially") assert.EqualValues(1, resp.SubmittedCount, "submitted count should be partial") // retry remaining blocks - resp = dalc.SubmitBlocks(ctx, []*types.Block{block2}) + resp = dalc.SubmitBlocks(ctx, []*types.Block{block2}, limit, -1) assert.Equal(StatusSuccess, resp.Code, "remaining blocks should submit") assert.EqualValues(resp.SubmittedCount, 1, "submitted count should match") } diff --git a/da/mock/main.go b/da/mock/cmd/main.go similarity index 100% rename from da/mock/main.go rename to da/mock/cmd/main.go diff --git a/da/mock/mock.go b/da/mock/mock.go new file mode 100644 index 0000000000..f7564f2269 --- /dev/null +++ b/da/mock/mock.go @@ -0,0 +1,61 @@ +package mock + +import ( + "context" + + "github.com/stretchr/testify/mock" + + "github.com/rollkit/go-da" +) + +// MockDA is a mock for the DA interface +type MockDA struct { + mock.Mock +} + +// MaxBlobSize returns the max blob size. +func (m *MockDA) MaxBlobSize(ctx context.Context) (uint64, error) { + args := m.Called() + return args.Get(0).(uint64), args.Error(1) +} + +// Get returns the blob by its ID. +func (m *MockDA) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) { + args := m.Called(ids, ns) + return args.Get(0).([]da.Blob), args.Error(1) +} + +// GetIDs returns the IDs in a specific DA height. +func (m *MockDA) GetIDs(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) { + args := m.Called(height, ns) + return args.Get(0).([]da.ID), args.Error(1) +} + +// Commit returns the commitments for the given blobs. +func (m *MockDA) Commit(ctx context.Context, blobs []da.Blob, ns da.Namespace) ([]da.Commitment, error) { + args := m.Called(blobs, ns) + return args.Get(0).([]da.Commitment), args.Error(1) +} + +// Submit submits and returns the IDs for the given blobs. +func (m *MockDA) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, ns da.Namespace) ([]da.ID, error) { + args := m.Called(blobs, gasPrice, ns) + select { + case <-ctx.Done(): + return nil, ctx.Err() + default: + return args.Get(0).([]da.ID), args.Error(1) + } +} + +// GetProofs returns the proofs for the given ids. +func (m *MockDA) GetProofs(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Proof, error) { + args := m.Called(ids, ns) + return args.Get(0).([]da.Proof), args.Error(1) +} + +// Validate validates the given ids and proofs and returns validation results. +func (m *MockDA) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, ns da.Namespace) ([]bool, error) { + args := m.Called(ids, proofs, ns) + return args.Get(0).([]bool), args.Error(1) +} diff --git a/node/full.go b/node/full.go index 64a12acd67..c320c8e3df 100644 --- a/node/full.go +++ b/node/full.go @@ -233,7 +233,7 @@ func initDALC(nodeConfig config.NodeConfig, dalcKV ds.TxnDatastore, logger log.L if err != nil { return nil, fmt.Errorf("error while establishing GRPC connection to DA layer: %w", err) } - return &da.DAClient{DA: daClient, Namespace: namespace, GasPrice: nodeConfig.DAGasPrice, Logger: logger.With("module", "da_client")}, nil + return &da.DAClient{DA: daClient, Namespace: namespace, GasPrice: nodeConfig.DAGasPrice, GasMultiplier: nodeConfig.DAGasMultiplier, Logger: logger.With("module", "da_client")}, nil } func initMempool(logger log.Logger, proxyApp proxy.AppConns, memplMetrics *mempool.Metrics) *mempool.CListMempool { diff --git a/node/full_client_test.go b/node/full_client_test.go index 53c207f02f..568124a894 100644 --- a/node/full_client_test.go +++ b/node/full_client_test.go @@ -386,7 +386,7 @@ func TestCometBFTLightClientCompability(t *testing.T) { // save the 3 blocks for _, b := range blocks { - err := rpc.node.Store.SaveBlock(ctx, b, &b.SignedHeader.Commit) + err := rpc.node.Store.SaveBlock(ctx, b, &b.SignedHeader.Commit) // #nosec G601 rpc.node.Store.SetHeight(ctx, b.Height()) require.NoError(err) } diff --git a/node/full_node_test.go b/node/full_node_test.go index 54abe8c52c..9fb46b4069 100644 --- a/node/full_node_test.go +++ b/node/full_node_test.go @@ -135,9 +135,12 @@ func TestInvalidBlocksIgnored(t *testing.T) { startNodeWithCleanup(t, node) + maxBlobSize, err := fullNode.dalc.DA.MaxBlobSize(ctx) + require.NoError(t, err) + // Submit invalid blocks to the mock DA // Invalid blocks should be ignored by the node - submitResp := fullNode.dalc.SubmitBlocks(ctx, []*types.Block{&junkProposerBlock, &junkCommitBlock, b1}) + submitResp := fullNode.dalc.SubmitBlocks(ctx, []*types.Block{&junkProposerBlock, &junkCommitBlock, b1}, maxBlobSize, -1) require.Equal(t, submitResp.Code, da.StatusSuccess) // Only the valid block gets synced diff --git a/node/helpers_test.go b/node/helpers_test.go index c9e39ebef4..ef583d13c0 100644 --- a/node/helpers_test.go +++ b/node/helpers_test.go @@ -21,7 +21,7 @@ func getMockDA(t *testing.T) *da.DAClient { namespace := make([]byte, len(MockNamespace)/2) _, err := hex.Decode(namespace, []byte(MockNamespace)) require.NoError(t, err) - return &da.DAClient{DA: goDATest.NewDummyDA(), Namespace: namespace, GasPrice: -1, Logger: log.TestingLogger()} + return &da.DAClient{DA: goDATest.NewDummyDA(), Namespace: namespace, GasPrice: -1, GasMultiplier: -1, Logger: log.TestingLogger()} } func TestMockTester(t *testing.T) {