Skip to content

Commit

Permalink
Merge pull request #15 from HaoyangLiu/0.23.1-rc0-iris1-hotfix
Browse files Browse the repository at this point in the history
Add RetreatLastBlock interface for replay
  • Loading branch information
HaoyangLiu authored Nov 13, 2018
2 parents 46b52ca + 10bfbae commit 346fca9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions blockchain/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
bs.db.SetSync(nil, nil)
}

func (bs *BlockStore) RetreatLastBlock() {
height := bs.height

bs.db.Delete(calcBlockMetaKey(height))
bs.db.Delete(calcBlockCommitKey(height-1))
bs.db.Delete(calcSeenCommitKey(height))

BlockStoreStateJSON{Height: height-1 }.Save(bs.db)

// Flush
bs.db.SetSync(nil, nil)
}

func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part) {
if height != bs.Height()+1 {
cmn.PanicSanity(cmn.Fmt("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height))
Expand Down
2 changes: 2 additions & 0 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ func (bs *mockBlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
func (bs *mockBlockStore) LoadBlockPart(height int64, index int) *types.Part { return nil }
func (bs *mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
}
func (bs *mockBlockStore) RetreatLastBlock() {
}
func (bs *mockBlockStore) LoadBlockCommit(height int64) *types.Commit {
return bs.commits[height-1]
}
Expand Down
1 change: 1 addition & 0 deletions state/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type BlockStoreRPC interface {
type BlockStore interface {
BlockStoreRPC
SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)
RetreatLastBlock()
}

//-----------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 346fca9

Please sign in to comment.