use of org.aion.mcf.db.IBlockStoreBase in project aion by aionnetwork.
the class RecoveryUtils method pruneAndCorrect.
/**
* Used by the CLI call.
*/
public static void pruneAndCorrect() {
// ensure mining is disabled
CfgAion cfg = CfgAion.inst();
cfg.dbFromXML();
cfg.getConsensus().setMining(false);
cfg.getDb().setHeapCacheEnabled(false);
Map<String, String> cfgLog = new HashMap<>();
cfgLog.put("DB", "INFO");
cfgLog.put("GEN", "INFO");
AionLoggerFactory.init(cfgLog);
// get the current blockchain
AionBlockchainImpl blockchain = AionBlockchainImpl.inst();
IBlockStoreBase store = blockchain.getBlockStore();
IBlock bestBlock = store.getBestBlock();
if (bestBlock == null) {
System.out.println("Empty database. Nothing to do.");
return;
}
// revert to block number and flush changes
store.pruneAndCorrect();
store.flush();
// compact database after the changes were applied
blockchain.getRepository().compact();
blockchain.getRepository().close();
}
use of org.aion.mcf.db.IBlockStoreBase in project aion by aionnetwork.
the class AionRepositoryImplTest method testRepoTrackUpdateStorageRow.
/**
* Repo track test suite
*/
/**
* This test confirms that updates done on the repo track are successfully translated
* into the root repository.
*/
@Test
public void testRepoTrackUpdateStorageRow() {
final AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig);
final IRepositoryCache<AccountState, DataWord, IBlockStoreBase<?, ?>> repoTrack = repository.startTracking();
final Address defaultAccount = Address.wrap(ByteUtil.hexStringToBytes("CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3CAF3"));
final byte[] key = HashUtil.blake128("hello".getBytes());
final byte[] value = HashUtil.blake128("world".getBytes());
repoTrack.addBalance(defaultAccount, BigInteger.valueOf(1));
final byte[] originalRoot = repository.getRoot();
repoTrack.addStorageRow(defaultAccount, new DataWord(key), new DataWord(value));
DataWord retrievedStorageValue = repoTrack.getStorageValue(defaultAccount, new DataWord(key));
assertThat(retrievedStorageValue).isEqualTo(new DataWord(value));
// commit changes, then check that the root has updated
repoTrack.flush();
assertThat(repository.getStorageValue(defaultAccount, new DataWord(key))).isEqualTo(retrievedStorageValue);
final byte[] newRoot = repository.getRoot();
assertThat(newRoot).isNotEqualTo(originalRoot);
}
use of org.aion.mcf.db.IBlockStoreBase in project aion by aionnetwork.
the class RecoveryUtils method revertTo.
/**
* Used by internal world state recovery method.
*/
public static Status revertTo(AionBlockchainImpl blockchain, long nbBlock) {
IBlockStoreBase store = blockchain.getBlockStore();
IBlock bestBlock = store.getBestBlock();
if (bestBlock == null) {
System.out.println("Empty database. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
long nbBestBlock = bestBlock.getNumber();
System.out.println("Attempting to revert best block from " + nbBestBlock + " to " + nbBlock + " ...");
// exit with warning if the given block is larger or negative
if (nbBlock < 0) {
System.out.println("Negative values <" + nbBlock + "> cannot be interpreted as block numbers. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
if (nbBestBlock == 0) {
System.out.println("Only genesis block in database. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
if (nbBlock == nbBestBlock) {
System.out.println("The block " + nbBlock + " is the current best block stored in the database. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
if (nbBlock > nbBestBlock) {
System.out.println("The block #" + nbBlock + " is greater than the current best block #" + nbBestBlock + " stored in the database. " + "Cannot move to that block without synchronizing with peers. Start Aion instance to sync.");
return Status.ILLEGAL_ARGUMENT;
}
// revert to block number and flush changes
store.revert(nbBlock);
store.flush();
nbBestBlock = store.getBestBlock().getNumber();
// ok if we managed to get down to the expected block
return (nbBestBlock == nbBlock) ? Status.SUCCESS : Status.FAILURE;
}
Aggregations