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.

657 lines
20 KiB

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