You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.6 KiB

  1. package factory
  2. import (
  3. "time"
  4. "github.com/tendermint/tendermint/internal/test/factory"
  5. sm "github.com/tendermint/tendermint/state"
  6. "github.com/tendermint/tendermint/types"
  7. )
  8. func MakeBlocks(n int, state *sm.State, privVal types.PrivValidator) []*types.Block {
  9. blocks := make([]*types.Block, 0)
  10. var (
  11. prevBlock *types.Block
  12. prevBlockMeta *types.BlockMeta
  13. )
  14. appHeight := byte(0x01)
  15. for i := 0; i < n; i++ {
  16. height := int64(i + 1)
  17. block, parts := makeBlockAndPartSet(*state, prevBlock, prevBlockMeta, privVal, height)
  18. blocks = append(blocks, block)
  19. prevBlock = block
  20. prevBlockMeta = types.NewBlockMeta(block, parts)
  21. // update state
  22. state.AppHash = []byte{appHeight}
  23. appHeight++
  24. state.LastBlockHeight = height
  25. }
  26. return blocks
  27. }
  28. func MakeBlock(state sm.State, height int64, c *types.Commit) *types.Block {
  29. block, _ := state.MakeBlock(
  30. height,
  31. factory.MakeTenTxs(state.LastBlockHeight),
  32. c,
  33. nil,
  34. state.Validators.GetProposer().Address,
  35. )
  36. return block
  37. }
  38. func makeBlockAndPartSet(state sm.State, lastBlock *types.Block, lastBlockMeta *types.BlockMeta,
  39. privVal types.PrivValidator, height int64) (*types.Block, *types.PartSet) {
  40. lastCommit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
  41. if height > 1 {
  42. vote, _ := factory.MakeVote(
  43. privVal,
  44. lastBlock.Header.ChainID,
  45. 1, lastBlock.Header.Height, 0, 2,
  46. lastBlockMeta.BlockID,
  47. time.Now())
  48. lastCommit = types.NewCommit(vote.Height, vote.Round,
  49. lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
  50. }
  51. return state.MakeBlock(height, []types.Tx{}, lastCommit, nil, state.Validators.GetProposer().Address)
  52. }