Search in sources :

Example 1 with PrivateStateStorage

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage in project besu by hyperledger.

the class PrivateStateRootResolverTest method resolveCorrectRootHashWhenMultipleCommitmentsExistForPrivacyGroup.

@Test
public void resolveCorrectRootHashWhenMultipleCommitmentsExistForPrivacyGroup() {
    final PrivateStateStorage.Updater updater = privateStateStorage.updater();
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(privacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt1StateHash))));
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(failingPrivacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt2StateHash))));
    updater.putPrivacyGroupHeadBlockMap(BLOCKCHAIN.getChainHeadHash(), new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(privacyGroupId), BLOCKCHAIN.getBlockByNumber(16).get().getHash())));
    updater.commit();
    final PrivateStateRootResolver privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    assertThat(privateStateRootResolver.resolveLastStateRoot(privacyGroupId, BLOCKCHAIN.getChainHeadHash())).isEqualTo(pmt1StateHash);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Example 2 with PrivateStateStorage

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage in project besu by hyperledger.

the class PrivateStorageMigrationBuilder method build.

public PrivateStorageMigration build() {
    final Blockchain blockchain = besuController.getProtocolContext().getBlockchain();
    final Address privacyPrecompileAddress = privacyParameters.getPrivacyAddress();
    final ProtocolSchedule protocolSchedule = besuController.getProtocolSchedule();
    final WorldStateArchive publicWorldStateArchive = besuController.getProtocolContext().getWorldStateArchive();
    final PrivateStateStorage privateStateStorage = privacyParameters.getPrivateStateStorage();
    final LegacyPrivateStateStorage legacyPrivateStateStorage = privacyParameters.getPrivateStorageProvider().createLegacyPrivateStateStorage();
    final PrivateStateRootResolver privateStateRootResolver = privacyParameters.getPrivateStateRootResolver();
    return new PrivateStorageMigration(blockchain, privacyPrecompileAddress, protocolSchedule, publicWorldStateArchive, privateStateStorage, privateStateRootResolver, legacyPrivateStateStorage, PrivateMigrationBlockProcessor::new);
}
Also used : Address(org.hyperledger.besu.datatypes.Address) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) PrivateStorageMigration(org.hyperledger.besu.ethereum.privacy.storage.migration.PrivateStorageMigration) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) PrivateMigrationBlockProcessor(org.hyperledger.besu.ethereum.privacy.storage.migration.PrivateMigrationBlockProcessor) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) LegacyPrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.LegacyPrivateStateStorage) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) LegacyPrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.LegacyPrivateStateStorage)

Example 3 with PrivateStateStorage

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage in project besu by hyperledger.

the class PrivacyPrecompiledContractIntegrationTest method testSendAndReceive.

@Test
public void testSendAndReceive() {
    final List<String> publicKeys = testHarness.getPublicKeys();
    final PrivateTransaction privateTransaction = PrivateTransactionDataFixture.privateContractDeploymentTransactionBesu(publicKeys.get(0));
    final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
    privateTransaction.writeTo(bytesValueRLPOutput);
    final String s = bytesValueRLPOutput.encoded().toBase64String();
    final SendResponse sr = enclave.send(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
    final PrivacyPrecompiledContract privacyPrecompiledContract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(false, (privacyGroupId, blockNumber) -> Collections::emptyList), "IntegrationTest");
    privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor());
    final PrecompiledContract.PrecompileContractResult result = privacyPrecompiledContract.computePrecompile(Bytes.fromBase64String(sr.getKey()), messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) EnclaveKeyConfiguration(org.hyperledger.enclave.testutil.EnclaveKeyConfiguration) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) OperationTracer(org.hyperledger.besu.evm.tracing.OperationTracer) AfterAll(org.junit.jupiter.api.AfterAll) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) BeforeAll(org.junit.jupiter.api.BeforeAll) Enclave(org.hyperledger.besu.enclave.Enclave) Block(org.hyperledger.besu.ethereum.core.Block) Path(java.nio.file.Path) Bytes32(org.apache.tuweni.bytes.Bytes32) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) TesseraTestHarness(org.hyperledger.enclave.testutil.TesseraTestHarness) Test(org.junit.jupiter.api.Test) List(java.util.List) PrivateStateGenesisAllocator(org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator) TempDir(org.junit.jupiter.api.io.TempDir) PrivateTransactionDataFixture(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Bytes(org.apache.tuweni.bytes.Bytes) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Address(org.hyperledger.besu.datatypes.Address) SendResponse(org.hyperledger.besu.enclave.types.SendResponse) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) Lists(com.google.common.collect.Lists) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) TesseraTestHarnessFactory(org.hyperledger.enclave.testutil.TesseraTestHarnessFactory) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) Files(java.nio.file.Files) Vertx(io.vertx.core.Vertx) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Mockito.when(org.mockito.Mockito.when) BlockHashLookup(org.hyperledger.besu.ethereum.vm.BlockHashLookup) PrivateTransactionProcessor(org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivateStateUtils(org.hyperledger.besu.ethereum.mainnet.PrivateStateUtils) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Collections(java.util.Collections) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) SendResponse(org.hyperledger.besu.enclave.types.SendResponse) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Bytes(org.apache.tuweni.bytes.Bytes) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivateStateGenesisAllocator(org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) Test(org.junit.jupiter.api.Test)

Example 4 with PrivateStateStorage

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage in project besu by hyperledger.

the class PrivateStateRootResolverTest method resolveLatestRootHashWhenMultipleCommitmentsForTheSamePrivacyGroupExist.

@Test
public void resolveLatestRootHashWhenMultipleCommitmentsForTheSamePrivacyGroupExist() {
    final PrivateStateStorage.Updater updater = privateStateStorage.updater();
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(privacyGroupId), new PrivateBlockMetadata(Arrays.asList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt1StateHash), new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt2StateHash))));
    updater.putPrivacyGroupHeadBlockMap(BLOCKCHAIN.getChainHeadHash(), new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(privacyGroupId), BLOCKCHAIN.getBlockByNumber(16).get().getHash())));
    updater.commit();
    final PrivateStateRootResolver privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    assertThat(privateStateRootResolver.resolveLastStateRoot(privacyGroupId, BLOCKCHAIN.getChainHeadHash())).isEqualTo(pmt2StateHash);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Example 5 with PrivateStateStorage

use of org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage in project besu by hyperledger.

the class PrivateStateRootResolverTest method resolveExpectedRootHashWhenCommitmentForPrivacyGroupExists.

@Test
public void resolveExpectedRootHashWhenCommitmentForPrivacyGroupExists() {
    final PrivateStateStorage.Updater updater = privateStateStorage.updater();
    updater.putPrivateBlockMetadata(BLOCKCHAIN.getBlockByNumber(16).get().getHash(), Bytes32.wrap(privacyGroupId), new PrivateBlockMetadata(Collections.singletonList(new PrivateTransactionMetadata(BLOCK_GENERATOR.transaction().getHash(), pmt1StateHash))));
    updater.putPrivacyGroupHeadBlockMap(BLOCKCHAIN.getChainHeadHash(), new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.wrap(privacyGroupId), BLOCKCHAIN.getBlockByNumber(16).get().getHash())));
    updater.commit();
    final PrivateStateRootResolver privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    assertThat(privateStateRootResolver.resolveLastStateRoot(privacyGroupId, BLOCKCHAIN.getChainHeadHash())).isEqualTo(pmt1StateHash);
}
Also used : PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Test(org.junit.Test)

Aggregations

PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)10 PrivacyGroupHeadBlockMap (org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)7 Block (org.hyperledger.besu.ethereum.core.Block)6 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)5 Optional (java.util.Optional)4 Bytes (org.apache.tuweni.bytes.Bytes)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)4 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)4 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)4 PrivateBlockMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata)4 PrivateTransactionMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)4 Test (org.junit.Test)4 List (java.util.List)3 Address (org.hyperledger.besu.datatypes.Address)3 Hash (org.hyperledger.besu.datatypes.Hash)3 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)3 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)3 PrivateMetadataUpdater (org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 EnclaveFactory (org.hyperledger.besu.enclave.EnclaveFactory)2