-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* reduce shard of testnet to 2 * remove harmony inner nodes in shard2 and shard3 * check shardID in VerifyCrossLink * get NumShards by epoch instead of hardcodeed shards * add Localnet in NewGenesisSpec * do mayTestnetShardReduction in the block before the last block * fix localnet epoch calculation * not use old committee if shard reduction happens * fix preLastBlock calculation * do testnet shard reduction when propose new blocks * enable 2s block period at epoch 0 * call IntermediateRoot once in the end * skip inactive&baned validators when testnet shard reduction happens * update ShardReductionEpoch to epoch 486
- Loading branch information
Showing
12 changed files
with
574 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package shardingconfig | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/harmony-one/harmony/internal/params" | ||
) | ||
|
||
func TestLocalnetEpochCalculation(t *testing.T) { | ||
check := func(epoch, expected uint64) { | ||
if got := LocalnetSchedule.EpochLastBlock(epoch); got != expected { | ||
t.Fatalf("wrong EpochLastBlock at epoch %d. TwoSecondsEpoch: %s. expected: %d got: %d.", epoch, params.LocalnetChainConfig.TwoSecondsEpoch.String(), expected, got) | ||
} | ||
if !LocalnetSchedule.IsLastBlock(expected) { | ||
t.Fatalf("%d is not LastBlock. TwoSecondsEpoch: %s", expected, params.LocalnetChainConfig.TwoSecondsEpoch.String()) | ||
} | ||
epochStart := uint64(0) | ||
if epoch > 0 { | ||
epochStart = LocalnetSchedule.EpochLastBlock(epoch-1) + 1 | ||
} | ||
for blockNo := epochStart; blockNo <= expected; blockNo++ { | ||
if isLastBlock := LocalnetSchedule.IsLastBlock(blockNo); isLastBlock != (blockNo == expected) { | ||
t.Fatalf("IsLastBlock for %d is wrong. TwoSecondsEpoch: %s. expected %v got %v", blockNo, params.LocalnetChainConfig.TwoSecondsEpoch.String(), blockNo == expected, isLastBlock) | ||
} | ||
got := LocalnetSchedule.CalcEpochNumber(blockNo).Uint64() | ||
if got != epoch { | ||
t.Fatalf("CalcEpochNumber for %d is wrong. TwoSecondsEpoch: %s. expected %d got %d", blockNo, params.LocalnetChainConfig.TwoSecondsEpoch.String(), epoch, got) | ||
} | ||
} | ||
} | ||
backup := params.LocalnetChainConfig.TwoSecondsEpoch | ||
params.LocalnetChainConfig.TwoSecondsEpoch = big.NewInt(0) | ||
check(0, localnetEpochBlock1-1) | ||
check(1, localnetEpochBlock1+localnetBlocksPerEpochV2-1) | ||
check(2, localnetEpochBlock1+localnetBlocksPerEpochV2*2-1) | ||
|
||
params.LocalnetChainConfig.TwoSecondsEpoch = big.NewInt(1) | ||
check(0, localnetEpochBlock1-1) | ||
check(1, localnetEpochBlock1+localnetBlocksPerEpochV2-1) | ||
check(2, localnetEpochBlock1+localnetBlocksPerEpochV2*2-1) | ||
|
||
params.LocalnetChainConfig.TwoSecondsEpoch = big.NewInt(2) | ||
check(0, localnetEpochBlock1-1) | ||
check(1, localnetEpochBlock1+localnetBlocksPerEpoch-1) | ||
check(2, localnetEpochBlock1+localnetBlocksPerEpoch+localnetBlocksPerEpochV2-1) | ||
check(3, localnetEpochBlock1+localnetBlocksPerEpoch+localnetBlocksPerEpochV2*2-1) | ||
|
||
params.LocalnetChainConfig.TwoSecondsEpoch = backup | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.