Skip to content

Conversation

@junderw
Copy link
Member

@junderw junderw commented Apr 14, 2025

In light mode, the block summary /txs for genesis block is borked thanks to RPC error.

@nymkappa
Copy link
Member

Fixes the issue described, but I will let other electrs champions actually review the PR.

electrs

DEBUG - Adding 2 transactions to Mempool
INFO - handle GET /block-height/0
INFO - handle GET /block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
DEBUG - Adding 2 transactions to Mempool

mempool backend

000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
Apr 15 10:23:02 [42564] NOTICE: [Mining] Blocks summaries indexing completed: indexed 1 blocks

@wiz
Copy link
Member

wiz commented Apr 15, 2025

How about when using dark mode

@nymkappa
Copy link
Member

How about when using dark mode

get out

@portlandhodl
Copy link

Approach Nack, (Too magical)

I am not in favor of this solution because at the end of the day this only solves for a single network Mainnet. For an application that supports various networks, Signet, Testnet, etc ... This would lead to inconsistent behavior across use cases.

@mononaut
Copy link
Contributor

why don't we fetch the whole genesis block, extract the coinbase transaction, and then cache it somewhere?

@junderw
Copy link
Member Author

junderw commented Apr 15, 2025

  1. I agree that fetching the genesis block (which seems to work) and pulling out the genesis tx is much more........ less trust-y.
  2. Does every network have only one genesis tx? (A custom signet can be pretty weird, no? What about regtest?) If not, then really either way, we're only doing this hack for mainnet anyways.

@wiz
Copy link
Member

wiz commented Apr 16, 2025

Just don't use light mode and this isn't an issue

@junderw junderw force-pushed the junderw/hardcode-genesis-tx branch from d849d02 to 523268e Compare April 16, 2025 10:03
@junderw junderw changed the title Hardcode genesis tx Fallback to getblock when getrawtransaction fails on Genesis TX Apr 16, 2025
Copy link

@portlandhodl portlandhodl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not in a position to approve or reject anything with that said here are my thoughts.

On the level of the bigger picture. My preference is not to overload the underlying forwarding calls to Bitcoin Core instead wrapping or defining a new fn()/trait with the overloaded functionality. I don't maintain anything here so it's just my opinion.

#[cfg(not(feature = "liquid"))]
Err(e)
if e.to_string().contains(
"genesis block coinbase is not considered an ordinary transaction",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common issue with Bitcoin Core is that errors are not enumerated, the error number value is considered more stable.


// Assert that there's only 1 tx, the previous block hash is all zeroes, and not using verbose
if verbose
|| block.txdata.len() != 1
Copy link

@portlandhodl portlandhodl Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Genesis blocks currently always have 1 TXN, but might not in the future + peoples own Regtest instances. A greater than 0 check would be better and still gives you safe access to [] accessor.

Edit: Because of the way the merkleroot in the header works, There isn't a need to put gaurdrails around accessing element 0 because at minimum a block will always have a single transaction in your array.

// Assert that there's only 1 tx, the previous block hash is all zeroes, and not using verbose
if verbose
|| block.txdata.len() != 1
|| block.header.prev_blockhash != BlockHash::default()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Not needed if you already have genesis TXN which is always a block at height 0, so previous hash is always 0...0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants