add GetShardingStructure interface and implmentation for each instance

pull/1429/head
Minh Doan 5 years ago
parent 97df87a095
commit 2fcf9ed8b8
  1. 5
      internal/configs/sharding/fixedschedule.go
  2. 10
      internal/configs/sharding/localnet.go
  3. 10
      internal/configs/sharding/mainnet.go
  4. 12
      internal/configs/sharding/pangaea.go
  5. 18
      internal/configs/sharding/shardingconfig.go
  6. 10
      internal/configs/sharding/testnet.go
  7. 26
      internal/hmyapi/blockchain.go

@ -90,6 +90,11 @@ func (s fixedSchedule) GetNetworkID() NetworkID {
return DevNet return DevNet
} }
// GetShardingStructure is the sharding structure for fixed schedule.
func (fixedSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, TestNetHTTPPattern, TestNetHTTPPattern)
}
// 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 {

@ -32,6 +32,11 @@ const (
localnetMaxTxPoolSizeLimit = 8000 localnetMaxTxPoolSizeLimit = 8000
localnetMaxNumTxsPerBlockLimit = 1000 localnetMaxNumTxsPerBlockLimit = 1000
localnetRecentTxDuration = time.Hour localnetRecentTxDuration = time.Hour
// LocalNetHTTPPattern is the http pattern for mainnet.
LocalNetHTTPPattern = "http://s%d.t.hmny.io:9500"
// LocalNetWSPattern is the websocket pattern for mainnet.
LocalNetWSPattern = "ws://s%d.t.hmny.io:9800"
) )
func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
@ -126,6 +131,11 @@ func (ls localnetSchedule) GetNetworkID() NetworkID {
return LocalNet return LocalNet
} }
// GetShardingStructure is the sharding structure for localnet.
func (ls localnetSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, LocalNetHTTPPattern, LocalNetWSPattern)
}
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)

@ -33,6 +33,11 @@ const (
mainnetMaxTxPoolSizeLimit = 8000 mainnetMaxTxPoolSizeLimit = 8000
mainnetMaxNumTxsPerBlockLimit = 1000 mainnetMaxNumTxsPerBlockLimit = 1000
mainnetRecentTxDuration = time.Hour mainnetRecentTxDuration = time.Hour
// MainNetHTTPPattern is the http pattern for mainnet.
MainNetHTTPPattern = "http://s%d.t.hmny.io:9500"
// MainNetWSPattern is the websocket pattern for mainnet.
MainNetWSPattern = "ws://s%d.t.hmny.io:9800"
) )
// MainnetSchedule is the mainnet sharding configuration schedule. // MainnetSchedule is the mainnet sharding configuration schedule.
@ -149,6 +154,11 @@ func (ms mainnetSchedule) GetNetworkID() NetworkID {
return MainNet return MainNet
} }
// GetShardingStructure is the sharding structure for mainnet.
func (ms mainnetSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, MainNetHTTPPattern, MainNetWSPattern)
}
var mainnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(mainnetV0_1Epoch), big.NewInt(mainnetV0_2Epoch), big.NewInt(mainnetV0_3Epoch), big.NewInt(mainnetV0_4Epoch), big.NewInt(mainnetV1Epoch), big.NewInt(mainnetV1_1Epoch), big.NewInt(mainnetV1_2Epoch)} var mainnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(mainnetV0_1Epoch), big.NewInt(mainnetV0_2Epoch), big.NewInt(mainnetV0_3Epoch), big.NewInt(mainnetV0_4Epoch), big.NewInt(mainnetV1Epoch), big.NewInt(mainnetV1_1Epoch), big.NewInt(mainnetV1_2Epoch)}
var mainnetV0 = MustNewInstance(4, 150, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts, mainnetReshardingEpoch) var mainnetV0 = MustNewInstance(4, 150, 112, genesis.HarmonyAccounts, genesis.FoundationalNodeAccounts, mainnetReshardingEpoch)

@ -10,6 +10,13 @@ import (
"github.com/harmony-one/harmony/internal/genesis" "github.com/harmony-one/harmony/internal/genesis"
) )
const (
// PangaeaHTTPPattern is the http pattern for pangaea.
PangaeaHTTPPattern = "http://s%d.pga.hmny.io:9500"
// PangaeaWSPattern is the websocket pattern for pangaea.
PangaeaWSPattern = "ws://s%d.pga.hmny.io:9800"
)
// PangaeaSchedule is the Pangaea sharding configuration schedule. // PangaeaSchedule is the Pangaea sharding configuration schedule.
var PangaeaSchedule pangaeaSchedule var PangaeaSchedule pangaeaSchedule
@ -89,3 +96,8 @@ func (ps pangaeaSchedule) TxsThrottleConfig() *TxsThrottleConfig {
func (pangaeaSchedule) GetNetworkID() NetworkID { func (pangaeaSchedule) GetNetworkID() NetworkID {
return Pangaea return Pangaea
} }
// GetShardingStructure is the sharding structure for mainnet.
func (pangaeaSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, PangaeaHTTPPattern, PangaeaWSPattern)
}

@ -3,6 +3,7 @@
package shardingconfig package shardingconfig
import ( import (
"fmt"
"math/big" "math/big"
"time" "time"
@ -56,6 +57,9 @@ type Schedule interface {
// GetNetworkID() return networkID type. // GetNetworkID() return networkID type.
GetNetworkID() NetworkID GetNetworkID() NetworkID
// GetShardingStructure returns sharding structure.
GetShardingStructure(int, int) []map[string]interface{}
} }
// Instance is one sharding configuration instance. // Instance is one sharding configuration instance.
@ -124,3 +128,17 @@ type TxsThrottleConfig struct {
// Max total number of transactions allowed to be processed per block // Max total number of transactions allowed to be processed per block
MaxNumTxsPerBlockLimit int MaxNumTxsPerBlockLimit int
} }
// genShardingStructure return sharding structure, given shard number and its patterns.
func genShardingStructure(shardNum, shardID int, httpPattern, wsPattern string) []map[string]interface{} {
res := []map[string]interface{}{}
for i := 0; i < shardNum; i++ {
res = append(res, map[string]interface{}{
"current": int(shardID) == i,
"shardID": i,
"http": fmt.Sprintf(httpPattern, i),
"ws": fmt.Sprintf(wsPattern, i),
})
}
return res
}

@ -30,6 +30,11 @@ const (
testnetMaxTxPoolSizeLimit = 8000 testnetMaxTxPoolSizeLimit = 8000
testnetMaxNumTxsPerBlockLimit = 1000 testnetMaxNumTxsPerBlockLimit = 1000
testnetRecentTxDuration = time.Hour testnetRecentTxDuration = time.Hour
// TestNetHTTPPattern is the http pattern for testnet.
TestNetHTTPPattern = "http://s%d.b.hmny.io:9500"
// TestNetWSPattern is the websocket pattern for testnet.
TestNetWSPattern = "ws://s%d.s.hmny.io:9800"
) )
func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
@ -125,6 +130,11 @@ func (ts testnetSchedule) GetNetworkID() NetworkID {
return TestNet return TestNet
} }
// GetShardingStructure is the sharding structure for testnet.
func (ts testnetSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, TestNetHTTPPattern, TestNetWSPattern)
}
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)

@ -17,7 +17,6 @@ import (
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
internal_common "github.com/harmony-one/harmony/internal/common" internal_common "github.com/harmony-one/harmony/internal/common"
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
) )
@ -90,29 +89,10 @@ func GenShardingStructure(shardNum, shardID uint32, httpPattern, wsPattern strin
func (s *PublicBlockChainAPI) GetShardingStructure(ctx context.Context) ([]map[string]interface{}, error) { func (s *PublicBlockChainAPI) GetShardingStructure(ctx context.Context) ([]map[string]interface{}, error) {
// Get header and number of shards. // Get header and number of shards.
header := s.b.CurrentBlock().Header() header := s.b.CurrentBlock().Header()
numShard := core.ShardingSchedule.InstanceForEpoch(header.Epoch).NumShards() numShard := core.ShardingSchedule.InstanceForEpoch(header.Epoch()).NumShards()
// Return shareding structure for each case. // Return shareding structure for each case.
if core.ShardingSchedule.GetNetworkID() == shardingconfig.MainNet { return core.ShardingSchedule.GetShardingStructure(int(numShard), int(s.b.GetShardID())), nil
s.b.CurrentBlock().Header()
return GenShardingStructure(numShard, s.b.GetShardID(), MainNetHTTPPattern, MainNetWSPattern), nil
} else if core.ShardingSchedule.GetNetworkID() == shardingconfig.TestNet {
return GenShardingStructure(numShard, s.b.GetShardID(), TestNetHTTPPattern, TestNetWSPattern), nil
} else {
return []map[string]interface{}{
map[string]interface{}{
"current": s.b.GetShardID() == 0,
"shardID": 0,
"http": "http://127.0.0.1:9500",
"ws": "ws://127.0.0.1:9800",
},
map[string]interface{}{
"current": s.b.GetShardID() == 1,
"shardID": 1,
"http": "http://127.0.0.1:9501",
"ws": "ws://127.0.0.1:9801",
},
}, nil
}
} }
// GetCode returns the code stored at the given address in the state for the given block number. // GetCode returns the code stored at the given address in the state for the given block number.

Loading…
Cancel
Save