Update 1_beacon_chain_misc.md
This commit is contained in:
parent
fe9fe8a151
commit
caadc0d234
|
@ -13,6 +13,17 @@
|
||||||
|
|
||||||
<!-- /TOC -->
|
<!-- /TOC -->
|
||||||
|
|
||||||
|
## Classes
|
||||||
|
|
||||||
|
#### `ShardReceiptProof`
|
||||||
|
|
||||||
|
```python
|
||||||
|
class ShardReceiptProof(Container):
|
||||||
|
shard: Shard
|
||||||
|
proof: List[Hash, PLACEHOLDER]
|
||||||
|
receipt: List[ShardReceiptDelta, PLACEHOLDER]
|
||||||
|
```
|
||||||
|
|
||||||
## Helpers
|
## Helpers
|
||||||
|
|
||||||
#### `pack_compact_validator`
|
#### `pack_compact_validator`
|
||||||
|
@ -27,7 +38,7 @@ def pack_compact_validator(index: uint64, slashed: bool, balance_in_increments:
|
||||||
return (index << 16) + (slashed << 15) + balance_in_increments
|
return (index << 16) + (slashed << 15) + balance_in_increments
|
||||||
```
|
```
|
||||||
|
|
||||||
### `unpack_compact_validator`
|
#### `unpack_compact_validator`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def unpack_compact_validator(compact_validator: uint64) -> Tuple[uint64, bool, uint64]:
|
def unpack_compact_validator(compact_validator: uint64) -> Tuple[uint64, bool, uint64]:
|
||||||
|
@ -92,9 +103,9 @@ def get_generalized_index_of_crosslink_header(index: int) -> GeneralizedIndex:
|
||||||
#### `process_shard_receipt`
|
#### `process_shard_receipt`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def process_shard_receipt(state: BeaconState, shard: Shard, proof: List[Hash, PLACEHOLDER], receipt: List[ShardReceiptDelta, PLACEHOLDER]):
|
def process_shard_receipt(state: BeaconState, receipt_proof: ShardReceiptProof):
|
||||||
receipt_slot = state.next_shard_receipt_period[shard] * SLOTS_PER_EPOCH * EPOCHS_PER_SHARD_PERIOD
|
receipt_slot = state.next_shard_receipt_period[receipt_proof.shard] * SLOTS_PER_EPOCH * EPOCHS_PER_SHARD_PERIOD
|
||||||
first_slot_in_last_crosslink = state.current_crosslinks[shard].start_epoch * SLOTS_PER_EPOCH
|
first_slot_in_last_crosslink = state.current_crosslinks[receipt_proof.shard].start_epoch * SLOTS_PER_EPOCH
|
||||||
gindex = concat_generalized_indices(
|
gindex = concat_generalized_indices(
|
||||||
get_generalized_index_of_crosslink_header(0),
|
get_generalized_index_of_crosslink_header(0),
|
||||||
get_generalized_index(ShardBlockHeader, 'state_root')
|
get_generalized_index(ShardBlockHeader, 'state_root')
|
||||||
|
@ -102,11 +113,16 @@ def process_shard_receipt(state: BeaconState, shard: Shard, proof: List[Hash, PL
|
||||||
get_generalized_index(ShardState, 'receipt_root')
|
get_generalized_index(ShardState, 'receipt_root')
|
||||||
)
|
)
|
||||||
assert verify_merkle_proof(
|
assert verify_merkle_proof(
|
||||||
leaf=hash_tree_root(receipt),
|
leaf=hash_tree_root(receipt_proof.receipt),
|
||||||
proof=proof,
|
proof=receipt_proof.proof,
|
||||||
index=gindex,
|
index=gindex,
|
||||||
root=state.current_crosslinks[shard].data_root
|
root=state.current_crosslinks[shard].data_root
|
||||||
)
|
)
|
||||||
|
for delta in receipt_proof.receipt:
|
||||||
|
increase_balance(state, delta.index, state.validators[delta.index].effective_balance * delta.reward_coefficient // REWARD_COEFFICIENT_BASE)
|
||||||
|
decrease_balance(state, delta.index, delta.block_fee)
|
||||||
|
state.next_shard_receipt_period[receipt_proof.shard] += 1
|
||||||
|
increase_balance(state, get_beacon_proposer_index(state), MICRO_REWARD)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
@ -133,3 +149,11 @@ def update_persistent_committee(state: BeaconState):
|
||||||
])
|
])
|
||||||
state.next_persistent_committee_root = hash_tree_root(committees)
|
state.next_persistent_committee_root = hash_tree_root(committees)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Shard receipt processing
|
||||||
|
|
||||||
|
Add to the beacon block body the following object:
|
||||||
|
|
||||||
|
* `shard_receipts: List[ShardReceipt, MAX_SHARD_RECEIPTS]`
|
||||||
|
|
||||||
|
Use `process_shard_receipt` to process each receipt.
|
||||||
|
|
Loading…
Reference in New Issue