Search in sources :

Example 21 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class BatchWorkflowFactoryProviderTest method provider.

@Test
public void provider() {
    try (var staticEnclave = mockStatic(Enclave.class);
        var staticDiscovery = mockStatic(Discovery.class);
        var staticResendBatchPublisher = mockStatic(ResendBatchPublisher.class)) {
        staticEnclave.when(Enclave::create).thenReturn(mock(Enclave.class));
        staticDiscovery.when(Discovery::create).thenReturn(mock(Discovery.class));
        staticResendBatchPublisher.when(ResendBatchPublisher::create).thenReturn(mock(ResendBatchPublisher.class));
        BatchWorkflowFactory batchWorkflowFactory = BatchWorkflowFactoryProvider.provider();
        assertThat(batchWorkflowFactory).isNotNull().isExactlyInstanceOf(BatchWorkflowFactoryImpl.class);
        staticEnclave.verify(Enclave::create);
        staticDiscovery.verify(Discovery::create);
        staticResendBatchPublisher.verify(ResendBatchPublisher::create);
        staticEnclave.verifyNoMoreInteractions();
        staticDiscovery.verifyNoMoreInteractions();
        staticResendBatchPublisher.verifyNoMoreInteractions();
    }
}
Also used : BatchWorkflowFactory(com.quorum.tessera.recovery.workflow.BatchWorkflowFactory) Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) ResendBatchPublisher(com.quorum.tessera.recovery.resend.ResendBatchPublisher) Test(org.junit.Test)

Example 22 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class LegacyResendManagerProviderTest method provider.

@Test
public void provider() {
    try (var enclaveMockedStatic = mockStatic(Enclave.class);
        var encryptedTransactionDAOMockedStatic = mockStatic(EncryptedTransactionDAO.class);
        var payloadPublisherMockedStatic = mockStatic(PayloadPublisher.class);
        var discoveryMockedStatic = mockStatic(Discovery.class)) {
        enclaveMockedStatic.when(Enclave::create).thenReturn(mock(Enclave.class));
        encryptedTransactionDAOMockedStatic.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        payloadPublisherMockedStatic.when(PayloadPublisher::create).thenReturn(mock(PayloadPublisher.class));
        discoveryMockedStatic.when(Discovery::create).thenReturn(mock(Discovery.class));
        LegacyResendManager legacyResendManager = LegacyResendManagerProvider.provider();
        assertThat(legacyResendManager).isNotNull();
        enclaveMockedStatic.verify(Enclave::create);
        enclaveMockedStatic.verifyNoMoreInteractions();
        encryptedTransactionDAOMockedStatic.verify(EncryptedTransactionDAO::create);
        encryptedTransactionDAOMockedStatic.verifyNoMoreInteractions();
        payloadPublisherMockedStatic.verify(PayloadPublisher::create);
        discoveryMockedStatic.verify(Discovery::create);
        discoveryMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) Enclave(com.quorum.tessera.enclave.Enclave) Discovery(com.quorum.tessera.discovery.Discovery) LegacyResendManager(com.quorum.tessera.recovery.workflow.LegacyResendManager) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) Test(org.junit.Test)

Example 23 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class Main method main.

public static void main(final String... args) throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    LOGGER.debug("args [{}]", String.join(",", args));
    try {
        PicoCliDelegate picoCliDelegate = new PicoCliDelegate();
        LOGGER.debug("Execute PicoCliDelegate with args [{}]", String.join(",", args));
        final CliResult cliResult = picoCliDelegate.execute(args);
        LOGGER.debug("Executed PicoCliDelegate with args [{}].", String.join(",", args));
        if (cliResult.isSuppressStartup()) {
            System.exit(0);
        }
        if (cliResult.getStatus() != 0) {
            System.exit(cliResult.getStatus());
        }
        final Config config = cliResult.getConfig().orElseThrow(() -> new NoSuchElementException("No config found. Tessera will not run."));
        // Start legacy spring profile stuff
        final String springProfileWarning = "Warn: Spring profiles will not be supported in future. To start in recover mode use 'tessera recover'";
        if (System.getProperties().containsKey("spring.profiles.active")) {
            System.out.println(springProfileWarning);
            config.setRecoveryMode(System.getProperty("spring.profiles.active").contains("enable-sync-poller"));
        } else if (System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) {
            System.out.println(springProfileWarning);
            config.setRecoveryMode(System.getenv("SPRING_PROFILES_ACTIVE").contains("enable-sync-poller"));
        }
        // end spring profile stuff
        LOGGER.debug("Storing config {}", config);
        ConfigFactory.create().store(config);
        LOGGER.debug("Stored config {}", config);
        LOGGER.debug("Creating enclave");
        final Enclave enclave = Enclave.create();
        LOGGER.debug("Created enclave {}", enclave);
        LOGGER.debug("Creating RuntimeContext");
        final RuntimeContext runtimeContext = RuntimeContext.getInstance();
        LOGGER.debug("Created RuntimeContext {}", runtimeContext);
        LOGGER.debug("Creating Discovery");
        Discovery discovery = Discovery.create();
        discovery.onCreate();
        LOGGER.debug("Created Discovery {}", discovery);
        if (runtimeContext.isMultiplePrivateStates()) {
            LOGGER.debug("Creating ResidentGroupHandler");
            ResidentGroupHandler residentGroupHandler = ResidentGroupHandler.create();
            residentGroupHandler.onCreate(config);
            LOGGER.debug("Created ResidentGroupHandler {}", residentGroupHandler);
        }
        LOGGER.debug("Creating EncodedPayloadManager");
        EncodedPayloadManager.create();
        LOGGER.debug("Created EncodedPayloadManager");
        LOGGER.debug("Creating BatchResendManager");
        BatchResendManager.create();
        LOGGER.debug("Created BatchResendManager");
        LOGGER.debug("Creating txn manager");
        TransactionManager transactionManager = TransactionManager.create();
        LOGGER.debug("Created txn manager");
        LOGGER.debug("Validating if transaction table exists");
        if (!transactionManager.upcheck()) {
            throw new RuntimeException("The database has not been setup correctly. Please ensure transaction tables " + "are present and correct");
        }
        LOGGER.debug("Creating ScheduledServiceFactory");
        ScheduledServiceFactory scheduledServiceFactory = ScheduledServiceFactory.fromConfig(config);
        scheduledServiceFactory.build();
        LOGGER.debug("Created ScheduledServiceFactory");
        LOGGER.debug("Creating Launcher");
        final List<TesseraServer> tesseraServers = Launcher.create(runtimeContext.isRecoveryMode()).launchServer(config);
        LOGGER.debug("Created Launcher");
        if (config.getOutputServerURIPath() != null) {
            ServerURIFileWriter.writeURIFile(config.getOutputServerURIPath(), tesseraServers);
        }
    } catch (final ConstraintViolationException ex) {
        for (final ConstraintViolation<?> violation : ex.getConstraintViolations()) {
            System.err.println("ERROR: Config validation issue: " + violation.getPropertyPath() + " " + violation.getMessage());
        }
        System.exit(1);
    } catch (final ConfigException ex) {
        LOGGER.debug("", ex);
        final Throwable cause = ExceptionUtils.getRootCause(ex);
        if (JsonException.class.isInstance(cause)) {
            System.err.println("ERROR: Invalid json, cause is " + cause.getMessage());
        } else {
            System.err.println("ERROR: Configuration exception, cause is " + Objects.toString(cause));
        }
        System.exit(3);
    } catch (final CliException ex) {
        LOGGER.debug("", ex);
        System.err.println("ERROR: CLI exception, cause is " + ex.getMessage());
        System.exit(4);
    } catch (final ServiceConfigurationError ex) {
        LOGGER.debug("", ex);
        Optional<Throwable> e = Optional.of(ex);
        e.map(Throwable::getMessage).ifPresent(System.err::println);
        // get root cause
        while (e.map(Throwable::getCause).isPresent()) {
            e = e.map(Throwable::getCause);
        }
        e.map(Throwable::toString).ifPresent(System.err::println);
        System.exit(5);
    } catch (final Throwable ex) {
        LOGGER.debug(null, ex);
        if (Arrays.asList(args).contains("--debug")) {
            ex.printStackTrace();
        } else {
            if (Optional.ofNullable(ex.getMessage()).isPresent()) {
                System.err.println("ERROR: Cause is " + ex.getMessage());
            } else {
                System.err.println("ERROR: In class " + ex.getClass().getSimpleName());
            }
        }
        System.exit(2);
    }
}
Also used : JsonException(jakarta.json.JsonException) Config(com.quorum.tessera.config.Config) ResidentGroupHandler(com.quorum.tessera.privacygroup.ResidentGroupHandler) Discovery(com.quorum.tessera.discovery.Discovery) ConfigException(com.quorum.tessera.config.ConfigException) TesseraServer(com.quorum.tessera.server.TesseraServer) PicoCliDelegate(com.quorum.tessera.config.cli.PicoCliDelegate) CliException(com.quorum.tessera.cli.CliException) CliResult(com.quorum.tessera.cli.CliResult) Enclave(com.quorum.tessera.enclave.Enclave) TransactionManager(com.quorum.tessera.transaction.TransactionManager) ConstraintViolation(jakarta.validation.ConstraintViolation) ConstraintViolationException(jakarta.validation.ConstraintViolationException) RuntimeContext(com.quorum.tessera.context.RuntimeContext) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 24 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class ScheduledServiceFactory method build.

public void build() {
    IntervalPropertyHelper intervalPropertyHelper = new IntervalPropertyHelper(config.getP2PServerConfig().getProperties());
    LOGGER.info("Creating p2p client");
    P2pClient p2pClient = P2pClient.create();
    LOGGER.info("Created p2p client {}", p2pClient);
    if (enableSync) {
        ResendPartyStore resendPartyStore = ResendPartyStore.create();
        TransactionRequester transactionRequester = TransactionRequester.create();
        SyncPoller syncPoller = new SyncPoller(resendPartyStore, transactionRequester, p2pClient);
        ScheduledExecutorService scheduledExecutorService = java.util.concurrent.Executors.newSingleThreadScheduledExecutor();
        tesseraScheduledExecutors.add(new TesseraScheduledExecutor(scheduledExecutorService, syncPoller, intervalPropertyHelper.syncInterval(), 5000L));
    }
    LOGGER.info("Creating EnclaveKeySynchroniser");
    final EnclaveKeySynchroniser enclaveKeySynchroniser = ServiceLoader.load(EnclaveKeySynchroniser.class).stream().map(ServiceLoader.Provider::get).findFirst().get();
    LOGGER.info("Created EnclaveKeySynchroniser {}", enclaveKeySynchroniser);
    tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), () -> enclaveKeySynchroniser.syncKeys(), intervalPropertyHelper.enclaveKeySyncInterval(), 5000L));
    LOGGER.info("Creating PartyInfoBroadcaster");
    PartyInfoBroadcaster partyInfoPoller = new PartyInfoBroadcaster(p2pClient);
    LOGGER.info("Created PartyInfoBroadcaster {}", partyInfoPoller);
    tesseraScheduledExecutors.add(new TesseraScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor(), partyInfoPoller, intervalPropertyHelper.partyInfoInterval(), 5000L));
    tesseraScheduledExecutors.forEach(TesseraScheduledExecutor::start);
    LOGGER.info("Creating Enclave");
    Enclave enclave = Enclave.create();
    LOGGER.info("Created Enclave {}", enclave);
    serviceContainer = new ServiceContainer(enclave);
    LOGGER.info("Starting Enclave");
    serviceContainer.start();
    LOGGER.info("Started Enclave");
}
Also used : TransactionRequester(com.quorum.tessera.p2p.resend.TransactionRequester) TesseraScheduledExecutor(com.quorum.tessera.threading.TesseraScheduledExecutor) ResendPartyStore(com.quorum.tessera.p2p.resend.ResendPartyStore) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IntervalPropertyHelper(com.quorum.tessera.config.util.IntervalPropertyHelper) SyncPoller(com.quorum.tessera.p2p.resend.SyncPoller) ServiceContainer(com.quorum.tessera.service.ServiceContainer) P2pClient(com.quorum.tessera.partyinfo.P2pClient) Enclave(com.quorum.tessera.enclave.Enclave) PartyInfoBroadcaster(com.quorum.tessera.p2p.partyinfo.PartyInfoBroadcaster) EnclaveKeySynchroniser(com.quorum.tessera.discovery.EnclaveKeySynchroniser)

Example 25 with Enclave

use of com.quorum.tessera.enclave.Enclave in project tessera by ConsenSys.

the class DiscoveryHelperProvider method provider.

public static DiscoveryHelper provider() {
    LOGGER.debug("Creating network store");
    final NetworkStore networkStore = NetworkStore.getInstance();
    LOGGER.debug("Created network store {}", networkStore);
    LOGGER.debug("Creating enclave");
    Enclave enclave = Enclave.create();
    LOGGER.debug("Created enclave {}", enclave);
    return new DiscoveryHelperImpl(networkStore, enclave);
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) NetworkStore(com.quorum.tessera.discovery.NetworkStore)

Aggregations

Enclave (com.quorum.tessera.enclave.Enclave)29 Test (org.junit.Test)11 Discovery (com.quorum.tessera.discovery.Discovery)9 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)7 PayloadDigest (com.quorum.tessera.enclave.PayloadDigest)6 RuntimeContext (com.quorum.tessera.context.RuntimeContext)5 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)5 NetworkStore (com.quorum.tessera.discovery.NetworkStore)4 PrivacyHelper (com.quorum.tessera.transaction.PrivacyHelper)4 TransactionManager (com.quorum.tessera.transaction.TransactionManager)4 Config (com.quorum.tessera.config.Config)3 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)3 LegacyResendManager (com.quorum.tessera.recovery.workflow.LegacyResendManager)3 Client (jakarta.ws.rs.client.Client)3 CliResult (com.quorum.tessera.cli.CliResult)2 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)2 RestClientFactory (com.quorum.tessera.context.RestClientFactory)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 ResendBatchPublisher (com.quorum.tessera.recovery.resend.ResendBatchPublisher)2