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.

655 lines
20 KiB

8 years ago
8 years ago
8 years ago
9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "io"
  7. "io/ioutil"
  8. "os"
  9. "path"
  10. "strings"
  11. "testing"
  12. "time"
  13. "github.com/tendermint/abci/example/dummy"
  14. "github.com/tendermint/go-crypto"
  15. "github.com/tendermint/go-wire"
  16. cmn "github.com/tendermint/tmlibs/common"
  17. dbm "github.com/tendermint/tmlibs/db"
  18. cfg "github.com/tendermint/tendermint/config"
  19. "github.com/tendermint/tendermint/proxy"
  20. sm "github.com/tendermint/tendermint/state"
  21. "github.com/tendermint/tendermint/types"
  22. )
  23. func init() {
  24. config = ResetConfig("consensus_replay_test")
  25. }
  26. // These tests ensure we can always recover from failure at any part of the consensus process.
  27. // There are two general failure scenarios: failure during consensus, and failure while applying the block.
  28. // Only the latter interacts with the app and store,
  29. // but the former has to deal with restrictions on re-use of priv_validator keys.
  30. // The `WAL Tests` are for failures during the consensus;
  31. // the `Handshake Tests` are for failures in applying the block.
  32. // With the help of the WAL, we can recover from it all!
  33. // NOTE: Files in this dir are generated by running the `build.sh` therein.
  34. // It's a simple way to generate wals for a single block, or multiple blocks, with random transactions,
  35. // and different part sizes. The output is not deterministic, and the stepChanges may need to be adjusted
  36. // after running it (eg. sometimes small_block2 will have 5 block parts, sometimes 6).
  37. // It should only have to be re-run if there is some breaking change to the consensus data structures (eg. blocks, votes)
  38. // or to the behaviour of the app (eg. computes app hash differently)
  39. var data_dir = path.Join(cmn.GoPath, "src/github.com/tendermint/tendermint/consensus", "test_data")
  40. //------------------------------------------------------------------------------------------
  41. // WAL Tests
  42. // TODO: It would be better to verify explicitly which states we can recover from without the wal
  43. // and which ones we need the wal for - then we'd also be able to only flush the
  44. // wal writer when we need to, instead of with every message.
  45. // the priv validator changes step at these lines for a block with 1 val and 1 part
  46. var baseStepChanges = []int{3, 6, 8}
  47. // test recovery from each line in each testCase
  48. var testCases = []*testCase{
  49. newTestCase("empty_block", baseStepChanges), // empty block (has 1 block part)
  50. newTestCase("small_block1", baseStepChanges), // small block with txs in 1 block part
  51. newTestCase("small_block2", []int{3, 11, 13}), // small block with txs across 6 smaller block parts
  52. }
  53. type testCase struct {
  54. name string
  55. log string //full cs wal
  56. stepMap map[int]int8 // map lines of log to privval step
  57. proposeLine int
  58. prevoteLine int
  59. precommitLine int
  60. }
  61. func newTestCase(name string, stepChanges []int) *testCase {
  62. if len(stepChanges) != 3 {
  63. panic(cmn.Fmt("a full wal has 3 step changes! Got array %v", stepChanges))
  64. }
  65. return &testCase{
  66. name: name,
  67. log: readWAL(path.Join(data_dir, name+".cswal")),
  68. stepMap: newMapFromChanges(stepChanges),
  69. proposeLine: stepChanges[0],
  70. prevoteLine: stepChanges[1],
  71. precommitLine: stepChanges[2],
  72. }
  73. }
  74. func newMapFromChanges(changes []int) map[int]int8 {
  75. changes = append(changes, changes[2]+1) // so we add the last step change to the map
  76. m := make(map[int]int8)
  77. var count int
  78. for changeNum, nextChange := range changes {
  79. for ; count < nextChange; count++ {
  80. m[count] = int8(changeNum)
  81. }
  82. }
  83. return m
  84. }
  85. func readWAL(p string) string {
  86. b, err := ioutil.ReadFile(p)
  87. if err != nil {
  88. panic(err)
  89. }
  90. return string(b)
  91. }
  92. func writeWAL(walMsgs string) string {
  93. tempDir := os.TempDir()
  94. walDir := path.Join(tempDir, "/wal"+cmn.RandStr(12))
  95. walFile := path.Join(walDir, "wal")
  96. // Create WAL directory
  97. err := cmn.EnsureDir(walDir, 0700)
  98. if err != nil {
  99. panic(err)
  100. }
  101. // Write the needed WAL to file
  102. err = cmn.WriteFile(walFile, []byte(walMsgs), 0600)
  103. if err != nil {
  104. panic(err)
  105. }
  106. return walFile
  107. }
  108. func waitForBlock(newBlockCh chan interface{}, thisCase *testCase, i int) {
  109. after := time.After(time.Second * 10)
  110. select {
  111. case <-newBlockCh:
  112. case <-after:
  113. panic(cmn.Fmt("Timed out waiting for new block for case '%s' line %d", thisCase.name, i))
  114. }
  115. }
  116. func runReplayTest(t *testing.T, cs *ConsensusState, walFile string, newBlockCh chan interface{},
  117. thisCase *testCase, i int) {
  118. cs.config.SetWalFile(walFile)
  119. started, err := cs.Start()
  120. if err != nil {
  121. t.Fatalf("Cannot start consensus: %v", err)
  122. }
  123. if !started {
  124. t.Error("Consensus did not start")
  125. }
  126. // Wait to make a new block.
  127. // This is just a signal that we haven't halted; its not something contained in the WAL itself.
  128. // Assuming the consensus state is running, replay of any WAL, including the empty one,
  129. // should eventually be followed by a new block, or else something is wrong
  130. waitForBlock(newBlockCh, thisCase, i)
  131. cs.evsw.Stop()
  132. cs.Stop()
  133. LOOP:
  134. for {
  135. select {
  136. case <-newBlockCh:
  137. default:
  138. break LOOP
  139. }
  140. }
  141. cs.Wait()
  142. }
  143. func toPV(pv PrivValidator) *types.PrivValidator {
  144. return pv.(*types.PrivValidator)
  145. }
  146. func setupReplayTest(thisCase *testCase, nLines int, crashAfter bool) (*ConsensusState, chan interface{}, string, string) {
  147. fmt.Println("-------------------------------------")
  148. log.Notice(cmn.Fmt("Starting replay test %v (of %d lines of WAL). Crash after = %v", thisCase.name, nLines, crashAfter))
  149. lineStep := nLines
  150. if crashAfter {
  151. lineStep -= 1
  152. }
  153. split := strings.Split(thisCase.log, "\n")
  154. lastMsg := split[nLines]
  155. // we write those lines up to (not including) one with the signature
  156. walFile := writeWAL(strings.Join(split[:nLines], "\n") + "\n")
  157. cs := fixedConsensusStateDummy()
  158. // set the last step according to when we crashed vs the wal
  159. toPV(cs.privValidator).LastHeight = 1 // first block
  160. toPV(cs.privValidator).LastStep = thisCase.stepMap[lineStep]
  161. log.Warn("setupReplayTest", "LastStep", toPV(cs.privValidator).LastStep)
  162. newBlockCh := subscribeToEvent(cs.evsw, "tester", types.EventStringNewBlock(), 1)
  163. return cs, newBlockCh, lastMsg, walFile
  164. }
  165. func readTimedWALMessage(t *testing.T, walMsg string) TimedWALMessage {
  166. var err error
  167. var msg TimedWALMessage
  168. wire.ReadJSON(&msg, []byte(walMsg), &err)
  169. if err != nil {
  170. t.Fatalf("Error reading json data: %v", err)
  171. }
  172. return msg
  173. }
  174. //-----------------------------------------------
  175. // Test the log at every iteration, and set the privVal last step
  176. // as if the log was written after signing, before the crash
  177. func TestWALCrashAfterWrite(t *testing.T) {
  178. for _, thisCase := range testCases {
  179. split := strings.Split(thisCase.log, "\n")
  180. for i := 0; i < len(split)-1; i++ {
  181. cs, newBlockCh, _, walFile := setupReplayTest(thisCase, i+1, true)
  182. runReplayTest(t, cs, walFile, newBlockCh, thisCase, i+1)
  183. }
  184. }
  185. }
  186. //-----------------------------------------------
  187. // Test the log as if we crashed after signing but before writing.
  188. // This relies on privValidator.LastSignature being set
  189. func TestWALCrashBeforeWritePropose(t *testing.T) {
  190. for _, thisCase := range testCases {
  191. lineNum := thisCase.proposeLine
  192. // setup replay test where last message is a proposal
  193. cs, newBlockCh, proposalMsg, walFile := setupReplayTest(thisCase, lineNum, false)
  194. msg := readTimedWALMessage(t, proposalMsg)
  195. proposal := msg.Msg.(msgInfo).Msg.(*ProposalMessage)
  196. // Set LastSig
  197. toPV(cs.privValidator).LastSignBytes = types.SignBytes(cs.state.ChainID, proposal.Proposal)
  198. toPV(cs.privValidator).LastSignature = proposal.Proposal.Signature
  199. runReplayTest(t, cs, walFile, newBlockCh, thisCase, lineNum)
  200. }
  201. }
  202. func TestWALCrashBeforeWritePrevote(t *testing.T) {
  203. for _, thisCase := range testCases {
  204. testReplayCrashBeforeWriteVote(t, thisCase, thisCase.prevoteLine, types.EventStringCompleteProposal())
  205. }
  206. }
  207. func TestWALCrashBeforeWritePrecommit(t *testing.T) {
  208. for _, thisCase := range testCases {
  209. testReplayCrashBeforeWriteVote(t, thisCase, thisCase.precommitLine, types.EventStringPolka())
  210. }
  211. }
  212. func testReplayCrashBeforeWriteVote(t *testing.T, thisCase *testCase, lineNum int, eventString string) {
  213. // setup replay test where last message is a vote
  214. cs, newBlockCh, voteMsg, walFile := setupReplayTest(thisCase, lineNum, false)
  215. types.AddListenerForEvent(cs.evsw, "tester", eventString, func(data types.TMEventData) {
  216. msg := readTimedWALMessage(t, voteMsg)
  217. vote := msg.Msg.(msgInfo).Msg.(*VoteMessage)
  218. // Set LastSig
  219. toPV(cs.privValidator).LastSignBytes = types.SignBytes(cs.state.ChainID, vote.Vote)
  220. toPV(cs.privValidator).LastSignature = vote.Vote.Signature
  221. })
  222. runReplayTest(t, cs, walFile, newBlockCh, thisCase, lineNum)
  223. }
  224. //------------------------------------------------------------------------------------------
  225. // Handshake Tests
  226. var (
  227. NUM_BLOCKS = 6 // number of blocks in the test_data/many_blocks.cswal
  228. mempool = types.MockMempool{}
  229. testPartSize int
  230. )
  231. //---------------------------------------
  232. // Test handshake/replay
  233. // 0 - all synced up
  234. // 1 - saved block but app and state are behind
  235. // 2 - save block and committed but state is behind
  236. var modes = []uint{0, 1, 2}
  237. // Sync from scratch
  238. func TestHandshakeReplayAll(t *testing.T) {
  239. for _, m := range modes {
  240. testHandshakeReplay(t, 0, m)
  241. }
  242. }
  243. // Sync many, not from scratch
  244. func TestHandshakeReplaySome(t *testing.T) {
  245. for _, m := range modes {
  246. testHandshakeReplay(t, 1, m)
  247. }
  248. }
  249. // Sync from lagging by one
  250. func TestHandshakeReplayOne(t *testing.T) {
  251. for _, m := range modes {
  252. testHandshakeReplay(t, NUM_BLOCKS-1, m)
  253. }
  254. }
  255. // Sync from caught up
  256. func TestHandshakeReplayNone(t *testing.T) {
  257. for _, m := range modes {
  258. testHandshakeReplay(t, NUM_BLOCKS, m)
  259. }
  260. }
  261. // Make some blocks. Start a fresh app and apply nBlocks blocks. Then restart the app and sync it up with the remaining blocks
  262. func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
  263. config := ResetConfig("proxy_test_")
  264. // copy the many_blocks file
  265. walBody, err := cmn.ReadFile(path.Join(data_dir, "many_blocks.cswal"))
  266. if err != nil {
  267. t.Fatal(err)
  268. }
  269. walFile := writeWAL(string(walBody))
  270. config.Consensus.SetWalFile(walFile)
  271. privVal := types.LoadPrivValidator(config.PrivValidatorFile())
  272. testPartSize = config.Consensus.BlockPartSize
  273. wal, err := NewWAL(walFile, false)
  274. if err != nil {
  275. t.Fatal(err)
  276. }
  277. chain, commits, err := makeBlockchainFromWAL(wal)
  278. if err != nil {
  279. t.Fatalf(err.Error())
  280. }
  281. state, store := stateAndStore(config, privVal.PubKey)
  282. store.chain = chain
  283. store.commits = commits
  284. // run the chain through state.ApplyBlock to build up the tendermint state
  285. latestAppHash := buildTMStateFromChain(config, state, chain, mode)
  286. // make a new client creator
  287. dummyApp := dummy.NewPersistentDummyApplication(path.Join(config.DBDir(), "2"))
  288. clientCreator2 := proxy.NewLocalClientCreator(dummyApp)
  289. if nBlocks > 0 {
  290. // run nBlocks against a new client to build up the app state.
  291. // use a throwaway tendermint state
  292. proxyApp := proxy.NewAppConns(clientCreator2, nil)
  293. state, _ := stateAndStore(config, privVal.PubKey)
  294. buildAppStateFromChain(proxyApp, state, chain, nBlocks, mode)
  295. }
  296. // now start the app using the handshake - it should sync
  297. handshaker := NewHandshaker(state, store)
  298. proxyApp := proxy.NewAppConns(clientCreator2, handshaker)
  299. if _, err := proxyApp.Start(); err != nil {
  300. t.Fatalf("Error starting proxy app connections: %v", err)
  301. }
  302. // get the latest app hash from the app
  303. res, err := proxyApp.Query().InfoSync()
  304. if err != nil {
  305. t.Fatal(err)
  306. }
  307. // the app hash should be synced up
  308. if !bytes.Equal(latestAppHash, res.LastBlockAppHash) {
  309. t.Fatalf("Expected app hashes to match after handshake/replay. got %X, expected %X", res.LastBlockAppHash, latestAppHash)
  310. }
  311. expectedBlocksToSync := NUM_BLOCKS - nBlocks
  312. if nBlocks == NUM_BLOCKS && mode > 0 {
  313. expectedBlocksToSync += 1
  314. } else if nBlocks > 0 && mode == 1 {
  315. expectedBlocksToSync += 1
  316. }
  317. if handshaker.NBlocks() != expectedBlocksToSync {
  318. t.Fatalf("Expected handshake to sync %d blocks, got %d", expectedBlocksToSync, handshaker.NBlocks())
  319. }
  320. }
  321. func applyBlock(st *sm.State, blk *types.Block, proxyApp proxy.AppConns) {
  322. err := st.ApplyBlock(nil, proxyApp.Consensus(), blk, blk.MakePartSet(testPartSize).Header(), mempool)
  323. if err != nil {
  324. panic(err)
  325. }
  326. }
  327. func buildAppStateFromChain(proxyApp proxy.AppConns,
  328. state *sm.State, chain []*types.Block, nBlocks int, mode uint) {
  329. // start a new app without handshake, play nBlocks blocks
  330. if _, err := proxyApp.Start(); err != nil {
  331. panic(err)
  332. }
  333. validators := types.TM2PB.Validators(state.Validators)
  334. proxyApp.Consensus().InitChainSync(validators)
  335. defer proxyApp.Stop()
  336. switch mode {
  337. case 0:
  338. for i := 0; i < nBlocks; i++ {
  339. block := chain[i]
  340. applyBlock(state, block, proxyApp)
  341. }
  342. case 1, 2:
  343. for i := 0; i < nBlocks-1; i++ {
  344. block := chain[i]
  345. applyBlock(state, block, proxyApp)
  346. }
  347. if mode == 2 {
  348. // update the dummy height and apphash
  349. // as if we ran commit but not
  350. applyBlock(state, chain[nBlocks-1], proxyApp)
  351. }
  352. }
  353. }
  354. func buildTMStateFromChain(config *cfg.Config, state *sm.State, chain []*types.Block, mode uint) []byte {
  355. // run the whole chain against this client to build up the tendermint state
  356. clientCreator := proxy.NewLocalClientCreator(dummy.NewPersistentDummyApplication(path.Join(config.DBDir(), "1")))
  357. proxyApp := proxy.NewAppConns(clientCreator, nil) // sm.NewHandshaker(config, state, store, ReplayLastBlock))
  358. if _, err := proxyApp.Start(); err != nil {
  359. panic(err)
  360. }
  361. defer proxyApp.Stop()
  362. validators := types.TM2PB.Validators(state.Validators)
  363. proxyApp.Consensus().InitChainSync(validators)
  364. var latestAppHash []byte
  365. switch mode {
  366. case 0:
  367. // sync right up
  368. for _, block := range chain {
  369. applyBlock(state, block, proxyApp)
  370. }
  371. latestAppHash = state.AppHash
  372. case 1, 2:
  373. // sync up to the penultimate as if we stored the block.
  374. // whether we commit or not depends on the appHash
  375. for _, block := range chain[:len(chain)-1] {
  376. applyBlock(state, block, proxyApp)
  377. }
  378. // apply the final block to a state copy so we can
  379. // get the right next appHash but keep the state back
  380. stateCopy := state.Copy()
  381. applyBlock(stateCopy, chain[len(chain)-1], proxyApp)
  382. latestAppHash = stateCopy.AppHash
  383. }
  384. return latestAppHash
  385. }
  386. //--------------------------
  387. // utils for making blocks
  388. func makeBlockchainFromWAL(wal *WAL) ([]*types.Block, []*types.Commit, error) {
  389. // Search for height marker
  390. gr, found, err := wal.group.Search("#ENDHEIGHT: ", makeHeightSearchFunc(0))
  391. if err != nil {
  392. return nil, nil, err
  393. }
  394. if !found {
  395. return nil, nil, errors.New(cmn.Fmt("WAL does not contain height %d.", 1))
  396. }
  397. defer gr.Close()
  398. log.Notice("Build a blockchain by reading from the WAL")
  399. var blockParts *types.PartSet
  400. var blocks []*types.Block
  401. var commits []*types.Commit
  402. for {
  403. line, err := gr.ReadLine()
  404. if err != nil {
  405. if err == io.EOF {
  406. break
  407. } else {
  408. return nil, nil, err
  409. }
  410. }
  411. piece, err := readPieceFromWAL([]byte(line))
  412. if err != nil {
  413. return nil, nil, err
  414. }
  415. if piece == nil {
  416. continue
  417. }
  418. switch p := piece.(type) {
  419. case *types.PartSetHeader:
  420. // if its not the first one, we have a full block
  421. if blockParts != nil {
  422. var n int
  423. block := wire.ReadBinary(&types.Block{}, blockParts.GetReader(), types.MaxBlockSize, &n, &err).(*types.Block)
  424. blocks = append(blocks, block)
  425. }
  426. blockParts = types.NewPartSetFromHeader(*p)
  427. case *types.Part:
  428. _, err := blockParts.AddPart(p, false)
  429. if err != nil {
  430. return nil, nil, err
  431. }
  432. case *types.Vote:
  433. if p.Type == types.VoteTypePrecommit {
  434. commit := &types.Commit{
  435. BlockID: p.BlockID,
  436. Precommits: []*types.Vote{p},
  437. }
  438. commits = append(commits, commit)
  439. }
  440. }
  441. }
  442. // grab the last block too
  443. var n int
  444. block := wire.ReadBinary(&types.Block{}, blockParts.GetReader(), types.MaxBlockSize, &n, &err).(*types.Block)
  445. blocks = append(blocks, block)
  446. return blocks, commits, nil
  447. }
  448. func readPieceFromWAL(msgBytes []byte) (interface{}, error) {
  449. // Skip over empty and meta lines
  450. if len(msgBytes) == 0 || msgBytes[0] == '#' {
  451. return nil, nil
  452. }
  453. var err error
  454. var msg TimedWALMessage
  455. wire.ReadJSON(&msg, msgBytes, &err)
  456. if err != nil {
  457. fmt.Println("MsgBytes:", msgBytes, string(msgBytes))
  458. return nil, fmt.Errorf("Error reading json data: %v", err)
  459. }
  460. // for logging
  461. switch m := msg.Msg.(type) {
  462. case msgInfo:
  463. switch msg := m.Msg.(type) {
  464. case *ProposalMessage:
  465. return &msg.Proposal.BlockPartsHeader, nil
  466. case *BlockPartMessage:
  467. return msg.Part, nil
  468. case *VoteMessage:
  469. return msg.Vote, nil
  470. }
  471. }
  472. return nil, nil
  473. }
  474. // make some bogus txs
  475. func txsFunc(blockNum int) (txs []types.Tx) {
  476. for i := 0; i < 10; i++ {
  477. txs = append(txs, types.Tx([]byte{byte(blockNum), byte(i)}))
  478. }
  479. return txs
  480. }
  481. // sign a commit vote
  482. func signCommit(chainID string, privVal *types.PrivValidator, height, round int, hash []byte, header types.PartSetHeader) *types.Vote {
  483. vote := &types.Vote{
  484. ValidatorIndex: 0,
  485. ValidatorAddress: privVal.Address,
  486. Height: height,
  487. Round: round,
  488. Type: types.VoteTypePrecommit,
  489. BlockID: types.BlockID{hash, header},
  490. }
  491. sig := privVal.Sign(types.SignBytes(chainID, vote))
  492. vote.Signature = sig
  493. return vote
  494. }
  495. // make a blockchain with one validator
  496. func makeBlockchain(t *testing.T, chainID string, nBlocks int, privVal *types.PrivValidator, proxyApp proxy.AppConns, state *sm.State) (blockchain []*types.Block, commits []*types.Commit) {
  497. prevHash := state.LastBlockID.Hash
  498. lastCommit := new(types.Commit)
  499. prevParts := types.PartSetHeader{}
  500. valHash := state.Validators.Hash()
  501. prevBlockID := types.BlockID{prevHash, prevParts}
  502. for i := 1; i < nBlocks+1; i++ {
  503. block, parts := types.MakeBlock(i, chainID, txsFunc(i), lastCommit,
  504. prevBlockID, valHash, state.AppHash, testPartSize)
  505. fmt.Println(i)
  506. fmt.Println(block.LastBlockID)
  507. err := state.ApplyBlock(nil, proxyApp.Consensus(), block, block.MakePartSet(testPartSize).Header(), mempool)
  508. if err != nil {
  509. t.Fatal(i, err)
  510. }
  511. voteSet := types.NewVoteSet(chainID, i, 0, types.VoteTypePrecommit, state.Validators)
  512. vote := signCommit(chainID, privVal, i, 0, block.Hash(), parts.Header())
  513. _, err = voteSet.AddVote(vote)
  514. if err != nil {
  515. t.Fatal(err)
  516. }
  517. prevHash = block.Hash()
  518. prevParts = parts.Header()
  519. lastCommit = voteSet.MakeCommit()
  520. prevBlockID = types.BlockID{prevHash, prevParts}
  521. blockchain = append(blockchain, block)
  522. commits = append(commits, lastCommit)
  523. }
  524. return blockchain, commits
  525. }
  526. // fresh state and mock store
  527. func stateAndStore(config *cfg.Config, pubKey crypto.PubKey) (*sm.State, *mockBlockStore) {
  528. stateDB := dbm.NewMemDB()
  529. state := sm.MakeGenesisStateFromFile(stateDB, config.GenesisFile())
  530. store := NewMockBlockStore(config)
  531. return state, store
  532. }
  533. //----------------------------------
  534. // mock block store
  535. type mockBlockStore struct {
  536. config *cfg.Config
  537. chain []*types.Block
  538. commits []*types.Commit
  539. }
  540. // TODO: NewBlockStore(db.NewMemDB) ...
  541. func NewMockBlockStore(config *cfg.Config) *mockBlockStore {
  542. return &mockBlockStore{config, nil, nil}
  543. }
  544. func (bs *mockBlockStore) Height() int { return len(bs.chain) }
  545. func (bs *mockBlockStore) LoadBlock(height int) *types.Block { return bs.chain[height-1] }
  546. func (bs *mockBlockStore) LoadBlockMeta(height int) *types.BlockMeta {
  547. block := bs.chain[height-1]
  548. return &types.BlockMeta{
  549. BlockID: types.BlockID{block.Hash(), block.MakePartSet(bs.config.Consensus.BlockPartSize).Header()},
  550. Header: block.Header,
  551. }
  552. }
  553. func (bs *mockBlockStore) LoadBlockPart(height int, index int) *types.Part { return nil }
  554. func (bs *mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
  555. }
  556. func (bs *mockBlockStore) LoadBlockCommit(height int) *types.Commit {
  557. return bs.commits[height-1]
  558. }
  559. func (bs *mockBlockStore) LoadSeenCommit(height int) *types.Commit {
  560. return bs.commits[height-1]
  561. }