mirror of
https://github.com/tendermint/tendermint.git
synced 2026-05-22 07:01:29 +00:00
ints: stricter numbers (#4939)
This commit is contained in:
@@ -12,6 +12,14 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
|
||||
|
||||
- [evidence] \#4725 Remove `Pubkey` from DuplicateVoteEvidence
|
||||
- [rpc] [\#4792](https://github.com/tendermint/tendermint/pull/4792) `/validators` are now sorted by voting power (@melekes)
|
||||
- [types] \#4382 `SignedMsgType` has moved to a Protobuf enum types
|
||||
- [types] \#4382 `Total` has been changed from a `int` to a `uint32`
|
||||
- [types] \#4582 Vote: `ValidatorIndex` & `Round` are now int32
|
||||
- [types] \#4582 Proposal: `POLRound` & `Round` are now int32
|
||||
- [types] \#4582 Block: `Round` is now int32
|
||||
- [consensus] \#4582 RoundState: `Round`, `LockedRound` & `CommitRound` are now int32
|
||||
- [consensus] \#4582 HeightVoteSet: `round` is now int32
|
||||
- [privval] \#4582 `round` in private_validator_state.json is no longer a string in json it is now a number.
|
||||
- [crypto] \#4940 All keys have become `[]byte` instead of `[<size>]byte`. The byte method no longer returns the marshaled value but just the `[]byte` form of the data.
|
||||
- [crypto] \#4941 Remove suffixes from all keys.
|
||||
- ed25519: type `PrivKeyEd25519` is now `PrivKey`
|
||||
|
||||
@@ -116,7 +116,7 @@ To install `protoc`, download an appropriate release (https://github.com/protoco
|
||||
|
||||
To install `gogoproto`, do the following:
|
||||
|
||||
```sh
|
||||
```
|
||||
$ go get github.com/gogo/protobuf/gogoproto
|
||||
$ cd $GOPATH/pkg/mod/github.com/gogo/protobuf@v1.3.1 # or wherever go get installs things
|
||||
$ make install
|
||||
@@ -178,34 +178,34 @@ The main development branch is master.
|
||||
|
||||
Every release is maintained in a release branch named `vX.Y.Z`.
|
||||
|
||||
Pending minor releases have long-lived release candidate ("RC") branches. Minor release changes should be merged to these long-lived RC branches at the same time that the changes are merged to master.
|
||||
Pending minor releases have long-lived release candidate ("RC") branches. Minor release changes should be merged to these long-lived RC branches at the same time that the changes are merged to master.
|
||||
|
||||
Note all pull requests should be squash merged except for merging to a release branch (named `vX.Y`). This keeps the commit history clean and makes it
|
||||
easy to reference the pull request where a change was introduced.
|
||||
|
||||
### Development Procedure
|
||||
|
||||
The latest state of development is on `master`, which must never fail `make test`. _Never_ force push `master`, unless fixing broken git history (which we rarely do anyways).
|
||||
The latest state of development is on `master`, which must never fail `make test`. _Never_ force push `master`, unless fixing broken git history (which we rarely do anyways).
|
||||
|
||||
To begin contributing, create a development branch either on github.com/tendermint/tendermint, or your fork (using `git remote add origin`).
|
||||
To begin contributing, create a development branch either on github.com/tendermint/tendermint, or your fork (using `git remote add origin`).
|
||||
|
||||
Make changes, and before submitting a pull request, update the `CHANGELOG_PENDING.md` to record your change. Also, run either `git rebase` or `git merge` on top of the latest `master`. (Since pull requests are squash-merged, either is fine!)
|
||||
|
||||
Once you have submitted a pull request label the pull request with either `R:minor`, if the change should be included in the next minor release, or `R:major`, if the change is meant for a major release.
|
||||
|
||||
Sometimes (often!) pull requests get out-of-date with master, as other people merge different pull requests to master. It is our convention that pull request authors are responsible for updating their branches with master. (This also means that you shouldn't update someone else's branch for them; even if it seems like you're doing them a favor, you may be interfering with their git flow in some way!)
|
||||
Sometimes (often!) pull requests get out-of-date with master, as other people merge different pull requests to master. It is our convention that pull request authors are responsible for updating their branches with master. (This also means that you shouldn't update someone else's branch for them; even if it seems like you're doing them a favor, you may be interfering with their git flow in some way!)
|
||||
|
||||
#### Merging Pull Requests
|
||||
#### Merging Pull Requests
|
||||
|
||||
It is also our convention that authors merge their own pull requests, when possible. External contributors may not have the necessary permissions to do this, in which case, a member of the core team will merge the pull request once it's been approved.
|
||||
It is also our convention that authors merge their own pull requests, when possible. External contributors may not have the necessary permissions to do this, in which case, a member of the core team will merge the pull request once it's been approved.
|
||||
|
||||
Before merging a pull request:
|
||||
Before merging a pull request:
|
||||
|
||||
- Ensure pull branch is up-to-date with a recent `master` (GitHub won't let you merge without this!)
|
||||
- Ensure pull branch is up-to-date with a recent `master` (GitHub won't let you merge without this!)
|
||||
- Run `make test` to ensure that all tests pass
|
||||
- [Squash](https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git) merge pull request
|
||||
|
||||
#### Pull Requests for Minor Releases
|
||||
#### Pull Requests for Minor Releases
|
||||
|
||||
If your change should be included in a minor release, please also open a PR against the long-lived minor release candidate branch (e.g., `rc1/v0.33.5`) _immediately after your change has been merged to master_.
|
||||
|
||||
@@ -214,12 +214,12 @@ You can do this by cherry-picking your commit off master:
|
||||
```
|
||||
$ git checkout rc1/v0.33.5
|
||||
$ git checkout -b {new branch name}
|
||||
$ git cherry-pick {commit SHA from master}
|
||||
$ git cherry-pick {commit SHA from master}
|
||||
# may need to fix conflicts, and then use git add and git cherry-pick --continue
|
||||
$ git push origin {new branch name}
|
||||
```
|
||||
|
||||
After this, you can open a PR. Please note in the PR body if there were merge conflicts so that reviewers can be sure to take a thorough look.
|
||||
After this, you can open a PR. Please note in the PR body if there were merge conflicts so that reviewers can be sure to take a thorough look.
|
||||
|
||||
### Git Commit Style
|
||||
|
||||
@@ -255,22 +255,22 @@ Each PR should have one commit once it lands on `master`; this can be accomplish
|
||||
|
||||
#### Minor Release
|
||||
|
||||
Minor releases are done differently from major releases: They are built off of long-lived release candidate branches, rather than from master.
|
||||
Minor releases are done differently from major releases: They are built off of long-lived release candidate branches, rather than from master.
|
||||
|
||||
1. Checkout the long-lived release candidate branch: `git checkout rcX/vX.X.X`
|
||||
2. Run integration tests: `make test_integrations`
|
||||
1. Checkout the long-lived release candidate branch: `git checkout rcX/vX.X.X`
|
||||
2. Run integration tests: `make test_integrations`
|
||||
3. Prepare the release:
|
||||
- Copy `CHANGELOG_PENDING.md` to top of `CHANGELOG.md`
|
||||
- Run `python ./scripts/linkify_changelog.py CHANGELOG.md` to add links for all issues
|
||||
- Run `bash ./scripts/authors.sh` to get a list of authors since the latest release, and add the GitHub aliases of external contributors to the top of the CHANGELOG. To lookup an alias from an email, try `bash ./scripts/authors.sh <email>`
|
||||
- Reset the `CHANGELOG_PENDING.md`
|
||||
- Bump the appropriate versions in `version.go`
|
||||
5. Create a release branch `release/vX.X.x` off the release candidate branch:
|
||||
- Copy `CHANGELOG_PENDING.md` to top of `CHANGELOG.md`
|
||||
- Run `python ./scripts/linkify_changelog.py CHANGELOG.md` to add links for all issues
|
||||
- Run `bash ./scripts/authors.sh` to get a list of authors since the latest release, and add the GitHub aliases of external contributors to the top of the CHANGELOG. To lookup an alias from an email, try `bash ./scripts/authors.sh <email>`
|
||||
- Reset the `CHANGELOG_PENDING.md`
|
||||
- Bump the appropriate versions in `version.go`
|
||||
4. Create a release branch `release/vX.X.x` off the release candidate branch:
|
||||
- `git checkout -b release/vX.X.x`
|
||||
- `git push -u origin release/vX.X.x`
|
||||
- Note that all branches prefixed with `release` are protected once pushed. You will need admin help to make any changes to the branch.
|
||||
6. Open a pull request of the new minor release branch onto the latest major release branch `vX.X` and then rebase to merge. This will start the release process.
|
||||
7. Create a pull request back to master with the CHANGELOG & version changes from the latest release.
|
||||
5. Open a pull request of the new minor release branch onto the latest major release branch `vX.X` and then rebase to merge. This will start the release process.
|
||||
6. Create a pull request back to master with the CHANGELOG & version changes from the latest release.
|
||||
- Remove all `R:minor` labels from the pull requests that were included in the release.
|
||||
- Do not merge the release branch into master.
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/mempool/mock"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/store"
|
||||
@@ -64,7 +65,7 @@ func makeVote(
|
||||
Height: header.Height,
|
||||
Round: 1,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: types.PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: blockID,
|
||||
}
|
||||
|
||||
|
||||
@@ -870,21 +870,21 @@ func (cfg *ConsensusConfig) WaitForTxs() bool {
|
||||
}
|
||||
|
||||
// Propose returns the amount of time to wait for a proposal
|
||||
func (cfg *ConsensusConfig) Propose(round int) time.Duration {
|
||||
func (cfg *ConsensusConfig) Propose(round int32) time.Duration {
|
||||
return time.Duration(
|
||||
cfg.TimeoutPropose.Nanoseconds()+cfg.TimeoutProposeDelta.Nanoseconds()*int64(round),
|
||||
) * time.Nanosecond
|
||||
}
|
||||
|
||||
// Prevote returns the amount of time to wait for straggler votes after receiving any +2/3 prevotes
|
||||
func (cfg *ConsensusConfig) Prevote(round int) time.Duration {
|
||||
func (cfg *ConsensusConfig) Prevote(round int32) time.Duration {
|
||||
return time.Duration(
|
||||
cfg.TimeoutPrevote.Nanoseconds()+cfg.TimeoutPrevoteDelta.Nanoseconds()*int64(round),
|
||||
) * time.Nanosecond
|
||||
}
|
||||
|
||||
// Precommit returns the amount of time to wait for straggler votes after receiving any +2/3 precommits
|
||||
func (cfg *ConsensusConfig) Precommit(round int) time.Duration {
|
||||
func (cfg *ConsensusConfig) Precommit(round int32) time.Duration {
|
||||
return time.Duration(
|
||||
cfg.TimeoutPrecommit.Nanoseconds()+cfg.TimeoutPrecommitDelta.Nanoseconds()*int64(round),
|
||||
) * time.Nanosecond
|
||||
|
||||
@@ -500,6 +500,6 @@ var testPrivValidatorKey = `{
|
||||
|
||||
var testPrivValidatorState = `{
|
||||
"height": "0",
|
||||
"round": "0",
|
||||
"round": 0,
|
||||
"step": 0
|
||||
}`
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@@ -56,12 +57,12 @@ func TestByzantine(t *testing.T) {
|
||||
// NOTE: Now, test validators are MockPV, which by default doesn't
|
||||
// do any safety checks.
|
||||
css[i].privValidator.(types.MockPV).DisableChecks()
|
||||
css[i].decideProposal = func(j int) func(int64, int) {
|
||||
return func(height int64, round int) {
|
||||
css[i].decideProposal = func(j int32) func(int64, int32) {
|
||||
return func(height int64, round int32) {
|
||||
byzantineDecideProposalFunc(t, height, round, css[j], switches[j])
|
||||
}
|
||||
}(i)
|
||||
css[i].doPrevote = func(height int64, round int) {}
|
||||
}(int32(i))
|
||||
css[i].doPrevote = func(height int64, round int32) {}
|
||||
}
|
||||
|
||||
eventBus := css[i].eventBus
|
||||
@@ -172,7 +173,7 @@ func TestByzantine(t *testing.T) {
|
||||
//-------------------------------
|
||||
// byzantine consensus functions
|
||||
|
||||
func byzantineDecideProposalFunc(t *testing.T, height int64, round int, cs *State, sw *p2p.Switch) {
|
||||
func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *State, sw *p2p.Switch) {
|
||||
// byzantine user should create two proposals and try to split the vote.
|
||||
// Avoid sending on internalMsgQueue and running consensus state.
|
||||
|
||||
@@ -209,7 +210,7 @@ func byzantineDecideProposalFunc(t *testing.T, height int64, round int, cs *Stat
|
||||
|
||||
func sendProposalAndParts(
|
||||
height int64,
|
||||
round int,
|
||||
round int32,
|
||||
cs *State,
|
||||
peer p2p.Peer,
|
||||
proposal *types.Proposal,
|
||||
@@ -221,7 +222,7 @@ func sendProposalAndParts(
|
||||
peer.Send(DataChannel, cdc.MustMarshalBinaryBare(msg))
|
||||
|
||||
// parts
|
||||
for i := 0; i < parts.Total(); i++ {
|
||||
for i := 0; i < int(parts.Total()); i++ {
|
||||
part := parts.GetPart(i)
|
||||
msg := &BlockPartMessage{
|
||||
Height: height, // This tells peer that this part applies to us.
|
||||
@@ -233,8 +234,8 @@ func sendProposalAndParts(
|
||||
|
||||
// votes
|
||||
cs.mtx.Lock()
|
||||
prevote, _ := cs.signVote(types.PrevoteType, blockHash, parts.Header())
|
||||
precommit, _ := cs.signVote(types.PrecommitType, blockHash, parts.Header())
|
||||
prevote, _ := cs.signVote(tmproto.PrevoteType, blockHash, parts.Header())
|
||||
precommit, _ := cs.signVote(tmproto.PrecommitType, blockHash, parts.Header())
|
||||
cs.mtx.Unlock()
|
||||
|
||||
peer.Send(VoteChannel, cdc.MustMarshalBinaryBare(&VoteMessage{prevote}))
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
mempl "github.com/tendermint/tendermint/mempool"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
"github.com/tendermint/tendermint/privval"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/store"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -67,16 +68,16 @@ func ResetConfig(name string) *cfg.Config {
|
||||
// validator stub (a kvstore consensus peer we control)
|
||||
|
||||
type validatorStub struct {
|
||||
Index int // Validator index. NOTE: we don't assume validator set changes.
|
||||
Index int32 // Validator index. NOTE: we don't assume validator set changes.
|
||||
Height int64
|
||||
Round int
|
||||
Round int32
|
||||
types.PrivValidator
|
||||
VotingPower int64
|
||||
}
|
||||
|
||||
var testMinPower int64 = 10
|
||||
|
||||
func newValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
|
||||
func newValidatorStub(privValidator types.PrivValidator, valIndex int32) *validatorStub {
|
||||
return &validatorStub{
|
||||
Index: valIndex,
|
||||
PrivValidator: privValidator,
|
||||
@@ -85,7 +86,7 @@ func newValidatorStub(privValidator types.PrivValidator, valIndex int) *validato
|
||||
}
|
||||
|
||||
func (vs *validatorStub) signVote(
|
||||
voteType types.SignedMsgType,
|
||||
voteType tmproto.SignedMsgType,
|
||||
hash []byte,
|
||||
header types.PartSetHeader) (*types.Vote, error) {
|
||||
|
||||
@@ -109,7 +110,7 @@ func (vs *validatorStub) signVote(
|
||||
}
|
||||
|
||||
// Sign vote for type/hash/header
|
||||
func signVote(vs *validatorStub, voteType types.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote {
|
||||
func signVote(vs *validatorStub, voteType tmproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote {
|
||||
v, err := vs.signVote(voteType, hash, header)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to sign vote: %v", err))
|
||||
@@ -118,7 +119,7 @@ func signVote(vs *validatorStub, voteType types.SignedMsgType, hash []byte, head
|
||||
}
|
||||
|
||||
func signVotes(
|
||||
voteType types.SignedMsgType,
|
||||
voteType tmproto.SignedMsgType,
|
||||
hash []byte,
|
||||
header types.PartSetHeader,
|
||||
vss ...*validatorStub) []*types.Vote {
|
||||
@@ -166,15 +167,15 @@ func (vss ValidatorStubsByPower) Less(i, j int) bool {
|
||||
func (vss ValidatorStubsByPower) Swap(i, j int) {
|
||||
it := vss[i]
|
||||
vss[i] = vss[j]
|
||||
vss[i].Index = i
|
||||
vss[i].Index = int32(i)
|
||||
vss[j] = it
|
||||
vss[j].Index = j
|
||||
vss[j].Index = int32(j)
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// Functions for transitioning the consensus state
|
||||
|
||||
func startTestRound(cs *State, height int64, round int) {
|
||||
func startTestRound(cs *State, height int64, round int32) {
|
||||
cs.enterNewRound(height, round)
|
||||
cs.startRoutines(0)
|
||||
}
|
||||
@@ -184,7 +185,7 @@ func decideProposal(
|
||||
cs1 *State,
|
||||
vs *validatorStub,
|
||||
height int64,
|
||||
round int,
|
||||
round int32,
|
||||
) (proposal *types.Proposal, block *types.Block) {
|
||||
cs1.mtx.Lock()
|
||||
block, blockParts := cs1.createProposalBlock()
|
||||
@@ -212,7 +213,7 @@ func addVotes(to *State, votes ...*types.Vote) {
|
||||
|
||||
func signAddVotes(
|
||||
to *State,
|
||||
voteType types.SignedMsgType,
|
||||
voteType tmproto.SignedMsgType,
|
||||
hash []byte,
|
||||
header types.PartSetHeader,
|
||||
vss ...*validatorStub,
|
||||
@@ -221,7 +222,7 @@ func signAddVotes(
|
||||
addVotes(to, votes...)
|
||||
}
|
||||
|
||||
func validatePrevote(t *testing.T, cs *State, round int, privVal *validatorStub, blockHash []byte) {
|
||||
func validatePrevote(t *testing.T, cs *State, round int32, privVal *validatorStub, blockHash []byte) {
|
||||
prevotes := cs.Votes.Prevotes(round)
|
||||
pubKey, err := privVal.GetPubKey()
|
||||
require.NoError(t, err)
|
||||
@@ -259,7 +260,7 @@ func validatePrecommit(
|
||||
t *testing.T,
|
||||
cs *State,
|
||||
thisRound,
|
||||
lockRound int,
|
||||
lockRound int32,
|
||||
privVal *validatorStub,
|
||||
votedBlockHash,
|
||||
lockedBlockHash []byte,
|
||||
@@ -307,7 +308,7 @@ func validatePrevoteAndPrecommit(
|
||||
t *testing.T,
|
||||
cs *State,
|
||||
thisRound,
|
||||
lockRound int,
|
||||
lockRound int32,
|
||||
privVal *validatorStub,
|
||||
votedBlockHash,
|
||||
lockedBlockHash []byte,
|
||||
@@ -413,7 +414,7 @@ func randState(nValidators int) (*State, []*validatorStub) {
|
||||
cs := newState(state, privVals[0], counter.NewApplication(true))
|
||||
|
||||
for i := 0; i < nValidators; i++ {
|
||||
vss[i] = newValidatorStub(privVals[i], i)
|
||||
vss[i] = newValidatorStub(privVals[i], int32(i))
|
||||
}
|
||||
// since cs1 starts at 1
|
||||
incrementHeight(vss[1:]...)
|
||||
@@ -462,7 +463,7 @@ func ensureNoNewTimeout(stepCh <-chan tmpubsub.Message, timeout int64) {
|
||||
"We should be stuck waiting, not receiving NewTimeout event")
|
||||
}
|
||||
|
||||
func ensureNewEvent(ch <-chan tmpubsub.Message, height int64, round int, timeout time.Duration, errorMessage string) {
|
||||
func ensureNewEvent(ch <-chan tmpubsub.Message, height int64, round int32, timeout time.Duration, errorMessage string) {
|
||||
select {
|
||||
case <-time.After(timeout):
|
||||
panic(errorMessage)
|
||||
@@ -482,7 +483,7 @@ func ensureNewEvent(ch <-chan tmpubsub.Message, height int64, round int, timeout
|
||||
}
|
||||
}
|
||||
|
||||
func ensureNewRound(roundCh <-chan tmpubsub.Message, height int64, round int) {
|
||||
func ensureNewRound(roundCh <-chan tmpubsub.Message, height int64, round int32) {
|
||||
select {
|
||||
case <-time.After(ensureTimeout):
|
||||
panic("Timeout expired while waiting for NewRound event")
|
||||
@@ -501,13 +502,13 @@ func ensureNewRound(roundCh <-chan tmpubsub.Message, height int64, round int) {
|
||||
}
|
||||
}
|
||||
|
||||
func ensureNewTimeout(timeoutCh <-chan tmpubsub.Message, height int64, round int, timeout int64) {
|
||||
func ensureNewTimeout(timeoutCh <-chan tmpubsub.Message, height int64, round int32, timeout int64) {
|
||||
timeoutDuration := time.Duration(timeout*10) * time.Nanosecond
|
||||
ensureNewEvent(timeoutCh, height, round, timeoutDuration,
|
||||
"Timeout expired while waiting for NewTimeout event")
|
||||
}
|
||||
|
||||
func ensureNewProposal(proposalCh <-chan tmpubsub.Message, height int64, round int) {
|
||||
func ensureNewProposal(proposalCh <-chan tmpubsub.Message, height int64, round int32) {
|
||||
select {
|
||||
case <-time.After(ensureTimeout):
|
||||
panic("Timeout expired while waiting for NewProposal event")
|
||||
@@ -526,7 +527,7 @@ func ensureNewProposal(proposalCh <-chan tmpubsub.Message, height int64, round i
|
||||
}
|
||||
}
|
||||
|
||||
func ensureNewValidBlock(validBlockCh <-chan tmpubsub.Message, height int64, round int) {
|
||||
func ensureNewValidBlock(validBlockCh <-chan tmpubsub.Message, height int64, round int32) {
|
||||
ensureNewEvent(validBlockCh, height, round, ensureTimeout,
|
||||
"Timeout expired while waiting for NewValidBlock event")
|
||||
}
|
||||
@@ -566,12 +567,12 @@ func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHa
|
||||
}
|
||||
}
|
||||
|
||||
func ensureNewUnlock(unlockCh <-chan tmpubsub.Message, height int64, round int) {
|
||||
func ensureNewUnlock(unlockCh <-chan tmpubsub.Message, height int64, round int32) {
|
||||
ensureNewEvent(unlockCh, height, round, ensureTimeout,
|
||||
"Timeout expired while waiting for NewUnlock event")
|
||||
}
|
||||
|
||||
func ensureProposal(proposalCh <-chan tmpubsub.Message, height int64, round int, propID types.BlockID) {
|
||||
func ensureProposal(proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID) {
|
||||
select {
|
||||
case <-time.After(ensureTimeout):
|
||||
panic("Timeout expired while waiting for NewProposal event")
|
||||
@@ -593,16 +594,16 @@ func ensureProposal(proposalCh <-chan tmpubsub.Message, height int64, round int,
|
||||
}
|
||||
}
|
||||
|
||||
func ensurePrecommit(voteCh <-chan tmpubsub.Message, height int64, round int) {
|
||||
ensureVote(voteCh, height, round, types.PrecommitType)
|
||||
func ensurePrecommit(voteCh <-chan tmpubsub.Message, height int64, round int32) {
|
||||
ensureVote(voteCh, height, round, tmproto.PrecommitType)
|
||||
}
|
||||
|
||||
func ensurePrevote(voteCh <-chan tmpubsub.Message, height int64, round int) {
|
||||
ensureVote(voteCh, height, round, types.PrevoteType)
|
||||
func ensurePrevote(voteCh <-chan tmpubsub.Message, height int64, round int32) {
|
||||
ensureVote(voteCh, height, round, tmproto.PrevoteType)
|
||||
}
|
||||
|
||||
func ensureVote(voteCh <-chan tmpubsub.Message, height int64, round int,
|
||||
voteType types.SignedMsgType) {
|
||||
func ensureVote(voteCh <-chan tmpubsub.Message, height int64, round int32,
|
||||
voteType tmproto.SignedMsgType) {
|
||||
select {
|
||||
case <-time.After(ensureTimeout):
|
||||
panic("Timeout expired while waiting for NewVote event")
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
tmevents "github.com/tendermint/tendermint/libs/events"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
@@ -263,9 +264,9 @@ func (conR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
|
||||
// (and consequently shows which we don't have)
|
||||
var ourVotes *bits.BitArray
|
||||
switch msg.Type {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
|
||||
default:
|
||||
panic("Bad VoteSetBitsMessage field Type. Forgot to add a check in ValidateBasic?")
|
||||
@@ -293,7 +294,7 @@ func (conR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
|
||||
case *ProposalPOLMessage:
|
||||
ps.ApplyProposalPOLMessage(msg)
|
||||
case *BlockPartMessage:
|
||||
ps.SetHasProposalBlockPart(msg.Height, msg.Round, msg.Part.Index)
|
||||
ps.SetHasProposalBlockPart(msg.Height, msg.Round, int(msg.Part.Index))
|
||||
conR.Metrics.BlockParts.With("peer_id", string(src.ID())).Add(1)
|
||||
conR.conS.peerMsgQueue <- msgInfo{msg, src.ID()}
|
||||
default:
|
||||
@@ -337,9 +338,9 @@ func (conR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
|
||||
if height == msg.Height {
|
||||
var ourVotes *bits.BitArray
|
||||
switch msg.Type {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
|
||||
default:
|
||||
panic("Bad VoteSetBitsMessage field Type. Forgot to add a check in ValidateBasic?")
|
||||
@@ -753,7 +754,7 @@ OUTER_LOOP:
|
||||
peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
|
||||
Height: prs.Height,
|
||||
Round: prs.Round,
|
||||
Type: types.PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: maj23,
|
||||
}))
|
||||
time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
|
||||
@@ -770,7 +771,7 @@ OUTER_LOOP:
|
||||
peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
|
||||
Height: prs.Height,
|
||||
Round: prs.Round,
|
||||
Type: types.PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: maj23,
|
||||
}))
|
||||
time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
|
||||
@@ -787,7 +788,7 @@ OUTER_LOOP:
|
||||
peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
|
||||
Height: prs.Height,
|
||||
Round: prs.ProposalPOLRound,
|
||||
Type: types.PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: maj23,
|
||||
}))
|
||||
time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
|
||||
@@ -807,7 +808,7 @@ OUTER_LOOP:
|
||||
peer.TrySend(StateChannel, cdc.MustMarshalBinaryBare(&VoteSetMaj23Message{
|
||||
Height: prs.Height,
|
||||
Round: commit.Round,
|
||||
Type: types.PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: commit.BlockID,
|
||||
}))
|
||||
time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
|
||||
@@ -989,7 +990,7 @@ func (ps *PeerState) SetHasProposal(proposal *types.Proposal) {
|
||||
}
|
||||
|
||||
ps.PRS.ProposalBlockPartsHeader = proposal.BlockID.PartsHeader
|
||||
ps.PRS.ProposalBlockParts = bits.NewBitArray(proposal.BlockID.PartsHeader.Total)
|
||||
ps.PRS.ProposalBlockParts = bits.NewBitArray(int(proposal.BlockID.PartsHeader.Total))
|
||||
ps.PRS.ProposalPOLRound = proposal.POLRound
|
||||
ps.PRS.ProposalPOL = nil // Nil until ProposalPOLMessage received.
|
||||
}
|
||||
@@ -1004,11 +1005,11 @@ func (ps *PeerState) InitProposalBlockParts(partsHeader types.PartSetHeader) {
|
||||
}
|
||||
|
||||
ps.PRS.ProposalBlockPartsHeader = partsHeader
|
||||
ps.PRS.ProposalBlockParts = bits.NewBitArray(partsHeader.Total)
|
||||
ps.PRS.ProposalBlockParts = bits.NewBitArray(int(partsHeader.Total))
|
||||
}
|
||||
|
||||
// SetHasProposalBlockPart sets the given block part index as known for the peer.
|
||||
func (ps *PeerState) SetHasProposalBlockPart(height int64, round int, index int) {
|
||||
func (ps *PeerState) SetHasProposalBlockPart(height int64, round int32, index int) {
|
||||
ps.mtx.Lock()
|
||||
defer ps.mtx.Unlock()
|
||||
|
||||
@@ -1045,7 +1046,8 @@ func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote
|
||||
return nil, false
|
||||
}
|
||||
|
||||
height, round, votesType, size := votes.GetHeight(), votes.GetRound(), types.SignedMsgType(votes.Type()), votes.Size()
|
||||
height, round, votesType, size := votes.GetHeight(), votes.GetRound(),
|
||||
tmproto.SignedMsgType(votes.Type()), votes.Size()
|
||||
|
||||
// Lazily set data using 'votes'.
|
||||
if votes.IsCommit() {
|
||||
@@ -1058,12 +1060,12 @@ func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote
|
||||
return nil, false // Not something worth sending
|
||||
}
|
||||
if index, ok := votes.BitArray().Sub(psVotes).PickRandom(); ok {
|
||||
return votes.GetByIndex(index), true
|
||||
return votes.GetByIndex(int32(index)), true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (ps *PeerState) getVoteBitArray(height int64, round int, votesType types.SignedMsgType) *bits.BitArray {
|
||||
func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType tmproto.SignedMsgType) *bits.BitArray {
|
||||
if !types.IsVoteTypeValid(votesType) {
|
||||
return nil
|
||||
}
|
||||
@@ -1071,25 +1073,25 @@ func (ps *PeerState) getVoteBitArray(height int64, round int, votesType types.Si
|
||||
if ps.PRS.Height == height {
|
||||
if ps.PRS.Round == round {
|
||||
switch votesType {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
return ps.PRS.Prevotes
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
return ps.PRS.Precommits
|
||||
}
|
||||
}
|
||||
if ps.PRS.CatchupCommitRound == round {
|
||||
switch votesType {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
return nil
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
return ps.PRS.CatchupCommit
|
||||
}
|
||||
}
|
||||
if ps.PRS.ProposalPOLRound == round {
|
||||
switch votesType {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
return ps.PRS.ProposalPOL
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -1098,9 +1100,9 @@ func (ps *PeerState) getVoteBitArray(height int64, round int, votesType types.Si
|
||||
if ps.PRS.Height == height+1 {
|
||||
if ps.PRS.LastCommitRound == round {
|
||||
switch votesType {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
return nil
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
return ps.PRS.LastCommit
|
||||
}
|
||||
}
|
||||
@@ -1110,7 +1112,7 @@ func (ps *PeerState) getVoteBitArray(height int64, round int, votesType types.Si
|
||||
}
|
||||
|
||||
// 'round': A round for which we have a +2/3 commit.
|
||||
func (ps *PeerState) ensureCatchupCommitRound(height int64, round int, numValidators int) {
|
||||
func (ps *PeerState) ensureCatchupCommitRound(height int64, round int32, numValidators int) {
|
||||
if ps.PRS.Height != height {
|
||||
return
|
||||
}
|
||||
@@ -1215,7 +1217,7 @@ func (ps *PeerState) SetHasVote(vote *types.Vote) {
|
||||
ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex)
|
||||
}
|
||||
|
||||
func (ps *PeerState) setHasVote(height int64, round int, voteType types.SignedMsgType, index int) {
|
||||
func (ps *PeerState) setHasVote(height int64, round int32, voteType tmproto.SignedMsgType, index int32) {
|
||||
logger := ps.logger.With(
|
||||
"peerH/R",
|
||||
fmt.Sprintf("%d/%d", ps.PRS.Height, ps.PRS.Round),
|
||||
@@ -1226,7 +1228,7 @@ func (ps *PeerState) setHasVote(height int64, round int, voteType types.SignedMs
|
||||
// NOTE: some may be nil BitArrays -> no side effects.
|
||||
psVotes := ps.getVoteBitArray(height, round, voteType)
|
||||
if psVotes != nil {
|
||||
psVotes.SetIndex(index, true)
|
||||
psVotes.SetIndex(int(index), true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1402,10 +1404,10 @@ func decodeMsg(bz []byte) (msg Message, err error) {
|
||||
// For every height/round/step transition
|
||||
type NewRoundStepMessage struct {
|
||||
Height int64
|
||||
Round int
|
||||
Round int32
|
||||
Step cstypes.RoundStepType
|
||||
SecondsSinceStartTime int
|
||||
LastCommitRound int
|
||||
LastCommitRound int32
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation.
|
||||
@@ -1442,7 +1444,7 @@ func (m *NewRoundStepMessage) String() string {
|
||||
// In case the block is also committed, then IsCommit flag is set to true.
|
||||
type NewValidBlockMessage struct {
|
||||
Height int64
|
||||
Round int
|
||||
Round int32
|
||||
BlockPartsHeader types.PartSetHeader
|
||||
BlockParts *bits.BitArray
|
||||
IsCommit bool
|
||||
@@ -1462,12 +1464,12 @@ func (m *NewValidBlockMessage) ValidateBasic() error {
|
||||
if m.BlockParts.Size() == 0 {
|
||||
return errors.New("empty blockParts")
|
||||
}
|
||||
if m.BlockParts.Size() != m.BlockPartsHeader.Total {
|
||||
if m.BlockParts.Size() != int(m.BlockPartsHeader.Total) {
|
||||
return fmt.Errorf("blockParts bit array size %d not equal to BlockPartsHeader.Total %d",
|
||||
m.BlockParts.Size(),
|
||||
m.BlockPartsHeader.Total)
|
||||
}
|
||||
if m.BlockParts.Size() > types.MaxBlockPartsCount {
|
||||
if m.BlockParts.Size() > int(types.MaxBlockPartsCount) {
|
||||
return fmt.Errorf("blockParts bit array is too big: %d, max: %d", m.BlockParts.Size(), types.MaxBlockPartsCount)
|
||||
}
|
||||
return nil
|
||||
@@ -1501,7 +1503,7 @@ func (m *ProposalMessage) String() string {
|
||||
// ProposalPOLMessage is sent when a previous proposal is re-proposed.
|
||||
type ProposalPOLMessage struct {
|
||||
Height int64
|
||||
ProposalPOLRound int
|
||||
ProposalPOLRound int32
|
||||
ProposalPOL *bits.BitArray
|
||||
}
|
||||
|
||||
@@ -1532,7 +1534,7 @@ func (m *ProposalPOLMessage) String() string {
|
||||
// BlockPartMessage is sent when gossipping a piece of the proposed block.
|
||||
type BlockPartMessage struct {
|
||||
Height int64
|
||||
Round int
|
||||
Round int32
|
||||
Part *types.Part
|
||||
}
|
||||
|
||||
@@ -1577,9 +1579,9 @@ func (m *VoteMessage) String() string {
|
||||
// HasVoteMessage is sent to indicate that a particular vote has been received.
|
||||
type HasVoteMessage struct {
|
||||
Height int64
|
||||
Round int
|
||||
Type types.SignedMsgType
|
||||
Index int
|
||||
Round int32
|
||||
Type tmproto.SignedMsgType
|
||||
Index int32
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation.
|
||||
@@ -1609,8 +1611,8 @@ func (m *HasVoteMessage) String() string {
|
||||
// VoteSetMaj23Message is sent to indicate that a given BlockID has seen +2/3 votes.
|
||||
type VoteSetMaj23Message struct {
|
||||
Height int64
|
||||
Round int
|
||||
Type types.SignedMsgType
|
||||
Round int32
|
||||
Type tmproto.SignedMsgType
|
||||
BlockID types.BlockID
|
||||
}
|
||||
|
||||
@@ -1641,8 +1643,8 @@ func (m *VoteSetMaj23Message) String() string {
|
||||
// VoteSetBitsMessage is sent to communicate the bit-array of votes seen for the BlockID.
|
||||
type VoteSetBitsMessage struct {
|
||||
Height int64
|
||||
Round int
|
||||
Type types.SignedMsgType
|
||||
Round int32
|
||||
Type tmproto.SignedMsgType
|
||||
BlockID types.BlockID
|
||||
Votes *bits.BitArray
|
||||
}
|
||||
@@ -1652,9 +1654,6 @@ func (m *VoteSetBitsMessage) ValidateBasic() error {
|
||||
if m.Height < 0 {
|
||||
return errors.New("negative Height")
|
||||
}
|
||||
if m.Round < 0 {
|
||||
return errors.New("negative Round")
|
||||
}
|
||||
if !types.IsVoteTypeValid(m.Type) {
|
||||
return errors.New("invalid Type")
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
mempl "github.com/tendermint/tendermint/mempool"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
"github.com/tendermint/tendermint/p2p/mock"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/store"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -272,7 +273,7 @@ func TestReactorReceiveDoesNotPanicIfAddPeerHasntBeenCalledYet(t *testing.T) {
|
||||
var (
|
||||
reactor = reactors[0]
|
||||
peer = mock.NewPeer(nil)
|
||||
msg = cdc.MustMarshalBinaryBare(&HasVoteMessage{Height: 1, Round: 1, Index: 1, Type: types.PrevoteType})
|
||||
msg = cdc.MustMarshalBinaryBare(&HasVoteMessage{Height: 1, Round: 1, Index: 1, Type: tmproto.PrevoteType})
|
||||
)
|
||||
|
||||
reactor.InitPeer(peer)
|
||||
@@ -294,7 +295,7 @@ func TestReactorReceivePanicsIfInitPeerHasntBeenCalledYet(t *testing.T) {
|
||||
var (
|
||||
reactor = reactors[0]
|
||||
peer = mock.NewPeer(nil)
|
||||
msg = cdc.MustMarshalBinaryBare(&HasVoteMessage{Height: 1, Round: 1, Index: 1, Type: types.PrevoteType})
|
||||
msg = cdc.MustMarshalBinaryBare(&HasVoteMessage{Height: 1, Round: 1, Index: 1, Type: tmproto.PrevoteType})
|
||||
)
|
||||
|
||||
// we should call InitPeer here
|
||||
@@ -692,8 +693,8 @@ func capture() {
|
||||
func TestNewRoundStepMessageValidateBasic(t *testing.T) {
|
||||
testCases := []struct { // nolint: maligned
|
||||
expectErr bool
|
||||
messageRound int
|
||||
messageLastCommitRound int
|
||||
messageRound int32
|
||||
messageLastCommitRound int32
|
||||
messageHeight int64
|
||||
testName string
|
||||
messageStep cstypes.RoundStepType
|
||||
@@ -738,7 +739,7 @@ func TestNewValidBlockMessageValidateBasic(t *testing.T) {
|
||||
"empty blockParts",
|
||||
},
|
||||
{
|
||||
func(msg *NewValidBlockMessage) { msg.BlockParts = bits.NewBitArray(types.MaxBlockPartsCount + 1) },
|
||||
func(msg *NewValidBlockMessage) { msg.BlockParts = bits.NewBitArray(int(types.MaxBlockPartsCount) + 1) },
|
||||
"blockParts bit array size 1602 not equal to BlockPartsHeader.Total 1",
|
||||
},
|
||||
}
|
||||
@@ -801,7 +802,7 @@ func TestBlockPartMessageValidateBasic(t *testing.T) {
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageRound int
|
||||
messageRound int32
|
||||
messagePart *types.Part
|
||||
expectErr bool
|
||||
}{
|
||||
@@ -824,24 +825,24 @@ func TestBlockPartMessageValidateBasic(t *testing.T) {
|
||||
}
|
||||
|
||||
message := BlockPartMessage{Height: 0, Round: 0, Part: new(types.Part)}
|
||||
message.Part.Index = -1
|
||||
message.Part.Index = 1
|
||||
|
||||
assert.Equal(t, true, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
}
|
||||
|
||||
func TestHasVoteMessageValidateBasic(t *testing.T) {
|
||||
const (
|
||||
validSignedMsgType types.SignedMsgType = 0x01
|
||||
invalidSignedMsgType types.SignedMsgType = 0x03
|
||||
validSignedMsgType tmproto.SignedMsgType = 0x01
|
||||
invalidSignedMsgType tmproto.SignedMsgType = 0x03
|
||||
)
|
||||
|
||||
testCases := []struct { // nolint: maligned
|
||||
expectErr bool
|
||||
messageRound int
|
||||
messageIndex int
|
||||
messageRound int32
|
||||
messageIndex int32
|
||||
messageHeight int64
|
||||
testName string
|
||||
messageType types.SignedMsgType
|
||||
messageType tmproto.SignedMsgType
|
||||
}{
|
||||
{false, 0, 0, 0, "Valid Message", validSignedMsgType},
|
||||
{true, -1, 0, 0, "Invalid Message", validSignedMsgType},
|
||||
@@ -867,25 +868,25 @@ func TestHasVoteMessageValidateBasic(t *testing.T) {
|
||||
|
||||
func TestVoteSetMaj23MessageValidateBasic(t *testing.T) {
|
||||
const (
|
||||
validSignedMsgType types.SignedMsgType = 0x01
|
||||
invalidSignedMsgType types.SignedMsgType = 0x03
|
||||
validSignedMsgType tmproto.SignedMsgType = 0x01
|
||||
invalidSignedMsgType tmproto.SignedMsgType = 0x03
|
||||
)
|
||||
|
||||
validBlockID := types.BlockID{}
|
||||
invalidBlockID := types.BlockID{
|
||||
Hash: bytes.HexBytes{},
|
||||
PartsHeader: types.PartSetHeader{
|
||||
Total: -1,
|
||||
Hash: bytes.HexBytes{},
|
||||
Total: 1,
|
||||
Hash: []byte{0},
|
||||
},
|
||||
}
|
||||
|
||||
testCases := []struct { // nolint: maligned
|
||||
expectErr bool
|
||||
messageRound int
|
||||
messageRound int32
|
||||
messageHeight int64
|
||||
testName string
|
||||
messageType types.SignedMsgType
|
||||
messageType tmproto.SignedMsgType
|
||||
messageBlockID types.BlockID
|
||||
}{
|
||||
{false, 0, 0, "Valid Message", validSignedMsgType, validBlockID},
|
||||
@@ -911,23 +912,22 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
|
||||
testCases := []struct { // nolint: maligned
|
||||
testCases := []struct {
|
||||
malleateFn func(*VoteSetBitsMessage)
|
||||
expErr string
|
||||
}{
|
||||
{func(msg *VoteSetBitsMessage) {}, ""},
|
||||
{func(msg *VoteSetBitsMessage) { msg.Height = -1 }, "negative Height"},
|
||||
{func(msg *VoteSetBitsMessage) { msg.Round = -1 }, "negative Round"},
|
||||
{func(msg *VoteSetBitsMessage) { msg.Type = 0x03 }, "invalid Type"},
|
||||
{func(msg *VoteSetBitsMessage) {
|
||||
msg.BlockID = types.BlockID{
|
||||
Hash: bytes.HexBytes{},
|
||||
PartsHeader: types.PartSetHeader{
|
||||
Total: -1,
|
||||
Hash: bytes.HexBytes{},
|
||||
Total: 1,
|
||||
Hash: []byte{0},
|
||||
},
|
||||
}
|
||||
}, "wrong BlockID: wrong PartsHeader: negative Total"},
|
||||
}, "wrong BlockID: wrong PartsHeader: wrong Hash:"},
|
||||
{func(msg *VoteSetBitsMessage) { msg.Votes = bits.NewBitArray(types.MaxVotesCount + 1) },
|
||||
"votes bit array is too big: 10001, max: 10000"},
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
mempl "github.com/tendermint/tendermint/mempool"
|
||||
"github.com/tendermint/tendermint/privval"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -330,7 +331,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
|
||||
|
||||
vss := make([]*validatorStub, nPeers)
|
||||
for i := 0; i < nPeers; i++ {
|
||||
vss[i] = newValidatorStub(css[i].privValidator, i)
|
||||
vss[i] = newValidatorStub(css[i].privValidator, int32(i))
|
||||
}
|
||||
height, round := css[0].Height, css[0].Round
|
||||
|
||||
@@ -340,7 +341,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
|
||||
ensureNewRound(newRoundCh, height, 0)
|
||||
ensureNewProposal(proposalCh, height, round)
|
||||
rs := css[0].GetRoundState()
|
||||
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
|
||||
signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -368,7 +369,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
|
||||
}
|
||||
ensureNewProposal(proposalCh, height, round)
|
||||
rs = css[0].GetRoundState()
|
||||
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
|
||||
signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -396,7 +397,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
|
||||
}
|
||||
ensureNewProposal(proposalCh, height, round)
|
||||
rs = css[0].GetRoundState()
|
||||
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
|
||||
signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -460,7 +461,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
|
||||
if i == selfIndex {
|
||||
continue
|
||||
}
|
||||
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
|
||||
signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
|
||||
}
|
||||
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
@@ -481,7 +482,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
|
||||
if i == selfIndex {
|
||||
continue
|
||||
}
|
||||
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
|
||||
signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
|
||||
}
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
|
||||
@@ -516,7 +517,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
|
||||
if i == selfIndex {
|
||||
continue
|
||||
}
|
||||
signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
|
||||
signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
|
||||
}
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
|
||||
@@ -1038,7 +1039,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
case *types.Vote:
|
||||
if p.Type == types.PrecommitType {
|
||||
if p.Type == tmproto.PrecommitType {
|
||||
thisBlockCommit = types.NewCommit(p.Height, p.Round,
|
||||
p.BlockID, []types.CommitSig{p.CommitSig()})
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
"github.com/tendermint/tendermint/libs/service"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
cstypes "github.com/tendermint/tendermint/consensus/types"
|
||||
tmevents "github.com/tendermint/tendermint/libs/events"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -50,7 +52,7 @@ type msgInfo struct {
|
||||
type timeoutInfo struct {
|
||||
Duration time.Duration `json:"duration"`
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
Step cstypes.RoundStepType `json:"step"`
|
||||
}
|
||||
|
||||
@@ -122,8 +124,8 @@ type State struct {
|
||||
nSteps int
|
||||
|
||||
// some functions can be overwritten for testing
|
||||
decideProposal func(height int64, round int)
|
||||
doPrevote func(height int64, round int)
|
||||
decideProposal func(height int64, round int32)
|
||||
doPrevote func(height int64, round int32)
|
||||
setProposal func(proposal *types.Proposal) error
|
||||
|
||||
// closed when we finish shutting down
|
||||
@@ -440,7 +442,7 @@ func (cs *State) SetProposal(proposal *types.Proposal, peerID p2p.ID) error {
|
||||
}
|
||||
|
||||
// AddProposalBlockPart inputs a part of the proposal block.
|
||||
func (cs *State) AddProposalBlockPart(height int64, round int, part *types.Part, peerID p2p.ID) error {
|
||||
func (cs *State) AddProposalBlockPart(height int64, round int32, part *types.Part, peerID p2p.ID) error {
|
||||
|
||||
if peerID == "" {
|
||||
cs.internalMsgQueue <- msgInfo{&BlockPartMessage{height, round, part}, ""}
|
||||
@@ -462,7 +464,7 @@ func (cs *State) SetProposalAndBlock(
|
||||
if err := cs.SetProposal(proposal, peerID); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < parts.Total(); i++ {
|
||||
for i := 0; i < int(parts.Total()); i++ {
|
||||
part := parts.GetPart(i)
|
||||
if err := cs.AddProposalBlockPart(proposal.Height, proposal.Round, part, peerID); err != nil {
|
||||
return err
|
||||
@@ -479,7 +481,7 @@ func (cs *State) updateHeight(height int64) {
|
||||
cs.Height = height
|
||||
}
|
||||
|
||||
func (cs *State) updateRoundStep(round int, step cstypes.RoundStepType) {
|
||||
func (cs *State) updateRoundStep(round int32, step cstypes.RoundStepType) {
|
||||
cs.Round = round
|
||||
cs.Step = step
|
||||
}
|
||||
@@ -492,7 +494,7 @@ func (cs *State) scheduleRound0(rs *cstypes.RoundState) {
|
||||
}
|
||||
|
||||
// Attempt to schedule a timeout (by sending timeoutInfo on the tickChan)
|
||||
func (cs *State) scheduleTimeout(duration time.Duration, height int64, round int, step cstypes.RoundStepType) {
|
||||
func (cs *State) scheduleTimeout(duration time.Duration, height int64, round int32, step cstypes.RoundStepType) {
|
||||
cs.timeoutTicker.ScheduleTimeout(timeoutInfo{duration, height, round, step})
|
||||
}
|
||||
|
||||
@@ -837,7 +839,7 @@ func (cs *State) handleTxsAvailable() {
|
||||
// Enter: +2/3 precommits for nil at (height,round-1)
|
||||
// Enter: +2/3 prevotes any or +2/3 precommits for block or any from (height, round)
|
||||
// NOTE: cs.StartTime was already set for height.
|
||||
func (cs *State) enterNewRound(height int64, round int) {
|
||||
func (cs *State) enterNewRound(height int64, round int32) {
|
||||
logger := cs.Logger.With("height", height, "round", round)
|
||||
|
||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cs.Step != cstypes.RoundStepNewHeight) {
|
||||
@@ -861,7 +863,7 @@ func (cs *State) enterNewRound(height int64, round int) {
|
||||
validators := cs.Validators
|
||||
if cs.Round < round {
|
||||
validators = validators.Copy()
|
||||
validators.IncrementProposerPriority(round - cs.Round)
|
||||
validators.IncrementProposerPriority(tmmath.SafeSubInt32(round, cs.Round))
|
||||
}
|
||||
|
||||
// Setup new round
|
||||
@@ -879,7 +881,7 @@ func (cs *State) enterNewRound(height int64, round int) {
|
||||
cs.ProposalBlock = nil
|
||||
cs.ProposalBlockParts = nil
|
||||
}
|
||||
cs.Votes.SetRound(round + 1) // also track next round (round+1) to allow round-skipping
|
||||
cs.Votes.SetRound(tmmath.SafeAddInt32(round, 1)) // also track next round (round+1) to allow round-skipping
|
||||
cs.TriggeredTimeoutPrecommit = false
|
||||
|
||||
cs.eventBus.PublishEventNewRound(cs.NewRoundEvent())
|
||||
@@ -917,7 +919,7 @@ func (cs *State) needProofBlock(height int64) bool {
|
||||
// Enter (CreateEmptyBlocks, CreateEmptyBlocksInterval > 0 ):
|
||||
// after enterNewRound(height,round), after timeout of CreateEmptyBlocksInterval
|
||||
// Enter (!CreateEmptyBlocks) : after enterNewRound(height,round), once txs are in the mempool
|
||||
func (cs *State) enterPropose(height int64, round int) {
|
||||
func (cs *State) enterPropose(height int64, round int32) {
|
||||
logger := cs.Logger.With("height", height, "round", round)
|
||||
|
||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPropose <= cs.Step) {
|
||||
@@ -990,7 +992,7 @@ func (cs *State) isProposer(address []byte) bool {
|
||||
return bytes.Equal(cs.Validators.GetProposer().Address, address)
|
||||
}
|
||||
|
||||
func (cs *State) defaultDecideProposal(height int64, round int) {
|
||||
func (cs *State) defaultDecideProposal(height int64, round int32) {
|
||||
var block *types.Block
|
||||
var blockParts *types.PartSet
|
||||
|
||||
@@ -1017,7 +1019,7 @@ func (cs *State) defaultDecideProposal(height int64, round int) {
|
||||
|
||||
// send proposal and block parts on internal msg queue
|
||||
cs.sendInternalMessage(msgInfo{&ProposalMessage{proposal}, ""})
|
||||
for i := 0; i < blockParts.Total(); i++ {
|
||||
for i := 0; i < int(blockParts.Total()); i++ {
|
||||
part := blockParts.GetPart(i)
|
||||
cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""})
|
||||
}
|
||||
@@ -1085,7 +1087,7 @@ func (cs *State) createProposalBlock() (block *types.Block, blockParts *types.Pa
|
||||
// Enter: proposal block and POL is ready.
|
||||
// Prevote for LockedBlock if we're locked, or ProposalBlock if valid.
|
||||
// Otherwise vote nil.
|
||||
func (cs *State) enterPrevote(height int64, round int) {
|
||||
func (cs *State) enterPrevote(height int64, round int32) {
|
||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrevote <= cs.Step) {
|
||||
cs.Logger.Debug(fmt.Sprintf(
|
||||
"enterPrevote(%v/%v): Invalid args. Current step: %v/%v/%v",
|
||||
@@ -1112,20 +1114,20 @@ func (cs *State) enterPrevote(height int64, round int) {
|
||||
// (so we have more time to try and collect +2/3 prevotes for a single block)
|
||||
}
|
||||
|
||||
func (cs *State) defaultDoPrevote(height int64, round int) {
|
||||
func (cs *State) defaultDoPrevote(height int64, round int32) {
|
||||
logger := cs.Logger.With("height", height, "round", round)
|
||||
|
||||
// If a block is locked, prevote that.
|
||||
if cs.LockedBlock != nil {
|
||||
logger.Info("enterPrevote: Already locked on a block, prevoting locked block")
|
||||
cs.signAddVote(types.PrevoteType, cs.LockedBlock.Hash(), cs.LockedBlockParts.Header())
|
||||
cs.signAddVote(tmproto.PrevoteType, cs.LockedBlock.Hash(), cs.LockedBlockParts.Header())
|
||||
return
|
||||
}
|
||||
|
||||
// If ProposalBlock is nil, prevote nil.
|
||||
if cs.ProposalBlock == nil {
|
||||
logger.Info("enterPrevote: ProposalBlock is nil")
|
||||
cs.signAddVote(types.PrevoteType, nil, types.PartSetHeader{})
|
||||
cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1134,7 +1136,7 @@ func (cs *State) defaultDoPrevote(height int64, round int) {
|
||||
if err != nil {
|
||||
// ProposalBlock is invalid, prevote nil.
|
||||
logger.Error("enterPrevote: ProposalBlock is invalid", "err", err)
|
||||
cs.signAddVote(types.PrevoteType, nil, types.PartSetHeader{})
|
||||
cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1142,11 +1144,11 @@ func (cs *State) defaultDoPrevote(height int64, round int) {
|
||||
// NOTE: the proposal signature is validated when it is received,
|
||||
// and the proposal block parts are validated as they are received (against the merkle hash in the proposal)
|
||||
logger.Info("enterPrevote: ProposalBlock is valid")
|
||||
cs.signAddVote(types.PrevoteType, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header())
|
||||
cs.signAddVote(tmproto.PrevoteType, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header())
|
||||
}
|
||||
|
||||
// Enter: any +2/3 prevotes at next round.
|
||||
func (cs *State) enterPrevoteWait(height int64, round int) {
|
||||
func (cs *State) enterPrevoteWait(height int64, round int32) {
|
||||
logger := cs.Logger.With("height", height, "round", round)
|
||||
|
||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrevoteWait <= cs.Step) {
|
||||
@@ -1180,7 +1182,7 @@ func (cs *State) enterPrevoteWait(height int64, round int) {
|
||||
// Lock & precommit the ProposalBlock if we have enough prevotes for it (a POL in this round)
|
||||
// else, unlock an existing lock and precommit nil if +2/3 of prevotes were nil,
|
||||
// else, precommit nil otherwise.
|
||||
func (cs *State) enterPrecommit(height int64, round int) {
|
||||
func (cs *State) enterPrecommit(height int64, round int32) {
|
||||
logger := cs.Logger.With("height", height, "round", round)
|
||||
|
||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrecommit <= cs.Step) {
|
||||
@@ -1212,7 +1214,7 @@ func (cs *State) enterPrecommit(height int64, round int) {
|
||||
} else {
|
||||
logger.Info("enterPrecommit: No +2/3 prevotes during enterPrecommit. Precommitting nil.")
|
||||
}
|
||||
cs.signAddVote(types.PrecommitType, nil, types.PartSetHeader{})
|
||||
cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1236,7 +1238,7 @@ func (cs *State) enterPrecommit(height int64, round int) {
|
||||
cs.LockedBlockParts = nil
|
||||
cs.eventBus.PublishEventUnlock(cs.RoundStateEvent())
|
||||
}
|
||||
cs.signAddVote(types.PrecommitType, nil, types.PartSetHeader{})
|
||||
cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1247,7 +1249,7 @@ func (cs *State) enterPrecommit(height int64, round int) {
|
||||
logger.Info("enterPrecommit: +2/3 prevoted locked block. Relocking")
|
||||
cs.LockedRound = round
|
||||
cs.eventBus.PublishEventRelock(cs.RoundStateEvent())
|
||||
cs.signAddVote(types.PrecommitType, blockID.Hash, blockID.PartsHeader)
|
||||
cs.signAddVote(tmproto.PrecommitType, blockID.Hash, blockID.PartsHeader)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1262,7 +1264,7 @@ func (cs *State) enterPrecommit(height int64, round int) {
|
||||
cs.LockedBlock = cs.ProposalBlock
|
||||
cs.LockedBlockParts = cs.ProposalBlockParts
|
||||
cs.eventBus.PublishEventLock(cs.RoundStateEvent())
|
||||
cs.signAddVote(types.PrecommitType, blockID.Hash, blockID.PartsHeader)
|
||||
cs.signAddVote(tmproto.PrecommitType, blockID.Hash, blockID.PartsHeader)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1278,10 +1280,10 @@ func (cs *State) enterPrecommit(height int64, round int) {
|
||||
cs.ProposalBlockParts = types.NewPartSetFromHeader(blockID.PartsHeader)
|
||||
}
|
||||
cs.eventBus.PublishEventUnlock(cs.RoundStateEvent())
|
||||
cs.signAddVote(types.PrecommitType, nil, types.PartSetHeader{})
|
||||
cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{})
|
||||
}
|
||||
|
||||
func (cs *State) savePOLC(round int, blockID types.BlockID) {
|
||||
func (cs *State) savePOLC(round int32, blockID types.BlockID) {
|
||||
// polc must be for rounds greater than 0
|
||||
if round == 0 {
|
||||
return
|
||||
@@ -1305,7 +1307,7 @@ func (cs *State) savePOLC(round int, blockID types.BlockID) {
|
||||
}
|
||||
|
||||
// Enter: any +2/3 precommits for next round.
|
||||
func (cs *State) enterPrecommitWait(height int64, round int) {
|
||||
func (cs *State) enterPrecommitWait(height int64, round int32) {
|
||||
logger := cs.Logger.With("height", height, "round", round)
|
||||
|
||||
if cs.Height != height || round < cs.Round || (cs.Round == round && cs.TriggeredTimeoutPrecommit) {
|
||||
@@ -1332,7 +1334,7 @@ func (cs *State) enterPrecommitWait(height int64, round int) {
|
||||
}
|
||||
|
||||
// Enter: +2/3 precommits for block
|
||||
func (cs *State) enterCommit(height int64, commitRound int) {
|
||||
func (cs *State) enterCommit(height int64, commitRound int32) {
|
||||
logger := cs.Logger.With("height", height, "commitRound", commitRound)
|
||||
|
||||
if cs.Height != height || cstypes.RoundStepCommit <= cs.Step {
|
||||
@@ -1816,7 +1818,7 @@ func (cs *State) addVote(
|
||||
// A precommit for the previous height?
|
||||
// These come in while we wait timeoutCommit
|
||||
if vote.Height+1 == cs.Height {
|
||||
if !(cs.Step == cstypes.RoundStepNewHeight && vote.Type == types.PrecommitType) {
|
||||
if !(cs.Step == cstypes.RoundStepNewHeight && vote.Type == tmproto.PrecommitType) {
|
||||
// TODO: give the reason ..
|
||||
// fmt.Errorf("tryAddVote: Wrong height, not a LastCommit straggler commit.")
|
||||
return added, ErrVoteHeightMismatch
|
||||
@@ -1859,7 +1861,7 @@ func (cs *State) addVote(
|
||||
cs.evsw.FireEvent(types.EventVote, vote)
|
||||
|
||||
switch vote.Type {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
prevotes := cs.Votes.Prevotes(vote.Round)
|
||||
cs.Logger.Info("Added to prevote", "vote", vote, "prevotes", prevotes.StringShort())
|
||||
|
||||
@@ -1931,7 +1933,7 @@ func (cs *State) addVote(
|
||||
}
|
||||
}
|
||||
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
precommits := cs.Votes.Precommits(vote.Round)
|
||||
cs.Logger.Info("Added to precommit", "vote", vote, "precommits", precommits.StringShort())
|
||||
|
||||
@@ -1962,7 +1964,7 @@ func (cs *State) addVote(
|
||||
|
||||
// CONTRACT: cs.privValidator is not nil.
|
||||
func (cs *State) signVote(
|
||||
msgType types.SignedMsgType,
|
||||
msgType tmproto.SignedMsgType,
|
||||
hash []byte,
|
||||
header types.PartSetHeader,
|
||||
) (*types.Vote, error) {
|
||||
@@ -2011,7 +2013,7 @@ func (cs *State) voteTime() time.Time {
|
||||
}
|
||||
|
||||
// sign the vote and publish on internalMsgQueue
|
||||
func (cs *State) signAddVote(msgType types.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote {
|
||||
func (cs *State) signAddVote(msgType tmproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote {
|
||||
if cs.privValidator == nil { // the node does not have a key
|
||||
return nil
|
||||
}
|
||||
@@ -2043,7 +2045,7 @@ func (cs *State) signAddVote(msgType types.SignedMsgType, hash []byte, header ty
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
func CompareHRS(h1 int64, r1 int, s1 cstypes.RoundStepType, h2 int64, r2 int, s2 cstypes.RoundStepType) int {
|
||||
func CompareHRS(h1 int64, r1 int32, s1 cstypes.RoundStepType, h2 int64, r2 int32, s2 cstypes.RoundStepType) int {
|
||||
if h1 < h2 {
|
||||
return -1
|
||||
} else if h1 > h2 {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
p2pmock "github.com/tendermint/tendermint/p2p/mock"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -77,7 +78,7 @@ func TestStateProposerSelection0(t *testing.T) {
|
||||
ensureNewProposal(proposalCh, height, round)
|
||||
|
||||
rs := cs1.GetRoundState()
|
||||
signAddVotes(cs1, types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:]...)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:]...)
|
||||
|
||||
// Wait for new round so next validator is set.
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
@@ -101,27 +102,27 @@ func TestStateProposerSelection2(t *testing.T) {
|
||||
incrementRound(vss[1:]...)
|
||||
incrementRound(vss[1:]...)
|
||||
|
||||
round := 2
|
||||
var round int32 = 2
|
||||
startTestRound(cs1, height, round)
|
||||
|
||||
ensureNewRound(newRoundCh, height, round) // wait for the new round
|
||||
|
||||
// everyone just votes nil. we get a new proposer each round
|
||||
for i := 0; i < len(vss); i++ {
|
||||
for i := int32(0); int(i) < len(vss); i++ {
|
||||
prop := cs1.GetRoundState().Validators.GetProposer()
|
||||
pvk, err := vss[(i+round)%len(vss)].GetPubKey()
|
||||
pvk, err := vss[int(i+round)%len(vss)].GetPubKey()
|
||||
require.NoError(t, err)
|
||||
addr := pvk.Address()
|
||||
correctProposer := addr
|
||||
if !bytes.Equal(prop.Address, correctProposer) {
|
||||
panic(fmt.Sprintf(
|
||||
"expected RoundState.Validators.GetProposer() to be validator %d. Got %X",
|
||||
(i+2)%len(vss),
|
||||
int(i+2)%len(vss),
|
||||
prop.Address))
|
||||
}
|
||||
|
||||
rs := cs1.GetRoundState()
|
||||
signAddVotes(cs1, types.PrecommitType, nil, rs.ProposalBlockParts.Header(), vss[1:]...)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, rs.ProposalBlockParts.Header(), vss[1:]...)
|
||||
ensureNewRound(newRoundCh, height, i+round+1) // wait for the new round event each round
|
||||
incrementRound(vss[1:]...)
|
||||
}
|
||||
@@ -224,13 +225,13 @@ func TestStateBadProposal(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], nil)
|
||||
|
||||
// add bad prevote from vs2 and wait for it
|
||||
signAddVotes(cs1, types.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
|
||||
ensurePrevote(voteCh, height, round)
|
||||
|
||||
// wait for precommit
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
|
||||
signAddVotes(cs1, types.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -309,7 +310,7 @@ func TestStateFullRound2(t *testing.T) {
|
||||
propBlockHash, propPartsHeader := rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header()
|
||||
|
||||
// prevote arrives from vs2:
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash, propPartsHeader, vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propPartsHeader, vs2)
|
||||
ensurePrevote(voteCh, height, round) // prevote
|
||||
|
||||
ensurePrecommit(voteCh, height, round) //precommit
|
||||
@@ -319,7 +320,7 @@ func TestStateFullRound2(t *testing.T) {
|
||||
// we should be stuck in limbo waiting for more precommits
|
||||
|
||||
// precommit arrives from vs2:
|
||||
signAddVotes(cs1, types.PrecommitType, propBlockHash, propPartsHeader, vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propPartsHeader, vs2)
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
|
||||
// wait to finish commit, propose in next height
|
||||
@@ -363,7 +364,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
|
||||
// we should now be stuck in limbo forever, waiting for more prevotes
|
||||
// prevote arrives from vs2:
|
||||
signAddVotes(cs1, types.PrevoteType, theBlockHash, thePartSetHeader, vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, thePartSetHeader, vs2)
|
||||
ensurePrevote(voteCh, height, round) // prevote
|
||||
|
||||
ensurePrecommit(voteCh, height, round) // precommit
|
||||
@@ -375,7 +376,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
hash := make([]byte, len(theBlockHash))
|
||||
copy(hash, theBlockHash)
|
||||
hash[0] = (hash[0] + 1) % 255
|
||||
signAddVotes(cs1, types.PrecommitType, hash, thePartSetHeader, vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, hash, thePartSetHeader, vs2)
|
||||
ensurePrecommit(voteCh, height, round) // precommit
|
||||
|
||||
// (note we're entering precommit for a second time this round)
|
||||
@@ -408,7 +409,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
|
||||
|
||||
// add a conflicting prevote from the other validator
|
||||
signAddVotes(cs1, types.PrevoteType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
|
||||
ensurePrevote(voteCh, height, round)
|
||||
|
||||
// now we're going to enter prevote again, but with invalid args
|
||||
@@ -421,7 +422,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
validatePrecommit(t, cs1, round, 0, vss[0], nil, theBlockHash)
|
||||
|
||||
// add conflicting precommit from vs2
|
||||
signAddVotes(cs1, types.PrecommitType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
|
||||
// (note we're entering precommit for a second time this round, but with invalid args
|
||||
@@ -451,7 +452,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round) // prevote
|
||||
validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
|
||||
ensurePrevote(voteCh, height, round)
|
||||
|
||||
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds())
|
||||
@@ -461,7 +462,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
|
||||
signAddVotes(
|
||||
cs1,
|
||||
types.PrecommitType,
|
||||
tmproto.PrecommitType,
|
||||
hash,
|
||||
rs.ProposalBlock.MakePartSet(partSize).Header(),
|
||||
vs2) // NOTE: conflicting precommits at same height
|
||||
@@ -497,7 +498,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
validatePrevote(t, cs1, 3, vss[0], cs1.LockedBlock.Hash())
|
||||
|
||||
// prevote for proposed block
|
||||
signAddVotes(cs1, types.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
|
||||
ensurePrevote(voteCh, height, round)
|
||||
|
||||
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds())
|
||||
@@ -506,7 +507,7 @@ func TestStateLockNoPOL(t *testing.T) {
|
||||
|
||||
signAddVotes(
|
||||
cs1,
|
||||
types.PrecommitType,
|
||||
tmproto.PrecommitType,
|
||||
propBlock.Hash(),
|
||||
propBlock.MakePartSet(partSize).Header(),
|
||||
vs2) // NOTE: conflicting precommits at same height
|
||||
@@ -552,14 +553,14 @@ func TestStateLockPOLRelockThenChangeLock(t *testing.T) {
|
||||
|
||||
ensurePrevote(voteCh, height, round) // prevote
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round) // our precommit
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
// before we timeout to the new round set the new proposal
|
||||
cs2 := newState(cs1.state, vs2, counter.NewApplication(true))
|
||||
@@ -600,14 +601,14 @@ func TestStateLockPOLRelockThenChangeLock(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], theBlockHash)
|
||||
|
||||
// now lets add prevotes from everyone else for the new block
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// we should have unlocked and locked on the new block, sending a precommit for this new block
|
||||
validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
|
||||
|
||||
// more prevote creating a majority on the new block and this is then committed
|
||||
signAddVotes(cs1, types.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3)
|
||||
ensureNewBlockHeader(newBlockCh, height, propBlockHash)
|
||||
|
||||
ensureNewRound(newRoundCh, height+1, 0)
|
||||
@@ -650,15 +651,15 @@ func TestStateLockPOLUnlock(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
validatePrevote(t, cs1, round, vss[0], theBlockHash)
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4)
|
||||
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs3)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3)
|
||||
|
||||
// before we time out into new round, set next proposal block
|
||||
prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
|
||||
@@ -690,7 +691,7 @@ func TestStateLockPOLUnlock(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
validatePrevote(t, cs1, round, vss[0], lockedBlockHash)
|
||||
// now lets add prevotes from everyone else for nil (a polka!)
|
||||
signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
// the polka makes us unlock and precommit nil
|
||||
ensureNewUnlock(unlockCh, height, round)
|
||||
@@ -700,7 +701,7 @@ func TestStateLockPOLUnlock(t *testing.T) {
|
||||
// NOTE: since we don't relock on nil, the lock round is -1
|
||||
validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
|
||||
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3)
|
||||
ensureNewRound(newRoundCh, height, round+1)
|
||||
}
|
||||
|
||||
@@ -739,14 +740,14 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
|
||||
|
||||
ensurePrevote(voteCh, height, round) // prevote
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, firstBlockHash, firstBlockParts, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, firstBlockHash, firstBlockParts, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round) // our precommit
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(t, cs1, round, round, vss[0], firstBlockHash, firstBlockHash)
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
// before we timeout to the new round set the new proposal
|
||||
cs2 := newState(cs1.state, vs2, counter.NewApplication(true))
|
||||
@@ -779,7 +780,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], firstBlockHash)
|
||||
|
||||
// now lets add prevotes from everyone else for the new block
|
||||
signAddVotes(cs1, types.PrevoteType, secondBlockHash, secondBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, secondBlockHash, secondBlockParts.Header(), vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// we should have unlocked and locked on the new block, sending a precommit for this new block
|
||||
@@ -790,7 +791,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
// more prevote creating a majority on the new block and this is then committed
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
// before we timeout to the new round set the new proposal
|
||||
cs3 := newState(cs1.state, vs3, counter.NewApplication(true))
|
||||
@@ -823,7 +824,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) {
|
||||
// we are no longer locked to the first block so we should be able to prevote
|
||||
validatePrevote(t, cs1, round, vss[0], thirdPropBlockHash)
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, thirdPropBlockHash, thirdPropBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, thirdPropBlockHash, thirdPropBlockParts.Header(), vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// we have a majority, now vs1 can change lock to the third block
|
||||
@@ -862,12 +863,12 @@ func TestStateLockPOLSafety1(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], propBlock.Hash())
|
||||
|
||||
// the others sign a polka but we don't see it
|
||||
prevotes := signVotes(types.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
|
||||
prevotes := signVotes(tmproto.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
|
||||
|
||||
t.Logf("old prop hash %v", fmt.Sprintf("%X", propBlock.Hash()))
|
||||
|
||||
// we do see them precommit nil
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
// cs1 precommit nil
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
@@ -907,13 +908,13 @@ func TestStateLockPOLSafety1(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], propBlockHash)
|
||||
|
||||
// now we see the others prevote for it, so we should lock on it
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// we should have precommitted
|
||||
validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
|
||||
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds())
|
||||
|
||||
@@ -977,7 +978,7 @@ func TestStateLockPOLSafety2(t *testing.T) {
|
||||
propBlockID0 := types.BlockID{Hash: propBlockHash0, PartsHeader: propBlockParts0.Header()}
|
||||
|
||||
// the others sign a polka but we don't see it
|
||||
prevotes := signVotes(types.PrevoteType, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4)
|
||||
prevotes := signVotes(tmproto.PrevoteType, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4)
|
||||
|
||||
// the block for round 1
|
||||
prop1, propBlock1 := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
|
||||
@@ -1000,15 +1001,15 @@ func TestStateLockPOLSafety2(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
validatePrevote(t, cs1, round, vss[0], propBlockHash1)
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(t, cs1, round, round, vss[0], propBlockHash1, propBlockHash1)
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4)
|
||||
signAddVotes(cs1, types.PrecommitType, propBlockHash1, propBlockParts1.Header(), vs3)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, propBlockHash1, propBlockParts1.Header(), vs3)
|
||||
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
@@ -1076,13 +1077,13 @@ func TestProposeValidBlock(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], propBlockHash)
|
||||
|
||||
// the others sign a polka
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// we should have precommitted
|
||||
validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
|
||||
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds())
|
||||
|
||||
@@ -1099,7 +1100,7 @@ func TestProposeValidBlock(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
validatePrevote(t, cs1, round, vss[0], propBlockHash)
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewUnlock(unlockCh, height, round)
|
||||
|
||||
@@ -1110,7 +1111,7 @@ func TestProposeValidBlock(t *testing.T) {
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
round += 2 // moving to the next round
|
||||
|
||||
@@ -1166,10 +1167,10 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
|
||||
validatePrevote(t, cs1, round, vss[0], propBlockHash)
|
||||
|
||||
// vs2 send prevote for propBlock
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2)
|
||||
|
||||
// vs3 send prevote nil
|
||||
signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs3)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs3)
|
||||
|
||||
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds())
|
||||
|
||||
@@ -1184,7 +1185,7 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
|
||||
assert.True(t, rs.ValidRound == -1)
|
||||
|
||||
// vs2 send (delayed) prevote for propBlock
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs4)
|
||||
|
||||
ensureNewValidBlock(validBlockCh, height, round)
|
||||
|
||||
@@ -1231,7 +1232,7 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) {
|
||||
propBlockParts := propBlock.MakePartSet(partSize)
|
||||
|
||||
// vs2, vs3 and vs4 send prevote for propBlock
|
||||
signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
ensureNewValidBlock(validBlockCh, height, round)
|
||||
|
||||
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds())
|
||||
@@ -1266,7 +1267,7 @@ func TestWaitingTimeoutOnNilPolka(t *testing.T) {
|
||||
startTestRound(cs1, height, round)
|
||||
ensureNewRound(newRoundCh, height, round)
|
||||
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds())
|
||||
ensureNewRound(newRoundCh, height, round+1)
|
||||
@@ -1294,7 +1295,7 @@ func TestWaitingTimeoutProposeOnNewRound(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
|
||||
incrementRound(vss[1:]...)
|
||||
signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
round++ // moving to the next round
|
||||
ensureNewRound(newRoundCh, height, round)
|
||||
@@ -1330,7 +1331,7 @@ func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
|
||||
incrementRound(vss[1:]...)
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
round++ // moving to the next round
|
||||
ensureNewRound(newRoundCh, height, round)
|
||||
@@ -1350,7 +1351,7 @@ func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) {
|
||||
func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
|
||||
cs1, vss := randState(4)
|
||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||
height, round := cs1.Height, 1
|
||||
height, round := cs1.Height, int32(1)
|
||||
|
||||
timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
|
||||
newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
|
||||
@@ -1364,7 +1365,7 @@ func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
|
||||
ensureNewRound(newRoundCh, height, round)
|
||||
|
||||
incrementRound(vss[1:]...)
|
||||
signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
|
||||
|
||||
ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds())
|
||||
|
||||
@@ -1377,7 +1378,7 @@ func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
|
||||
func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) {
|
||||
cs1, vss := randState(4)
|
||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||
height, round := cs1.Height, 1
|
||||
height, round := cs1.Height, int32(1)
|
||||
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
@@ -1395,7 +1396,7 @@ func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) {
|
||||
ensureNewRound(newRoundCh, height, round)
|
||||
|
||||
// vs2, vs3 and vs4 send precommit for propBlock
|
||||
signAddVotes(cs1, types.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
ensureNewValidBlock(validBlockCh, height, round)
|
||||
|
||||
rs := cs1.GetRoundState()
|
||||
@@ -1411,7 +1412,7 @@ func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) {
|
||||
func TestCommitFromPreviousRound(t *testing.T) {
|
||||
cs1, vss := randState(4)
|
||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||
height, round := cs1.Height, 1
|
||||
height, round := cs1.Height, int32(1)
|
||||
|
||||
partSize := types.BlockPartSizeBytes
|
||||
|
||||
@@ -1428,7 +1429,7 @@ func TestCommitFromPreviousRound(t *testing.T) {
|
||||
ensureNewRound(newRoundCh, height, round)
|
||||
|
||||
// vs2, vs3 and vs4 send precommit for propBlock for the previous round
|
||||
signAddVotes(cs1, types.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
|
||||
|
||||
ensureNewValidBlock(validBlockCh, height, round)
|
||||
|
||||
@@ -1492,15 +1493,15 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
validatePrevote(t, cs1, round, vss[0], theBlockHash)
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
|
||||
|
||||
// add precommits
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2)
|
||||
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs3)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3)
|
||||
|
||||
// wait till timeout occurs
|
||||
ensurePrecommitTimeout(precommitTimeoutCh)
|
||||
@@ -1508,7 +1509,7 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) {
|
||||
ensureNewRound(newRoundCh, height, round+1)
|
||||
|
||||
// majority is now reached
|
||||
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4)
|
||||
|
||||
ensureNewBlockHeader(newBlockHeader, height, theBlockHash)
|
||||
|
||||
@@ -1552,15 +1553,15 @@ func TestResetTimeoutPrecommitUponNewHeight(t *testing.T) {
|
||||
ensurePrevote(voteCh, height, round)
|
||||
validatePrevote(t, cs1, round, vss[0], theBlockHash)
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
|
||||
|
||||
// add precommits
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2)
|
||||
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs3)
|
||||
signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs4)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4)
|
||||
|
||||
ensureNewBlockHeader(newBlockHeader, height, theBlockHash)
|
||||
|
||||
@@ -1606,7 +1607,7 @@ func TestStateSlashingPrevotes(t *testing.T) {
|
||||
// add one for a different block should cause us to go into prevote wait
|
||||
hash := rs.ProposalBlock.Hash()
|
||||
hash[0] = byte(hash[0]+1) % 255
|
||||
signAddVotes(cs1, types.PrevoteType, hash, rs.ProposalBlockParts.Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, hash, rs.ProposalBlockParts.Header(), vs2)
|
||||
|
||||
<-timeoutWaitCh
|
||||
|
||||
@@ -1614,7 +1615,7 @@ func TestStateSlashingPrevotes(t *testing.T) {
|
||||
// away and ignore more prevotes (and thus fail to slash!)
|
||||
|
||||
// add the conflicting vote
|
||||
signAddVotes(cs1, types.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
|
||||
|
||||
// XXX: Check for existence of Dupeout info
|
||||
}
|
||||
@@ -1636,7 +1637,7 @@ func TestStateSlashingPrecommits(t *testing.T) {
|
||||
<-voteCh // prevote
|
||||
|
||||
// add prevote from vs2
|
||||
signAddVotes(cs1, types.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
|
||||
|
||||
<-voteCh // precommit
|
||||
|
||||
@@ -1644,13 +1645,13 @@ func TestStateSlashingPrecommits(t *testing.T) {
|
||||
// add one for a different block should cause us to go into prevote wait
|
||||
hash := rs.ProposalBlock.Hash()
|
||||
hash[0] = byte(hash[0]+1) % 255
|
||||
signAddVotes(cs1, types.PrecommitType, hash, rs.ProposalBlockParts.Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, hash, rs.ProposalBlockParts.Header(), vs2)
|
||||
|
||||
// NOTE: we have to send the vote for different block first so we don't just go into precommit round right
|
||||
// away and ignore more prevotes (and thus fail to slash!)
|
||||
|
||||
// add precommit from vs2
|
||||
signAddVotes(cs1, types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
|
||||
|
||||
// XXX: Check for existence of Dupeout info
|
||||
}
|
||||
@@ -1690,17 +1691,17 @@ func TestStateHalt1(t *testing.T) {
|
||||
|
||||
ensurePrevote(voteCh, height, round)
|
||||
|
||||
signAddVotes(cs1, types.PrevoteType, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4)
|
||||
signAddVotes(cs1, tmproto.PrevoteType, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4)
|
||||
|
||||
ensurePrecommit(voteCh, height, round)
|
||||
// the proposed block should now be locked and our precommit added
|
||||
validatePrecommit(t, cs1, round, round, vss[0], propBlock.Hash(), propBlock.Hash())
|
||||
|
||||
// add precommits from the rest
|
||||
signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2) // didnt receive proposal
|
||||
signAddVotes(cs1, types.PrecommitType, propBlock.Hash(), propBlockParts.Header(), vs3)
|
||||
signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2) // didnt receive proposal
|
||||
signAddVotes(cs1, tmproto.PrecommitType, propBlock.Hash(), propBlockParts.Header(), vs3)
|
||||
// we receive this later, but vs3 might receive it earlier and with ours will go to commit!
|
||||
precommit4 := signVote(vs4, types.PrecommitType, propBlock.Hash(), propBlockParts.Header())
|
||||
precommit4 := signVote(vs4, tmproto.PrecommitType, propBlock.Hash(), propBlockParts.Header())
|
||||
|
||||
incrementRound(vs2, vs3, vs4)
|
||||
|
||||
@@ -1779,7 +1780,7 @@ func TestStateOutputVoteStats(t *testing.T) {
|
||||
// create dummy peer
|
||||
peer := p2pmock.NewPeer(nil)
|
||||
|
||||
vote := signVote(vss[1], types.PrecommitType, []byte("test"), types.PartSetHeader{})
|
||||
vote := signVote(vss[1], tmproto.PrecommitType, []byte("test"), types.PartSetHeader{})
|
||||
|
||||
voteMessage := &VoteMessage{vote}
|
||||
cs.handleMsg(msgInfo{voteMessage, peer.ID()})
|
||||
@@ -1793,7 +1794,7 @@ func TestStateOutputVoteStats(t *testing.T) {
|
||||
|
||||
// sending the vote for the bigger height
|
||||
incrementHeight(vss[1])
|
||||
vote = signVote(vss[1], types.PrecommitType, []byte("test"), types.PartSetHeader{})
|
||||
vote = signVote(vss[1], tmproto.PrecommitType, []byte("test"), types.PartSetHeader{})
|
||||
|
||||
cs.handleMsg(msgInfo{&VoteMessage{vote}, peer.ID()})
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -41,9 +43,9 @@ type HeightVoteSet struct {
|
||||
valSet *types.ValidatorSet
|
||||
|
||||
mtx sync.Mutex
|
||||
round int // max tracked round
|
||||
roundVoteSets map[int]RoundVoteSet // keys: [0...round]
|
||||
peerCatchupRounds map[p2p.ID][]int // keys: peer.ID; values: at most 2 rounds
|
||||
round int32 // max tracked round
|
||||
roundVoteSets map[int32]RoundVoteSet // keys: [0...round]
|
||||
peerCatchupRounds map[p2p.ID][]int32 // keys: peer.ID; values: at most 2 rounds
|
||||
}
|
||||
|
||||
func NewHeightVoteSet(chainID string, height int64, valSet *types.ValidatorSet) *HeightVoteSet {
|
||||
@@ -60,8 +62,8 @@ func (hvs *HeightVoteSet) Reset(height int64, valSet *types.ValidatorSet) {
|
||||
|
||||
hvs.height = height
|
||||
hvs.valSet = valSet
|
||||
hvs.roundVoteSets = make(map[int]RoundVoteSet)
|
||||
hvs.peerCatchupRounds = make(map[p2p.ID][]int)
|
||||
hvs.roundVoteSets = make(map[int32]RoundVoteSet)
|
||||
hvs.peerCatchupRounds = make(map[p2p.ID][]int32)
|
||||
|
||||
hvs.addRound(0)
|
||||
hvs.round = 0
|
||||
@@ -73,20 +75,21 @@ func (hvs *HeightVoteSet) Height() int64 {
|
||||
return hvs.height
|
||||
}
|
||||
|
||||
func (hvs *HeightVoteSet) Round() int {
|
||||
func (hvs *HeightVoteSet) Round() int32 {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
return hvs.round
|
||||
}
|
||||
|
||||
// Create more RoundVoteSets up to round.
|
||||
func (hvs *HeightVoteSet) SetRound(round int) {
|
||||
func (hvs *HeightVoteSet) SetRound(round int32) {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
if hvs.round != 0 && (round < hvs.round+1) {
|
||||
newRound := tmmath.SafeSubInt32(hvs.round, 1)
|
||||
if hvs.round != 0 && (round < newRound) {
|
||||
panic("SetRound() must increment hvs.round")
|
||||
}
|
||||
for r := hvs.round + 1; r <= round; r++ {
|
||||
for r := newRound; r <= round; r++ {
|
||||
if _, ok := hvs.roundVoteSets[r]; ok {
|
||||
continue // Already exists because peerCatchupRounds.
|
||||
}
|
||||
@@ -95,13 +98,13 @@ func (hvs *HeightVoteSet) SetRound(round int) {
|
||||
hvs.round = round
|
||||
}
|
||||
|
||||
func (hvs *HeightVoteSet) addRound(round int) {
|
||||
func (hvs *HeightVoteSet) addRound(round int32) {
|
||||
if _, ok := hvs.roundVoteSets[round]; ok {
|
||||
panic("addRound() for an existing round")
|
||||
}
|
||||
// log.Debug("addRound(round)", "round", round)
|
||||
prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, types.PrevoteType, hvs.valSet)
|
||||
precommits := types.NewVoteSet(hvs.chainID, hvs.height, round, types.PrecommitType, hvs.valSet)
|
||||
prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrevoteType, hvs.valSet)
|
||||
precommits := types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrecommitType, hvs.valSet)
|
||||
hvs.roundVoteSets[round] = RoundVoteSet{
|
||||
Prevotes: prevotes,
|
||||
Precommits: precommits,
|
||||
@@ -132,25 +135,25 @@ func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerID p2p.ID) (added bool,
|
||||
return
|
||||
}
|
||||
|
||||
func (hvs *HeightVoteSet) Prevotes(round int) *types.VoteSet {
|
||||
func (hvs *HeightVoteSet) Prevotes(round int32) *types.VoteSet {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
return hvs.getVoteSet(round, types.PrevoteType)
|
||||
return hvs.getVoteSet(round, tmproto.PrevoteType)
|
||||
}
|
||||
|
||||
func (hvs *HeightVoteSet) Precommits(round int) *types.VoteSet {
|
||||
func (hvs *HeightVoteSet) Precommits(round int32) *types.VoteSet {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
return hvs.getVoteSet(round, types.PrecommitType)
|
||||
return hvs.getVoteSet(round, tmproto.PrecommitType)
|
||||
}
|
||||
|
||||
// Last round and blockID that has +2/3 prevotes for a particular block or nil.
|
||||
// Returns -1 if no such round exists.
|
||||
func (hvs *HeightVoteSet) POLInfo() (polRound int, polBlockID types.BlockID) {
|
||||
func (hvs *HeightVoteSet) POLInfo() (polRound int32, polBlockID types.BlockID) {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
for r := hvs.round; r >= 0; r-- {
|
||||
rvs := hvs.getVoteSet(r, types.PrevoteType)
|
||||
rvs := hvs.getVoteSet(r, tmproto.PrevoteType)
|
||||
polBlockID, ok := rvs.TwoThirdsMajority()
|
||||
if ok {
|
||||
return r, polBlockID
|
||||
@@ -159,15 +162,15 @@ func (hvs *HeightVoteSet) POLInfo() (polRound int, polBlockID types.BlockID) {
|
||||
return -1, types.BlockID{}
|
||||
}
|
||||
|
||||
func (hvs *HeightVoteSet) getVoteSet(round int, voteType types.SignedMsgType) *types.VoteSet {
|
||||
func (hvs *HeightVoteSet) getVoteSet(round int32, voteType tmproto.SignedMsgType) *types.VoteSet {
|
||||
rvs, ok := hvs.roundVoteSets[round]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
switch voteType {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
return rvs.Prevotes
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
return rvs.Precommits
|
||||
default:
|
||||
panic(fmt.Sprintf("Unexpected vote type %X", voteType))
|
||||
@@ -179,8 +182,8 @@ func (hvs *HeightVoteSet) getVoteSet(round int, voteType types.SignedMsgType) *t
|
||||
// this can cause memory issues.
|
||||
// TODO: implement ability to remove peers too
|
||||
func (hvs *HeightVoteSet) SetPeerMaj23(
|
||||
round int,
|
||||
voteType types.SignedMsgType,
|
||||
round int32,
|
||||
voteType tmproto.SignedMsgType,
|
||||
peerID p2p.ID,
|
||||
blockID types.BlockID) error {
|
||||
hvs.mtx.Lock()
|
||||
@@ -207,7 +210,7 @@ func (hvs *HeightVoteSet) StringIndented(indent string) string {
|
||||
defer hvs.mtx.Unlock()
|
||||
vsStrings := make([]string, 0, (len(hvs.roundVoteSets)+1)*2)
|
||||
// rounds 0 ~ hvs.round inclusive
|
||||
for round := 0; round <= hvs.round; round++ {
|
||||
for round := int32(0); round <= hvs.round; round++ {
|
||||
voteSetString := hvs.roundVoteSets[round].Prevotes.StringShort()
|
||||
vsStrings = append(vsStrings, voteSetString)
|
||||
voteSetString = hvs.roundVoteSets[round].Precommits.StringShort()
|
||||
@@ -243,7 +246,7 @@ func (hvs *HeightVoteSet) toAllRoundVotes() []roundVotes {
|
||||
totalRounds := hvs.round + 1
|
||||
allVotes := make([]roundVotes, totalRounds)
|
||||
// rounds 0 ~ hvs.round inclusive
|
||||
for round := 0; round < totalRounds; round++ {
|
||||
for round := int32(0); round < totalRounds; round++ {
|
||||
allVotes[round] = roundVotes{
|
||||
Round: round,
|
||||
Prevotes: hvs.roundVoteSets[round].Prevotes.VoteStrings(),
|
||||
@@ -257,7 +260,7 @@ func (hvs *HeightVoteSet) toAllRoundVotes() []roundVotes {
|
||||
}
|
||||
|
||||
type roundVotes struct {
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
Prevotes []string `json:"prevotes"`
|
||||
PrevotesBitArray string `json:"prevotes_bit_array"`
|
||||
Precommits []string `json:"precommits"`
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
@@ -24,19 +25,19 @@ func TestPeerCatchupRounds(t *testing.T) {
|
||||
|
||||
hvs := NewHeightVoteSet(config.ChainID(), 1, valSet)
|
||||
|
||||
vote999_0 := makeVoteHR(t, 1, 999, privVals, 0)
|
||||
vote999_0 := makeVoteHR(t, 1, 0, 999, privVals)
|
||||
added, err := hvs.AddVote(vote999_0, "peer1")
|
||||
if !added || err != nil {
|
||||
t.Error("Expected to successfully add vote from peer", added, err)
|
||||
}
|
||||
|
||||
vote1000_0 := makeVoteHR(t, 1, 1000, privVals, 0)
|
||||
vote1000_0 := makeVoteHR(t, 1, 0, 1000, privVals)
|
||||
added, err = hvs.AddVote(vote1000_0, "peer1")
|
||||
if !added || err != nil {
|
||||
t.Error("Expected to successfully add vote from peer", added, err)
|
||||
}
|
||||
|
||||
vote1001_0 := makeVoteHR(t, 1, 1001, privVals, 0)
|
||||
vote1001_0 := makeVoteHR(t, 1, 0, 1001, privVals)
|
||||
added, err = hvs.AddVote(vote1001_0, "peer1")
|
||||
if err != ErrGotVoteFromUnwantedRound {
|
||||
t.Errorf("expected GotVoteFromUnwantedRoundError, but got %v", err)
|
||||
@@ -52,7 +53,7 @@ func TestPeerCatchupRounds(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func makeVoteHR(t *testing.T, height int64, round int, privVals []types.PrivValidator, valIndex int) *types.Vote {
|
||||
func makeVoteHR(t *testing.T, height int64, valIndex, round int32, privVals []types.PrivValidator) *types.Vote {
|
||||
privVal := privVals[valIndex]
|
||||
pubKey, err := privVal.GetPubKey()
|
||||
if err != nil {
|
||||
@@ -65,7 +66,7 @@ func makeVoteHR(t *testing.T, height int64, round int, privVals []types.PrivVali
|
||||
Height: height,
|
||||
Round: round,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: types.PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: types.BlockID{Hash: []byte("fakehash"), PartsHeader: types.PartSetHeader{}},
|
||||
}
|
||||
chainID := config.ChainID()
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// NOTE: Read-only when returned by PeerState.GetRoundState().
|
||||
type PeerRoundState struct {
|
||||
Height int64 `json:"height"` // Height peer is at
|
||||
Round int `json:"round"` // Round peer is at, -1 if unknown.
|
||||
Round int32 `json:"round"` // Round peer is at, -1 if unknown.
|
||||
Step RoundStepType `json:"step"` // Step peer is at
|
||||
|
||||
// Estimated start of round 0 at this height
|
||||
@@ -24,17 +24,17 @@ type PeerRoundState struct {
|
||||
Proposal bool `json:"proposal"`
|
||||
ProposalBlockPartsHeader types.PartSetHeader `json:"proposal_block_parts_header"` //
|
||||
ProposalBlockParts *bits.BitArray `json:"proposal_block_parts"` //
|
||||
ProposalPOLRound int `json:"proposal_pol_round"` // Proposal's POL round. -1 if none.
|
||||
ProposalPOLRound int32 `json:"proposal_pol_round"` // Proposal's POL round. -1 if none.
|
||||
|
||||
// nil until ProposalPOLMessage received.
|
||||
ProposalPOL *bits.BitArray `json:"proposal_pol"`
|
||||
Prevotes *bits.BitArray `json:"prevotes"` // All votes peer has for this round
|
||||
Precommits *bits.BitArray `json:"precommits"` // All precommits peer has for this round
|
||||
LastCommitRound int `json:"last_commit_round"` // Round of commit for last height. -1 if none.
|
||||
LastCommitRound int32 `json:"last_commit_round"` // Round of commit for last height. -1 if none.
|
||||
LastCommit *bits.BitArray `json:"last_commit"` // All commit precommits of commit for last height.
|
||||
|
||||
// Round that we have commit for. Not necessarily unique. -1 if none.
|
||||
CatchupCommitRound int `json:"catchup_commit_round"`
|
||||
CatchupCommitRound int32 `json:"catchup_commit_round"`
|
||||
|
||||
// All commit precommits peer has for this height & CatchupCommitRound
|
||||
CatchupCommit *bits.BitArray `json:"catchup_commit"`
|
||||
|
||||
@@ -66,7 +66,7 @@ func (rs RoundStepType) String() string {
|
||||
// of the cs.receiveRoutine
|
||||
type RoundState struct {
|
||||
Height int64 `json:"height"` // Height we are working on
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
Step RoundStepType `json:"step"`
|
||||
StartTime time.Time `json:"start_time"`
|
||||
|
||||
@@ -76,18 +76,18 @@ type RoundState struct {
|
||||
Proposal *types.Proposal `json:"proposal"`
|
||||
ProposalBlock *types.Block `json:"proposal_block"`
|
||||
ProposalBlockParts *types.PartSet `json:"proposal_block_parts"`
|
||||
LockedRound int `json:"locked_round"`
|
||||
LockedRound int32 `json:"locked_round"`
|
||||
LockedBlock *types.Block `json:"locked_block"`
|
||||
LockedBlockParts *types.PartSet `json:"locked_block_parts"`
|
||||
|
||||
// Last known round with POL for non-nil valid block.
|
||||
ValidRound int `json:"valid_round"`
|
||||
ValidRound int32 `json:"valid_round"`
|
||||
ValidBlock *types.Block `json:"valid_block"` // Last known block of POL mentioned above.
|
||||
|
||||
// Last known block parts of POL metnioned above.
|
||||
ValidBlockParts *types.PartSet `json:"valid_block_parts"`
|
||||
Votes *HeightVoteSet `json:"votes"`
|
||||
CommitRound int `json:"commit_round"` //
|
||||
CommitRound int32 `json:"commit_round"` //
|
||||
LastCommit *types.VoteSet `json:"last_commit"` // Last precommits at Height-1
|
||||
LastValidators *types.ValidatorSet `json:"last_validators"`
|
||||
TriggeredTimeoutPrecommit bool `json:"triggered_timeout_precommit"`
|
||||
|
||||
@@ -276,7 +276,7 @@ func (evpool *Pool) IsPending(evidence types.Evidence) bool {
|
||||
}
|
||||
|
||||
// RetrievePOLC attempts to find a polc at the given height and round, if not there it returns an error
|
||||
func (evpool *Pool) RetrievePOLC(height int64, round int) (types.ProofOfLockChange, error) {
|
||||
func (evpool *Pool) RetrievePOLC(height int64, round int32) (types.ProofOfLockChange, error) {
|
||||
var polc types.ProofOfLockChange
|
||||
key := keyPOLCFromHeightAndRound(height, round)
|
||||
polcBytes, err := evpool.evidenceStore.Get(key)
|
||||
@@ -545,7 +545,7 @@ func keyPOLC(polc types.ProofOfLockChange) []byte {
|
||||
return keyPOLCFromHeightAndRound(polc.Height(), polc.Round())
|
||||
}
|
||||
|
||||
func keyPOLCFromHeightAndRound(height int64, round int) []byte {
|
||||
func keyPOLCFromHeightAndRound(height int64, round int32) []byte {
|
||||
return append([]byte{baseKeyPOLC}, []byte(fmt.Sprintf("%s/%s", bE(height), bE(int64(round))))...)
|
||||
}
|
||||
|
||||
|
||||
41
libs/math/safemath.go
Normal file
41
libs/math/safemath.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package math
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
)
|
||||
|
||||
var ErrOverflowInt32 = errors.New("int32 overflow")
|
||||
|
||||
// SafeAddInt32 adds two int32 integers
|
||||
// If there is an overflow this will panic
|
||||
func SafeAddInt32(a, b int32) int32 {
|
||||
if b > 0 && (a > math.MaxInt32-b) {
|
||||
panic(ErrOverflowInt32)
|
||||
} else if b < 0 && (a < math.MinInt32-b) {
|
||||
panic(ErrOverflowInt32)
|
||||
}
|
||||
return a + b
|
||||
}
|
||||
|
||||
// SafeSubInt32 subtracts two int32 integers
|
||||
// If there is an overflow this will panic
|
||||
func SafeSubInt32(a, b int32) int32 {
|
||||
if b > 0 && (a < math.MinInt32+b) {
|
||||
panic(ErrOverflowInt32)
|
||||
} else if b < 0 && (a > math.MaxInt32+b) {
|
||||
panic(ErrOverflowInt32)
|
||||
}
|
||||
return a - b
|
||||
}
|
||||
|
||||
// SafeConvertInt32 takes a int and checks if it overflows
|
||||
// If there is an overflow this will panic
|
||||
func SafeConvertInt32(a int64) int32 {
|
||||
if a > math.MaxInt32 {
|
||||
panic(ErrOverflowInt32)
|
||||
} else if a < math.MinInt32 {
|
||||
panic(ErrOverflowInt32)
|
||||
}
|
||||
return int32(a)
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
@@ -105,7 +105,7 @@ func makeVote(header *types.Header, valset *types.ValidatorSet,
|
||||
Height: header.Height,
|
||||
Round: 1,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: types.PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: blockID,
|
||||
}
|
||||
// Sign it
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
"github.com/tendermint/tendermint/libs/tempfile"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
@@ -27,9 +28,9 @@ const (
|
||||
// A vote is either stepPrevote or stepPrecommit.
|
||||
func voteToStep(vote *types.Vote) int8 {
|
||||
switch vote.Type {
|
||||
case types.PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
return stepPrevote
|
||||
case types.PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
return stepPrecommit
|
||||
default:
|
||||
panic(fmt.Sprintf("Unknown vote type: %v", vote.Type))
|
||||
@@ -70,7 +71,7 @@ func (pvKey FilePVKey) Save() {
|
||||
// FilePVLastSignState stores the mutable part of PrivValidator.
|
||||
type FilePVLastSignState struct {
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
Step int8 `json:"step"`
|
||||
Signature []byte `json:"signature,omitempty"`
|
||||
SignBytes tmbytes.HexBytes `json:"signbytes,omitempty"`
|
||||
@@ -85,7 +86,7 @@ type FilePVLastSignState struct {
|
||||
// it returns true if the HRS matches the arguments and the SignBytes are not empty (indicating
|
||||
// we have already signed for this HRS, and can reuse the existing signature).
|
||||
// It panics if the HRS matches the arguments, there's a SignBytes, but no Signature.
|
||||
func (lss *FilePVLastSignState) CheckHRS(height int64, round int, step int8) (bool, error) {
|
||||
func (lss *FilePVLastSignState) CheckHRS(height int64, round int32, step int8) (bool, error) {
|
||||
|
||||
if lss.Height > height {
|
||||
return false, fmt.Errorf("height regression. Got %v, last height %v", height, lss.Height)
|
||||
@@ -375,7 +376,7 @@ func (pv *FilePV) signProposal(chainID string, proposal *types.Proposal) error {
|
||||
}
|
||||
|
||||
// Persist height/round/step and signature
|
||||
func (pv *FilePV) saveSigned(height int64, round int, step int8,
|
||||
func (pv *FilePV) saveSigned(height int64, round int32, step int8,
|
||||
signBytes []byte, sig []byte) {
|
||||
|
||||
pv.LastSignState.Height = height
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
@@ -49,8 +50,8 @@ func TestResetValidator(t *testing.T) {
|
||||
assert.Equal(t, privVal.LastSignState, emptyState)
|
||||
|
||||
// test vote
|
||||
height, round := int64(10), 1
|
||||
voteType := byte(types.PrevoteType)
|
||||
height, round := int64(10), int32(1)
|
||||
voteType := byte(tmproto.PrevoteType)
|
||||
blockID := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{}}
|
||||
vote := newVote(privVal.Key.Address, 0, height, round, voteType, blockID)
|
||||
err = privVal.SignVote("mychainid", vote)
|
||||
@@ -93,7 +94,7 @@ func TestUnmarshalValidatorState(t *testing.T) {
|
||||
// create some fixed values
|
||||
serialized := `{
|
||||
"height": "1",
|
||||
"round": "1",
|
||||
"round": 1,
|
||||
"step": 1
|
||||
}`
|
||||
|
||||
@@ -164,8 +165,8 @@ func TestSignVote(t *testing.T) {
|
||||
block1 := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{}}
|
||||
block2 := types.BlockID{Hash: []byte{3, 2, 1}, PartsHeader: types.PartSetHeader{}}
|
||||
|
||||
height, round := int64(10), 1
|
||||
voteType := byte(types.PrevoteType)
|
||||
height, round := int64(10), int32(1)
|
||||
voteType := byte(tmproto.PrevoteType)
|
||||
|
||||
// sign a vote for first time
|
||||
vote := newVote(privVal.Key.Address, 0, height, round, voteType, block1)
|
||||
@@ -209,7 +210,7 @@ func TestSignProposal(t *testing.T) {
|
||||
|
||||
block1 := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{Total: 5, Hash: []byte{1, 2, 3}}}
|
||||
block2 := types.BlockID{Hash: []byte{3, 2, 1}, PartsHeader: types.PartSetHeader{Total: 10, Hash: []byte{3, 2, 1}}}
|
||||
height, round := int64(10), 1
|
||||
height, round := int64(10), int32(1)
|
||||
|
||||
// sign a proposal for first time
|
||||
proposal := newProposal(height, round, block1)
|
||||
@@ -250,7 +251,7 @@ func TestDifferByTimestamp(t *testing.T) {
|
||||
privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
|
||||
|
||||
block1 := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{Total: 5, Hash: []byte{1, 2, 3}}}
|
||||
height, round := int64(10), 1
|
||||
height, round := int64(10), int32(1)
|
||||
chainID := "mychainid"
|
||||
|
||||
// test proposal
|
||||
@@ -276,7 +277,7 @@ func TestDifferByTimestamp(t *testing.T) {
|
||||
|
||||
// test vote
|
||||
{
|
||||
voteType := byte(types.PrevoteType)
|
||||
voteType := byte(tmproto.PrevoteType)
|
||||
blockID := types.BlockID{Hash: []byte{1, 2, 3}, PartsHeader: types.PartSetHeader{}}
|
||||
vote := newVote(privVal.Key.Address, 0, height, round, voteType, blockID)
|
||||
err := privVal.SignVote("mychainid", vote)
|
||||
@@ -299,19 +300,19 @@ func TestDifferByTimestamp(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newVote(addr types.Address, idx int, height int64, round int, typ byte, blockID types.BlockID) *types.Vote {
|
||||
func newVote(addr types.Address, idx int32, height int64, round int32, typ byte, blockID types.BlockID) *types.Vote {
|
||||
return &types.Vote{
|
||||
ValidatorAddress: addr,
|
||||
ValidatorIndex: idx,
|
||||
Height: height,
|
||||
Round: round,
|
||||
Type: types.SignedMsgType(typ),
|
||||
Type: tmproto.SignedMsgType(typ),
|
||||
Timestamp: tmtime.Now(),
|
||||
BlockID: blockID,
|
||||
}
|
||||
}
|
||||
|
||||
func newProposal(height int64, round int, blockID types.BlockID) *types.Proposal {
|
||||
func newProposal(height int64, round int32, blockID types.BlockID) *types.Proposal {
|
||||
return &types.Proposal{
|
||||
Height: height,
|
||||
Round: round,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -110,8 +111,8 @@ func TestSignerProposal(t *testing.T) {
|
||||
func TestSignerVote(t *testing.T) {
|
||||
for _, tc := range getSignerTestCases(t) {
|
||||
ts := time.Now()
|
||||
want := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
have := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
want := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
have := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
|
||||
defer tc.signerServer.Stop()
|
||||
defer tc.signerClient.Close()
|
||||
@@ -126,8 +127,8 @@ func TestSignerVote(t *testing.T) {
|
||||
func TestSignerVoteResetDeadline(t *testing.T) {
|
||||
for _, tc := range getSignerTestCases(t) {
|
||||
ts := time.Now()
|
||||
want := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
have := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
want := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
have := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
|
||||
defer tc.signerServer.Stop()
|
||||
defer tc.signerClient.Close()
|
||||
@@ -152,8 +153,8 @@ func TestSignerVoteResetDeadline(t *testing.T) {
|
||||
func TestSignerVoteKeepAlive(t *testing.T) {
|
||||
for _, tc := range getSignerTestCases(t) {
|
||||
ts := time.Now()
|
||||
want := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
have := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
want := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
have := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
|
||||
defer tc.signerServer.Stop()
|
||||
defer tc.signerClient.Close()
|
||||
@@ -199,7 +200,7 @@ func TestSignerSignProposalErrors(t *testing.T) {
|
||||
func TestSignerSignVoteErrors(t *testing.T) {
|
||||
for _, tc := range getSignerTestCases(t) {
|
||||
ts := time.Now()
|
||||
vote := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
vote := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
|
||||
// Replace signer service privval with one that always fails
|
||||
tc.signerServer.privVal = types.NewErroringMockPV()
|
||||
@@ -254,7 +255,7 @@ func TestSignerUnexpectedResponse(t *testing.T) {
|
||||
defer tc.signerClient.Close()
|
||||
|
||||
ts := time.Now()
|
||||
want := &types.Vote{Timestamp: ts, Type: types.PrecommitType}
|
||||
want := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType}
|
||||
|
||||
e := tc.signerClient.SignVote(tc.chainID, want)
|
||||
assert.EqualError(t, e, "received unexpected response")
|
||||
|
||||
@@ -85,7 +85,7 @@ func (SignedMsgType) EnumDescriptor() ([]byte, []int) {
|
||||
|
||||
// PartsetHeader
|
||||
type PartSetHeader struct {
|
||||
Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"`
|
||||
Total uint32 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"`
|
||||
Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
@@ -116,7 +116,7 @@ func (m *PartSetHeader) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_PartSetHeader proto.InternalMessageInfo
|
||||
|
||||
func (m *PartSetHeader) GetTotal() int64 {
|
||||
func (m *PartSetHeader) GetTotal() uint32 {
|
||||
if m != nil {
|
||||
return m.Total
|
||||
}
|
||||
@@ -435,11 +435,11 @@ func (m *Data) GetHash() []byte {
|
||||
type Vote struct {
|
||||
Type SignedMsgType `protobuf:"varint,1,opt,name=type,proto3,enum=tendermint.proto.types.SignedMsgType" json:"type,omitempty"`
|
||||
Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"`
|
||||
Round int64 `protobuf:"varint,3,opt,name=round,proto3" json:"round,omitempty"`
|
||||
Round int32 `protobuf:"varint,3,opt,name=round,proto3" json:"round,omitempty"`
|
||||
BlockID BlockID `protobuf:"bytes,4,opt,name=block_id,json=blockId,proto3" json:"block_id"`
|
||||
Timestamp time.Time `protobuf:"bytes,5,opt,name=timestamp,proto3,stdtime" json:"timestamp"`
|
||||
ValidatorAddress []byte `protobuf:"bytes,6,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"`
|
||||
ValidatorIndex int64 `protobuf:"varint,7,opt,name=validator_index,json=validatorIndex,proto3" json:"validator_index,omitempty"`
|
||||
ValidatorIndex int32 `protobuf:"varint,7,opt,name=validator_index,json=validatorIndex,proto3" json:"validator_index,omitempty"`
|
||||
Signature []byte `protobuf:"bytes,8,opt,name=signature,proto3" json:"signature,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
@@ -484,7 +484,7 @@ func (m *Vote) GetHeight() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Vote) GetRound() int64 {
|
||||
func (m *Vote) GetRound() int32 {
|
||||
if m != nil {
|
||||
return m.Round
|
||||
}
|
||||
@@ -512,7 +512,7 @@ func (m *Vote) GetValidatorAddress() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Vote) GetValidatorIndex() int64 {
|
||||
func (m *Vote) GetValidatorIndex() int32 {
|
||||
if m != nil {
|
||||
return m.ValidatorIndex
|
||||
}
|
||||
@@ -881,85 +881,85 @@ func init() {
|
||||
func init() { proto.RegisterFile("proto/types/types.proto", fileDescriptor_ff06f8095857fb18) }
|
||||
|
||||
var fileDescriptor_ff06f8095857fb18 = []byte{
|
||||
// 1274 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xcd, 0x6e, 0xdb, 0xc6,
|
||||
// 1270 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x57, 0xcd, 0x6e, 0xdb, 0xc6,
|
||||
0x13, 0x37, 0x25, 0xca, 0x92, 0x86, 0x92, 0x2d, 0xf3, 0xef, 0x7f, 0xa2, 0xca, 0xad, 0xa5, 0xc8,
|
||||
0x4d, 0xea, 0x7c, 0x80, 0x2a, 0x5c, 0xa0, 0x68, 0x80, 0x5e, 0x24, 0xdb, 0x71, 0x84, 0xd8, 0xb2,
|
||||
0x40, 0xa9, 0xe9, 0xc7, 0x85, 0x58, 0x89, 0x1b, 0x8a, 0x08, 0x45, 0x12, 0xdc, 0x95, 0x61, 0xa7,
|
||||
0x40, 0x81, 0xde, 0x0a, 0x9f, 0xfa, 0x02, 0x3e, 0xa5, 0x05, 0xfa, 0x16, 0xed, 0xb1, 0xa7, 0x3e,
|
||||
0x42, 0x0a, 0xa4, 0xaf, 0xd0, 0x07, 0x28, 0xf6, 0x83, 0x94, 0x14, 0xd9, 0x6d, 0xd0, 0xa4, 0x17,
|
||||
0x9b, 0x3b, 0xf3, 0x9b, 0xd9, 0x9d, 0xdf, 0xfc, 0x66, 0xd7, 0x86, 0xeb, 0x61, 0x14, 0xd0, 0xa0,
|
||||
0x41, 0xcf, 0x42, 0x4c, 0xc4, 0x4f, 0x83, 0x5b, 0xf4, 0x6b, 0x14, 0xfb, 0x36, 0x8e, 0xc6, 0xae,
|
||||
0x4f, 0x85, 0xc5, 0xe0, 0xde, 0xca, 0x2d, 0x3a, 0x72, 0x23, 0xdb, 0x0a, 0x51, 0x44, 0xcf, 0x1a,
|
||||
0x22, 0xd8, 0x09, 0x9c, 0x60, 0xfa, 0x25, 0xd0, 0x95, 0xaa, 0x13, 0x04, 0x8e, 0x87, 0x05, 0x64,
|
||||
0x30, 0x79, 0xd2, 0xa0, 0xee, 0x18, 0x13, 0x8a, 0xc6, 0xa1, 0x04, 0x6c, 0x88, 0x10, 0xcf, 0x1d,
|
||||
0x90, 0xc6, 0xc0, 0xa5, 0x73, 0xbb, 0x57, 0xaa, 0xc2, 0x39, 0x8c, 0xce, 0x42, 0x1a, 0x34, 0xc6,
|
||||
0x38, 0x7a, 0xea, 0xe1, 0x39, 0x80, 0x8c, 0x3e, 0xc1, 0x11, 0x71, 0x03, 0x3f, 0xfe, 0x2d, 0x9c,
|
||||
0xf5, 0xfb, 0x50, 0xec, 0xa2, 0x88, 0xf6, 0x30, 0x7d, 0x88, 0x91, 0x8d, 0x23, 0x7d, 0x1d, 0x32,
|
||||
0x34, 0xa0, 0xc8, 0x2b, 0x2b, 0x35, 0x65, 0x3b, 0x6d, 0x8a, 0x85, 0xae, 0x83, 0x3a, 0x42, 0x64,
|
||||
0x54, 0x4e, 0xd5, 0x94, 0xed, 0x82, 0xc9, 0xbf, 0xeb, 0x5f, 0x83, 0xca, 0x42, 0x59, 0x84, 0xeb,
|
||||
0xdb, 0xf8, 0x94, 0x47, 0x14, 0x4d, 0xb1, 0x60, 0xd6, 0xc1, 0x19, 0xc5, 0x44, 0x86, 0x88, 0x85,
|
||||
0x7e, 0x00, 0x99, 0x30, 0x0a, 0x82, 0x27, 0xe5, 0x74, 0x4d, 0xd9, 0xd6, 0x76, 0xee, 0x1a, 0x0b,
|
||||
0xd4, 0x89, 0x3a, 0x0c, 0x51, 0x87, 0xd1, 0x73, 0xc7, 0xa1, 0x87, 0xbb, 0x2c, 0xa4, 0xa5, 0xfe,
|
||||
0xfa, 0xa2, 0xba, 0x64, 0x8a, 0xf8, 0xfa, 0x18, 0xb2, 0x2d, 0x2f, 0x18, 0x3e, 0x6d, 0xef, 0x25,
|
||||
0x67, 0x53, 0xa6, 0x67, 0xd3, 0x3b, 0x50, 0x60, 0xb4, 0x13, 0x6b, 0xc4, 0xab, 0xe2, 0x87, 0xd0,
|
||||
0x76, 0x6e, 0x1a, 0x97, 0x77, 0xca, 0x98, 0xa3, 0x40, 0x6e, 0xa4, 0xf1, 0x04, 0xc2, 0x54, 0xff,
|
||||
0x36, 0x03, 0xcb, 0x92, 0xa0, 0x5d, 0xc8, 0x4a, 0x0a, 0xf9, 0x8e, 0xda, 0xce, 0xd6, 0x62, 0xd6,
|
||||
0x98, 0xe3, 0xdd, 0xc0, 0x27, 0xd8, 0x27, 0x13, 0x22, 0x73, 0xc6, 0x91, 0xfa, 0x2d, 0xc8, 0x0d,
|
||||
0x47, 0xc8, 0xf5, 0x2d, 0xd7, 0xe6, 0x67, 0xcb, 0xb7, 0xb4, 0x97, 0x2f, 0xaa, 0xd9, 0x5d, 0x66,
|
||||
0x6b, 0xef, 0x99, 0x59, 0xee, 0x6c, 0xdb, 0xfa, 0x35, 0x58, 0x1e, 0x61, 0xd7, 0x19, 0x51, 0x4e,
|
||||
0x58, 0xda, 0x94, 0x2b, 0xfd, 0x13, 0x50, 0x99, 0x48, 0xca, 0x2a, 0x3f, 0x41, 0xc5, 0x10, 0x0a,
|
||||
0x32, 0x62, 0x05, 0x19, 0xfd, 0x58, 0x41, 0xad, 0x1c, 0xdb, 0xf8, 0xfb, 0xdf, 0xab, 0x8a, 0xc9,
|
||||
0x23, 0xf4, 0x2f, 0xa0, 0xe8, 0x21, 0x42, 0xad, 0x01, 0x63, 0x8f, 0x6d, 0x9f, 0xe1, 0x29, 0xaa,
|
||||
0x57, 0x51, 0x23, 0x59, 0x6e, 0xfd, 0x8f, 0xe5, 0x79, 0xf9, 0xa2, 0xaa, 0x1d, 0x22, 0x42, 0xa5,
|
||||
0xd1, 0xd4, 0xbc, 0x64, 0x61, 0xeb, 0xdb, 0x50, 0xe2, 0x99, 0x87, 0xc1, 0x78, 0xec, 0x52, 0x8b,
|
||||
0xf7, 0x64, 0x99, 0xf7, 0x64, 0x85, 0xd9, 0x77, 0xb9, 0xf9, 0x21, 0xeb, 0xce, 0x06, 0xe4, 0x6d,
|
||||
0x44, 0x91, 0x80, 0x64, 0x39, 0x24, 0xc7, 0x0c, 0xdc, 0xf9, 0x01, 0xac, 0x9e, 0x20, 0xcf, 0xb5,
|
||||
0x11, 0x0d, 0x22, 0x22, 0x20, 0x39, 0x91, 0x65, 0x6a, 0xe6, 0xc0, 0x0f, 0x61, 0xdd, 0xc7, 0xa7,
|
||||
0xd4, 0x7a, 0x15, 0x9d, 0xe7, 0x68, 0x9d, 0xf9, 0x1e, 0xcf, 0x47, 0xdc, 0x84, 0x95, 0x61, 0xdc,
|
||||
0x11, 0x81, 0x05, 0x8e, 0x2d, 0x26, 0x56, 0x0e, 0x7b, 0x07, 0x72, 0x28, 0x0c, 0x05, 0x40, 0xe3,
|
||||
0x80, 0x2c, 0x0a, 0x43, 0xee, 0xba, 0x03, 0x6b, 0xbc, 0xc6, 0x08, 0x93, 0x89, 0x47, 0x65, 0x92,
|
||||
0x02, 0xc7, 0xac, 0x32, 0x87, 0x29, 0xec, 0x1c, 0xbb, 0x05, 0x45, 0x7c, 0xe2, 0xda, 0xd8, 0x1f,
|
||||
0x62, 0x81, 0x2b, 0x72, 0x5c, 0x21, 0x36, 0x72, 0xd0, 0x6d, 0x28, 0x85, 0x51, 0x10, 0x06, 0x04,
|
||||
0x47, 0x16, 0xb2, 0xed, 0x08, 0x13, 0x52, 0x5e, 0x11, 0xf9, 0x62, 0x7b, 0x53, 0x98, 0xeb, 0xf7,
|
||||
0x40, 0xdd, 0x43, 0x14, 0xe9, 0x25, 0x48, 0xd3, 0x53, 0x52, 0x56, 0x6a, 0xe9, 0xed, 0x82, 0xc9,
|
||||
0x3e, 0x2f, 0x9d, 0xce, 0x3f, 0x53, 0xa0, 0x3e, 0x0e, 0x28, 0xd6, 0xef, 0x83, 0xca, 0x3a, 0xc9,
|
||||
0xc5, 0xba, 0x72, 0xf5, 0x08, 0xf4, 0x5c, 0xc7, 0xc7, 0xf6, 0x11, 0x71, 0xfa, 0x67, 0x21, 0x36,
|
||||
0x79, 0xc8, 0x8c, 0xfa, 0x52, 0x73, 0xea, 0x5b, 0x87, 0x4c, 0x14, 0x4c, 0x7c, 0x5b, 0x8a, 0x52,
|
||||
0x2c, 0xf4, 0x47, 0x90, 0x4b, 0x44, 0xa5, 0xbe, 0x9e, 0xa8, 0x56, 0xa5, 0xa8, 0xe2, 0x59, 0x36,
|
||||
0xb3, 0x03, 0x29, 0xa6, 0x16, 0xe4, 0x93, 0x5b, 0x50, 0x4a, 0xf4, 0xf5, 0x54, 0x3e, 0x0d, 0xd3,
|
||||
0xef, 0xc2, 0x5a, 0xa2, 0x8d, 0x84, 0x5c, 0xa1, 0xc8, 0x52, 0xe2, 0x90, 0xec, 0xce, 0xc9, 0xce,
|
||||
0x12, 0xf7, 0x59, 0x96, 0x57, 0x37, 0x95, 0x5d, 0x9b, 0x5f, 0x6c, 0xef, 0x42, 0x9e, 0xb8, 0x8e,
|
||||
0x8f, 0xe8, 0x24, 0xc2, 0x52, 0x99, 0x53, 0x43, 0xfd, 0x79, 0x0a, 0x96, 0x85, 0xd2, 0x67, 0xd8,
|
||||
0x53, 0x2e, 0x67, 0x8f, 0x91, 0x9a, 0xb9, 0x8c, 0xbd, 0xf4, 0x9b, 0xb2, 0x77, 0x00, 0x90, 0x1c,
|
||||
0x89, 0x94, 0xd5, 0x5a, 0x7a, 0x5b, 0xdb, 0xb9, 0x71, 0x55, 0x3a, 0x71, 0xdc, 0x9e, 0xeb, 0xc8,
|
||||
0x4b, 0x6a, 0x26, 0x34, 0x51, 0x56, 0x66, 0xe6, 0x6e, 0x6d, 0x42, 0x7e, 0xe0, 0x52, 0x0b, 0x45,
|
||||
0x11, 0x3a, 0xe3, 0x74, 0x6a, 0x3b, 0xef, 0x2f, 0xe6, 0x66, 0x8f, 0x95, 0xc1, 0x1e, 0x2b, 0xa3,
|
||||
0xe5, 0xd2, 0x26, 0xc3, 0x9a, 0xb9, 0x81, 0xfc, 0xaa, 0xff, 0xa1, 0x40, 0x3e, 0xd9, 0x56, 0x3f,
|
||||
0x80, 0x62, 0x5c, 0xba, 0xf5, 0xc4, 0x43, 0x8e, 0x94, 0xea, 0xd6, 0x3f, 0xd4, 0xff, 0xc0, 0x43,
|
||||
0x8e, 0xa9, 0xc9, 0x92, 0xd9, 0xe2, 0xf2, 0x86, 0xa7, 0xae, 0x68, 0xf8, 0x9c, 0xc2, 0xd2, 0xff,
|
||||
0x4e, 0x61, 0x73, 0x5a, 0x50, 0x5f, 0xd5, 0xc2, 0xcf, 0x29, 0xc8, 0x75, 0xf9, 0x10, 0x23, 0xef,
|
||||
0x3f, 0x1f, 0xc3, 0x44, 0x48, 0x1b, 0x90, 0x0f, 0x03, 0xcf, 0x12, 0x1e, 0x95, 0x7b, 0x72, 0x61,
|
||||
0xe0, 0x99, 0x0b, 0x2a, 0xcb, 0xbc, 0xd5, 0x19, 0x5d, 0x7e, 0x0b, 0x0c, 0x66, 0x5f, 0x65, 0xf0,
|
||||
0x1b, 0x28, 0x08, 0x42, 0xe4, 0xdb, 0xfb, 0x31, 0x63, 0x82, 0x3f, 0xe8, 0xe2, 0xe9, 0xdd, 0xbc,
|
||||
0xea, 0xf0, 0x02, 0x6f, 0x4a, 0x34, 0x8b, 0x13, 0xaf, 0x92, 0xfc, 0x43, 0x60, 0xf3, 0xef, 0x67,
|
||||
0xc1, 0x94, 0xe8, 0xfa, 0x6f, 0x0a, 0xe4, 0x79, 0xd9, 0x47, 0x98, 0xa2, 0x39, 0xf2, 0x94, 0x37,
|
||||
0x25, 0xef, 0x3d, 0x00, 0x91, 0x8c, 0xb8, 0xcf, 0xb0, 0x6c, 0x6c, 0x9e, 0x5b, 0x7a, 0xee, 0x33,
|
||||
0xac, 0x7f, 0x9a, 0x54, 0x9a, 0x7e, 0x9d, 0x4a, 0xe5, 0xe8, 0xc6, 0xf5, 0x5e, 0x87, 0xac, 0x3f,
|
||||
0x19, 0x5b, 0xec, 0x99, 0x50, 0x85, 0x64, 0xfc, 0xc9, 0xb8, 0x7f, 0x4a, 0xee, 0xfc, 0xa2, 0x80,
|
||||
0x36, 0x33, 0x3e, 0x7a, 0x05, 0xae, 0xb5, 0x0e, 0x8f, 0x77, 0x1f, 0xed, 0x59, 0xed, 0x3d, 0xeb,
|
||||
0xc1, 0x61, 0xf3, 0xc0, 0xfa, 0xac, 0xf3, 0xa8, 0x73, 0xfc, 0x79, 0xa7, 0xb4, 0xa4, 0x37, 0x60,
|
||||
0x9d, 0xfb, 0x12, 0x57, 0xb3, 0xd5, 0xdb, 0xef, 0xf4, 0x4b, 0x4a, 0xe5, 0xff, 0xe7, 0x17, 0xb5,
|
||||
0xb5, 0x99, 0x34, 0xcd, 0x01, 0xc1, 0x3e, 0x5d, 0x0c, 0xd8, 0x3d, 0x3e, 0x3a, 0x6a, 0xf7, 0x4b,
|
||||
0xa9, 0x85, 0x00, 0x79, 0x43, 0xde, 0x86, 0xb5, 0xf9, 0x80, 0x4e, 0xfb, 0xb0, 0x94, 0xae, 0xe8,
|
||||
0xe7, 0x17, 0xb5, 0x95, 0x19, 0x74, 0xc7, 0xf5, 0x2a, 0xb9, 0xef, 0x9e, 0x6f, 0x2e, 0xfd, 0xf4,
|
||||
0xc3, 0xe6, 0xd2, 0x9d, 0x1f, 0x15, 0x28, 0xce, 0x4d, 0x89, 0xbe, 0x01, 0xd7, 0x7b, 0xed, 0x83,
|
||||
0xce, 0xfe, 0x9e, 0x75, 0xd4, 0x3b, 0xb0, 0xfa, 0x5f, 0x76, 0xf7, 0x67, 0xaa, 0xb8, 0x01, 0x85,
|
||||
0xae, 0xb9, 0xff, 0xf8, 0xb8, 0xbf, 0xcf, 0x3d, 0x25, 0xa5, 0xb2, 0x7a, 0x7e, 0x51, 0xd3, 0xba,
|
||||
0x11, 0x3e, 0x09, 0x28, 0xe6, 0xf1, 0x37, 0x61, 0xa5, 0x6b, 0xee, 0x8b, 0xc3, 0x0a, 0x50, 0xaa,
|
||||
0xb2, 0x76, 0x7e, 0x51, 0x2b, 0x76, 0x23, 0x2c, 0x84, 0xc0, 0x61, 0x5b, 0x50, 0xec, 0x9a, 0xc7,
|
||||
0xdd, 0xe3, 0x5e, 0xf3, 0x50, 0xa0, 0xd2, 0x95, 0xd2, 0xf9, 0x45, 0xad, 0x10, 0x8f, 0x38, 0x03,
|
||||
0x4d, 0xcf, 0xd9, 0x32, 0xbe, 0xba, 0xe7, 0xb8, 0x74, 0x34, 0x19, 0x18, 0xc3, 0x60, 0xdc, 0x98,
|
||||
0x76, 0x6f, 0xf6, 0x73, 0xe6, 0x3f, 0x8a, 0xc1, 0x32, 0x5f, 0x7c, 0xf4, 0x57, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xfb, 0xb3, 0xf9, 0x43, 0x67, 0x0c, 0x00, 0x00,
|
||||
0x42, 0x0a, 0xa4, 0xaf, 0xd0, 0x07, 0x28, 0xf6, 0x83, 0x94, 0x14, 0x5b, 0x6d, 0xd0, 0x04, 0xbd,
|
||||
0xd8, 0xdc, 0x99, 0xdf, 0xcc, 0xee, 0xfc, 0xe6, 0x37, 0xbb, 0x36, 0x5c, 0x0f, 0xa3, 0x80, 0x06,
|
||||
0x0d, 0x7a, 0x16, 0x62, 0x22, 0x7e, 0x1a, 0xdc, 0xa2, 0x5f, 0xa3, 0xd8, 0xb7, 0x71, 0x34, 0x76,
|
||||
0x7d, 0x2a, 0x2c, 0x06, 0xf7, 0x56, 0x6e, 0xd1, 0x91, 0x1b, 0xd9, 0x56, 0x88, 0x22, 0x7a, 0xd6,
|
||||
0x10, 0xc1, 0x4e, 0xe0, 0x04, 0xd3, 0x2f, 0x81, 0xae, 0x54, 0x9d, 0x20, 0x70, 0x3c, 0x2c, 0x20,
|
||||
0x83, 0xc9, 0x93, 0x06, 0x75, 0xc7, 0x98, 0x50, 0x34, 0x0e, 0x25, 0x60, 0x43, 0x84, 0x78, 0xee,
|
||||
0x80, 0x34, 0x06, 0x2e, 0x9d, 0xdb, 0xbd, 0x52, 0x15, 0xce, 0x61, 0x74, 0x16, 0xd2, 0xa0, 0x31,
|
||||
0xc6, 0xd1, 0x53, 0x0f, 0xcf, 0x01, 0x64, 0xf4, 0x09, 0x8e, 0x88, 0x1b, 0xf8, 0xf1, 0x6f, 0xe1,
|
||||
0xac, 0xdf, 0x87, 0x62, 0x17, 0x45, 0xb4, 0x87, 0xe9, 0x43, 0x8c, 0x6c, 0x1c, 0xe9, 0xeb, 0x90,
|
||||
0xa1, 0x01, 0x45, 0x5e, 0x59, 0xa9, 0x29, 0xdb, 0x45, 0x53, 0x2c, 0x74, 0x1d, 0xd4, 0x11, 0x22,
|
||||
0xa3, 0x72, 0xaa, 0xa6, 0x6c, 0x17, 0x4c, 0xfe, 0x5d, 0xff, 0x1a, 0x54, 0x16, 0xca, 0x22, 0x5c,
|
||||
0xdf, 0xc6, 0xa7, 0x71, 0x04, 0x5f, 0x30, 0xeb, 0xe0, 0x8c, 0x62, 0x22, 0x43, 0xc4, 0x42, 0x3f,
|
||||
0x80, 0x4c, 0x18, 0x05, 0xc1, 0x93, 0x72, 0xba, 0xa6, 0x6c, 0x6b, 0x3b, 0x77, 0x8d, 0x4b, 0xd4,
|
||||
0x89, 0x3a, 0x0c, 0x51, 0x87, 0xd1, 0x73, 0xc7, 0xa1, 0x87, 0xbb, 0x2c, 0xa4, 0xa5, 0xfe, 0xfa,
|
||||
0xa2, 0xba, 0x64, 0x8a, 0xf8, 0xfa, 0x18, 0xb2, 0x2d, 0x2f, 0x18, 0x3e, 0x6d, 0xef, 0x25, 0x67,
|
||||
0x53, 0xa6, 0x67, 0xd3, 0x3b, 0x50, 0x60, 0xb4, 0x13, 0x6b, 0xc4, 0xab, 0xe2, 0x87, 0xd0, 0x76,
|
||||
0x6e, 0x1a, 0x57, 0x77, 0xca, 0x98, 0xa3, 0x40, 0x6e, 0xa4, 0xf1, 0x04, 0xc2, 0x54, 0xff, 0x36,
|
||||
0x03, 0xcb, 0x92, 0xa0, 0x5d, 0xc8, 0x4a, 0x0a, 0xf9, 0x8e, 0xda, 0xce, 0xd6, 0xe5, 0xac, 0x31,
|
||||
0xc7, 0xbb, 0x81, 0x4f, 0xb0, 0x4f, 0x26, 0x44, 0xe6, 0x8c, 0x23, 0xf5, 0x5b, 0x90, 0x1b, 0x8e,
|
||||
0x90, 0xeb, 0x5b, 0xae, 0xcd, 0xcf, 0x96, 0x6f, 0x69, 0x2f, 0x5f, 0x54, 0xb3, 0xbb, 0xcc, 0xd6,
|
||||
0xde, 0x33, 0xb3, 0xdc, 0xd9, 0xb6, 0xf5, 0x6b, 0xb0, 0x3c, 0xc2, 0xae, 0x33, 0xa2, 0x9c, 0xb0,
|
||||
0xb4, 0x29, 0x57, 0xfa, 0x27, 0xa0, 0x32, 0x91, 0x94, 0x55, 0x7e, 0x82, 0x8a, 0x21, 0x14, 0x64,
|
||||
0xc4, 0x0a, 0x32, 0xfa, 0xb1, 0x82, 0x5a, 0x39, 0xb6, 0xf1, 0xf7, 0xbf, 0x57, 0x15, 0x93, 0x47,
|
||||
0xe8, 0x5f, 0x40, 0xd1, 0x43, 0x84, 0x5a, 0x03, 0xc6, 0x1e, 0xdb, 0x3e, 0xc3, 0x53, 0x54, 0x17,
|
||||
0x51, 0x23, 0x59, 0x6e, 0xfd, 0x8f, 0xe5, 0x79, 0xf9, 0xa2, 0xaa, 0x1d, 0x22, 0x42, 0xa5, 0xd1,
|
||||
0xd4, 0xbc, 0x64, 0x61, 0xeb, 0xdb, 0x50, 0xe2, 0x99, 0x87, 0xc1, 0x78, 0xec, 0x52, 0x8b, 0xf7,
|
||||
0x64, 0x99, 0xf7, 0x64, 0x85, 0xd9, 0x77, 0xb9, 0xf9, 0x21, 0xeb, 0xce, 0x06, 0xe4, 0x6d, 0x44,
|
||||
0x91, 0x80, 0x64, 0x39, 0x24, 0xc7, 0x0c, 0xdc, 0xf9, 0x01, 0xac, 0x9e, 0x20, 0xcf, 0xb5, 0x11,
|
||||
0x0d, 0x22, 0x22, 0x20, 0x39, 0x91, 0x65, 0x6a, 0xe6, 0xc0, 0x0f, 0x61, 0xdd, 0xc7, 0xa7, 0xd4,
|
||||
0x7a, 0x15, 0x9d, 0xe7, 0x68, 0x9d, 0xf9, 0x1e, 0xcf, 0x47, 0xdc, 0x84, 0x95, 0x61, 0xdc, 0x11,
|
||||
0x81, 0x05, 0x8e, 0x2d, 0x26, 0x56, 0x0e, 0x7b, 0x07, 0x72, 0x28, 0x0c, 0x05, 0x40, 0xe3, 0x80,
|
||||
0x2c, 0x0a, 0x43, 0xee, 0xba, 0x03, 0x6b, 0xbc, 0xc6, 0x08, 0x93, 0x89, 0x47, 0x65, 0x92, 0x02,
|
||||
0xc7, 0xac, 0x32, 0x87, 0x29, 0xec, 0x1c, 0xbb, 0x05, 0x45, 0x7c, 0xe2, 0xda, 0xd8, 0x1f, 0x62,
|
||||
0x81, 0x2b, 0x72, 0x5c, 0x21, 0x36, 0x72, 0xd0, 0x6d, 0x28, 0x85, 0x51, 0x10, 0x06, 0x04, 0x47,
|
||||
0x16, 0xb2, 0xed, 0x08, 0x13, 0x52, 0x5e, 0x11, 0xf9, 0x62, 0x7b, 0x53, 0x98, 0xeb, 0xf7, 0x40,
|
||||
0xdd, 0x43, 0x14, 0xe9, 0x25, 0x48, 0xd3, 0x53, 0x52, 0x56, 0x6a, 0xe9, 0xed, 0x82, 0xc9, 0x3e,
|
||||
0xaf, 0x9c, 0xce, 0x3f, 0x53, 0xa0, 0x3e, 0x0e, 0x28, 0xd6, 0xef, 0x83, 0xca, 0x3a, 0xc9, 0xc5,
|
||||
0xba, 0xb2, 0x78, 0x04, 0x7a, 0xae, 0xe3, 0x63, 0xfb, 0x88, 0x38, 0xfd, 0xb3, 0x10, 0x9b, 0x3c,
|
||||
0x64, 0x46, 0x7d, 0xa9, 0x39, 0xf5, 0xad, 0x43, 0x26, 0x0a, 0x26, 0xbe, 0xcd, 0x45, 0x99, 0x31,
|
||||
0xc5, 0x42, 0x7f, 0x04, 0xb9, 0x44, 0x54, 0xea, 0xeb, 0x89, 0x6a, 0x55, 0x8a, 0x2a, 0x9e, 0x65,
|
||||
0x33, 0x3b, 0x90, 0x62, 0x6a, 0x41, 0x3e, 0xb9, 0x05, 0xa5, 0x44, 0x5f, 0x4f, 0xe5, 0xd3, 0x30,
|
||||
0xfd, 0x2e, 0xac, 0x25, 0xda, 0x48, 0xc8, 0x15, 0x8a, 0x2c, 0x25, 0x0e, 0xc9, 0xee, 0x9c, 0xec,
|
||||
0x2c, 0x71, 0x9f, 0x65, 0x79, 0x75, 0x53, 0xd9, 0xb5, 0xf9, 0xc5, 0xf6, 0x2e, 0xe4, 0x89, 0xeb,
|
||||
0xf8, 0x88, 0x4e, 0x22, 0x2c, 0x95, 0x39, 0x35, 0xd4, 0x9f, 0xa7, 0x60, 0x59, 0x28, 0x7d, 0x86,
|
||||
0x3d, 0xe5, 0x6a, 0xf6, 0x52, 0x8b, 0xd8, 0x4b, 0xbf, 0x29, 0x7b, 0x07, 0x00, 0xc9, 0x91, 0x48,
|
||||
0x59, 0xad, 0xa5, 0xb7, 0xb5, 0x9d, 0x1b, 0x8b, 0xd2, 0x89, 0xe3, 0xf6, 0x5c, 0x47, 0x5e, 0x52,
|
||||
0x33, 0xa1, 0x89, 0xb2, 0x32, 0x33, 0x77, 0x6b, 0x13, 0xf2, 0x03, 0x97, 0x5a, 0x28, 0x8a, 0xd0,
|
||||
0x19, 0xa7, 0x53, 0xdb, 0x79, 0xff, 0x72, 0x6e, 0xf6, 0x58, 0x19, 0xec, 0xb1, 0x32, 0x5a, 0x2e,
|
||||
0x6d, 0x32, 0xac, 0x99, 0x1b, 0xc8, 0xaf, 0xfa, 0x1f, 0x0a, 0xe4, 0x93, 0x6d, 0xf5, 0x03, 0x28,
|
||||
0xc6, 0xa5, 0x5b, 0x4f, 0x3c, 0xe4, 0x48, 0xa9, 0x6e, 0xfd, 0x43, 0xfd, 0x0f, 0x3c, 0xe4, 0x98,
|
||||
0x9a, 0x2c, 0x99, 0x2d, 0xae, 0x6e, 0x78, 0x6a, 0x41, 0xc3, 0xe7, 0x14, 0x96, 0xfe, 0x77, 0x0a,
|
||||
0x9b, 0xd3, 0x82, 0xfa, 0xaa, 0x16, 0x7e, 0x4e, 0x41, 0xae, 0xcb, 0x87, 0x18, 0x79, 0xff, 0xdd,
|
||||
0x18, 0x6e, 0x40, 0x3e, 0x0c, 0x3c, 0x4b, 0x78, 0x54, 0xee, 0xc9, 0x85, 0x81, 0x67, 0x5e, 0x52,
|
||||
0x59, 0xe6, 0xad, 0xce, 0xe8, 0xf2, 0x5b, 0x60, 0x30, 0xfb, 0x2a, 0x83, 0xdf, 0x40, 0x41, 0x10,
|
||||
0x22, 0xdf, 0xde, 0x8f, 0x19, 0x13, 0xfc, 0x41, 0x17, 0x4f, 0xef, 0xe6, 0xa2, 0xc3, 0x0b, 0xbc,
|
||||
0x29, 0xd1, 0x2c, 0x4e, 0xbc, 0x4a, 0xf2, 0x0f, 0x81, 0xcd, 0xbf, 0x9f, 0x05, 0x53, 0xa2, 0xeb,
|
||||
0xbf, 0x29, 0x90, 0xe7, 0x65, 0x1f, 0x61, 0x8a, 0xe6, 0xc8, 0x53, 0xde, 0x94, 0xbc, 0xf7, 0x00,
|
||||
0x44, 0x32, 0xe2, 0x3e, 0xc3, 0xb2, 0xb1, 0x79, 0x6e, 0xe9, 0xb9, 0xcf, 0xb0, 0xfe, 0x69, 0x52,
|
||||
0x69, 0xfa, 0x75, 0x2a, 0x95, 0xa3, 0x1b, 0xd7, 0x7b, 0x1d, 0xb2, 0xfe, 0x64, 0x6c, 0xb1, 0x67,
|
||||
0x42, 0x15, 0x92, 0xf1, 0x27, 0xe3, 0xfe, 0x29, 0xb9, 0xf3, 0x8b, 0x02, 0xda, 0xcc, 0xf8, 0xe8,
|
||||
0x15, 0xb8, 0xd6, 0x3a, 0x3c, 0xde, 0x7d, 0xb4, 0x67, 0xb5, 0xf7, 0xac, 0x07, 0x87, 0xcd, 0x03,
|
||||
0xeb, 0xb3, 0xce, 0xa3, 0xce, 0xf1, 0xe7, 0x9d, 0xd2, 0x92, 0xde, 0x80, 0x75, 0xee, 0x4b, 0x5c,
|
||||
0xcd, 0x56, 0x6f, 0xbf, 0xd3, 0x2f, 0x29, 0x95, 0xff, 0x9f, 0x5f, 0xd4, 0xd6, 0x66, 0xd2, 0x34,
|
||||
0x07, 0x04, 0xfb, 0xf4, 0x72, 0xc0, 0xee, 0xf1, 0xd1, 0x51, 0xbb, 0x5f, 0x4a, 0x5d, 0x0a, 0x90,
|
||||
0x37, 0xe4, 0x6d, 0x58, 0x9b, 0x0f, 0xe8, 0xb4, 0x0f, 0x4b, 0xe9, 0x8a, 0x7e, 0x7e, 0x51, 0x5b,
|
||||
0x99, 0x41, 0x77, 0x5c, 0xaf, 0x92, 0xfb, 0xee, 0xf9, 0xe6, 0xd2, 0x4f, 0x3f, 0x6c, 0x2e, 0xdd,
|
||||
0xf9, 0x51, 0x81, 0xe2, 0xdc, 0x94, 0xe8, 0x1b, 0x70, 0xbd, 0xd7, 0x3e, 0xe8, 0xec, 0xef, 0x59,
|
||||
0x47, 0xbd, 0x03, 0xab, 0xff, 0x65, 0x77, 0x7f, 0xa6, 0x8a, 0x1b, 0x50, 0xe8, 0x9a, 0xfb, 0x8f,
|
||||
0x8f, 0xfb, 0xfb, 0xdc, 0x53, 0x52, 0x2a, 0xab, 0xe7, 0x17, 0x35, 0xad, 0x1b, 0xe1, 0x93, 0x80,
|
||||
0x62, 0x1e, 0x7f, 0x13, 0x56, 0xba, 0xe6, 0xbe, 0x38, 0xac, 0x00, 0xa5, 0x2a, 0x6b, 0xe7, 0x17,
|
||||
0xb5, 0x62, 0x37, 0xc2, 0x42, 0x08, 0x1c, 0xb6, 0x05, 0xc5, 0xae, 0x79, 0xdc, 0x3d, 0xee, 0x35,
|
||||
0x0f, 0x05, 0x2a, 0x5d, 0x29, 0x9d, 0x5f, 0xd4, 0x0a, 0xf1, 0x88, 0x33, 0xd0, 0xf4, 0x9c, 0x2d,
|
||||
0xe3, 0xab, 0x7b, 0x8e, 0x4b, 0x47, 0x93, 0x81, 0x31, 0x0c, 0xc6, 0x8d, 0x69, 0xf7, 0x66, 0x3f,
|
||||
0x67, 0xfe, 0xa3, 0x18, 0x2c, 0xf3, 0xc5, 0x47, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x96,
|
||||
0xf2, 0xb9, 0x67, 0x0c, 0x00, 0x00,
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ enum SignedMsgType {
|
||||
|
||||
// PartsetHeader
|
||||
message PartSetHeader {
|
||||
int64 total = 1;
|
||||
bytes hash = 2;
|
||||
uint32 total = 1;
|
||||
bytes hash = 2;
|
||||
}
|
||||
|
||||
message Part {
|
||||
@@ -93,13 +93,13 @@ message Data {
|
||||
message Vote {
|
||||
SignedMsgType type = 1;
|
||||
int64 height = 2;
|
||||
int64 round = 3;
|
||||
int32 round = 3;
|
||||
BlockID block_id = 4
|
||||
[(gogoproto.nullable) = false, (gogoproto.customname) = "BlockID"]; // zero if vote is nil.
|
||||
google.protobuf.Timestamp timestamp = 5
|
||||
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
|
||||
bytes validator_address = 6;
|
||||
int64 validator_index = 7;
|
||||
int32 validator_index = 7;
|
||||
bytes signature = 8;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
"github.com/tendermint/tendermint/privval"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -42,7 +43,7 @@ func makeEvidences(
|
||||
ValidatorIndex: 0,
|
||||
Height: 1,
|
||||
Round: 0,
|
||||
Type: types.PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
Timestamp: time.Now().UTC(),
|
||||
BlockID: types.BlockID{
|
||||
Hash: tmhash.Sum([]byte("blockhash")),
|
||||
@@ -90,7 +91,7 @@ func makeEvidences(
|
||||
// different type
|
||||
{
|
||||
v := vote2
|
||||
v.Type = types.PrecommitType
|
||||
v.Type = tmproto.PrecommitType
|
||||
fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID))
|
||||
}
|
||||
|
||||
@@ -188,7 +189,7 @@ func TestBroadcastEvidence_ConflictingHeadersEvidence(t *testing.T) {
|
||||
Height: h2.Height,
|
||||
Round: h2.Commit.Round,
|
||||
Timestamp: h2.Time,
|
||||
Type: types.PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: h2.Commit.BlockID,
|
||||
}
|
||||
signBytes, err := pv.Key.PrivKey.Sign(vote.SignBytes(chainID))
|
||||
|
||||
@@ -49,7 +49,7 @@ func main() {
|
||||
// the length of tendermint/wal/MsgInfo in the wal.json may exceed the defaultBufSize(4096) of bufio
|
||||
// because of the byte array in BlockPart
|
||||
// leading to unmarshal error: unexpected end of JSON input
|
||||
br := bufio.NewReaderSize(f, 2*types.BlockPartSizeBytes)
|
||||
br := bufio.NewReaderSize(f, int(2*types.BlockPartSizeBytes))
|
||||
dec := cs.NewWALEncoder(walFile)
|
||||
|
||||
for {
|
||||
|
||||
@@ -7,5 +7,5 @@ for dir in $proto_dirs; do
|
||||
protoc \
|
||||
-I. \
|
||||
--gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration,plugins=grpc,paths=source_relative:. \
|
||||
$(find "${dir}" -name '*.proto')
|
||||
$(find "${dir}" -maxdepth 1 -name '*.proto')
|
||||
done
|
||||
|
||||
@@ -354,7 +354,7 @@ func getBeginBlockValidatorInfo(block *types.Block, stateDB dbm.DB) (abci.LastCo
|
||||
}
|
||||
|
||||
return abci.LastCommitInfo{
|
||||
Round: int32(block.LastCommit.Round),
|
||||
Round: block.LastCommit.Round,
|
||||
Votes: voteInfos,
|
||||
}, byzVals
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
chainID = "execution_chain"
|
||||
testPartSize = 65536
|
||||
nTxsPerBlock = 10
|
||||
chainID = "execution_chain"
|
||||
testPartSize uint32 = 65536
|
||||
nTxsPerBlock = 10
|
||||
)
|
||||
|
||||
func TestApplyBlock(t *testing.T) {
|
||||
|
||||
@@ -73,7 +73,7 @@ func makeValidCommit(
|
||||
) (*types.Commit, error) {
|
||||
sigs := make([]types.CommitSig, 0)
|
||||
for i := 0; i < vals.Size(); i++ {
|
||||
_, val := vals.GetByIndex(i)
|
||||
_, val := vals.GetByIndex(int32(i))
|
||||
vote, err := types.MakeVote(height, blockID, vals, privVals[val.Address.String()], chainID, time.Now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -371,7 +371,7 @@ func testProposerFreq(t *testing.T, caseNum int, valSet *types.ValidatorSet) {
|
||||
|
||||
// assert frequencies match expected (max off by 1)
|
||||
for i, freq := range freqs {
|
||||
_, val := valSet.GetByIndex(i)
|
||||
_, val := valSet.GetByIndex(int32(i))
|
||||
expectFreq := int(val.VotingPower) * runMult
|
||||
gotFreq := freq
|
||||
abs := int(math.Abs(float64(expectFreq - gotFreq)))
|
||||
|
||||
@@ -321,7 +321,7 @@ func LoadValidators(db dbm.DB, height int64) (*types.ValidatorSet, error) {
|
||||
),
|
||||
)
|
||||
}
|
||||
valInfo2.ValidatorSet.IncrementProposerPriority(int(height - lastStoredHeight)) // mutate
|
||||
valInfo2.ValidatorSet.IncrementProposerPriority(tmmath.SafeConvertInt32(height - lastStoredHeight)) // mutate
|
||||
valInfo = valInfo2
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestTxFilter(t *testing.T) {
|
||||
state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
|
||||
require.NoError(t, err)
|
||||
|
||||
f := sm.TxPreCheck(state)
|
||||
f := sm.TxPreCheck(state) // current max size of a tx 1850
|
||||
if tc.isErr {
|
||||
assert.NotNil(t, f(tc.tx), "#%v", i)
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
memmock "github.com/tendermint/tendermint/mempool/mock"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/state/mocks"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -185,7 +186,7 @@ func TestValidateBlockCommit(t *testing.T) {
|
||||
Height: height,
|
||||
Round: 0,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: types.PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: blockID,
|
||||
}
|
||||
err = badPrivVal.SignVote(chainID, goodVote)
|
||||
@@ -240,9 +241,9 @@ func TestValidateBlockEvidence(t *testing.T) {
|
||||
require.True(t, maxNumEvidence > 2)
|
||||
evidence := make([]types.Evidence, 0)
|
||||
// precisely the amount of allowed evidence
|
||||
for i := uint32(0); i < maxNumEvidence; i++ {
|
||||
for i := int32(0); uint32(i) < maxNumEvidence; i++ {
|
||||
// make different evidence for each validator
|
||||
addr, _ := state.Validators.GetByIndex(int(i))
|
||||
addr, _ := state.Validators.GetByIndex(i)
|
||||
evidence = append(evidence, types.NewMockEvidence(height, time.Now(), addr))
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ func (bs *BlockStore) LoadBlock(height int64) *types.Block {
|
||||
|
||||
var block = new(types.Block)
|
||||
buf := []byte{}
|
||||
for i := 0; i < blockMeta.BlockID.PartsHeader.Total; i++ {
|
||||
for i := 0; i < int(blockMeta.BlockID.PartsHeader.Total); i++ {
|
||||
part := bs.LoadBlockPart(height, i)
|
||||
buf = append(buf, part.Bytes...)
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (bs *BlockStore) PruneBlocks(height int64) (uint64, error) {
|
||||
batch.Delete(calcBlockHashKey(meta.BlockID.Hash))
|
||||
batch.Delete(calcBlockCommitKey(h))
|
||||
batch.Delete(calcSeenCommitKey(h))
|
||||
for p := 0; p < meta.BlockID.PartsHeader.Total; p++ {
|
||||
for p := 0; p < int(meta.BlockID.PartsHeader.Total); p++ {
|
||||
batch.Delete(calcBlockPartKey(h, p))
|
||||
}
|
||||
pruned++
|
||||
@@ -286,7 +286,7 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
|
||||
bs.db.Set(calcBlockHashKey(hash), []byte(fmt.Sprintf("%d", height)))
|
||||
|
||||
// Save block parts
|
||||
for i := 0; i < blockParts.Total(); i++ {
|
||||
for i := 0; i < int(blockParts.Total()); i++ {
|
||||
part := blockParts.GetPart(i)
|
||||
bs.saveBlockPart(height, i, part)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmnet "github.com/tendermint/tendermint/libs/net"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -35,7 +36,7 @@ const (
|
||||
ErrTestSignVoteFailed // 10
|
||||
)
|
||||
|
||||
var voteTypes = []types.SignedMsgType{types.PrevoteType, types.PrecommitType}
|
||||
var voteTypes = []tmproto.SignedMsgType{tmproto.PrevoteType, tmproto.PrecommitType}
|
||||
|
||||
// TestHarnessError allows us to keep track of which exit code should be used
|
||||
// when exiting the main program.
|
||||
@@ -215,7 +216,7 @@ func (th *TestHarness) TestSignProposal() error {
|
||||
// sha256 hash of "hash"
|
||||
hash := tmhash.Sum([]byte("hash"))
|
||||
prop := &types.Proposal{
|
||||
Type: types.ProposalType,
|
||||
Type: tmproto.ProposalType,
|
||||
Height: 100,
|
||||
Round: 0,
|
||||
POLRound: -1,
|
||||
|
||||
@@ -32,7 +32,7 @@ const (
|
||||
|
||||
stateFileContents = `{
|
||||
"height": "0",
|
||||
"round": "0",
|
||||
"round": 0,
|
||||
"step": 0
|
||||
}`
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
const (
|
||||
// MaxHeaderBytes is a maximum header size (including amino overhead).
|
||||
MaxHeaderBytes int64 = 632
|
||||
MaxHeaderBytes int64 = 628
|
||||
|
||||
// MaxAminoOverheadForBlock - maximum amino overhead to encode a block (up to
|
||||
// MaxBlockSizeBytes in size) not including it's parts except Data.
|
||||
@@ -134,7 +134,7 @@ func (b *Block) Hash() tmbytes.HexBytes {
|
||||
// MakePartSet returns a PartSet containing parts of a serialized block.
|
||||
// This is the form in which the block is gossipped to peers.
|
||||
// CONTRACT: partSize is greater than zero.
|
||||
func (b *Block) MakePartSet(partSize int) *PartSet {
|
||||
func (b *Block) MakePartSet(partSize uint32) *PartSet {
|
||||
if b == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -657,7 +657,7 @@ type Commit struct {
|
||||
// Any peer with a block can gossip signatures by index with a peer without
|
||||
// recalculating the active ValidatorSet.
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
BlockID BlockID `json:"block_id"`
|
||||
Signatures []CommitSig `json:"signatures"`
|
||||
|
||||
@@ -669,7 +669,7 @@ type Commit struct {
|
||||
}
|
||||
|
||||
// NewCommit returns a new Commit.
|
||||
func NewCommit(height int64, round int, blockID BlockID, commitSigs []CommitSig) *Commit {
|
||||
func NewCommit(height int64, round int32, blockID BlockID, commitSigs []CommitSig) *Commit {
|
||||
return &Commit{
|
||||
Height: height,
|
||||
Round: round,
|
||||
@@ -682,12 +682,12 @@ func NewCommit(height int64, round int, blockID BlockID, commitSigs []CommitSig)
|
||||
// Panics if signatures from the commit can't be added to the voteset.
|
||||
// Inverse of VoteSet.MakeCommit().
|
||||
func CommitToVoteSet(chainID string, commit *Commit, vals *ValidatorSet) *VoteSet {
|
||||
voteSet := NewVoteSet(chainID, commit.Height, commit.Round, PrecommitType, vals)
|
||||
voteSet := NewVoteSet(chainID, commit.Height, commit.Round, tmproto.PrecommitType, vals)
|
||||
for idx, commitSig := range commit.Signatures {
|
||||
if commitSig.Absent() {
|
||||
continue // OK, some precommits can be missing.
|
||||
}
|
||||
added, err := voteSet.AddVote(commit.GetVote(idx))
|
||||
added, err := voteSet.AddVote(commit.GetVote(int32(idx)))
|
||||
if !added || err != nil {
|
||||
panic(fmt.Sprintf("Failed to reconstruct LastCommit: %v", err))
|
||||
}
|
||||
@@ -698,10 +698,10 @@ func CommitToVoteSet(chainID string, commit *Commit, vals *ValidatorSet) *VoteSe
|
||||
// GetVote converts the CommitSig for the given valIdx to a Vote.
|
||||
// Returns nil if the precommit at valIdx is nil.
|
||||
// Panics if valIdx >= commit.Size().
|
||||
func (commit *Commit) GetVote(valIdx int) *Vote {
|
||||
func (commit *Commit) GetVote(valIdx int32) *Vote {
|
||||
commitSig := commit.Signatures[valIdx]
|
||||
return &Vote{
|
||||
Type: PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
Height: commit.Height,
|
||||
Round: commit.Round,
|
||||
BlockID: commitSig.BlockID(commit.BlockID),
|
||||
@@ -716,14 +716,14 @@ func (commit *Commit) GetVote(valIdx int) *Vote {
|
||||
// The only unique part of the SignBytes is the Timestamp - all other fields
|
||||
// signed over are otherwise the same for all validators.
|
||||
// Panics if valIdx >= commit.Size().
|
||||
func (commit *Commit) VoteSignBytes(chainID string, valIdx int) []byte {
|
||||
func (commit *Commit) VoteSignBytes(chainID string, valIdx int32) []byte {
|
||||
return commit.GetVote(valIdx).SignBytes(chainID)
|
||||
}
|
||||
|
||||
// Type returns the vote type of the commit, which is always VoteTypePrecommit
|
||||
// Implements VoteSetReader.
|
||||
func (commit *Commit) Type() byte {
|
||||
return byte(PrecommitType)
|
||||
return byte(tmproto.PrecommitType)
|
||||
}
|
||||
|
||||
// GetHeight returns height of the commit.
|
||||
@@ -734,7 +734,7 @@ func (commit *Commit) GetHeight() int64 {
|
||||
|
||||
// GetRound returns height of the commit.
|
||||
// Implements VoteSetReader.
|
||||
func (commit *Commit) GetRound() int {
|
||||
func (commit *Commit) GetRound() int32 {
|
||||
return commit.Round
|
||||
}
|
||||
|
||||
@@ -764,7 +764,7 @@ func (commit *Commit) BitArray() *bits.BitArray {
|
||||
// GetByIndex returns the vote corresponding to a given validator index.
|
||||
// Panics if `index >= commit.Size()`.
|
||||
// Implements VoteSetReader.
|
||||
func (commit *Commit) GetByIndex(valIdx int) *Vote {
|
||||
func (commit *Commit) GetByIndex(valIdx int32) *Vote {
|
||||
return commit.GetVote(valIdx)
|
||||
}
|
||||
|
||||
@@ -854,7 +854,7 @@ func (commit *Commit) ToProto() *tmproto.Commit {
|
||||
c.Signatures = sigs
|
||||
|
||||
c.Height = commit.Height
|
||||
c.Round = int32(commit.Round)
|
||||
c.Round = commit.Round
|
||||
c.BlockID = commit.BlockID.ToProto()
|
||||
if commit.hash != nil {
|
||||
c.Hash = commit.hash
|
||||
@@ -891,7 +891,7 @@ func CommitFromProto(cp *tmproto.Commit) (*Commit, error) {
|
||||
commit.Signatures = sigs
|
||||
|
||||
commit.Height = cp.Height
|
||||
commit.Round = int(cp.Round)
|
||||
commit.Round = cp.Round
|
||||
commit.BlockID = *bi
|
||||
commit.hash = cp.Hash
|
||||
commit.bitArray = bitArray
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/bits"
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
"github.com/tendermint/tendermint/version"
|
||||
)
|
||||
@@ -36,7 +37,7 @@ func TestBlockAddEvidence(t *testing.T) {
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, PrecommitType, 10, 1)
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
|
||||
commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -56,7 +57,7 @@ func TestBlockValidateBasic(t *testing.T) {
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, PrecommitType, 10, 1)
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
|
||||
commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -110,7 +111,7 @@ func TestBlockMakePartSet(t *testing.T) {
|
||||
|
||||
partSet := MakeBlock(int64(3), []Tx{Tx("Hello World")}, nil, nil).MakePartSet(1024)
|
||||
assert.NotNil(t, partSet)
|
||||
assert.Equal(t, 1, partSet.Total())
|
||||
assert.EqualValues(t, 1, partSet.Total())
|
||||
}
|
||||
|
||||
func TestBlockMakePartSetWithEvidence(t *testing.T) {
|
||||
@@ -119,7 +120,7 @@ func TestBlockMakePartSetWithEvidence(t *testing.T) {
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, PrecommitType, 10, 1)
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
|
||||
commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -128,7 +129,7 @@ func TestBlockMakePartSetWithEvidence(t *testing.T) {
|
||||
|
||||
partSet := MakeBlock(h, []Tx{Tx("Hello World")}, commit, evList).MakePartSet(512)
|
||||
assert.NotNil(t, partSet)
|
||||
assert.Equal(t, 3, partSet.Total())
|
||||
assert.EqualValues(t, 3, partSet.Total())
|
||||
}
|
||||
|
||||
func TestBlockHashesTo(t *testing.T) {
|
||||
@@ -136,7 +137,7 @@ func TestBlockHashesTo(t *testing.T) {
|
||||
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, PrecommitType, 10, 1)
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
|
||||
commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -178,7 +179,7 @@ func makeBlockIDRandom() BlockID {
|
||||
return BlockID{blockHash, PartSetHeader{123, partSetHash}}
|
||||
}
|
||||
|
||||
func makeBlockID(hash []byte, partSetSize int, partSetHash []byte) BlockID {
|
||||
func makeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) BlockID {
|
||||
var (
|
||||
h = make([]byte, tmhash.Size)
|
||||
psH = make([]byte, tmhash.Size)
|
||||
@@ -209,13 +210,13 @@ func TestNilDataHashDoesntCrash(t *testing.T) {
|
||||
func TestCommit(t *testing.T) {
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
voteSet, _, vals := randVoteSet(h-1, 1, PrecommitType, 10, 1)
|
||||
voteSet, _, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
|
||||
commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, h-1, commit.Height)
|
||||
assert.Equal(t, 1, commit.Round)
|
||||
assert.Equal(t, PrecommitType, SignedMsgType(commit.Type()))
|
||||
assert.EqualValues(t, 1, commit.Round)
|
||||
assert.Equal(t, tmproto.PrecommitType, tmproto.SignedMsgType(commit.Type()))
|
||||
if commit.Size() <= 0 {
|
||||
t.Fatalf("commit %v has a zero or negative size: %d", commit, commit.Size())
|
||||
}
|
||||
@@ -330,7 +331,7 @@ func TestMaxHeaderBytes(t *testing.T) {
|
||||
ChainID: maxChainID,
|
||||
Height: math.MaxInt64,
|
||||
Time: timestamp,
|
||||
LastBlockID: makeBlockID(make([]byte, tmhash.Size), math.MaxInt64, make([]byte, tmhash.Size)),
|
||||
LastBlockID: makeBlockID(make([]byte, tmhash.Size), math.MaxInt32, make([]byte, tmhash.Size)),
|
||||
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
|
||||
DataHash: tmhash.Sum([]byte("data_hash")),
|
||||
ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
|
||||
@@ -351,7 +352,7 @@ func TestMaxHeaderBytes(t *testing.T) {
|
||||
func randCommit(now time.Time) *Commit {
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
voteSet, _, vals := randVoteSet(h-1, 1, PrecommitType, 10, 1)
|
||||
voteSet, _, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
|
||||
commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, now)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -377,9 +378,9 @@ func TestBlockMaxDataBytes(t *testing.T) {
|
||||
}{
|
||||
0: {-10, 1, 0, true, 0},
|
||||
1: {10, 1, 0, true, 0},
|
||||
2: {865, 1, 0, true, 0},
|
||||
3: {866, 1, 0, false, 0},
|
||||
4: {867, 1, 0, false, 1},
|
||||
2: {849, 1, 0, true, 0},
|
||||
3: {850, 1, 0, false, 0},
|
||||
4: {851, 1, 0, false, 1},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
@@ -407,10 +408,10 @@ func TestBlockMaxDataBytesUnknownEvidence(t *testing.T) {
|
||||
}{
|
||||
0: {-10, 0, 1, true, 0},
|
||||
1: {10, 0, 1, true, 0},
|
||||
2: {865, 0, 1, true, 0},
|
||||
3: {866, 0, 1, false, 0},
|
||||
4: {1310, 1, 1, false, 0},
|
||||
5: {1311, 1, 1, false, 1},
|
||||
2: {849, 0, 1, true, 0},
|
||||
3: {850, 0, 1, false, 0},
|
||||
4: {1294, 1, 1, false, 0},
|
||||
5: {1295, 1, 1, false, 1},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
@@ -432,14 +433,14 @@ func TestCommitToVoteSet(t *testing.T) {
|
||||
lastID := makeBlockIDRandom()
|
||||
h := int64(3)
|
||||
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, PrecommitType, 10, 1)
|
||||
voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1)
|
||||
commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now())
|
||||
assert.NoError(t, err)
|
||||
|
||||
chainID := voteSet.ChainID()
|
||||
voteSet2 := CommitToVoteSet(chainID, commit, valSet)
|
||||
|
||||
for i := 0; i < len(vals); i++ {
|
||||
for i := int32(0); int(i) < len(vals); i++ {
|
||||
vote1 := voteSet.GetByIndex(i)
|
||||
vote2 := voteSet2.GetByIndex(i)
|
||||
vote3 := commit.GetVote(i)
|
||||
@@ -472,9 +473,9 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
voteSet, valSet, vals := randVoteSet(height-1, round, PrecommitType, tc.numValidators, 1)
|
||||
voteSet, valSet, vals := randVoteSet(height-1, round, tmproto.PrecommitType, tc.numValidators, 1)
|
||||
|
||||
vi := 0
|
||||
vi := int32(0)
|
||||
for n := range tc.blockIDs {
|
||||
for i := 0; i < tc.numVotes[n]; i++ {
|
||||
pubKey, err := vals[vi].GetPubKey()
|
||||
@@ -484,7 +485,7 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) {
|
||||
ValidatorIndex: vi,
|
||||
Height: height - 1,
|
||||
Round: round,
|
||||
Type: PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: tc.blockIDs[n],
|
||||
Timestamp: tmtime.Now(),
|
||||
}
|
||||
@@ -573,8 +574,8 @@ func TestBlockIDValidateBasic(t *testing.T) {
|
||||
invalidBlockID := BlockID{
|
||||
Hash: []byte{0},
|
||||
PartsHeader: PartSetHeader{
|
||||
Total: -1,
|
||||
Hash: bytes.HexBytes{},
|
||||
Total: 1,
|
||||
Hash: []byte{0},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bytes"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
|
||||
@@ -19,23 +20,23 @@ type CanonicalBlockID struct {
|
||||
|
||||
type CanonicalPartSetHeader struct {
|
||||
Hash bytes.HexBytes
|
||||
Total int
|
||||
Total uint32
|
||||
}
|
||||
|
||||
type CanonicalProposal struct {
|
||||
Type SignedMsgType // type alias for byte
|
||||
Height int64 `binary:"fixed64"`
|
||||
Round int64 `binary:"fixed64"`
|
||||
POLRound int64 `binary:"fixed64"`
|
||||
Type tmproto.SignedMsgType // type alias for byte
|
||||
Height int64 `binary:"fixed64"`
|
||||
Round int64 `binary:"fixed64"`
|
||||
POLRound int64 `binary:"fixed64"`
|
||||
BlockID CanonicalBlockID
|
||||
Timestamp time.Time
|
||||
ChainID string
|
||||
}
|
||||
|
||||
type CanonicalVote struct {
|
||||
Type SignedMsgType // type alias for byte
|
||||
Height int64 `binary:"fixed64"`
|
||||
Round int64 `binary:"fixed64"`
|
||||
Type tmproto.SignedMsgType // type alias for byte
|
||||
Height int64 `binary:"fixed64"`
|
||||
Round int64 `binary:"fixed64"`
|
||||
BlockID CanonicalBlockID
|
||||
Timestamp time.Time
|
||||
ChainID string
|
||||
@@ -60,7 +61,7 @@ func CanonicalizePartSetHeader(psh PartSetHeader) CanonicalPartSetHeader {
|
||||
|
||||
func CanonicalizeProposal(chainID string, proposal *Proposal) CanonicalProposal {
|
||||
return CanonicalProposal{
|
||||
Type: ProposalType,
|
||||
Type: tmproto.ProposalType,
|
||||
Height: proposal.Height,
|
||||
Round: int64(proposal.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int)
|
||||
POLRound: int64(proposal.POLRound),
|
||||
|
||||
@@ -86,18 +86,18 @@ type EventDataTx struct {
|
||||
// NOTE: This goes into the replay WAL
|
||||
type EventDataRoundState struct {
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
Step string `json:"step"`
|
||||
}
|
||||
|
||||
type ValidatorInfo struct {
|
||||
Address Address `json:"address"`
|
||||
Index int `json:"index"`
|
||||
Index int32 `json:"index"`
|
||||
}
|
||||
|
||||
type EventDataNewRound struct {
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
Step string `json:"step"`
|
||||
|
||||
Proposer ValidatorInfo `json:"proposer"`
|
||||
@@ -105,7 +105,7 @@ type EventDataNewRound struct {
|
||||
|
||||
type EventDataCompleteProposal struct {
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Round int32 `json:"round"`
|
||||
Step string `json:"step"`
|
||||
|
||||
BlockID BlockID `json:"block_id"`
|
||||
|
||||
@@ -567,7 +567,7 @@ func (ev ConflictingHeadersEvidence) Split(committedHeader *Header, valSet *Vali
|
||||
|
||||
if !valSet.HasAddress(sig.ValidatorAddress) {
|
||||
evList = append(evList, &PhantomValidatorEvidence{
|
||||
Vote: alternativeHeader.Commit.GetVote(i),
|
||||
Vote: alternativeHeader.Commit.GetVote(int32(i)),
|
||||
LastHeightValidatorWasInSet: lastHeightValidatorWasInSet,
|
||||
})
|
||||
}
|
||||
@@ -597,7 +597,7 @@ func (ev ConflictingHeadersEvidence) Split(committedHeader *Header, valSet *Vali
|
||||
}
|
||||
evList = append(evList, &LunaticValidatorEvidence{
|
||||
Header: alternativeHeader.Header,
|
||||
Vote: alternativeHeader.Commit.GetVote(i),
|
||||
Vote: alternativeHeader.Commit.GetVote(int32(i)),
|
||||
InvalidHeaderField: invalidField,
|
||||
})
|
||||
}
|
||||
@@ -638,15 +638,15 @@ OUTER_LOOP:
|
||||
// immediately slashable (#F1).
|
||||
if ev.H1.Commit.Round == ev.H2.Commit.Round {
|
||||
evList = append(evList, &DuplicateVoteEvidence{
|
||||
VoteA: ev.H1.Commit.GetVote(i),
|
||||
VoteB: ev.H2.Commit.GetVote(j),
|
||||
VoteA: ev.H1.Commit.GetVote(int32(i)),
|
||||
VoteB: ev.H2.Commit.GetVote(int32(j)),
|
||||
})
|
||||
} else {
|
||||
// if H1.Round != H2.Round we need to run full detection procedure => not
|
||||
// immediately slashable.
|
||||
evList = append(evList, &PotentialAmnesiaEvidence{
|
||||
VoteA: ev.H1.Commit.GetVote(i),
|
||||
VoteB: ev.H2.Commit.GetVote(j),
|
||||
VoteA: ev.H1.Commit.GetVote(int32(i)),
|
||||
VoteB: ev.H2.Commit.GetVote(int32(j)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1128,7 +1128,7 @@ func MakePOLCFromVoteSet(voteSet *VoteSet, pubKey crypto.PubKey, blockID BlockID
|
||||
func makePOLCFromVoteSet(voteSet *VoteSet, pubKey crypto.PubKey, blockID BlockID) ProofOfLockChange {
|
||||
var votes []Vote
|
||||
valSetSize := voteSet.Size()
|
||||
for valIdx := 0; valIdx < valSetSize; valIdx++ {
|
||||
for valIdx := int32(0); int(valIdx) < valSetSize; valIdx++ {
|
||||
vote := voteSet.GetByIndex(valIdx)
|
||||
if vote != nil && vote.BlockID.Equals(blockID) {
|
||||
votes = append(votes, *vote)
|
||||
@@ -1155,7 +1155,7 @@ func (e ProofOfLockChange) Time() time.Time {
|
||||
return latest
|
||||
}
|
||||
|
||||
func (e ProofOfLockChange) Round() int {
|
||||
func (e ProofOfLockChange) Round() int32 {
|
||||
return e.Votes[0].Round
|
||||
}
|
||||
|
||||
@@ -1315,7 +1315,7 @@ func (e MockEvidence) String() string {
|
||||
func NewMockPOLC(height int64, time time.Time, pubKey crypto.PubKey) ProofOfLockChange {
|
||||
voteVal := NewMockPV()
|
||||
pKey, _ := voteVal.GetPubKey()
|
||||
vote := Vote{Type: PrecommitType, Height: height, Round: 1, BlockID: BlockID{},
|
||||
vote := Vote{Type: tmproto.PrecommitType, Height: height, Round: 1, BlockID: BlockID{},
|
||||
Timestamp: time, ValidatorAddress: pKey.Address(), ValidatorIndex: 1, Signature: []byte{}}
|
||||
_ = voteVal.SignVote("mock-chain-id", &vote)
|
||||
return ProofOfLockChange{
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
)
|
||||
|
||||
type voteData struct {
|
||||
@@ -22,7 +23,7 @@ type voteData struct {
|
||||
var defaultVoteTime = time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
func makeVote(
|
||||
t *testing.T, val PrivValidator, chainID string, valIndex int, height int64, round, step int, blockID BlockID,
|
||||
t *testing.T, val PrivValidator, chainID string, valIndex int32, height int64, round int32, step int, blockID BlockID,
|
||||
time time.Time) *Vote {
|
||||
pubKey, err := val.GetPubKey()
|
||||
require.NoError(t, err)
|
||||
@@ -31,7 +32,7 @@ func makeVote(
|
||||
ValidatorIndex: valIndex,
|
||||
Height: height,
|
||||
Round: round,
|
||||
Type: SignedMsgType(step),
|
||||
Type: tmproto.SignedMsgType(step),
|
||||
Timestamp: time,
|
||||
BlockID: blockID,
|
||||
}
|
||||
@@ -108,13 +109,13 @@ func TestEvidenceList(t *testing.T) {
|
||||
|
||||
func TestMaxEvidenceBytes(t *testing.T) {
|
||||
val := NewMockPV()
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
maxTime := time.Date(9999, 0, 0, 0, 0, 0, 0, time.UTC)
|
||||
const chainID = "mychain"
|
||||
ev := &DuplicateVoteEvidence{
|
||||
VoteA: makeVote(t, val, chainID, math.MaxInt64, math.MaxInt64, math.MaxInt64, math.MaxInt64, blockID, maxTime),
|
||||
VoteB: makeVote(t, val, chainID, math.MaxInt64, math.MaxInt64, math.MaxInt64, math.MaxInt64, blockID2, maxTime),
|
||||
VoteA: makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, math.MaxInt32, math.MaxInt64, blockID, maxTime),
|
||||
VoteB: makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, math.MaxInt32, math.MaxInt64, blockID2, maxTime),
|
||||
}
|
||||
|
||||
//TODO: Add other types of evidence to test and set MaxEvidenceBytes accordingly
|
||||
@@ -171,8 +172,8 @@ func randomDuplicatedVoteEvidence(t *testing.T) *DuplicateVoteEvidence {
|
||||
|
||||
func TestDuplicateVoteEvidenceValidation(t *testing.T) {
|
||||
val := NewMockPV()
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
const chainID = "mychain"
|
||||
|
||||
testCases := []struct {
|
||||
@@ -188,7 +189,7 @@ func TestDuplicateVoteEvidenceValidation(t *testing.T) {
|
||||
ev.VoteB = nil
|
||||
}, true},
|
||||
{"Invalid vote type", func(ev *DuplicateVoteEvidence) {
|
||||
ev.VoteA = makeVote(t, val, chainID, math.MaxInt64, math.MaxInt64, math.MaxInt64, 0, blockID2, defaultVoteTime)
|
||||
ev.VoteA = makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, math.MaxInt32, 0, blockID2, defaultVoteTime)
|
||||
}, true},
|
||||
{"Invalid vote order", func(ev *DuplicateVoteEvidence) {
|
||||
swap := ev.VoteA.Copy()
|
||||
@@ -199,8 +200,8 @@ func TestDuplicateVoteEvidenceValidation(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
vote1 := makeVote(t, val, chainID, math.MaxInt64, math.MaxInt64, math.MaxInt64, 0x02, blockID, defaultVoteTime)
|
||||
vote2 := makeVote(t, val, chainID, math.MaxInt64, math.MaxInt64, math.MaxInt64, 0x02, blockID2, defaultVoteTime)
|
||||
vote1 := makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, math.MaxInt32, 0x02, blockID, defaultVoteTime)
|
||||
vote2 := makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, math.MaxInt32, 0x02, blockID2, defaultVoteTime)
|
||||
ev := NewDuplicateVoteEvidence(vote1, vote2)
|
||||
tc.malleateEvidence(ev)
|
||||
assert.Equal(t, tc.expectErr, ev.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
@@ -302,8 +303,8 @@ func TestConflictingHeadersEvidence(t *testing.T) {
|
||||
header2.LastBlockID = blockID
|
||||
header2.ChainID = chainID
|
||||
|
||||
voteSet1, valSet, vals := randVoteSet(height, 1, PrecommitType, 10, 1)
|
||||
voteSet2 := NewVoteSet(chainID, height, 1, PrecommitType, valSet)
|
||||
voteSet1, valSet, vals := randVoteSet(height, 1, tmproto.PrecommitType, 10, 1)
|
||||
voteSet2 := NewVoteSet(chainID, height, 1, tmproto.PrecommitType, valSet)
|
||||
|
||||
commit1, err := MakeCommit(BlockID{
|
||||
Hash: header1.Hash(),
|
||||
@@ -360,8 +361,8 @@ func TestPotentialAmnesiaEvidence(t *testing.T) {
|
||||
|
||||
var (
|
||||
val = NewMockPV()
|
||||
blockID = makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 = makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID = makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 = makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
vote1 = makeVote(t, val, chainID, 0, height, 0, 2, blockID, defaultVoteTime)
|
||||
vote2 = makeVote(t, val, chainID, 0, height, 1, 2, blockID2, defaultVoteTime)
|
||||
)
|
||||
@@ -394,7 +395,7 @@ func TestProofOfLockChange(t *testing.T) {
|
||||
height int64 = 37
|
||||
)
|
||||
// 1: valid POLC - nothing should fail
|
||||
voteSet, valSet, privValidators, blockID := buildVoteSet(height, 1, 3, 7, 0, PrecommitType)
|
||||
voteSet, valSet, privValidators, blockID := buildVoteSet(height, 1, 3, 7, 0, tmproto.PrecommitType)
|
||||
pubKey, err := privValidators[7].GetPubKey()
|
||||
require.NoError(t, err)
|
||||
polc := makePOLCFromVoteSet(voteSet, pubKey, blockID)
|
||||
@@ -412,7 +413,7 @@ func TestProofOfLockChange(t *testing.T) {
|
||||
polc2 := makePOLCFromVoteSet(voteSet, pubKey, blockID)
|
||||
badPOLCs = append(badPOLCs, polc2)
|
||||
// 3: one vote was from a different round
|
||||
voteSet, _, privValidators, blockID = buildVoteSet(height, 1, 3, 7, 0, PrecommitType)
|
||||
voteSet, _, privValidators, blockID = buildVoteSet(height, 1, 3, 7, 0, tmproto.PrecommitType)
|
||||
pubKey, err = privValidators[7].GetPubKey()
|
||||
require.NoError(t, err)
|
||||
polc = makePOLCFromVoteSet(voteSet, pubKey, blockID)
|
||||
@@ -466,11 +467,11 @@ func makeHeaderRandom() *Header {
|
||||
func TestEvidenceProto(t *testing.T) {
|
||||
// -------- Votes --------
|
||||
val := NewMockPV()
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
const chainID = "mychain"
|
||||
v := makeVote(t, val, chainID, math.MaxInt64, math.MaxInt64, 1, 0x01, blockID, defaultVoteTime)
|
||||
v2 := makeVote(t, val, chainID, math.MaxInt64, math.MaxInt64, 2, 0x01, blockID2, defaultVoteTime)
|
||||
v := makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, 1, 0x01, blockID, defaultVoteTime)
|
||||
v2 := makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, 2, 0x01, blockID2, defaultVoteTime)
|
||||
|
||||
// -------- SignedHeaders --------
|
||||
const height int64 = 37
|
||||
@@ -488,8 +489,8 @@ func TestEvidenceProto(t *testing.T) {
|
||||
header2.LastBlockID = blockID
|
||||
header2.ChainID = chainID
|
||||
|
||||
voteSet1, valSet, vals := randVoteSet(height, 1, PrecommitType, 10, 1)
|
||||
voteSet2 := NewVoteSet(chainID, height, 1, PrecommitType, valSet)
|
||||
voteSet1, valSet, vals := randVoteSet(height, 1, tmproto.PrecommitType, 10, 1)
|
||||
voteSet2 := NewVoteSet(chainID, height, 1, tmproto.PrecommitType, valSet)
|
||||
|
||||
commit1, err := MakeCommit(BlockID{
|
||||
Hash: header1.Hash(),
|
||||
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
MaxBlockSizeBytes = 104857600 // 100MB
|
||||
|
||||
// BlockPartSizeBytes is the size of one block part.
|
||||
BlockPartSizeBytes = 65536 // 64kB
|
||||
BlockPartSizeBytes uint32 = 65536 // 64kB
|
||||
|
||||
// MaxBlockPartsCount is the maximum number of block parts.
|
||||
MaxBlockPartsCount = (MaxBlockSizeBytes / BlockPartSizeBytes) + 1
|
||||
|
||||
@@ -20,17 +20,14 @@ var (
|
||||
)
|
||||
|
||||
type Part struct {
|
||||
Index int `json:"index"`
|
||||
Index uint32 `json:"index"`
|
||||
Bytes tmbytes.HexBytes `json:"bytes"`
|
||||
Proof merkle.SimpleProof `json:"proof"`
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic validation.
|
||||
func (part *Part) ValidateBasic() error {
|
||||
if part.Index < 0 {
|
||||
return errors.New("negative Index")
|
||||
}
|
||||
if len(part.Bytes) > BlockPartSizeBytes {
|
||||
if len(part.Bytes) > int(BlockPartSizeBytes) {
|
||||
return fmt.Errorf("too big: %d bytes, max: %d", len(part.Bytes), BlockPartSizeBytes)
|
||||
}
|
||||
if err := part.Proof.ValidateBasic(); err != nil {
|
||||
@@ -57,7 +54,7 @@ func (part *Part) StringIndented(indent string) string {
|
||||
//-------------------------------------
|
||||
|
||||
type PartSetHeader struct {
|
||||
Total int `json:"total"`
|
||||
Total uint32 `json:"total"`
|
||||
Hash tmbytes.HexBytes `json:"hash"`
|
||||
}
|
||||
|
||||
@@ -75,9 +72,6 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool {
|
||||
|
||||
// ValidateBasic performs basic validation.
|
||||
func (psh PartSetHeader) ValidateBasic() error {
|
||||
if psh.Total < 0 {
|
||||
return errors.New("negative Total")
|
||||
}
|
||||
// Hash can be empty in case of POLBlockID.PartsHeader in Proposal.
|
||||
if err := ValidateHash(psh.Hash); err != nil {
|
||||
return fmt.Errorf("wrong Hash: %w", err)
|
||||
@@ -92,7 +86,7 @@ func (psh *PartSetHeader) ToProto() tmproto.PartSetHeader {
|
||||
}
|
||||
|
||||
return tmproto.PartSetHeader{
|
||||
Total: int64(psh.Total),
|
||||
Total: psh.Total,
|
||||
Hash: psh.Hash,
|
||||
}
|
||||
}
|
||||
@@ -103,7 +97,7 @@ func PartSetHeaderFromProto(ppsh *tmproto.PartSetHeader) (*PartSetHeader, error)
|
||||
return nil, errors.New("nil PartSetHeader")
|
||||
}
|
||||
psh := new(PartSetHeader)
|
||||
psh.Total = int(ppsh.Total)
|
||||
psh.Total = ppsh.Total
|
||||
psh.Hash = ppsh.Hash
|
||||
|
||||
return psh, psh.ValidateBasic()
|
||||
@@ -112,35 +106,36 @@ func PartSetHeaderFromProto(ppsh *tmproto.PartSetHeader) (*PartSetHeader, error)
|
||||
//-------------------------------------
|
||||
|
||||
type PartSet struct {
|
||||
total int
|
||||
total uint32
|
||||
hash []byte
|
||||
|
||||
mtx sync.Mutex
|
||||
parts []*Part
|
||||
partsBitArray *bits.BitArray
|
||||
count int
|
||||
count uint32
|
||||
}
|
||||
|
||||
// Returns an immutable, full PartSet from the data bytes.
|
||||
// The data bytes are split into "partSize" chunks, and merkle tree computed.
|
||||
func NewPartSetFromData(data []byte, partSize int) *PartSet {
|
||||
// CONTRACT: partSize is greater than zero.
|
||||
func NewPartSetFromData(data []byte, partSize uint32) *PartSet {
|
||||
// divide data into 4kb parts.
|
||||
total := (len(data) + partSize - 1) / partSize
|
||||
total := (uint32(len(data)) + partSize - 1) / partSize
|
||||
parts := make([]*Part, total)
|
||||
partsBytes := make([][]byte, total)
|
||||
partsBitArray := bits.NewBitArray(total)
|
||||
for i := 0; i < total; i++ {
|
||||
partsBitArray := bits.NewBitArray(int(total))
|
||||
for i := uint32(0); i < total; i++ {
|
||||
part := &Part{
|
||||
Index: i,
|
||||
Bytes: data[i*partSize : tmmath.MinInt(len(data), (i+1)*partSize)],
|
||||
Bytes: data[i*partSize : tmmath.MinInt(len(data), int((i+1)*partSize))],
|
||||
}
|
||||
parts[i] = part
|
||||
partsBytes[i] = part.Bytes
|
||||
partsBitArray.SetIndex(i, true)
|
||||
partsBitArray.SetIndex(int(i), true)
|
||||
}
|
||||
// Compute merkle proofs
|
||||
root, proofs := merkle.SimpleProofsFromByteSlices(partsBytes)
|
||||
for i := 0; i < total; i++ {
|
||||
for i := uint32(0); i < total; i++ {
|
||||
parts[i].Proof = *proofs[i]
|
||||
}
|
||||
return &PartSet{
|
||||
@@ -158,7 +153,7 @@ func NewPartSetFromHeader(header PartSetHeader) *PartSet {
|
||||
total: header.Total,
|
||||
hash: header.Hash,
|
||||
parts: make([]*Part, header.Total),
|
||||
partsBitArray: bits.NewBitArray(header.Total),
|
||||
partsBitArray: bits.NewBitArray(int(header.Total)),
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
@@ -200,14 +195,14 @@ func (ps *PartSet) HashesTo(hash []byte) bool {
|
||||
return bytes.Equal(ps.hash, hash)
|
||||
}
|
||||
|
||||
func (ps *PartSet) Count() int {
|
||||
func (ps *PartSet) Count() uint32 {
|
||||
if ps == nil {
|
||||
return 0
|
||||
}
|
||||
return ps.count
|
||||
}
|
||||
|
||||
func (ps *PartSet) Total() int {
|
||||
func (ps *PartSet) Total() uint32 {
|
||||
if ps == nil {
|
||||
return 0
|
||||
}
|
||||
@@ -238,7 +233,7 @@ func (ps *PartSet) AddPart(part *Part) (bool, error) {
|
||||
|
||||
// Add part
|
||||
ps.parts[part.Index] = part
|
||||
ps.partsBitArray.SetIndex(part.Index, true)
|
||||
ps.partsBitArray.SetIndex(int(part.Index), true)
|
||||
ps.count++
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ func TestBasicPartSet(t *testing.T) {
|
||||
partSet := NewPartSetFromData(data, testPartSize)
|
||||
|
||||
assert.NotEmpty(t, partSet.Hash())
|
||||
assert.Equal(t, 100, partSet.Total())
|
||||
assert.EqualValues(t, 100, partSet.Total())
|
||||
assert.Equal(t, 100, partSet.BitArray().Size())
|
||||
assert.True(t, partSet.HashesTo(partSet.Hash()))
|
||||
assert.True(t, partSet.IsComplete())
|
||||
assert.Equal(t, 100, partSet.Count())
|
||||
assert.EqualValues(t, 100, partSet.Count())
|
||||
|
||||
// Test adding parts to a new partSet.
|
||||
partSet2 := NewPartSetFromHeader(partSet.Header())
|
||||
|
||||
assert.True(t, partSet2.HasHeader(partSet.Header()))
|
||||
for i := 0; i < partSet.Total(); i++ {
|
||||
for i := 0; i < int(partSet.Total()); i++ {
|
||||
part := partSet.GetPart(i)
|
||||
//t.Logf("\n%v", part)
|
||||
added, err := partSet2.AddPart(part)
|
||||
@@ -49,7 +49,7 @@ func TestBasicPartSet(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
|
||||
assert.Equal(t, partSet.Hash(), partSet2.Hash())
|
||||
assert.Equal(t, 100, partSet2.Total())
|
||||
assert.EqualValues(t, 100, partSet2.Total())
|
||||
assert.True(t, partSet2.IsComplete())
|
||||
|
||||
// Reconstruct data, assert that they are equal.
|
||||
@@ -92,7 +92,6 @@ func TestPartSetHeaderValidateBasic(t *testing.T) {
|
||||
expectErr bool
|
||||
}{
|
||||
{"Good PartSet", func(psHeader *PartSetHeader) {}, false},
|
||||
{"Negative Total", func(psHeader *PartSetHeader) { psHeader.Total = -2 }, true},
|
||||
{"Invalid Hash", func(psHeader *PartSetHeader) { psHeader.Hash = make([]byte, 1) }, true},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
@@ -114,7 +113,6 @@ func TestPartValidateBasic(t *testing.T) {
|
||||
expectErr bool
|
||||
}{
|
||||
{"Good Part", func(pt *Part) {}, false},
|
||||
{"Negative index", func(pt *Part) { pt.Index = -1 }, true},
|
||||
{"Too big part", func(pt *Part) { pt.Bytes = make([]byte, BlockPartSizeBytes+1) }, true},
|
||||
{"Too big proof", func(pt *Part) {
|
||||
pt.Proof = merkle.SimpleProof{
|
||||
|
||||
@@ -22,10 +22,10 @@ var (
|
||||
// a so-called Proof-of-Lock (POL) round, as noted in the POLRound.
|
||||
// If POLRound >= 0, then BlockID corresponds to the block that is locked in POLRound.
|
||||
type Proposal struct {
|
||||
Type SignedMsgType
|
||||
Type tmproto.SignedMsgType
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
POLRound int `json:"pol_round"` // -1 if null.
|
||||
Round int32 `json:"round"` // there can not be greater than 2_147_483_647 rounds
|
||||
POLRound int32 `json:"pol_round"` // -1 if null.
|
||||
BlockID BlockID `json:"block_id"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Signature []byte `json:"signature"`
|
||||
@@ -33,9 +33,9 @@ type Proposal struct {
|
||||
|
||||
// NewProposal returns a new Proposal.
|
||||
// If there is no POLRound, polRound should be -1.
|
||||
func NewProposal(height int64, round int, polRound int, blockID BlockID) *Proposal {
|
||||
func NewProposal(height int64, round int32, polRound int32, blockID BlockID) *Proposal {
|
||||
return &Proposal{
|
||||
Type: ProposalType,
|
||||
Type: tmproto.ProposalType,
|
||||
Height: height,
|
||||
Round: round,
|
||||
BlockID: blockID,
|
||||
@@ -46,7 +46,7 @@ func NewProposal(height int64, round int, polRound int, blockID BlockID) *Propos
|
||||
|
||||
// ValidateBasic performs basic validation.
|
||||
func (p *Proposal) ValidateBasic() error {
|
||||
if p.Type != ProposalType {
|
||||
if p.Type != tmproto.ProposalType {
|
||||
return errors.New("invalid Type")
|
||||
}
|
||||
if p.Height < 0 {
|
||||
@@ -105,10 +105,10 @@ func (p *Proposal) ToProto() *tmproto.Proposal {
|
||||
pb := new(tmproto.Proposal)
|
||||
|
||||
pb.BlockID = p.BlockID.ToProto()
|
||||
pb.Type = tmproto.SignedMsgType(p.Type)
|
||||
pb.Type = p.Type
|
||||
pb.Height = p.Height
|
||||
pb.Round = int32(p.Round)
|
||||
pb.PolRound = int32(p.POLRound)
|
||||
pb.Round = p.Round
|
||||
pb.PolRound = p.POLRound
|
||||
pb.Timestamp = p.Timestamp
|
||||
pb.Signature = p.Signature
|
||||
|
||||
@@ -130,10 +130,10 @@ func ProposalFromProto(pp *tmproto.Proposal) (*Proposal, error) {
|
||||
}
|
||||
|
||||
p.BlockID = *blockID
|
||||
p.Type = SignedMsgType(pp.Type)
|
||||
p.Type = pp.Type
|
||||
p.Height = pp.Height
|
||||
p.Round = int(pp.Round)
|
||||
p.POLRound = int(pp.PolRound)
|
||||
p.Round = pp.Round
|
||||
p.POLRound = pp.PolRound
|
||||
p.Timestamp = pp.Timestamp
|
||||
p.Signature = pp.Signature
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
)
|
||||
|
||||
var testProposal *Proposal
|
||||
@@ -113,7 +114,7 @@ func TestProposalValidateBasic(t *testing.T) {
|
||||
expectErr bool
|
||||
}{
|
||||
{"Good Proposal", func(p *Proposal) {}, false},
|
||||
{"Invalid Type", func(p *Proposal) { p.Type = PrecommitType }, true},
|
||||
{"Invalid Type", func(p *Proposal) { p.Type = tmproto.PrecommitType }, true},
|
||||
{"Invalid Height", func(p *Proposal) { p.Height = -1 }, true},
|
||||
{"Invalid Round", func(p *Proposal) { p.Round = -1 }, true},
|
||||
{"Invalid POLRound", func(p *Proposal) { p.POLRound = -2 }, true},
|
||||
@@ -127,7 +128,7 @@ func TestProposalValidateBasic(t *testing.T) {
|
||||
p.Signature = make([]byte, MaxSignatureSize+1)
|
||||
}, true},
|
||||
}
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
|
||||
blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash")))
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
package types
|
||||
|
||||
// SignedMsgType is a type of signed message in the consensus.
|
||||
type SignedMsgType byte
|
||||
|
||||
const (
|
||||
// Votes
|
||||
PrevoteType SignedMsgType = 0x01
|
||||
PrecommitType SignedMsgType = 0x02
|
||||
|
||||
// Proposals
|
||||
ProposalType SignedMsgType = 0x20
|
||||
)
|
||||
import tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
|
||||
// IsVoteTypeValid returns true if t is a valid vote type.
|
||||
func IsVoteTypeValid(t SignedMsgType) bool {
|
||||
func IsVoteTypeValid(t tmproto.SignedMsgType) bool {
|
||||
switch t {
|
||||
case PrevoteType, PrecommitType:
|
||||
case tmproto.PrevoteType, tmproto.PrecommitType:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
||||
@@ -3,9 +3,11 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
)
|
||||
|
||||
func MakeCommit(blockID BlockID, height int64, round int,
|
||||
func MakeCommit(blockID BlockID, height int64, round int32,
|
||||
voteSet *VoteSet, validators []PrivValidator, now time.Time) (*Commit, error) {
|
||||
|
||||
// all sign
|
||||
@@ -16,10 +18,10 @@ func MakeCommit(blockID BlockID, height int64, round int,
|
||||
}
|
||||
vote := &Vote{
|
||||
ValidatorAddress: pubKey.Address(),
|
||||
ValidatorIndex: i,
|
||||
ValidatorIndex: int32(i),
|
||||
Height: height,
|
||||
Round: round,
|
||||
Type: PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: blockID,
|
||||
Timestamp: now,
|
||||
}
|
||||
@@ -61,7 +63,7 @@ func MakeVote(
|
||||
Height: height,
|
||||
Round: 0,
|
||||
Timestamp: now,
|
||||
Type: PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: blockID,
|
||||
}
|
||||
if err := privVal.SignVote(chainID, vote); err != nil {
|
||||
|
||||
@@ -104,7 +104,7 @@ func (vals *ValidatorSet) IsNilOrEmpty() bool {
|
||||
|
||||
// CopyIncrementProposerPriority increments ProposerPriority and updates the
|
||||
// proposer on a copy, and returns it.
|
||||
func (vals *ValidatorSet) CopyIncrementProposerPriority(times int) *ValidatorSet {
|
||||
func (vals *ValidatorSet) CopyIncrementProposerPriority(times int32) *ValidatorSet {
|
||||
copy := vals.Copy()
|
||||
copy.IncrementProposerPriority(times)
|
||||
return copy
|
||||
@@ -113,7 +113,7 @@ func (vals *ValidatorSet) CopyIncrementProposerPriority(times int) *ValidatorSet
|
||||
// IncrementProposerPriority increments ProposerPriority of each validator and
|
||||
// updates the proposer. Panics if validator set is empty.
|
||||
// `times` must be positive.
|
||||
func (vals *ValidatorSet) IncrementProposerPriority(times int) {
|
||||
func (vals *ValidatorSet) IncrementProposerPriority(times int32) {
|
||||
if vals.IsNilOrEmpty() {
|
||||
panic("empty validator set")
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func (vals *ValidatorSet) IncrementProposerPriority(times int) {
|
||||
|
||||
var proposer *Validator
|
||||
// Call IncrementProposerPriority(1) times times.
|
||||
for i := 0; i < times; i++ {
|
||||
for i := int32(0); i < times; i++ {
|
||||
proposer = vals.incrementProposerPriority()
|
||||
}
|
||||
|
||||
@@ -267,10 +267,10 @@ func (vals *ValidatorSet) HasAddress(address []byte) bool {
|
||||
|
||||
// GetByAddress returns an index of the validator with address and validator
|
||||
// itself (copy) if found. Otherwise, -1 and nil are returned.
|
||||
func (vals *ValidatorSet) GetByAddress(address []byte) (index int, val *Validator) {
|
||||
func (vals *ValidatorSet) GetByAddress(address []byte) (index int32, val *Validator) {
|
||||
for idx, val := range vals.Validators {
|
||||
if bytes.Equal(val.Address, address) {
|
||||
return idx, val.Copy()
|
||||
return int32(idx), val.Copy()
|
||||
}
|
||||
}
|
||||
return -1, nil
|
||||
@@ -280,8 +280,8 @@ func (vals *ValidatorSet) GetByAddress(address []byte) (index int, val *Validato
|
||||
// index.
|
||||
// It returns nil values if index is less than 0 or greater or equal to
|
||||
// len(ValidatorSet.Validators).
|
||||
func (vals *ValidatorSet) GetByIndex(index int) (address []byte, val *Validator) {
|
||||
if index < 0 || index >= len(vals.Validators) {
|
||||
func (vals *ValidatorSet) GetByIndex(index int32) (address []byte, val *Validator) {
|
||||
if index < 0 || int(index) >= len(vals.Validators) {
|
||||
return nil, nil
|
||||
}
|
||||
val = vals.Validators[index]
|
||||
@@ -691,7 +691,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
|
||||
val := vals.Validators[idx]
|
||||
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, idx)
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, int32(idx))
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
@@ -755,7 +755,7 @@ func (vals *ValidatorSet) VerifyFutureCommit(newSet *ValidatorSet, chainID strin
|
||||
|
||||
// Check old voting power.
|
||||
oldVotingPower := int64(0)
|
||||
seen := map[int]bool{}
|
||||
seen := map[int32]bool{}
|
||||
|
||||
for idx, commitSig := range commit.Signatures {
|
||||
if commitSig.Absent() {
|
||||
@@ -770,7 +770,7 @@ func (vals *ValidatorSet) VerifyFutureCommit(newSet *ValidatorSet, chainID strin
|
||||
seen[oldIdx] = true
|
||||
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, idx)
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, int32(idx))
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
@@ -803,7 +803,7 @@ func (vals *ValidatorSet) VerifyCommitTrusting(chainID string, commit *Commit, t
|
||||
|
||||
var (
|
||||
talliedVotingPower int64
|
||||
seenVals = make(map[int]int, len(commit.Signatures)) // validator index -> commit index
|
||||
seenVals = make(map[int32]int, len(commit.Signatures)) // validator index -> commit index
|
||||
)
|
||||
|
||||
// Safely calculate voting power needed.
|
||||
@@ -831,7 +831,7 @@ func (vals *ValidatorSet) VerifyCommitTrusting(chainID string, commit *Commit, t
|
||||
seenVals[valIdx] = idx
|
||||
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, idx)
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, int32(idx))
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
|
||||
@@ -32,7 +33,7 @@ func TestValidatorSetBasic(t *testing.T) {
|
||||
assert.EqualValues(t, vset, vset.Copy())
|
||||
assert.False(t, vset.HasAddress([]byte("some val")))
|
||||
idx, val := vset.GetByAddress([]byte("some val"))
|
||||
assert.Equal(t, -1, idx)
|
||||
assert.EqualValues(t, -1, idx)
|
||||
assert.Nil(t, val)
|
||||
addr, val := vset.GetByIndex(-100)
|
||||
assert.Nil(t, addr)
|
||||
@@ -54,7 +55,7 @@ func TestValidatorSetBasic(t *testing.T) {
|
||||
|
||||
assert.True(t, vset.HasAddress(val.Address))
|
||||
idx, _ = vset.GetByAddress(val.Address)
|
||||
assert.Equal(t, 0, idx)
|
||||
assert.EqualValues(t, 0, idx)
|
||||
addr, _ = vset.GetByIndex(0)
|
||||
assert.Equal(t, []byte(val.Address), addr)
|
||||
assert.Equal(t, 1, vset.Size())
|
||||
@@ -315,7 +316,10 @@ func TestProposerSelection3(t *testing.T) {
|
||||
// i for the loop
|
||||
// j for the times
|
||||
// we should go in order for ever, despite some IncrementProposerPriority with times > 1
|
||||
var i, j int
|
||||
var (
|
||||
i int
|
||||
j int32
|
||||
)
|
||||
for ; i < 10000; i++ {
|
||||
got := vset.GetProposer().Address
|
||||
expected := proposerOrder[j%4].Address
|
||||
@@ -343,11 +347,11 @@ func TestProposerSelection3(t *testing.T) {
|
||||
}
|
||||
|
||||
// times is usually 1
|
||||
times := 1
|
||||
times := int32(1)
|
||||
mod := (tmrand.Int() % 5) + 1
|
||||
if tmrand.Int()%mod > 0 {
|
||||
// sometimes its up to 5
|
||||
times = (tmrand.Int() % 4) + 1
|
||||
times = (tmrand.Int31() % 4) + 1
|
||||
}
|
||||
vset.IncrementProposerPriority(times)
|
||||
|
||||
@@ -455,7 +459,7 @@ func TestAveragingInIncrementProposerPriority(t *testing.T) {
|
||||
// the expected ProposerPriority.
|
||||
tcs := []struct {
|
||||
vs ValidatorSet
|
||||
times int
|
||||
times int32
|
||||
avg int64
|
||||
}{
|
||||
0: {ValidatorSet{
|
||||
@@ -505,7 +509,7 @@ func TestAveragingInIncrementProposerPriorityWithVotingPower(t *testing.T) {
|
||||
tcs := []struct {
|
||||
vals *ValidatorSet
|
||||
wantProposerPrioritys []int64
|
||||
times int
|
||||
times int32
|
||||
wantProposer *Validator
|
||||
}{
|
||||
|
||||
@@ -660,7 +664,7 @@ func TestValidatorSetVerifyCommit(t *testing.T) {
|
||||
Height: height,
|
||||
Round: 0,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: blockID,
|
||||
}
|
||||
sig, err := privKey.Sign(vote.SignBytes(chainID))
|
||||
@@ -1233,7 +1237,7 @@ func applyChangesToValSet(t *testing.T, expErr error, valSet *ValidatorSet, vals
|
||||
}
|
||||
|
||||
func TestValSetUpdatePriorityOrderTests(t *testing.T) {
|
||||
const nMaxElections = 5000
|
||||
const nMaxElections int32 = 5000
|
||||
|
||||
testCases := []testVSetCfg{
|
||||
0: { // remove high power validator, keep old equal lower power validators
|
||||
@@ -1283,9 +1287,9 @@ func TestValSetUpdatePriorityOrderTests(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func verifyValSetUpdatePriorityOrder(t *testing.T, valSet *ValidatorSet, cfg testVSetCfg, nMaxElections int) {
|
||||
func verifyValSetUpdatePriorityOrder(t *testing.T, valSet *ValidatorSet, cfg testVSetCfg, nMaxElections int32) {
|
||||
// Run election up to nMaxElections times, sort validators by priorities
|
||||
valSet.IncrementProposerPriority(tmrand.Int()%nMaxElections + 1)
|
||||
valSet.IncrementProposerPriority(tmrand.Int31()%nMaxElections + 1)
|
||||
|
||||
// apply the changes, get the updated validators, sort by priorities
|
||||
applyChangesToValSet(t, nil, valSet, cfg.addedVals, cfg.updatedVals, cfg.deletedVals)
|
||||
@@ -1387,7 +1391,7 @@ func TestValSetUpdateOverflowRelated(t *testing.T) {
|
||||
func TestVerifyCommitTrusting(t *testing.T) {
|
||||
var (
|
||||
blockID = makeBlockIDRandom()
|
||||
voteSet, originalValset, vals = randVoteSet(1, 1, PrecommitType, 6, 1)
|
||||
voteSet, originalValset, vals = randVoteSet(1, 1, tmproto.PrecommitType, 6, 1)
|
||||
commit, err = MakeCommit(blockID, 1, 1, voteSet, vals, time.Now())
|
||||
newValSet, _ = RandValidatorSet(2, 1)
|
||||
)
|
||||
@@ -1428,7 +1432,7 @@ func TestVerifyCommitTrusting(t *testing.T) {
|
||||
func TestVerifyCommitTrustingErrorsOnOverflow(t *testing.T) {
|
||||
var (
|
||||
blockID = makeBlockIDRandom()
|
||||
voteSet, valSet, vals = randVoteSet(1, 1, PrecommitType, 1, MaxTotalVotingPower)
|
||||
voteSet, valSet, vals = randVoteSet(1, 1, tmproto.PrecommitType, 1, MaxTotalVotingPower)
|
||||
commit, err = MakeCommit(blockID, 1, 1, voteSet, vals, time.Now())
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const (
|
||||
// MaxVoteBytes is a maximum vote size (including amino overhead).
|
||||
MaxVoteBytes int64 = 223
|
||||
MaxVoteBytes int64 = 211
|
||||
nilVoteStr string = "nil-Vote"
|
||||
)
|
||||
|
||||
@@ -47,14 +47,14 @@ type Address = crypto.Address
|
||||
// Vote represents a prevote, precommit, or commit vote from validators for
|
||||
// consensus.
|
||||
type Vote struct {
|
||||
Type SignedMsgType `json:"type"`
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
BlockID BlockID `json:"block_id"` // zero if vote is nil.
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
ValidatorAddress Address `json:"validator_address"`
|
||||
ValidatorIndex int `json:"validator_index"`
|
||||
Signature []byte `json:"signature"`
|
||||
Type tmproto.SignedMsgType `json:"type"`
|
||||
Height int64 `json:"height"`
|
||||
Round int32 `json:"round"` // assume there will not be greater than 2_147_483_647 rounds
|
||||
BlockID BlockID `json:"block_id"` // zero if vote is nil.
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
ValidatorAddress Address `json:"validator_address"`
|
||||
ValidatorIndex int32 `json:"validator_index"`
|
||||
Signature []byte `json:"signature"`
|
||||
}
|
||||
|
||||
// CommitSig converts the Vote to a CommitSig.
|
||||
@@ -101,9 +101,9 @@ func (vote *Vote) String() string {
|
||||
|
||||
var typeString string
|
||||
switch vote.Type {
|
||||
case PrevoteType:
|
||||
case tmproto.PrevoteType:
|
||||
typeString = "Prevote"
|
||||
case PrecommitType:
|
||||
case tmproto.PrecommitType:
|
||||
typeString = "Precommit"
|
||||
default:
|
||||
panic("Unknown vote type")
|
||||
@@ -138,9 +138,11 @@ func (vote *Vote) ValidateBasic() error {
|
||||
if !IsVoteTypeValid(vote.Type) {
|
||||
return errors.New("invalid Type")
|
||||
}
|
||||
|
||||
if vote.Height < 0 {
|
||||
return errors.New("negative Height")
|
||||
}
|
||||
|
||||
if vote.Round < 0 {
|
||||
return errors.New("negative Round")
|
||||
}
|
||||
@@ -181,13 +183,13 @@ func (vote *Vote) ToProto() *tmproto.Vote {
|
||||
}
|
||||
|
||||
return &tmproto.Vote{
|
||||
Type: tmproto.SignedMsgType(vote.Type),
|
||||
Type: vote.Type,
|
||||
Height: vote.Height,
|
||||
Round: int64(vote.Round),
|
||||
Round: vote.Round,
|
||||
BlockID: vote.BlockID.ToProto(),
|
||||
Timestamp: vote.Timestamp,
|
||||
ValidatorAddress: vote.ValidatorAddress,
|
||||
ValidatorIndex: int64(vote.ValidatorIndex),
|
||||
ValidatorIndex: vote.ValidatorIndex,
|
||||
Signature: vote.Signature,
|
||||
}
|
||||
}
|
||||
@@ -205,13 +207,13 @@ func VoteFromProto(pv *tmproto.Vote) (*Vote, error) {
|
||||
}
|
||||
|
||||
vote := new(Vote)
|
||||
vote.Type = SignedMsgType(pv.Type)
|
||||
vote.Type = pv.Type
|
||||
vote.Height = pv.Height
|
||||
vote.Round = int(pv.Round)
|
||||
vote.Round = pv.Round
|
||||
vote.BlockID = *blockID
|
||||
vote.Timestamp = pv.Timestamp
|
||||
vote.ValidatorAddress = pv.ValidatorAddress
|
||||
vote.ValidatorIndex = int(pv.ValidatorIndex)
|
||||
vote.ValidatorIndex = pv.ValidatorIndex
|
||||
vote.Signature = pv.Signature
|
||||
|
||||
return vote, vote.ValidateBasic()
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bits"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -59,8 +60,8 @@ type P2PID string
|
||||
type VoteSet struct {
|
||||
chainID string
|
||||
height int64
|
||||
round int
|
||||
signedMsgType SignedMsgType
|
||||
round int32
|
||||
signedMsgType tmproto.SignedMsgType
|
||||
valSet *ValidatorSet
|
||||
|
||||
mtx sync.Mutex
|
||||
@@ -73,7 +74,8 @@ type VoteSet struct {
|
||||
}
|
||||
|
||||
// Constructs a new VoteSet struct used to accumulate votes for given height/round.
|
||||
func NewVoteSet(chainID string, height int64, round int, signedMsgType SignedMsgType, valSet *ValidatorSet) *VoteSet {
|
||||
func NewVoteSet(chainID string, height int64, round int32,
|
||||
signedMsgType tmproto.SignedMsgType, valSet *ValidatorSet) *VoteSet {
|
||||
if height == 0 {
|
||||
panic("Cannot make VoteSet for height == 0, doesn't make sense.")
|
||||
}
|
||||
@@ -105,7 +107,7 @@ func (voteSet *VoteSet) GetHeight() int64 {
|
||||
}
|
||||
|
||||
// Implements VoteSetReader.
|
||||
func (voteSet *VoteSet) GetRound() int {
|
||||
func (voteSet *VoteSet) GetRound() int32 {
|
||||
if voteSet == nil {
|
||||
return -1
|
||||
}
|
||||
@@ -213,7 +215,7 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
|
||||
}
|
||||
|
||||
// Returns (vote, true) if vote exists for valIndex and blockKey.
|
||||
func (voteSet *VoteSet) getVote(valIndex int, blockKey string) (vote *Vote, ok bool) {
|
||||
func (voteSet *VoteSet) getVote(valIndex int32, blockKey string) (vote *Vote, ok bool) {
|
||||
if existing := voteSet.votes[valIndex]; existing != nil && existing.BlockID.Key() == blockKey {
|
||||
return existing, true
|
||||
}
|
||||
@@ -242,13 +244,13 @@ func (voteSet *VoteSet) addVerifiedVote(
|
||||
// Replace vote if blockKey matches voteSet.maj23.
|
||||
if voteSet.maj23 != nil && voteSet.maj23.Key() == blockKey {
|
||||
voteSet.votes[valIndex] = vote
|
||||
voteSet.votesBitArray.SetIndex(valIndex, true)
|
||||
voteSet.votesBitArray.SetIndex(int(valIndex), true)
|
||||
}
|
||||
// Otherwise don't add it to voteSet.votes
|
||||
} else {
|
||||
// Add to voteSet.votes and incr .sum
|
||||
voteSet.votes[valIndex] = vote
|
||||
voteSet.votesBitArray.SetIndex(valIndex, true)
|
||||
voteSet.votesBitArray.SetIndex(int(valIndex), true)
|
||||
voteSet.sum += votingPower
|
||||
}
|
||||
|
||||
@@ -363,7 +365,7 @@ func (voteSet *VoteSet) BitArrayByBlockID(blockID BlockID) *bits.BitArray {
|
||||
|
||||
// NOTE: if validator has conflicting votes, returns "canonical" vote
|
||||
// Implements VoteSetReader.
|
||||
func (voteSet *VoteSet) GetByIndex(valIndex int) *Vote {
|
||||
func (voteSet *VoteSet) GetByIndex(valIndex int32) *Vote {
|
||||
if voteSet == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -399,7 +401,7 @@ func (voteSet *VoteSet) IsCommit() bool {
|
||||
if voteSet == nil {
|
||||
return false
|
||||
}
|
||||
if voteSet.signedMsgType != PrecommitType {
|
||||
if voteSet.signedMsgType != tmproto.PrecommitType {
|
||||
return false
|
||||
}
|
||||
voteSet.mtx.Lock()
|
||||
@@ -550,7 +552,7 @@ func (voteSet *VoteSet) sumTotalFrac() (int64, int64, float64) {
|
||||
// Panics if the vote type is not PrecommitType or if
|
||||
// there's no +2/3 votes for a single block.
|
||||
func (voteSet *VoteSet) MakeCommit() *Commit {
|
||||
if voteSet.signedMsgType != PrecommitType {
|
||||
if voteSet.signedMsgType != tmproto.PrecommitType {
|
||||
panic("Cannot MakeCommit() unless VoteSet.Type is PrecommitType")
|
||||
}
|
||||
voteSet.mtx.Lock()
|
||||
@@ -597,13 +599,13 @@ func newBlockVotes(peerMaj23 bool, numValidators int) *blockVotes {
|
||||
func (vs *blockVotes) addVerifiedVote(vote *Vote, votingPower int64) {
|
||||
valIndex := vote.ValidatorIndex
|
||||
if existing := vs.votes[valIndex]; existing == nil {
|
||||
vs.bitArray.SetIndex(valIndex, true)
|
||||
vs.bitArray.SetIndex(int(valIndex), true)
|
||||
vs.votes[valIndex] = vote
|
||||
vs.sum += votingPower
|
||||
}
|
||||
}
|
||||
|
||||
func (vs *blockVotes) getByIndex(index int) *Vote {
|
||||
func (vs *blockVotes) getByIndex(index int32) *Vote {
|
||||
if vs == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -615,10 +617,10 @@ func (vs *blockVotes) getByIndex(index int) *Vote {
|
||||
// Common interface between *consensus.VoteSet and types.Commit
|
||||
type VoteSetReader interface {
|
||||
GetHeight() int64
|
||||
GetRound() int
|
||||
GetRound() int32
|
||||
Type() byte
|
||||
Size() int
|
||||
BitArray() *bits.BitArray
|
||||
GetByIndex(int) *Vote
|
||||
GetByIndex(int32) *Vote
|
||||
IsCommit() bool
|
||||
}
|
||||
|
||||
@@ -9,14 +9,15 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
)
|
||||
|
||||
// NOTE: privValidators are in order
|
||||
func randVoteSet(
|
||||
height int64,
|
||||
round int,
|
||||
signedMsgType SignedMsgType,
|
||||
round int32,
|
||||
signedMsgType tmproto.SignedMsgType,
|
||||
numValidators int,
|
||||
votingPower int64,
|
||||
) (*VoteSet, *ValidatorSet, []PrivValidator) {
|
||||
@@ -25,7 +26,7 @@ func randVoteSet(
|
||||
}
|
||||
|
||||
// Convenience: Return new vote with different validator address/index
|
||||
func withValidator(vote *Vote, addr []byte, idx int) *Vote {
|
||||
func withValidator(vote *Vote, addr []byte, idx int32) *Vote {
|
||||
vote = vote.Copy()
|
||||
vote.ValidatorAddress = addr
|
||||
vote.ValidatorIndex = idx
|
||||
@@ -40,7 +41,7 @@ func withHeight(vote *Vote, height int64) *Vote {
|
||||
}
|
||||
|
||||
// Convenience: Return new vote with different round
|
||||
func withRound(vote *Vote, round int) *Vote {
|
||||
func withRound(vote *Vote, round int32) *Vote {
|
||||
vote = vote.Copy()
|
||||
vote.Round = round
|
||||
return vote
|
||||
@@ -49,7 +50,7 @@ func withRound(vote *Vote, round int) *Vote {
|
||||
// Convenience: Return new vote with different type
|
||||
func withType(vote *Vote, signedMsgType byte) *Vote {
|
||||
vote = vote.Copy()
|
||||
vote.Type = SignedMsgType(signedMsgType)
|
||||
vote.Type = tmproto.SignedMsgType(signedMsgType)
|
||||
return vote
|
||||
}
|
||||
|
||||
@@ -68,8 +69,8 @@ func withBlockPartsHeader(vote *Vote, blockPartsHeader PartSetHeader) *Vote {
|
||||
}
|
||||
|
||||
func TestAddVote(t *testing.T) {
|
||||
height, round := int64(1), 0
|
||||
voteSet, _, privValidators := randVoteSet(height, round, PrevoteType, 10, 1)
|
||||
height, round := int64(1), int32(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1)
|
||||
val0 := privValidators[0]
|
||||
|
||||
// t.Logf(">> %v", voteSet)
|
||||
@@ -94,7 +95,7 @@ func TestAddVote(t *testing.T) {
|
||||
ValidatorIndex: 0, // since privValidators are in order
|
||||
Height: height,
|
||||
Round: round,
|
||||
Type: PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
Timestamp: tmtime.Now(),
|
||||
BlockID: BlockID{nil, PartSetHeader{}},
|
||||
}
|
||||
@@ -116,20 +117,20 @@ func TestAddVote(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test2_3Majority(t *testing.T) {
|
||||
height, round := int64(1), 0
|
||||
voteSet, _, privValidators := randVoteSet(height, round, PrevoteType, 10, 1)
|
||||
height, round := int64(1), int32(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1)
|
||||
|
||||
voteProto := &Vote{
|
||||
ValidatorAddress: nil, // NOTE: must fill in
|
||||
ValidatorIndex: -1, // NOTE: must fill in
|
||||
Height: height,
|
||||
Round: round,
|
||||
Type: PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
Timestamp: tmtime.Now(),
|
||||
BlockID: BlockID{nil, PartSetHeader{}},
|
||||
}
|
||||
// 6 out of 10 voted for nil.
|
||||
for i := 0; i < 6; i++ {
|
||||
for i := int32(0); i < 6; i++ {
|
||||
pubKey, err := privValidators[i].GetPubKey()
|
||||
require.NoError(t, err)
|
||||
addr := pubKey.Address()
|
||||
@@ -178,11 +179,11 @@ func Test2_3Majority(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test2_3MajorityRedux(t *testing.T) {
|
||||
height, round := int64(1), 0
|
||||
voteSet, _, privValidators := randVoteSet(height, round, PrevoteType, 100, 1)
|
||||
height, round := int64(1), int32(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 100, 1)
|
||||
|
||||
blockHash := crypto.CRandBytes(32)
|
||||
blockPartsTotal := 123
|
||||
blockPartsTotal := uint32(123)
|
||||
blockPartsHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)}
|
||||
|
||||
voteProto := &Vote{
|
||||
@@ -191,12 +192,12 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
Height: height,
|
||||
Round: round,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: BlockID{blockHash, blockPartsHeader},
|
||||
}
|
||||
|
||||
// 66 out of 100 voted for nil.
|
||||
for i := 0; i < 66; i++ {
|
||||
for i := int32(0); i < 66; i++ {
|
||||
pubKey, err := privValidators[i].GetPubKey()
|
||||
require.NoError(t, err)
|
||||
addr := pubKey.Address()
|
||||
@@ -295,8 +296,8 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBadVotes(t *testing.T) {
|
||||
height, round := int64(1), 0
|
||||
voteSet, _, privValidators := randVoteSet(height, round, PrevoteType, 10, 1)
|
||||
height, round := int64(1), int32(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1)
|
||||
|
||||
voteProto := &Vote{
|
||||
ValidatorAddress: nil,
|
||||
@@ -304,7 +305,7 @@ func TestBadVotes(t *testing.T) {
|
||||
Height: height,
|
||||
Round: round,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: BlockID{nil, PartSetHeader{}},
|
||||
}
|
||||
|
||||
@@ -362,7 +363,7 @@ func TestBadVotes(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
addr := pubKey.Address()
|
||||
vote := withValidator(voteProto, addr, 3)
|
||||
added, err := signAddVote(privValidators[3], withType(vote, byte(PrecommitType)), voteSet)
|
||||
added, err := signAddVote(privValidators[3], withType(vote, byte(tmproto.PrecommitType)), voteSet)
|
||||
if added || err == nil {
|
||||
t.Errorf("expected VoteSet.Add to fail, wrong type")
|
||||
}
|
||||
@@ -370,8 +371,8 @@ func TestBadVotes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConflicts(t *testing.T) {
|
||||
height, round := int64(1), 0
|
||||
voteSet, _, privValidators := randVoteSet(height, round, PrevoteType, 4, 1)
|
||||
height, round := int64(1), int32(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 4, 1)
|
||||
blockHash1 := tmrand.Bytes(32)
|
||||
blockHash2 := tmrand.Bytes(32)
|
||||
|
||||
@@ -381,7 +382,7 @@ func TestConflicts(t *testing.T) {
|
||||
Height: height,
|
||||
Round: round,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: BlockID{nil, PartSetHeader{}},
|
||||
}
|
||||
|
||||
@@ -513,8 +514,8 @@ func TestConflicts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMakeCommit(t *testing.T) {
|
||||
height, round := int64(1), 0
|
||||
voteSet, _, privValidators := randVoteSet(height, round, PrecommitType, 10, 1)
|
||||
height, round := int64(1), int32(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrecommitType, 10, 1)
|
||||
blockHash, blockPartsHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)}
|
||||
|
||||
voteProto := &Vote{
|
||||
@@ -523,12 +524,12 @@ func TestMakeCommit(t *testing.T) {
|
||||
Height: height,
|
||||
Round: round,
|
||||
Timestamp: tmtime.Now(),
|
||||
Type: PrecommitType,
|
||||
Type: tmproto.PrecommitType,
|
||||
BlockID: BlockID{blockHash, blockPartsHeader},
|
||||
}
|
||||
|
||||
// 6 out of 10 voted for some block.
|
||||
for i := 0; i < 6; i++ {
|
||||
for i := int32(0); i < 6; i++ {
|
||||
pv, err := privValidators[i].GetPubKey()
|
||||
assert.NoError(t, err)
|
||||
addr := pv.Address()
|
||||
@@ -598,8 +599,8 @@ func TestMakeCommit(t *testing.T) {
|
||||
|
||||
func buildVoteSet(
|
||||
height int64,
|
||||
round, nonVotes, nonNilVotes, nilVotes int,
|
||||
voteType SignedMsgType) (*VoteSet, *ValidatorSet, []PrivValidator, BlockID) {
|
||||
round int32, nonVotes, nonNilVotes, nilVotes int,
|
||||
voteType tmproto.SignedMsgType) (*VoteSet, *ValidatorSet, []PrivValidator, BlockID) {
|
||||
valSize := nonVotes + nilVotes + nonNilVotes
|
||||
voteSet, valSet, privValidators := randVoteSet(height, round, voteType, valSize, 1)
|
||||
blockID := makeBlockIDRandom()
|
||||
@@ -615,13 +616,13 @@ func buildVoteSet(
|
||||
for i := 0; i < nonNilVotes; i++ {
|
||||
pubKey, _ := privValidators[i].GetPubKey()
|
||||
addr := pubKey.Address()
|
||||
vote := withValidator(voteProto, addr, i)
|
||||
vote := withValidator(voteProto, addr, int32(i))
|
||||
_, _ = signAddVote(privValidators[i], vote, voteSet)
|
||||
}
|
||||
for i := nonNilVotes; i < nonNilVotes+nilVotes; i++ {
|
||||
pubKey, _ := privValidators[i].GetPubKey()
|
||||
addr := pubKey.Address()
|
||||
vote := withValidator(voteProto, addr, i)
|
||||
vote := withValidator(voteProto, addr, int32(i))
|
||||
_, _ = signAddVote(privValidators[i], withBlockHash(vote, nil), voteSet)
|
||||
}
|
||||
return voteSet, valSet, privValidators, blockID
|
||||
|
||||
@@ -11,14 +11,15 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmproto "github.com/tendermint/tendermint/proto/types"
|
||||
)
|
||||
|
||||
func examplePrevote() *Vote {
|
||||
return exampleVote(byte(PrevoteType))
|
||||
return exampleVote(byte(tmproto.PrevoteType))
|
||||
}
|
||||
|
||||
func examplePrecommit() *Vote {
|
||||
return exampleVote(byte(PrecommitType))
|
||||
return exampleVote(byte(tmproto.PrecommitType))
|
||||
}
|
||||
|
||||
func exampleVote(t byte) *Vote {
|
||||
@@ -28,7 +29,7 @@ func exampleVote(t byte) *Vote {
|
||||
}
|
||||
|
||||
return &Vote{
|
||||
Type: SignedMsgType(t),
|
||||
Type: tmproto.SignedMsgType(t),
|
||||
Height: 12345,
|
||||
Round: 2,
|
||||
Timestamp: stamp,
|
||||
@@ -68,7 +69,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) {
|
||||
},
|
||||
// with proper (fixed size) height and round (PreCommit):
|
||||
1: {
|
||||
"", &Vote{Height: 1, Round: 1, Type: PrecommitType},
|
||||
"", &Vote{Height: 1, Round: 1, Type: tmproto.PrecommitType},
|
||||
[]byte{
|
||||
0x21, // length
|
||||
0x8, // (field_number << 3) | wire_type
|
||||
@@ -83,7 +84,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) {
|
||||
},
|
||||
// with proper (fixed size) height and round (PreVote):
|
||||
2: {
|
||||
"", &Vote{Height: 1, Round: 1, Type: PrevoteType},
|
||||
"", &Vote{Height: 1, Round: 1, Type: tmproto.PrevoteType},
|
||||
[]byte{
|
||||
0x21, // length
|
||||
0x8, // (field_number << 3) | wire_type
|
||||
@@ -174,12 +175,12 @@ func TestVoteVerifySignature(t *testing.T) {
|
||||
func TestIsVoteTypeValid(t *testing.T) {
|
||||
tc := []struct {
|
||||
name string
|
||||
in SignedMsgType
|
||||
in tmproto.SignedMsgType
|
||||
out bool
|
||||
}{
|
||||
{"Prevote", PrevoteType, true},
|
||||
{"Precommit", PrecommitType, true},
|
||||
{"InvalidType", SignedMsgType(0x3), false},
|
||||
{"Prevote", tmproto.PrevoteType, true},
|
||||
{"Precommit", tmproto.PrecommitType, true},
|
||||
{"InvalidType", tmproto.SignedMsgType(0x3), false},
|
||||
}
|
||||
|
||||
for _, tt := range tc {
|
||||
@@ -218,15 +219,15 @@ func TestMaxVoteBytes(t *testing.T) {
|
||||
|
||||
vote := &Vote{
|
||||
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
|
||||
ValidatorIndex: math.MaxInt64,
|
||||
ValidatorIndex: math.MaxInt32,
|
||||
Height: math.MaxInt64,
|
||||
Round: math.MaxInt64,
|
||||
Round: math.MaxInt32,
|
||||
Timestamp: timestamp,
|
||||
Type: PrevoteType,
|
||||
Type: tmproto.PrevoteType,
|
||||
BlockID: BlockID{
|
||||
Hash: tmhash.Sum([]byte("blockID_hash")),
|
||||
PartsHeader: PartSetHeader{
|
||||
Total: math.MaxInt64,
|
||||
Total: math.MaxInt32,
|
||||
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user