-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
# Conflicts: # beacon-chain/sync/subscriber_beacon_blocks.go
consensus-types/blocks/proto.go
Outdated
@@ -188,7 +188,7 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) { | |||
|
|||
func initSignedBlockFromProtoPhase0(pb *eth.SignedBeaconBlock) (*SignedBeaconBlock, error) { | |||
if pb == nil { | |||
return nil, errNilBlock |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
consensus-types/blocks/proto.go
Outdated
func (b *SignedBeaconBlock) Proto() (proto.Message, error) { | ||
if b == nil { | ||
return nil, errNilBlock | ||
return nil, nil |
There was a problem hiding this comment.
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()
):
- Converting a
nil
block to anil
proto equivalent makes sense. SignedBeaconBlock.Copy()
usesProto()
internally and will not work if the block or body arenil
. 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 isnil
.
There was a problem hiding this comment.
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.
7194864
to
42368bc
Compare
# 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
b7b42c1
to
9064b3d
Compare
# Conflicts: # beacon-chain/blockchain/service_test.go # consensus-types/blocks/BUILD.bazel # consensus-types/blocks/getters_test.go # validator/client/validator.go
This PR is currently marked as WIP because the code changes undergo testing in a dev cluster. |
func (b *BeaconBlock) Proto() (proto.Message, error) { | ||
if b == nil { | ||
return nil, errNilBlock | ||
return nil, nil | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #10885 (comment)
# 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
# Conflicts: # beacon-chain/rpc/prysm/v1alpha1/validator/proposer_bellatrix_test.go
8d287c2
to
af5b903
Compare
# Conflicts: # testing/util/bellatrix.go # testing/util/helpers.go
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 newblocks
package. It accomplishes the following tasks from notion.so/prysmaticlabs/Native-Beacon-Block-c862730f431545b6a57333eaa50025d2:interfaces.SignedBeaconBlock
,interfaces.BeaconBlock
,interfaces.BeaconBlockBody
/consensus-types/wrapper
and replace them with calls to the new code.