Skip to content

Fix null bitcoin block 2 #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
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
23 changes: 16 additions & 7 deletions services/webhooks/chainhook/handlers/block_state_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async def handle_block(self, block: Apply) -> None:
block: The block to handle
"""
try:
self.logger.debug(f"Received block metadata: {block.metadata}")
# Get current chain state
current_state = backend.get_latest_chain_state(
network=config.network.network
Expand All @@ -85,6 +86,9 @@ async def handle_block(self, block: Apply) -> None:
bitcoin_block_height = (
block.metadata.bitcoin_anchor_block_identifier.index
)
self.logger.debug(
f"Extracted bitcoin_block_height: {bitcoin_block_height} for block_hash {block.block_identifier.hash}"
)

self.logger.info(
f"Processing block: height={block_height}, hash={block_hash}, "
Expand Down Expand Up @@ -114,6 +118,9 @@ async def handle_block(self, block: Apply) -> None:
if bitcoin_block_height is not None:
update_data["bitcoin_block_height"] = bitcoin_block_height

self.logger.debug(
f"Updating chain_state {current_state.id} with update_data: {update_data}"
)
updated = backend.update_chain_state(
current_state.id,
ChainStateBase(**update_data),
Expand All @@ -135,14 +142,16 @@ async def handle_block(self, block: Apply) -> None:
f"No existing chain state found. Creating first record for "
f"block {block_height}"
)
created = backend.create_chain_state(
ChainStateCreate(
block_height=block_height,
block_hash=block_hash,
network=config.network.network,
bitcoin_block_height=bitcoin_block_height,
)
chain_state_create_payload = ChainStateCreate(
block_height=block_height,
block_hash=block_hash,
network=config.network.network,
bitcoin_block_height=bitcoin_block_height,
)
self.logger.debug(
f"Creating new chain_state with payload: {chain_state_create_payload.model_dump_json()}"
)
created = backend.create_chain_state(chain_state_create_payload)
if not created:
self.logger.error(
f"Failed to create chain state for block {block_height}"
Expand Down