Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R] tools: state_recover add index height rollback #643

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ BUG FIXES

IMPROVEMENTS
* [\#638](https://github.com/binance-chain/node/pull/638) [Pub] BEP39 - add memo to transfer kafka message
* [\#639](https://github.com/binance-chain/node/pull/639) [ABCI] add levels parameter to depth ABCI query
* [\#639](https://github.com/binance-chain/node/pull/639) [ABCI] add levels parameter to depth ABCI query
* [\#643](https://github.com/binance-chain/node/pull/643) [TOOL] tools: state_recover add index height rollback
9 changes: 5 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
[[override]]
name = "github.com/tendermint/tendermint"
source = "github.com/binance-chain/bnc-tendermint"
version = "=v0.31.5-binance.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The master branch is =v0.31.5-binance.1, we don't omit =v0.31.5-binance.1, it is ok

version = "=v0.31.5-binance.2"

[[constraint]]
name = "github.com/cosmos/cosmos-sdk"
Expand Down
22 changes: 22 additions & 0 deletions networks/tools/state_recover/state_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ func resetBlockChainState(height int64, rootDir string) {
}

state.SaveState(stateDb, blockState)

// reset index height in state db
// NOTICE: Will not rollback index data in index db. If roll back all validators, the index db may contain dirty data.
rawHeight := stateDb.Get(state.IndexHeightKey)
if rawHeight != nil {
var indexHeight int64
err := cdc.UnmarshalBinaryBare(rawHeight, &indexHeight)
if err != nil {
// should not happen
cmn.Exit(fmt.Sprintf(`Load IndexHeight: Data has been corrupted or its spec has changed:
%v\n`, err))
}
if height < indexHeight {
bz, err := cdc.MarshalBinaryBare(height)
if err != nil {
cmn.Exit(fmt.Sprintf(`Faile to marshal index height:
%v\n`, err))
} else {
stateDb.Set(state.IndexHeightKey, bz)
}
}
}
}

func resetBlockStoreState(height int64, rootDir string) {
Expand Down