koinos / koinos-block-store

The block store microservice saves blocks to disk and provides an API to the Koinos cluster via RPC over AMQP.
MIT License
1 stars 1 forks source link

[BUG]: Blocks are stored twice in block store #130

Closed theoreticalbts closed 1 year ago

theoreticalbts commented 1 year ago

Is there an existing issue for this?

Current behavior

Currently, block-store is executing AddBlock() twice for every received block.

Expected behavior

How should the block store receive new blocks?

There are two different design options for what block-store should do:

Expected behavior is to do either (a) or (b). The current code does both (a) and (b) which causes every block to be stored twice.

Steps to reproduce

Add log.Infof("AddBlock(%d)", record.BlockHeight) to AddBlock() and attempt to sync to mainnet. You will see two calls with the same block height for every block.

Environment

- OS: Ubuntu 22.04

Anything else?

Whether to choose (a) or (b)? Both seem reasonable at first glance, in fact (a) seems slightly superior as it makes the chain and block-store microservices slightly less tightly coupled. However (b) has the advantage of backpressure:

Basically this means if you're receiving blocks faster than you can save them, with (a) you might get into an unpleasant situation where block-store falls further and further behind an unboundedly growing lump of unsaved broadcast notifications in RabbitMQ. I'm not sure if RabbitMQ will eventually give up and discard some of those notifications (this seems bad, accepted blocks might not be stored), or if the backlog in RabbitMQ will just grow and grow. (It wouldn't be truly unbounded; you'll reach the current head block at some point, and then new blocks will only arrive as they're produced, which means the rate of incoming blocks should fall to something manageable and the RabbitMQ backlog should start to shrink. But if Koinos history grows to the same size as, say, Steem / Hive, this effect could easily result in many millions of block notifications stuck in RabbitMQ.)

With (b) by contrast, when receiving blocks faster than you can save them, AFAICT the excess will pile up in p2p which will hopefully handle things more gracefully (e.g. we'll just stop requesting more blocks from a peer if we still have a lot of unprocessed blocks from that peer).

koinos-ci commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

koinos-ci commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.