Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐼 #3670

Merged
merged 3 commits into from
May 30, 2022
Merged

🐼 #3670

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion beacon_chain/consensus_object_pools/block_pools_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -705,6 +706,8 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
updateFlags: {verifyFinalization} * updateFlags,
cfg: cfg,

vanityLogs: vanityLogs,

serveLightClientData: serveLightClientData,
importLightClientData: importLightClientData,

Expand Down Expand Up @@ -1547,8 +1550,16 @@ proc updateHead*(
error "Cannot update head to block without parent"
return

template getHeadStateMergeComplete(): bool =
etan-status marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions beacon_chain/consensus_object_pools/vanity_logs/blink-version.ans
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions beacon_chain/consensus_object_pools/vanity_logs/color-version.ans
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 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,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 🐼"))
31 changes: 31 additions & 0 deletions beacon_chain/consensus_object_pools/vanity_logs/text-version.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ from
import
TopicParams, validateParameters, init

from consensus_object_pools/vanity_logs/pandas import getPandas

when defined(windows):
import winlean

Expand Down Expand Up @@ -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)

Expand Down
28 changes: 15 additions & 13 deletions beacon_chain/nimbus_binary_common.nim
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down