Skip to content

Commit

Permalink
debug command to see what values are in variables
Browse files Browse the repository at this point in the history
Probably incomplete, but the state variable was unset, and I was looking at what other values were in a broken database.

Probably worth keeping for next time.

Signed-off-by: Paul Harris <[email protected]>
  • Loading branch information
rolfyone committed Jan 24, 2025
1 parent 2b37b47 commit 08fb923
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ default Stream<SlotAndBlockRootAndBlobIndex> streamBlobSidecarKeys(final UInt64

Map<String, Long> getColumnCounts(final Optional<String> maybeColumnFilter);

Map<String, Optional<String>> getVariables();

long getBlobSidecarColumnCount();

long getNonCanonicalBlobSidecarColumnCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ public Map<String, Long> getColumnCounts(final Optional<String> maybeColumnFilte
return dao.getColumnCounts(maybeColumnFilter);
}

@Override
public Map<String, Optional<String>> getVariables() {
return dao.getVariables();
}

@Override
public long getBlobSidecarColumnCount() {
return dao.getBlobSidecarColumnCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public CombinedKvStoreDao(

@Override
public Optional<UInt64> getGenesisTime() {
return db.get(schema.getVariableGenesisTime());
try {
return db.get(schema.getVariableGenesisTime());
} catch (final Exception e) {
return Optional.empty();
}
}

@Override
Expand Down Expand Up @@ -432,6 +436,37 @@ public Map<String, Long> getColumnCounts(final Optional<String> maybeColumnFilte
return columnCounts;
}

@Override
public Map<String, Optional<String>> getVariables() {
Map<String, Optional<String>> variables = new LinkedHashMap<>();
variables.put("GENESIS_TIME", getGenesisTime().map(UInt64::toString));
variables.put("JUSTIFIED_CHECKPOINT", getJustifiedCheckpoint().map(Checkpoint::toString));
variables.put(
"BEST_JUSTIFIED_CHECKPOINT", getBestJustifiedCheckpoint().map(Checkpoint::toString));
variables.put("FINALIZED_CHECKPOINT", getFinalizedCheckpoint().map(Checkpoint::toString));
variables.put(
"WEAK_SUBJECTIVITY_CHECKPOINT", getWeakSubjectivityCheckpoint().map(Checkpoint::toString));
variables.put("ANCHOR_CHECKPOINT", getAnchor().map(Checkpoint::toString));
variables.put(
"FINALIZED_DEPOSIT_SNAPSHOT",
getFinalizedDepositSnapshot().map(DepositTreeSnapshot::toString));
try {
variables.put(
"LATEST_FINALIZED_STATE",
getLatestFinalizedState()
.map(
state ->
"BeaconState{slot="
+ state.getSlot()
+ ", root="
+ state.hashTreeRoot().toHexString()
+ "}"));
} catch (final Exception e) {
variables.put("FINALIZED_STATE", Optional.of(e.toString()));
}
return variables;
}

@Override
public long getBlobSidecarColumnCount() {
final KvStoreColumn<?, ?> column =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ List<SlotAndBlockRootAndBlobIndex> getNonCanonicalBlobSidecarKeys(

Map<String, Long> getColumnCounts(final Optional<String> maybeColumnFilter);

Map<String, Optional<String>> getVariables();

long getBlobSidecarColumnCount();

long getNonCanonicalBlobSidecarColumnCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ public Map<String, Long> getColumnCounts(final Optional<String> maybeColumnFilte
return result;
}

@Override
public Map<String, Optional<String>> getVariables() {
return Map.of();
}

@Override
public long getBlobSidecarColumnCount() {
return finalizedDao.getBlobSidecarColumnCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ public Map<String, Long> getColumnCounts(final Optional<String> maybeColumnFilte
return new HashMap<>();
}

@Override
public Map<String, Optional<String>> getVariables() {
return new HashMap<>();
}

@Override
public long getBlobSidecarColumnCount() {
return 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,40 @@ public int getColumnCounts(
return 0;
}

@Command(
name = "get-variables",
description = "Check variable values",
mixinStandardHelpOptions = true,
showDefaultValues = true,
abbreviateSynopsis = true,
versionProvider = PicoCliVersionProvider.class,
synopsisHeading = "%n",
descriptionHeading = "%nDescription:%n%n",
optionListHeading = "%nOptions:%n",
footerHeading = "%n",
footer = "Teku is licensed under the Apache License 2.0")
public int getVariables(
@Mixin final BeaconNodeDataOptions beaconNodeDataOptions,
@Mixin final Eth2NetworkOptions eth2NetworkOptions,
@Option(
names = {"--filter"},
description = "Only get variables that match a given filter.")
final String filter)
throws Exception {
try (final Database database = createDatabase(beaconNodeDataOptions, eth2NetworkOptions)) {
final Map<String, Optional<String>> variables = database.getVariables();
variables
.keySet()
.forEach(
k -> {
if (filter == null || k.contains(filter)) {
System.out.printf("%-30s: %s\n", k, variables.get(k).orElse("EMPTY"));
}
});
}
return 0;
}

@Command(
name = "validate-block-history",
description = "Validate the chain of finalized blocks via parent references",
Expand Down

0 comments on commit 08fb923

Please sign in to comment.