mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-21 14:58:12 +00:00
Abstracted (Kate commitment, length) into separate object
This commit is contained in:
parent
3d108e7fe2
commit
ed357b9f9f
@ -108,7 +108,7 @@ class BeaconBlock(phase0.BeaconBlock):
|
|||||||
class BeaconState(phase0.BeaconState):
|
class BeaconState(phase0.BeaconState):
|
||||||
current_epoch_pending_headers: List[PendingHeader, MAX_PENDING_HEADERS * SLOTS_PER_EPOCH]
|
current_epoch_pending_headers: List[PendingHeader, MAX_PENDING_HEADERS * SLOTS_PER_EPOCH]
|
||||||
previous_epoch_pending_headers: List[PendingHeader, MAX_PENDING_HEADERS * SLOTS_PER_EPOCH]
|
previous_epoch_pending_headers: List[PendingHeader, MAX_PENDING_HEADERS * SLOTS_PER_EPOCH]
|
||||||
two_epochs_ago_confirmed_headers: Vector[Vector[PendingShardHeader, SLOTS_PER_EPOCH], MAX_SHARDS]
|
most_recent_confirmed_commitments: Vector[Vector[DataCommitment, SLOTS_PER_EPOCH], MAX_SHARDS]
|
||||||
shard_gasprice: uint64
|
shard_gasprice: uint64
|
||||||
current_epoch_start_shard: Shard
|
current_epoch_start_shard: Shard
|
||||||
```
|
```
|
||||||
@ -117,6 +117,16 @@ class BeaconState(phase0.BeaconState):
|
|||||||
|
|
||||||
The following containers are new in Phase 1.
|
The following containers are new in Phase 1.
|
||||||
|
|
||||||
|
### `DataCommitment`
|
||||||
|
|
||||||
|
```python
|
||||||
|
class DataCommitment(Container):
|
||||||
|
# Kate commitment to the data
|
||||||
|
point: BLSCommitment
|
||||||
|
# Length of the data in samples
|
||||||
|
length: length
|
||||||
|
```
|
||||||
|
|
||||||
### `ShardHeader`
|
### `ShardHeader`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -124,10 +134,8 @@ class ShardHeader(Container):
|
|||||||
# Slot and shard that this header is intended for
|
# Slot and shard that this header is intended for
|
||||||
slot: Slot
|
slot: Slot
|
||||||
shard: Shard
|
shard: Shard
|
||||||
# Kate commitment to the data
|
# The actual data commitment
|
||||||
commitment: BLSCommitment
|
commitment: DataCommitment
|
||||||
# Length of the data in samples
|
|
||||||
length: uint64
|
|
||||||
# Proof of the length (more precisely, proof that values at
|
# Proof of the length (more precisely, proof that values at
|
||||||
# positions >= the length all equal zero)
|
# positions >= the length all equal zero)
|
||||||
length_proof: BLSCommitment
|
length_proof: BLSCommitment
|
||||||
@ -400,8 +408,8 @@ def process_shard_header(state: BeaconState,
|
|||||||
)
|
)
|
||||||
# Verify length of the header
|
# Verify length of the header
|
||||||
assert (
|
assert (
|
||||||
bls.Pairing(header.length_proof, SIZE_CHECK_POINTS[header.length]) ==
|
bls.Pairing(header.length_proof, SIZE_CHECK_POINTS[header.commitment.length]) ==
|
||||||
bls.Pairing(header.commitment, G2_ONE)
|
bls.Pairing(header.commitment.point, G2_ONE)
|
||||||
)
|
)
|
||||||
# Get the correct pending header list
|
# Get the correct pending header list
|
||||||
if compute_epoch_at_slot(header.slot) == get_current_epoch(state):
|
if compute_epoch_at_slot(header.slot) == get_current_epoch(state):
|
||||||
@ -419,7 +427,6 @@ def process_shard_header(state: BeaconState,
|
|||||||
shard=header.shard,
|
shard=header.shard,
|
||||||
commitment=header.commitment,
|
commitment=header.commitment,
|
||||||
root=header_root,
|
root=header_root,
|
||||||
length=header.length,
|
|
||||||
votes=Bitlist[MAX_COMMITTEE_SIZE]([0] * committee_length),
|
votes=Bitlist[MAX_COMMITTEE_SIZE]([0] * committee_length),
|
||||||
confirmed=False
|
confirmed=False
|
||||||
))
|
))
|
||||||
@ -499,10 +506,10 @@ def process_pending_headers(state: BeaconState):
|
|||||||
candidates[winning_index].confirmed = True
|
candidates[winning_index].confirmed = True
|
||||||
for slot in range(SLOTS_PER_EPOCH):
|
for slot in range(SLOTS_PER_EPOCH):
|
||||||
for shard in range(SHARD_COUNT):
|
for shard in range(SHARD_COUNT):
|
||||||
state.two_epochs_ago_confirmed_headers[shard][slot] = PendingHeader()
|
state.most_recent_confirmed_commitments[shard][slot] = DataCommitment()
|
||||||
for c in state.previous_epoch_pending_headers:
|
for c in state.previous_epoch_pending_headers:
|
||||||
if c.confirmed:
|
if c.confirmed:
|
||||||
state.two_epochs_ago_confirmed_headers[c.shard][c.slot % SLOTS_PER_EPOCH] = c
|
state.most_recent_confirmed_commitments[c.shard][c.slot % SLOTS_PER_EPOCH] = c.commitment
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -520,13 +527,13 @@ def charge_confirmed_header_fees(state: BeaconState) -> None:
|
|||||||
# Charge EIP 1559 fee
|
# Charge EIP 1559 fee
|
||||||
proposer = get_shard_proposer(state, slot, shard)
|
proposer = get_shard_proposer(state, slot, shard)
|
||||||
fee = (
|
fee = (
|
||||||
(state.shard_gasprice * candidates[i].length) //
|
(state.shard_gasprice * candidates[i].commitment.length) //
|
||||||
TARGET_SAMPLES_PER_BLOCK
|
TARGET_SAMPLES_PER_BLOCK
|
||||||
)
|
)
|
||||||
decrease_balance(state, proposer, fee)
|
decrease_balance(state, proposer, fee)
|
||||||
new_gasprice = compute_updated_gasprice(
|
new_gasprice = compute_updated_gasprice(
|
||||||
new_gasprice,
|
new_gasprice,
|
||||||
candidates[i].length,
|
candidates[i].commitment.length,
|
||||||
adjustment_quotient
|
adjustment_quotient
|
||||||
)
|
)
|
||||||
state.shard_gasprice = new_gasprice
|
state.shard_gasprice = new_gasprice
|
||||||
@ -556,9 +563,8 @@ def reset_pending_headers(state: BeaconState):
|
|||||||
state.current_epoch_pending_headers.append(PendingShardHeader(
|
state.current_epoch_pending_headers.append(PendingShardHeader(
|
||||||
slot=slot,
|
slot=slot,
|
||||||
shard=shard,
|
shard=shard,
|
||||||
commitment=BLSCommitment(),
|
commitment=DataCommitment(),
|
||||||
root=Root(),
|
root=Root(),
|
||||||
length=0,
|
|
||||||
votes=Bitlist[MAX_COMMITTEE_SIZE]([0] * committee_length),
|
votes=Bitlist[MAX_COMMITTEE_SIZE]([0] * committee_length),
|
||||||
confirmed=False
|
confirmed=False
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user