From ca4e8ccb5c5f750ca3bb7dac2530fe672d58df93 Mon Sep 17 00:00:00 2001 From: danwt <30197399+danwt@users.noreply.github.com> Date: Thu, 9 May 2024 09:57:15 +0100 Subject: [PATCH 1/3] remove batch validation --- block/production_test.go | 43 ++-------------------------------------- block/submit.go | 15 -------------- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/block/production_test.go b/block/production_test.go index fa11a781c..3679f684d 100644 --- a/block/production_test.go +++ b/block/production_test.go @@ -13,7 +13,6 @@ import ( "github.com/dymensionxyz/dymint/mempool" mempoolv1 "github.com/dymensionxyz/dymint/mempool/v1" "github.com/dymensionxyz/dymint/node/events" - "github.com/dymensionxyz/dymint/types" uevent "github.com/dymensionxyz/dymint/utils/event" tmcfg "github.com/tendermint/tendermint/config" @@ -61,8 +60,8 @@ func TestCreateEmptyBlocksEnableDisable(t *testing.T) { go manager.ProduceBlockLoop(mCtx) go managerWithEmptyBlocks.ProduceBlockLoop(mCtx) - buf1 := make(chan struct{}, 100) //dummy to avoid unhealthy event - buf2 := make(chan struct{}, 100) //dummy to avoid unhealthy event + buf1 := make(chan struct{}, 100) // dummy to avoid unhealthy event + buf2 := make(chan struct{}, 100) // dummy to avoid unhealthy event go manager.AccumulatedDataLoop(mCtx, buf1) go managerWithEmptyBlocks.AccumulatedDataLoop(mCtx, buf2) <-mCtx.Done() @@ -176,44 +175,6 @@ func TestCreateEmptyBlocksNew(t *testing.T) { assert.True(foundTx) } -func TestInvalidBatch(t *testing.T) { - assert := assert.New(t) - require := require.New(t) - - manager, err := testutil.GetManager(testutil.GetManagerConfig(), nil, nil, 1, 1, 0, nil, nil) - require.NoError(err) - - batchSize := uint64(5) - syncTarget := uint64(10) - - // Create cases - cases := []struct { - startHeight uint64 - endHeight uint64 - shouldError bool - }{ - {startHeight: syncTarget + 1, endHeight: syncTarget + batchSize, shouldError: false}, - // batch with endHight < startHeight - {startHeight: syncTarget + 1, endHeight: syncTarget, shouldError: true}, - // batch with startHeight != previousEndHeight + 1 - {startHeight: syncTarget, endHeight: syncTarget + batchSize + batchSize, shouldError: true}, - } - for _, c := range cases { - batch := &types.Batch{ - StartHeight: c.startHeight, - EndHeight: c.endHeight, - } - - manager.UpdateSyncParams(syncTarget) - err := manager.ValidateBatch(batch) - if c.shouldError { - assert.Error(err) - } else { - assert.NoError(err) - } - } -} - // TestStopBlockProduction tests the block production stops when submitter is full // and resumes when submitter is ready to accept more batches func TestStopBlockProduction(t *testing.T) { diff --git a/block/submit.go b/block/submit.go index 9b077edaf..fb798fbd1 100644 --- a/block/submit.go +++ b/block/submit.go @@ -126,10 +126,6 @@ func (m *Manager) HandleSubmissionTrigger() error { return fmt.Errorf("create next batch to submit: %w", err) } - if err := m.ValidateBatch(nextBatch); err != nil { - return fmt.Errorf("validate batch: %w", err) - } - resultSubmitToDA, err := m.submitNextBatchToDA(nextBatch) if err != nil { return fmt.Errorf("submit next batch to da: %w", err) @@ -169,17 +165,6 @@ func (m *Manager) submitNextBatchToSL(batch *types.Batch, daResult *da.ResultSub return actualEndHeight, nil } -func (m *Manager) ValidateBatch(batch *types.Batch) error { - syncTarget := m.SyncTarget.Load() - if batch.StartHeight != syncTarget+1 { - return fmt.Errorf("batch start height != syncTarget + 1. StartHeight %d, m.SyncTarget %d", batch.StartHeight, syncTarget) - } - if batch.EndHeight < batch.StartHeight { - return fmt.Errorf("batch end height must be greater than start height. EndHeight %d, StartHeight %d", batch.EndHeight, batch.StartHeight) - } - return nil -} - func (m *Manager) CreateNextBatchToSubmit(startHeight uint64, endHeightInclusive uint64) (*types.Batch, error) { var height uint64 // Create the batch From ddc094fa2b6548f5a4898c02f2f072f9321a4b0e Mon Sep 17 00:00:00 2001 From: danwt <30197399+danwt@users.noreply.github.com> Date: Thu, 9 May 2024 10:03:25 +0100 Subject: [PATCH 2/3] inlines submit to sl func --- block/submit.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/block/submit.go b/block/submit.go index fb798fbd1..ada04390e 100644 --- a/block/submit.go +++ b/block/submit.go @@ -131,13 +131,12 @@ func (m *Manager) HandleSubmissionTrigger() error { return fmt.Errorf("submit next batch to da: %w", err) } - syncHeight, err := m.submitNextBatchToSL(nextBatch, resultSubmitToDA) + err = m.SLClient.SubmitBatch(nextBatch, m.DAClient.GetClientType(), resultSubmitToDA) if err != nil { - return fmt.Errorf("submit pending batch to sl: %w", err) + return fmt.Errorf("sl client submit batch: start height: %d: inclusive end height: %d: %w", startHeight, endHeightInclusive, err) } - // Update the syncTarget to the height of the last block in the last batch as seen by this node. - m.UpdateSyncParams(syncHeight) + m.UpdateSyncParams(endHeightInclusive) return nil } @@ -154,17 +153,6 @@ func (m *Manager) submitNextBatchToDA(nextBatch *types.Batch) (*da.ResultSubmitB return &resultSubmitToDA, nil } -func (m *Manager) submitNextBatchToSL(batch *types.Batch, daResult *da.ResultSubmitBatch) (uint64, error) { - startHeight := batch.StartHeight - actualEndHeight := batch.EndHeight - err := m.SLClient.SubmitBatch(batch, m.DAClient.GetClientType(), daResult) - if err != nil { - return 0, fmt.Errorf("sl client submit batch: startheight: %d: actual end height: %d: %w", startHeight, actualEndHeight, err) - } - - return actualEndHeight, nil -} - func (m *Manager) CreateNextBatchToSubmit(startHeight uint64, endHeightInclusive uint64) (*types.Batch, error) { var height uint64 // Create the batch From 000cc9fec7b112a29fa07b45a14e723513f13105 Mon Sep 17 00:00:00 2001 From: danwt <30197399+danwt@users.noreply.github.com> Date: Thu, 9 May 2024 10:04:30 +0100 Subject: [PATCH 3/3] Revert "inlines submit to sl func" This reverts commit ddc094fa2b6548f5a4898c02f2f072f9321a4b0e. --- block/submit.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/block/submit.go b/block/submit.go index ada04390e..fb798fbd1 100644 --- a/block/submit.go +++ b/block/submit.go @@ -131,12 +131,13 @@ func (m *Manager) HandleSubmissionTrigger() error { return fmt.Errorf("submit next batch to da: %w", err) } - err = m.SLClient.SubmitBatch(nextBatch, m.DAClient.GetClientType(), resultSubmitToDA) + syncHeight, err := m.submitNextBatchToSL(nextBatch, resultSubmitToDA) if err != nil { - return fmt.Errorf("sl client submit batch: start height: %d: inclusive end height: %d: %w", startHeight, endHeightInclusive, err) + return fmt.Errorf("submit pending batch to sl: %w", err) } - m.UpdateSyncParams(endHeightInclusive) + // Update the syncTarget to the height of the last block in the last batch as seen by this node. + m.UpdateSyncParams(syncHeight) return nil } @@ -153,6 +154,17 @@ func (m *Manager) submitNextBatchToDA(nextBatch *types.Batch) (*da.ResultSubmitB return &resultSubmitToDA, nil } +func (m *Manager) submitNextBatchToSL(batch *types.Batch, daResult *da.ResultSubmitBatch) (uint64, error) { + startHeight := batch.StartHeight + actualEndHeight := batch.EndHeight + err := m.SLClient.SubmitBatch(batch, m.DAClient.GetClientType(), daResult) + if err != nil { + return 0, fmt.Errorf("sl client submit batch: startheight: %d: actual end height: %d: %w", startHeight, actualEndHeight, err) + } + + return actualEndHeight, nil +} + func (m *Manager) CreateNextBatchToSubmit(startHeight uint64, endHeightInclusive uint64) (*types.Batch, error) { var height uint64 // Create the batch