From 01534b04316b97c0b11205eb5215fab36e9d62e9 Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 30 May 2022 08:25:27 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=BC=20(#3670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐼 * rm panda refs outside core module; preprocess text/ANSI artwork sources * credit artwork to beatscribe --- .../block_pools_types.nim | 10 ++++- .../consensus_object_pools/blockchain_dag.nim | 21 +++++++++- .../vanity_logs/blink-version.ans | 31 +++++++++++++++ .../vanity_logs/color-version.ans | 31 +++++++++++++++ .../vanity_logs/pandas.nim | 38 +++++++++++++++++++ .../vanity_logs/text-version.txt | 31 +++++++++++++++ beacon_chain/nimbus_beacon_node.nim | 5 ++- beacon_chain/nimbus_binary_common.nim | 28 +++++++------- 8 files changed, 179 insertions(+), 16 deletions(-) create mode 100644 beacon_chain/consensus_object_pools/vanity_logs/blink-version.ans create mode 100644 beacon_chain/consensus_object_pools/vanity_logs/color-version.ans create mode 100644 beacon_chain/consensus_object_pools/vanity_logs/pandas.nim create mode 100644 beacon_chain/consensus_object_pools/vanity_logs/text-version.txt diff --git a/beacon_chain/consensus_object_pools/block_pools_types.nim b/beacon_chain/consensus_object_pools/block_pools_types.nim index f8e0f96f2..84b6e58ea 100644 --- a/beacon_chain/consensus_object_pools/block_pools_types.nim +++ b/beacon_chain/consensus_object_pools/block_pools_types.nim @@ -19,9 +19,11 @@ import ../validators/validator_monitor, ./block_dag, block_pools_types_light_client +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 + 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 @@ -200,6 +202,12 @@ type ## value with other components which don't have access to the ## full ChainDAG. + 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 diff --git a/beacon_chain/consensus_object_pools/blockchain_dag.nim b/beacon_chain/consensus_object_pools/blockchain_dag.nim index dc132058c..031759695 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag.nim @@ -663,7 +663,8 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB, onLCFinalityUpdateCb: OnLightClientFinalityUpdateCallback = nil, onLCOptimisticUpdateCb: OnLightClientOptimisticUpdateCallback = nil, serveLightClientData = false, - importLightClientData = ImportLightClientData.None): ChainDAGRef = + importLightClientData = ImportLightClientData.None, + vanityLogs = default(VanityLogs)): ChainDAGRef = # TODO move fork version sanity checking elsewhere? let forkVersions = [cfg.GENESIS_FORK_VERSION, cfg.ALTAIR_FORK_VERSION, @@ -705,6 +706,8 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB, updateFlags: {verifyFinalization} * updateFlags, cfg: cfg, + vanityLogs: vanityLogs, + serveLightClientData: serveLightClientData, importLightClientData: importLightClientData, @@ -1547,8 +1550,16 @@ proc updateHead*( error "Cannot update head to block without parent" return + template getHeadStateMergeComplete(): bool = + withState(dag.headState): + when stateFork >= BeaconStateFork.Bellatrix: + is_merge_transition_complete(state.data) + else: + false + let lastHeadStateRoot = getStateRoot(dag.headState) + lastHeadMergeComplete = getHeadStateMergeComplete() # Start off by making sure we have the right state - updateState will try # to use existing in-memory states to make this smooth @@ -1562,8 +1573,12 @@ proc updateHead*( fatal "Unable to load head state during head update, database corrupt?", lastHead = shortLog(lastHead) quit 1 + dag.head = newHead + if getHeadStateMergeComplete() and not lastHeadMergeComplete: + dag.vanityLogs.onMergeTransitionBlock() + dag.db.putHeadBlock(newHead.root) updateBeaconMetrics(dag.headState, dag.head.bid, cache) @@ -1659,6 +1674,10 @@ proc updateHead*( dag.db.updateFinalizedBlocks(newFinalized) + if oldFinalizedHead.blck.executionBlockRoot.isZero and + not dag.finalizedHead.blck.executionBlockRoot.isZero: + 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 # therefore no longer be considered as part of the chain we're following diff --git a/beacon_chain/consensus_object_pools/vanity_logs/blink-version.ans b/beacon_chain/consensus_object_pools/vanity_logs/blink-version.ans new file mode 100644 index 000000000..6b3f1d8b5 --- /dev/null +++ b/beacon_chain/consensus_object_pools/vanity_logs/blink-version.ans @@ -0,0 +1,31 @@ +. +.: ___ + ` ___ :._ \.\\ ) ) . +\\ .)`\ )\ \ \ ./') / ; ; +)`/  `\/ (''('('/ '` (.__/\ + ./'' dMb  " " " ,mMm   / +  . (  d;::`bmd""""""""""""bd':::`. (' . +. \ {::::;.;;;)  ) . + ../: } `;;' .:::. .::::. ;.;'  { . \.   . + `.// \\ {' d'' ::(*): :(*):: \.  `}// \\   ; +)\ . (e`\ /'; \ |:::::' `:::::| ./'{ /' ) /( +` / /' ; \th(.{ } |`::;'______`:::'| { \^/'  / /^'\ \ , + ; ( ( (| `)\ \`\' |`" :_ _; "'| ` /' { / ( ( ( ; + /| `.`\ \`\| `\) ` `b||d' '\`\ \`.\ \. +( `\. \ `\) .  md$n`-_+'`+_-'d$b.'  (/' / ./' ) + \. `\ |  ; .  ...;;;;;;` m `=='m ' ;;;..  .  | /' ./ + ` \. `' .;;;;;:::;:::;::::.......;::::::::::::;;;.   '' ./ . + ; \ `. .::;::::;:'' """""""""""""""" `:::;:::'.   / ; + ( \/'/:::::;:::'    . . `:::;:;::\  :  `\/ ) + :  \  ./;:::;::::' mm.   | :  .mm: `::;:;:;:;    . / +  . .'./;;:::Mmmm;;;;;/'::|   || :: |:: \_:::::mmm:::";\  .  b`. . +  /\ ;n  |::::::::;:`"""::;:/   ||| ::: \::::'"""'::;:;;:;:|   ea; / + { `'i  |::;::::;::::;:;::{   ||\\ //::  };;::;:::;:;;::;::| ' `t'', + ./ . m'   `::::;::::;::::;:;\  |\\\\ ////:  /::::;:::;::::::::;`;sc( + } b.  .  """mm:::::::::::\_} .. \\ // .. {_::::::::::::mm""" . .  `ri) + / .:/ us.. .' . """"mmmmPQ._:) `::.. ..:;' (-:::QPmmmm""" .: .  . ; `be +  `' `:: ::'  `" + QM$Mb .d$b. .d$b. .d$b. .d$b. $$$$$ $\ /$ $: $$ .d$b. $$$$$ $$$$$ $$$b. d$P + |: d$ $: $$ $b."P $: $$ $: "" [$: [$: Q$:$P $: $$  [$: $P.. $: Q$ .$$; + Pb"' $: $$ `""b. $$22$ $: mm [$:  [$: Q$P $$$$$ [$: $b"" $: d$ `$: + |$b `Q$P' `MpM; $: $$ `Q$P' [$: $$$$$ `$' $: $$ [$: $$ETH $$$$' mm diff --git a/beacon_chain/consensus_object_pools/vanity_logs/color-version.ans b/beacon_chain/consensus_object_pools/vanity_logs/color-version.ans new file mode 100644 index 000000000..d8c77abab --- /dev/null +++ b/beacon_chain/consensus_object_pools/vanity_logs/color-version.ans @@ -0,0 +1,31 @@ +. +.: ___ + ` ___ :._ \.\\ ) ) . +\\ .)`\ )\ \ \ ./') / ; ; +)`/  `\/ (''('('/ '` (.__/\ + ./'' dMb  " " " ,mMm   / +  . (  d;::`bmd""""""""""""bd':::`. (' . +. \ {::::;.;;;)  ) . + ../: } `;;' .:::. .::::. ;.;'  { . \.   . + `.// \\ {' d'' ::(*): :(*):: \.  `}// \\   ; +)\ . (e`\ /'; \ |:::::' `:::::| ./'{ /' ) /( +` / /' ; \th(.{ } |`::;'______`:::'| { \^/'  / /^'\ \ , + ; ( ( (| `)\ \`\' |`" :_ _; "'| ` /' { / ( ( ( ; + /| `.`\ \`\| `\) ` `b||d' '\`\ \`.\ \. +( `\. \ `\) .  md$n`-_+'`+_-'d$b.'  (/' / ./' ) + \. `\ |  ; .  ...;;;;;;` m `=='m ' ;;;..  .  | /' ./ + ` \. `' .;;;;;:::;:::;::::.......;::::::::::::;;;.   '' ./ . + ; \ `. .::;::::;:'' """""""""""""""" `:::;:::'.   / ; + ( \/'/:::::;:::'    . . `:::;:;::\  :  `\/ ) + :  \  ./;:::;::::' mm.   | :  .mm: `::;:;:;:;    . / +  . .'./;;:::Mmmm;;;;;/'::|   || :: |:: \_:::::mmm:::";\  .  b`. . +  /\ ;n  |::::::::;:`"""::;:/   ||| ::: \::::'"""'::;:;;:;:|   ea; / + { `'i  |::;::::;::::;:;::{   ||\\ //::  };;::;:::;:;;::;::| ' `t'', + ./ . m'   `::::;::::;::::;:;\  |\\\\ ////:  /::::;:::;::::::::;`;sc( + } b.  .  """mm:::::::::::\_} .. \\ // .. {_::::::::::::mm""" . .  `ri) + / .:/ us.. .' . """"mmmmPQ._:) `::.. ..:;' (-:::QPmmmm""" .: .  . ; `be +  `' `:: ::'  `" + QM$Mb .d$b. .d$b. .d$b. .d$b. $$$$$ $\ /$ $: $$ .d$b. $$$$$ $$$$$ $$$b. d$P + |: d$ $: $$ $b."P $: $$ $: "" [$: [$: Q$:$P $: $$  [$: $P.. $: Q$ .$$; + Pb"' $: $$ `""b. $$22$ $: mm [$:  [$: Q$P $$$$$ [$: $b"" $: d$ `$: + |$b `Q$P' `MpM; $: $$ `Q$P' [$: $$$$$ `$' $: $$ [$: $$ETH $$$$' mm diff --git a/beacon_chain/consensus_object_pools/vanity_logs/pandas.nim b/beacon_chain/consensus_object_pools/vanity_logs/pandas.nim new file mode 100644 index 000000000..e69f41e97 --- /dev/null +++ b/beacon_chain/consensus_object_pools/vanity_logs/pandas.nim @@ -0,0 +1,38 @@ +# 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].} + +# Created by http://beatscribe.com/ (beatscribe#1008 on Discord) +# 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 🐼")) diff --git a/beacon_chain/consensus_object_pools/vanity_logs/text-version.txt b/beacon_chain/consensus_object_pools/vanity_logs/text-version.txt new file mode 100644 index 000000000..a5c218da7 --- /dev/null +++ b/beacon_chain/consensus_object_pools/vanity_logs/text-version.txt @@ -0,0 +1,31 @@ + . + . : ___ + ` ___ :._ \. \\ ) ) . + \\ .)`\ )\ \ \ ./') / ; ; + )`/ `\/ (''('('/ '` (.__/\ + . /'' dMb " " " ,mMm / + . ( d;::`bmd""""""""""""bd':::`. (' . + . \ {::::; .;;;) ) . + . ./: } `;;' .:::. .::::. ;.;' { . \. . + `. // \\ {' d'' ::(*): :(*):: \. `}// \\ ; + )\ . (e`\ /'; \ | :::::' `::::: | ./'{ /' ) /( + ` / /' ; \th(.{ } | `::;'______`:::' | { \^/' / /^'\ \ , + ; ( ( (| `)\ \`\' | `" :_ _; "' | ` /' { / ( ( ( ; + /| `.`\ \`\| `\) ` `b || d' ' \`\ \`.\ \. + ( `\. \ `\) . md$n `-_+'`+_-' d$b. ' (/' / ./' ) + \. `\ | ; . ...;;;;;;` m `==' m ' ;;;.. . | /' ./ + ` \. `' .;;;;;:::;:::;::::.......;::::::::::::;;;. '' ./ . + ; \ `. .::;::::;:'' """""""""""""""" `:::;:::'. / ; + ( \/' /:::::;:::' . . `:::;:;::\ : `\/ ) + : \ . /;:::;::::' mm. | : .mm: `::;:;:;:; . / + . .'. /;;:::Mmmm;;;;;/'::| || :: |:: \_:::::mmm:::";\ . b`. . + /\ ;n |::::::::;:`"""::;:/ ||| ::: \::::'"""'::;:;;:;:| ea; / + { `'i |::;::::;::::;:;::{ ||\\ //:: };;::;:::;:;;::;::| ' `t'', + ./ . m' `::::;::::;::::;:;\ |\\\\ ////: /::::;:::;::::::::;` ;sc( + } b. . """mm:::::::::::\_} .. \\ // .. {_::::::::::::mm""" . . `ri) + / .:/ us.. .' . """"mmmmPQ._:) `::.. ..:;' (-:::QPmmmm""" .: . . ; `be + `' `:: ::' `" + QM$Mb .d$b. .d$b. .d$b. .d$b. $$$$$ $\ /$ $: $$ .d$b. $$$$$ $$$$$ $$$b. d$P + |: d$ $: $$ $b."P $: $$ $: "" [$: [$: Q$:$P $: $$ [$: $P.. $: Q$ .$$; + Pb"' $: $$ `""b. $$22$ $: mm [$: [$: Q$P $$$$$ [$: $b"" $: d$ `$: + |$b `Q$P' `MpM; $: $$ `Q$P' [$: $$$$$ `$' $: $$ [$: $$ETH $$$$' mm diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 37dffce8f..3d90bc492 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -30,6 +30,8 @@ from import TopicParams, validateParameters, init +from consensus_object_pools/vanity_logs/pandas import getPandas + when defined(windows): import winlean @@ -179,7 +181,8 @@ proc loadChainDag( onLCFinalityUpdateCb = onLightClientFinalityUpdateCb, onLCOptimisticUpdateCb = onLightClientOptimisticUpdateCb, serveLightClientData = config.serveLightClientData.get, - importLightClientData = config.importLightClientData.get) + importLightClientData = config.importLightClientData.get, + vanityLogs = getPandas(detectTTY(config.logStdout))) databaseGenesisValidatorsRoot = getStateField(dag.headState, genesis_validators_root) diff --git a/beacon_chain/nimbus_binary_common.nim b/beacon_chain/nimbus_binary_common.nim index bdf57fa8a..2ecda64e7 100644 --- a/beacon_chain/nimbus_binary_common.nim +++ b/beacon_chain/nimbus_binary_common.nim @@ -1,5 +1,5 @@ # beacon_chain -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-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). @@ -83,6 +83,19 @@ proc updateLogLevel*(logLevel: string) {.raises: [Defect, ValueError].} = if not setTopicState(topicName, settings.state, settings.logLevel): warn "Unrecognized logging topic", topic = topicName +proc detectTTY*(stdoutKind: StdoutLogKind): StdoutLogKind = + if stdoutKind == StdoutLogKind.Auto: + if isatty(stdout): + # On a TTY, let's be fancy + StdoutLogKind.Colors + else: + # When there's no TTY, we output no colors because this matches what + # released binaries were doing before auto-detection was around and + # looks decent in systemd-captured journals. + StdoutLogKind.NoColors + else: + stdoutKind + proc setupLogging*( logLevel: string, stdoutKind: StdoutLogKind, logFile: Option[OutFile]) = # In the cfg file for nimbus, we create two formats: textlines and json. @@ -135,18 +148,7 @@ proc setupLogging*( defaultChroniclesStream.outputs[1].writer = fileWriter - let tmp = - if stdoutKind == StdoutLogKind.Auto: - if isatty(stdout): - # On a TTY, let's be fancy - StdoutLogKind.Colors - else: - # When there's no TTY, we output no colors because this matches what - # released binaries were doing before auto-detection was around and - # looks decent in systemd-captured journals. - StdoutLogKind.NoColors - else: - stdoutKind + let tmp = detectTTY(stdoutKind) case tmp of StdoutLogKind.Auto: raiseAssert "checked above"