diff --git a/build.gradle b/build.gradle index eef80c4b8cc..7ee6494ba9b 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { } plugins { - id 'com.diffplug.spotless' version '7.0.2' + id 'com.diffplug.spotless' version '7.0.3' id 'com.github.ben-manes.versions' version '0.52.0' id 'com.github.jk1.dependency-license-report' version '2.9' id 'io.spring.dependency-management' version '1.1.7' @@ -249,6 +249,9 @@ allprojects { check('BannedMethod', net.ltgt.gradle.errorprone.CheckSeverity.OFF) check('ExperimentalCliOptionMustBeCorrectlyDisplayed', net.ltgt.gradle.errorprone.CheckSeverity.OFF) + // ignore PatternMatchingInstanceof for now + check("PatternMatchingInstanceof", net.ltgt.gradle.errorprone.CheckSeverity.OFF) + // These are experimental checks that we want enabled check('ClassName', net.ltgt.gradle.errorprone.CheckSeverity.WARN) check('DeduplicateConstants', net.ltgt.gradle.errorprone.CheckSeverity.WARN) diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_blob_sidecars_{block_id}.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_blob_sidecars_{block_id}.json index 3fd930829e2..2d2da89b4c9 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_blob_sidecars_{block_id}.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_blob_sidecars_{block_id}.json @@ -3,7 +3,7 @@ "tags" : [ "Beacon" ], "operationId" : "getBlobSidecars", "summary" : "Get blob sidecars", - "description" : "Retrieves blob sidecars for a given block id.\n Depending on `Accept` header it can be returned either as json or as bytes serialized by SSZ.\n If the `indices` parameter is specified, only the blob sidecars with the specified indices will be returned. There are no guarantees\n for the returned blob sidecars in terms of ordering.", + "description" : "Retrieves blob sidecars for a given block id.\n Depending on `Accept` header it can be returned either as json or as bytes serialized by SSZ.\n If the `indices` parameter is specified, only the blob sidecars with the specified indices will be returned. There are no guarantees\n for the returned blob sidecars in terms of ordering.\n", "parameters" : [ { "name" : "block_id", "required" : true, diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_pool_sync_committees.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_pool_sync_committees.json index 50334eaab83..408fa738c7c 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_pool_sync_committees.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_pool_sync_committees.json @@ -3,7 +3,7 @@ "tags" : [ "Beacon", "Validator Required Api" ], "operationId" : "submitPoolSyncCommitteeSignatures", "summary" : "Submit sync committee signatures to node", - "description" : "Submits sync committee message objects to the node.\n\nSync committee messages are not present in phase0, but are required for Altair networks.\n\nIf a sync committee message is validated successfully the node MUST publish that sync committee message on all applicable subnets.\n\nIf one or more sync committee messages fail validation the node MUST return a 400 error with details of which sync committee messages have failed, and why.", + "description" : "Submits sync committee message objects to the node.\n\nSync committee messages are not present in phase0, but are required for Altair networks.\n\nIf a sync committee message is validated successfully the node MUST publish that sync committee message on all applicable subnets.\n\nIf one or more sync committee messages fail validation the node MUST return a 400 error with details of which sync committee messages have failed, and why.\n", "requestBody" : { "content" : { "application/json" : { diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_prepare_beacon_proposer.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_prepare_beacon_proposer.json index 8d7bd4ffebf..fb8ed5a6f95 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_prepare_beacon_proposer.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_prepare_beacon_proposer.json @@ -3,7 +3,7 @@ "tags" : [ "Validator", "Validator Required Api" ], "operationId" : "prepareBeaconProposer", "summary" : "Provide beacon node with proposals for the given validators.", - "description" : "Prepares the beacon node for potential proposers by supplying information required when proposing blocks for the given validators. The information supplied for each validator index is considered persistent until overwritten by new information for the given validator index, or until the beacon node restarts.\n\nNote that because the information is not persistent across beacon node restarts it is recommended that either the beacon node is monitored for restarts or this information is refreshed by resending this request periodically (for example, each epoch).\n\nAlso note that requests containing currently inactive or unknown validator indices will be accepted, as they may become active at a later epoch.", + "description" : "Prepares the beacon node for potential proposers by supplying information required when proposing blocks for the given validators. The information supplied for each validator index is considered persistent until overwritten by new information for the given validator index, or until the beacon node restarts.\n\nNote that because the information is not persistent across beacon node restarts it is recommended that either the beacon node is monitored for restarts or this information is refreshed by resending this request periodically (for example, each epoch).\n\nAlso note that requests containing currently inactive or unknown validator indices will be accepted, as they may become active at a later epoch.\n", "requestBody" : { "content" : { "application/json" : { diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_sync_committee_subscriptions.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_sync_committee_subscriptions.json index a32174d4e40..2ee1b9e8306 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_sync_committee_subscriptions.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_validator_sync_committee_subscriptions.json @@ -3,7 +3,7 @@ "tags" : [ "Validator", "Validator Required Api" ], "operationId" : "prepareSyncCommitteeSubnets", "summary" : "Subscribe to sync committee subnets", - "description" : "Subscribe to a number of sync committee subnets\n\nSync committees are not present in phase0, but are required for Altair networks.\n\nSubscribing to sync committee subnets is an action performed by VC to enable network participation in Altair networks, and only required if the VC has an active validator in an active sync committee.", + "description" : "Subscribe to a number of sync committee subnets\n\nSync committees are not present in phase0, but are required for Altair networks.\n\nSubscribing to sync committee subnets is an action performed by VC to enable network participation in Altair networks, and only required if the VC has an active validator in an active sync committee.\n", "requestBody" : { "content" : { "application/json" : { diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_beacon_pool_attestations.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_beacon_pool_attestations.json index 7242e8ad9ee..592f1b8bc6d 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_beacon_pool_attestations.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_beacon_pool_attestations.json @@ -78,7 +78,7 @@ "tags" : [ "Beacon", "Validator Required Api", "Experimental" ], "operationId" : "submitPoolAttestationsV2", "summary" : "Submit Attestation objects to node", - "description" : "Submits Attestation objects to the node. Each attestation in the request body is processed individually.\nIf an attestation is validated successfully, the node MUST publish that attestation on the appropriate subnet.\nIf one or more attestations fail validation, the node MUST return a 400 error with details of which attestations have failed, and why.", + "description" : "Submits Attestation objects to the node. Each attestation in the request body is processed individually.\nIf an attestation is validated successfully, the node MUST publish that attestation on the appropriate subnet.\nIf one or more attestations fail validation, the node MUST return a 400 error with details of which attestations have failed, and why.\n", "parameters" : [ { "name" : "Eth-Consensus-Version", "required" : true, diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_validator_aggregate_attestation.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_validator_aggregate_attestation.json index 08fb7006ac2..232b9a64bd7 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_validator_aggregate_attestation.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_validator_aggregate_attestation.json @@ -3,7 +3,7 @@ "tags" : [ "Validator", "Validator Required Api" ], "operationId" : "getAggregatedAttestationV2", "summary" : "Get aggregated attestation", - "description" : "Aggregates all attestations matching given attestation data root, slot and committee index.\nA 503 error must be returned if the block identified by the response\n`beacon_block_root` is optimistic (i.e. the aggregated attestation attests\nto a block that has not been fully verified by an execution engine).\nA 404 error must be returned if no attestation is available for the requested\n`attestation_data_root`.", + "description" : "Aggregates all attestations matching given attestation data root, slot and committee index.\nA 503 error must be returned if the block identified by the response\n`beacon_block_root` is optimistic (i.e. the aggregated attestation attests\nto a block that has not been fully verified by an execution engine).\nA 404 error must be returned if no attestation is available for the requested\n`attestation_data_root`.\n", "parameters" : [ { "name" : "attestation_data_root", "required" : true, diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v3_validator_blocks_{slot}.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v3_validator_blocks_{slot}.json index 5228c531b1c..f0d04e5f761 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v3_validator_blocks_{slot}.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v3_validator_blocks_{slot}.json @@ -3,7 +3,7 @@ "tags" : [ "Validator", "Validator Required Api" ], "operationId" : "produceBlockV3", "summary" : "Produce a new block, without signature.", - "description" : "Requests a beacon node to produce a valid block, which can then be signed by a validator. The\nreturned block may be blinded or unblinded, depending on the current state of the network as\ndecided by the execution and beacon nodes.\nThe beacon node must return an unblinded block if it obtains the execution payload from its\npaired execution node. It must only return a blinded block if it obtains the execution payload\nheader from an MEV relay.\nMetadata in the response indicates the type of block produced, and the supported types of block\nwill be added to as forks progress.", + "description" : "Requests a beacon node to produce a valid block, which can then be signed by a validator. The\nreturned block may be blinded or unblinded, depending on the current state of the network as\ndecided by the execution and beacon nodes.\nThe beacon node must return an unblinded block if it obtains the execution payload from its\npaired execution node. It must only return a blinded block if it obtains the execution payload\nheader from an MEV relay.\nMetadata in the response indicates the type of block produced, and the supported types of block\nwill be added to as forks progress.\n", "parameters" : [ { "name" : "slot", "required" : true, diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java index df71e555246..45754ed33fe 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetBlobSidecars.java @@ -67,10 +67,12 @@ private static EndpointMetadata createEndpointMetadata(final SchemaDefinitionCac .operationId("getBlobSidecars") .summary("Get blob sidecars") .description( - "Retrieves blob sidecars for a given block id.\n" - + " Depending on `Accept` header it can be returned either as json or as bytes serialized by SSZ.\n" - + " If the `indices` parameter is specified, only the blob sidecars with the specified indices will be returned. There are no guarantees\n" - + " for the returned blob sidecars in terms of ordering.") + """ + Retrieves blob sidecars for a given block id. + Depending on `Accept` header it can be returned either as json or as bytes serialized by SSZ. + If the `indices` parameter is specified, only the blob sidecars with the specified indices will be returned. There are no guarantees + for the returned blob sidecars in terms of ordering. + """) .tags(TAG_BEACON) .pathParam(PARAMETER_BLOCK_ID) .queryListParam(BLOB_INDICES_PARAMETER) diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostSyncCommittees.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostSyncCommittees.java index 43e828f24e1..1caf209a21c 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostSyncCommittees.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostSyncCommittees.java @@ -52,10 +52,15 @@ public PostSyncCommittees(final ValidatorDataProvider provider) { .operationId("submitPoolSyncCommitteeSignatures") .summary("Submit sync committee signatures to node") .description( - "Submits sync committee message objects to the node.\n\n" - + "Sync committee messages are not present in phase0, but are required for Altair networks.\n\n" - + "If a sync committee message is validated successfully the node MUST publish that sync committee message on all applicable subnets.\n\n" - + "If one or more sync committee messages fail validation the node MUST return a 400 error with details of which sync committee messages have failed, and why.") + """ + Submits sync committee message objects to the node. + + Sync committee messages are not present in phase0, but are required for Altair networks. + + If a sync committee message is validated successfully the node MUST publish that sync committee message on all applicable subnets. + + If one or more sync committee messages fail validation the node MUST return a 400 error with details of which sync committee messages have failed, and why. + """) .tags(TAG_BEACON, TAG_VALIDATOR_REQUIRED) .requestBodyType( DeserializableTypeDefinition.listOf( diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/debug/GetState.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/debug/GetState.java index 84383019654..3d9a0dab9f0 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/debug/GetState.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/debug/GetState.java @@ -57,9 +57,13 @@ public GetState( .operationId("getState") .summary("Get state") .description( - "Returns full BeaconState object for given state_id.\n\n" - + "Use Accept header to select `application/octet-stream` if SSZ response type is required.\n\n" - + "__NOTE__: Only phase0 beacon state will be returned in JSON, use `/eth/v2/beacon/states/{state_id}` for altair.") + """ + Returns full BeaconState object for given state_id. + + Use Accept header to select `application/octet-stream` if SSZ response type is required. + + __NOTE__: Only phase0 beacon state will be returned in JSON, use `/eth/v2/beacon/states/{state_id}` for altair. + """) .tags(TAG_DEBUG) .pathParam(PARAMETER_STATE_ID) .response( diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostPrepareBeaconProposer.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostPrepareBeaconProposer.java index f8e610375e3..6c1e4b9ce7a 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostPrepareBeaconProposer.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostPrepareBeaconProposer.java @@ -68,9 +68,13 @@ private static EndpointMetadata createMetadata() { .operationId("prepareBeaconProposer") .summary("Provide beacon node with proposals for the given validators.") .description( - "Prepares the beacon node for potential proposers by supplying information required when proposing blocks for the given validators. The information supplied for each validator index is considered persistent until overwritten by new information for the given validator index, or until the beacon node restarts.\n\n" - + "Note that because the information is not persistent across beacon node restarts it is recommended that either the beacon node is monitored for restarts or this information is refreshed by resending this request periodically (for example, each epoch).\n\n" - + "Also note that requests containing currently inactive or unknown validator indices will be accepted, as they may become active at a later epoch.") + """ + Prepares the beacon node for potential proposers by supplying information required when proposing blocks for the given validators. The information supplied for each validator index is considered persistent until overwritten by new information for the given validator index, or until the beacon node restarts. + + Note that because the information is not persistent across beacon node restarts it is recommended that either the beacon node is monitored for restarts or this information is refreshed by resending this request periodically (for example, each epoch). + + Also note that requests containing currently inactive or unknown validator indices will be accepted, as they may become active at a later epoch. + """) .tags(TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED) .requestBodyType(DeserializableTypeDefinition.listOf(BeaconPreparableProposer.SSZ_DATA)) .response(SC_OK, "Preparation information has been received.") diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSubscribeToBeaconCommitteeSubnet.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSubscribeToBeaconCommitteeSubnet.java index 21e110e49dd..847a45f8dd9 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSubscribeToBeaconCommitteeSubnet.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSubscribeToBeaconCommitteeSubnet.java @@ -44,9 +44,11 @@ public PostSubscribeToBeaconCommitteeSubnet(final ValidatorDataProvider provider .operationId("prepareBeaconCommitteeSubnet") .summary("Signal beacon node to prepare for a committee subnet") .description( - "After Beacon node receives this request, search using discv5 for peers related to this subnet and replace current peers with those ones if necessary If validator is_aggregator, beacon node must:\n" - + "- announce subnet topic subscription on gossipsub\n" - + "- aggregate attestations received on that subnet\n") + """ + After Beacon node receives this request, search using discv5 for peers related to this subnet and replace current peers with those ones if necessary If validator is_aggregator, beacon node must: + - announce subnet topic subscription on gossipsub + - aggregate attestations received on that subnet + """) .tags(TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED) .requestBodyType( DeserializableTypeDefinition.listOf(CommitteeSubscriptionData.SSZ_DATA)) diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSyncCommitteeSubscriptions.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSyncCommitteeSubscriptions.java index 91f1b9535fc..74b6132b9f0 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSyncCommitteeSubscriptions.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/validator/PostSyncCommitteeSubscriptions.java @@ -44,9 +44,13 @@ public PostSyncCommitteeSubscriptions(final ValidatorDataProvider validatorDataP .operationId("prepareSyncCommitteeSubnets") .summary("Subscribe to sync committee subnets") .description( - "Subscribe to a number of sync committee subnets\n\n" - + "Sync committees are not present in phase0, but are required for Altair networks.\n\n" - + "Subscribing to sync committee subnets is an action performed by VC to enable network participation in Altair networks, and only required if the VC has an active validator in an active sync committee.") + """ + Subscribe to a number of sync committee subnets + + Sync committees are not present in phase0, but are required for Altair networks. + + Subscribing to sync committee subnets is an action performed by VC to enable network participation in Altair networks, and only required if the VC has an active validator in an active sync committee. + """) .tags(TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED) .requestBodyType(DeserializableTypeDefinition.listOf(SYNC_COMMITTEE_SUBSCRIPTION)) .response(SC_OK, "Successful response") diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttestationsV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttestationsV2.java index 2f8b817ba04..7868630003e 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttestationsV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttestationsV2.java @@ -116,9 +116,11 @@ private static EndpointMetadata createMetadata( .operationId("submitPoolAttestationsV2") .summary("Submit Attestation objects to node") .description( - "Submits Attestation objects to the node. Each attestation in the request body is processed individually.\n" - + "If an attestation is validated successfully, the node MUST publish that attestation on the appropriate subnet.\n" - + "If one or more attestations fail validation, the node MUST return a 400 error with details of which attestations have failed, and why.") + """ + Submits Attestation objects to the node. Each attestation in the request body is processed individually. + If an attestation is validated successfully, the node MUST publish that attestation on the appropriate subnet. + If one or more attestations fail validation, the node MUST return a 400 error with details of which attestations have failed, and why. + """) .tags(TAG_BEACON, TAG_VALIDATOR_REQUIRED, TAG_EXPERIMENTAL) .requestBodyType( SerializableTypeDefinition.listOf(attestationSchemaDefinition), attestationBodySelector) diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java index 2e9d7111100..8177b6b4cfb 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java @@ -61,12 +61,14 @@ public GetAggregateAttestationV2( .operationId("getAggregatedAttestationV2") .summary("Get aggregated attestation") .description( - "Aggregates all attestations matching given attestation data root, slot and committee index.\n" - + "A 503 error must be returned if the block identified by the response\n" - + "`beacon_block_root` is optimistic (i.e. the aggregated attestation attests\n" - + "to a block that has not been fully verified by an execution engine).\n" - + "A 404 error must be returned if no attestation is available for the requested\n" - + "`attestation_data_root`.") + """ + Aggregates all attestations matching given attestation data root, slot and committee index. + A 503 error must be returned if the block identified by the response + `beacon_block_root` is optimistic (i.e. the aggregated attestation attests + to a block that has not been fully verified by an execution engine). + A 404 error must be returned if no attestation is available for the requested + `attestation_data_root`. + """) .tags(TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED) .queryParamRequired(ATTESTATION_DATA_ROOT_PARAMETER) .queryParamRequired(SLOT_PARAMETER) diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v3/validator/GetNewBlockV3.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v3/validator/GetNewBlockV3.java index 84c61cf56a7..01fa2669747 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v3/validator/GetNewBlockV3.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v3/validator/GetNewBlockV3.java @@ -87,14 +87,16 @@ private static EndpointMetadata getEndpointMetaData( .operationId("produceBlockV3") .summary("Produce a new block, without signature.") .description( - "Requests a beacon node to produce a valid block, which can then be signed by a validator. The\n" - + "returned block may be blinded or unblinded, depending on the current state of the network as\n" - + "decided by the execution and beacon nodes.\n" - + "The beacon node must return an unblinded block if it obtains the execution payload from its\n" - + "paired execution node. It must only return a blinded block if it obtains the execution payload\n" - + "header from an MEV relay.\n" - + "Metadata in the response indicates the type of block produced, and the supported types of block\n" - + "will be added to as forks progress.") + """ + Requests a beacon node to produce a valid block, which can then be signed by a validator. The + returned block may be blinded or unblinded, depending on the current state of the network as + decided by the execution and beacon nodes. + The beacon node must return an unblinded block if it obtains the execution payload from its + paired execution node. It must only return a blinded block if it obtains the execution payload + header from an MEV relay. + Metadata in the response indicates the type of block produced, and the supported types of block + will be added to as forks progress. + """) .tags(TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED) .pathParam(SLOT_PARAMETER.withDescription(SLOT_PATH_DESCRIPTION)) .queryParamRequired(RANDAO_PARAMETER) diff --git a/data/provider/src/main/java/tech/pegasys/teku/api/rewards/EpochAttestationRewardsCalculator.java b/data/provider/src/main/java/tech/pegasys/teku/api/rewards/EpochAttestationRewardsCalculator.java index c6334e00fe1..7a3a70cd20a 100644 --- a/data/provider/src/main/java/tech/pegasys/teku/api/rewards/EpochAttestationRewardsCalculator.java +++ b/data/provider/src/main/java/tech/pegasys/teku/api/rewards/EpochAttestationRewardsCalculator.java @@ -147,16 +147,13 @@ private boolean isInactivityLeak() { private UInt64 getPrevEpochTotalParticipatingBalance(final int flagIndex) { final TotalBalances totalBalances = validatorStatuses.getTotalBalances(); - switch (flagIndex) { - case TIMELY_HEAD_FLAG_INDEX: - return totalBalances.getPreviousEpochHeadAttesters(); - case TIMELY_TARGET_FLAG_INDEX: - return totalBalances.getPreviousEpochTargetAttesters(); - case TIMELY_SOURCE_FLAG_INDEX: - return totalBalances.getPreviousEpochSourceAttesters(); - default: - throw new IllegalArgumentException("Unable to process unknown flag index:" + flagIndex); - } + return switch (flagIndex) { + case TIMELY_HEAD_FLAG_INDEX -> totalBalances.getPreviousEpochHeadAttesters(); + case TIMELY_TARGET_FLAG_INDEX -> totalBalances.getPreviousEpochTargetAttesters(); + case TIMELY_SOURCE_FLAG_INDEX -> totalBalances.getPreviousEpochSourceAttesters(); + default -> + throw new IllegalArgumentException("Unable to process unknown flag index:" + flagIndex); + }; } @VisibleForTesting diff --git a/data/provider/src/test/java/tech/pegasys/teku/api/ValidatorDataProviderTest.java b/data/provider/src/test/java/tech/pegasys/teku/api/ValidatorDataProviderTest.java index dd36ffa6dc8..0457d913e41 100644 --- a/data/provider/src/test/java/tech/pegasys/teku/api/ValidatorDataProviderTest.java +++ b/data/provider/src/test/java/tech/pegasys/teku/api/ValidatorDataProviderTest.java @@ -402,6 +402,7 @@ void registerValidators_shouldReportErrorIfCannotRetrieveValidatorStatuses() { } @TestTemplate + @SuppressWarnings("EnumOrdinal") void registerValidators_shouldIgnoreExitedAndUnknownValidators() { final int numOfValidatorRegistrationsAttempted = ValidatorStatus.values().length + 2; @@ -425,7 +426,6 @@ void registerValidators_shouldIgnoreExitedAndUnknownValidators() { e.getValue(), dataStructureUtil.randomValidator()))); - @SuppressWarnings("EnumOrdinal") final List exitedOrUnknownKeys = IntStream.range( ValidatorStatus.exited_unslashed.ordinal(), numOfValidatorRegistrationsAttempted) diff --git a/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/MetricsDataFactory.java b/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/MetricsDataFactory.java index 4fea19f1bf4..34ae3d64778 100644 --- a/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/MetricsDataFactory.java +++ b/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/MetricsDataFactory.java @@ -53,11 +53,11 @@ List getMetricData(final MetricsPublisherSource source) { } public List getMetricData() { - if (!(metricsSystem instanceof PrometheusMetricsSystem)) { + if (metricsSystem instanceof final PrometheusMetricsSystem prometheusMetricsSystem) { + return getMetricData(new PrometheusMetricsPublisherSource(prometheusMetricsSystem)); + } else { LOG.error("Prometheus metric system not found, cannot export metrics data."); return new ArrayList<>(); } - return getMetricData( - new PrometheusMetricsPublisherSource((PrometheusMetricsSystem) metricsSystem)); } } diff --git a/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/SystemMetricData.java b/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/SystemMetricData.java index 0edb395b57a..779597895be 100644 --- a/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/SystemMetricData.java +++ b/data/publisher/src/main/java/tech/pegasys/teku/data/publisher/SystemMetricData.java @@ -112,16 +112,12 @@ public SystemMetricData(final long timestamp, final File beaconNodeDirectory) { } private long getNodeBootSeconds() { - switch (miscOs) { - case "lin": - return new LinuxOperatingSystem().getSystemBootTime(); - case "win": - return new WindowsOperatingSystem().getSystemBootTime(); - case "mac": - return new MacOperatingSystem().getSystemBootTime(); - default: - return 0L; - } + return switch (miscOs) { + case "lin" -> new LinuxOperatingSystem().getSystemBootTime(); + case "win" -> new WindowsOperatingSystem().getSystemBootTime(); + case "mac" -> new MacOperatingSystem().getSystemBootTime(); + default -> 0L; + }; } private long[] calculateProcessLoadTicks(final long[][] processorCpuLoadTicks) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBlockAndState.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBlockAndState.java index 7809b3ddaac..bae52c5ceeb 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBlockAndState.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/SignedBlockAndState.java @@ -39,12 +39,12 @@ public boolean equals(final Object o) { if (o == this) { return true; } - if (!(o instanceof SignedBlockAndState)) { + if (o instanceof final SignedBlockAndState that) { + return Objects.equals(getBlock(), that.getBlock()) + && Objects.equals(getState(), that.getState()); + } else { return false; } - final SignedBlockAndState that = (SignedBlockAndState) o; - return Objects.equals(getBlock(), that.getBlock()) - && Objects.equals(getState(), that.getState()); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/NewPayloadRequest.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/NewPayloadRequest.java index 3c0a46c8c77..b9c62728063 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/NewPayloadRequest.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/NewPayloadRequest.java @@ -77,14 +77,15 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (!(o instanceof NewPayloadRequest)) { + if (o instanceof final NewPayloadRequest that) { + + return Objects.equals(executionPayload, that.executionPayload) + && Objects.equals(versionedHashes, that.versionedHashes) + && Objects.equals(parentBeaconBlockRoot, that.parentBeaconBlockRoot) + && Objects.equals(executionRequests, that.executionRequests); + } else { return false; } - final NewPayloadRequest that = (NewPayloadRequest) o; - return Objects.equals(executionPayload, that.executionPayload) - && Objects.equals(versionedHashes, that.versionedHashes) - && Objects.equals(parentBeaconBlockRoot, that.parentBeaconBlockRoot) - && Objects.equals(executionRequests, that.executionRequests); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/CheckpointState.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/CheckpointState.java index 910b4de7c98..b5db8cf7775 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/CheckpointState.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/CheckpointState.java @@ -84,13 +84,13 @@ public boolean equals(final Object o) { if (o == this) { return true; } - if (!(o instanceof CheckpointState)) { + if (o instanceof final CheckpointState that) { + return Objects.equals(checkpoint, that.checkpoint) + && Objects.equals(block, that.block) + && Objects.equals(state, that.state); + } else { return false; } - final CheckpointState that = (CheckpointState) o; - return Objects.equals(checkpoint, that.checkpoint) - && Objects.equals(block, that.block) - && Objects.equals(state, that.state); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateInvariants.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateInvariants.java index b1dba9fcb34..b7a40958f11 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateInvariants.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/state/beaconstate/common/BeaconStateInvariants.java @@ -82,12 +82,12 @@ static boolean equals(final BeaconState state, final Object obj) { return true; } - if (!(obj instanceof BeaconState)) { + if (obj instanceof final BeaconState other) { + + return state.hashTreeRoot().equals(other.hashTreeRoot()); + } else { return false; } - - BeaconState other = (BeaconState) obj; - return state.hashTreeRoot().equals(other.hashTreeRoot()); } static int hashCode(final BeaconState state) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/statetransition/epoch/RewardsAndPenaltiesCalculatorAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/statetransition/epoch/RewardsAndPenaltiesCalculatorAltair.java index b00e757e731..46e7bce1e72 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/statetransition/epoch/RewardsAndPenaltiesCalculatorAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/statetransition/epoch/RewardsAndPenaltiesCalculatorAltair.java @@ -192,30 +192,26 @@ protected UInt64 getInactivityPenaltyQuotient() { private boolean validatorHasPrevEpochParticipationFlag( final ValidatorStatus validator, final int flagIndex) { - switch (flagIndex) { - case TIMELY_HEAD_FLAG_INDEX: - return validator.isPreviousEpochHeadAttester(); - case ParticipationFlags.TIMELY_TARGET_FLAG_INDEX: - return validator.isPreviousEpochTargetAttester(); - case ParticipationFlags.TIMELY_SOURCE_FLAG_INDEX: - return validator.isPreviousEpochSourceAttester(); - default: - throw new IllegalArgumentException("Unable to process unknown flag index:" + flagIndex); - } + return switch (flagIndex) { + case TIMELY_HEAD_FLAG_INDEX -> validator.isPreviousEpochHeadAttester(); + case ParticipationFlags.TIMELY_TARGET_FLAG_INDEX -> validator.isPreviousEpochTargetAttester(); + case ParticipationFlags.TIMELY_SOURCE_FLAG_INDEX -> validator.isPreviousEpochSourceAttester(); + default -> + throw new IllegalArgumentException("Unable to process unknown flag index:" + flagIndex); + }; } private UInt64 getPrevEpochTotalParticipatingBalance(final int flagIndex) { final TotalBalances totalBalances = validatorStatuses.getTotalBalances(); - switch (flagIndex) { - case TIMELY_HEAD_FLAG_INDEX: - return totalBalances.getPreviousEpochHeadAttesters(); - case ParticipationFlags.TIMELY_TARGET_FLAG_INDEX: - return totalBalances.getPreviousEpochTargetAttesters(); - case ParticipationFlags.TIMELY_SOURCE_FLAG_INDEX: - return totalBalances.getPreviousEpochSourceAttesters(); - default: - throw new IllegalArgumentException("Unable to process unknown flag index:" + flagIndex); - } + return switch (flagIndex) { + case TIMELY_HEAD_FLAG_INDEX -> totalBalances.getPreviousEpochHeadAttesters(); + case ParticipationFlags.TIMELY_TARGET_FLAG_INDEX -> + totalBalances.getPreviousEpochTargetAttesters(); + case ParticipationFlags.TIMELY_SOURCE_FLAG_INDEX -> + totalBalances.getPreviousEpochSourceAttesters(); + default -> + throw new IllegalArgumentException("Unable to process unknown flag index:" + flagIndex); + }; } private boolean isUnslashedPrevEpochParticipatingIndex( diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtilTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtilTest.java index a1bc99e23f2..2abbf8e780e 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtilTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtilTest.java @@ -90,34 +90,28 @@ void setUp(final SpecContext specContext) { .thenReturn(SafeFuture.completedFuture(true)); attestationUtil = spec.getGenesisSpec().getAttestationUtil(); - switch (specContext.getSpecMilestone()) { - case PHASE0: - attestationUtil = - new AttestationUtilPhase0( - spec.getGenesisSpecConfig(), - specVersion.getSchemaDefinitions(), - beaconStateAccessors, - miscHelpers); - break; - case DENEB: - attestationUtil = - new AttestationUtilDeneb( - spec.getGenesisSpecConfig(), - specVersion.getSchemaDefinitions(), - beaconStateAccessors, - miscHelpers); - break; - case ELECTRA: - attestationUtil = - new AttestationUtilElectra( - spec.getGenesisSpecConfig(), - specVersion.getSchemaDefinitions(), - beaconStateAccessors, - miscHelpers); - break; - default: - throw new UnsupportedOperationException("unsupported milestone"); - } + attestationUtil = + switch (specContext.getSpecMilestone()) { + case PHASE0 -> + new AttestationUtilPhase0( + spec.getGenesisSpecConfig(), + specVersion.getSchemaDefinitions(), + beaconStateAccessors, + miscHelpers); + case DENEB -> + new AttestationUtilDeneb( + spec.getGenesisSpecConfig(), + specVersion.getSchemaDefinitions(), + beaconStateAccessors, + miscHelpers); + case ELECTRA -> + new AttestationUtilElectra( + spec.getGenesisSpecConfig(), + specVersion.getSchemaDefinitions(), + beaconStateAccessors, + miscHelpers); + default -> throw new UnsupportedOperationException("unsupported milestone"); + }; } @TestTemplate diff --git a/fork-choice-tests/src/integration-test/java/tech/pegasys/teku/forkChoiceTests/ForkChoiceIntegrationTest.java b/fork-choice-tests/src/integration-test/java/tech/pegasys/teku/forkChoiceTests/ForkChoiceIntegrationTest.java index b4094bb32ab..bacc83eeaff 100644 --- a/fork-choice-tests/src/integration-test/java/tech/pegasys/teku/forkChoiceTests/ForkChoiceIntegrationTest.java +++ b/fork-choice-tests/src/integration-test/java/tech/pegasys/teku/forkChoiceTests/ForkChoiceIntegrationTest.java @@ -113,34 +113,23 @@ private static Object extractTestStep( ForkChoiceTestStep stepKind = getStepKind(stepDescription); Object value = stepDescription.get(stepKind.name()); - switch (stepKind) { - case slot: - { - return UInt64.valueOf((Integer) value); - } - case block: - { - return resolvePart( + return switch (stepKind) { + case slot -> UInt64.valueOf((Integer) value); + case block -> + resolvePart( SignedBeaconBlock.class, SPEC.getGenesisSchemaDefinitions().getSignedBeaconBlockSchema(), file, value); - } - case attestation: - { - return resolvePart( + case attestation -> + resolvePart( Attestation.class, SPEC.getGenesisSchemaDefinitions().getAttestationSchema(), file, value); - } - case checks: - { - return value; - } - default: - throw new IllegalArgumentException("Unsupported step kind " + stepKind); - } + case checks -> value; + default -> throw new IllegalArgumentException("Unsupported step kind " + stepKind); + }; } private static ForkChoiceTestStep getStepKind(final Map ss) { diff --git a/gradle/versions.gradle b/gradle/versions.gradle index 3c04742d15f..8af0801031f 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -1,11 +1,11 @@ dependencyManagement { dependencies { - dependency 'com.fasterxml.jackson.core:jackson-databind:2.18.2' - dependency 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2' - dependency 'com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.18.2' - dependency 'com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2' + dependency 'com.fasterxml.jackson.core:jackson-databind:2.18.3' + dependency 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.3' + dependency 'com.fasterxml.jackson.dataformat:jackson-dataformat-toml:2.18.3' + dependency 'com.fasterxml.jackson.module:jackson-module-kotlin:2.18.3' - dependencySet(group: 'com.google.errorprone', version: '2.36.0') { + dependencySet(group: 'com.google.errorprone', version: '2.37.0') { entry 'error_prone_annotation' entry 'error_prone_check_api' entry 'error_prone_core' @@ -27,7 +27,7 @@ dependencyManagement { dependency 'info.picocli:picocli:4.7.6' - dependencySet(group: 'io.javalin', version: '6.4.0') { + dependencySet(group: 'io.javalin', version: '6.6.0') { entry 'javalin' entry 'javalin-rendering' } @@ -42,7 +42,7 @@ dependencyManagement { dependency 'org.mock-server:mockserver-junit-jupiter:5.15.0' - dependencySet(group: 'io.swagger.core.v3', version: '2.2.28') { + dependencySet(group: 'io.swagger.core.v3', version: '2.2.30') { entry 'swagger-parser' entry 'swagger-core' entry 'swagger-models' @@ -50,11 +50,11 @@ dependencyManagement { } // On update don't forget to change version in tech.pegasys.teku.infrastructure.restapi.SwaggerUIBuilder - dependency 'org.webjars:swagger-ui:5.18.3' + dependency 'org.webjars:swagger-ui:5.20.7' dependency 'org.thymeleaf:thymeleaf:3.1.3.RELEASE' dependency 'io.github.classgraph:classgraph:4.8.179' - dependencySet(group: 'com.github.oshi', version: '6.6.6') { + dependencySet(group: 'com.github.oshi', version: '6.8.0') { entry 'oshi-core' entry 'oshi-core-java11' } @@ -140,12 +140,12 @@ dependencyManagement { dependency 'io.prometheus:prometheus-metrics-bom:1.3.5' - dependencySet(group: 'org.hyperledger.besu.internal', version: '25.3.0') { + dependencySet(group: 'org.hyperledger.besu.internal', version: '25.4.0') { entry('metrics-core') entry('core') entry('config') } - dependencySet(group: 'org.hyperledger.besu', version: '25.3.0') { + dependencySet(group: 'org.hyperledger.besu', version: '25.4.0') { entry('besu-datatypes') entry('evm') entry('plugin-api') diff --git a/infrastructure/bls-keystore/src/main/java/tech/pegasys/teku/bls/keystore/KeyStoreLoader.java b/infrastructure/bls-keystore/src/main/java/tech/pegasys/teku/bls/keystore/KeyStoreLoader.java index 80045591a76..012d81f0695 100644 --- a/infrastructure/bls-keystore/src/main/java/tech/pegasys/teku/bls/keystore/KeyStoreLoader.java +++ b/infrastructure/bls-keystore/src/main/java/tech/pegasys/teku/bls/keystore/KeyStoreLoader.java @@ -93,14 +93,14 @@ public static KeyStoreData loadFromUrl(final URL keystoreFile) private static KeyStoreValidationException convertToKeyStoreValidationException( final JsonMappingException e) { final String cause; - if (e.getCause() instanceof KeyStoreValidationException) { + if (e.getCause() instanceof final KeyStoreValidationException keyStoreValidationException) { // this is wrapped because it is raised from custom deserializer in KeyStoreBytesModule to // validate enums - throw (KeyStoreValidationException) e.getCause(); + throw keyStoreValidationException; } - if (e instanceof InvalidTypeIdException) { - cause = getKdfFunctionErrorMessage((InvalidTypeIdException) e); + if (e instanceof final InvalidTypeIdException invalidTypeIdException) { + cause = getKdfFunctionErrorMessage(invalidTypeIdException); } else { cause = "Invalid KeyStore: " + e.getMessage(); } diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSPublicKey.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSPublicKey.java index 0ccf6660cba..fe792a3c412 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSPublicKey.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSPublicKey.java @@ -173,12 +173,12 @@ public boolean equals(final Object obj) { return true; } - if (!(obj instanceof BLSPublicKey)) { + if (obj instanceof final BLSPublicKey other) { + + return Objects.equals(this.toBytesCompressed(), other.toBytesCompressed()); + } else { return false; } - - BLSPublicKey other = (BLSPublicKey) obj; - return Objects.equals(this.toBytesCompressed(), other.toBytesCompressed()); } @Override diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSSignature.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSSignature.java index 7e5cecd52ce..1d84687b00f 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSSignature.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLSSignature.java @@ -145,10 +145,10 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (!(obj instanceof BLSSignature)) { + if (obj instanceof final BLSSignature signature) { + return Objects.equals(toBytesCompressed(), signature.toBytesCompressed()); + } else { return false; } - BLSSignature other = (BLSSignature) obj; - return Objects.equals(toBytesCompressed(), other.toBytesCompressed()); } } diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstPublicKey.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstPublicKey.java index 48eeb778c64..5475e0b66c4 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstPublicKey.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstPublicKey.java @@ -45,8 +45,8 @@ public static BlstPublicKey fromBytes(final Bytes48 compressed) { } static BlstPublicKey fromPublicKey(final PublicKey publicKey) { - if (publicKey instanceof BlstPublicKey) { - return (BlstPublicKey) publicKey; + if (publicKey instanceof final BlstPublicKey blstPublicKey) { + return blstPublicKey; } else { return fromBytes(publicKey.toBytesCompressed()); } @@ -122,11 +122,11 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (!(o instanceof PublicKey)) { + if (o instanceof PublicKey publicKey) { + return Objects.equals(toBytesCompressed(), publicKey.toBytesCompressed()); + } else { return false; } - - return Objects.equals(toBytesCompressed(), ((PublicKey) o).toBytesCompressed()); } @Override diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSecretKey.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSecretKey.java index 04b99bd3c8e..e3e74eb301e 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSecretKey.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSecretKey.java @@ -97,9 +97,10 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (!(o instanceof SecretKey)) { + if (o instanceof final SecretKey secretKey) { + return Objects.equals(toBytes(), secretKey.toBytes()); + } else { return false; } - return Objects.equals(toBytes(), ((SecretKey) o).toBytes()); } } diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSignature.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSignature.java index 9bf06c97047..8b5f5124369 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSignature.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/impl/blst/BlstSignature.java @@ -47,8 +47,8 @@ public static BlstSignature fromBytes(final Bytes compressed) { } static BlstSignature fromSignature(final Signature signature) { - if (signature instanceof BlstSignature) { - return (BlstSignature) signature; + if (signature instanceof BlstSignature blstSignature) { + return blstSignature; } else { return fromBytes(signature.toBytesCompressed()); } @@ -158,9 +158,10 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (!(o instanceof Signature)) { + if (o instanceof final Signature signature) { + return Objects.equals(toBytesCompressed(), signature.toBytesCompressed()); + } else { return false; } - return Objects.equals(toBytesCompressed(), ((Signature) o).toBytesCompressed()); } } diff --git a/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes20.java b/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes20.java index 41950432574..42910b5dd8d 100644 --- a/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes20.java +++ b/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes20.java @@ -49,8 +49,8 @@ public String toHexString() { */ public static Bytes20 leftPad(final Bytes value) { checkNotNull(value); - if (value instanceof Bytes20) { - return (Bytes20) value; + if (value instanceof final Bytes20 bytes20) { + return bytes20; } checkArgument(value.size() <= SIZE, "Expected at most %s bytes but got %s", SIZE, value.size()); MutableBytes result = MutableBytes.create(SIZE); @@ -67,8 +67,8 @@ public static Bytes20 leftPad(final Bytes value) { */ public static Bytes20 rightPad(final Bytes value) { checkNotNull(value); - if (value instanceof Bytes20) { - return (Bytes20) value; + if (value instanceof final Bytes20 bytes20) { + return bytes20; } checkArgument(value.size() <= SIZE, "Expected at most %s bytes but got %s", SIZE, value.size()); MutableBytes result = MutableBytes.create(SIZE); diff --git a/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes4.java b/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes4.java index de4633fd953..8a70dd3847f 100644 --- a/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes4.java +++ b/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes4.java @@ -52,8 +52,8 @@ public String toHexString() { */ public static Bytes4 leftPad(final Bytes value) { checkNotNull(value); - if (value instanceof Bytes4) { - return (Bytes4) value; + if (value instanceof final Bytes4 bytes4) { + return bytes4; } checkArgument(value.size() <= 4, "Expected at most %s bytes but got %s", 4, value.size()); MutableBytes result = MutableBytes.create(4); @@ -70,8 +70,8 @@ public static Bytes4 leftPad(final Bytes value) { */ public static Bytes4 rightPad(final Bytes value) { checkNotNull(value); - if (value instanceof Bytes4) { - return (Bytes4) value; + if (value instanceof final Bytes4 bytes4) { + return bytes4; } checkArgument(value.size() <= 4, "Expected at most %s bytes but got %s", 4, value.size()); MutableBytes result = MutableBytes.create(4); diff --git a/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes8.java b/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes8.java index 5d68e2970e8..a95b2155a90 100644 --- a/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes8.java +++ b/infrastructure/bytes/src/main/java/tech/pegasys/teku/infrastructure/bytes/Bytes8.java @@ -51,8 +51,8 @@ public String toHexString() { */ public static Bytes8 leftPad(final Bytes value) { checkNotNull(value); - if (value instanceof Bytes8) { - return (Bytes8) value; + if (value instanceof final Bytes8 bytes8) { + return bytes8; } checkArgument(value.size() <= 8, "Expected at most %s bytes but got %s", 8, value.size()); MutableBytes result = MutableBytes.create(8); @@ -69,8 +69,8 @@ public static Bytes8 leftPad(final Bytes value) { */ public static Bytes8 rightPad(final Bytes value) { checkNotNull(value); - if (value instanceof Bytes8) { - return (Bytes8) value; + if (value instanceof final Bytes8 bytes8) { + return bytes8; } checkArgument(value.size() <= 8, "Expected at most %s bytes but got %s", 8, value.size()); MutableBytes result = MutableBytes.create(8); diff --git a/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGCommitment.java b/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGCommitment.java index bd1a4c5831e..b01018aedc1 100644 --- a/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGCommitment.java +++ b/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGCommitment.java @@ -93,12 +93,11 @@ public boolean equals(final Object obj) { return true; } - if (!(obj instanceof KZGCommitment)) { + if (obj instanceof final KZGCommitment other) { + return Objects.equals(this.getBytesCompressed(), other.getBytesCompressed()); + } else { return false; } - - final KZGCommitment other = (KZGCommitment) obj; - return Objects.equals(this.getBytesCompressed(), other.getBytesCompressed()); } @Override diff --git a/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGProof.java b/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGProof.java index 6733bc2b3c2..6b7402d9d45 100644 --- a/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGProof.java +++ b/infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZGProof.java @@ -91,12 +91,11 @@ public boolean equals(final Object obj) { return true; } - if (!(obj instanceof KZGProof)) { + if (obj instanceof final KZGProof other) { + return Objects.equals(this.getBytesCompressed(), other.getBytesCompressed()); + } else { return false; } - - final KZGProof other = (KZGProof) obj; - return Objects.equals(this.getBytesCompressed(), other.getBytesCompressed()); } @Override diff --git a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/EventLogger.java b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/EventLogger.java index 0c7c6996255..5701a4a1b27 100644 --- a/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/EventLogger.java +++ b/infrastructure/logging/src/main/java/tech/pegasys/teku/infrastructure/logging/EventLogger.java @@ -55,10 +55,12 @@ public void genesisEvent( final String genesisEventLog = String.format( - "Genesis Event *** \n" - + "Genesis state root: %s \n" - + "Genesis block root: %s \n" - + "Genesis time: %s GMT", + """ + Genesis Event *** + Genesis state root: %s + Genesis block root: %s + Genesis time: %s GMT + """, hashTreeRoot.toHexString(), genesisBlockRoot.toHexString(), formattedGenesisTime); info(genesisEventLog, Color.CYAN); } diff --git a/infrastructure/restapi/src/main/java/tech/pegasys/teku/infrastructure/restapi/SwaggerUIBuilder.java b/infrastructure/restapi/src/main/java/tech/pegasys/teku/infrastructure/restapi/SwaggerUIBuilder.java index 8c8d689dbfb..552c0e998b9 100644 --- a/infrastructure/restapi/src/main/java/tech/pegasys/teku/infrastructure/restapi/SwaggerUIBuilder.java +++ b/infrastructure/restapi/src/main/java/tech/pegasys/teku/infrastructure/restapi/SwaggerUIBuilder.java @@ -30,7 +30,7 @@ public class SwaggerUIBuilder { // Version here MUST match `swagger-ui` library version - private static final String SWAGGER_UI_VERSION = "5.18.3"; + private static final String SWAGGER_UI_VERSION = "5.20.7"; private static final String SWAGGER_UI_PATH = "/swagger-ui"; private static final String SWAGGER_HOSTED_PATH = "/webjars/swagger-ui/" + SWAGGER_UI_VERSION; diff --git a/infrastructure/ssz/generator/src/main/java/tech/pegasys/teku/infrastructure/ssz/ContainersGenerator.java b/infrastructure/ssz/generator/src/main/java/tech/pegasys/teku/infrastructure/ssz/ContainersGenerator.java index 386e349bec9..ec9ab63b2d9 100644 --- a/infrastructure/ssz/generator/src/main/java/tech/pegasys/teku/infrastructure/ssz/ContainersGenerator.java +++ b/infrastructure/ssz/generator/src/main/java/tech/pegasys/teku/infrastructure/ssz/ContainersGenerator.java @@ -133,10 +133,13 @@ public void generateContainerClasses(final int fieldsCount) { IntStream.range(0, fieldsCount) .mapToObj( i -> - (" @SuppressWarnings(\"unchecked\")\n" - + " public SszSchema getFieldSchema$() {\n" - + " return (SszSchema) getChildSchema($);\n" - + " }\n") + """ + @SuppressWarnings("unchecked") + public SszSchema getFieldSchema$() { + return (SszSchema) getChildSchema($); + } + + """ .replace("$", "" + i)) .collect(Collectors.joining("\n\n")))); generateFromTemplate( diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/collections/impl/BitvectorImpl.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/collections/impl/BitvectorImpl.java index 16330e9e231..df546bb9b4a 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/collections/impl/BitvectorImpl.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/collections/impl/BitvectorImpl.java @@ -146,11 +146,12 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (!(o instanceof BitvectorImpl)) { + if (o instanceof final BitvectorImpl bitvector) { + + return getSize() == bitvector.getSize() && Objects.equal(data, bitvector.data); + } else { return false; } - BitvectorImpl bitvector = (BitvectorImpl) o; - return getSize() == bitvector.getSize() && Objects.equal(data, bitvector.data); } @Override diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszImmutableContainer.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszImmutableContainer.java index ded173d676d..ecfdd7e03a4 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszImmutableContainer.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszImmutableContainer.java @@ -90,12 +90,12 @@ public boolean equals(final Object obj) { return true; } - if (!(obj instanceof AbstractSszImmutableContainer)) { + if (obj instanceof final AbstractSszImmutableContainer other) { + + return hashTreeRoot().equals(other.hashTreeRoot()); + } else { return false; } - - AbstractSszImmutableContainer other = (AbstractSszImmutableContainer) obj; - return hashTreeRoot().equals(other.hashTreeRoot()); } @Override diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszMutableComposite.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszMutableComposite.java index c03cc074408..3887e2f7bc5 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszMutableComposite.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/AbstractSszMutableComposite.java @@ -83,8 +83,8 @@ public void set(final int index, final SszChildT value) { validateChildSchema(index, value); final SszChildT immutableValue; - if (value instanceof SszMutableData) { - immutableValue = (SszChildT) ((SszMutableData) value).commitChanges(); + if (value instanceof final SszMutableData sszMutableData) { + immutableValue = (SszChildT) sszMutableData.commitChanges(); } else { immutableValue = value; } diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/SszUnionImpl.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/SszUnionImpl.java index 371185bf794..c661adfb483 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/SszUnionImpl.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/impl/SszUnionImpl.java @@ -69,13 +69,13 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (!(o instanceof SszUnion)) { + if (o instanceof final SszUnion sszUnion) { + return Objects.equal(getSchema(), sszUnion.getSchema()) + && getSelector() == sszUnion.getSelector() + && Objects.equal(hashTreeRoot(), sszUnion.hashTreeRoot()); + } else { return false; } - SszUnion sszUnion = (SszUnion) o; - return Objects.equal(getSchema(), sszUnion.getSchema()) - && getSelector() == sszUnion.getSelector() - && Objects.equal(hashTreeRoot(), sszUnion.hashTreeRoot()); } @Override diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszPrimitiveSchema.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszPrimitiveSchema.java index bea047068ec..4637e3c6dd6 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszPrimitiveSchema.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/AbstractSszPrimitiveSchema.java @@ -103,6 +103,7 @@ public TreeNode loadBackingNodes( } @Override + @SuppressWarnings("PatternMatchingInstanceof") public final DataT createFromPackedNodeUnboxed(final TreeNode node, final int internalIndex) { assert node instanceof LeafDataNode; return createFromLeafBackingNode((LeafDataNode) node, internalIndex); @@ -149,9 +150,9 @@ public int getSszVariablePartSize(final TreeNode node) { @Override public int sszSerializeTree(final TreeNode node, final SszWriter writer) { final Bytes nodeData; - if (node instanceof LeafDataNode) { + if (node instanceof final LeafDataNode leafDataNode) { // small perf optimization - nodeData = ((LeafDataNode) node).getData(); + nodeData = leafDataNode.getData(); } else { nodeData = node.hashTreeRoot(); } diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/LoadingUtil.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/LoadingUtil.java index 96980e3ead0..5248cea8741 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/LoadingUtil.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/schema/impl/LoadingUtil.java @@ -130,19 +130,12 @@ public static TreeNode loadNodesToDepth( private static boolean isZeroBranchUseful(final long rootGIndex, final long lastUsefulGIndex) { final NodeRelation relationRootToLastUseful = GIndexUtil.gIdxCompare(rootGIndex, lastUsefulGIndex); - switch (relationRootToLastUseful) { - case LEFT: - case PREDECESSOR: - return true; - - case SAME: - case RIGHT: - case SUCCESSOR: - return false; - - default: - throw new IllegalStateException("Unknown relation type: " + relationRootToLastUseful); - } + return switch (relationRootToLastUseful) { + case LEFT, PREDECESSOR -> true; + case SAME, RIGHT, SUCCESSOR -> false; + default -> + throw new IllegalStateException("Unknown relation type: " + relationRootToLastUseful); + }; } private static BranchNode createUsefulEmptyBranch( diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/GIndexUtil.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/GIndexUtil.java index 1b12e257c23..6e752231da4 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/GIndexUtil.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/GIndexUtil.java @@ -39,20 +39,14 @@ public enum NodeRelation { /** gIdxCompare(idx1, idx2) == gIdxCompare(idx2, idx1).inverse() */ public NodeRelation inverse() { - switch (this) { - case LEFT: - return RIGHT; - case RIGHT: - return LEFT; - case PREDECESSOR: - return SUCCESSOR; - case SUCCESSOR: - return PREDECESSOR; - case SAME: - return SAME; - default: - throw new IllegalArgumentException("Unknown: " + this); - } + return switch (this) { + case LEFT -> RIGHT; + case RIGHT -> LEFT; + case PREDECESSOR -> SUCCESSOR; + case SUCCESSOR -> PREDECESSOR; + case SAME -> SAME; + default -> throw new IllegalArgumentException("Unknown: " + this); + }; } } diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SimpleLeafNode.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SimpleLeafNode.java index 0a2365ef05f..4e8c15867a3 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SimpleLeafNode.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SimpleLeafNode.java @@ -81,11 +81,11 @@ public boolean equals(final Object o) { if (this == o) { return true; } - if (!(o instanceof LeafNode)) { + if (o instanceof final LeafNode otherLeaf) { + return Objects.equals(getData(), otherLeaf.getData()); + } else { return false; } - LeafNode otherLeaf = (LeafNode) o; - return Objects.equals(getData(), otherLeaf.getData()); } @Override diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SszNodeTemplate.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SszNodeTemplate.java index 9b33bfc887c..33a8fe8613f 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SszNodeTemplate.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/SszNodeTemplate.java @@ -182,8 +182,8 @@ public Bytes32 visitBranch( private static T binaryTraverse( final long gIndex, final TreeNode node, final BinaryVisitor visitor) { - if (node instanceof LeafNode) { - return visitor.visitLeaf(gIndex, (LeafNode) node); + if (node instanceof final LeafNode leafnode) { + return visitor.visitLeaf(gIndex, leafnode); } else if (node instanceof BranchNode branchNode) { return visitor.visitBranch( gIndex, diff --git a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/TreeUtil.java b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/TreeUtil.java index 9bfd668536f..d72fc46cf7c 100644 --- a/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/TreeUtil.java +++ b/infrastructure/ssz/src/main/java/tech/pegasys/teku/infrastructure/ssz/tree/TreeUtil.java @@ -177,8 +177,8 @@ static void iterateLeaves( fromGeneralIndex, toGeneralIndex, (n, idx) -> { - if (n instanceof LeafNode) { - visitor.accept((LeafNode) n); + if (n instanceof final LeafNode leafNode) { + visitor.accept(leafNode); } return true; }); @@ -193,8 +193,8 @@ public static void iterateLeavesData( fromGeneralIndex, toGeneralIndex, (n, idx) -> { - if (n instanceof LeafDataNode) { - visitor.accept(((LeafDataNode) n).getData()); + if (n instanceof final LeafDataNode leafDataNode) { + visitor.accept(leafDataNode.getData()); } return true; }); diff --git a/infrastructure/ssz/src/testFixtures/java/tech/pegasys/teku/infrastructure/ssz/SszDataAssert.java b/infrastructure/ssz/src/testFixtures/java/tech/pegasys/teku/infrastructure/ssz/SszDataAssert.java index a3faedda9b0..92dd148c629 100644 --- a/infrastructure/ssz/src/testFixtures/java/tech/pegasys/teku/infrastructure/ssz/SszDataAssert.java +++ b/infrastructure/ssz/src/testFixtures/java/tech/pegasys/teku/infrastructure/ssz/SszDataAssert.java @@ -133,8 +133,8 @@ private static List compareByGetters(final SszData actual, final SszData List res = compareByGetters(c1.get(i), c2.get(i)); if (!res.isEmpty()) { String traceDetails; - if (actual instanceof SszContainer) { - SszContainerSchema containerSchema = ((SszContainer) actual).getSchema(); + if (actual instanceof final SszContainer sszContainer) { + SszContainerSchema containerSchema = sszContainer.getSchema(); traceDetails = containerSchema.toString() + "." + containerSchema.getFieldNames().get(i); } else { diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/topics/GossipTopicsTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/topics/GossipTopicsTest.java index 2b6e9fafbf9..794b24b18d6 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/topics/GossipTopicsTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/topics/GossipTopicsTest.java @@ -56,7 +56,7 @@ public void extractForkDigest_invalid() { @Test public void maxSubscribedTopicsConstantIsLargeEnough() { - final SpecMilestone latestMilestone = SpecMilestone.values()[SpecMilestone.values().length - 1]; + final SpecMilestone latestMilestone = SpecMilestone.getHighestMilestone(); final Spec spec = TestSpecFactory.createMainnet(latestMilestone); final StorageSystem storageSystem = InMemoryStorageSystemBuilder.buildDefault(spec); diff --git a/networking/nat/src/main/java/tech/pegasys/teku/networking/nat/UpnpClient.java b/networking/nat/src/main/java/tech/pegasys/teku/networking/nat/UpnpClient.java index 74f31d8926e..7d51537553b 100644 --- a/networking/nat/src/main/java/tech/pegasys/teku/networking/nat/UpnpClient.java +++ b/networking/nat/src/main/java/tech/pegasys/teku/networking/nat/UpnpClient.java @@ -182,13 +182,10 @@ private void inspectDeviceRecursive(final RemoteDevice device) { } private PortMapping.Protocol toJupnpProtocol(final NetworkProtocol protocol) { - switch (protocol) { - case UDP: - return PortMapping.Protocol.UDP; - case TCP: - return PortMapping.Protocol.TCP; - } - return null; + return switch (protocol) { + case UDP -> PortMapping.Protocol.UDP; + case TCP -> PortMapping.Protocol.TCP; + }; } private PortMapping toJupnpPortMapping(final NatPortMapping natPortMapping) { diff --git a/services/bootnode/build.gradle b/services/bootnode/build.gradle index b72dcaeba15..5b9a1bc0b48 100644 --- a/services/bootnode/build.gradle +++ b/services/bootnode/build.gradle @@ -13,6 +13,6 @@ dependencies { implementation project(':storage') implementation project(':storage:api') - testImplementation platform('org.junit:junit-bom:5.10.0') + testImplementation platform('org.junit:junit-bom:5.12.2') testImplementation 'org.junit.jupiter:junit-jupiter' } \ No newline at end of file diff --git a/storage/src/main/java/tech/pegasys/teku/storage/server/rocksdb/RocksDbExceptionUtil.java b/storage/src/main/java/tech/pegasys/teku/storage/server/rocksdb/RocksDbExceptionUtil.java index 440ad9a194b..f0fb7200a5f 100644 --- a/storage/src/main/java/tech/pegasys/teku/storage/server/rocksdb/RocksDbExceptionUtil.java +++ b/storage/src/main/java/tech/pegasys/teku/storage/server/rocksdb/RocksDbExceptionUtil.java @@ -28,16 +28,9 @@ private static boolean isUnrecoverable(final RocksDBException cause) { if (cause.getStatus() == null) { return true; } - switch (cause.getStatus().getCode()) { - case TimedOut: - case TryAgain: - case MergeInProgress: - case Incomplete: - case Busy: - case Expired: - return false; - default: - return true; - } + return switch (cause.getStatus().getCode()) { + case TimedOut, TryAgain, MergeInProgress, Incomplete, Busy, Expired -> false; + default -> true; + }; } } diff --git a/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/FileBackedStorageSystemBuilder.java b/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/FileBackedStorageSystemBuilder.java index 255a1b9e6bb..90a099fce97 100644 --- a/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/FileBackedStorageSystemBuilder.java +++ b/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/FileBackedStorageSystemBuilder.java @@ -69,29 +69,17 @@ public StorageSystem build() { } private Database buildDatabase() { - final Database database; - switch (version) { - case LEVELDB_TREE: - database = createLevelDbTrieDatabase(); - break; - case LEVELDB2: - database = createLevelDb2Database(); - break; - case LEVELDB1: - database = createLevelDb1Database(); - break; - case V6: - database = createV6Database(); - break; - case V5: - database = createV5Database(); - break; - case V4: - database = createV4Database(); - break; - default: - throw new UnsupportedOperationException("Unsupported database version: " + version); - } + final Database database = + switch (version) { + case LEVELDB_TREE -> createLevelDbTrieDatabase(); + case LEVELDB2 -> createLevelDb2Database(); + case LEVELDB1 -> createLevelDb1Database(); + case V6 -> createV6Database(); + case V5 -> createV5Database(); + case V4 -> createV4Database(); + default -> + throw new UnsupportedOperationException("Unsupported database version: " + version); + }; return database; } diff --git a/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/InMemoryStorageSystemBuilder.java b/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/InMemoryStorageSystemBuilder.java index 0f60361ddec..fc6014f4519 100644 --- a/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/InMemoryStorageSystemBuilder.java +++ b/storage/src/testFixtures/java/tech/pegasys/teku/storage/storageSystem/InMemoryStorageSystemBuilder.java @@ -74,25 +74,18 @@ public static StorageSystem buildDefault(final Spec spec) { } public StorageSystem build() { - final Database database; - switch (version) { - case LEVELDB_TREE: - database = createLevelDbTreeDatabase(); - break; - case LEVELDB2: // Leveldb only varies by db type which doesn't apply to in-memory - case V6: - database = createV6Database(); - break; - case LEVELDB1: // Leveldb only varies by db type which doesn't apply to in-memory - case V5: - database = createV5Database(); - break; - case V4: - database = createV4Database(); - break; - default: - throw new UnsupportedOperationException("Unsupported database version: " + version); - } + final Database database = + switch (version) { + case LEVELDB_TREE -> + createLevelDbTreeDatabase(); // Leveldb only varies by db type which doesn't apply to + // in-memory + case LEVELDB2, V6 -> + createV6Database(); // Leveldb only varies by db type which doesn't apply to in-memory + case LEVELDB1, V5 -> createV5Database(); + case V4 -> createV4Database(); + default -> + throw new UnsupportedOperationException("Unsupported database version: " + version); + }; final List validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, numberOfValidators); diff --git a/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/KeystorePasswordOptionsTest.java b/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/KeystorePasswordOptionsTest.java index 6e435f2f909..acd03b8e2ec 100644 --- a/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/KeystorePasswordOptionsTest.java +++ b/teku/src/test/java/tech/pegasys/teku/cli/subcommand/internal/validator/options/KeystorePasswordOptionsTest.java @@ -32,16 +32,12 @@ class KeystorePasswordOptionsTest { private static final String EXPECTED_ENV_VARIABLE = "TEST_ENV"; private static final String SPACE_ENV_VARIABLE = "SPACE_ENV"; private static final Function ENV_SUPPLIER = - envVariable -> { - switch (envVariable) { - case EXPECTED_ENV_VARIABLE: - return PASSWORD; - case SPACE_ENV_VARIABLE: - return " "; - default: - return null; - } - }; + envVariable -> + switch (envVariable) { + case EXPECTED_ENV_VARIABLE -> PASSWORD; + case SPACE_ENV_VARIABLE -> " "; + default -> null; + }; private static final String EXPECTED_ENV_ERROR = "Error: Password cannot be read from environment variable: %s"; private static final String EXPECTED_EMPTY_PASSWORD_FILE_ERROR = diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/GetGasLimit.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/GetGasLimit.java index c9ec3cd16b8..e35929ee521 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/GetGasLimit.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/GetGasLimit.java @@ -61,9 +61,11 @@ public GetGasLimit(final Optional proposerConfigManager) .tags(TAG_GAS_LIMIT) .pathParam(PARAM_PUBKEY_TYPE) .description( - "Get the execution gas limit for an individual validator. This gas limit is the one used by the validator when proposing blocks via an external builder. If no limit has been set explicitly for a key then the process-wide default will be returned.\n" - + "The server may return a 400 status code if no external builder is configured.\n" - + "WARNING: The gas_limit is not used on Phase0 or Altair networks.") + """ + Get the execution gas limit for an individual validator. This gas limit is the one used by the validator when proposing blocks via an external builder. If no limit has been set explicitly for a key then the process-wide default will be returned. + The server may return a 400 status code if no external builder is configured. + WARNING: The gas_limit is not used on Phase0 or Altair networks. + """) .response(SC_OK, "Success response", RESPONSE_TYPE) .withAuthenticationResponses() .withNotFoundResponse() diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/SetGasLimit.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/SetGasLimit.java index ff42bb08850..ca5180f62b6 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/SetGasLimit.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/SetGasLimit.java @@ -58,10 +58,12 @@ public SetGasLimit(final Optional proposerConfigManager) .tags(TAG_GAS_LIMIT) .pathParam(PARAM_PUBKEY_TYPE) .description( - "Set the gas limit for an individual validator. This limit will be propagated to the beacon node for use on future block proposals.\n" - + "The beacon node is responsible for informing external block builders of the change.\n" - + "The server may return a 400 status code if no external builder is configured.\n" - + "WARNING: The gas_limit is not used on Phase0 or Altair networks.") + """ + Set the gas limit for an individual validator. This limit will be propagated to the beacon node for use on future block proposals. + The beacon node is responsible for informing external block builders of the change. + The server may return a 400 status code if no external builder is configured. + WARNING: The gas_limit is not used on Phase0 or Altair networks. + """) .requestBodyType(GAS_LIMIT_REQUEST_BODY) .response(SC_ACCEPTED, "Success") .response(SC_SERVICE_UNAVAILABLE, "Unable to update gas limit at this time") diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/ProposerConfigManagerTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/ProposerConfigManagerTest.java index 486fcf8c5af..08ca919bfe8 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/ProposerConfigManagerTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/ProposerConfigManagerTest.java @@ -436,32 +436,29 @@ private void prepareConfigWithDefaultConfigProperty(final Properties property, f private ProposerConfig.Config buildSingleConfigWithProperty( final Properties property, final Object value, final boolean isDefault) { - switch (property) { - case FEE_RECIPIENT: - return new ProposerConfig.Config((Eth1Address) value, null); - case BUILDER_ENABLED: - return new ProposerConfig.Config( - isDefault ? defaultFeeRecipientConfig : null, - new ProposerConfig.BuilderConfig((Boolean) value, null, null)); - case BUILDER_GAS_LIMIT: - return new ProposerConfig.Config( - isDefault ? defaultFeeRecipientConfig : null, - new ProposerConfig.BuilderConfig(isDefault ? false : null, (UInt64) value, null)); - case BUILDER_REGISTRATION_OVERRIDE_PUB_KEY: - return new ProposerConfig.Config( - isDefault ? defaultFeeRecipientConfig : null, - new ProposerConfig.BuilderConfig( - isDefault ? false : null, - null, - new RegistrationOverrides(null, (BLSPublicKey) value))); - case BUILDER_REGISTRATION_OVERRIDE_TIMESTAMP: - return new ProposerConfig.Config( - isDefault ? defaultFeeRecipientConfig : null, - new ProposerConfig.BuilderConfig( - isDefault ? false : null, null, new RegistrationOverrides((UInt64) value, null))); - } - - throw new RuntimeException(); + return switch (property) { + case FEE_RECIPIENT -> new ProposerConfig.Config((Eth1Address) value, null); + case BUILDER_ENABLED -> + new ProposerConfig.Config( + isDefault ? defaultFeeRecipientConfig : null, + new ProposerConfig.BuilderConfig((Boolean) value, null, null)); + case BUILDER_GAS_LIMIT -> + new ProposerConfig.Config( + isDefault ? defaultFeeRecipientConfig : null, + new ProposerConfig.BuilderConfig(isDefault ? false : null, (UInt64) value, null)); + case BUILDER_REGISTRATION_OVERRIDE_PUB_KEY -> + new ProposerConfig.Config( + isDefault ? defaultFeeRecipientConfig : null, + new ProposerConfig.BuilderConfig( + isDefault ? false : null, + null, + new RegistrationOverrides(null, (BLSPublicKey) value))); + case BUILDER_REGISTRATION_OVERRIDE_TIMESTAMP -> + new ProposerConfig.Config( + isDefault ? defaultFeeRecipientConfig : null, + new ProposerConfig.BuilderConfig( + isDefault ? false : null, null, new RegistrationOverrides((UInt64) value, null))); + }; } private void proposerWithRuntimeConfiguration(final Path tempDir) throws IOException { diff --git a/validator/client/src/test/resources/tech/pegasys/teku/validator/client/restapi/paths/_eth_v1_validator_{pubkey}_gas_limit.json b/validator/client/src/test/resources/tech/pegasys/teku/validator/client/restapi/paths/_eth_v1_validator_{pubkey}_gas_limit.json index 8d599af673f..478a5b79186 100644 --- a/validator/client/src/test/resources/tech/pegasys/teku/validator/client/restapi/paths/_eth_v1_validator_{pubkey}_gas_limit.json +++ b/validator/client/src/test/resources/tech/pegasys/teku/validator/client/restapi/paths/_eth_v1_validator_{pubkey}_gas_limit.json @@ -3,7 +3,7 @@ "tags" : [ "Gas Limit" ], "operationId" : "GetGasLimit", "summary" : "Get Validator Gas Limit", - "description" : "Get the execution gas limit for an individual validator. This gas limit is the one used by the validator when proposing blocks via an external builder. If no limit has been set explicitly for a key then the process-wide default will be returned.\nThe server may return a 400 status code if no external builder is configured.\nWARNING: The gas_limit is not used on Phase0 or Altair networks.", + "description" : "Get the execution gas limit for an individual validator. This gas limit is the one used by the validator when proposing blocks via an external builder. If no limit has been set explicitly for a key then the process-wide default will be returned.\nThe server may return a 400 status code if no external builder is configured.\nWARNING: The gas_limit is not used on Phase0 or Altair networks.\n", "parameters" : [ { "name" : "pubkey", "required" : true, @@ -90,7 +90,7 @@ "tags" : [ "Gas Limit" ], "operationId" : "SetGasLimit", "summary" : "Set validator gas limit", - "description" : "Set the gas limit for an individual validator. This limit will be propagated to the beacon node for use on future block proposals.\nThe beacon node is responsible for informing external block builders of the change.\nThe server may return a 400 status code if no external builder is configured.\nWARNING: The gas_limit is not used on Phase0 or Altair networks.", + "description" : "Set the gas limit for an individual validator. This limit will be propagated to the beacon node for use on future block proposals.\nThe beacon node is responsible for informing external block builders of the change.\nThe server may return a 400 status code if no external builder is configured.\nWARNING: The gas_limit is not used on Phase0 or Altair networks.\n", "parameters" : [ { "name" : "pubkey", "required" : true, diff --git a/validator/remote/src/integration-test/java/tech/pegasys/teku/validator/remote/typedef/OkHttpValidatorTypeDefClientTest.java b/validator/remote/src/integration-test/java/tech/pegasys/teku/validator/remote/typedef/OkHttpValidatorTypeDefClientTest.java index a5fe0dbc5b7..f2ffa97fe99 100644 --- a/validator/remote/src/integration-test/java/tech/pegasys/teku/validator/remote/typedef/OkHttpValidatorTypeDefClientTest.java +++ b/validator/remote/src/integration-test/java/tech/pegasys/teku/validator/remote/typedef/OkHttpValidatorTypeDefClientTest.java @@ -227,14 +227,15 @@ void getsSyncingStatus() throws InterruptedException { new MockResponse() .setResponseCode(200) .setBody( - "{\n" - + " \"data\": {\n" - + " \"head_slot\": \"1\",\n" - + " \"sync_distance\": \"1\",\n" - + " \"is_syncing\": true,\n" - + " \"is_optimistic\": true\n" - + " }\n" - + "}")); + """ + { + "data": { + "head_slot": "1", + "sync_distance": "1", + "is_syncing": true, + "is_optimistic": true + } + }""")); final SyncingStatus result = typeDefClient.getSyncingStatus();