Skip to content

Feature branch Attesteer System WIP #173

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
508 changes: 508 additions & 0 deletions modules/rollkitmngr/keeper/rollkit_block_test.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pkg/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"github.com/rollkit/go-execution-abci/pkg/p2p"
)

var _ execution.Executor = &Adapter{}

Check failure on line 39 in pkg/adapter/adapter.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

cannot use &Adapter{} (value of type *Adapter) as execution.Executor value in variable declaration: *Adapter does not implement execution.Executor (missing method GetExecutionMode) (typecheck)

Check failure on line 39 in pkg/adapter/adapter.go

View workflow job for this annotation

GitHub Actions / test / Run Unit Tests

cannot use &Adapter{} (value of type *Adapter) as execution.Executor value in variable declaration: *Adapter does not implement execution.Executor (missing method GetExecutionMode)

type P2PClientInfo interface {
Info() (string, string, string, error)
Expand Down Expand Up @@ -327,7 +327,7 @@
return nil, 0, fmt.Errorf("get last commit: %w", err)
}

emptyBlock, err := cometcompat.ToABCIBlock(header, &types.Data{}, lastCommit)
emptyBlock, err := cometcompat.ToABCIBlock(header, &types.Data{}, lastCommit) // todo (Alex): is an empty valset correct?
if err != nil {
return nil, 0, fmt.Errorf("compute header hash: %w", err)
}
Expand Down Expand Up @@ -732,6 +732,6 @@
return nil
}

func (a *Adapter) GetExecutionMode() execution.ExecutionMode {
return execution.ExecutionModeDelayed
}
//func (a *Adapter) GetExecutionMode() execution.ExecutionMode {
// return execution.ExecutionModeDelayed
//}
20 changes: 20 additions & 0 deletions pkg/adapter/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
proto "github.com/cosmos/gogoproto/proto"
ds "github.com/ipfs/go-datastore"
kt "github.com/ipfs/go-datastore/keytransform"
rollkittypes "github.com/rollkit/rollkit/types"
)

const (
Expand Down Expand Up @@ -105,3 +106,22 @@ func (s *Store) GetBlockResponse(ctx context.Context, height uint64) (*abci.Resp

return resp, nil
}

func ValidatorHasher(store *Store) func() (rollkittypes.Hash, error) {
return func() (rollkittypes.Hash, error) {
s, err := store.LoadState(context.Background())

Choose a reason for hiding this comment

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

high

Using context.Background() here prevents cancellation or timeouts. Consider using a context passed from the caller to allow for better control over the operation's lifecycle.


if err != nil {
return make(rollkittypes.Hash, 32), err
}

hash := s.Validators.Hash()

fmt.Printf("validator hash: %x\n", hash)

Choose a reason for hiding this comment

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

medium

The fmt.Printf statement seems to be a debugging artifact. Remove it or replace it with structured logging using a logger instance for production code.


if hash == nil {
return make(rollkittypes.Hash, 32), nil
}
return hash, nil
}
}
27 changes: 14 additions & 13 deletions pkg/cometcompat/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cometcompat

import (
"errors"
"fmt"

cmbytes "github.com/cometbft/cometbft/libs/bytes"
cmprotoversion "github.com/cometbft/cometbft/proto/tendermint/version"
cmttypes "github.com/cometbft/cometbft/types"
Expand All @@ -13,7 +11,11 @@ import (
)

// ToABCIBlock converts Rolkit block into block format defined by ABCI.
func ToABCIBlock(header *rlktypes.SignedHeader, data *rlktypes.Data, lastCommit *cmttypes.Commit) (*cmttypes.Block, error) {
func ToABCIBlock(
header *rlktypes.SignedHeader,
data *rlktypes.Data,
lastCommit *cmttypes.Commit,
) (*cmttypes.Block, error) {
abciHeader, err := ToABCIHeader(&header.Header)
if err != nil {
return nil, err
Expand All @@ -27,15 +29,9 @@ func ToABCIBlock(header *rlktypes.SignedHeader, data *rlktypes.Data, lastCommit
// set commit hash
abciHeader.LastCommitHash = lastCommit.Hash()

// set validator hash
if header.Signer.Address != nil {
validatorHash, err := validatorHasher(header.ProposerAddress, header.Signer.PubKey)
if err != nil {
return nil, fmt.Errorf("failed to compute validator hash: %w", err)
}
abciHeader.ValidatorsHash = cmbytes.HexBytes(validatorHash)
abciHeader.NextValidatorsHash = cmbytes.HexBytes(validatorHash)
}
validatorHash := header.ValidatorHash
abciHeader.ValidatorsHash = cmbytes.HexBytes(validatorHash)
abciHeader.NextValidatorsHash = cmbytes.HexBytes(validatorHash)

abciBlock := cmttypes.Block{
Header: abciHeader,
Expand All @@ -54,8 +50,13 @@ func ToABCIBlock(header *rlktypes.SignedHeader, data *rlktypes.Data, lastCommit
}

// ToABCIBlockMeta converts Rollkit block into BlockMeta format defined by ABCI
func ToABCIBlockMeta(header *rlktypes.SignedHeader, data *rlktypes.Data, lastCommit *cmttypes.Commit) (*cmttypes.BlockMeta, error) {
func ToABCIBlockMeta(
header *rlktypes.SignedHeader,
data *rlktypes.Data,
lastCommit *cmttypes.Commit,
) (*cmttypes.BlockMeta, error) {
cmblock, err := ToABCIBlock(header, data, lastCommit)

if err != nil {
return nil, err
}
Expand Down
54 changes: 0 additions & 54 deletions pkg/cometcompat/validator_hasher.go

This file was deleted.

34 changes: 16 additions & 18 deletions pkg/rpc/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)
return nil, fmt.Errorf("failed to get last commit for block %d: %w", heightValue, err)
}

// First apply ToABCIBlock to get the final header with all transformations
abciBlock, err := cometcompat.ToABCIBlock(header, data, lastCommit)
block, err := cometcompat.ToABCIBlock(header, data, lastCommit)
if err != nil {
return nil, err
}
Expand All @@ -149,10 +148,10 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)
Height: int64(header.Height()), //nolint:gosec
Round: 0,
BlockID: cmtproto.BlockID{
Hash: abciBlock.Header.Hash(),
Hash: block.Header.Hash(),
PartSetHeader: cmtproto.PartSetHeader{},
},
Timestamp: abciBlock.Time,
Timestamp: block.Time,
ValidatorAddress: header.ProposerAddress,
ValidatorIndex: 0,
}
Expand All @@ -165,14 +164,14 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)
}

// Update the signature in the block
if len(abciBlock.LastCommit.Signatures) > 0 {
abciBlock.LastCommit.Signatures[0].Signature = newSignature
if len(block.LastCommit.Signatures) > 0 {
block.LastCommit.Signatures[0].Signature = newSignature
}
}

return &ctypes.ResultBlock{
BlockID: cmttypes.BlockID{Hash: abciBlock.Hash()},
Block: abciBlock,
BlockID: cmttypes.BlockID{Hash: block.Hash()},
Block: block,
}, nil
}

Expand All @@ -189,7 +188,7 @@ func BlockByHash(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error
return nil, fmt.Errorf("failed to get last commit for block %d: %w", header.Height(), err)
}

abciBlock, err := cometcompat.ToABCIBlock(header, data, lastCommit)
block, err := cometcompat.ToABCIBlock(header, data, lastCommit)
if err != nil {
return nil, err
}
Expand All @@ -202,7 +201,7 @@ func BlockByHash(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error
Hash: nil,
},
},
Block: abciBlock,
Block: block,
}, nil
}

Expand Down Expand Up @@ -236,8 +235,7 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro
}},
}

// First apply ToABCIBlock to get the final header with all transformations
abciBlock, err := cometcompat.ToABCIBlock(header, rollkitData, abciCommit)
block, err := cometcompat.ToABCIBlock(header, rollkitData, abciCommit)
if err != nil {
return nil, err
}
Expand All @@ -250,10 +248,10 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro
Height: int64(header.Height()), //nolint:gosec
Round: 0,
BlockID: cmtproto.BlockID{
Hash: abciBlock.Header.Hash(),
Hash: block.Header.Hash(),
PartSetHeader: cmtproto.PartSetHeader{},
},
Timestamp: abciBlock.Time,
Timestamp: block.Time,
ValidatorAddress: header.ProposerAddress,
ValidatorIndex: 0,
}
Expand All @@ -266,16 +264,16 @@ func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, erro
}

// Update the commit with the new signature
abciBlock.LastCommit.Signatures[0].Signature = newSignature
block.LastCommit.Signatures[0].Signature = newSignature
}

// Update the commit's BlockID to match the final ABCI block hash
abciBlock.LastCommit.BlockID.Hash = abciBlock.Header.Hash()
block.LastCommit.BlockID.Hash = block.Header.Hash()

return &ctypes.ResultCommit{
SignedHeader: cmttypes.SignedHeader{
Header: &abciBlock.Header,
Commit: abciBlock.LastCommit,
Header: &block.Header,
Commit: block.LastCommit,
},
CanonicalCommit: true,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func signBlock(t *testing.T, header types.Header, data *types.Data, privKey cryp
Signature: types.Signature(make([]byte, 64)),
}

abciBlock, err := cometcompat.ToABCIBlock(tempSignedHeader, data, tempCommit)
abciBlock, err := cometcompat.ToABCIBlock(tempSignedHeader, data, tempCommit, nil) // todo (Alex): set correct valset

Choose a reason for hiding this comment

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

critical

The cometcompat.ToABCIBlock function is called with four arguments, but its definition in pkg/cometcompat/convert.go expects only three. This will cause a compilation error. Correct the function call to match the definition.

require.NoError(t, err)

vote := cmtproto.Vote{
Expand Down
23 changes: 11 additions & 12 deletions pkg/rpc/core/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, pagePtr, perPagePtr *in
}
// Since it's a centralized sequencer
// changed behavior to get this from genesis
genesisValidator := genesisValidators[0]
validator := cmttypes.Validator{
Address: genesisValidator.Address,
PubKey: genesisValidator.PubKey,
VotingPower: int64(1),
ProposerPriority: int64(1),
valSet := make([]*cmttypes.Validator, len(genesisValidators))
for i, v := range genesisValidators {
valSet[i] = &cmttypes.Validator{
Address: v.Address,
PubKey: v.PubKey,
VotingPower: v.Power,
ProposerPriority: int64(1),
}
}

return &coretypes.ResultValidators{
BlockHeight: int64(height), //nolint:gosec
Validators: []*cmttypes.Validator{
&validator,
},
Count: 1,
Total: 1,
Validators: valSet,
Count: len(valSet),
Total: len(valSet),
}, nil
}

Expand Down
10 changes: 2 additions & 8 deletions pkg/rpc/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,9 @@ func getBlockMeta(ctx context.Context, n uint64) *cmttypes.BlockMeta {
}

// Create empty commit for ToABCIBlockMeta call
emptyCommit := &cmttypes.Commit{
Height: int64(header.Height()),
Round: 0,
BlockID: cmttypes.BlockID{},
Signatures: []cmttypes.CommitSig{},
}

emptyCommit := &cmttypes.Commit{}
// Assuming ToABCIBlockMeta is now in pkg/rpc/provider/provider_utils.go
bmeta, err := cometcompat.ToABCIBlockMeta(header, data, emptyCommit) // Removed rpc. prefix
bmeta, err := cometcompat.ToABCIBlockMeta(header, data, emptyCommit)
if err != nil {
env.Logger.Error("Failed to convert block to ABCI block meta", "height", n, "err", err)
return nil
Expand Down
1 change: 1 addition & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ func setupNodeAndExecutor(
metrics,
NewLogAdapter(logger),
cometcompat.PayloadProvider(),
adapter.ValidatorHasher(executor.Store),
)
if err != nil {
return nil, nil, cleanupFn, err
Expand Down
Loading