Skip to content

Commit

Permalink
Further cherry picks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalank committed Aug 17, 2021
1 parent ea2def4 commit 50f5125
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 272 deletions.
69 changes: 26 additions & 43 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,13 @@ func MakeDataDir(ctx *cli.Context) string {
// Ropsten database in `testnet` instead of `ropsten`.
return filepath.Join(path, "ropsten")
}
if ctx.GlobalIsSet(ZoneFlag.Name) {
dir := node.QuaiContextDataDir("Zone", strconv.Itoa(ctx.GlobalInt(ZoneFlag.Name)))
if ctx.GlobalIsSet(RegionFlag.Name) && !ctx.GlobalIsSet(ZoneFlag.Name) {
dir := node.QuaiRegionDataDir(strconv.Itoa(ctx.GlobalInt(RegionFlag.Name)))
log.Info("Setting dir path", dir)
return dir
}
if ctx.GlobalIsSet(RegionFlag.Name) {
dir := node.QuaiContextDataDir("Region", strconv.Itoa(ctx.GlobalInt(RegionFlag.Name)))
if ctx.GlobalIsSet(RegionFlag.Name) && ctx.GlobalIsSet(ZoneFlag.Name) {
dir := node.QuaiZoneDataDir(strconv.Itoa(ctx.GlobalInt(RegionFlag.Name)), strconv.Itoa(ctx.GlobalInt(ZoneFlag.Name)))
log.Info("Setting dir path", dir)
return dir
}
Expand Down Expand Up @@ -1274,16 +1274,14 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
}

cfg.DataDir = filepath.Join(node.DefaultDataDir(), "ropsten")
case ctx.GlobalIsSet(ZoneFlag.Name):
dir := node.QuaiContextDataDir("Zone", strconv.Itoa(ctx.GlobalInt(ZoneFlag.Name)))
case ctx.GlobalIsSet(RegionFlag.Name) && !ctx.GlobalIsSet(ZoneFlag.Name):
dir := node.QuaiRegionDataDir(strconv.Itoa(ctx.GlobalInt(RegionFlag.Name)))
log.Info("Setting dir path", dir)
cfg.DataDir = dir

case ctx.GlobalIsSet(RegionFlag.Name):
dir := node.QuaiContextDataDir("Region", strconv.Itoa(ctx.GlobalInt(RegionFlag.Name)))
case ctx.GlobalIsSet(RegionFlag.Name) && ctx.GlobalIsSet(ZoneFlag.Name):
dir := node.QuaiZoneDataDir(strconv.Itoa(ctx.GlobalInt(RegionFlag.Name)), strconv.Itoa(ctx.GlobalInt(ZoneFlag.Name)))
log.Info("Setting dir path", dir)
cfg.DataDir = dir

}
}

Expand Down Expand Up @@ -1610,6 +1608,20 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
cfg.Genesis = core.DefaultRopstenGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.RopstenGenesisHash)
case ctx.GlobalIsSet(RegionFlag.Name) && !ctx.GlobalIsSet(ZoneFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = params.MainnetRegionChainConfigs[ctx.GlobalInt(RegionFlag.Name)-1].ChainID.Uint64()
}
cfg.Genesis = core.MainnetRegionGenesisBlock(&params.MainnetRegionChainConfigs[ctx.GlobalInt(RegionFlag.Name)-1])
types.QuaiNetworkContext = cfg.Genesis.Config.Context
SetDNSDiscoveryDefaults(cfg, params.MainnetPrimeGenesisHash)
case ctx.GlobalIsSet(RegionFlag.Name) && ctx.GlobalIsSet(ZoneFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = params.MainnetZoneChainConfigs[ctx.GlobalInt(RegionFlag.Name)-1][ctx.GlobalInt(ZoneFlag.Name)-1].ChainID.Uint64()
}
cfg.Genesis = core.MainnetZoneGenesisBlock(&params.MainnetZoneChainConfigs[ctx.GlobalInt(RegionFlag.Name)-1][ctx.GlobalInt(ZoneFlag.Name)-1])
types.QuaiNetworkContext = cfg.Genesis.Config.Context
SetDNSDiscoveryDefaults(cfg, params.MainnetPrimeGenesisHash)
case ctx.GlobalBool(DeveloperFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
Expand Down Expand Up @@ -1791,39 +1803,10 @@ func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb.
func MakeGenesis(ctx *cli.Context) *core.Genesis {
var genesis *core.Genesis
switch {
case ctx.GlobalBool(MainnetFlag.Name):
switch {
case ctx.GlobalBool(ZoneFlag.Name):
switch ZoneFlag.Value {
case 1:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneOneChainConfig)
case 2:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneTwoChainConfig)
case 3:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneThreeChainConfig)
case 4:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneFourChainConfig)
case 5:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneFiveChainConfig)
case 6:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneSixChainConfig)
case 7:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneSevenChainConfig)
case 8:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneEightChainConfig)
case 9:
genesis = core.MainnetZoneGenesisBlock(params.MainnetZoneNineChainConfig)
}
case ctx.GlobalBool(RegionFlag.Name):
switch RegionFlag.Value {
case 1:
genesis = core.MainnetRegionGenesisBlock(params.MainnetRegionOneChainConfig)
case 2:
genesis = core.MainnetRegionGenesisBlock(params.MainnetRegionTwoChainConfig)
case 3:
genesis = core.MainnetRegionGenesisBlock(params.MainnetRegionThreeChainConfig)
}
}
case ctx.GlobalBool(RegionFlag.Name) && ctx.GlobalBool(ZoneFlag.Name):
genesis = core.MainnetZoneGenesisBlock(&params.MainnetZoneChainConfigs[ctx.GlobalInt(RegionFlag.Name)-1][ctx.GlobalInt(ZoneFlag.Name)-1])
case ctx.GlobalBool(RegionFlag.Name) && !ctx.GlobalBool(ZoneFlag.Name):
genesis = core.MainnetRegionGenesisBlock(&params.MainnetRegionChainConfigs[ctx.GlobalInt(RegionFlag.Name)-1])
default:
genesis = core.MainnetPrimeGenesisBlock()
}
Expand Down
39 changes: 33 additions & 6 deletions node/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,54 @@ func DefaultDataDir() string {
return ""
}

// QuaiContextDataDir is the default data directory to use for the databases and other
// QuaiRegionDataDir is the default data directory to use for the databases and other
// persistence requirements.
func QuaiContextDataDir(contextType string, contextNumber string) string {
func QuaiRegionDataDir(contextNumber string) string {
// Try to place the data folder in the user's home dir
home := homeDir()
if home != "" {
switch runtime.GOOS {
case "darwin":
return filepath.Join(home, "Library", "Quai", contextType+contextNumber)
return filepath.Join(home, "Library", "Quai", "Region"+contextNumber)
case "windows":
// We used to put everything in %HOME%\AppData\Roaming, but this caused
// problems with non-typical setups. If this fallback location exists and
// is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%.
fallback := filepath.Join(home, "AppData", "Roaming", "Quai", contextType+contextNumber)
fallback := filepath.Join(home, "AppData", "Roaming", "Quai", "Region"+contextNumber)
appdata := windowsAppData()
if appdata == "" || isNonEmptyDir(fallback) {
return fallback
}
return filepath.Join(appdata, "Quai", contextType+contextNumber)
return filepath.Join(appdata, "Quai", "Region"+contextNumber)
default:
return filepath.Join(home, ".quai", contextType+contextNumber)
return filepath.Join(home, ".quai", "region"+contextNumber)
}
}
// As we cannot guess a stable location, return empty and handle later
return ""
}

// QuaiZoneDataDir is the default data directory to use for the databases and other
// persistence requirements.
func QuaiZoneDataDir(regionNumber string, zoneNumber string) string {
// Try to place the data folder in the user's home dir
home := homeDir()
if home != "" {
switch runtime.GOOS {
case "darwin":
return filepath.Join(home, "Library", "Quai", "Region"+regionNumber, "Zone"+zoneNumber)
case "windows":
// We used to put everything in %HOME%\AppData\Roaming, but this caused
// problems with non-typical setups. If this fallback location exists and
// is non-empty, use it, otherwise DTRT and check %LOCALAPPDATA%.
fallback := filepath.Join(home, "AppData", "Roaming", "Quai", "Region"+regionNumber, "Zone"+zoneNumber)
appdata := windowsAppData()
if appdata == "" || isNonEmptyDir(fallback) {
return fallback
}
return filepath.Join(appdata, "Quai", "Region"+regionNumber, "Zone"+zoneNumber)
default:
return filepath.Join(home, ".quai", "region"+regionNumber, "zone"+zoneNumber)
}
}
// As we cannot guess a stable location, return empty and handle later
Expand Down
Loading

0 comments on commit 50f5125

Please sign in to comment.