use of org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_4_0 in project besu by hyperledger.
the class PrivateStorageMigration method migratePrivateStorage.
public void migratePrivateStorage() {
final long migrationStartTimestamp = System.currentTimeMillis();
final long chainHeadBlockNumber = blockchain.getChainHeadBlockNumber();
LOG.info("Migrating private storage database...");
for (long blockNumber = 0; blockNumber <= chainHeadBlockNumber; blockNumber++) {
final Block block = blockchain.getBlockByNumber(blockNumber).orElseThrow(PrivateStorageMigrationException::new);
final Hash blockHash = block.getHash();
final BlockHeader blockHeader = block.getHeader();
LOG.info("Processing block {} ({}/{})", blockHash, blockNumber, chainHeadBlockNumber);
createPrivacyGroupHeadBlockMap(blockHeader);
final int lastPmtIndex = findLastPMTIndexInBlock(block);
if (lastPmtIndex >= 0) {
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockNumber);
final PrivateMigrationBlockProcessor privateMigrationBlockProcessor = privateMigrationBlockProcessorBuilder.apply(protocolSpec);
final MutableWorldState publicWorldState = blockchain.getBlockHeader(blockHeader.getParentHash()).flatMap(header -> publicWorldStateArchive.getMutable(header.getStateRoot(), header.getHash())).orElseThrow(PrivateStorageMigrationException::new);
final List<Transaction> transactionsToProcess = block.getBody().getTransactions().subList(0, lastPmtIndex + 1);
final List<BlockHeader> ommers = block.getBody().getOmmers();
privateMigrationBlockProcessor.processBlock(blockchain, publicWorldState, blockHeader, transactionsToProcess, ommers);
}
}
if (isResultingPrivateStateRootAtHeadValid()) {
privateStateStorage.updater().putDatabaseVersion(SCHEMA_VERSION_1_4_0).commit();
} else {
throw new PrivateStorageMigrationException("Inconsistent state root. Please re-sync.");
}
final long migrationDuration = System.currentTimeMillis() - migrationStartTimestamp;
LOG.info("Migration took {} seconds", migrationDuration / 1000.0);
}
Aggregations