Skip to content

Commit b296f3f

Browse files
authored
Merge pull request #806 from rollkit/tuxcanfly/gossip-validator-set
types: signed header validator set - use tendermint types
2 parents 2efe202 + aec53d0 commit b296f3f

13 files changed

Lines changed: 151 additions & 500 deletions

File tree

block/manager.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/libp2p/go-libp2p/core/crypto"
1111
abci "github.com/tendermint/tendermint/abci/types"
1212
tmcrypto "github.com/tendermint/tendermint/crypto"
13+
"github.com/tendermint/tendermint/crypto/ed25519"
1314
"github.com/tendermint/tendermint/crypto/merkle"
1415
"github.com/tendermint/tendermint/proxy"
1516
tmtypes "github.com/tendermint/tendermint/types"
@@ -495,11 +496,17 @@ func (m *Manager) publishBlock(ctx context.Context) error {
495496

496497
// set the validator set using the signer's public key
497498
// TODO(ganesh): need to hook into a module that selects signers
498-
pubKey, err := m.proposerKey.GetPublic().Raw()
499+
pubKeyRaw, err := m.proposerKey.GetPublic().Raw()
499500
if err != nil {
500501
return err
501502
}
502-
block.SignedHeader.Validators = types.ValidatorSet{Validators: []types.Validator{{PublicKey: pubKey}}}
503+
pubKey := ed25519.PubKey(pubKeyRaw)
504+
proposer := &tmtypes.Validator{Address: pubKey.Address(), PubKey: pubKey}
505+
// TODO: read staking query to construct validators
506+
block.SignedHeader.Validators = &tmtypes.ValidatorSet{
507+
Validators: []*tmtypes.Validator{proposer},
508+
Proposer: proposer,
509+
}
503510

504511
// SaveBlock commits the DB tx
505512
err = m.store.SaveBlock(block, commit)

da/grpc/grpc.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ func (d *DataAvailabilityLayerClient) Stop() error {
7676

7777
// SubmitBlock proxies SubmitBlock request to gRPC server.
7878
func (d *DataAvailabilityLayerClient) SubmitBlock(ctx context.Context, block *types.Block) da.ResultSubmitBlock {
79-
resp, err := d.client.SubmitBlock(ctx, &dalc.SubmitBlockRequest{Block: block.ToProto()})
79+
bp, err := block.ToProto()
80+
if err != nil {
81+
return da.ResultSubmitBlock{
82+
BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()},
83+
}
84+
}
85+
resp, err := d.client.SubmitBlock(ctx, &dalc.SubmitBlockRequest{Block: bp})
8086
if err != nil {
8187
return da.ResultSubmitBlock{
8288
BaseResult: da.BaseResult{Code: da.StatusError, Message: err.Error()},

da/grpc/mockserv/mockserv.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ func (m *mockImpl) RetrieveBlocks(ctx context.Context, request *dalc.RetrieveBlo
6767
resp := m.mock.RetrieveBlocks(ctx, request.DAHeight)
6868
blocks := make([]*rollkit.Block, len(resp.Blocks))
6969
for i := range resp.Blocks {
70-
blocks[i] = resp.Blocks[i].ToProto()
70+
bp, err := resp.Blocks[i].ToProto()
71+
if err != nil {
72+
return nil, err
73+
}
74+
blocks[i] = bp
7175
}
7276
return &dalc.RetrieveBlocksResponse{
7377
Result: &dalc.DAResponse{

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7
107107
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
108108
github.com/celestiaorg/go-cnc v0.3.0 h1:eAVPNHGpx+2sBO7NZyQ1+VW8rzf6W4FQDlSq6aqSTsM=
109109
github.com/celestiaorg/go-cnc v0.3.0/go.mod h1:zYzvHudSd1iNPuHBMyvZ1YvWou5aT9JXgtch9Tkaf70=
110-
github.com/celestiaorg/go-header v0.1.0 h1:K/atYWwZ/bjMLJ/Apy0dokbREa8BGgxUMiMjhRHlF4E=
111-
github.com/celestiaorg/go-header v0.1.0/go.mod h1:AR7GQ1519TDLEFxRC0rt9emq1IvhU+Nf+1Ufe3JI3nA=
112-
github.com/celestiaorg/go-header v0.2.0 h1:UnufpDXQGLpP40SyiwfZLRT7alKLmo3lraPaJtsV8qI=
113-
github.com/celestiaorg/go-header v0.2.0/go.mod h1:6XKf0yhoEQqfKQTZnyTZjTjF5jH5Wq9uO9AvDMkdYbs=
114110
github.com/celestiaorg/go-header v0.2.1 h1:h6EiEcrA7K9dg5bRNe7aNQ13rDAL4/wRB5jujMGP1Ho=
115111
github.com/celestiaorg/go-header v0.2.1/go.mod h1:6XKf0yhoEQqfKQTZnyTZjTjF5jH5Wq9uO9AvDMkdYbs=
116112
github.com/celestiaorg/go-libp2p-messenger v0.2.0 h1:/0MuPDcFamQMbw9xTZ73yImqgTO3jHV7wKHvWD/Irao=

node/full_client_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ var expectedInfo = abci.ResponseInfo{
4242

4343
var mockTxProcessingTime = 10 * time.Millisecond
4444

45+
// TODO: accept argument for number of validators / proposer index
46+
func getRandomValidatorSet() *tmtypes.ValidatorSet {
47+
pubKey := ed25519.GenPrivKey().PubKey()
48+
return &tmtypes.ValidatorSet{
49+
Proposer: &tmtypes.Validator{PubKey: pubKey, Address: pubKey.Address()},
50+
Validators: []*tmtypes.Validator{
51+
{PubKey: pubKey, Address: pubKey.Address()},
52+
},
53+
}
54+
}
55+
4556
func TestConnectionGetter(t *testing.T) {
4657
assert := assert.New(t)
4758

@@ -400,14 +411,22 @@ func TestTx(t *testing.T) {
400411
mockApp.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{})
401412
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
402413
signingKey, _, _ := crypto.GenerateEd25519Key(crand.Reader)
414+
415+
vKeys := make([]tmcrypto.PrivKey, 4)
416+
genesisValidators := make([]tmtypes.GenesisValidator, len(vKeys))
417+
for i := 0; i < len(vKeys); i++ {
418+
vKeys[i] = ed25519.GenPrivKey()
419+
genesisValidators[i] = tmtypes.GenesisValidator{Address: vKeys[i].PubKey().Address(), PubKey: vKeys[i].PubKey(), Power: int64(i + 100), Name: fmt.Sprintf("genesis validator #%d", i)}
420+
}
421+
403422
node, err := newFullNode(context.Background(), config.NodeConfig{
404423
DALayer: "mock",
405424
Aggregator: true,
406425
BlockManagerConfig: config.BlockManagerConfig{
407426
BlockTime: 1 * time.Second, // blocks must be at least 1 sec apart for adjacent headers to get verified correctly
408427
}},
409428
key, signingKey, abcicli.NewLocalClient(nil, mockApp),
410-
&tmtypes.GenesisDoc{ChainID: "test"},
429+
&tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators},
411430
log.TestingLogger())
412431
require.NoError(err)
413432
require.NotNil(node)
@@ -750,6 +769,8 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t
750769
copy(lastCommitHash, tmprotoLC.Hash().Bytes())
751770
block.SignedHeader.Header.LastCommitHash = lastCommitHash
752771

772+
block.SignedHeader.Validators = getRandomValidatorSet()
773+
753774
return block
754775
}
755776

proto/rollkit/rollkit.proto

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ syntax = "proto3";
22
package rollkit;
33
option go_package = "github.com/rollkit/rollkit/types/pb/rollkit";
44
import "tendermint/abci/types.proto";
5+
import "tendermint/types/validator.proto";
56

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

2829
// Commit from aggregator(s) from the last block
2930
bytes last_commit_hash = 5;
30-
31+
3132
// Block.Data root aka Transactions
3233
bytes data_hash = 6;
3334

@@ -60,18 +61,10 @@ message Commit {
6061
repeated bytes signatures = 1;
6162
}
6263

63-
message Validator {
64-
bytes public_key = 1;
65-
}
66-
67-
message ValidatorSet {
68-
repeated Validator validators = 1;
69-
}
70-
7164
message SignedHeader {
7265
Header header = 1;
7366
Commit commit = 2;
74-
ValidatorSet validators = 3;
67+
tendermint.types.ValidatorSet validators = 3;
7568
}
7669

7770
message Data {
@@ -80,7 +73,7 @@ message Data {
8073
repeated tendermint.abci.Evidence evidence = 3;
8174
}
8275

83-
message Block {
76+
message Block {
8477
SignedHeader signed_header = 1;
8578
Data data = 2;
8679
}

state/executor_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,7 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
166166
block.SignedHeader.Commit = types.Commit{
167167
Signatures: []types.Signature{sig},
168168
}
169-
block.SignedHeader.Validators = types.ValidatorSet{
170-
Validators: []types.Validator{{
171-
PublicKey: vKey.PubKey().Bytes(),
172-
}},
173-
}
169+
block.SignedHeader.Validators = tmtypes.NewValidatorSet(validators)
174170

175171
newState, resp, err := executor.ApplyBlock(context.Background(), state, block)
176172
require.NoError(err)
@@ -195,11 +191,7 @@ func doTestApplyBlock(t *testing.T, fraudProofsEnabled bool) {
195191
block.SignedHeader.Commit = types.Commit{
196192
Signatures: []types.Signature{sig},
197193
}
198-
block.SignedHeader.Validators = types.ValidatorSet{
199-
Validators: []types.Validator{{
200-
PublicKey: vKey.PubKey().Bytes(),
201-
}},
202-
}
194+
block.SignedHeader.Validators = tmtypes.NewValidatorSet(validators)
203195

204196
newState, resp, err = executor.ApplyBlock(context.Background(), newState, block)
205197
require.NoError(err)

store/store_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func TestStoreLoad(t *testing.T) {
104104
for _, block := range c.blocks {
105105
commit := &types.Commit{}
106106
block.SignedHeader.Commit = *lastCommit
107+
block.SignedHeader.Validators = getRandomValidatorSet()
107108
err := bstore.SaveBlock(block, commit)
108109
require.NoError(err)
109110
lastCommit = commit

types/block.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package types
22

33
import (
44
"encoding"
5+
6+
tmtypes "github.com/tendermint/tendermint/types"
57
)
68

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

44-
type Validator struct {
45-
PublicKey []byte
46-
}
47-
48-
type ValidatorSet struct {
49-
Validators []Validator
50-
}
51-
5246
// SignedHeader combines Header and its Commit.
5347
//
5448
// Used mostly for gossiping.
5549
type SignedHeader struct {
5650
Header
5751
Commit Commit
58-
Validators ValidatorSet
52+
Validators *tmtypes.ValidatorSet
5953
}
6054

6155
// Signature represents signature of block creator.

0 commit comments

Comments
 (0)