|
|
@ -268,6 +268,29 @@ func setupNodeLog(config harmonyconfig.HarmonyConfig) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func revert(chain core.BlockChain, hc harmonyconfig.HarmonyConfig) { |
|
|
|
|
|
|
|
curNum := chain.CurrentBlock().NumberU64() |
|
|
|
|
|
|
|
if curNum < uint64(hc.Revert.RevertBefore) && curNum >= uint64(hc.Revert.RevertTo) { |
|
|
|
|
|
|
|
// Remove invalid blocks
|
|
|
|
|
|
|
|
for chain.CurrentBlock().NumberU64() >= uint64(hc.Revert.RevertTo) { |
|
|
|
|
|
|
|
curBlock := chain.CurrentBlock() |
|
|
|
|
|
|
|
rollbacks := []ethCommon.Hash{curBlock.Hash()} |
|
|
|
|
|
|
|
if err := chain.Rollback(rollbacks); err != nil { |
|
|
|
|
|
|
|
fmt.Printf("Revert failed: %v\n", err) |
|
|
|
|
|
|
|
os.Exit(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lastSig := curBlock.Header().LastCommitSignature() |
|
|
|
|
|
|
|
sigAndBitMap := append(lastSig[:], curBlock.Header().LastCommitBitmap()...) |
|
|
|
|
|
|
|
chain.WriteCommitSig(curBlock.NumberU64()-1, sigAndBitMap) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fmt.Printf("Revert finished. Current block: %v\n", chain.CurrentBlock().NumberU64()) |
|
|
|
|
|
|
|
utils.Logger().Warn(). |
|
|
|
|
|
|
|
Uint64("Current Block", chain.CurrentBlock().NumberU64()). |
|
|
|
|
|
|
|
Msg("Revert finished.") |
|
|
|
|
|
|
|
os.Exit(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) { |
|
|
|
func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) { |
|
|
|
var err error |
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
@ -353,26 +376,7 @@ func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) { |
|
|
|
if hc.Revert.RevertBeacon { |
|
|
|
if hc.Revert.RevertBeacon { |
|
|
|
chain = currentNode.Beaconchain() |
|
|
|
chain = currentNode.Beaconchain() |
|
|
|
} |
|
|
|
} |
|
|
|
curNum := chain.CurrentBlock().NumberU64() |
|
|
|
revert(chain, hc) |
|
|
|
if curNum < uint64(hc.Revert.RevertBefore) && curNum >= uint64(hc.Revert.RevertTo) { |
|
|
|
|
|
|
|
// Remove invalid blocks
|
|
|
|
|
|
|
|
for chain.CurrentBlock().NumberU64() >= uint64(hc.Revert.RevertTo) { |
|
|
|
|
|
|
|
curBlock := chain.CurrentBlock() |
|
|
|
|
|
|
|
rollbacks := []ethCommon.Hash{curBlock.Hash()} |
|
|
|
|
|
|
|
if err := chain.Rollback(rollbacks); err != nil { |
|
|
|
|
|
|
|
fmt.Printf("Revert failed: %v\n", err) |
|
|
|
|
|
|
|
os.Exit(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
lastSig := curBlock.Header().LastCommitSignature() |
|
|
|
|
|
|
|
sigAndBitMap := append(lastSig[:], curBlock.Header().LastCommitBitmap()...) |
|
|
|
|
|
|
|
chain.WriteCommitSig(curBlock.NumberU64()-1, sigAndBitMap) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fmt.Printf("Revert finished. Current block: %v\n", chain.CurrentBlock().NumberU64()) |
|
|
|
|
|
|
|
utils.Logger().Warn(). |
|
|
|
|
|
|
|
Uint64("Current Block", chain.CurrentBlock().NumberU64()). |
|
|
|
|
|
|
|
Msg("Revert finished.") |
|
|
|
|
|
|
|
os.Exit(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//// code to handle pre-image export, import and generation
|
|
|
|
//// code to handle pre-image export, import and generation
|
|
|
@ -727,31 +731,7 @@ func createGlobalConfig(hc harmonyconfig.HarmonyConfig) (*nodeconfig.ConfigType, |
|
|
|
return nodeConfig, nil |
|
|
|
return nodeConfig, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfig.ConfigType, registry *registry.Registry) *node.Node { |
|
|
|
func setupChain(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfig.ConfigType, registry *registry.Registry) *registry.Registry { |
|
|
|
// Parse minPeers from harmonyconfig.HarmonyConfig
|
|
|
|
|
|
|
|
var minPeers int |
|
|
|
|
|
|
|
var aggregateSig bool |
|
|
|
|
|
|
|
if hc.Consensus != nil { |
|
|
|
|
|
|
|
minPeers = hc.Consensus.MinPeers |
|
|
|
|
|
|
|
aggregateSig = hc.Consensus.AggregateSig |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
minPeers = defaultConsensusConfig.MinPeers |
|
|
|
|
|
|
|
aggregateSig = defaultConsensusConfig.AggregateSig |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blacklist, err := setupBlacklist(hc) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
utils.Logger().Warn().Msgf("Blacklist setup error: %s", err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
allowedTxs, err := setupAllowedTxs(hc) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
utils.Logger().Warn().Msgf("AllowedTxs setup error: %s", err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
localAccounts, err := setupLocalAccounts(hc, blacklist) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
utils.Logger().Warn().Msgf("local accounts setup error: %s", err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Current node.
|
|
|
|
// Current node.
|
|
|
|
var chainDBFactory shardchain.DBFactory |
|
|
|
var chainDBFactory shardchain.DBFactory |
|
|
@ -770,6 +750,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
engine := chain.NewEngine() |
|
|
|
engine := chain.NewEngine() |
|
|
|
|
|
|
|
registry.SetEngine(engine) |
|
|
|
|
|
|
|
|
|
|
|
chainConfig := nodeConfig.GetNetworkType().ChainConfig() |
|
|
|
chainConfig := nodeConfig.GetNetworkType().ChainConfig() |
|
|
|
collection := shardchain.NewCollection( |
|
|
|
collection := shardchain.NewCollection( |
|
|
@ -780,6 +761,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi |
|
|
|
collection.DisableCache(shardID) |
|
|
|
collection.DisableCache(shardID) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
registry.SetShardChainCollection(collection) |
|
|
|
|
|
|
|
|
|
|
|
var blockchain core.BlockChain |
|
|
|
var blockchain core.BlockChain |
|
|
|
|
|
|
|
|
|
|
@ -793,17 +775,48 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi |
|
|
|
registry.SetBeaconchain(beacon) |
|
|
|
registry.SetBeaconchain(beacon) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
blockchain, err = collection.ShardChain(nodeConfig.ShardID) |
|
|
|
blockchain, err := collection.ShardChain(nodeConfig.ShardID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "Error :%v \n", err) |
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "Error :%v \n", err) |
|
|
|
os.Exit(1) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
} |
|
|
|
registry.SetBlockchain(blockchain) |
|
|
|
registry.SetBlockchain(blockchain) |
|
|
|
registry.SetWebHooks(nodeConfig.WebHooks.Hooks) |
|
|
|
|
|
|
|
if registry.GetBeaconchain() == nil { |
|
|
|
if registry.GetBeaconchain() == nil { |
|
|
|
registry.SetBeaconchain(registry.GetBlockchain()) |
|
|
|
registry.SetBeaconchain(registry.GetBlockchain()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return registry |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfig.ConfigType, registry *registry.Registry) *node.Node { |
|
|
|
|
|
|
|
// Parse minPeers from harmonyconfig.HarmonyConfig
|
|
|
|
|
|
|
|
var minPeers int |
|
|
|
|
|
|
|
var aggregateSig bool |
|
|
|
|
|
|
|
if hc.Consensus != nil { |
|
|
|
|
|
|
|
minPeers = hc.Consensus.MinPeers |
|
|
|
|
|
|
|
aggregateSig = hc.Consensus.AggregateSig |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
minPeers = defaultConsensusConfig.MinPeers |
|
|
|
|
|
|
|
aggregateSig = defaultConsensusConfig.AggregateSig |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blacklist, err := setupBlacklist(hc) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
utils.Logger().Warn().Msgf("Blacklist setup error: %s", err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
allowedTxs, err := setupAllowedTxs(hc) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
utils.Logger().Warn().Msgf("AllowedTxs setup error: %s", err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
localAccounts, err := setupLocalAccounts(hc, blacklist) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
utils.Logger().Warn().Msgf("local accounts setup error: %s", err.Error()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registry = setupChain(hc, nodeConfig, registry) |
|
|
|
|
|
|
|
if registry.GetShardChainCollection() == nil { |
|
|
|
|
|
|
|
panic("shard chain collection is nil1111111") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
registry.SetWebHooks(nodeConfig.WebHooks.Hooks) |
|
|
|
cxPool := core.NewCxPool(core.CxPoolSize) |
|
|
|
cxPool := core.NewCxPool(core.CxPoolSize) |
|
|
|
registry.SetCxPool(cxPool) |
|
|
|
registry.SetCxPool(cxPool) |
|
|
|
|
|
|
|
|
|
|
@ -818,7 +831,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi |
|
|
|
os.Exit(1) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
currentNode := node.New(myHost, currentConsensus, engine, collection, blacklist, allowedTxs, localAccounts, nodeConfig.ArchiveModes(), &hc, registry) |
|
|
|
currentNode := node.New(myHost, currentConsensus, blacklist, allowedTxs, localAccounts, &hc, registry) |
|
|
|
|
|
|
|
|
|
|
|
if hc.Legacy != nil && hc.Legacy.TPBroadcastInvalidTxn != nil { |
|
|
|
if hc.Legacy != nil && hc.Legacy.TPBroadcastInvalidTxn != nil { |
|
|
|
currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn |
|
|
|
currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn |
|
|
|