Skip to content

Commit

Permalink
Checking correctness merging of master (from beginning to infrastruct…
Browse files Browse the repository at this point in the history
…ure module)
  • Loading branch information
zilm13 committed Oct 17, 2024
1 parent 89d4630 commit db7139e
Show file tree
Hide file tree
Showing 73 changed files with 1,477 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class DepositProviderBenchmark {
new DepositProvider(
metricsSystem,
mock(RecentChainData.class),
new Eth1DataCache(metricsSystem, new Eth1VotingPeriod(spec)),
new Eth1DataCache(spec, metricsSystem, new Eth1VotingPeriod(spec)),
mock(StorageUpdateChannel.class),
mock(Eth1DepositStorageChannel.class),
spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public void onSlot(final UInt64 slot) {
.get()
.thenAccept(
state -> {
if (spec.isFormerDepositMechanismDisabled(state)) {
return;
}
// We want to verify our Beacon Node view of the eth1 deposits.
// So we want to check if it has the necessary deposit data to propose a block
final UInt64 eth1DepositCount = state.getEth1Data().getDepositCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import tech.pegasys.teku.infrastructure.metrics.SettableGauge;
import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blocks.Eth1Data;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;

Expand All @@ -39,6 +40,7 @@ public class Eth1DataCache {
static final String VOTES_CURRENT_METRIC_NAME = "eth1_current_period_votes_current";
static final String VOTES_BEST_METRIC_NAME = "eth1_current_period_votes_best";

private final Spec spec;
private final Eth1VotingPeriod eth1VotingPeriod;
private final UInt64 cacheDuration;

Expand All @@ -50,7 +52,9 @@ public class Eth1DataCache {
private final SettableGauge currentPeriodVotesBest;
private final SettableGauge currentPeriodVotesMax;

public Eth1DataCache(final MetricsSystem metricsSystem, final Eth1VotingPeriod eth1VotingPeriod) {
public Eth1DataCache(
final Spec spec, final MetricsSystem metricsSystem, final Eth1VotingPeriod eth1VotingPeriod) {
this.spec = spec;
this.eth1VotingPeriod = eth1VotingPeriod;
cacheDuration = eth1VotingPeriod.getCacheDurationInSeconds();
metricsSystem.createIntegerGauge(
Expand Down Expand Up @@ -111,6 +115,10 @@ public void onEth1Block(
}

public Eth1Data getEth1Vote(final BeaconState state) {
if (spec.isFormerDepositMechanismDisabled(state)) {
// no need for a real vote when Eth1 polling has been disabled
return state.getEth1Data();
}
final NavigableMap<UInt64, Eth1Data> votesToConsider =
getVotesToConsider(state.getSlot(), state.getGenesisTime(), state.getEth1Data());
// Avoid using .values() directly as it has O(n) lookup which gets expensive fast
Expand All @@ -134,6 +142,10 @@ public Collection<Eth1Data> getAllEth1Blocks() {
}

public void updateMetrics(final BeaconState state) {
if (spec.isFormerDepositMechanismDisabled(state)) {
// no need to update metrics when Eth1 polling has been disabled
return;
}
final Eth1Data currentEth1Data = state.getEth1Data();
// Avoid using .values() directly as it has O(n) lookup which gets expensive fast
final Set<Eth1Data> knownBlocks =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void setUp() {
when(eth1VotingPeriod.getSpecRangeLowerBound(SLOT, GENESIS_TIME))
.thenReturn(VOTING_PERIOD_START);
when(eth1VotingPeriod.getSpecRangeUpperBound(SLOT, GENESIS_TIME)).thenReturn(VOTING_PERIOD_END);
eth1DataCache = new Eth1DataCache(metricsSystem, eth1VotingPeriod);
eth1DataCache = new Eth1DataCache(spec, metricsSystem, eth1VotingPeriod);
}

// Add tests for eth1 block with no votes
Expand Down Expand Up @@ -215,6 +215,17 @@ void noValidVotesInThisPeriod_eth1ChainNotLive() {
assertThat(eth1DataCache.getEth1Vote(beaconState)).isEqualTo(stateEth1Data);
}

@Test
void shouldReturnStateEth1Data_ifFormerDepositMechanismHasBeenDisabled() {
final Spec spec = mock(Spec.class);
eth1DataCache = new Eth1DataCache(spec, new StubMetricsSystem(), eth1VotingPeriod);
final BeaconState beaconState = createBeaconStateWithVotes(createEth1Data(STATE_DEPOSIT_COUNT));

when(spec.isFormerDepositMechanismDisabled(beaconState)).thenReturn(true);

assertThat(eth1DataCache.getEth1Vote(beaconState)).isEqualTo(beaconState.getEth1Data());
}

@Test
void shouldPruneOldBlocksWhenNewerOnesReceived() {
final UInt64 olderBlockTimestamp = ZERO;
Expand Down Expand Up @@ -254,6 +265,24 @@ void shouldUpdateMetrics() {
assertGaugeValue(Eth1DataCache.VOTES_BEST_METRIC_NAME, 4);
}

@Test
void shouldNotUpdateMetrics_ifFormerDepositMechanismHasBeenDisabled() {
final Spec spec = mock(Spec.class);
eth1DataCache = new Eth1DataCache(spec, new StubMetricsSystem(), eth1VotingPeriod);
final BeaconState beaconState = getStateForMetricsAssertions();

when(spec.isFormerDepositMechanismDisabled(beaconState)).thenReturn(true);

eth1DataCache.updateMetrics(beaconState);

// all gauge values are 0
assertGaugeValue(Eth1DataCache.VOTES_TOTAL_METRIC_NAME, 0);
assertGaugeValue(Eth1DataCache.VOTES_MAX_METRIC_NAME, 0);
assertGaugeValue(Eth1DataCache.VOTES_UNKNOWN_METRIC_NAME, 0);
assertGaugeValue(Eth1DataCache.VOTES_CURRENT_METRIC_NAME, 0);
assertGaugeValue(Eth1DataCache.VOTES_BEST_METRIC_NAME, 0);
}

@Test
void shouldIncludeUnknownBlocksWhenCalculatingVoteBestMetric() {
// Metric needs to indicate when a block will be voted in which happens even when unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void setup() {
assertThat(slotsInVotingPeriod).isEqualTo(SLOTS_IN_VOTING_PERIOD_ASSERTION);

final Eth1VotingPeriod eth1VotingPeriod = new Eth1VotingPeriod(spec);
final Eth1DataCache eth1DataCache = new Eth1DataCache(metricsSystem, eth1VotingPeriod);
final Eth1DataCache eth1DataCache = new Eth1DataCache(spec, metricsSystem, eth1VotingPeriod);
final DepositProvider depositProvider =
new DepositProvider(
new StubMetricsSystem(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"in" : "header",
"schema" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "eip7594" ],
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
"description" : "Version of the block being submitted, if using SSZ encoding."
}
} ],
Expand All @@ -37,7 +37,7 @@
}, {
"$ref" : "#/components/schemas/SignedBlockContentsDeneb"
}, {
"$ref" : "#/components/schemas/SignedBlockContentsEip7594"
"$ref" : "#/components/schemas/SignedBlockContentsElectra"
} ]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"bellatrix",
"capella",
"deneb",
"eip7594"
"electra"
]
},
"data": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title" : "BlindedBlockEip7594",
"title" : "BeaconBlockElectra",
"type" : "object",
"required" : [ "slot", "proposer_index", "parent_root", "state_root", "body" ],
"properties" : {
Expand Down Expand Up @@ -28,7 +28,7 @@
"format" : "byte"
},
"body" : {
"$ref" : "#/components/schemas/BlindedBlockBodyEip7594"
"$ref" : "#/components/schemas/BeaconBlockBodyElectra"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title" : "BeaconStateElectra",
"type" : "object",
"required" : [ "genesis_time", "genesis_validators_root", "slot", "fork", "latest_block_header", "block_roots", "state_roots", "historical_roots", "eth1_data", "eth1_data_votes", "eth1_deposit_index", "validators", "balances", "randao_mixes", "slashings", "previous_epoch_participation", "current_epoch_participation", "justification_bits", "previous_justified_checkpoint", "current_justified_checkpoint", "finalized_checkpoint", "inactivity_scores", "current_sync_committee", "next_sync_committee", "latest_execution_payload_header", "next_withdrawal_index", "next_withdrawal_validator_index", "historical_summaries", "deposit_requests_start_index", "deposit_balance_to_consume", "exit_balance_to_consume", "earliest_exit_epoch", "consolidation_balance_to_consume", "earliest_consolidation_epoch", "pending_balance_deposits", "pending_partial_withdrawals", "pending_consolidations" ],
"required" : [ "genesis_time", "genesis_validators_root", "slot", "fork", "latest_block_header", "block_roots", "state_roots", "historical_roots", "eth1_data", "eth1_data_votes", "eth1_deposit_index", "validators", "balances", "randao_mixes", "slashings", "previous_epoch_participation", "current_epoch_participation", "justification_bits", "previous_justified_checkpoint", "current_justified_checkpoint", "finalized_checkpoint", "inactivity_scores", "current_sync_committee", "next_sync_committee", "latest_execution_payload_header", "next_withdrawal_index", "next_withdrawal_validator_index", "historical_summaries", "deposit_requests_start_index", "deposit_balance_to_consume", "exit_balance_to_consume", "earliest_exit_epoch", "consolidation_balance_to_consume", "earliest_consolidation_epoch", "pending_deposits", "pending_partial_withdrawals", "pending_consolidations" ],
"properties" : {
"genesis_time" : {
"type" : "string",
Expand Down Expand Up @@ -207,10 +207,10 @@
"example" : "1",
"format" : "uint64"
},
"pending_balance_deposits" : {
"pending_deposits" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/PendingBalanceDeposit"
"$ref" : "#/components/schemas/PendingDeposit"
}
},
"pending_partial_withdrawals" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"title" : "BlindedBlockElectra",
"type" : "object",
"required" : [ "slot", "proposer_index", "parent_root", "state_root", "body" ],
"properties" : {
"slot" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"proposer_index" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"parent_root" : {
"type" : "string",
"description" : "Bytes32 hexadecimal",
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
},
"state_root" : {
"type" : "string",
"description" : "Bytes32 hexadecimal",
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
},
"body" : {
"$ref" : "#/components/schemas/BlindedBlockBodyElectra"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"title" : "BlockContentsEip7594",
"title" : "BlockContentsElectra",
"type" : "object",
"required" : [ "block", "kzg_proofs", "blobs" ],
"properties" : {
"block" : {
"$ref" : "#/components/schemas/BeaconBlockEip7594"
"$ref" : "#/components/schemas/BeaconBlockElectra"
},
"kzg_proofs" : {
"type" : "array",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
{
<<<<<<<< HEAD:data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/schema/DepositRequest.json
"title" : "DepositRequest",
========
"title" : "BeaconBlockEip7594",
>>>>>>>> das:data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/schema/BeaconBlockEip7594.json
"type" : "object",
"required" : [ "slot", "proposer_index", "parent_root", "state_root", "body" ],
"required" : [ "pubkey", "withdrawal_credentials", "amount", "signature", "index" ],
"properties" : {
"slot" : {
"pubkey" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
"pattern" : "^0x[a-fA-F0-9]{2,}$",
"description" : "Bytes48 hexadecimal",
"format" : "bytes"
},
"proposer_index" : {
"withdrawal_credentials" : {
"type" : "string",
"description" : "Bytes32 hexadecimal",
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
},
"amount" : {
"type" : "string",
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
},
"parent_root" : {
"signature" : {
"type" : "string",
"description" : "Bytes32 hexadecimal",
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
"pattern" : "^0x[a-fA-F0-9]{2,}$",
"description" : "SSZ hexadecimal",
"format" : "bytes"
},
"state_root" : {
"index" : {
"type" : "string",
"description" : "Bytes32 hexadecimal",
"example" : "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
"format" : "byte"
},
"body" : {
"$ref" : "#/components/schemas/BeaconBlockBodyEip7594"
"description" : "unsigned 64 bit integer",
"example" : "1",
"format" : "uint64"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"properties" : {
"version" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "eip7594" ]
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ]
},
"data" : {
"type" : "array",
Expand All @@ -27,7 +27,7 @@
}, {
"$ref" : "#/components/schemas/BeaconBlockDeneb"
}, {
"$ref" : "#/components/schemas/BeaconBlockEip7594"
"$ref" : "#/components/schemas/BeaconBlockElectra"
} ]
},
"signature" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"properties" : {
"version" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "eip7594" ]
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ]
},
"execution_optimistic" : {
"type" : "boolean"
Expand All @@ -27,7 +27,7 @@
}, {
"$ref" : "#/components/schemas/SignedBlindedBlockDeneb"
}, {
"$ref" : "#/components/schemas/SignedBlindedBlockEip7594"
"$ref" : "#/components/schemas/SignedBlindedBlockElectra"
} ]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"properties" : {
"version" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "eip7594" ]
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ]
},
"execution_optimistic" : {
"type" : "boolean"
Expand All @@ -27,7 +27,7 @@
}, {
"$ref" : "#/components/schemas/SignedBeaconBlockDeneb"
}, {
"$ref" : "#/components/schemas/SignedBeaconBlockEip7594"
"$ref" : "#/components/schemas/SignedBeaconBlockElectra"
} ]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"properties" : {
"version" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "eip7594" ]
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ]
},
"data" : {
"$ref" : "#/components/schemas/LightClientBootstrap"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"properties" : {
"version" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "eip7594" ]
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ]
},
"execution_optimistic" : {
"type" : "boolean"
Expand All @@ -27,7 +27,7 @@
}, {
"$ref" : "#/components/schemas/BeaconStateDeneb"
}, {
"$ref" : "#/components/schemas/BeaconStateEip7594"
"$ref" : "#/components/schemas/BeaconStateElectra"
} ]
}
}
Expand Down
Loading

0 comments on commit db7139e

Please sign in to comment.