Search in sources :

Example 1 with InMemoryPrivacyStorageProvider

use of org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider in project besu by hyperledger.

the class PrivateMetadataUpdaterTest method before.

@Before
public void before() {
    blockHeader = mock(BlockHeader.class);
    privateStateStorage = new InMemoryPrivacyStorageProvider().createPrivateStateStorage();
    final Hash hashBlockZero = Hash.ZERO;
    when(blockHeader.getParentHash()).thenReturn(hashBlockZero);
    updater = new PrivateMetadataUpdater(blockHeader, privateStateStorage);
    hashBlockOne = Hash.fromHexString("1111111111111111111111111111111111111111111111111111111111111111");
    stateRoot = Hash.fromHexString("2222222222222222222222222222222222222222222222222222222222222222");
    privacyGroupId = Bytes32.fromHexString("3333333333333333333333333333333333333333333333333333333333333333");
}
Also used : BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) InMemoryPrivacyStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) Before(org.junit.Before)

Example 2 with InMemoryPrivacyStorageProvider

use of org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider in project besu by hyperledger.

the class BesuNodeFactory method createNodeWithMultiTenantedPrivacy.

public BesuNode createNodeWithMultiTenantedPrivacy(final String name, final String enclaveUrl, final String authFile, final String privTransactionSigningKey, final boolean enableFlexiblePrivacy) throws IOException, URISyntaxException {
    final PrivacyParameters.Builder privacyParametersBuilder = new PrivacyParameters.Builder();
    final PrivacyParameters privacyParameters = privacyParametersBuilder.setMultiTenancyEnabled(true).setEnabled(true).setFlexiblePrivacyGroupsEnabled(enableFlexiblePrivacy).setStorageProvider(new InMemoryPrivacyStorageProvider()).setEnclaveFactory(new EnclaveFactory(Vertx.vertx())).setEnclaveUrl(URI.create(enclaveUrl)).setPrivateKeyPath(Paths.get(ClassLoader.getSystemResource(privTransactionSigningKey).toURI())).build();
    final MiningParameters miningParameters = new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).coinbase(AddressHelpers.ofValue(1)).miningEnabled(true).build();
    return create(new BesuNodeConfigurationBuilder().name(name).jsonRpcEnabled().jsonRpcAuthenticationConfiguration(authFile).enablePrivateTransactions().privacyParameters(privacyParameters).miningConfiguration(miningParameters).build());
}
Also used : EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) InMemoryPrivacyStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider)

Example 3 with InMemoryPrivacyStorageProvider

use of org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider in project besu by hyperledger.

the class PrivacyPluginPrecompiledContractTest method setup.

@Before
public void setup() {
    final PrivateStateStorage privateStateStorage = mock(PrivateStateStorage.class);
    messageFrame = mock(MessageFrame.class);
    final BlockDataGenerator blockGenerator = new BlockDataGenerator();
    final Block genesis = blockGenerator.genesisBlock();
    final Block block = blockGenerator.block(new BlockDataGenerator.BlockOptions().setParentHash(genesis.getHeader().getHash()));
    when(messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)).thenReturn(false);
    when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
    when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(mock(PrivateMetadataUpdater.class));
    when(messageFrame.getBlockValues()).thenReturn(block.getHeader());
    when(privateStateStorage.getPrivacyGroupHeadBlockMap(any())).thenReturn(Optional.of(PrivacyGroupHeadBlockMap.empty()));
    final PrivateMetadataUpdater privateMetadataUpdater = mock(PrivateMetadataUpdater.class);
    when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
    when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(privateMetadataUpdater);
    when(privateMetadataUpdater.getPrivacyGroupHeadBlockMap()).thenReturn(PrivacyGroupHeadBlockMap.empty());
    contract = new PrivacyPluginPrecompiledContract(new SpuriousDragonGasCalculator(), new PrivacyParameters.Builder().setEnabled(true).setPrivacyPluginEnabled(true).setStorageProvider(new InMemoryPrivacyStorageProvider()).setPrivacyService(new PrivacyPluginService() {

        @Override
        public void setPayloadProvider(final PrivacyPluginPayloadProvider provider) {
        }

        @Override
        public PrivacyPluginPayloadProvider getPayloadProvider() {
            return new PrivacyPluginPayloadProvider() {

                @Override
                public Bytes generateMarkerPayload(final org.hyperledger.besu.plugin.data.PrivateTransaction privateTransaction, final String privacyUserId) {
                    return serialize(privateTransaction).encoded();
                }

                @Override
                public Optional<org.hyperledger.besu.plugin.data.PrivateTransaction> getPrivateTransactionFromPayload(final org.hyperledger.besu.plugin.data.Transaction transaction) {
                    final BytesValueRLPInput bytesValueRLPInput = new BytesValueRLPInput(transaction.getPayload(), false);
                    return Optional.of(readFrom(bytesValueRLPInput));
                }
            };
        }

        @Override
        public void setPrivacyGroupAuthProvider(final PrivacyGroupAuthProvider privacyGroupAuthProvider) {
        }

        @Override
        public PrivacyGroupAuthProvider getPrivacyGroupAuthProvider() {
            return (privacyGroupId, privacyUserId, blockNumber) -> true;
        }

        @Override
        public void setPrivacyGroupGenesisProvider(final PrivacyGroupGenesisProvider privacyGroupAuthProvider) {
        }

        @Override
        public PrivacyGroupGenesisProvider getPrivacyGroupGenesisProvider() {
            return (privacyGroupId, blockNumber) -> (PrivacyGenesis) Collections::emptyList;
        }

        @Override
        public PrivateMarkerTransactionFactory getPrivateMarkerTransactionFactory() {
            return null;
        }

        @Override
        public void setPrivateMarkerTransactionFactory(final PrivateMarkerTransactionFactory privateMarkerTransactionFactory) {
        }
    }).setEnclaveFactory(mock(EnclaveFactory.class)).build());
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Bytes(org.apache.tuweni.bytes.Bytes) PrivacyPluginPayloadProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyPluginPayloadProvider) Optional(java.util.Optional) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) InMemoryPrivacyStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivacyPluginService(org.hyperledger.besu.plugin.services.PrivacyPluginService) Block(org.hyperledger.besu.ethereum.core.Block) PrivateMarkerTransactionFactory(org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory) PrivacyGroupGenesisProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyGroupGenesisProvider) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) PrivacyGroupAuthProvider(org.hyperledger.besu.plugin.services.privacy.PrivacyGroupAuthProvider) Before(org.junit.Before)

Aggregations

InMemoryPrivacyStorageProvider (org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider)3 PrivateMetadataUpdater (org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater)2 Before (org.junit.Before)2 Optional (java.util.Optional)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Hash (org.hyperledger.besu.datatypes.Hash)1 EnclaveFactory (org.hyperledger.besu.enclave.EnclaveFactory)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)1 PrivacyParameters (org.hyperledger.besu.ethereum.core.PrivacyParameters)1 PrivateStateStorage (org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage)1 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)1 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)1 SpuriousDragonGasCalculator (org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator)1 PrivacyPluginService (org.hyperledger.besu.plugin.services.PrivacyPluginService)1 PrivacyGroupAuthProvider (org.hyperledger.besu.plugin.services.privacy.PrivacyGroupAuthProvider)1 PrivacyGroupGenesisProvider (org.hyperledger.besu.plugin.services.privacy.PrivacyGroupGenesisProvider)1 PrivacyPluginPayloadProvider (org.hyperledger.besu.plugin.services.privacy.PrivacyPluginPayloadProvider)1