Skip to content

Commit 3b72870

Browse files
Manav-Aggarwaltac0turtletac0turtlejulienrbrt
authored
fix: Fix Validation logic (#2237)
<!-- 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 Closes: #2230 Uses approach 2 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added robust batch transaction submission to the Data Availability (DA) layer with retry, backoff, and gas price adjustment. - Introduced DA inclusion tracking that advances only when both header and data are confirmed on the DA layer. - Improved block and data validation with explicit DA commitment checks. - Enhanced cache management with new methods for hash-based access. - **Bug Fixes** - Improved error handling and robustness in deserialization and DA inclusion logic. - Fixed configuration and terminology inconsistencies, shifting from "blocks" to "headers" in pending limits and related settings. - **Documentation** - Updated specifications to clarify DA inclusion requirements and document new DAIncluderLoop and SetFinal message. - Added and improved comments for tests and configuration options. - **Tests** - Expanded and refined test coverage for DA inclusion, batch submission, retriever logic, and synchronization. - Improved test reliability with parallel execution and better state management. - **Chores** - Updated dependencies and configuration defaults for improved maintainability. - Refactored and cleaned up internal code and test setup for clarity and efficiency. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: tac0turtle <you@example.com> Co-authored-by: Marko <marko@baricevic.me> Co-authored-by: julienrbrt <julien@rbrt.fr>
1 parent 9ea57dc commit 3b72870

49 files changed

Lines changed: 2004 additions & 1319 deletions

Some content is hidden

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

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ linters:
3434
- examples$
3535
formatters:
3636
enable:
37-
- gci
3837
- gofmt
3938
settings:
4039
gci:

block/aggregation_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
"github.com/rollkit/rollkit/types"
2121
)
2222

23-
// TestAggregationLoop_Normal_BasicInterval verifies the basic time interval logic of the normal aggregation loop.
23+
// TestAggregationLoop_Normal_BasicInterval verifies that the aggregation loop publishes blocks at the expected interval under normal conditions.
2424
func TestAggregationLoop_Normal_BasicInterval(t *testing.T) {
25+
t.Parallel()
2526
assert := assert.New(t)
2627
require := require.New(t)
2728

@@ -114,8 +115,9 @@ func TestAggregationLoop_Normal_BasicInterval(t *testing.T) {
114115
}
115116
}
116117

117-
// TestAggregationLoop_Normal_PublishBlockError verifies the loop continues after publishBlock returns an error.
118+
// TestAggregationLoop_Normal_PublishBlockError verifies that the aggregation loop handles errors from publishBlock gracefully.
118119
func TestAggregationLoop_Normal_PublishBlockError(t *testing.T) {
120+
t.Parallel()
119121
assert := assert.New(t)
120122
require := require.New(t)
121123

block/daIncluder.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package block
2+
3+
import (
4+
"context"
5+
"encoding/binary"
6+
"fmt"
7+
)
8+
9+
// DAIncluderLoop is responsible for advancing the DAIncludedHeight by checking if blocks after the current height
10+
// have both their header and data marked as DA-included in the caches. If so, it calls setDAIncludedHeight.
11+
func (m *Manager) DAIncluderLoop(ctx context.Context) {
12+
for {
13+
select {
14+
case <-ctx.Done():
15+
return
16+
case <-m.daIncluderCh:
17+
// proceed to check for DA inclusion
18+
}
19+
currentDAIncluded := m.GetDAIncludedHeight()
20+
for {
21+
nextHeight := currentDAIncluded + 1
22+
daIncluded, err := m.IsDAIncluded(ctx, nextHeight)
23+
if err != nil {
24+
// No more blocks to check at this time
25+
m.logger.Debug("no more blocks to check at this time", "height", nextHeight, "error", err)
26+
break
27+
}
28+
if daIncluded {
29+
// Both header and data are DA-included, so we can advance the height
30+
if err := m.incrementDAIncludedHeight(ctx); err != nil {
31+
panic(fmt.Errorf("error while incrementing DA included height: %w", err))
32+
}
33+
currentDAIncluded = nextHeight
34+
} else {
35+
// Stop at the first block that is not DA-included
36+
break
37+
}
38+
}
39+
}
40+
}
41+
42+
// incrementDAIncludedHeight sets the DA included height in the store
43+
// It returns an error if the DA included height is not set.
44+
func (m *Manager) incrementDAIncludedHeight(ctx context.Context) error {
45+
currentHeight := m.GetDAIncludedHeight()
46+
newHeight := currentHeight + 1
47+
m.logger.Debug("setting final", "height", newHeight)
48+
err := m.exec.SetFinal(ctx, newHeight)
49+
if err != nil {
50+
m.logger.Error("failed to set final", "height", newHeight, "error", err)
51+
return err
52+
}
53+
heightBytes := make([]byte, 8)
54+
binary.LittleEndian.PutUint64(heightBytes, newHeight)
55+
m.logger.Debug("setting DA included height", "height", newHeight)
56+
err = m.store.SetMetadata(ctx, DAIncludedHeightKey, heightBytes)
57+
if err != nil {
58+
m.logger.Error("failed to set DA included height", "height", newHeight, "error", err)
59+
return err
60+
}
61+
if !m.daIncludedHeight.CompareAndSwap(currentHeight, newHeight) {
62+
return fmt.Errorf("failed to set DA included height: %d", newHeight)
63+
}
64+
return nil
65+
}

0 commit comments

Comments
 (0)