Search in sources :

Example 16 with Discovery

use of com.quorum.tessera.discovery.Discovery 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 17 with Discovery

use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.

the class PayloadPublisherProviderTest method provider.

@Test
public void provider() {
    ConfigFactory configFactory = mock(ConfigFactory.class);
    Config config = mock(Config.class);
    ServerConfig serverConfig = mock(ServerConfig.class);
    when(config.getP2PServerConfig()).thenReturn(serverConfig);
    when(configFactory.getConfig()).thenReturn(config);
    try (var configFactoryMockedStatic = mockStatic(ConfigFactory.class);
        var discoveryMockedStatic = mockStatic(Discovery.class)) {
        configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
        discoveryMockedStatic.when(Discovery::create).thenReturn(mock(Discovery.class));
        PayloadPublisher payloadPublisher = PayloadPublisherProvider.provider();
        assertThat(payloadPublisher).isNotNull();
        configFactoryMockedStatic.verify(ConfigFactory::create);
        configFactoryMockedStatic.verifyNoMoreInteractions();
        discoveryMockedStatic.verify(Discovery::create);
        discoveryMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) PayloadPublisher(com.quorum.tessera.transaction.publish.PayloadPublisher) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) Discovery(com.quorum.tessera.discovery.Discovery) ConfigFactory(com.quorum.tessera.config.ConfigFactory) Test(org.junit.Test)

Example 18 with Discovery

use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.

the class P2PRestApp method getSingletons.

@Override
public Set<Object> getSingletons() {
    RuntimeContext runtimeContext = RuntimeContext.getInstance();
    List<URI> peers = runtimeContext.getPeers();
    LOGGER.debug("Found configured peers {}", peers);
    peers.stream().map(NodeUri::create).map(NodeUri::asURI).peek(u -> LOGGER.debug("Adding {} to party store", u)).forEach(partyStore::store);
    final PartyInfoResource partyInfoResource = new PartyInfoResource(discovery, partyInfoParser, runtimeContext.getP2pClient(), enclave, runtimeContext.isRemoteKeyValidation());
    final IPWhitelistFilter iPWhitelistFilter = new IPWhitelistFilter();
    final TransactionResource transactionResource = new TransactionResource(transactionManager, batchResendManager, legacyResendManager);
    final UpCheckResource upCheckResource = new UpCheckResource();
    final PrivacyGroupResource privacyGroupResource = new PrivacyGroupResource(privacyGroupManager);
    if (runtimeContext.isRecoveryMode()) {
        final RecoveryResource recoveryResource = new RecoveryResource(transactionManager, batchResendManager);
        return Set.of(partyInfoResource, iPWhitelistFilter, recoveryResource, upCheckResource);
    }
    return Set.of(partyInfoResource, iPWhitelistFilter, transactionResource, privacyGroupResource, upCheckResource);
}
Also used : PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) AppType(com.quorum.tessera.config.AppType) Logger(org.slf4j.Logger) TransactionManager(com.quorum.tessera.transaction.TransactionManager) LoggerFactory(org.slf4j.LoggerFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) Set(java.util.Set) PrivacyGroupManager(com.quorum.tessera.privacygroup.PrivacyGroupManager) NodeUri(com.quorum.tessera.discovery.NodeUri) PartyStore(com.quorum.tessera.p2p.partyinfo.PartyStore) Objects(java.util.Objects) Discovery(com.quorum.tessera.discovery.Discovery) ApplicationPath(jakarta.ws.rs.ApplicationPath) List(java.util.List) Stream(java.util.stream.Stream) UpCheckResource(com.quorum.tessera.api.common.UpCheckResource) GlobalFilter(com.quorum.tessera.api.filter.GlobalFilter) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) LegacyResendManager(com.quorum.tessera.recovery.workflow.LegacyResendManager) Collectors.toSet(java.util.stream.Collectors.toSet) IPWhitelistFilter(com.quorum.tessera.api.filter.IPWhitelistFilter) TesseraRestApplication(com.quorum.tessera.app.TesseraRestApplication) UpCheckResource(com.quorum.tessera.api.common.UpCheckResource) IPWhitelistFilter(com.quorum.tessera.api.filter.IPWhitelistFilter) NodeUri(com.quorum.tessera.discovery.NodeUri) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI)

Example 19 with Discovery

use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.

the class P2PRestAppTest method setUp.

@Before
public void setUp() {
    runtimeContext = mock(RuntimeContext.class);
    enclave = mock(Enclave.class);
    discovery = mock(Discovery.class);
    partyStore = mock(PartyStore.class);
    transactionManager = mock(TransactionManager.class);
    batchResendManager = mock(BatchResendManager.class);
    legacyResendManager = mock(LegacyResendManager.class);
    privacyGroupManager = mock(PrivacyGroupManager.class);
    p2PRestApp = new P2PRestApp(discovery, enclave, partyStore, transactionManager, batchResendManager, legacyResendManager, privacyGroupManager);
    Client client = mock(Client.class);
    when(runtimeContext.getP2pClient()).thenReturn(client);
    when(runtimeContext.isRemoteKeyValidation()).thenReturn(true);
    when(runtimeContext.getPeers()).thenReturn(List.of(peerUri));
}
Also used : BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) PrivacyGroupManager(com.quorum.tessera.privacygroup.PrivacyGroupManager) Enclave(com.quorum.tessera.enclave.Enclave) TransactionManager(com.quorum.tessera.transaction.TransactionManager) PartyStore(com.quorum.tessera.p2p.partyinfo.PartyStore) Discovery(com.quorum.tessera.discovery.Discovery) LegacyResendManager(com.quorum.tessera.recovery.workflow.LegacyResendManager) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Client(jakarta.ws.rs.client.Client) Before(org.junit.Before)

Example 20 with Discovery

use of com.quorum.tessera.discovery.Discovery in project tessera by ConsenSys.

the class PartyInfoBroadcaster method run.

/**
 * Iterates over all known parties and contacts them for the current state of their known node
 * discovery list
 *
 * <p>For Tessera 0.9 backwards, after contacting the known parties, this poller then updates this
 * nodes list of data with any new information collected.
 *
 * <p>This behaviour is now deprecated since the /partyinfo API call now has been made more strict
 * with node validation to prevent exploiting the API to attack the Tessera network.
 *
 * <p>This call is merely to let its parties know about this node existence, any recipients that
 * want to be added to this node's PartyInfo will need to make their own partyinfo call and
 * validation
 */
@Override
public void run() {
    LOGGER.info("Started PartyInfo polling round");
    partyStore.loadFromConfigIfEmpty();
    final NodeInfo nodeInfo = discovery.getCurrent();
    final NodeUri ourUrl = NodeUri.create(nodeInfo.getUrl());
    final PartyInfo partyInfo = PartyInfoBuilder.create().withUri(nodeInfo.getUrl()).withRecipients(nodeInfo.getRecipientsAsMap()).build();
    final byte[] encodedPartyInfo = partyInfoParser.to(partyInfo);
    LOGGER.debug("Contacting following peers with PartyInfo: {}", partyInfo.getParties());
    LOGGER.debug("Sending party info {}", nodeInfo);
    partyStore.getParties().stream().map(NodeUri::create).filter(url -> !ourUrl.equals(url)).forEach(url -> pollSingleParty(url.asString(), encodedPartyInfo));
    LOGGER.info("Finished PartyInfo polling round");
}
Also used : Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) NodeUri(com.quorum.tessera.discovery.NodeUri) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Discovery(com.quorum.tessera.discovery.Discovery) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ProcessingException(jakarta.ws.rs.ProcessingException) Optional(java.util.Optional) P2pClient(com.quorum.tessera.partyinfo.P2pClient) URI(java.net.URI) PartyInfoBuilder(com.quorum.tessera.partyinfo.model.PartyInfoBuilder) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) NodeUri(com.quorum.tessera.discovery.NodeUri) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo)

Aggregations

Discovery (com.quorum.tessera.discovery.Discovery)20 Test (org.junit.Test)9 Enclave (com.quorum.tessera.enclave.Enclave)8 RuntimeContext (com.quorum.tessera.context.RuntimeContext)6 Config (com.quorum.tessera.config.Config)5 TransactionManager (com.quorum.tessera.transaction.TransactionManager)5 NodeUri (com.quorum.tessera.discovery.NodeUri)3 ResendBatchPublisher (com.quorum.tessera.recovery.resend.ResendBatchPublisher)3 LegacyResendManager (com.quorum.tessera.recovery.workflow.LegacyResendManager)3 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)3 Objects (java.util.Objects)3 ConfigFactory (com.quorum.tessera.config.ConfigFactory)2 ServerConfig (com.quorum.tessera.config.ServerConfig)2 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)2 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)2 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 PrivacyGroupManager (com.quorum.tessera.privacygroup.PrivacyGroupManager)2 BatchTransactionRequester (com.quorum.tessera.recovery.resend.BatchTransactionRequester)2 BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)2