Skip to content

Commit

Permalink
feat: store proof, round on block
Browse files Browse the repository at this point in the history
  • Loading branch information
Woosang Son authored and torao committed Mar 20, 2021
1 parent c52ecc2 commit 594d766
Show file tree
Hide file tree
Showing 41 changed files with 688 additions and 177 deletions.
8 changes: 5 additions & 3 deletions blockchain/v0/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func newBlockchainReactor(
lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
}

thisBlock := makeBlock(blockHeight, state, lastCommit)
thisBlock := makeBlock(privVals[0], blockHeight, state, lastCommit)

thisParts := thisBlock.MakePartSet(types.BlockPartSizeBytes)
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()}
Expand Down Expand Up @@ -288,8 +288,10 @@ func makeTxs(height int64) (txs []types.Tx) {
return txs
}

func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block {
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address)
func makeBlock(privVal types.PrivValidator, height int64, state sm.State, lastCommit *types.Commit) *types.Block {
message, _ := state.MakeHashMessage(0)
proof, _ := privVal.GenerateVRFProof(message)
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address, 0, proof)
return block
}

Expand Down
8 changes: 5 additions & 3 deletions blockchain/v1/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func newBlockchainReactor(
lastCommit = types.NewCommit(vote.Height, vote.Round, lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
}

thisBlock := makeBlock(blockHeight, state, lastCommit)
thisBlock := makeBlock(privVals[0], blockHeight, state, lastCommit)

thisParts := thisBlock.MakePartSet(types.BlockPartSizeBytes)
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()}
Expand Down Expand Up @@ -355,8 +355,10 @@ func makeTxs(height int64) (txs []types.Tx) {
return txs
}

func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block {
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address)
func makeBlock(privVal types.PrivValidator, height int64, state sm.State, lastCommit *types.Commit) *types.Block {
message, _ := state.MakeHashMessage(0)
proof, _ := privVal.GenerateVRFProof(message)
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address, 0, proof)
return block
}

Expand Down
9 changes: 6 additions & 3 deletions blockchain/v2/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ func makeTxs(height int64) (txs []types.Tx) {
return txs
}

func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block {
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address)
func makeBlock(privVal types.PrivValidator, height int64, state sm.State, lastCommit *types.Commit) *types.Block {
message, _ := state.MakeHashMessage(0)
proof, _ := privVal.GenerateVRFProof(message)
proposerAddr := state.Validators.GetProposer().Address
block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, proposerAddr, 0, proof)
return block
}

Expand Down Expand Up @@ -536,7 +539,7 @@ func newReactorStore(
lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
}

thisBlock := makeBlock(blockHeight, state, lastCommit)
thisBlock := makeBlock(privVals[0], blockHeight, state, lastCommit)

thisParts := thisBlock.MakePartSet(types.BlockPartSizeBytes)
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()}
Expand Down
4 changes: 3 additions & 1 deletion consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
}
proposerAddr := lazyProposer.privValidatorPubKey.Address()

message, _ := lazyProposer.state.MakeHashMessage(lazyProposer.Round)
proof, _ := lazyProposer.privValidator.GenerateVRFProof(message)
block, blockParts := lazyProposer.blockExec.CreateProposalBlock(
lazyProposer.Height, lazyProposer.state, commit, proposerAddr,
lazyProposer.Height, lazyProposer.state, commit, proposerAddr, lazyProposer.Round, proof,
)

// Flush the WAL. Otherwise, we may not recompute the same proposal to sign,
Expand Down
9 changes: 8 additions & 1 deletion consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ func testHandshakeReplay(t *testing.T, config *cfg.Config, nBlocks int, mode uin
defer os.RemoveAll(testConfig.RootDir)
stateDB = dbm.NewMemDB()

// Make the global variable "sim" be initialized forcefully by calling "TestSimulateValidatorChange()"
// if it is not initialized as in unit execution.
if sim.Config == nil {
TestSimulateValidatorsChange(t)
}
genesisState = sim.GenesisState
config = sim.Config
chain = append([]*types.Block{}, sim.Chain...) // copy chain
Expand Down Expand Up @@ -990,7 +995,9 @@ func makeBlock(state sm.State, lastBlock *types.Block, lastBlockMeta *types.Bloc
lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
}

return state.MakeBlock(height, []types.Tx{}, lastCommit, nil, state.Validators.GetProposer().Address)
message, _ := state.MakeHashMessage(0)
proof, _ := privVal.GenerateVRFProof(message)
return state.MakeBlock(height, []types.Tx{}, lastCommit, nil, state.Validators.GetProposer().Address, 0, proof)
}

type badApp struct {
Expand Down
23 changes: 20 additions & 3 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,9 +1198,26 @@ func (cs *State) createProposalBlock() (block *types.Block, blockParts *types.Pa
return
}

proposerAddr := cs.privValidatorPubKey.Address()
pubKey, err := cs.privValidator.GetPubKey()
if err != nil {
cs.Logger.Error(fmt.Sprintf("enterPropose: Cannot retrieve public key: %s", err.Error()))
return
}
proposerAddr := pubKey.Address()

return cs.blockExec.CreateProposalBlock(cs.Height, cs.state, commit, proposerAddr)
message, err := cs.state.MakeHashMessage(cs.Round)
if err != nil {
cs.Logger.Error(fmt.Sprintf("enterPropose: Cannot generate vrf message: %s", err.Error()))
return
}

proof, err := cs.privValidator.GenerateVRFProof(message)
if err != nil {
cs.Logger.Error(fmt.Sprintf("enterPropose: Cannot generate vrf proof: %s", err.Error()))
return
}

return cs.blockExec.CreateProposalBlock(cs.Height, cs.state, commit, proposerAddr, cs.Round, proof)
}

// Enter: `timeoutPropose` after entering Propose.
Expand Down Expand Up @@ -1388,6 +1405,7 @@ func (cs *State) enterPrecommit(height int64, round int32) {

// Validate the block.
if err := cs.blockExec.ValidateBlock(cs.state, cs.ProposalBlock); err != nil {
cs.Logger.Error(fmt.Sprintf("%v; block=%v", err, cs.ProposalBlock))
panic(fmt.Sprintf("precommit step; +2/3 prevoted for an invalid block: %v", err))
}

Expand Down Expand Up @@ -1663,7 +1681,6 @@ func (cs *State) finalizeCommit(height int64) {

// NewHeightStep!
cs.updateToState(stateCopy)

fail.Fail() // XXX

// Private validator might have changed it's key pair => refetch pubkey.
Expand Down
1 change: 1 addition & 0 deletions crypto/vrf/vrf_coniks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"

coniksimpl "github.com/coniks-sys/coniks-go/crypto/vrf"

"github.com/tendermint/tendermint/crypto/ed25519"
)

Expand Down
2 changes: 1 addition & 1 deletion crypto/vrf/vrf_coniks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package vrf

import (
"bytes"
"github.com/stretchr/testify/require"
"testing"

coniksimpl "github.com/coniks-sys/coniks-go/crypto/vrf"
"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/crypto/ed25519"
)

Expand Down
1 change: 1 addition & 0 deletions crypto/vrf/vrf_r2ishiguro.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package vrf

import (
r2ishiguro "github.com/r2ishiguro/vrf/go/vrf_ed25519"

"github.com/tendermint/tendermint/crypto/ed25519"
)

Expand Down
1 change: 1 addition & 0 deletions crypto/vrf/vrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/crypto/ed25519"
)

Expand Down
1 change: 1 addition & 0 deletions evidence/mocks/block_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,11 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) *store.Bloc
blockStore := store.NewBlockStore(db)

for i := int64(1); i <= state.LastBlockHeight; i++ {
round := int32(0)
lastCommit := makeCommit(i-1, valAddr)
proof, _ := state.MakeHashMessage(round)
block, _ := state.MakeBlock(i, []types.Tx{}, lastCommit, nil,
state.Validators.GetProposer().Address)
state.Validators.GetProposer().Address, round, proof)
block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute)
block.Header.Version = tmversion.Consensus{Block: version.BlockProtocol, App: 1}
const parts = 1
Expand Down
14 changes: 12 additions & 2 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,14 @@ func TestCreateProposalBlock(t *testing.T) {
)

commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
message, _ := state.MakeHashMessage(0)
proof, _ := privVals[0].GenerateVRFProof(message)
block, _ := blockExec.CreateProposalBlock(
height,
state, commit,
proposerAddr,
0,
proof,
)

// check that the part set does not exceed the maximum block size
Expand Down Expand Up @@ -325,7 +329,7 @@ func TestMaxProposalBlockSize(t *testing.T) {
logger := log.TestingLogger()

var height int64 = 1
state, stateDB, _ := state(1, height)
state, stateDB, privVals := state(1, height)
stateStore := sm.NewStore(stateDB)
var maxBytes int64 = 16384
var partSize uint32 = 256
Expand Down Expand Up @@ -359,10 +363,14 @@ func TestMaxProposalBlockSize(t *testing.T) {
)

commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
message, _ := state.MakeHashMessage(0)
proof, _ := privVals[0].GenerateVRFProof(message)
block, _ := blockExec.CreateProposalBlock(
height,
state, commit,
proposerAddr,
0,
proof,
)

pb, err := block.ToProto()
Expand Down Expand Up @@ -411,7 +419,9 @@ func state(nVals int, height int64) (sm.State, dbm.DB, []types.PrivValidator) {
privVals := make([]types.PrivValidator, nVals)
vals := make([]types.GenesisValidator, nVals)
for i := 0; i < nVals; i++ {
privVal := types.NewMockPV()
secret := []byte(fmt.Sprintf("test%d", i))
pk := ed25519.GenPrivKeyFromSecret(secret)
privVal := types.NewMockPVWithParams(pk, false, false)
privVals[i] = privVal
vals[i] = types.GenesisValidator{
Address: privVal.PrivKey.PubKey().Address(),
Expand Down
3 changes: 2 additions & 1 deletion privval/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"time"

"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/crypto/vrf"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/vrf"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"
Expand Down
3 changes: 2 additions & 1 deletion privval/retry_signer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package privval

import (
"fmt"
"github.com/tendermint/tendermint/crypto/vrf"
"time"

"github.com/tendermint/tendermint/crypto/vrf"

"github.com/tendermint/tendermint/crypto"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
Expand Down
4 changes: 2 additions & 2 deletions privval/signer_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/crypto/vrf"
tmrand "github.com/tendermint/tendermint/libs/rand"
cryptoproto "github.com/tendermint/tendermint/proto/tendermint/crypto"
privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/vrf"
"github.com/tendermint/tendermint/types"
)

Expand Down
3 changes: 1 addition & 2 deletions privval/signer_requestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ func DefaultValidationRequestHandler(
err, res = nil, mustWrapMsg(&privvalproto.PingResponse{})

case *privvalproto.Message_VrfProofRequest:
message := r.VrfProofRequest.Message
proof, err := privVal.GenerateVRFProof(message)
proof, err := privVal.GenerateVRFProof(r.VrfProofRequest.Message)
if err != nil {
err := privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}
res = mustWrapMsg(&privvalproto.VRFProofResponse{Proof: nil, Error: &err})
Expand Down
Loading

0 comments on commit 594d766

Please sign in to comment.