From 09ffce3960c7ecd4f5490a45c3907a2c3eb48574 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Sun, 8 Dec 2019 11:07:52 -0800 Subject: [PATCH] add flag to revert only beacon chain; also fix a epoch calc bug --- cmd/harmony/main.go | 4 ++++ internal/configs/sharding/testnet.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 500e76da0..f48fa6043 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -119,6 +119,7 @@ var ( // 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") + revertBeacon = flag.Bool("revert_beacon", false, "Whether to revert beacon chain or the chain this node is assigned to") ) func initSetup() { @@ -505,6 +506,9 @@ func main() { if uint64(*doRevertBefore) != 0 && uint64(*revertTo) != 0 { chain := currentNode.Blockchain() + if *revertBeacon { + chain = currentNode.Beaconchain() + } curNum := chain.CurrentBlock().NumberU64() if curNum < uint64(*doRevertBefore) && curNum >= uint64(*revertTo) { // Remove invalid blocks diff --git a/internal/configs/sharding/testnet.go b/internal/configs/sharding/testnet.go index 63a40ff8b..4a9c0f551 100644 --- a/internal/configs/sharding/testnet.go +++ b/internal/configs/sharding/testnet.go @@ -39,7 +39,7 @@ func (testnetSchedule) BlocksPerEpoch() uint64 { } func (ts testnetSchedule) CalcEpochNumber(blockNum uint64) *big.Int { - epoch := blockNum % ts.BlocksPerEpoch() + epoch := blockNum / ts.BlocksPerEpoch() return big.NewInt(int64(epoch)) }