Skip to content

feat: fix IBC #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4a00e43
some refactors
randygrok May 21, 2025
90b41ee
Merge branch 'main' into feat/fix-ibc
randygrok May 21, 2025
c02a0bb
update adapter and fix
randygrok May 23, 2025
52d17df
Merge branch 'feat/fix-ibc' of github.com-randy:rollkit/go-execution-…
randygrok May 23, 2025
0496245
add signature payload provider
randygrok May 26, 2025
3536797
add header hasher
randygrok May 26, 2025
59a24ad
remove old passing of commit between layers
randygrok May 26, 2025
be850b6
build blocks
randygrok May 26, 2025
b1d2d4c
remove attestation fields that are not needed
randygrok May 27, 2025
a842ae1
remove usage of attestation on several places
randygrok May 27, 2025
c0979a0
add test
randygrok May 27, 2025
9f3846e
add test for validation of signature
randygrok May 27, 2025
9a250bb
commit pre clean
randygrok May 27, 2025
b746bce
Merge remote-tracking branch 'origin/main' into feat/fix-ibc
randygrok May 27, 2025
4585ebc
fix after merge
randygrok May 28, 2025
38a4ab1
fix tests
randygrok May 28, 2025
d01f033
remove some comments
randygrok May 28, 2025
0c0ce26
update go mod
randygrok May 28, 2025
450fec3
go mod tidy
randygrok May 28, 2025
4d84d69
fix linter
randygrok May 29, 2025
9d99a5d
linter
randygrok May 30, 2025
24b1479
add go mod update
randygrok May 30, 2025
ca03b26
update dependency
randygrok Jun 3, 2025
f41ee25
use new options manager
randygrok Jun 3, 2025
9990da1
Merge remote-tracking branch 'origin/main' into feat/fix-ibc
randygrok Jun 3, 2025
0986c52
add hasher as global
randygrok Jun 4, 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ require (
github.com/libp2p/go-libp2p-pubsub v0.13.1
github.com/multiformats/go-multiaddr v0.15.0
github.com/prometheus/client_golang v1.22.0
github.com/rollkit/rollkit v0.14.2-0.20250526094218-4a5686055970
github.com/rollkit/rollkit/core v0.0.0-20250526094218-4a5686055970
github.com/rollkit/rollkit v0.14.2-0.20250529164851-d4b4a1e88558
github.com/rollkit/rollkit/core v0.0.0-20250529164851-d4b4a1e88558
github.com/rollkit/rollkit/da v0.0.0-20250526094218-4a5686055970
github.com/rollkit/rollkit/sequencers/single v0.0.0-20250526094218-4a5686055970
github.com/rs/cors v1.11.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,10 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/rollkit/rollkit v0.14.2-0.20250526094218-4a5686055970 h1:KL0gIjEEMf9ETxsN4iGj707q8w8v6HJVngMOhex9mnY=
github.com/rollkit/rollkit v0.14.2-0.20250526094218-4a5686055970/go.mod h1:7IgdPhN0q+TyVnzrNyMY6XIta2Tv+xUeQ82XAnHk9X0=
github.com/rollkit/rollkit/core v0.0.0-20250526094218-4a5686055970 h1:CM3cIruk4DwrdcTjfvYJpK4YmucSe4AWyLRNulRbDKs=
github.com/rollkit/rollkit/core v0.0.0-20250526094218-4a5686055970/go.mod h1:0RhbqC8Is970KRhr6zPUQOZkmKt6/WqPRDQWfd2P7P0=
github.com/rollkit/rollkit v0.14.2-0.20250529164851-d4b4a1e88558 h1:LenIlcgTjZ89MtiYa+2rx1l84hs0jKrxkhjfD3AJcSQ=
github.com/rollkit/rollkit v0.14.2-0.20250529164851-d4b4a1e88558/go.mod h1:Gw1i+hGmPp9Y7b05SXlqGj+tnXhzaiW/xs4wboXsEL0=
github.com/rollkit/rollkit/core v0.0.0-20250529164851-d4b4a1e88558 h1:0jWzjfP/DQSdsRYnIMPNAD7itd8Oq7roV3cu9MddTEA=
github.com/rollkit/rollkit/core v0.0.0-20250529164851-d4b4a1e88558/go.mod h1:0RhbqC8Is970KRhr6zPUQOZkmKt6/WqPRDQWfd2P7P0=
github.com/rollkit/rollkit/da v0.0.0-20250526094218-4a5686055970 h1:PnnQLIkI119NALSqI91peceGsqnBVyBBeyunk6auTpM=
github.com/rollkit/rollkit/da v0.0.0-20250526094218-4a5686055970/go.mod h1:MqbHTMhjb1PGbGaZ7bVddCm5OJg1+GMVEPpERdsO058=
github.com/rollkit/rollkit/sequencers/single v0.0.0-20250526094218-4a5686055970 h1:vQVPtGxKquSxE74CtA/kv2OmtyIDKivKYT8AcRjFNak=
Expand Down
135 changes: 125 additions & 10 deletions pkg/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/bytes"
"github.com/cometbft/cometbft/mempool"
corep2p "github.com/cometbft/cometbft/p2p"
types1 "github.com/cometbft/cometbft/proto/tendermint/types"
cmtstate "github.com/cometbft/cometbft/state"
cmttypes "github.com/cometbft/cometbft/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -25,6 +27,7 @@ import (
rollnode "github.com/rollkit/rollkit/node"
rollkitp2p "github.com/rollkit/rollkit/pkg/p2p"
rstore "github.com/rollkit/rollkit/pkg/store"
"github.com/rollkit/rollkit/types"

"github.com/rollkit/go-execution-abci/pkg/p2p"
)
Expand Down Expand Up @@ -244,6 +247,7 @@ func (a *Adapter) InitChain(ctx context.Context, genesisTime time.Time, initialH
} else {
s.ConsensusParams = cmttypes.ConsensusParamsFromProto(consensusParams)
}
s.ChainID = chainID

vals, err := cmttypes.PB2TM.ValidatorUpdates(res.Validators)
if err != nil {
Expand Down Expand Up @@ -279,6 +283,7 @@ func (a *Adapter) ExecuteTxs(
blockHeight uint64,
timestamp time.Time,
prevStateRoot []byte,
metadata map[string]interface{},
) ([]byte, uint64, error) {
execStart := time.Now()
defer func() {
Expand All @@ -287,19 +292,53 @@ func (a *Adapter) ExecuteTxs(
a.Logger.Info("Executing block", "height", blockHeight, "num_txs", len(txs), "timestamp", timestamp)
a.Metrics.TxsExecutedPerBlock.Observe(float64(len(txs)))

var headerHash types.Hash
if h, ok := metadata[types.HeaderHashKey]; ok {
headerHash = h.(types.Hash)
} else {
a.Logger.Info("header hash not found in metadata, running genesis block")
}
Comment on lines +295 to +300
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding validation for the header hash type assertion.

While the code handles the case when header hash is not found (genesis block), the type assertion on line 297 could panic if the metadata contains an unexpected type.

Add type assertion safety check:

 var headerHash types.Hash
 if h, ok := metadata[types.HeaderHashKey]; ok {
-    headerHash = h.(types.Hash)
+    if hash, ok := h.(types.Hash); ok {
+        headerHash = hash
+    } else {
+        return nil, 0, fmt.Errorf("invalid header hash type in metadata: expected types.Hash, got %T", h)
+    }
 } else {
     a.Logger.Info("header hash not found in metadata, running genesis block")
 }
📝 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
var headerHash types.Hash
if h, ok := metadata[types.HeaderHashKey]; ok {
headerHash = h.(types.Hash)
} else {
a.Logger.Info("header hash not found in metadata, running genesis block")
}
var headerHash types.Hash
if h, ok := metadata[types.HeaderHashKey]; ok {
if hash, ok := h.(types.Hash); ok {
headerHash = hash
} else {
return nil, 0, fmt.Errorf(
"invalid header hash type in metadata: expected types.Hash, got %T", h,
)
}
} else {
a.Logger.Info("header hash not found in metadata, running genesis block")
}
🤖 Prompt for AI Agents
In pkg/adapter/adapter.go around lines 295 to 300, the type assertion for
headerHash from metadata can panic if the type is unexpected. Modify the code to
use the two-value form of type assertion to safely check the type. If the
assertion fails, log an appropriate error or handle the case gracefully instead
of panicking.

Comment on lines +295 to +300
Copy link

Choose a reason for hiding this comment

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

The code is attempting to access metadata[types.HeaderHashKey] without first checking if metadata is nil. This could cause a panic when metadata is nil (which happens in the test). Consider adding a nil check before accessing the map:

if metadata != nil {
    if h, ok := metadata[types.HeaderHashKey]; ok {
        headerHash = h.(types.Hash)
    } else {
        a.Logger.Info("header hash not found in metadata, running genesis block")
    }
} else {
    a.Logger.Info("metadata is nil, running genesis block")
}

This will prevent nil pointer dereference panics when metadata is nil.

Suggested change
var headerHash types.Hash
if h, ok := metadata[types.HeaderHashKey]; ok {
headerHash = h.(types.Hash)
} else {
a.Logger.Info("header hash not found in metadata, running genesis block")
}
var headerHash types.Hash
if metadata != nil {
if h, ok := metadata[types.HeaderHashKey]; ok {
headerHash = h.(types.Hash)
} else {
a.Logger.Info("header hash not found in metadata, running genesis block")
}
} else {
a.Logger.Info("metadata is nil, running genesis block")
}

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.


s, err := a.Store.LoadState(ctx)
if err != nil {
return nil, 0, fmt.Errorf("failed to load state: %w", err)
}

var proposedLastCommit abci.CommitInfo
if blockHeight > 1 {
header, data, err := a.RollkitStore.GetBlockData(ctx, blockHeight-1)
if err != nil {
return nil, 0, fmt.Errorf("failed to get previous block data: %w", err)
}

commitForPrevBlock := &cmttypes.Commit{
Height: int64(header.Height()),
Round: 0,
BlockID: cmttypes.BlockID{Hash: bytes.HexBytes(header.Hash()), PartSetHeader: cmttypes.PartSetHeader{Total: 1, Hash: bytes.HexBytes(data.Hash())}},
Signatures: []cmttypes.CommitSig{
{
BlockIDFlag: cmttypes.BlockIDFlagCommit,
ValidatorAddress: cmttypes.Address(header.ProposerAddress),
Timestamp: header.Time(),
Signature: header.Signature,
},
},
}
proposedLastCommit = cometCommitToABCICommitInfo(commitForPrevBlock)
} else {
// For the first block, ProposedLastCommit is empty
proposedLastCommit = abci.CommitInfo{Round: 0, Votes: []abci.VoteInfo{}}
}

ppResp, err := a.App.ProcessProposal(&abci.RequestProcessProposal{
Txs: txs,
ProposedLastCommit: abci.CommitInfo{},
Hash: prevStateRoot,
Hash: headerHash,
Height: int64(blockHeight),
Time: timestamp,
NextValidatorsHash: s.NextValidators.Hash(),
Txs: txs,
ProposedLastCommit: proposedLastCommit,
Misbehavior: []abci.Misbehavior{},
ProposerAddress: s.Validators.Proposer.Address,
NextValidatorsHash: s.NextValidators.Hash(),
})
if err != nil {
return nil, 0, err
Expand All @@ -310,17 +349,24 @@ func (a *Adapter) ExecuteTxs(
}

fbResp, err := a.App.FinalizeBlock(&abci.RequestFinalizeBlock{
Txs: txs,
Hash: prevStateRoot,
Height: int64(blockHeight),
Time: timestamp,
Hash: headerHash,
NextValidatorsHash: s.NextValidators.Hash(),
ProposerAddress: s.Validators.Proposer.Address,
Height: int64(blockHeight),
Time: timestamp,
DecidedLastCommit: abci.CommitInfo{
Round: 0,
Votes: nil,
},
Txs: txs,
})
if err != nil {
return nil, 0, err
}

s.AppHash = fbResp.AppHash
s.LastBlockHeight = int64(blockHeight)

nValSet := s.NextValidators.Copy()

validatorUpdates, err := cmttypes.PB2TM.ValidatorUpdates(fbResp.ValidatorUpdates)
Expand Down Expand Up @@ -404,8 +450,46 @@ func (a *Adapter) ExecuteTxs(
for i := range txs {
cmtTxs[i] = txs[i]
}
block := s.MakeBlock(int64(blockHeight), cmtTxs, &cmttypes.Commit{Height: int64(blockHeight)}, nil, s.Validators.Proposer.Address)
fireEvents(a.Logger, a.EventBus, block, cmttypes.BlockID{}, fbResp, validatorUpdates)

var commit = &cmttypes.Commit{
Height: int64(blockHeight),
Round: 0,
Signatures: []cmttypes.CommitSig{
{
BlockIDFlag: cmttypes.BlockIDFlagCommit,
ValidatorAddress: s.Validators.Proposer.Address,
Timestamp: time.Now(),
Copy link

Choose a reason for hiding this comment

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

The timestamp for the commit signature should match the block's timestamp rather than using time.Now(). Using the current time creates inconsistency between the block timestamp and commit timestamp, which could cause validation issues. Consider using the block's timestamp value instead to ensure consistency throughout the block data structure.

Suggested change
Timestamp: time.Now(),
Timestamp: blockTimestamp,

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Signature: []byte{},
},
},
}

if blockHeight > 1 {
header, data, err := a.RollkitStore.GetBlockData(ctx, blockHeight-1)
if err != nil {
return nil, 0, fmt.Errorf("failed to get previous block data: %w", err)
}

commit = &cmttypes.Commit{
Height: int64(header.Height()),
Round: 0,
BlockID: cmttypes.BlockID{Hash: bytes.HexBytes(header.Hash()), PartSetHeader: cmttypes.PartSetHeader{Total: 1, Hash: bytes.HexBytes(data.Hash())}},
Signatures: []cmttypes.CommitSig{
{
BlockIDFlag: cmttypes.BlockIDFlagCommit,
ValidatorAddress: cmttypes.Address(header.ProposerAddress),
Timestamp: header.Time(),
Signature: header.Signature,
},
},
}
}
Comment on lines +454 to +486
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Redundant commit construction logic.

The commit construction logic appears twice - once for proposedLastCommit (lines 314-326) and again here (lines 473-485). This duplication could lead to maintenance issues.

Consider extracting the commit construction into a helper function:

+func (a *Adapter) buildCommitFromPreviousBlock(ctx context.Context, blockHeight uint64) (*cmttypes.Commit, error) {
+    if blockHeight <= 1 {
+        return &cmttypes.Commit{
+            Height: int64(blockHeight),
+            Round:  0,
+            Signatures: []cmttypes.CommitSig{
+                {
+                    BlockIDFlag:      cmttypes.BlockIDFlagCommit,
+                    ValidatorAddress: nil, // or appropriate default
+                    Timestamp:        time.Now(),
+                    Signature:        []byte{},
+                },
+            },
+        }, nil
+    }
+    
+    header, data, err := a.RollkitStore.GetBlockData(ctx, blockHeight-1)
+    if err != nil {
+        return nil, fmt.Errorf("failed to get previous block data: %w", err)
+    }
+    
+    return &cmttypes.Commit{
+        Height:  int64(header.Height()),
+        Round:   0,
+        BlockID: cmttypes.BlockID{Hash: bytes.HexBytes(header.Hash()), PartSetHeader: cmttypes.PartSetHeader{Total: 1, Hash: bytes.HexBytes(data.Hash())}},
+        Signatures: []cmttypes.CommitSig{
+            {
+                BlockIDFlag:      cmttypes.BlockIDFlagCommit,
+                ValidatorAddress: cmttypes.Address(header.ProposerAddress),
+                Timestamp:        header.Time(),
+                Signature:        header.Signature,
+            },
+        },
+    }, nil
+}

Then use it in both places to eliminate duplication.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In pkg/adapter/adapter.go around lines 454 to 486, the commit construction logic
is duplicated, which can cause maintenance problems. Extract the commit creation
code into a separate helper function that takes necessary parameters like block
height and block data, then call this helper function in both places where the
commit is constructed to remove redundancy and improve code maintainability.


block := s.MakeBlock(int64(blockHeight), cmtTxs, commit, nil, s.Validators.Proposer.Address)

currentBlockID := cmttypes.BlockID{Hash: block.Hash(), PartSetHeader: cmttypes.PartSetHeader{Total: 1, Hash: block.DataHash}}

fireEvents(a.Logger, a.EventBus, block, currentBlockID, fbResp, validatorUpdates)

a.Logger.Info("block executed successfully", "height", blockHeight, "appHash", fmt.Sprintf("%X", fbResp.AppHash))
return fbResp.AppHash, uint64(s.ConsensusParams.Block.MaxBytes), nil
Expand Down Expand Up @@ -521,3 +605,34 @@ func (a *Adapter) GetTxs(ctx context.Context) ([][]byte, error) {
func (a *Adapter) SetFinal(ctx context.Context, blockHeight uint64) error {
return nil
}

func cometCommitToABCICommitInfo(commit *cmttypes.Commit) abci.CommitInfo {
if commit == nil {
return abci.CommitInfo{
Round: 0,
Votes: []abci.VoteInfo{},
}
}

if len(commit.Signatures) == 0 {
return abci.CommitInfo{
Round: commit.Round,
Votes: []abci.VoteInfo{},
}
}

votes := make([]abci.VoteInfo, len(commit.Signatures))
for i, sig := range commit.Signatures {
votes[i] = abci.VoteInfo{
Validator: abci.Validator{
Address: sig.ValidatorAddress,
Power: 0,
},
BlockIdFlag: types1.BlockIDFlag(sig.BlockIDFlag),
}
}
return abci.CommitInfo{
Round: commit.Round,
Votes: votes,
}
}
2 changes: 1 addition & 1 deletion pkg/adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestExecuteFiresEvents(t *testing.T) {
require.NoError(t, adapter.Store.SaveState(ctx, stateFixture()))

// when
_, _, err := adapter.ExecuteTxs(ctx, spec.txs, 1, timestamp, bytes.Repeat([]byte{1}, 32))
_, _, err := adapter.ExecuteTxs(ctx, spec.txs, 1, timestamp, bytes.Repeat([]byte{1}, 32), nil)
if spec.expErr {
require.Error(t, err)
blockMx.RLock()
Expand Down
11 changes: 6 additions & 5 deletions pkg/common/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"time"

cmbytes "github.com/cometbft/cometbft/libs/bytes"
cmversion "github.com/cometbft/cometbft/proto/tendermint/version"
cmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version"
cmttypes "github.com/cometbft/cometbft/types"
cmtversion "github.com/cometbft/cometbft/version"

rlktypes "github.com/rollkit/rollkit/types"
)
Expand All @@ -15,14 +16,14 @@ import (
// Caller should fill all the fields that are not available in Rollkit header (like ChainID).
func ToABCIHeader(header *rlktypes.Header) (cmttypes.Header, error) {
return cmttypes.Header{
Version: cmversion.Consensus{
Block: header.Version.Block,
Version: cmprotoversion.Consensus{
Block: cmtversion.BlockProtocol,
App: header.Version.App,
},
Height: int64(header.Height()), //nolint:gosec
Time: header.Time(),
LastBlockID: cmttypes.BlockID{
Hash: cmbytes.HexBytes(header.LastHeaderHash[:]),
Hash: cmbytes.HexBytes(header.LastHeaderHash),
PartSetHeader: cmttypes.PartSetHeader{
Total: 0,
Hash: nil,
Expand Down Expand Up @@ -94,7 +95,7 @@ func ToABCIBlockMeta(header *rlktypes.SignedHeader, data *rlktypes.Data) (*cmtty

// ToABCICommit returns a commit format defined by ABCI.
// Other fields (especially ValidatorAddress and Timestamp of Signature) have to be filled by caller.
func ToABCICommit(height uint64, hash rlktypes.Hash, val cmttypes.Address, time time.Time, signature rlktypes.Signature) *cmttypes.Commit {
func ToABCICommit(height uint64, hash []byte, val cmttypes.Address, time time.Time, signature rlktypes.Signature) *cmttypes.Commit {
return &cmttypes.Commit{
Height: int64(height), //nolint:gosec
Round: 0,
Expand Down
16 changes: 16 additions & 0 deletions pkg/rollkit_adapter/commit_hasher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package rollkitadapter
Copy link

Choose a reason for hiding this comment

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

The package name rollkitadapter doesn't match its directory name rollkit_adapter. Go convention recommends that package names match their directory names, using lowercase single words without underscores. Consider either:

  1. Renaming the package to rollkit_adapter to match the directory, or
  2. Renaming the directory to rollkitadapter to match the package name

This will improve code organization and make imports more intuitive for other developers.

Spotted by Diamond (based on custom rules)

Is this helpful? React 👍 or 👎 to let us know.


import (
"github.com/rollkit/rollkit/types"

"github.com/rollkit/go-execution-abci/pkg/rpc"
)

func CreateCometBFTCommitHasher() types.CommitHashProvider {
return func(signature *types.Signature, header *types.Header, proposerAddress []byte) (types.Hash, error) {
abciCommit := rpc.GetABCICommit(header.Height(), header.Hash(), proposerAddress, header.Time(), *signature)
abciCommit.Signatures[0].ValidatorAddress = proposerAddress
abciCommit.Signatures[0].Timestamp = header.Time()
return types.Hash(abciCommit.Hash()), nil
}
}
Comment on lines +9 to +16
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant field assignments.

Lines 12-13 are redundant as GetABCICommit already sets these fields with the same values:

  • ValidatorAddress is set to proposerAddress (line 141 in GetABCICommit)
  • Timestamp is set to header.Time() (line 142 in GetABCICommit)

Apply this diff to remove the redundant assignments:

 func CreateCometBFTCommitHasher() types.CommitHashProvider {
 	return func(signature *types.Signature, header *types.Header, proposerAddress []byte) (types.Hash, error) {
 		abciCommit := rpc.GetABCICommit(header.Height(), header.Hash(), proposerAddress, header.Time(), *signature)
-		abciCommit.Signatures[0].ValidatorAddress = proposerAddress
-		abciCommit.Signatures[0].Timestamp = header.Time()
 		return types.Hash(abciCommit.Hash()), nil
 	}
 }
📝 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
func CreateCometBFTCommitHasher() types.CommitHashProvider {
return func(signature *types.Signature, header *types.Header, proposerAddress []byte) (types.Hash, error) {
abciCommit := rpc.GetABCICommit(header.Height(), header.Hash(), proposerAddress, header.Time(), *signature)
abciCommit.Signatures[0].ValidatorAddress = proposerAddress
abciCommit.Signatures[0].Timestamp = header.Time()
return types.Hash(abciCommit.Hash()), nil
}
}
func CreateCometBFTCommitHasher() types.CommitHashProvider {
return func(signature *types.Signature, header *types.Header, proposerAddress []byte) (types.Hash, error) {
abciCommit := rpc.GetABCICommit(header.Height(), header.Hash(), proposerAddress, header.Time(), *signature)
return types.Hash(abciCommit.Hash()), nil
}
}
🤖 Prompt for AI Agents
In pkg/rollkit_adapter/commit_hasher.go between lines 9 and 16, remove the
redundant assignments to abciCommit.Signatures[0].ValidatorAddress and
abciCommit.Signatures[0].Timestamp on lines 12 and 13, since GetABCICommit
already sets these fields with the correct values. Simply delete these two lines
to clean up the code.

18 changes: 18 additions & 0 deletions pkg/rollkit_adapter/header_hasher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package rollkitadapter

import (
"github.com/rollkit/rollkit/types"

"github.com/rollkit/go-execution-abci/pkg/common"
)

func CreateCometBFTHeaderHasher() types.HeaderHasher {
return func(header *types.Header) (types.Hash, error) {
abciHeader, err := common.ToABCIHeader(header)
if err != nil {
return nil, err
}

return types.Hash(abciHeader.Hash()), nil
}
}
35 changes: 35 additions & 0 deletions pkg/rollkit_adapter/signer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package rollkitadapter

import (
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtypes "github.com/cometbft/cometbft/types"

"github.com/rollkit/rollkit/types"

"github.com/rollkit/go-execution-abci/pkg/rpc"
)

func CreateCometBFTPayloadProvider() types.SignaturePayloadProvider {
return func(header *types.Header, data *types.Data) ([]byte, error) {
abciHeaderForSigning, err := rpc.ToABCIHeader(header)
if err != nil {
return nil, err
}
vote := cmtproto.Vote{
Type: cmtproto.PrecommitType,
Height: int64(header.Height()), //nolint:gosec
Round: 0,
BlockID: cmtproto.BlockID{
Hash: abciHeaderForSigning.Hash(),
PartSetHeader: cmtproto.PartSetHeader{},
},
Timestamp: header.Time(),
ValidatorAddress: header.ProposerAddress,
ValidatorIndex: 0,
}
chainID := header.ChainID()
consensusVoteBytes := cmtypes.VoteSignBytes(chainID, &vote)

return consensusVoteBytes, nil
}
}
Loading
Loading