[config] disable beacon archival by default

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3471/head
Leo Chen 4 years ago
parent 4a0553fb84
commit 74971b63b9
  1. 13
      cmd/harmony/config.go
  2. 13
      cmd/harmony/default.go
  3. 10
      cmd/harmony/flags.go
  4. 7
      cmd/harmony/main.go
  5. 2
      hmy/hmy.go
  6. 20
      internal/configs/node/config.go
  7. 14
      internal/shardchain/shardchains.go
  8. 9
      node/node.go

@ -52,12 +52,13 @@ type p2pConfig struct {
}
type generalConfig struct {
NodeType string
NoStaking bool
ShardID int
IsArchival bool
IsOffline bool
DataDir string
NodeType string
NoStaking bool
ShardID int
IsArchival bool
IsBeaconArchival bool
IsOffline bool
DataDir string
}
type consensusConfig struct {

@ -11,12 +11,13 @@ const (
var defaultConfig = harmonyConfig{
Version: tomlConfigVersion,
General: generalConfig{
NodeType: "validator",
NoStaking: false,
ShardID: -1,
IsArchival: false,
IsOffline: false,
DataDir: "./",
NodeType: "validator",
NoStaking: false,
ShardID: -1,
IsArchival: false,
IsBeaconArchival: false,
IsOffline: false,
DataDir: "./",
},
Network: getDefaultNetworkConfig(defNetworkType),
P2P: p2pConfig{

@ -15,6 +15,7 @@ var (
noStakingFlag,
shardIDFlag,
isArchiveFlag,
isBeaconArchiveFlag,
isOfflineFlag,
dataDirFlag,
@ -197,6 +198,11 @@ var (
Usage: "run node in archive mode",
DefValue: defaultConfig.General.IsArchival,
}
isBeaconArchiveFlag = cli.BoolFlag{
Name: "run.beacon-archive",
Usage: "beacon chain also in archival mode",
DefValue: defaultConfig.General.IsBeaconArchival,
}
isOfflineFlag = cli.BoolFlag{
Name: "run.offline",
Usage: "run node in offline mode",
@ -293,6 +299,10 @@ func applyGeneralFlags(cmd *cobra.Command, config *harmonyConfig) {
config.General.IsArchival = cli.GetBoolFlagValue(cmd, legacyIsArchiveFlag)
}
if cli.IsFlagChanged(cmd, isBeaconArchiveFlag) {
config.General.IsBeaconArchival = cli.GetBoolFlagValue(cmd, isBeaconArchiveFlag)
}
if cli.IsFlagChanged(cmd, dataDirFlag) {
config.General.DataDir = cli.GetStringFlagValue(cmd, dataDirFlag)
} else if cli.IsFlagChanged(cmd, legacyDataDirFlag) {

@ -534,8 +534,9 @@ func createGlobalConfig(hc harmonyConfig) (*nodeconfig.ConfigType, error) {
// Set network type
netType := nodeconfig.NetworkType(hc.Network.NetworkType)
nodeconfig.SetNetworkType(netType) // sets for both global and shard configs
nodeConfig.SetArchival(hc.General.IsArchival)
nodeconfig.SetNetworkType(netType) // sets for both global and shard configs
nodeConfig.SetShardID(initialAccounts[0].ShardID) // sets shard ID
nodeConfig.SetArchival(hc.General.IsBeaconArchival, hc.General.IsArchival)
nodeConfig.IsOffline = hc.General.IsOffline
// P2P private key is used for secure message transfer between p2p nodes.
@ -615,7 +616,7 @@ func setupConsensusAndNode(hc harmonyConfig, nodeConfig *nodeconfig.ConfigType)
// Current node.
chainDBFactory := &shardchain.LDBFactory{RootDir: nodeConfig.DBDir}
currentNode := node.New(myHost, currentConsensus, chainDBFactory, blacklist, hc.General.IsArchival)
currentNode := node.New(myHost, currentConsensus, chainDBFactory, blacklist, nodeConfig.IsArchival())
if hc.Legacy != nil && hc.Legacy.TPBroadcastInvalidTxn != nil {
currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn

@ -164,8 +164,8 @@ func (hmy *Harmony) IsLeader() bool {
// GetNodeMetadata ..
func (hmy *Harmony) GetNodeMetadata() commonRPC.NodeMetadata {
cfg := nodeconfig.GetDefaultConfig()
header := hmy.CurrentBlock().Header()
cfg := nodeconfig.GetShardConfig(header.ShardID())
var blockEpoch *uint64
if header.ShardID() == shard.BeaconChainShardID {

@ -14,6 +14,7 @@ import (
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/multibls"
"github.com/harmony-one/harmony/shard"
"github.com/harmony-one/harmony/webhooks"
p2p_crypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
@ -88,7 +89,7 @@ type ConfigType struct {
networkType NetworkType
shardingSchedule shardingconfig.Schedule
DNSZone string
isArchival bool
isArchival map[uint32]bool
WebHooks struct {
Hooks *webhooks.Hooks
}
@ -200,7 +201,7 @@ func (conf *ConfigType) GetClientGroupID() GroupID {
// GetArchival returns archival mode
func (conf *ConfigType) GetArchival() bool {
return conf.isArchival
return conf.isArchival[conf.ShardID]
}
// Role returns the role
@ -218,8 +219,19 @@ func SetNetworkType(networkType NetworkType) {
}
// SetArchival set archival mode
func (conf *ConfigType) SetArchival(archival bool) {
defaultConfig.isArchival = archival
// for beacon chain node, the archival variable will
// overrdie bcArchival as the shardID is the same
func (conf *ConfigType) SetArchival(bcArchival, archival bool) {
if conf.isArchival == nil {
conf.isArchival = make(map[uint32]bool)
}
conf.isArchival[shard.BeaconChainShardID] = bcArchival
conf.isArchival[conf.ShardID] = archival
}
// IsArchival return the isArchival map
func (conf *ConfigType) IsArchival() map[uint32]bool {
return conf.isArchival
}
// GetNetworkType gets the networkType

@ -35,7 +35,7 @@ type CollectionImpl struct {
engine engine.Engine
mtx sync.Mutex
pool map[uint32]*core.BlockChain
disableCache bool
disableCache map[uint32]bool
chainConfig *params.ChainConfig
}
@ -88,8 +88,11 @@ func (sc *CollectionImpl) ShardChain(shardID uint32) (*core.BlockChain, error) {
}
}
var cacheConfig *core.CacheConfig
if sc.disableCache {
if sc.disableCache[shardID] {
cacheConfig = &core.CacheConfig{Disabled: true}
utils.Logger().Info().
Uint32("shardID", shardID).
Msg("disable cache, running in archival mode")
}
bc, err := core.NewBlockChain(
@ -106,8 +109,11 @@ func (sc *CollectionImpl) ShardChain(shardID uint32) (*core.BlockChain, error) {
// DisableCache disables caching mode for newly opened chains.
// It does not affect already open chains. For best effect,
// use this immediately after creating collection.
func (sc *CollectionImpl) DisableCache() {
sc.disableCache = true
func (sc *CollectionImpl) DisableCache(shardID uint32) {
if sc.disableCache == nil {
sc.disableCache = make(map[uint32]bool)
}
sc.disableCache[shardID] = true
}
// CloseShardChain closes the given shard chain.

@ -870,7 +870,7 @@ func New(
consensusObj *consensus.Consensus,
chainDBFactory shardchain.DBFactory,
blacklist map[common.Address]struct{},
isArchival bool,
isArchival map[uint32]bool,
) *Node {
node := Node{}
node.unixTimeAtNodeStart = time.Now().Unix()
@ -895,8 +895,11 @@ func New(
collection := shardchain.NewCollection(
chainDBFactory, &genesisInitializer{&node}, chain.Engine, &chainConfig,
)
if isArchival {
collection.DisableCache()
for shardID, archival := range isArchival {
if archival {
collection.DisableCache(shardID)
}
}
node.shardChains = collection
node.IsInSync = abool.NewBool(false)

Loading…
Cancel
Save