From 1ff5f21bb22d2388e931c960c7d807b8e64ff6c6 Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Tue, 3 Dec 2024 14:28:20 +1000 Subject: [PATCH 1/5] Updated consolidation rules for devnet5 - updated fuzzUtil to use prettyJson to report diffs for the tests that broke... - currently the fuzz utils need some changes, will just raise a draft until we're ready... fixes #8875 Signed-off-by: Paul Harris --- .../electra/block/BlockProcessorElectra.java | 9 +---- .../spec/config/presets/mainnet/electra.yaml | 2 +- .../spec/config/presets/minimal/electra.yaml | 2 +- .../spec/config/presets/swift/electra.yaml | 2 +- fuzz/build.gradle | 2 + .../tech/pegasys/teku/fuzz/FuzzUtilTest.java | 38 ++++++++++++------- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index 49493302242..8430a95ab49 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -490,8 +490,8 @@ private void processConsolidationRequest( return; } - // Verify that target has execution withdrawal credentials - if (!predicatesElectra.hasExecutionWithdrawalCredential(targetValidator)) { + // Verify that target has compounding withdrawal credentials + if (!predicatesElectra.hasCompoundingWithdrawalCredential(targetValidator)) { LOG.debug("process_consolidation_request: invalid target credentials"); return; } @@ -545,11 +545,6 @@ private void processConsolidationRequest( SszUInt64.of(UInt64.valueOf(targetValidatorIndex))); state.getPendingConsolidations().append(pendingConsolidation); - // Churn any target excess active balance of target and raise its max - if (predicatesElectra.hasEth1WithdrawalCredential(targetValidator)) { - beaconStateMutatorsElectra.switchToCompoundingValidator(state, targetValidatorIndex); - } - LOG.debug("process_consolidation_request: created {}", pendingConsolidation); } diff --git a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/electra.yaml b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/electra.yaml index 0b594ff3404..4bb3ebe2fe5 100644 --- a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/electra.yaml +++ b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/mainnet/electra.yaml @@ -30,7 +30,7 @@ MAX_ATTESTER_SLASHINGS_ELECTRA: 1 # `uint64(2**3)` (= 8) MAX_ATTESTATIONS_ELECTRA: 8 # `uint64(2**0)` (= 1) -MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1 +MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2 # Execution # --------------------------------------------------------------- diff --git a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/electra.yaml b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/electra.yaml index 71adaa4aaa0..c87a328472f 100644 --- a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/electra.yaml +++ b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/minimal/electra.yaml @@ -30,7 +30,7 @@ MAX_ATTESTER_SLASHINGS_ELECTRA: 1 # `uint64(2**3)` (= 8) MAX_ATTESTATIONS_ELECTRA: 8 # `uint64(2**0)` (= 1) -MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1 +MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2 # Execution # --------------------------------------------------------------- diff --git a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/electra.yaml b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/electra.yaml index 71adaa4aaa0..c87a328472f 100644 --- a/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/electra.yaml +++ b/ethereum/spec/src/main/resources/tech/pegasys/teku/spec/config/presets/swift/electra.yaml @@ -30,7 +30,7 @@ MAX_ATTESTER_SLASHINGS_ELECTRA: 1 # `uint64(2**3)` (= 8) MAX_ATTESTATIONS_ELECTRA: 8 # `uint64(2**0)` (= 1) -MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 1 +MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD: 2 # Execution # --------------------------------------------------------------- diff --git a/fuzz/build.gradle b/fuzz/build.gradle index 66e809ff2e8..c8d19168de5 100644 --- a/fuzz/build.gradle +++ b/fuzz/build.gradle @@ -1,4 +1,5 @@ dependencies { + api 'com.fasterxml.jackson.core:jackson-databind' implementation project(':ethereum:networks') implementation project(':ethereum:spec') implementation testFixtures(project(':ethereum:spec')) @@ -10,6 +11,7 @@ dependencies { testImplementation 'org.xerial.snappy:snappy-java' testImplementation testFixtures(project(':ethereum:spec')) + testImplementation project(':infrastructure:json') } diff --git a/fuzz/src/test/java/tech/pegasys/teku/fuzz/FuzzUtilTest.java b/fuzz/src/test/java/tech/pegasys/teku/fuzz/FuzzUtilTest.java index 05811285b46..a370a241cbe 100644 --- a/fuzz/src/test/java/tech/pegasys/teku/fuzz/FuzzUtilTest.java +++ b/fuzz/src/test/java/tech/pegasys/teku/fuzz/FuzzUtilTest.java @@ -15,6 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Path; @@ -38,6 +39,7 @@ import tech.pegasys.teku.fuzz.input.SyncAggregateFuzzInput; import tech.pegasys.teku.fuzz.input.VoluntaryExitFuzzInput; import tech.pegasys.teku.fuzz.input.WithdrawalRequestFuzzInput; +import tech.pegasys.teku.infrastructure.json.JsonUtil; import tech.pegasys.teku.infrastructure.ssz.SszData; import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema; import tech.pegasys.teku.spec.Spec; @@ -62,6 +64,7 @@ import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateElectra; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateSchemaElectra; import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra; @@ -166,23 +169,26 @@ public void fuzzBlock_minimal() { } @Test - public void fuzzBlockHeader_minimal() { + public void fuzzBlockHeader_minimal() throws JsonProcessingException { final FuzzUtil fuzzUtil = new FuzzUtil(false, true); final Path testCaseDir = Path.of("minimal/operations/block_header/pyspec_tests/basic_block_header"); final BeaconBlock data = loadSsz(testCaseDir.resolve("block.ssz_snappy"), beaconBlockSchema); final BeaconState preState = loadSsz(testCaseDir.resolve("pre.ssz_snappy"), beaconStateSchema); - final BeaconState postState = + final BeaconStateElectra postState = loadSsz(testCaseDir.resolve("post.ssz_snappy"), beaconStateSchema); - BlockHeaderFuzzInput input = new BlockHeaderFuzzInput(spec, preState, data); - byte[] rawInput = input.sszSerialize().toArrayUnsafe(); - Optional result = fuzzUtil.fuzzBlockHeader(rawInput).map(Bytes::wrap); + final BlockHeaderFuzzInput input = new BlockHeaderFuzzInput(spec, preState, data); + final byte[] rawInput = input.sszSerialize().toArrayUnsafe(); + final Optional result = fuzzUtil.fuzzBlockHeader(rawInput).map(Bytes::wrap); - Bytes expected = postState.sszSerialize(); assertThat(result).isNotEmpty(); - assertThat(result.get()).isEqualTo(expected); + final BeaconStateElectra resultState = + BeaconStateElectra.required( + spec.getGenesisSchemaDefinitions().getBeaconStateSchema().sszDeserialize(result.get())); + assertThat(JsonUtil.prettySerialize(resultState, beaconStateSchema.getJsonTypeDefinition())) + .isEqualTo(JsonUtil.prettySerialize(postState, beaconStateSchema.getJsonTypeDefinition())); } @Test @@ -377,7 +383,7 @@ public void fuzzWithdrawalRequest_minimal() { } @Test - public void fuzzConsolidationRequest_minimal() { + public void fuzzConsolidationRequest_minimal() throws JsonProcessingException { final FuzzUtil fuzzUtil = new FuzzUtil(false, true); final Path testCaseDir = @@ -391,16 +397,20 @@ public void fuzzConsolidationRequest_minimal() { .getConsolidationRequestsSchema() .getElementSchema()); final BeaconState preState = loadSsz(testCaseDir.resolve("pre.ssz_snappy"), beaconStateSchema); - final BeaconState postState = + final BeaconStateElectra postState = loadSsz(testCaseDir.resolve("post.ssz_snappy"), beaconStateSchema); - ConsolidationRequestFuzzInput input = new ConsolidationRequestFuzzInput(spec, preState, data); - byte[] rawInput = input.sszSerialize().toArrayUnsafe(); - Optional result = fuzzUtil.fuzzConsolidationRequest(rawInput).map(Bytes::wrap); + final ConsolidationRequestFuzzInput input = + new ConsolidationRequestFuzzInput(spec, preState, data); + final byte[] rawInput = input.sszSerialize().toArrayUnsafe(); + final Optional result = fuzzUtil.fuzzConsolidationRequest(rawInput).map(Bytes::wrap); - Bytes expected = postState.sszSerialize(); assertThat(result).isNotEmpty(); - assertThat(result.get()).isEqualTo(expected); + final BeaconStateElectra resultState = + BeaconStateElectra.required( + spec.getGenesisSchemaDefinitions().getBeaconStateSchema().sszDeserialize(result.get())); + assertThat(JsonUtil.prettySerialize(resultState, beaconStateSchema.getJsonTypeDefinition())) + .isEqualTo(JsonUtil.prettySerialize(postState, beaconStateSchema.getJsonTypeDefinition())); } @Test From 5c50019017442ad5c50821570145b78970a580da Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Mon, 16 Dec 2024 11:41:52 +1000 Subject: [PATCH 2/5] renamed consolidation request Signed-off-by: Paul Harris --- .../common/operations/DefaultOperationProcessor.java | 2 +- .../reference/common/operations/OperationProcessor.java | 2 +- .../reference/common/operations/OperationsTestExecutor.java | 6 +++--- fuzz/src/main/java/tech/pegasys/teku/fuzz/FuzzUtil.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/DefaultOperationProcessor.java b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/DefaultOperationProcessor.java index c861fbbab61..d0d8656dcfe 100644 --- a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/DefaultOperationProcessor.java +++ b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/DefaultOperationProcessor.java @@ -160,7 +160,7 @@ public void processWithdrawalRequest( } @Override - public void processConsolidationRequest( + public void processConsolidationRequests( final MutableBeaconState state, final List consolidationRequests) throws BlockProcessingException { spec.getBlockProcessor(state.getSlot()) diff --git a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationProcessor.java b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationProcessor.java index 519468ce32f..bae92e06718 100644 --- a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationProcessor.java +++ b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationProcessor.java @@ -73,7 +73,7 @@ void processDepositRequest(MutableBeaconState state, List deposi void processWithdrawalRequest(MutableBeaconState state, List withdrawalRequest) throws BlockProcessingException; - void processConsolidationRequest( + void processConsolidationRequests( MutableBeaconState state, List consolidationRequest) throws BlockProcessingException; } diff --git a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java index df11615cc16..7f25fee5231 100644 --- a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java +++ b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java @@ -320,7 +320,7 @@ private void processOperation( case WITHDRAWAL -> processWithdrawal(testDefinition, state, processor); case DEPOSIT_REQUEST -> processDepositRequest(testDefinition, state, processor); case WITHDRAWAL_REQUEST -> processWithdrawalRequest(testDefinition, state, processor); - case CONSOLIDATION_REQUEST -> processConsolidation(testDefinition, state, processor); + case CONSOLIDATION_REQUEST -> processConsolidations(testDefinition, state, processor); default -> throw new UnsupportedOperationException( "Operation " + operation + " not implemented in OperationTestExecutor"); @@ -381,7 +381,7 @@ private void processWithdrawalRequest( processor.processWithdrawalRequest(state, withdrawalRequests.asList()); } - private void processConsolidation( + private void processConsolidations( final TestDefinition testDefinition, final MutableBeaconState state, final OperationProcessor processor) @@ -394,7 +394,7 @@ private void processConsolidation( final SszList consolidationRequests = loadSsz(testDefinition, dataFileName, consolidationRequestsSchema); - processor.processConsolidationRequest(state, consolidationRequests.asList()); + processor.processConsolidationRequests(state, consolidationRequests.asList()); } private SignedVoluntaryExit loadVoluntaryExit(final TestDefinition testDefinition) { diff --git a/fuzz/src/main/java/tech/pegasys/teku/fuzz/FuzzUtil.java b/fuzz/src/main/java/tech/pegasys/teku/fuzz/FuzzUtil.java index 9aab8d8ef23..4a4bd3505f9 100644 --- a/fuzz/src/main/java/tech/pegasys/teku/fuzz/FuzzUtil.java +++ b/fuzz/src/main/java/tech/pegasys/teku/fuzz/FuzzUtil.java @@ -182,14 +182,14 @@ public Optional fuzzBlockHeader(final byte[] input) { deserialize(input, BlockHeaderFuzzInput.createType(specVersion)); try { - BeaconState postState = + final BeaconState postState = structuredInput .getState() .updated( state -> spec.getBlockProcessor(state.getSlot()) .processBlockHeader(state, structuredInput.getBlock())); - Bytes output = postState.sszSerialize(); + final Bytes output = postState.sszSerialize(); return Optional.of(output.toArrayUnsafe()); } catch (BlockProcessingException e) { // "expected error" From 37ba8267cf982ff5d6ce99980d3bd4e78dd72b60 Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Tue, 17 Dec 2024 06:53:26 +1000 Subject: [PATCH 3/5] update test Signed-off-by: Paul Harris --- .../teku/beaconrestapi/handlers/v1/config/mainnetConfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/config/mainnetConfig.json b/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/config/mainnetConfig.json index 1a551da743b..68f03baa8b2 100644 --- a/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/config/mainnetConfig.json +++ b/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/config/mainnetConfig.json @@ -131,7 +131,7 @@ "GENESIS_FORK_VERSION" : "0x00000000", "KZG_COMMITMENT_INCLUSION_PROOF_DEPTH" : "17", "DEPOSIT_NETWORK_ID" : "1", -"MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD" : "1", +"MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD" : "2", "MAX_REQUEST_BLOCKS_DENEB" : "128", "BLOB_SIDECAR_SUBNET_COUNT" : "6", "SYNC_COMMITTEE_SUBNET_COUNT" : "4", From 77385eaadc8aefd37ebc52ae94e4a80bb946df69 Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Tue, 17 Dec 2024 10:28:42 +1000 Subject: [PATCH 4/5] pull in functional change that was needed to test electra devnet5 tests change from #8908 Signed-off-by: Paul Harris --- .../epoch/EpochProcessorElectra.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java index 8eedf3e372e..b2f1f1af19c 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java @@ -322,12 +322,18 @@ public void processPendingConsolidations(final MutableBeaconState state) { break; } - final UInt64 activeBalance = - stateAccessorsElectra.getActiveBalance(state, pendingConsolidation.getSourceIndex()); + // Calculate the consolidated balance + final UInt64 sourceEffectiveBalance = + state + .getBalances() + .get(pendingConsolidation.getSourceIndex()) + .get() + .min(sourceValidator.getEffectiveBalance()); + // Move active balance to target. Excess balance is withdrawable. beaconStateMutators.decreaseBalance( - state, pendingConsolidation.getSourceIndex(), activeBalance); + state, pendingConsolidation.getSourceIndex(), sourceEffectiveBalance); beaconStateMutators.increaseBalance( - state, pendingConsolidation.getTargetIndex(), activeBalance); + state, pendingConsolidation.getTargetIndex(), sourceEffectiveBalance); nextPendingBalanceConsolidation++; } From 7137382273805be82d2fd8d2113cffa87be3a774 Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Tue, 17 Dec 2024 10:29:22 +1000 Subject: [PATCH 5/5] spotless Signed-off-by: Paul Harris --- .../statetransition/epoch/EpochProcessorElectra.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java index b2f1f1af19c..dd9e716baf6 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java @@ -324,11 +324,11 @@ public void processPendingConsolidations(final MutableBeaconState state) { // Calculate the consolidated balance final UInt64 sourceEffectiveBalance = - state - .getBalances() - .get(pendingConsolidation.getSourceIndex()) - .get() - .min(sourceValidator.getEffectiveBalance()); + state + .getBalances() + .get(pendingConsolidation.getSourceIndex()) + .get() + .min(sourceValidator.getEffectiveBalance()); // Move active balance to target. Excess balance is withdrawable. beaconStateMutators.decreaseBalance( state, pendingConsolidation.getSourceIndex(), sourceEffectiveBalance);