Skip to content

Commit

Permalink
fork art feature
Browse files Browse the repository at this point in the history
Add the ability to have ascii fork art. Will read from a resource file called the fork name. If none exists, then it'll just do what's done today.

I added placeholders just using figlet output, but this should enable us to take community contributions for any kind of ascii upgrade things... we just want to make sure they're sensible as they'll go to screen.

Signed-off-by: Paul Harris <paul.harris@consensys.net>
  • Loading branch information
rolfyone committed Jan 17, 2025
1 parent 477080a commit c06f649
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@

import static com.google.common.base.Preconditions.checkState;

import com.google.common.io.Resources;
import java.nio.charset.StandardCharsets;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;
import java.util.stream.Stream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tech.pegasys.teku.infrastructure.bytes.Bytes4;
import tech.pegasys.teku.infrastructure.collections.TekuPair;
import tech.pegasys.teku.infrastructure.logging.EventLogger;
Expand All @@ -33,6 +38,7 @@
import tech.pegasys.teku.spec.datastructures.util.ForkAndSpecMilestone;

public class ForkSchedule {
private static final Logger LOG = LogManager.getLogger();
private final NavigableMap<UInt64, SpecMilestone> epochToMilestone;
private final NavigableMap<UInt64, SpecMilestone> slotToMilestone;
private final NavigableMap<UInt64, SpecMilestone> genesisOffsetToMilestone;
Expand Down Expand Up @@ -135,7 +141,16 @@ public void reportActivatingMilestones(final UInt64 epoch) {
if (activatingMilestone == null) {
return;
}
EventLogger.EVENT_LOG.networkUpgradeActivated(epoch, activatingMilestone.name());

final String resourceName = activatingMilestone.name().toLowerCase(Locale.ROOT) + ".txt";
String banner = "";
try {
banner =
Resources.toString(this.getClass().getResource(resourceName), StandardCharsets.UTF_8);

Check warning

Code scanning / CodeQL

Unsafe use of getResource Warning test

The idiom getClass().getResource() is unsafe for classes that may be extended.
} catch (Exception ex) {
LOG.debug("failed to read resource file", ex);
}
EventLogger.EVENT_LOG.networkUpgradeActivated(epoch, activatingMilestone.name(), banner);
}

public SpecMilestone getSpecMilestoneAtEpoch(final UInt64 epoch) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

_ _ _ _
/ \ | | |_ __ _(_)_ __
/ _ \ | | __/ _` | | '__|
/ ___ \| | || (_| | | |
/_/ \_\_|\__\__,_|_|_|
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

____ _ _ _ _
| __ ) ___| | | __ _| |_ _ __(_)_ __
| _ \ / _ \ | |/ _` | __| '__| \ \/ /
| |_) | __/ | | (_| | |_| | | |> <
|____/ \___|_|_|\__,_|\__|_| |_/_/\_\
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

____ _ _
/ ___|__ _ _ __ ___| | | __ _
| | / _` | '_ \ / _ \ | |/ _` |
| |__| (_| | |_) | __/ | | (_| |
\____\__,_| .__/ \___|_|_|\__,_|
|_|
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

____ _
| _ \ ___ _ __ ___| |__
| | | |/ _ \ '_ \ / _ \ '_ \
| |_| | __/ | | | __/ |_) |
|____/ \___|_| |_|\___|_.__/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

_____ _ _
| ____| | ___ ___| |_ _ __ __ _
| _| | |/ _ \/ __| __| '__/ _` |
| |___| | __/ (__| |_| | | (_| |
|_____|_|\___|\___|\__|_| \__,_|
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,20 @@ public void reorgEvent(
info(reorgEventLog, Color.YELLOW);
}

public void networkUpgradeActivated(final UInt64 nodeEpoch, final String upgradeName) {
info(
String.format(
"Milestone *** Epoch: %s, Activating network upgrade: %s", nodeEpoch, upgradeName),
Color.GREEN);
public void networkUpgradeActivated(
final UInt64 nodeEpoch, final String upgradeName, final String banner) {
if (banner.isEmpty()) {
info(
String.format(
"Milestone *** Epoch: %s, Activating network upgrade: %s", nodeEpoch, upgradeName),
Color.GREEN);
} else {
info(
String.format(
"Milestone *** Epoch: %s, Activating network upgrade: %s\n%s\n",
nodeEpoch, upgradeName, banner),
Color.GREEN);
}
}

public void terminalPowBlockDetected(final Bytes32 terminalBlockHash) {
Expand Down

0 comments on commit c06f649

Please sign in to comment.