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

Revert bad blocks #1295

Merged
merged 3 commits into from Aug 7, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 25 additions & 1 deletion cmd/harmony/main.go
Expand Up @@ -11,14 +11,16 @@ import (
"runtime"
"time"

common2 "github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/internal/common"

"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/bls/ffi/go/bls"

"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/internal/blsgen"
"github.com/harmony-one/harmony/internal/common"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding"
"github.com/harmony-one/harmony/internal/ctxerror"
Expand Down Expand Up @@ -120,6 +122,10 @@ var (

// Disable view change.
disableViewChange = flag.Bool("disable_view_change", false, "Do not propose view change (testing only)")

// Bad block revert
doRevertBefore = flag.Int("do_revert_before", 0, "If the current block is less than do_revert_before, revert all blocks until (including) revert_to block")
revertTo = flag.Int("revert_to", 0, "The revert will rollback all blocks until and including block number revert_to")
)

func initSetup() {
Expand Down Expand Up @@ -308,6 +314,24 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
// Current node.
chainDBFactory := &shardchain.LDBFactory{RootDir: nodeConfig.DBDir}
currentNode := node.New(nodeConfig.Host, currentConsensus, chainDBFactory, *isArchival)

////// Temporary fix for 8-6 incident /////////
chain := currentNode.Blockchain()
curNum := chain.CurrentBlock().NumberU64()
if curNum < uint64(*doRevertBefore) && curNum >= uint64(*revertTo) {
utils.GetLogInstance().Warn("[WARNING] Reverting blocks",
Copy link
Contributor

Choose a reason for hiding this comment

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

this has to be fixed using zerolog.

"to", *revertTo, "curBlock", curNum)
// Remove invalid blocks
for chain.CurrentBlock().NumberU64() >= uint64(*revertTo) {
curBlock := chain.CurrentBlock()
rollbacks := []common2.Hash{curBlock.Hash()}
chain.Rollback(rollbacks)
sigAndBitMap := append(curBlock.Header().LastCommitSignature[:], curBlock.Header().LastCommitBitmap...)
chain.WriteLastCommits(sigAndBitMap)
}
}
///////////////////////////////////////////////

if *dnsZone != "" {
currentNode.SetDNSZone(*dnsZone)
} else if *dnsFlag {
Expand Down