Starting on phase 1 misc beacon changes#1323
Conversation
Co-Authored-By: Carl Beekhuizen <carl@ethereum.org>
2329171 to
c5acddc
Compare
Co-Authored-By: Hsiao-Wei Wang <hwwang156@gmail.com>
Co-Authored-By: Hsiao-Wei Wang <hwwang156@gmail.com>
…d receipt proof Co-Authored-By: vbuterin <v@buterin.com>
| """ | ||
| Given a state and a list of validator indices, outputs the CompactCommittee representing them. | ||
| """ | ||
| validators = [state.validators[i] for i in committee] |
There was a problem hiding this comment.
| validators = [state.validators[i] for i in committee] | |
| assert len(committee) <= MAX_VALIDATORS_PER_COMMITTEE | |
| validators = [state.validators[i] for i in committee] |
There was a problem hiding this comment.
Is this needed? This function could theoretically be used for different kinds of committees; doesn't seem wise to put a maximum designed around a specific type of committee.
There was a problem hiding this comment.
It's a safety check since the size of CompactCommittee elements are set to maximum MAX_VALIDATORS_PER_COMMITTEE:
class CompactCommittee(Container):
pubkeys: List[BLSPubkey, MAX_VALIDATORS_PER_COMMITTEE]
compact_validators: List[uint64, MAX_VALIDATORS_PER_COMMITTEE]It leads to one more implicit config validity condition of that MAX_VALIDATORS_PER_COMMITTEE >= TARGET_PERSISTENT_COMMITTEE_SIZE. (p.s. #407)
If we want to make this function could be used for different kinds of committees, how about refactoring this function into:
def pack_committee(state: BeaconState, committee: Sequence[ValidatorIndex]) -> Tuple[Sequence[BLSPubkey], Sequence[int]]:
validators = [state.validators[i] for i in committee]
compact_validators = [
pack_compact_validator(i, v.slashed, v.effective_balance // EFFECTIVE_BALANCE_INCREMENT)
for i, v in zip(committee, validators)
]
pubkeys = [v.pubkey for v in validators]
return pubkeys, compact_validators
def committee_to_compact_committee(state: BeaconState, committee: Sequence[ValidatorIndex]) -> CompactCommittee:
assert len(committee) <= MAX_VALIDATORS_PER_COMMITTEE
pubkeys, compact_validators = pack_committee(state, committee)
return CompactCommittee(pubkeys=pubkeys, compact_validators=compact_validators)| ```python | ||
| class CompactCommittee(Container): | ||
| pubkeys: List[BLSPubkey, MAX_VALIDATORS_PER_COMMITTEE] | ||
| compact_validators: List[uint64, MAX_VALIDATORS_PER_COMMITTEE] |
There was a problem hiding this comment.
What do you think about adding a custom type CompactValidator: uint64?
Edit: just realized that CompactValidator and unpack_compact_validator are defined in sync_protocol.md. I'd say:
- Remove
unpack_compact_validatorfrom1_beacon-chain-misc.mdsince it's not used here. - Move
CompactValidatordefinition to1_beacon-chain-misc.md.
There was a problem hiding this comment.
Remove unpack_compact_validator from 1_beacon-chain-misc.md since it's not used here.
Where would it be put though? In the light client file that actually uses it? I can see how that's theoretically better in one way, but it has a big disadvantage, which is that pack and unpack are no longer beside each other. So I'd still favor putting both in the same file, to make it easier for readers to see that they are inverses.
Co-Authored-By: John Adler <adlerjohn@users.noreply.github.com>
Co-Authored-By: John Adler <adlerjohn@users.noreply.github.com>
Co-Authored-By: John Adler <adlerjohn@users.noreply.github.com>
Co-Authored-By: Hsiao-Wei Wang <hwwang156@gmail.com>
|
@vbuterin Is this ready for merge? |
I'd say so. My preference is generally to merge earlier for specs that are still in-progress; it makes it easier to propose further changes. Justin's upcoming PR may force a change to the internals of receipt processing but it won't be large. |
The PR is ready for review :) #1383 |
| class ShardReceiptProof(Container): | ||
| shard: Shard | ||
| proof: List[Hash, PLACEHOLDER] | ||
| receipt: List[ShardReceiptDelta, PLACEHOLDER] |
There was a problem hiding this comment.
Looks like ShardReceiptDelta is going away in #1383. Should we define the ShardReceiptDelta container here?
There was a problem hiding this comment.
Going to merge this and handle the conflict after reviewing #1383. Thanks for pointing this out :)
No description provided.