2019-07-29 13:47:35 +00:00
|
|
|
from eth2spec.test.helpers.keys import privkeys
|
|
|
|
from eth2spec.utils.bls import (
|
|
|
|
bls_sign,
|
|
|
|
only_with_bls,
|
|
|
|
)
|
|
|
|
from eth2spec.utils.ssz.ssz_impl import (
|
|
|
|
signing_root,
|
|
|
|
)
|
|
|
|
|
2019-08-01 06:19:08 +00:00
|
|
|
from .attestations import (
|
|
|
|
sign_shard_attestation,
|
|
|
|
)
|
|
|
|
|
2019-07-29 13:47:35 +00:00
|
|
|
|
|
|
|
@only_with_bls()
|
|
|
|
def sign_shard_block(spec, state, block, shard, proposer_index=None):
|
|
|
|
if proposer_index is None:
|
|
|
|
proposer_index = spec.get_shard_block_proposer_index(state, shard, block.core.slot)
|
|
|
|
|
|
|
|
privkey = privkeys[proposer_index]
|
|
|
|
|
|
|
|
block.signatures.proposer_signature = bls_sign(
|
|
|
|
message_hash=signing_root(block),
|
|
|
|
privkey=privkey,
|
|
|
|
domain=spec.get_domain(
|
|
|
|
state,
|
|
|
|
spec.DOMAIN_SHARD_PROPOSER,
|
|
|
|
spec.compute_epoch_of_shard_slot(block.core.slot),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-08-01 06:19:08 +00:00
|
|
|
def build_empty_shard_block(spec,
|
|
|
|
shard_state,
|
|
|
|
beacon_state,
|
|
|
|
slot,
|
|
|
|
parent_root,
|
|
|
|
signed=False,
|
|
|
|
full_attestation=False):
|
2019-07-29 13:47:35 +00:00
|
|
|
if slot is None:
|
2019-08-01 06:19:08 +00:00
|
|
|
slot = shard_state.slot
|
|
|
|
|
2019-07-29 13:47:35 +00:00
|
|
|
block = spec.ShardBlock(
|
|
|
|
core=spec.ExtendedShardBlockCore(
|
|
|
|
slot=slot,
|
2019-08-01 06:19:08 +00:00
|
|
|
beacon_chain_root=beacon_state.block_roots[beacon_state.slot % spec.SLOTS_PER_HISTORICAL_ROOT],
|
2019-07-29 13:47:35 +00:00
|
|
|
parent_root=parent_root,
|
|
|
|
),
|
|
|
|
signatures=spec.ShardBlockSignatures(
|
2019-08-01 06:19:08 +00:00
|
|
|
attestation_signature=b'\x00' * 96,
|
2019-07-29 13:47:35 +00:00
|
|
|
proposer_signature=b'\x25' * 96,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2019-08-01 06:19:08 +00:00
|
|
|
# attestation
|
|
|
|
if full_attestation:
|
|
|
|
attester_committee = spec.get_persistent_committee(beacon_state, shard_state.shard, block.core.slot)
|
|
|
|
block.core.attester_bitfield = list(
|
|
|
|
(True,) * len(attester_committee) +
|
2019-08-13 01:05:16 +00:00
|
|
|
(False,) * (spec.TARGET_PERSISTENT_COMMITTEE_SIZE * 2 - len(attester_committee))
|
2019-08-01 06:19:08 +00:00
|
|
|
)
|
|
|
|
block.signatures.attestation_signature = sign_shard_attestation(
|
|
|
|
spec,
|
|
|
|
shard_state,
|
|
|
|
beacon_state,
|
|
|
|
block,
|
|
|
|
participants=attester_committee,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
block.signatures.attestation_signature = sign_shard_attestation(
|
|
|
|
spec,
|
|
|
|
shard_state,
|
|
|
|
beacon_state,
|
|
|
|
block,
|
|
|
|
participants=(),
|
|
|
|
)
|
|
|
|
|
2019-07-29 13:47:35 +00:00
|
|
|
if signed:
|
2019-08-01 06:19:08 +00:00
|
|
|
sign_shard_block(spec, beacon_state, block, shard_state.shard)
|
2019-07-29 13:47:35 +00:00
|
|
|
|
|
|
|
return block
|