Skip to content

Commit

Permalink
better way
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Oct 20, 2023
1 parent 45901f3 commit e9d0726
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.kzg.KZGProof;
import tech.pegasys.teku.reference.TestDataUtils;
import tech.pegasys.teku.reference.TestExecutor;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.SpecVersion;
import tech.pegasys.teku.spec.datastructures.attestation.ValidatableAttestation;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock;
Expand All @@ -63,7 +66,9 @@
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannelStub;
import tech.pegasys.teku.spec.executionlayer.ExecutionPayloadStatus;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers;
import tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult;
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoice;
import tech.pegasys.teku.statetransition.forkchoice.ForkChoiceStateProvider;
import tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator;
Expand Down Expand Up @@ -156,6 +161,8 @@ spec, new SignedBlockAndState(anchorBlock, anchorState)),
+ "\nProtoarray data:\n"
+ protoArrayData,
e);
} finally {
freeTrustedSetupIfRequired(spec);
}
}

Expand Down Expand Up @@ -482,6 +489,14 @@ private void assertCheckpoint(
.isEqualTo(new Checkpoint(expectedEpoch, expectedRoot));
}

private void freeTrustedSetupIfRequired(final Spec spec) {
Optional.ofNullable(spec.forMilestone(SpecMilestone.DENEB))
.map(SpecVersion::miscHelpers)
.flatMap(MiscHelpers::toVersionDeneb)
.map(MiscHelpersDeneb::getKzg)
.ifPresent(KZG::freeTrustedSetup);
}

@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
private static <T> T get(final Map<String, Object> yamlData, final String key) {
return (T) yamlData.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ private static KZG initKZG(final SpecConfigDeneb config) {
return kzg;
}

public KZG getKzg() {
return kzg;
}

/**
* Performs complete data availability check <a
* href="https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/fork-choice.md#is_data_available">is_data_available</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ public synchronized void loadTrustedSetup(final String trustedSetupFile) throws
}

try {
// allow loading different trusted setup
loadedTrustedSetupFile.ifPresent(
currentTrustedSetupFile -> {
LOG.debug(
"Replacing current trusted setup {} with {}",
currentTrustedSetupFile,
trustedSetupFile);
freeTrustedSetup();
});
final TrustedSetup trustedSetup = CKZG4844Utils.parseTrustedSetupFile(trustedSetupFile);
final List<Bytes> g1Points = trustedSetup.g1Points();
final List<Bytes> g2Points = trustedSetup.g2Points();
Expand Down

0 comments on commit e9d0726

Please sign in to comment.