Skip to content

Commit

Permalink
Merge pull request cosmos#806 from rollkit/tuxcanfly/gossip-validator…
Browse files Browse the repository at this point in the history
…-set

types: signed header validator set - use tendermint types
  • Loading branch information
tuxcanfly committed Mar 28, 2023
2 parents 2efe202 + aec53d0 commit b296f3f
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 500 deletions.
11 changes: 9 additions & 2 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"
abci "github.com/tendermint/tendermint/abci/types"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/proxy"
tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -495,11 +496,17 @@ func (m *Manager) publishBlock(ctx context.Context) error {

// set the validator set using the signer's public key
// TODO(ganesh): need to hook into a module that selects signers
pubKey, err := m.proposerKey.GetPublic().Raw()
pubKeyRaw, err := m.proposerKey.GetPublic().Raw()
if err != nil {
return err
}
block.SignedHeader.Validators = types.ValidatorSet{Validators: []types.Validator{{PublicKey: pubKey}}}
pubKey := ed25519.PubKey(pubKeyRaw)
proposer := &tmtypes.Validator{Address: pubKey.Address(), PubKey: pubKey}
// TODO: read staking query to construct validators
block.SignedHeader.Validators = &tmtypes.ValidatorSet{
Validators: []*tmtypes.Validator{proposer},
Proposer: proposer,
}

// SaveBlock commits the DB tx
err = m.store.SaveBlock(block, commit)
Expand Down
8 changes: 7 additions & 1 deletion da/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ func (d *DataAvailabilityLayerClient) Stop() error {

// SubmitBlock proxies SubmitBlock request to gRPC server.
func (d *DataAvailabilityLayerClient) SubmitBlock(ctx context.Context, block *types.Block) da.ResultSubmitBlock {
resp, err := d.client.SubmitBlock(ctx, &dalc.SubmitBlockRequest{Block: block.ToProto()})
bp, err := block.ToProto()
if err != nil {
return da.ResultSubmitBlock{
BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()},
}
}
resp, err := d.client.SubmitBlock(ctx, &dalc.SubmitBlockRequest{Block: bp})
if err != nil {
return da.ResultSubmitBlock{
BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()},
Expand Down
6 changes: 5 additions & 1 deletion da/grpc/mockserv/mockserv.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func (m *mockImpl) RetrieveBlocks(ctx context.Context, request *dalc.RetrieveBlo
resp := m.mock.RetrieveBlocks(ctx, request.DAHeight)
blocks := make([]*rollkit.Block, len(resp.Blocks))
for i := range resp.Blocks {
blocks[i] = resp.Blocks[i].ToProto()
bp, err := resp.Blocks[i].ToProto()
if err != nil {
return nil, err
}
blocks[i] = bp
}
return &dalc.RetrieveBlocksResponse{
Result: &dalc.DAResponse{
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/go-cnc v0.3.0 h1:eAVPNHGpx+2sBO7NZyQ1+VW8rzf6W4FQDlSq6aqSTsM=
github.com/celestiaorg/go-cnc v0.3.0/go.mod h1:zYzvHudSd1iNPuHBMyvZ1YvWou5aT9JXgtch9Tkaf70=
github.com/celestiaorg/go-header v0.1.0 h1:K/atYWwZ/bjMLJ/Apy0dokbREa8BGgxUMiMjhRHlF4E=
github.com/celestiaorg/go-header v0.1.0/go.mod h1:AR7GQ1519TDLEFxRC0rt9emq1IvhU+Nf+1Ufe3JI3nA=
github.com/celestiaorg/go-header v0.2.0 h1:UnufpDXQGLpP40SyiwfZLRT7alKLmo3lraPaJtsV8qI=
github.com/celestiaorg/go-header v0.2.0/go.mod h1:6XKf0yhoEQqfKQTZnyTZjTjF5jH5Wq9uO9AvDMkdYbs=
github.com/celestiaorg/go-header v0.2.1 h1:h6EiEcrA7K9dg5bRNe7aNQ13rDAL4/wRB5jujMGP1Ho=
github.com/celestiaorg/go-header v0.2.1/go.mod h1:6XKf0yhoEQqfKQTZnyTZjTjF5jH5Wq9uO9AvDMkdYbs=
github.com/celestiaorg/go-libp2p-messenger v0.2.0 h1:/0MuPDcFamQMbw9xTZ73yImqgTO3jHV7wKHvWD/Irao=
Expand Down
23 changes: 22 additions & 1 deletion node/full_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ var expectedInfo = abci.ResponseInfo{

var mockTxProcessingTime = 10 * time.Millisecond

// TODO: accept argument for number of validators / proposer index
func getRandomValidatorSet() *tmtypes.ValidatorSet {
pubKey := ed25519.GenPrivKey().PubKey()
return &tmtypes.ValidatorSet{
Proposer: &tmtypes.Validator{PubKey: pubKey, Address: pubKey.Address()},
Validators: []*tmtypes.Validator{
{PubKey: pubKey, Address: pubKey.Address()},
},
}
}

func TestConnectionGetter(t *testing.T) {
assert := assert.New(t)

Expand Down Expand Up @@ -400,14 +411,22 @@ func TestTx(t *testing.T) {
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)

vKeys := make([]tmcrypto.PrivKey, 4)
genesisValidators := make([]tmtypes.GenesisValidator, len(vKeys))
for i := 0; i < len(vKeys); i++ {
vKeys[i] = ed25519.GenPrivKey()
genesisValidators[i] = tmtypes.GenesisValidator{Address: vKeys[i].PubKey().Address(), PubKey: vKeys[i].PubKey(), Power: int64(i + 100), Name: fmt.Sprintf("genesis validator #%d", i)}
}

node, err := newFullNode(context.Background(), config.NodeConfig{
DALayer: "mock",
Aggregator: true,
BlockManagerConfig: config.BlockManagerConfig{
BlockTime: 1 * time.Second, // blocks must be at least 1 sec apart for adjacent headers to get verified correctly
}},
key, signingKey, abcicli.NewLocalClient(nil, mockApp),
&tmtypes.GenesisDoc{ChainID: "test"},
&tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators},
log.TestingLogger())
require.NoError(err)
require.NotNil(node)
Expand Down Expand Up @@ -750,6 +769,8 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t
copy(lastCommitHash, tmprotoLC.Hash().Bytes())
block.SignedHeader.Header.LastCommitHash = lastCommitHash

block.SignedHeader.Validators = getRandomValidatorSet()

return block
}

Expand Down
15 changes: 4 additions & 11 deletions proto/rollkit/rollkit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package rollkit;
option go_package = "github.com/rollkit/rollkit/types/pb/rollkit";
import "tendermint/abci/types.proto";
import "tendermint/types/validator.proto";

// Version captures the consensus rules for processing a block in the blockchain,
// including all blockchain data structures and the rules of the application's
Expand All @@ -27,7 +28,7 @@ message Header {

// Commit from aggregator(s) from the last block
bytes last_commit_hash = 5;

// Block.Data root aka Transactions
bytes data_hash = 6;

Expand Down Expand Up @@ -60,18 +61,10 @@ message Commit {
repeated bytes signatures = 1;
}

message Validator {
bytes public_key = 1;
}

message ValidatorSet {
repeated Validator validators = 1;
}

message SignedHeader {
Header header = 1;
Commit commit = 2;
ValidatorSet validators = 3;
tendermint.types.ValidatorSet validators = 3;
}

message Data {
Expand All @@ -80,7 +73,7 @@ message Data {
repeated tendermint.abci.Evidence evidence = 3;
}

message Block {
message Block {
SignedHeader signed_header = 1;
Data data = 2;
}
12 changes: 2 additions & 10 deletions state/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
block.SignedHeader.Commit = types.Commit{
Signatures: []types.Signature{sig},
}
block.SignedHeader.Validators = types.ValidatorSet{
Validators: []types.Validator{{
PublicKey: vKey.PubKey().Bytes(),
}},
}
block.SignedHeader.Validators = tmtypes.NewValidatorSet(validators)

newState, resp, err := executor.ApplyBlock(context.Background(), state, block)
require.NoError(err)
Expand All @@ -195,11 +191,7 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
block.SignedHeader.Commit = types.Commit{
Signatures: []types.Signature{sig},
}
block.SignedHeader.Validators = types.ValidatorSet{
Validators: []types.Validator{{
PublicKey: vKey.PubKey().Bytes(),
}},
}
block.SignedHeader.Validators = tmtypes.NewValidatorSet(validators)

newState, resp, err = executor.ApplyBlock(context.Background(), newState, block)
require.NoError(err)
Expand Down
1 change: 1 addition & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestStoreLoad(t *testing.T) {
for _, block := range c.blocks {
commit := &types.Commit{}
block.SignedHeader.Commit = *lastCommit
block.SignedHeader.Validators = getRandomValidatorSet()
err := bstore.SaveBlock(block, commit)
require.NoError(err)
lastCommit = commit
Expand Down
12 changes: 3 additions & 9 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package types

import (
"encoding"

tmtypes "github.com/tendermint/tendermint/types"
)

type NamespaceID [8]byte
Expand Down Expand Up @@ -41,21 +43,13 @@ type Commit struct {
Signatures []Signature // most of the time this is a single signature
}

type Validator struct {
PublicKey []byte
}

type ValidatorSet struct {
Validators []Validator
}

// SignedHeader combines Header and its Commit.
//
// Used mostly for gossiping.
type SignedHeader struct {
Header
Commit Commit
Validators ValidatorSet
Validators *tmtypes.ValidatorSet
}

// Signature represents signature of block creator.
Expand Down
Loading

0 comments on commit b296f3f

Please sign in to comment.