diff --git a/consensus/types/reactor.go b/consensus/types/peer_round_state.go similarity index 100% rename from consensus/types/reactor.go rename to consensus/types/peer_round_state.go diff --git a/consensus/types/state.go b/consensus/types/round_state.go similarity index 100% rename from consensus/types/state.go rename to consensus/types/round_state.go diff --git a/consensus/types/round_state_test.go b/consensus/types/round_state_test.go new file mode 100644 index 000000000..dc88c3a13 --- /dev/null +++ b/consensus/types/round_state_test.go @@ -0,0 +1,95 @@ +package types + +import ( + "testing" + "time" + + "github.com/tendermint/go-amino" + "github.com/tendermint/go-crypto" + "github.com/tendermint/tendermint/types" + cmn "github.com/tendermint/tmlibs/common" +) + +func BenchmarkRoundStateDeepCopy(b *testing.B) { + b.StopTimer() + + // Random validators + nval, ntxs := 100, 100 + vset, _ := types.RandValidatorSet(nval, 1) + precommits := make([]*types.Vote, nval) + blockID := types.BlockID{ + Hash: cmn.RandBytes(20), + PartsHeader: types.PartSetHeader{ + Hash: cmn.RandBytes(20), + }, + } + sig := crypto.SignatureEd25519{} + for i := 0; i < nval; i++ { + precommits[i] = &types.Vote{ + ValidatorAddress: types.Address(cmn.RandBytes(20)), + Timestamp: time.Now(), + BlockID: blockID, + Signature: sig, + } + } + txs := make([]types.Tx, ntxs) + for i := 0; i < ntxs; i++ { + txs[i] = cmn.RandBytes(100) + } + // Random block + block := &types.Block{ + Header: &types.Header{ + ChainID: cmn.RandStr(12), + Time: time.Now(), + LastBlockID: blockID, + LastCommitHash: cmn.RandBytes(20), + DataHash: cmn.RandBytes(20), + ValidatorsHash: cmn.RandBytes(20), + ConsensusHash: cmn.RandBytes(20), + AppHash: cmn.RandBytes(20), + LastResultsHash: cmn.RandBytes(20), + EvidenceHash: cmn.RandBytes(20), + }, + Data: &types.Data{ + Txs: txs, + }, + Evidence: types.EvidenceData{}, + LastCommit: &types.Commit{ + BlockID: blockID, + Precommits: precommits, + }, + } + parts := block.MakePartSet(4096) + // Random Proposal + proposal := &types.Proposal{ + Timestamp: time.Now(), + BlockPartsHeader: types.PartSetHeader{ + Hash: cmn.RandBytes(20), + }, + POLBlockID: blockID, + Signature: sig, + } + // Random HeightVoteSet + // TODO: hvs := + + rs := &RoundState{ + StartTime: time.Now(), + CommitTime: time.Now(), + Validators: vset, + Proposal: proposal, + ProposalBlock: block, + ProposalBlockParts: parts, + LockedBlock: block, + LockedBlockParts: parts, + ValidBlock: block, + ValidBlockParts: parts, + Votes: nil, // TODO + LastCommit: nil, // TODO + LastValidators: vset, + } + b.StartTimer() + + for i := 0; i < b.N; i++ { + amino.DeepCopy(rs) + } +}