Search in sources :

Example 1 with SCHEMA_VERSION_1_4_0

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);
}
Also used : PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) Logger(org.slf4j.Logger) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) Address(org.hyperledger.besu.datatypes.Address) Function(java.util.function.Function) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) LegacyPrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.LegacyPrivateStateStorage) List(java.util.List) SCHEMA_VERSION_1_4_0(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_4_0) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Optional(java.util.Optional) Block(org.hyperledger.besu.ethereum.core.Block) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) Transaction(org.hyperledger.besu.ethereum.core.Transaction) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Bytes32(org.apache.tuweni.bytes.Bytes32) Hash(org.hyperledger.besu.datatypes.Hash) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) Hash(org.hyperledger.besu.datatypes.Hash) Transaction(org.hyperledger.besu.ethereum.core.Transaction) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) Block(org.hyperledger.besu.ethereum.core.Block) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Aggregations

List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Address (org.hyperledger.besu.datatypes.Address)1 Hash (org.hyperledger.besu.datatypes.Hash)1 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 Transaction (org.hyperledger.besu.ethereum.core.Transaction)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1 ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)1 PrivateStateRootResolver (org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver)1 LegacyPrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.LegacyPrivateStateStorage)1 PrivacyGroupHeadBlockMap (org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)1 SCHEMA_VERSION_1_4_0 (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_4_0)1 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)1 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)1