Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def make_fixture(self) -> Self:
)

# Store the filled block for serialization.
block = signed_block.message
block = signed_block.block
step._filled_block = block

# Register labeled blocks for fork building.
Expand Down Expand Up @@ -449,7 +449,7 @@ def _build_block_from_spec(

# Assemble the signed block.
return SignedBlock(
message=final_block,
block=final_block,
signature=BlockSignatures(
attestation_signatures=attestation_signatures_blob,
proposer_signature=proposer_signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _build_block_from_spec(
proposer_signature = create_dummy_signature()

return SignedBlock(
message=final_block,
block=final_block,
signature=BlockSignatures(
attestation_signatures=attestation_signatures,
proposer_signature=proposer_signature,
Expand Down
6 changes: 3 additions & 3 deletions src/lean_spec/subspecs/containers/block/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class BlockSignatures(Container):
class SignedBlock(Container):
"""Envelope carrying a block and its aggregated signatures."""

message: Block
block: Block
"""The block being signed."""

signature: BlockSignatures
Expand All @@ -116,9 +116,9 @@ def verify_signatures(
Raises:
AssertionError: On verification failure.
"""
block = self.message
block = self.block
signatures = self.signature
aggregated_attestations = block.body.attestations
aggregated_attestations = self.block.body.attestations
attestation_signatures = signatures.attestation_signatures

# Each attestation in the body must have a corresponding signature entry.
Expand Down
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/forkchoice/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def on_block(
Raises:
AssertionError: If parent block/state not found in store.
"""
block = signed_block.message
block = signed_block.block
block_root = hash_tree_root(block)

# Skip duplicate blocks (idempotent operation)
Expand Down
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/networking/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async def publish_block(self, block: SignedBlock) -> None:
compressed = compress(ssz_bytes)

await self.event_source.publish(topic.to_topic_id(), compressed)
logger.debug("Published block at slot %s", block.message.slot)
logger.debug("Published block at slot %s", block.block.slot)

async def publish_attestation(
self, attestation: SignedAttestation, subnet_id: SubnetId
Expand Down
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/sync/block_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def add(
Returns:
The PendingBlock wrapper, either newly created or existing.
"""
block_inner = block.message
block_inner = block.block
root = hash_tree_root(block_inner)

# Deduplication: if we already have this block, return the existing entry.
Expand Down
8 changes: 4 additions & 4 deletions src/lean_spec/subspecs/sync/head_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def on_gossip_block(
Tuple of (result describing what happened, updated store).
The store is unchanged if the block was cached.
"""
block_inner = block.message
block_inner = block.block
block_root = hash_tree_root(block_inner)
parent_root = block_inner.parent_root
slot = block_inner.slot
Expand Down Expand Up @@ -234,8 +234,8 @@ async def _process_block_with_descendants(
Returns:
Result and updated store.
"""
block_root = hash_tree_root(block.message)
slot = block.message.slot
block_root = hash_tree_root(block.block)
slot = block.block.slot
self._processing.add(block_root)

try:
Expand Down Expand Up @@ -366,7 +366,7 @@ async def _cache_and_backfill(
Returns:
Result indicating the block was cached, and unchanged store.
"""
block_inner = block.message
block_inner = block.block
parent_root = block_inner.parent_root

# Add to cache.
Expand Down
8 changes: 4 additions & 4 deletions src/lean_spec/subspecs/sync/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _process_block_wrapper(
# This is write-through: data is persisted synchronously after processing.
# The database call is optional - nodes can run without persistence.
if self.database is not None:
self._persist_block(new_store, block.message)
self._persist_block(new_store, block.block)

return new_store

Expand Down Expand Up @@ -423,7 +423,7 @@ async def on_gossip_block(
logger.info(
"Block received from peer %s slot=%s (state=%s)",
peer_id,
block.message.slot,
block.block.slot,
self._state.name,
)

Expand All @@ -445,8 +445,8 @@ async def on_gossip_block(
#
# A block may be cached instead of processed if its parent is unknown.
if result.processed:
slot = block.message.slot
block_root = hash_tree_root(block.message)
slot = block.block.slot
block_root = hash_tree_root(block.block)
logger.info(
"Block processed slot=%s root=%s from peer %s",
slot,
Expand Down
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/validator/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def _sign_block(
)

return SignedBlock(
message=block,
block=block,
signature=signature,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/consensus/devnet/ssz/test_consensus_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_signed_block_minimal(ssz: SSZTestFiller) -> None:
)
ssz(
type_name="SignedBlock",
value=SignedBlock(message=block, signature=signature),
value=SignedBlock(block=block, signature=signature),
)


Expand Down
4 changes: 2 additions & 2 deletions tests/lean_spec/helpers/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def make_signed_block(
)

return SignedBlock(
message=block,
block=block,
signature=BlockSignatures(
attestation_signatures=AttestationSignatures(data=[]),
proposer_signature=make_mock_signature(),
Expand Down Expand Up @@ -458,7 +458,7 @@ def make_signed_block_from_store(
attestation_signatures = key_manager.build_attestation_signatures(block.body.attestations)

signed_block = SignedBlock(
message=block,
block=block,
signature=BlockSignatures(
attestation_signatures=attestation_signatures,
proposer_signature=proposer_signature,
Expand Down
8 changes: 4 additions & 4 deletions tests/lean_spec/helpers/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def request_block_by_root(

def add_block(self, block: SignedBlock) -> Bytes32:
"""Add a block to the mock network. Returns its root."""
root = hash_tree_root(block.message)
root = hash_tree_root(block.block)
self.blocks_by_root[root] = block
return root

Expand Down Expand Up @@ -119,10 +119,10 @@ def on_block(
**kwargs: object,
) -> MockForkchoiceStore:
"""Track block additions. Returns self for assignment chaining."""
root = hash_tree_root(block.message)
self.blocks[root] = block.message
root = hash_tree_root(block.block)
self.blocks[root] = block.block
self.head = root
self.head_slot = block.message.slot
self.head_slot = block.block.slot
return self

def on_gossip_attestation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def test_attestation_target_after_on_block(
proposer_signature = key_manager.sign_block_root(proposer_1, slot_1, block_root)

signed_block = SignedBlock(
message=block,
block=block,
signature=BlockSignatures(
attestation_signatures=AttestationSignatures(data=signatures),
proposer_signature=proposer_signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def test_linear_chain_weight_accumulates_upward(base_store: Store) -> None:
parent_root=genesis_root,
state_root=make_bytes32(10),
)
block1_root = hash_tree_root(block1.message)
block1_root = hash_tree_root(block1.block)

block2 = make_signed_block(
slot=Slot(2),
proposer_index=ValidatorIndex(1),
parent_root=block1_root,
state_root=make_bytes32(20),
)
block2_root = hash_tree_root(block2.message)
block2_root = hash_tree_root(block2.block)

new_blocks = dict(base_store.blocks)
new_blocks[block1_root] = block1.message
new_blocks[block2_root] = block2.message
new_blocks[block1_root] = block1.block
new_blocks[block2_root] = block2.block

new_states = dict(base_store.states)
genesis_state = base_store.states[genesis_root]
Expand Down Expand Up @@ -93,10 +93,10 @@ def test_multiple_attestations_accumulate(base_store: Store) -> None:
parent_root=genesis_root,
state_root=make_bytes32(10),
)
block1_root = hash_tree_root(block1.message)
block1_root = hash_tree_root(block1.block)

new_blocks = dict(base_store.blocks)
new_blocks[block1_root] = block1.message
new_blocks[block1_root] = block1.block

new_states = dict(base_store.states)
new_states[block1_root] = base_store.states[genesis_root]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async def test_request_single_block_success(self) -> None:
blocks = await client.request_blocks_by_root(peer_id, roots)

assert len(blocks) == 1
assert blocks[0].message.slot == Slot(10)
assert blocks[0].block.slot == Slot(10)

async def test_request_multiple_blocks_success(self) -> None:
"""Successfully request multiple blocks."""
Expand All @@ -312,7 +312,7 @@ async def test_request_multiple_blocks_success(self) -> None:
blocks = await client.request_blocks_by_root(peer_id, roots)

assert len(blocks) == 2
slots = {b.message.slot for b in blocks}
slots = {b.block.slot for b in blocks}
assert Slot(10) in slots
assert Slot(20) in slots

Expand All @@ -335,7 +335,7 @@ async def test_request_blocks_partial_response(self) -> None:

# Only one block returned, RESOURCE_UNAVAILABLE continues reading
assert len(blocks) == 1
assert blocks[0].message.slot == Slot(10)
assert blocks[0].block.slot == Slot(10)

async def test_request_blocks_empty_request(self) -> None:
"""Empty root list returns empty without request."""
Expand Down Expand Up @@ -535,7 +535,7 @@ async def test_blocks_codec_error_stops_reading(self) -> None:

# Only block before codec error is returned
assert len(blocks) == 1
assert blocks[0].message.slot == Slot(10)
assert blocks[0].block.slot == Slot(10)


class TestReqRespClientConcurrency:
Expand Down Expand Up @@ -615,7 +615,7 @@ async def test_concurrent_mixed_requests(self) -> None:
assert status is not None
assert status.head.slot == Slot(200)
assert len(blocks) == 1
assert blocks[0].message.slot == Slot(42)
assert blocks[0].block.slot == Slot(42)


class TestReqRespClientStreamLifecycle:
Expand Down
20 changes: 10 additions & 10 deletions tests/lean_spec/subspecs/networking/reqresp/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ async def lookup(root: Bytes32) -> SignedBlock | None:
decoded1 = SignedBlock.decode_bytes(response.successes[0])
decoded2 = SignedBlock.decode_bytes(response.successes[1])

assert decoded1.message.slot == Slot(1)
assert decoded2.message.slot == Slot(2)
assert decoded1.block.slot == Slot(1)
assert decoded2.block.slot == Slot(2)

async def test_handle_blocks_by_root_skips_missing_blocks(self) -> None:
"""Missing blocks are silently skipped."""
Expand Down Expand Up @@ -359,7 +359,7 @@ async def lookup(root: Bytes32) -> SignedBlock | None:
assert len(response.successes) == 1

decoded = SignedBlock.decode_bytes(response.successes[0])
assert decoded.message.slot == Slot(2)
assert decoded.block.slot == Slot(2)


class TestReqRespServer:
Expand Down Expand Up @@ -423,7 +423,7 @@ async def lookup(root: Bytes32) -> SignedBlock | None:
assert code == ResponseCode.SUCCESS

returned_block = SignedBlock.decode_bytes(ssz_data)
assert returned_block.message.slot == Slot(1)
assert returned_block.block.slot == Slot(1)

async def test_empty_request_returns_error(self) -> None:
"""Empty request data returns INVALID_REQUEST error."""
Expand Down Expand Up @@ -618,7 +618,7 @@ async def lookup(root: Bytes32) -> SignedBlock | None:
blocks.append(SignedBlock.decode_bytes(ssz_bytes))

assert len(blocks) == 2
slots = {b.message.slot for b in blocks}
slots = {b.block.slot for b in blocks}
assert Slot(10) in slots
assert Slot(20) in slots

Expand Down Expand Up @@ -652,7 +652,7 @@ async def lookup(root: Bytes32) -> SignedBlock | None:

# Only one block returned
assert len(blocks) == 1
assert blocks[0].message.slot == Slot(10)
assert blocks[0].block.slot == Slot(10)


class TestStreamResponseAdapterMultipleResponses:
Expand Down Expand Up @@ -876,7 +876,7 @@ async def lookup(r: Bytes32) -> SignedBlock | None:
assert len(response.successes) == 1

decoded = SignedBlock.decode_bytes(response.successes[0])
assert decoded.message.slot == Slot(999)
assert decoded.block.slot == Slot(999)

async def test_blocks_by_root_all_missing(self) -> None:
"""Request where all blocks are missing returns no success responses."""
Expand Down Expand Up @@ -938,8 +938,8 @@ async def lookup(root: Bytes32) -> SignedBlock | None:
decoded1 = SignedBlock.decode_bytes(response.successes[0])
decoded2 = SignedBlock.decode_bytes(response.successes[1])

assert decoded1.message.slot == Slot(1)
assert decoded2.message.slot == Slot(3)
assert decoded1.block.slot == Slot(1)
assert decoded2.block.slot == Slot(3)

async def test_status_update_after_initialization(self) -> None:
"""Status can be updated after handler creation."""
Expand Down Expand Up @@ -1039,7 +1039,7 @@ async def lookup(r: Bytes32) -> SignedBlock | None:
block_result = SignedBlock.decode_bytes(ssz_data)

assert status_result.head.slot == Slot(200)
assert block_result.message.slot == Slot(42)
assert block_result.block.slot == Slot(42)


class MockFailingStream:
Expand Down
Loading
Loading