Add shard state transition function#1326
Conversation
hwwhww
left a comment
There was a problem hiding this comment.
Good job! 🎉
- I'm writing some more tests for
shard_state_transitionwith minimalPHASE_1_FORK_EPOCH: SHARD_SLOTS_PER_BEACON_SLOT * SLOTS_PER_EPOCH * EPOCHS_PER_SHARD_PERIOD * 2. Found some bugs and some pending questions in my comments. - It seems
GENESIS_SHARD_SLOTcan be removed now.
| attestations += 1 | ||
|
|
||
| for i in range(len(attester_committee), MAX_PERSISTENT_COMMITTEE_SIZE): | ||
| assert block.core.attester_bitfield[i] is False or block.core.attester_bitfield[i] == 0 # TODO: FIX Bitvector |
There was a problem hiding this comment.
Somehow block.core.attester_bitfield[i] returns 0.
@protolambda is it the expected behavior in pyspec?
There was a problem hiding this comment.
The elements of bitfields are typed as Bit. Bits are int subtypes, since bool can't be changed. It's a trade-off to make bitlist fully consistent with other typed lists. The int output can be cast to a bool. Or you change the other operand to Bit(False). Or, if it is not already working, we change the equality function to accept a bool type when comparing with a Bit.
Co-Authored-By: Hsiao-Wei Wang <hwwang156@gmail.com>
1. Clean up configurations 2. Add `HISTORY_ACCUMULATOR_VECTOR` 3. Add `validate_state_root` flag in `shard_state_transition` for testing 4. Rename `history_acc` to `history_accumulator`
…nd `fee` is in `Gwei`
| if len(block.core.data) > SHARD_BLOCK_SIZE_TARGET: | ||
| state.basefee += Gwei(max(1, state.basefee * (len(block.core.data) - SHARD_BLOCK_SIZE_TARGET) // QUOTIENT)) | ||
| elif len(block.core.data) < SHARD_BLOCK_SIZE_TARGET: | ||
| state.basefee -= Gwei(max(1, state.basefee * (len(block.core.data) - SHARD_BLOCK_SIZE_TARGET) // QUOTIENT)) |
There was a problem hiding this comment.
Although you cap state.basefee to be at least 1 in the next line (state.basefee = Gwei(max(1, min(...) )), but at this line, it seems possible if state.basefee is 1, and then state.basefee -= Gwei(max(1, ...) -> state.basefee = 1 - 2 = -1? It is not allowable since it's an SSZ uint64 field.
Maybe use a temporary variable here?
diff_amount = Gwei(max(1, state.basefee * (len(block.core.data) - SHARD_BLOCK_SIZE_TARGET) // QUOTIENT))
if len(block.core.data) > SHARD_BLOCK_SIZE_TARGET:
basefee_diff = diff_amount
elif len(block.core.data) < SHARD_BLOCK_SIZE_TARGET:
basefee_diff = - diff_amount
else:
basefee_diff = 0
state.basefee = Gwei(max(
1,
min(
EFFECTIVE_BALANCE_INCREMENT // EPOCHS_PER_SHARD_PERIOD // SHARD_SLOTS_PER_BEACON_SLOT * SLOTS_PER_EPOCH,
state.basefee + basefee_diff,
)
))There was a problem hiding this comment.
I think people will complain about even temporary variables that could be negative 😄
I don't know, I'm fine with any approach.
Co-Authored-By: Hsiao-Wei Wang <hwwang156@gmail.com>
Also adds `total_bytes` to state. The goal is to facilitate easier fraud proofs, so that one needs to simply check two adjacent headers in a crosslink and their respective bodies to verify a fraud proof.
hwwhww
left a comment
There was a problem hiding this comment.
As telegram discussion, it may need more iterations, but since it's blocking others, suggest merging it now.
No description provided.