Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Blocks Ep. 2 - Switch usages to new package #10885

Merged
merged 46 commits into from
Aug 2, 2022

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Jun 15, 2022

Previous episode: #10837

What type of PR is this?

Feature

What does this PR do? Why is it needed?

This PR replace all usages of the old wrapper package with the new blocks package. It accomplishes the following tasks from notion.so/prysmaticlabs/Native-Beacon-Block-c862730f431545b6a57333eaa50025d2:

  • Make these new consensus types implement corresponding existing interfaces: interfaces.SignedBeaconBlock, interfaces.BeaconBlock, interfaces.BeaconBlockBody
  • Find all usages of the current block-related functions from /consensus-types/wrapper and replace them with calls to the new code.
  • Find all usages of the current functions in tests, test helpers and tools, and replace them with calls to the new code.

@rkapka rkapka requested a review from a team as a code owner June 15, 2022 14:00
@rkapka rkapka changed the title Native Blocks Ep. 2 - Switch usages to new package [WIP] Native Blocks Ep. 2 - Switch usages to new package Jun 15, 2022
@@ -188,7 +188,7 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {

func initSignedBlockFromProtoPhase0(pb *eth.SignedBeaconBlock) (*SignedBeaconBlock, error) {
if pb == nil {
return nil, errNilBlock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to relax this assertion because of tests, especially fuzz. Fuzz test randomizing can result in Block or Block.Body being nil, which results in errors and failed tests. I don't know if there is a way to overcome this. Additionally, returning an error means that all test setups, not only fuzz tests, need to set Block and Block.Body fields even if they don't need them. Furthermore, these functions are not exported, and so this change is not too risky.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean even with an error, this shouldn't cause a fuzz test to fail. The fuzz test should be able to handle nil blocks gracefully. Is this what you are seeing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fuzzer generates nil values and then the fuzz test calls NewSignedBeaconBlock which returns an error. This makes the whole test fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job of the fuzzer is to find crashes though, having a nil block shouldnt be an issue. We should be gracefully handling it, can you link which fuzz test causes issues ?

@@ -312,3 +338,29 @@ func Test_BeaconBlockBody_HashTreeRoot(t *testing.T) {
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, actualHTR)
}

func hydrateSignedBeaconBlock() *eth.SignedBeaconBlock {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't use utils.HydrateXXX functions here because that will result in a cyclic dependency. The utils package uses functions from this package.

func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
if b == nil {
return nil, errNilBlock
return nil, nil
Copy link
Contributor Author

@rkapka rkapka Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why I think this change is fine (especially for BeaconBlock.Proto() and BeaconBlockBody.Proto()):

  1. Converting a nil block to a nil proto equivalent makes sense.
  2. SignedBeaconBlock.Copy() uses Proto() internally and will not work if the block or body are nil. This issue came up in several tests. And to me it makes sense to be able to copy a block even if some part of it is nil.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any possible cases where the signed beacon block is ever nil ? Ex: its possible to initialize a block which is nil.

@rkapka rkapka force-pushed the native-blocks-swap-usage branch from 7194864 to 42368bc Compare June 24, 2022 09:26
rkapka added 2 commits June 24, 2022 13:19
# Conflicts:
#	beacon-chain/blockchain/chain_info_test.go
#	beacon-chain/blockchain/execution_engine_test.go
#	beacon-chain/blockchain/head.go
#	beacon-chain/blockchain/head_test.go
#	beacon-chain/blockchain/init_sync_process_block_test.go
#	beacon-chain/blockchain/new_slot_test.go
#	beacon-chain/blockchain/process_attestation_test.go
#	beacon-chain/blockchain/process_block_test.go
#	beacon-chain/blockchain/receive_attestation_test.go
#	beacon-chain/blockchain/receive_block_test.go
#	beacon-chain/blockchain/service_test.go
#	beacon-chain/blockchain/weak_subjectivity_checks_test.go
#	beacon-chain/rpc/eth/beacon/blocks_test.go
#	beacon-chain/rpc/eth/beacon/state_test.go
#	beacon-chain/rpc/eth/beacon/sync_committee_test.go
#	beacon-chain/rpc/eth/beacon/validator_test.go
#	beacon-chain/rpc/eth/debug/debug_test.go
#	beacon-chain/rpc/eth/validator/validator_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/assignments_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go
#	beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go
#	beacon-chain/rpc/prysm/v1alpha1/debug/block_test.go
#	beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/blocks_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_execution_payload_test.go
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go
#	beacon-chain/rpc/statefetcher/fetcher_test.go
#	beacon-chain/state/stategen/getter_test.go
#	beacon-chain/state/stategen/migrate_test.go
#	beacon-chain/state/stategen/replay_test.go
#	beacon-chain/state/stategen/service_test.go
#	beacon-chain/state/stategen/setter_test.go
#	beacon-chain/sync/initial-sync/blocks_fetcher_test.go
#	beacon-chain/sync/initial-sync/blocks_fetcher_utils_test.go
#	beacon-chain/sync/initial-sync/blocks_queue_test.go
#	beacon-chain/sync/initial-sync/initial_sync_test.go
#	beacon-chain/sync/initial-sync/round_robin_test.go
#	beacon-chain/sync/initial-sync/service_test.go
#	beacon-chain/sync/pending_attestations_queue_test.go
#	beacon-chain/sync/pending_blocks_queue_test.go
#	beacon-chain/sync/rpc_beacon_blocks_by_range_test.go
#	beacon-chain/sync/rpc_beacon_blocks_by_root_test.go
#	beacon-chain/sync/rpc_status_test.go
#	beacon-chain/sync/service_test.go
#	beacon-chain/sync/sync_fuzz_test.go
#	beacon-chain/sync/validate_aggregate_proof_test.go
#	beacon-chain/sync/validate_beacon_attestation_test.go
#	beacon-chain/sync/validate_beacon_blocks_test.go
@rkapka rkapka force-pushed the native-blocks-swap-usage branch from b7b42c1 to 9064b3d Compare June 27, 2022 13:22
rkapka added 2 commits June 28, 2022 17:06
# Conflicts:
#	beacon-chain/blockchain/service_test.go
#	consensus-types/blocks/BUILD.bazel
#	consensus-types/blocks/getters_test.go
#	validator/client/validator.go
@rkapka
Copy link
Contributor Author

rkapka commented Jun 28, 2022

This PR is currently marked as WIP because the code changes undergo testing in a dev cluster.

Comment on lines 80 to 83
func (b *BeaconBlock) Proto() (proto.Message, error) {
if b == nil {
return nil, errNilBlock
return nil, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change? I think i saw a comment about it relating to fuzz testing, but I see this change only some structs and not others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rkapka added 3 commits July 28, 2022 18:11
# Conflicts:
#	beacon-chain/blockchain/BUILD.bazel
#	beacon-chain/blockchain/pow_block_test.go
#	beacon-chain/blockchain/process_block.go
#	beacon-chain/core/blocks/BUILD.bazel
#	beacon-chain/core/blocks/payload.go
#	beacon-chain/core/blocks/payload_test.go
#	beacon-chain/db/kv/blocks_test.go
#	beacon-chain/rpc/eth/beacon/blocks.go
#	consensus-types/interfaces/beacon_block.go
@rkapka rkapka dismissed a stale review via 88116c4 July 28, 2022 20:09
@rkapka rkapka requested a review from rauljordan as a code owner July 28, 2022 20:09
@rkapka rkapka changed the title [WIP] Native Blocks Ep. 2 - Switch usages to new package Native Blocks Ep. 2 - Switch usages to new package Aug 1, 2022
# Conflicts:
#	beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go
rauljordan
rauljordan previously approved these changes Aug 2, 2022
@rkapka rkapka force-pushed the native-blocks-swap-usage branch from 8d287c2 to af5b903 Compare August 2, 2022 13:49
rauljordan
rauljordan previously approved these changes Aug 2, 2022
rkapka added 2 commits August 2, 2022 16:58
# Conflicts:
#	testing/util/bellatrix.go
#	testing/util/helpers.go
@prylabs-bulldozer prylabs-bulldozer bot merged commit 879e310 into develop Aug 2, 2022
@delete-merged-branch delete-merged-branch bot deleted the native-blocks-swap-usage branch August 2, 2022 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants