RCasatta / blocks_iterator

Iterate over bitcoin blocks
MIT License
51 stars 5 forks source link

Get a `block_extra` or a `block` from a `Txid`, a `TxOut` or an `OutPoint` #74

Closed drgarlic closed 1 year ago

drgarlic commented 1 year ago

Hi !

First of all, thank you for your hard work ! Your crate is exactly what I was looking to play around and crunch the data from my node.

I've been trying to get previous blocks linked to a block via a txout/outpoint (or any other data inside the block) but I'm having a quite a hard time with this. For context, the goal is to do it for each outpoint of each block.

While browsing the library's code, I couldn't find any way to do this.

Am I missing something and there is an idiomatic way to do it ?

RCasatta commented 1 year ago

Hi @gawlk !

First of all, thank you for your hard work ! Your crate is exactly what I was looking to play around and crunch the data from my node.

I appreciate this crate is useful to you!

I've been trying to get previous blocks linked to a block via a txout/outpoint (or any other data inside the block) but I'm having a quite a hard time with this. For context, the goal is to do it for each outpoint of each block.

While browsing the library's code, I couldn't find any way to do this.

Am I missing something and there is an idiomatic way to do it ?

BlockExtra comes with previous outpoints of the transactions of the block

Methods like tx_fee use previous outpoint info to work, if you are not interested in the fee but in something else you can directly access previous outpoint via the HashMap, for example how it is done in the verify example

With this crate you cannot access the block given a generic Txid, for that is better to use bitcoin core with txindex=1

drgarlic commented 1 year ago

Thank you ! But sadly neither tx_fee nor outpoint_values will do.

Just for context, what I'm currently trying to do is fetch the timestamp of the block's head of each TxOut in outpoint_values of every single block_extra.

I'll check what I can do with bitcoin core thanks ! But I'll need something super fast, if it's too slow I was thinking maybe creating another RocksDB just for that ?

RCasatta commented 1 year ago

Do you have low-memory requirement for your task? The memory mode (the default if no db directory is specified) stores the utxo set in about 5gb of memory, I guess you can store what you need in memory with similar requirement using an HashMap<Outpoint,u32> Inserting values for every output value in a block and removing them for every input

drgarlic commented 1 year ago

I actually did something very similar and forgot update and close this issue.

Thank you so much though, you've been very helpful !