From 8ff2832c7c63e0f3606476db97f2202c94d31e6a Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Tue, 6 Aug 2019 18:43:07 -0700 Subject: [PATCH 1/3] Revert bad blocks --- cmd/harmony/main.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 0e50a7dea2..1cddadce4c 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -11,6 +11,9 @@ 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" @@ -18,7 +21,6 @@ import ( "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" @@ -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() { @@ -308,6 +314,22 @@ 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) { + // 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 { From b7f77539e893bb84ba74380e77e7b68057fe34b1 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Tue, 6 Aug 2019 18:50:43 -0700 Subject: [PATCH 2/3] Add warning --- cmd/harmony/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 1cddadce4c..06068a62d4 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -319,6 +319,8 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node { chain := currentNode.Blockchain() curNum := chain.CurrentBlock().NumberU64() if curNum < uint64(*doRevertBefore) && curNum >= uint64(*revertTo) { + utils.GetLogInstance().Warn("[WARNING] Reverting blocks", + "to", *revertTo, "curBlock", curNum) // Remove invalid blocks for chain.CurrentBlock().NumberU64() >= uint64(*revertTo) { curBlock := chain.CurrentBlock() From aa536b5bab6a748ac7e2689b9070f0b115170d49 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Tue, 6 Aug 2019 19:54:29 -0700 Subject: [PATCH 3/3] Add shard check and set default revert valus --- cmd/harmony/main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 06068a62d4..332b1b12fd 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -124,8 +124,9 @@ var ( 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") + doRevertBefore = flag.Int("do_revert_before", 408701, "If the current block is less than do_revert_before, revert all blocks until (including) revert_to block") + revertTo = flag.Int("revert_to", 407735, "The revert will rollback all blocks until and including block number revert_to") + revertShardID = flag.Int("revert_shard_id", 3, "The shard id where the revert will happen") ) func initSetup() { @@ -318,7 +319,7 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node { ////// Temporary fix for 8-6 incident ///////// chain := currentNode.Blockchain() curNum := chain.CurrentBlock().NumberU64() - if curNum < uint64(*doRevertBefore) && curNum >= uint64(*revertTo) { + if chain.ShardID() == uint32(*revertShardID) && curNum < uint64(*doRevertBefore) && curNum >= uint64(*revertTo) { utils.GetLogInstance().Warn("[WARNING] Reverting blocks", "to", *revertTo, "curBlock", curNum) // Remove invalid blocks