uint64 height (Refs #911)

This commit is contained in:
Anton Kaliaev
2017-11-30 13:08:38 -06:00
committed by Ethan Buchman
parent b2489b4318
commit b3492356e6
64 changed files with 296 additions and 270 deletions

View File

@ -23,7 +23,7 @@ type Block struct {
// MakeBlock returns a new block and corresponding partset from the given information.
// TODO: Add version information to the Block struct.
func MakeBlock(height int, chainID string, txs []Tx, commit *Commit,
func MakeBlock(height uint64, chainID string, txs []Tx, commit *Commit,
prevBlockID BlockID, valHash, appHash []byte, partSize int) (*Block, *PartSet) {
block := &Block{
Header: &Header{
@ -45,7 +45,7 @@ func MakeBlock(height int, chainID string, txs []Tx, commit *Commit,
}
// ValidateBasic performs basic validation that doesn't involve state data.
func (b *Block) ValidateBasic(chainID string, lastBlockHeight int, lastBlockID BlockID,
func (b *Block) ValidateBasic(chainID string, lastBlockHeight uint64, lastBlockID BlockID,
lastBlockTime time.Time, appHash []byte) error {
if b.ChainID != chainID {
return errors.New(cmn.Fmt("Wrong Block.Header.ChainID. Expected %v, got %v", chainID, b.ChainID))
@ -158,7 +158,7 @@ func (b *Block) StringShort() string {
// Header defines the structure of a Tendermint block header
type Header struct {
ChainID string `json:"chain_id"`
Height int `json:"height"`
Height uint64 `json:"height"`
Time time.Time `json:"time"`
NumTxs int `json:"num_txs"` // XXX: Can we get rid of this?
LastBlockID BlockID `json:"last_block_id"`
@ -250,7 +250,7 @@ func (commit *Commit) FirstPrecommit() *Vote {
}
// Height returns the height of the commit
func (commit *Commit) Height() int {
func (commit *Commit) Height() uint64 {
if len(commit.Precommits) == 0 {
return 0
}

View File

@ -18,7 +18,7 @@ type CanonicalJSONPartSetHeader struct {
type CanonicalJSONProposal struct {
BlockPartsHeader CanonicalJSONPartSetHeader `json:"block_parts_header"`
Height int `json:"height"`
Height uint64 `json:"height"`
POLBlockID CanonicalJSONBlockID `json:"pol_block_id"`
POLRound int `json:"pol_round"`
Round int `json:"round"`
@ -26,13 +26,13 @@ type CanonicalJSONProposal struct {
type CanonicalJSONVote struct {
BlockID CanonicalJSONBlockID `json:"block_id"`
Height int `json:"height"`
Height uint64 `json:"height"`
Round int `json:"round"`
Type byte `json:"type"`
}
type CanonicalJSONHeartbeat struct {
Height int `json:"height"`
Height uint64 `json:"height"`
Round int `json:"round"`
Sequence int `json:"sequence"`
ValidatorAddress data.Bytes `json:"validator_address"`

View File

@ -118,7 +118,7 @@ type EventDataProposalHeartbeat struct {
// NOTE: This goes into the replay WAL
type EventDataRoundState struct {
Height int `json:"height"`
Height uint64 `json:"height"`
Round int `json:"round"`
Step string `json:"step"`

View File

@ -18,7 +18,7 @@ import (
type Heartbeat struct {
ValidatorAddress data.Bytes `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
Height int `json:"height"`
Height uint64 `json:"height"`
Round int `json:"round"`
Sequence int `json:"sequence"`
Signature crypto.Signature `json:"signature"`

View File

@ -51,7 +51,7 @@ type PrivValidator interface {
type PrivValidatorFS struct {
Address data.Bytes `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
LastHeight int `json:"last_height"`
LastHeight uint64 `json:"last_height"`
LastRound int `json:"last_round"`
LastStep int8 `json:"last_step"`
LastSignature crypto.Signature `json:"last_signature,omitempty"` // so we dont lose signatures
@ -222,7 +222,7 @@ func (privVal *PrivValidatorFS) SignProposal(chainID string, proposal *Proposal)
// signBytesHRS signs the given signBytes if the height/round/step (HRS)
// are greater than the latest state. If the HRS are equal,
// it returns the privValidator.LastSignature.
func (privVal *PrivValidatorFS) signBytesHRS(height, round int, step int8, signBytes []byte) (crypto.Signature, error) {
func (privVal *PrivValidatorFS) signBytesHRS(height uint64, round int, step int8, signBytes []byte) (crypto.Signature, error) {
sig := crypto.Signature{}
// If height regression, err

View File

@ -20,7 +20,7 @@ func TestGenLoadValidator(t *testing.T) {
_, tempFilePath := cmn.Tempfile("priv_validator_")
privVal := GenPrivValidatorFS(tempFilePath)
height := 100
height := uint64(100)
privVal.LastHeight = height
privVal.Save()
addr := privVal.GetAddress()
@ -99,7 +99,7 @@ func TestSignVote(t *testing.T) {
block1 := BlockID{[]byte{1, 2, 3}, PartSetHeader{}}
block2 := BlockID{[]byte{3, 2, 1}, PartSetHeader{}}
height, round := 10, 1
height, round := uint64(10), 1
voteType := VoteTypePrevote
// sign a vote for first time
@ -133,7 +133,7 @@ func TestSignProposal(t *testing.T) {
block1 := PartSetHeader{5, []byte{1, 2, 3}}
block2 := PartSetHeader{10, []byte{3, 2, 1}}
height, round := 10, 1
height, round := uint64(10), 1
// sign a proposal for first time
proposal := newProposal(height, round, block1)
@ -158,7 +158,7 @@ func TestSignProposal(t *testing.T) {
}
}
func newVote(addr data.Bytes, idx, height, round int, typ byte, blockID BlockID) *Vote {
func newVote(addr data.Bytes, idx int, height uint64, round int, typ byte, blockID BlockID) *Vote {
return &Vote{
ValidatorAddress: addr,
ValidatorIndex: idx,
@ -169,7 +169,7 @@ func newVote(addr data.Bytes, idx, height, round int, typ byte, blockID BlockID)
}
}
func newProposal(height, round int, partsHeader PartSetHeader) *Proposal {
func newProposal(height uint64, round int, partsHeader PartSetHeader) *Proposal {
return &Proposal{
Height: height,
Round: round,

View File

@ -20,7 +20,7 @@ var (
// to be considered valid. It may depend on votes from a previous round,
// a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.
type Proposal struct {
Height int `json:"height"`
Height uint64 `json:"height"`
Round int `json:"round"`
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
POLRound int `json:"pol_round"` // -1 if null.
@ -30,7 +30,7 @@ type Proposal struct {
// NewProposal returns a new Proposal.
// If there is no POLRound, polRound should be -1.
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
func NewProposal(height uint64, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
return &Proposal{
Height: height,
Round: round,

View File

@ -25,10 +25,10 @@ type Mempool interface {
Size() int
CheckTx(Tx, func(*abci.Response)) error
Reap(int) Txs
Update(height int, txs Txs) error
Update(height uint64, txs Txs) error
Flush()
TxsAvailable() <-chan int
TxsAvailable() <-chan uint64
EnableTxsAvailable()
}
@ -42,9 +42,9 @@ func (m MockMempool) Unlock() {}
func (m MockMempool) Size() int { return 0 }
func (m MockMempool) CheckTx(tx Tx, cb func(*abci.Response)) error { return nil }
func (m MockMempool) Reap(n int) Txs { return Txs{} }
func (m MockMempool) Update(height int, txs Txs) error { return nil }
func (m MockMempool) Update(height uint64, txs Txs) error { return nil }
func (m MockMempool) Flush() {}
func (m MockMempool) TxsAvailable() <-chan int { return make(chan int) }
func (m MockMempool) TxsAvailable() <-chan uint64 { return make(chan uint64) }
func (m MockMempool) EnableTxsAvailable() {}
//------------------------------------------------------
@ -53,14 +53,14 @@ func (m MockMempool) EnableTxsAvailable() {}
// BlockStoreRPC is the block store interface used by the RPC.
// UNSTABLE
type BlockStoreRPC interface {
Height() int
Height() uint64
LoadBlockMeta(height int) *BlockMeta
LoadBlock(height int) *Block
LoadBlockPart(height int, index int) *Part
LoadBlockMeta(height uint64) *BlockMeta
LoadBlock(height uint64) *Block
LoadBlockPart(height uint64, index int) *Part
LoadBlockCommit(height int) *Commit
LoadSeenCommit(height int) *Commit
LoadBlockCommit(height uint64) *Commit
LoadSeenCommit(height uint64) *Commit
}
// BlockStore defines the BlockStore interface.

View File

@ -223,7 +223,7 @@ func (valSet *ValidatorSet) Iterate(fn func(index int, val *Validator) bool) {
}
// Verify that +2/3 of the set had signed the given signBytes
func (valSet *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height int, commit *Commit) error {
func (valSet *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height uint64, commit *Commit) error {
if valSet.Size() != len(commit.Precommits) {
return fmt.Errorf("Invalid commit -- wrong set size: %v vs %v", valSet.Size(), len(commit.Precommits))
}
@ -283,7 +283,7 @@ func (valSet *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height
// * 10% of the valset can't just declare themselves kings
// * If the validator set is 3x old size, we need more proof to trust
func (valSet *ValidatorSet) VerifyCommitAny(newSet *ValidatorSet, chainID string,
blockID BlockID, height int, commit *Commit) error {
blockID BlockID, height uint64, commit *Commit) error {
if newSet.Size() != len(commit.Precommits) {
return errors.Errorf("Invalid commit -- wrong set size: %v vs %v", newSet.Size(), len(commit.Precommits))

View File

@ -51,7 +51,7 @@ func IsVoteTypeValid(type_ byte) bool {
type Vote struct {
ValidatorAddress data.Bytes `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
Height int `json:"height"`
Height uint64 `json:"height"`
Round int `json:"round"`
Type byte `json:"type"`
BlockID BlockID `json:"block_id"` // zero if vote is nil.

View File

@ -45,7 +45,7 @@ import (
*/
type VoteSet struct {
chainID string
height int
height uint64
round int
type_ byte
@ -60,7 +60,7 @@ type VoteSet struct {
}
// Constructs a new VoteSet struct used to accumulate votes for given height/round.
func NewVoteSet(chainID string, height int, round int, type_ byte, valSet *ValidatorSet) *VoteSet {
func NewVoteSet(chainID string, height uint64, round int, type_ byte, valSet *ValidatorSet) *VoteSet {
if height == 0 {
cmn.PanicSanity("Cannot make VoteSet for height == 0, doesn't make sense.")
}
@ -83,7 +83,7 @@ func (voteSet *VoteSet) ChainID() string {
return voteSet.chainID
}
func (voteSet *VoteSet) Height() int {
func (voteSet *VoteSet) Height() uint64 {
if voteSet == nil {
return 0
} else {
@ -523,7 +523,7 @@ func (vs *blockVotes) getByIndex(index int) *Vote {
// Common interface between *consensus.VoteSet and types.Commit
type VoteSetReader interface {
Height() int
Height() uint64
Round() int
Type() byte
Size() int

View File

@ -4,13 +4,13 @@ import (
"bytes"
"testing"
"github.com/tendermint/go-crypto"
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
tst "github.com/tendermint/tmlibs/test"
)
// NOTE: privValidators are in order
func randVoteSet(height int, round int, type_ byte, numValidators int, votingPower int64) (*VoteSet, *ValidatorSet, []*PrivValidatorFS) {
func randVoteSet(height uint64, round int, type_ byte, numValidators int, votingPower int64) (*VoteSet, *ValidatorSet, []*PrivValidatorFS) {
valSet, privValidators := RandValidatorSet(numValidators, votingPower)
return NewVoteSet("test_chain_id", height, round, type_, valSet), valSet, privValidators
}
@ -24,7 +24,7 @@ func withValidator(vote *Vote, addr []byte, idx int) *Vote {
}
// Convenience: Return new vote with different height
func withHeight(vote *Vote, height int) *Vote {
func withHeight(vote *Vote, height uint64) *Vote {
vote = vote.Copy()
vote.Height = height
return vote
@ -69,7 +69,7 @@ func signAddVote(privVal *PrivValidatorFS, vote *Vote, voteSet *VoteSet) (bool,
}
func TestAddVote(t *testing.T) {
height, round := 1, 0
height, round := uint64(1), 0
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
val0 := privValidators[0]
@ -112,7 +112,7 @@ func TestAddVote(t *testing.T) {
}
func Test2_3Majority(t *testing.T) {
height, round := 1, 0
height, round := uint64(1), 0
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
voteProto := &Vote{
@ -164,7 +164,7 @@ func Test2_3Majority(t *testing.T) {
}
func Test2_3MajorityRedux(t *testing.T) {
height, round := 1, 0
height, round := uint64(1), 0
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 100, 1)
blockHash := crypto.CRandBytes(32)
@ -262,7 +262,7 @@ func Test2_3MajorityRedux(t *testing.T) {
}
func TestBadVotes(t *testing.T) {
height, round := 1, 0
height, round := uint64(1), 0
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
voteProto := &Vote{
@ -321,7 +321,7 @@ func TestBadVotes(t *testing.T) {
}
func TestConflicts(t *testing.T) {
height, round := 1, 0
height, round := uint64(1), 0
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 4, 1)
blockHash1 := cmn.RandBytes(32)
blockHash2 := cmn.RandBytes(32)
@ -450,7 +450,7 @@ func TestConflicts(t *testing.T) {
}
func TestMakeCommit(t *testing.T) {
height, round := 1, 0
height, round := uint64(1), 0
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrecommit, 10, 1)
blockHash, blockPartsHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)}