Search in sources :

Example 1 with PrivateStateRootResolver

use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.

the class PrivacyBlockProcessorTest method setUp.

@Before
public void setUp() {
    blockProcessor = mock(AbstractBlockProcessor.class);
    privateStateStorage = new PrivateStateKeyValueStorage(new InMemoryKeyValueStorage());
    privateWorldStateArchive = mock(WorldStateArchive.class);
    enclave = mock(Enclave.class);
    protocolSchedule = mock(ProtocolSchedule.class);
    this.privacyBlockProcessor = new PrivacyBlockProcessor(blockProcessor, protocolSchedule, enclave, privateStateStorage, privateWorldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(true, (privacyGroupId, blockNumber) -> Collections::emptyList));
    publicWorldStateArchive = mock(WorldStateArchive.class);
    privacyBlockProcessor.setPublicWorldStateArchive(publicWorldStateArchive);
}
Also used : InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Enclave(org.hyperledger.besu.enclave.Enclave) PrivateStateGenesisAllocator(org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) Collections(java.util.Collections) PrivateStateKeyValueStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage) Before(org.junit.Before)

Example 2 with PrivateStateRootResolver

use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver 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 PrivateStateRootResolver

use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.

the class PrivacyReorgTest method setUp.

@Before
public void setUp() throws IOException {
    mockEnclave = mock(Enclave.class);
    final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
    PRIVATE_TRANSACTION.writeTo(rlpOutput);
    when(mockEnclave.receive(any())).thenReturn(new ReceiveResponse(rlpOutput.encoded().toBase64String().getBytes(StandardCharsets.UTF_8), PRIVACY_GROUP_BYTES32.toBase64String(), ENCLAVE_PUBLIC_KEY.toBase64String()));
    privacyMarkerTransaction = Transaction.builder().type(TransactionType.FRONTIER).chainId(BigInteger.valueOf(1337)).gasLimit(60000).gasPrice(Wei.of(1000)).nonce(0).payload(PRIVACY_TRANSACTION_PAYLOAD).to(DEFAULT_PRIVACY).value(Wei.ZERO).signAndBuild(KEY_PAIR);
    // Create Storage
    final Path dataDir = folder.newFolder().toPath();
    // Configure Privacy
    EnclaveFactory enclaveFactory = mock(EnclaveFactory.class);
    when(enclaveFactory.createVertxEnclave(any())).thenReturn(mockEnclave);
    privacyParameters = new PrivacyParameters.Builder().setEnabled(true).setStorageProvider(createKeyValueStorageProvider()).setEnclaveUrl(URI.create("http//1.1.1.1:1234")).setEnclaveFactory(enclaveFactory).build();
    privacyParameters.setPrivacyUserId(ENCLAVE_PUBLIC_KEY.toBase64String());
    privacyController = mock(RestrictedDefaultPrivacyController.class);
    when(privacyController.findPrivacyGroupByGroupId(any(), any())).thenReturn(Optional.of(new PrivacyGroup()));
    privateStateRootResolver = new PrivateStateRootResolver(privacyParameters.getPrivateStateStorage());
    besuController = new BesuController.Builder().fromGenesisConfig(GenesisConfigFile.development()).synchronizerConfiguration(SynchronizerConfiguration.builder().build()).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).storageProvider(new InMemoryKeyValueStorageProvider()).networkId(BigInteger.ONE).miningParameters(new MiningParameters.Builder().minTransactionGasPrice(Wei.of(1000)).miningEnabled(false).build()).nodeKey(NodeKeyUtils.generate()).metricsSystem(new NoOpMetricsSystem()).dataDirectory(dataDir).clock(TestClock.fixed()).privacyParameters(privacyParameters).transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT).gasLimitCalculator(GasLimitCalculator.constant()).evmConfiguration(EvmConfiguration.DEFAULT).build();
}
Also used : Path(java.nio.file.Path) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) Enclave(org.hyperledger.besu.enclave.Enclave) RestrictedDefaultPrivacyController(org.hyperledger.besu.ethereum.privacy.RestrictedDefaultPrivacyController) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) InMemoryKeyValueStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Before(org.junit.Before)

Example 4 with PrivateStateRootResolver

use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver 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 5 with PrivateStateRootResolver

use of org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver in project besu by hyperledger.

the class PrivateStorageMigrationTest method setUp.

@Before
public void setUp() {
    final KeyValueStorage kvStorage = new InMemoryKeyValueStorage();
    privateStateStorage = new PrivateStateKeyValueStorage(kvStorage);
    privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
    lenient().when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec);
    lenient().when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor);
    lenient().when(protocolSpec.getTransactionReceiptFactory()).thenReturn(transactionReceiptFactory);
    lenient().when(protocolSpec.getBlockReward()).thenReturn(Wei.ZERO);
    lenient().when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(miningBeneficiaryCalculator);
    lenient().when(protocolSpec.isSkipZeroBlockRewards()).thenReturn(false);
    migration = new PrivateStorageMigration(blockchain, PRIVACY_ADDRESS, protocolSchedule, publicWorldStateArchive, privateStateStorage, privateStateRootResolver, legacyPrivateStateStorage, (protocolSpec) -> privateMigrationBlockProcessor);
}
Also used : PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) Arrays(java.util.Arrays) PrivateTransactionMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) DEFAULT_PRIVACY(org.hyperledger.besu.ethereum.core.PrivacyParameters.DEFAULT_PRIVACY) Map(java.util.Map) BigInteger(java.math.BigInteger) Block(org.hyperledger.besu.ethereum.core.Block) Bytes32(org.apache.tuweni.bytes.Bytes32) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) List(java.util.List) PrivateBlockMetadata(org.hyperledger.besu.ethereum.privacy.storage.PrivateBlockMetadata) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) Optional(java.util.Optional) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) TransactionType(org.hyperledger.besu.plugin.data.TransactionType) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) EMPTY_ROOT_HASH(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver.EMPTY_ROOT_HASH) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Bytes(org.apache.tuweni.bytes.Bytes) Mockito.lenient(org.mockito.Mockito.lenient) Address(org.hyperledger.besu.datatypes.Address) ArrayList(java.util.ArrayList) TransactionReceiptFactory(org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor.TransactionReceiptFactory) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) SCHEMA_VERSION_1_0_0(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_0_0) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SCHEMA_VERSION_1_4_0(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_4_0) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Wei(org.hyperledger.besu.datatypes.Wei) Before(org.junit.Before) PrivateTransactionDataFixture.privateMarkerTransaction(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) MainnetTransactionProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SignatureAlgorithmFactory(org.hyperledger.besu.crypto.SignatureAlgorithmFactory) PrivateStateKeyValueStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage) Mockito.verify(org.mockito.Mockito.verify) LegacyPrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.LegacyPrivateStateStorage) KeyValueStorage(org.hyperledger.besu.plugin.services.storage.KeyValueStorage) MiningBeneficiaryCalculator(org.hyperledger.besu.ethereum.mainnet.MiningBeneficiaryCalculator) Transaction(org.hyperledger.besu.ethereum.core.Transaction) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) PrivateStateKeyValueStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage) KeyValueStorage(org.hyperledger.besu.plugin.services.storage.KeyValueStorage) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) PrivateStateKeyValueStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage) Before(org.junit.Before)

Aggregations

PrivateStateRootResolver (org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver)5 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)4 Address (org.hyperledger.besu.datatypes.Address)3 Enclave (org.hyperledger.besu.enclave.Enclave)3 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)3 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 Bytes (org.apache.tuweni.bytes.Bytes)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Hash (org.hyperledger.besu.datatypes.Hash)2 EnclaveFactory (org.hyperledger.besu.enclave.EnclaveFactory)2 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)2 Block (org.hyperledger.besu.ethereum.core.Block)2 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)2 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)2 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)2 PrivateStateGenesisAllocator (org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator)2