planetarium / libplanet

Blockchain in C#/.NET for on-chain, decentralized gaming
https://docs.libplanet.io/
GNU Lesser General Public License v2.1
506 stars 142 forks source link

NRE on `MigrateChainDBFromColumnFamilies()` #2295

Closed longfin closed 1 year ago

longfin commented 1 year ago
 Unexpected exception occurred during Run. System.NullReferenceException: Object reference not set to an instance of an object.
   at Libplanet.RocksDBStore.RocksDBStoreBitConverter.ToInt64(Byte[] value) in /app/Lib9c/.Libplanet/Libplanet.RocksDBStore/RocksDBStoreBitConverter.cs:line 21
   at Libplanet.RocksDBStore.RocksDBStore.MigrateChainDBFromColumnFamilies(String path) in /app/Lib9c/.Libplanet/Libplanet.RocksDBStore/RocksDBStore.cs:line 344
   at Libplanet.Headless.Hosting.LibplanetNodeService`1.LoadStore(String path, String type, Int32 statesCacheSize, Boolean noReduceStore) in /app/Libplanet.Headless/Hosting/LibplanetNodeService.cs:line 299
   at Libplanet.Headless.Hosting.LibplanetNodeService`1..ctor(LibplanetNodeServiceProperties`1 properties, IBlockPolicy`1 blockPolicy, IStagePolicy`1 stagePolicy, IEnumerable`1 renderers, Func`5 minerLoopAction, Progress`1 preloadProgress, Action`2 exceptionHandlerAction, Action`1 preloadStatusHandlerAction, Boolean ignoreBootstrapFailure, Boolean ignorePreloadFailure) in /app/Libplanet.Headless/Hosting/LibplanetNodeService.cs:line 97
   at NineChronicles.Headless.NineChroniclesNodeService..ctor(PrivateKey minerPrivateKey, LibplanetNodeServiceProperties`1 properties, IBlockPolicy`1 blockPolicy, NetworkType networkType, Progress`1 preloadProgress, Boolean ignoreBootstrapFailure, Boolean ignorePreloadFailure, Boolean strictRendering, Boolean isDev, Int32 blockInterval, Int32 reorgInterval, TimeSpan txLifeTime, Int32 minerCount, Int32 txQuotaPerSigner) in /app/NineChronicles.Headless/NineChroniclesNodeService.cs:line 258
   at NineChronicles.Headless.NineChroniclesNodeService.Create(NineChroniclesNodeServiceProperties properties, StandaloneContext context) in /app/NineChronicles.Headless/NineChroniclesNodeService.cs:line 319
   at NineChronicles.Headless.HostBuilderExtensions.UseNineChroniclesNode(IHostBuilder builder, NineChroniclesNodeServiceProperties properties, StandaloneContext context) in /app/NineChronicles.Headless/HostBuilderExtensions.cs:line 28
   at NineChronicles.Headless.Executable.Program.Run(String appProtocolVersionToken, String genesisBlockPath, String host, Nullable`1 port, String swarmPrivateKeyString, Int32 workers, Boolean noMiner, Int32 minerCount, String minerPrivateKeyString, String storeType, String storePath, Boolean noReduceStore, String[] iceServerStrings, String[] peerStrings, String[] trustedAppProtocolVersionSigners, Boolean rpcServer, String rpcListenHost, Nullable`1 rpcListenPort, Boolean rpcRemoteServer, Boolean rpcHttpServer, Boolean graphQLServer, String graphQLHost, Nullable`1 graphQLPort, String graphQLSecretTokenPath, Boolean noCors, Int32 confirmations, Boolean nonblockRenderer, Int32 nonblockRendererQueue, Boolean strictRendering, Boolean logActionRenders, NetworkType networkType, Boolean isDev, Int32 blockInterval, Int32 reorgInterval, String awsCognitoIdentity, String awsAccessKey, String awsSecretKey, String awsRegion, Int32 txLifeTime, Int32 messageTimeout, Int32 tipTimeout, Int32 demandBuffer, String[] staticPeerStrings, Boolean skipPreload, Int32 minimumBroadcastTarget, Int32 bucketSize, String chainTipStaleBehaviorType, Int32 txQuotaPerSigner, Int32 maximumPollPeers, Nullable`1 cancellationToken) in /app/NineChronicles.Headless.Executable/Program.cs:line 372
longfin commented 1 year ago

I've investigated in there and found some clues.

root@snapshot-partition-27707400-jl6sk:/data/headless/chain# ldb list_column_families --db="/data/headless/chain"
Column families in /data/headless/chain:
{default, b6f22104-f990-40d7-8f47-6f67f585b571}

MigrateChainDBFromColumnFamilies() is assuming that there is more than one column family, it requires to migration. so it had tried to migrate.

https://github.com/planetarium/libplanet/blob/2fb6918b7dc433a7d4720a9549f9c0b40363abc4/Libplanet.RocksDBStore/RocksDBStore.cs#L270

But, it seemed that already had been migrated because there are indexed keys on the default column famliy.

root@snapshot-partition-27707400-jl6sk:/data/headless/chain# ldb scan 0x49 --db="/data/headless/chain" --hex | less
0x43 : 0x0421F2B690F9D7408F476F67F585B571
0x49002EE8706E5C834387008F676612EC9A00000000004923EC : 0xB62BEB34E2506809014EDD480CA7FA4BBD5B3571B64D3E47DBDD8B813B28726F
0x49002EE8706E5C834387008F676612EC9A00000000004923ED : 0xDC72A573D2CC6FE64C17EA4D12DF779D5E8FD0367A474761C79B4D27F3090BF2
0x49002EE8706E5C834387008F676612EC9A00000000004923EE : 0x986DA01C6E4FFC388F997B64CCF209B649EE19F5CA3A0D29B810705B78E4DD7D
0x49002EE8706E5C834387008F676612EC9A00000000004923EF : 0x484AA6C4831E8EBD27E73278F4329C132367660CDC2B52F2DEBBAA3AF8B7EBEF
0x49002EE8706E5C834387008F676612EC9A00000000004923F0 : 

Thus I suspect that there may be any possibility about remaining column family even after migration.

longfin commented 1 year ago

Temporarly solution.

root@snapshot-partition-27707400-jl6sk:/data/headless/chain# ldb list_column_families --db="/data/headless/chain"
Column families in /data/headless/chain:
{default, b6f22104-f990-40d7-8f47-6f67f585b571}
root@snapshot-partition-27707400-jl6sk:/data/headless/chain# ldb drop_column_family --db="/data/headless/chain" "b6f22104-f990-40d7-8f47-6f67f585b571"
OK
root@snapshot-partition-27707400-jl6sk:/data/headless/chain# ldb list_column_families --db="/data/headless/chain"
Column families in /data/headless/chain:
{default}
stale[bot] commented 1 year ago

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