Merge pull request #1281 from coolcottontail/fix_localnet

Created different consensysratio for localnet/mainnet
pull/1287/head
Leo Chen 5 years ago committed by GitHub
commit ec389f8ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      api/service/syncing/syncing.go
  2. 5
      internal/configs/sharding/fixedschedule.go
  3. 8
      internal/configs/sharding/localnet.go
  4. 8
      internal/configs/sharding/mainnet.go
  5. 3
      internal/configs/sharding/shardingconfig.go
  6. 5
      internal/configs/sharding/testnet.go

@ -25,7 +25,6 @@ import (
// Constants for syncing. // Constants for syncing.
const ( const (
ConsensusRatio = float64(0.66)
SleepTimeAfterNonConsensusBlockHashes = time.Second * 30 SleepTimeAfterNonConsensusBlockHashes = time.Second * 30
TimesToFail = 5 // Downloadblocks service retry limit TimesToFail = 5 // Downloadblocks service retry limit
RegistrationNumber = 3 RegistrationNumber = 3
@ -318,7 +317,7 @@ func (sc *SyncConfig) GetBlockHashesConsensusAndCleanUp() bool {
Int("maxFirstID", maxFirstID). Int("maxFirstID", maxFirstID).
Int("maxCount", maxCount). Int("maxCount", maxCount).
Msg("[SYNC] block consensus hashes") Msg("[SYNC] block consensus hashes")
if float64(maxCount) >= ConsensusRatio*float64(len(sc.peers)) { if float64(maxCount) >= core.ShardingSchedule.ConsensusRatio()*float64(len(sc.peers)) {
sc.cleanUpPeers(maxFirstID) sc.cleanUpPeers(maxFirstID)
return true return true
} }

@ -36,6 +36,11 @@ func (s fixedSchedule) VdfDifficulty() int {
return mainnetVdfDifficulty return mainnetVdfDifficulty
} }
// ConsensusRatio ratio of new nodes vs consensus total nodes
func (s fixedSchedule) ConsensusRatio() float64 {
return mainnetConsensusRatio
}
// NewFixedSchedule returns a sharding configuration schedule that uses the // NewFixedSchedule returns a sharding configuration schedule that uses the
// given config instance for all epochs. Useful for testing. // given config instance for all epochs. Useful for testing.
func NewFixedSchedule(instance Instance) Schedule { func NewFixedSchedule(instance Instance) Schedule {

@ -19,7 +19,8 @@ const (
localnetEpochBlock1 = 10 localnetEpochBlock1 = 10
twoOne = 5 twoOne = 5
localnetVdfDifficulty = 5000 // This takes about 10s to finish the vdf localnetVdfDifficulty = 5000 // This takes about 10s to finish the vdf
localnetConsensusRatio = float64(0.1)
) )
func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
@ -63,6 +64,11 @@ func (ls localnetSchedule) VdfDifficulty() int {
return localnetVdfDifficulty return localnetVdfDifficulty
} }
// ConsensusRatio ratio of new nodes vs consensus total nodes
func (ls localnetSchedule) ConsensusRatio() float64 {
return localnetConsensusRatio
}
var localnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(localnetV1Epoch), big.NewInt(localnetV2Epoch)} var localnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(localnetV1Epoch), big.NewInt(localnetV2Epoch)}
var localnetV0 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccounts, genesis.LocalFnAccounts, localnetReshardingEpoch) var localnetV0 = MustNewInstance(2, 7, 5, genesis.LocalHarmonyAccounts, genesis.LocalFnAccounts, localnetReshardingEpoch)

@ -12,7 +12,8 @@ const (
mainnetV1Epoch = 1 mainnetV1Epoch = 1
mainnetV2Epoch = 5 mainnetV2Epoch = 5
mainnetVdfDifficulty = 50000 // This takes about 100s to finish the vdf mainnetVdfDifficulty = 50000 // This takes about 100s to finish the vdf
mainnetConsensusRatio = float64(0.66)
) )
// MainnetSchedule is the mainnet sharding configuration schedule. // MainnetSchedule is the mainnet sharding configuration schedule.
@ -63,6 +64,11 @@ func (ms mainnetSchedule) VdfDifficulty() int {
return mainnetVdfDifficulty return mainnetVdfDifficulty
} }
// ConsensusRatio ratio of new nodes vs consensus total nodes
func (ms mainnetSchedule) ConsensusRatio() float64 {
return mainnetConsensusRatio
}
var mainnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(mainnetV1Epoch)} var mainnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(mainnetV1Epoch)}
var mainnetV0 = MustNewInstance(4, 150, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts, mainnetReshardingEpoch) var mainnetV0 = MustNewInstance(4, 150, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts, mainnetReshardingEpoch)
var mainnetV1 = MustNewInstance(4, 152, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccountsV1, mainnetReshardingEpoch) var mainnetV1 = MustNewInstance(4, 152, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccountsV1, mainnetReshardingEpoch)

@ -24,6 +24,9 @@ type Schedule interface {
// VDFDifficulty returns number of iterations for VDF calculation // VDFDifficulty returns number of iterations for VDF calculation
VdfDifficulty() int VdfDifficulty() int
// ConsensusRatio ratio of new nodes vs consensus total nodes
ConsensusRatio() float64
} }
// Instance is one sharding configuration instance. // Instance is one sharding configuration instance.

@ -64,6 +64,11 @@ func (ts testnetSchedule) VdfDifficulty() int {
return testnetVdfDifficulty return testnetVdfDifficulty
} }
// ConsensusRatio ratio of new nodes vs consensus total nodes
func (ts testnetSchedule) ConsensusRatio() float64 {
return mainnetConsensusRatio
}
var testnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(testnetV1Epoch), big.NewInt(testnetV2Epoch)} var testnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(testnetV1Epoch), big.NewInt(testnetV2Epoch)}
var testnetV0 = MustNewInstance(2, 150, 150, genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, testnetReshardingEpoch) var testnetV0 = MustNewInstance(2, 150, 150, genesis.TNHarmonyAccounts, genesis.TNFoundationalAccounts, testnetReshardingEpoch)

Loading…
Cancel
Save