@@ -84,7 +84,7 @@ namespace Libplanet.RocksDBStore
84
84
/// </list>
85
85
/// </summary>
86
86
/// <seealso cref="IStore"/>
87
- public class RocksDBStore : BaseStore
87
+ public partial class RocksDBStore : BaseStore
88
88
{
89
89
private const string BlockDbRootPathName = "block" ;
90
90
private const string BlockIndexDbName = "blockindex" ;
@@ -648,64 +648,6 @@ public override long AppendIndex(Guid chainId, BlockHash hash)
648
648
return index ;
649
649
}
650
650
651
- /// <summary>
652
- /// Forks block indexes from <paramref name="sourceChainId"/> to
653
- /// <paramref name="destinationChainId"/>.
654
- /// </summary>
655
- /// <param name="sourceChainId">The chain ID of block indexes to fork.</param>
656
- /// <param name="destinationChainId">The chain ID of destination block indexes.</param>
657
- /// <param name="branchpoint">The branchpoint <see cref="Block"/> to fork.</param>
658
- /// <seealso cref="IterateIndexes(Guid, int, int?)"/>
659
- /// <seealso cref="AppendIndex(Guid, BlockHash)"/>
660
- public void ForkBlockIndexes (
661
- Guid sourceChainId ,
662
- Guid destinationChainId ,
663
- BlockHash branchpoint
664
- )
665
- {
666
- BlockHash [ ] bottoms = IterateIndexes ( sourceChainId , 0 , 1 , true ) . ToArray ( ) ;
667
- BlockHash ? genesisHash = bottoms . Any ( ) ? bottoms [ 0 ] : ( BlockHash ? ) null ;
668
-
669
- if ( genesisHash is null || branchpoint . Equals ( genesisHash ) )
670
- {
671
- return ;
672
- }
673
-
674
- using var batch = new WriteBatch ( ) ;
675
- foreach ( Iterator k in IterateDb ( _chainDb , IndexKey ( destinationChainId ) ) )
676
- {
677
- batch . Delete ( k . Key ( ) ) ;
678
- }
679
-
680
- if ( ! ( GetBlockIndex ( branchpoint ) is { } bpIndex ) )
681
- {
682
- return ;
683
- }
684
-
685
- _chainDb . Write ( batch ) ;
686
-
687
- // Do fork from previous chain instead current if it's available and same as current.
688
- if ( GetPreviousChainInfo ( sourceChainId ) is { } chainInfo &&
689
- chainInfo . Item2 == bpIndex )
690
- {
691
- ForkBlockIndexes ( chainInfo . Item1 , destinationChainId , branchpoint ) ;
692
- return ;
693
- }
694
-
695
- _chainDb . Put ( PreviousChainIdKey ( destinationChainId ) , sourceChainId . ToByteArray ( ) ) ;
696
- _chainDb . Put (
697
- PreviousChainIndexKey ( destinationChainId ) ,
698
- RocksDBStoreBitConverter . GetBytes ( bpIndex )
699
- ) ;
700
- _chainDb . Put (
701
- IndexCountKey ( destinationChainId ) ,
702
- RocksDBStoreBitConverter . GetBytes ( bpIndex + 1 )
703
- ) ;
704
-
705
- _chainDb . Put ( ChainIdKey ( destinationChainId ) , destinationChainId . ToByteArray ( ) ) ;
706
- AddFork ( sourceChainId , destinationChainId ) ;
707
- }
708
-
709
651
/// <inheritdoc/>
710
652
public override Transaction ? GetTransaction ( TxId txid )
711
653
{
@@ -1145,49 +1087,6 @@ public override void Dispose()
1145
1087
}
1146
1088
}
1147
1089
1148
- /// <summary>
1149
- /// Forks <see cref="Transaction"/> <see cref="Transaction.Nonce"/>s from
1150
- /// <paramref name="sourceChainId"/> to <paramref name="destinationChainId"/>.
1151
- /// </summary>
1152
- /// <param name="sourceChainId">The chain <see cref="BlockChain.Id"/> of
1153
- /// <see cref="Transaction"/> <see cref="Transaction.Nonce"/>s to fork.</param>
1154
- /// <param name="destinationChainId">The chain <see cref="BlockChain.Id"/> of destination
1155
- /// <see cref="Transaction"/> <see cref="Transaction.Nonce"/>s.</param>
1156
- public void ForkTxNonces ( Guid sourceChainId , Guid destinationChainId )
1157
- {
1158
- var writeBatch = new WriteBatch ( ) ;
1159
- bool exist = false ;
1160
- try
1161
- {
1162
- byte [ ] prefix = TxNonceKey ( sourceChainId ) ;
1163
- foreach ( Iterator it in IterateDb ( _chainDb , prefix ) )
1164
- {
1165
- exist = true ;
1166
- Address address = new Address ( it . Key ( ) . Skip ( prefix . Length ) . ToArray ( ) ) ;
1167
- writeBatch . Put ( TxNonceKey ( destinationChainId , address ) , it . Value ( ) ) ;
1168
- if ( writeBatch . Count ( ) >= ForkWriteBatchSize )
1169
- {
1170
- _chainDb . Write ( writeBatch ) ;
1171
- writeBatch . Dispose ( ) ;
1172
- writeBatch = new WriteBatch ( ) ;
1173
- }
1174
- }
1175
- }
1176
- catch ( Exception e )
1177
- {
1178
- LogUnexpectedException ( nameof ( ForkTxNonces ) , e ) ;
1179
- throw ;
1180
- }
1181
- finally
1182
- {
1183
- if ( exist )
1184
- {
1185
- _chainDb . Write ( writeBatch ) ;
1186
- writeBatch . Dispose ( ) ;
1187
- }
1188
- }
1189
- }
1190
-
1191
1090
/// <inheritdoc />
1192
1091
public override void PruneOutdatedChains ( bool noopWithoutCanon = false )
1193
1092
{
0 commit comments