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);
}
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);
}
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));
}
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);
}
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);
}
Aggregations