Skip to content
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

DefaultStore.ContainsBlock() & DefaultStore.GetBlock<T>() are not consistent #1539

Closed
dahlia opened this issue Oct 22, 2021 · 1 comment
Closed
Labels
bug Something isn't working stale The issue is stale storage Related to storage (Libplanet.Store)

Comments

@dahlia
Copy link
Contributor

dahlia commented Oct 22, 2021

In some corner cases, DefaultStore.GetBlock<T>() can return null while DefaultStore.ContainsBlock() returns true. For example, the following error log was caused due to this corner case:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Libplanet.Blocks.BlockMarshaler.MarshalBlock[T](Block`1 block) in C:\libplanet\Libplanet\Blocks\BlockMarshaler.cs:line 149
   at Libplanet.Net.Swarm`1.TransferBlocks(GetBlocks getData) in C:\libplanet\Libplanet\Net\Swarm.MessageHandlers.cs:line 252
   at Libplanet.Net.Swarm`1.ProcessMessageHandler(Object target, Message message) in C:\libplanet\Libplanet\Net\Swarm.MessageHandlers.cs:line 70
   at Libplanet.Net.Transports.NetMQTransport.<>c__DisplayClass59_0.<ReceiveMessage>b__0() in C:\libplanet\Libplanet\Net\Transports\NetMQTransport.cs:line 576

The exception was thrown from the line 252 of the below code:

if (_store.ContainsBlock(hash))
{
Block<T> block = _store.GetBlock<T>(BlockChain.Policy.GetHashAlgorithm, hash);
byte[] payload = Codec.Encode(block.MarshalBlock());

It shows there is a case where _store.ContainsBlock(hash) returns true while _store.GetBlock<T>(..., hash) returns null.

Although I experienced this case with DefaultStore, it can be a bug of BaseStore, or RocksDBStore may have a similar bug too.

@dahlia dahlia added bug Something isn't working storage Related to storage (Libplanet.Store) labels Oct 22, 2021
dahlia added a commit to dahlia/libplanet that referenced this issue Oct 22, 2021
@stale
Copy link

stale bot commented Mar 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the stale The issue is stale label Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale The issue is stale storage Related to storage (Libplanet.Store)
Projects
None yet
Development

No branches or pull requests

2 participants