Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e0c9d5e
include the validator hasher
randygrok May 19, 2025
3791755
add attestation commit
randygrok May 20, 2025
39f40b7
first batch of changes
randygrok May 21, 2025
21d3136
Merge remote-tracking branch 'origin/main' into feat/fix-block-fields…
randygrok May 21, 2025
519df96
refactor for clarity
randygrok May 21, 2025
1ab5f07
add better comment for publishBlockInternal
randygrok May 21, 2025
21283d2
temp commit before finishing last tests
randygrok May 23, 2025
fd46274
update and it does forge blocks
randygrok May 23, 2025
782aba0
add payload provider for signature
randygrok May 26, 2025
adf4ad5
add signature payload provider
randygrok May 26, 2025
eaef309
add header hasher
randygrok May 26, 2025
20e9d17
include proto for attestation
randygrok May 26, 2025
d58ff27
build blocks
randygrok May 26, 2025
22427fd
remove unused code
randygrok May 27, 2025
a039e4f
remove unused code
randygrok May 27, 2025
54c7c06
Merge remote-tracking branch 'origin/main' into feat/fix-block-fields…
randygrok May 27, 2025
e242311
Fixes after merge
randygrok May 28, 2025
f29fa1f
fix tests
randygrok May 28, 2025
7eb6017
fix lint
randygrok May 28, 2025
a8f5ed9
Merge remote-tracking branch 'origin/main' into feat/fix-block-fields…
randygrok May 28, 2025
fdef9f0
go mod tidy
randygrok May 28, 2025
0c913cb
go mod tidy
randygrok May 28, 2025
1d39a24
fix linter
randygrok May 28, 2025
9ffa5af
fix tests
randygrok May 29, 2025
a856d9f
update apps evm based
randygrok May 29, 2025
df6dc00
fix e2e
randygrok May 29, 2025
330f476
delete bins
randygrok May 29, 2025
db366b4
fix some tests
randygrok May 29, 2025
5280c5b
fix some more tests
randygrok May 29, 2025
7c0325c
Merge branch 'main' into feat/fix-block-fields-ibc
randygrok May 29, 2025
ddfd254
fix some more tests 2
randygrok May 29, 2025
51ec46b
fix some more tests 3
randygrok May 29, 2025
2ad973f
Merge branch 'main' into feat/fix-block-fields-ibc
randygrok May 29, 2025
654b267
remove comment
randygrok May 29, 2025
f892f8a
fix linter
randygrok May 29, 2025
d4b4a1e
fix failed test
randygrok May 29, 2025
65ab03c
add variadic options
randygrok Jun 2, 2025
6a441b7
bring up the stack the manager options
randygrok Jun 3, 2025
47df1ad
use latest
randygrok Jun 3, 2025
c620107
Merge remote-tracking branch 'origin/main' into feat/fix-block-fields…
randygrok Jun 3, 2025
6d13bfe
remove old header hasher
randygrok Jun 4, 2025
f16a969
fix tests
randygrok Jun 4, 2025
725de12
remove unused fields
randygrok Jun 4, 2025
6ae8751
Refactor: replace createDefaultSignaturePayloadProvider with types.Cr…
randygrok Jun 4, 2025
21492c1
use utils
randygrok Jun 4, 2025
5e4aa31
some comments from the review
randygrok Jun 4, 2025
8bb299c
Merge remote-tracking branch 'origin/main' into feat/fix-block-fields…
randygrok Jun 4, 2025
a54894a
fix build problem
randygrok Jun 4, 2025
be96a0c
solve e2e
randygrok Jun 4, 2025
52d4fc8
Merge branch 'main' into feat/fix-block-fields-ibc
randygrok Jun 4, 2025
d7aad29
provide default values
randygrok Jun 4, 2025
153026d
Merge branch 'feat/fix-block-fields-ibc' of git.832008.xyz-randy:rollkit/…
randygrok Jun 4, 2025
5811214
fix evm tests
randygrok Jun 4, 2025
15a6cf2
Merge branch 'main' into feat/fix-block-fields-ibc
randygrok Jun 5, 2025
8728d14
Merge branch 'main' into feat/fix-block-fields-ibc
randygrok Jun 6, 2025
91a658c
remove magic number
randygrok Jun 6, 2025
372dbf1
create default header hasher now private
randygrok Jun 6, 2025
cb91837
fix tests
randygrok Jun 6, 2025
2872be6
refactor and rename the blockDataWithSignature
randygrok Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 289 additions & 114 deletions block/manager.go

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions block/publish_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ func TestPublishBlockInternal_MaxPendingHeadersReached(t *testing.T) {
mockStore.On("Height", ctx).Return(currentHeight, nil)

err := manager.publishBlock(ctx)

require.Nil(err, "publishBlockInternal should not return an error (otherwise the chain would halt)")
require.Contains(logBuffer.String(), "pending blocks [5] reached limit [5]", "log message mismatch")
require.Error(err, "publishBlockInternal should return an error when pending headers limit is reached")
require.Contains(err.Error(), "pending headers [5] reached limit [5]", "error message mismatch")

mockStore.AssertExpectations(t)
mockExec.AssertNotCalled(t, "GetTxs", mock.Anything)
Expand Down Expand Up @@ -197,6 +196,8 @@ func Test_publishBlock_NoBatch(t *testing.T) {
mockStore.On("GetBlockData", ctx, currentHeight).Return(lastHeader, lastData, nil)
mockStore.On("GetBlockData", ctx, currentHeight+1).Return(nil, nil, errors.New("not found"))

mockStore.On("GetCommitHash", ctx, currentHeight).Return([]byte(nil), nil).Maybe()

// No longer testing GetTxs and SubmitRollupBatchTxs since they're handled by reaper.go

// *** Crucial Mock: Sequencer returns ErrNoBatch ***
Expand Down Expand Up @@ -291,6 +292,8 @@ func Test_publishBlock_EmptyBatch(t *testing.T) {
mockStore.On("GetBlockData", ctx, currentHeight).Return(lastHeader, lastData, nil)
mockStore.On("GetBlockData", ctx, currentHeight+1).Return(nil, nil, errors.New("not found"))

mockStore.On("GetCommitHash", mock.Anything, currentHeight).Return([]byte(nil), nil).Maybe()

// No longer testing GetTxs and SubmitRollupBatchTxs since they're handled by reaper.go

// *** Crucial Mock: Sequencer returns an empty batch ***
Expand All @@ -309,10 +312,7 @@ func Test_publishBlock_EmptyBatch(t *testing.T) {
// Mock SetMetadata for LastBatchDataKey (required for empty batch handling)
mockStore.On("SetMetadata", ctx, "l", mock.AnythingOfType("[]uint8")).Return(nil).Once()

// With our new implementation, we should expect SaveBlockData to be called for empty blocks
mockStore.On("SaveBlockData", ctx, mock.AnythingOfType("*types.SignedHeader"), mock.AnythingOfType("*types.Data"), mock.AnythingOfType("*types.Signature")).Return(nil).Once()

// We should also expect ExecuteTxs to be called with an empty transaction list
// We should expect ExecuteTxs to be called with an empty transaction list
newAppHash := []byte("newAppHash")
mockExec.On("ExecuteTxs", ctx, mock.Anything, currentHeight+1, mock.AnythingOfType("time.Time"), m.lastState.AppHash).Return(newAppHash, uint64(100), nil).Once()

Expand All @@ -322,9 +322,12 @@ func Test_publishBlock_EmptyBatch(t *testing.T) {
// UpdateState should be called
mockStore.On("UpdateState", ctx, mock.AnythingOfType("types.State")).Return(nil).Once()

// SaveBlockData should be called again after validation
// SaveBlockData should be called after validation
mockStore.On("SaveBlockData", ctx, mock.AnythingOfType("*types.SignedHeader"), mock.AnythingOfType("*types.Data"), mock.AnythingOfType("*types.Signature")).Return(nil).Once()

// SaveSequencerAttestation should be called
mockStore.On("SaveSequencerAttestation", ctx, currentHeight+1, mock.AnythingOfType("*types.RollkitSequencerAttestation")).Return(nil).Once()

// Call publishBlock
err = m.publishBlock(ctx)

Expand Down Expand Up @@ -355,12 +358,17 @@ func Test_publishBlock_Success(t *testing.T) {
lastHeader.ProposerAddress = manager.genesis.ProposerAddress
mockStore.On("GetBlockData", t.Context(), initialHeight).Return(lastHeader, lastData, nil).Once()
mockStore.On("GetBlockData", t.Context(), newHeight).Return(nil, nil, errors.New("not found")).Once()
mockStore.On("SaveBlockData", t.Context(), mock.AnythingOfType("*types.SignedHeader"), mock.AnythingOfType("*types.Data"), mock.AnythingOfType("*types.Signature")).Return(nil).Once()

mockStore.On("GetCommitHash", t.Context(), initialHeight).Return([]byte(nil), nil).Maybe()

mockStore.On("SaveBlockData", t.Context(), mock.AnythingOfType("*types.SignedHeader"), mock.AnythingOfType("*types.Data"), mock.AnythingOfType("*types.Signature")).Return(nil).Once()
mockStore.On("SetHeight", t.Context(), newHeight).Return(nil).Once()
mockStore.On("UpdateState", t.Context(), mock.AnythingOfType("types.State")).Return(nil).Once()
mockStore.On("SetMetadata", t.Context(), LastBatchDataKey, mock.AnythingOfType("[]uint8")).Return(nil).Once()

// SaveSequencerAttestation should be called
mockStore.On("SaveSequencerAttestation", t.Context(), newHeight, mock.AnythingOfType("*types.RollkitSequencerAttestation")).Return(nil).Once()

// --- Mock Executor ---
sampleTxs := [][]byte{[]byte("tx1"), []byte("tx2")}
// No longer mocking GetTxs since it's handled by reaper.go
Expand Down
30 changes: 1 addition & 29 deletions da/internal/mocks/da.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ retract v0.12.0 // Published by accident

replace github.com/rollkit/rollkit/core => ./core

replace github.com/rollkit/rollkit/da => ./da

require (
connectrpc.com/connect v1.18.1
connectrpc.com/grpcreflect v1.3.0
Expand Down
17 changes: 17 additions & 0 deletions node/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/rollkit/rollkit/pkg/signer"
"github.com/rollkit/rollkit/pkg/store"
"github.com/rollkit/rollkit/pkg/sync"
"github.com/rollkit/rollkit/types"
)

// prefixes used in KV store to separate rollkit data from execution environment data (if the same data base is reused)
Expand Down Expand Up @@ -81,6 +82,10 @@ func newFullNode(
da coreda.DA,
metricsProvider MetricsProvider,
logger log.Logger,
validatorHasher types.ValidatorHasher,
headerHasher types.HeaderHasher,
commitHashProvider types.CommitHashProvider,
signaturePayloadProvider types.SignaturePayloadProvider,
Comment thread
randygrok marked this conversation as resolved.
Outdated
) (fn *FullNode, err error) {
seqMetrics, _ := metricsProvider(genesis.ChainID)

Expand Down Expand Up @@ -112,6 +117,10 @@ func newFullNode(
seqMetrics,
nodeConfig.DA.GasPrice,
nodeConfig.DA.GasMultiplier,
validatorHasher,
signaturePayloadProvider,
headerHasher,
commitHashProvider,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -198,6 +207,10 @@ func initBlockManager(
seqMetrics *block.Metrics,
gasPrice float64,
gasMultiplier float64,
validatorHasher types.ValidatorHasher,
signaturePayloadProvider types.SignaturePayloadProvider,
headerHasher types.HeaderHasher,
commitHashProvider types.CommitHashProvider,
) (*block.Manager, error) {
logger.Debug("Proposer address", "address", genesis.ProposerAddress)

Expand All @@ -216,6 +229,10 @@ func initBlockManager(
seqMetrics,
gasPrice,
gasMultiplier,
validatorHasher,
headerHasher,
commitHashProvider,
signaturePayloadProvider,
)
if err != nil {
return nil, fmt.Errorf("error while initializing BlockManager: %w", err)
Expand Down
1 change: 1 addition & 0 deletions node/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func setupTestNodeWithCleanup(t *testing.T, config rollkitconfig.Config) (*FullN
ds,
DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()),
log.NewTestLogger(t),
types.ValidatorHasher(nil),
)
require.NoError(t, err)

Expand Down
9 changes: 9 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/rollkit/rollkit/pkg/p2p/key"
"github.com/rollkit/rollkit/pkg/service"
"github.com/rollkit/rollkit/pkg/signer"
"github.com/rollkit/rollkit/types"
)

// Node is the interface for a rollup node
Expand All @@ -40,6 +41,10 @@ func NewNode(
database ds.Batching,
metricsProvider MetricsProvider,
logger log.Logger,
validatorHasher types.ValidatorHasher,
Comment thread
randygrok marked this conversation as resolved.
Outdated
signaturePayloadProvider types.SignaturePayloadProvider,
headerHasher types.HeaderHasher,
commitHashProvider types.CommitHashProvider,
) (Node, error) {
if conf.Node.Light {
return newLightNode(conf, genesis, p2pClient, nodeKey, database, logger)
Expand All @@ -58,5 +63,9 @@ func NewNode(
da,
metricsProvider,
logger,
validatorHasher,
headerHasher,
commitHashProvider,
signaturePayloadProvider,
)
}
1 change: 1 addition & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func newTestNode(ctx context.Context, t *testing.T, nodeType NodeType, chainID s
ds,
DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()),
logger,
types.ValidatorHasher(nil),
)
return node, genesisValidatorKey, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"github.com/rollkit/rollkit/pkg/p2p/key"
"github.com/rollkit/rollkit/pkg/signer"
"github.com/rollkit/rollkit/pkg/signer/file"
"github.com/rollkit/rollkit/types"
)

// ParseConfig is an helpers that loads the node configuration and validates it.
Expand Down Expand Up @@ -140,6 +141,7 @@
datastore,
metrics,
logger,
types.ValidatorHasher(nil),

Check failure on line 144 in pkg/cmd/run_node.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

not enough arguments in call to node.NewNode
)
if err != nil {
return fmt.Errorf("failed to create node: %w", err)
Expand Down
54 changes: 47 additions & 7 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
)

var (
headerPrefix = "h"
dataPrefix = "d"
indexPrefix = "i"
signaturePrefix = "c"
statePrefix = "s"
metaPrefix = "m"
heightPrefix = "t"
headerPrefix = "h"
dataPrefix = "d"
indexPrefix = "i"
signaturePrefix = "c"
statePrefix = "s"
metaPrefix = "m"
heightPrefix = "t"
seqAttestationPrefix = "sa"
)

// DefaultStore is a default store implmementation.
Expand Down Expand Up @@ -230,6 +231,41 @@ func (s *DefaultStore) GetMetadata(ctx context.Context, key string) ([]byte, err
return data, nil
}

// SaveSequencerAttestation saves the sequencer attestation for a given height.
func (s *DefaultStore) SaveSequencerAttestation(ctx context.Context, height uint64, attestation *pb.RollkitSequencerAttestation) error {
key := ds.NewKey(getSeqAttestationKey(height))
// TODO (gmm): consider using proto for marshalling if a proto definition exists or will be created.
// For now, using a simple binary marshaller if available, or json as a fallback.
// This will require RollkitSequencerAttestation to implement MarshalBinary and UnmarshalBinary.
// For simplicity in this example, let's assume it will be marshalled to protobuf if available, or JSON.
// As a placeholder, we'll use a direct proto marshal if the object were a proto message.
// If RollkitSequencerAttestation is not a proto message, this needs to be adapted (e.g. json.Marshal).
// For the ADR, it's defined as a simple Go struct. We'll use JSON for now.
attestationBytes, err := proto.Marshal(attestation) // Assuming MarshalBinary for now as per other types.
if err != nil {
return fmt.Errorf("failed to marshal sequencer attestation: %w", err)
}
return s.db.Put(ctx, key, attestationBytes)
}

// GetSequencerAttestation retrieves the sequencer attestation for a given height.
func (s *DefaultStore) GetSequencerAttestation(ctx context.Context, height uint64) (*pb.RollkitSequencerAttestation, error) {
key := ds.NewKey(getSeqAttestationKey(height))
attestationBytes, err := s.db.Get(ctx, key)
if errors.Is(err, ds.ErrNotFound) {
return nil, err // Return ErrNotFound directly
}
if err != nil {
return nil, fmt.Errorf("failed to get sequencer attestation for height %d: %w", height, err)
}
attestation := new(pb.RollkitSequencerAttestation)
// Assuming UnmarshalBinary for now.
if err := proto.Unmarshal(attestationBytes, attestation); err != nil {
return nil, fmt.Errorf("failed to unmarshal sequencer attestation for height %d: %w", height, err)
}
return attestation, nil
}

const heightLength = 8

func encodeHeight(height uint64) []byte {
Expand All @@ -244,3 +280,7 @@ func decodeHeight(heightBytes []byte) (uint64, error) {
}
return binary.LittleEndian.Uint64(heightBytes), nil
}

func getSeqAttestationKey(height uint64) string {
return seqAttestationPrefix + string(encodeHeight(height))
}
6 changes: 6 additions & 0 deletions pkg/store/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/rollkit/rollkit/types"
pb "github.com/rollkit/rollkit/types/pb/rollkit/v1"
)

// Store is minimal interface for storing and retrieving blocks, commits and state.
Expand Down Expand Up @@ -41,6 +42,11 @@ type Store interface {
// GetMetadata returns values stored for given key with SetMetadata.
GetMetadata(ctx context.Context, key string) ([]byte, error)

// SaveSequencerAttestation saves the sequencer attestation for a given height.
SaveSequencerAttestation(ctx context.Context, height uint64, attestation *pb.RollkitSequencerAttestation) error
// GetSequencerAttestation retrieves the sequencer attestation for a given height.
GetSequencerAttestation(ctx context.Context, height uint64) (*pb.RollkitSequencerAttestation, error)

// Close safely closes underlying data storage, to ensure that data is actually saved.
Close() error
}
12 changes: 12 additions & 0 deletions proto/rollkit/v1/rollkit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,15 @@ message Vote {
// Validator address
bytes validator_address = 5;
}

// RollkitSequencerAttestation holds the essential data signed by the sequencer for a given block.
message RollkitSequencerAttestation {
SignedHeader header = 1;
uint64 height = 2;
int32 round = 3;
bytes block_header_hash = 4;
bytes block_data_hash = 5;
bytes sequencer_address = 6;
google.protobuf.Timestamp timestamp = 7;
bytes signature = 8;
}
2 changes: 1 addition & 1 deletion scripts/proto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bu
## proto-gen: Generate protobuf files. Requires docker.
proto-gen:
@echo "--> Generating Protobuf files"
buf generate --path="./proto/rollkit" --template="buf.gen.yaml" --config="buf.yaml"
@$(DOCKER_BUF) generate --path="./proto/rollkit" --template="buf.gen.yaml" --config="buf.yaml"
.PHONY: proto-gen

## proto-lint: Lint protobuf files. Requires docker.
Expand Down
21 changes: 21 additions & 0 deletions scripts/utils.mk
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,24 @@ mock-gen:
mock-header:
mockery --output test/mocks --srcpkg github.com/celestiaorg/go-header --name Store --filename="external/hstore.go"
.PHONY: mock-header

## mockery-docker: generate mocks using Docker
mockery-docker:
@echo "-> Generating mocks using Docker"
docker run --rm \
-v $(CURDIR):/src \
-v $(GOPATH)/pkg/mod:/go/pkg/mod \
-w /src \
-e GOPATH=/go \
golang:1.24.3 bash -c "\
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
go mod download && \
go mod tidy && \
go install github.com/vektra/mockery/v2@v2.53.0 && \
mockery --output test/mocks --srcpkg github.com/rollkit/rollkit/core/da --name DA --filename da.go --with-expecter && \
mockery --output test/mocks --srcpkg github.com/rollkit/rollkit/core/da --name Client --filename daclient.go --with-expecter && \
mockery --output test/mocks --srcpkg github.com/rollkit/rollkit/core/execution --name Executor --filename execution.go --with-expecter && \
mockery --output test/mocks --srcpkg github.com/rollkit/rollkit/core/sequencer --name Sequencer --filename sequencer.go --with-expecter && \
mockery --output test/mocks --srcpkg github.com/rollkit/rollkit/pkg/store --name Store --filename store.go --with-expecter && \
mockery --output test/mocks --srcpkg github.com/rollkit/rollkit/pkg/p2p --name P2PRPC --filename p2p.go --with-expecter && \
mockery --output test/mocks --srcpkg github.com/celestiaorg/go-header --name Store --filename external/hstore.go --with-expecter"
.PHONY: mockery-docker
Loading
Loading