Skip to content

Commit

Permalink
rm panda refs outside core module; preprocess text/ANSI artwork sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed May 29, 2022
1 parent 480ac59 commit 3b3f417
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 53 deletions.
12 changes: 7 additions & 5 deletions beacon_chain/consensus_object_pools/block_pools_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import
../validators/validator_monitor,
./block_dag, block_pools_types_light_client

from "."/pandas/pandas import PandaTexts
from "."/vanity_logs/pandas import VanityLogs

export
options, sets, tables, hashes, helpers, beacon_chain_db, era_db, block_dag,
block_pools_types_light_client, validator_monitor, PandaTexts
block_pools_types_light_client, validator_monitor, VanityLogs

# ChainDAG and types related to forming a DAG of blocks, keeping track of their
# relationships and allowing various forms of lookups
Expand Down Expand Up @@ -202,9 +202,11 @@ type
## value with other components which don't have access to the
## full ChainDAG.

pandaTexts*: PandaTexts
## Upon the merge activating, these get displayed, first when the head
## is post-merge and then when the merge is finalized.
vanityLogs*: VanityLogs
## Upon the merge activating, these get displayed, at least once when the
## head becomes post-merge and then when the merge is finalized. If chain
## reorgs happen around the initial merge onMergeTransitionBlock might be
## called several times.

# -----------------------------------
# Data to enable light clients to stay in sync with the network
Expand Down
8 changes: 4 additions & 4 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
onLCOptimisticUpdateCb: OnLightClientOptimisticUpdateCallback = nil,
serveLightClientData = false,
importLightClientData = ImportLightClientData.None,
pandaTexts = default(PandaTexts)): ChainDAGRef =
vanityLogs = default(VanityLogs)): ChainDAGRef =
# TODO move fork version sanity checking elsewhere?
let forkVersions =
[cfg.GENESIS_FORK_VERSION, cfg.ALTAIR_FORK_VERSION,
Expand Down Expand Up @@ -706,7 +706,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
updateFlags: {verifyFinalization} * updateFlags,
cfg: cfg,

pandaTexts: pandaTexts,
vanityLogs: vanityLogs,

serveLightClientData: serveLightClientData,
importLightClientData: importLightClientData,
Expand Down Expand Up @@ -1577,7 +1577,7 @@ proc updateHead*(
dag.head = newHead

if getHeadStateMergeComplete() and not lastHeadMergeComplete:
dag.pandaTexts.headPanda()
dag.vanityLogs.onMergeTransitionBlock()

dag.db.putHeadBlock(newHead.root)

Expand Down Expand Up @@ -1676,7 +1676,7 @@ proc updateHead*(

if oldFinalizedHead.blck.executionBlockRoot.isZero and
not dag.finalizedHead.blck.executionBlockRoot.isZero:
dag.pandaTexts.finalizedPanda()
dag.vanityLogs.onFinalizedMergeTransitionBlock()

# Pruning the block dag is required every time the finalized head changes
# in order to clear out blocks that are no longer viable and should
Expand Down
41 changes: 0 additions & 41 deletions beacon_chain/consensus_object_pools/pandas/pandas.nim

This file was deleted.

Binary file not shown.
Binary file not shown.
37 changes: 37 additions & 0 deletions beacon_chain/consensus_object_pools/vanity_logs/pandas.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# beacon_chain
# Copyright (c) 2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{.push raises: [Defect].}

import chronicles
from ".."/".."/conf import StdoutLogKind

type
VanityLogs* = object
onMergeTransitionBlock*: proc() {.gcsafe, raises: [Defect].}
onFinalizedMergeTransitionBlock*: proc() {.gcsafe, raises: [Defect].}

# These need to be the main body of the log not to be reformatted or escaped.
proc mono🐼() = notice "text-version.txt".staticRead
proc color🐼() = notice "color-version.ans".staticRead
proc blink🐼() = notice "blink-version.ans".staticRead

func getPandas*(stdoutKind: StdoutLogKind): VanityLogs =
case stdoutKind
of StdoutLogKind.Auto: raiseAssert "inadmissable here"
of StdoutLogKind.Colors:
VanityLogs(
onMergeTransitionBlock: color🐼,
onFinalizedMergeTransitionBlock: blink🐼)
of StdoutLogKind.NoColors:
VanityLogs(
onMergeTransitionBlock: mono🐼,
onFinalizedMergeTransitionBlock: mono🐼)
of StdoutLogKind.Json, StdoutLogKind.None:
VanityLogs(
onMergeTransitionBlock: (proc() = notice "🐼 Proof of Stake Activated 🐼"),
onFinalizedMergeTransitionBlock: (proc() = notice "🐼 Proof of Stake Finalized 🐼"))
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
|: d$ $: $$ $b."P $: $$ $: "" [$: [$: Q$:$P $: $$ [$: $P.. $: Q$ .$$;
Pb"' $: $$ `""b. $$22$ $: mm [$: [$: Q$P $$$$$ [$: $b"" $: d$ `$:
|$b `Q$P' `MpM; $: $$ `Q$P' [$: $$$$$ `$' $: $$ [$: $$ETH $$$$' mm
SAUCE00 20220522@PIBM VGA
4 changes: 2 additions & 2 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ from
import
TopicParams, validateParameters, init

from consensus_object_pools/pandas/pandas import getPandas
from consensus_object_pools/vanity_logs/pandas import getPandas

when defined(windows):
import winlean
Expand Down Expand Up @@ -182,7 +182,7 @@ proc loadChainDag(
onLCOptimisticUpdateCb = onLightClientOptimisticUpdateCb,
serveLightClientData = config.serveLightClientData.get,
importLightClientData = config.importLightClientData.get,
pandaTexts = getPandas(detectTTY(config.logStdout)))
vanityLogs = getPandas(detectTTY(config.logStdout)))
databaseGenesisValidatorsRoot =
getStateField(dag.headState, genesis_validators_root)

Expand Down

0 comments on commit 3b3f417

Please sign in to comment.