HathorNetwork / hathor-core

Hathor core is the official and reference client for operating a full node in Hathor Network.
https://hathor.network
Apache License 2.0
83 stars 26 forks source link

`RocksDBTokensIndex` and `MemoryTokensIndex` with different behavior on the HTR token #1068

Open msbrogli opened 5 months ago

msbrogli commented 5 months ago

RocksDBTokensIndex._create_genesis_info() takes care of creating token info for the HTR token. This similar method does not exist in MemoryTokensIndex. Maybe we could have a common code in TokenIndexInfo.

Another issue is that both indexes are not indexing the genesis block. So they just work as expected after the first block is mined. Here is a simple test that fails in master (commit 4a46f3af85b6b016cefb875f5d3f4d0e45e8b7ea):

Run a full node with no connections. Cmdline: ./hathor-cli run_node --status 8080 --nano-testnet --wallet-index --memory-storage. It fails when using a RocksDB storage too.

❯ curl "http://localhost:8080/v1a/thin_wallet/token?id=00"
{"success":false,"message":"Unknown token"}%
jansegre commented 5 months ago

I see, RocksDBTokensIndex._create_genesis_info() doesn't exist in MemoryTokensIndex because it uses a defaultdict, its purpose is to create the info for the HTR token when first needed. However if the genesis transactions are added to the index, and handled as a token creation (which is how it possibly should be handled), then it will be created and that method will not be needed.

I'll open a fix for this soon.