Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 github.com-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
Next Next commit
include the validator hasher
  • Loading branch information
randygrok committed May 19, 2025
commit e0c9d5eaa192aadcc3024eed97771b7d0b08bed1
68 changes: 43 additions & 25 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ type Manager struct {
genesis genesis.Genesis

signer signer.Signer
// Injected hasher for ValidatorHash calculation
validatorHasher types.ValidatorHasher

daHeight *atomic.Uint64

Expand Down Expand Up @@ -258,6 +260,7 @@ func NewManager(
seqMetrics *Metrics,
gasPrice float64,
gasMultiplier float64,
validatorHasher types.ValidatorHasher,
) (*Manager, error) {
s, err := getInitialState(ctx, genesis, signer, store, exec, logger)
if err != nil {
Expand Down Expand Up @@ -321,29 +324,30 @@ func NewManager(
store: store,
daHeight: &daH,
// channels are buffered to avoid blocking on input/output operations, buffer sizes are arbitrary
HeaderCh: make(chan *types.SignedHeader, channelLength),
DataCh: make(chan *types.Data, channelLength),
headerInCh: make(chan NewHeaderEvent, headerInChLength),
dataInCh: make(chan NewDataEvent, headerInChLength),
headerStoreCh: make(chan struct{}, 1),
dataStoreCh: make(chan struct{}, 1),
headerStore: headerStore,
dataStore: dataStore,
lastStateMtx: new(sync.RWMutex),
lastBatchData: lastBatchData,
headerCache: cache.NewCache[types.SignedHeader](),
dataCache: cache.NewCache[types.Data](),
retrieveCh: make(chan struct{}, 1),
logger: logger,
txsAvailable: false,
pendingHeaders: pendingHeaders,
metrics: seqMetrics,
sequencer: sequencer,
exec: exec,
da: da,
gasPrice: gasPrice,
gasMultiplier: gasMultiplier,
txNotifyCh: make(chan struct{}, 1), // Non-blocking channel
HeaderCh: make(chan *types.SignedHeader, channelLength),
DataCh: make(chan *types.Data, channelLength),
headerInCh: make(chan NewHeaderEvent, headerInChLength),
dataInCh: make(chan NewDataEvent, headerInChLength),
headerStoreCh: make(chan struct{}, 1),
dataStoreCh: make(chan struct{}, 1),
headerStore: headerStore,
dataStore: dataStore,
lastStateMtx: new(sync.RWMutex),
lastBatchData: lastBatchData,
headerCache: cache.NewCache[types.SignedHeader](),
dataCache: cache.NewCache[types.Data](),
retrieveCh: make(chan struct{}, 1),
logger: logger,
txsAvailable: false,
pendingHeaders: pendingHeaders,
metrics: seqMetrics,
sequencer: sequencer,
exec: exec,
da: da,
gasPrice: gasPrice,
gasMultiplier: gasMultiplier,
txNotifyCh: make(chan struct{}, 1),
validatorHasher: validatorHasher,
}
agg.init(ctx)
// Set the default publishBlock implementation
Expand Down Expand Up @@ -455,7 +459,7 @@ func (m *Manager) retrieveBatch(ctx context.Context) (*BatchData, error) {
if len(res.Batch.Transactions) == 0 {
errRetrieveBatch = ErrNoBatch
}
// Even if there are no transactions, update lastBatchData so we don’t
// Even if there are no transactions, update lastBatchData so we don't
// repeatedly emit the same empty batch, and persist it to metadata.
if err := m.store.SetMetadata(ctx, LastBatchDataKey, convertBatchDataToBytes(res.BatchData)); err != nil {
m.logger.Error("error while setting last batch hash", "error", err)
Expand Down Expand Up @@ -697,6 +701,19 @@ func (m *Manager) execCreateBlock(ctx context.Context, height uint64, lastSignat
return nil, nil, fmt.Errorf("proposer address is not the same as the genesis proposer address %x != %x", address, m.genesis.ProposerAddress)
}

var validatorHash types.Hash
if m.validatorHasher != nil {
calculatedVHash, err := m.validatorHasher(m.genesis.ProposerAddress, key)
if err != nil {
m.logger.Info("Failed to calculate ValidatorHash using injected hasher", "error", err)
} else {
validatorHash = calculatedVHash
m.logger.Info("Successfully calculated ValidatorHash using injected hasher", "validatorHash", hex.EncodeToString(validatorHash))
}
} else {
m.logger.Info("ValidatorHasher not provided to Manager, ValidatorHash will be zero.")
}

Comment on lines +854 to 865

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider consistent error handling for missing providers.

The validatorHasher logs and continues with a zero hash when the provider is missing, while getSignature returns an error. Consider adopting a consistent approach across all provider usages.

 var validatorHash types.Hash
 if m.validatorHasher != nil {
 	calculatedVHash, err := m.validatorHasher(m.genesis.ProposerAddress, key)
 	if err != nil {
-		m.logger.Info("Failed to calculate ValidatorHash using injected hasher", "error", err)
+		return nil, nil, fmt.Errorf("failed to calculate validator hash: %w", err)
 	} else {
 		validatorHash = calculatedVHash
 		m.logger.Info("Successfully calculated ValidatorHash using injected hasher", "validatorHash", hex.EncodeToString(validatorHash))
 	}
 } else {
-	m.logger.Info("ValidatorHasher not provided to Manager, ValidatorHash will be zero.")
+	return nil, nil, errors.New("validatorHasher is required but not provided")
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if m.validatorHasher != nil {
calculatedVHash, err := m.validatorHasher(m.genesis.ProposerAddress, key)
if err != nil {
m.logger.Info("Failed to calculate ValidatorHash using injected hasher", "error", err)
} else {
validatorHash = calculatedVHash
m.logger.Info("Successfully calculated ValidatorHash using injected hasher", "validatorHash", hex.EncodeToString(validatorHash))
}
} else {
m.logger.Info("ValidatorHasher not provided to Manager, ValidatorHash will be zero.")
}
var validatorHash types.Hash
if m.validatorHasher != nil {
calculatedVHash, err := m.validatorHasher(m.genesis.ProposerAddress, key)
if err != nil {
return nil, nil, fmt.Errorf("failed to calculate validator hash: %w", err)
} else {
validatorHash = calculatedVHash
m.logger.Info("Successfully calculated ValidatorHash using injected hasher", "validatorHash", hex.EncodeToString(validatorHash))
}
} else {
return nil, nil, errors.New("validatorHasher is required but not provided")
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 842-842: block/manager.go#L842
Added line #L842 was not covered by tests


[warning] 847-849: block/manager.go#L847-L849
Added lines #L847 - L849 were not covered by tests

🤖 Prompt for AI Agents
In block/manager.go around lines 839 to 850, the handling of a missing
validatorHasher is inconsistent with other provider usages like getSignature;
here it logs and continues with a zero hash, whereas getSignature returns an
error. Modify the code to return an error when validatorHasher is nil instead of
just logging and proceeding, ensuring consistent error handling across all
provider usages.

// Determine if this is an empty block
isEmpty := batchData.Batch == nil || len(batchData.Transactions) == 0

Expand All @@ -711,7 +728,7 @@ func (m *Manager) execCreateBlock(ctx context.Context, height uint64, lastSignat
header := &types.SignedHeader{
Header: types.Header{
Version: types.Version{
Block: m.lastState.Version.Block,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Block: 11, // hardcoded
Comment thread
randygrok marked this conversation as resolved.
Outdated
Comment thread
randygrok marked this conversation as resolved.
Outdated
App: m.lastState.Version.App,
},
BaseHeader: types.BaseHeader{
Expand All @@ -724,6 +741,7 @@ func (m *Manager) execCreateBlock(ctx context.Context, height uint64, lastSignat
ConsensusHash: make(types.Hash, 32),
AppHash: m.lastState.AppHash,
ProposerAddress: m.genesis.ProposerAddress,
ValidatorHash: validatorHash,
},
Signature: *lastSignature,
Signer: types.Signer{
Expand Down
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
5 changes: 5 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,7 @@ func newFullNode(
da coreda.DA,
metricsProvider MetricsProvider,
logger log.Logger,
validatorHasher types.ValidatorHasher,
) (fn *FullNode, err error) {
seqMetrics, _ := metricsProvider(genesis.ChainID)

Expand Down Expand Up @@ -112,6 +114,7 @@ func newFullNode(
seqMetrics,
nodeConfig.DA.GasPrice,
nodeConfig.DA.GasMultiplier,
validatorHasher,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -198,6 +201,7 @@ func initBlockManager(
seqMetrics *block.Metrics,
gasPrice float64,
gasMultiplier float64,
validatorHasher types.ValidatorHasher,
) (*block.Manager, error) {
logger.Debug("Proposer address", "address", genesis.ProposerAddress)

Expand All @@ -216,6 +220,7 @@ func initBlockManager(
seqMetrics,
gasPrice,
gasMultiplier,
validatorHasher,
)
if err != nil {
return nil, fmt.Errorf("error while initializing BlockManager: %w", err)
Expand Down
3 changes: 3 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,7 @@ func NewNode(
database ds.Batching,
metricsProvider MetricsProvider,
logger log.Logger,
validatorHasher types.ValidatorHasher,
Comment thread
randygrok marked this conversation as resolved.
Outdated
) (Node, error) {
if conf.Node.Light {
return newLightNode(conf, genesis, p2pClient, nodeKey, database, logger)
Expand All @@ -58,5 +60,6 @@ func NewNode(
da,
metricsProvider,
logger,
validatorHasher,
)
}
10 changes: 10 additions & 0 deletions types/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
import (
"crypto/sha256"
"hash"

"github.com/libp2p/go-libp2p/core/crypto"
)

var (
Expand Down Expand Up @@ -33,3 +35,11 @@ func leafHashOpt(s hash.Hash, leaf []byte) []byte {
s.Write(leaf)
return s.Sum(nil)
}

// ValidatorHasher defines the function signature for a component that can calculate
// the ValidatorHash for a block header.
// It takes the proposer's address and public key (as known by Rollkit's signer)
// and is expected to return a types.Hash compatible with the target consensus system (e.g., CometBFT).
// If the hasher is not configured or an error occurs, it should be handled appropriately
// by the caller (e.g., using a zero hash or returning an error).
type ValidatorHasher func(proposerAddress []byte, pubKey crypto.PubKey) (Hash, error)
2 changes: 1 addition & 1 deletion types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// The Consensus.App version will be set during the Handshake, once
// we hear from the app what protocol version it is running.
var InitStateVersion = Version{
Block: 1,
Block: 11,
Comment thread
randygrok marked this conversation as resolved.
Outdated
App: 0,
}

Expand Down