move handshake to state, use Handshaker, more tests

This commit is contained in:
Ethan Buchman
2016-11-16 13:29:22 -05:00
parent befd8b0cb2
commit 4360c360a4
14 changed files with 439 additions and 204 deletions
+21
View File
@@ -21,6 +21,27 @@ type Block struct {
LastCommit *Commit `json:"last_commit"`
}
func MakeBlock(height int, chainID string, txs []Tx, commit *Commit,
prevBlockID BlockID, valHash, appHash []byte) (*Block, *PartSet) {
block := &Block{
Header: &Header{
ChainID: chainID,
Height: height,
Time: time.Now(),
NumTxs: len(txs),
LastBlockID: prevBlockID,
ValidatorsHash: valHash,
AppHash: appHash, // state merkle root of txs from the previous block.
},
LastCommit: commit,
Data: &Data{
Txs: txs,
},
}
block.FillHeader()
return block, block.MakePartSet()
}
// Basic validation that doesn't involve state data.
func (b *Block) ValidateBasic(chainID string, lastBlockHeight int, lastBlockID BlockID,
lastBlockTime time.Time, appHash []byte) error {
+3 -2
View File
@@ -11,8 +11,9 @@ import (
)
// Volatile state for each Validator
// Also persisted with the state, but fields change
// every height|round so they don't go in merkle.Tree
// TODO: make non-volatile identity
// - Remove LastCommitHeight, send bitarray of vals that signed in BeginBlock
// - Remove Accum - it can be computed, and now valset becomes identifying
type Validator struct {
Address []byte `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
+1 -1
View File
@@ -20,7 +20,7 @@ import (
// NOTE: Not goroutine-safe.
// NOTE: All get/set to validators should copy the value for safety.
// TODO: consider validator Accum overflow
// TODO: replace validators []*Validator with github.com/jaekwon/go-ibbs?
// TODO: move valset into an iavl tree where key is 'blockbonded|pubkey'
type ValidatorSet struct {
Validators []*Validator // NOTE: persisted via reflect, must be exported.