Search in sources :

Example 1 with P2PModule

use of com.radixdlt.network.p2p.P2PModule in project radixdlt by radixdlt.

the class RadixNodeModule method configure.

@Override
protected void configure() {
    if (this.networkId <= 0) {
        throw new IllegalStateException("Illegal networkId " + networkId);
    }
    var addressing = Addressing.ofNetworkId(networkId);
    bind(Addressing.class).toInstance(addressing);
    bindConstant().annotatedWith(NetworkId.class).to(networkId);
    bind(Txn.class).annotatedWith(Genesis.class).toInstance(loadGenesis(networkId));
    bind(RuntimeProperties.class).toInstance(properties);
    // Consensus configuration
    // These cannot be changed without introducing possibilities of
    // going out of sync with consensus.
    bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(properties.get("bft.sync.patience", 200));
    // Default values mean that pacemakers will sync if they are within 5 views of each other.
    // 5 consecutive failing views will take 1*(2^6)-1 seconds = 63 seconds.
    bindConstant().annotatedWith(PacemakerTimeout.class).to(3000L);
    bindConstant().annotatedWith(PacemakerRate.class).to(1.1);
    bindConstant().annotatedWith(PacemakerMaxExponent.class).to(0);
    // Mempool configuration
    var mempoolMaxSize = properties.get("mempool.maxSize", 10000);
    install(MempoolConfig.asModule(mempoolMaxSize, 5, 60000, 60000, 100));
    // Sync configuration
    final long syncPatience = properties.get("sync.patience", 5000L);
    bind(SyncConfig.class).toInstance(SyncConfig.of(syncPatience, 10, 3000L));
    // System (e.g. time, random)
    install(new SystemModule());
    install(new RxEnvironmentModule());
    install(new EventLoggerModule());
    install(new DispatcherModule());
    // Consensus
    install(new PersistedBFTKeyModule());
    install(new CryptoModule());
    install(new ConsensusModule());
    // Ledger
    install(new LedgerModule());
    install(new MempoolReceiverModule());
    // Mempool Relay
    install(new MempoolRelayerModule());
    // Sync
    install(new SyncServiceModule());
    // Epochs - Consensus
    install(new EpochsConsensusModule());
    // Epochs - Sync
    install(new EpochsSyncModule());
    // State Computer
    install(new ForksModule());
    if (properties.get("testing_forks.enable", false)) {
        String testingForksModuleName = properties.get("testing_forks.fork_config_name", "TestingForksModuleV1");
        if (testingForksModuleName.isBlank()) {
            testingForksModuleName = "TestingForksModuleV1";
        }
        log.info("Using testing forks module '{}'", testingForksModuleName);
        install(new TestingForksLoader().createTestingForksModuleConfigFromClassName(testingForksModuleName));
    } else {
        final var forksModule = FORKS_MODULE_BY_NETWORK_ID.getOrDefault(networkId, new GenericTestnetForksModule());
        log.info("Using a predefined forks module '{}'", forksModule.getClass().getSimpleName());
        install(forksModule);
    }
    if (properties.get("overwrite_forks.enable", false)) {
        log.info("Enabling fork overwrites from properties");
        install(new ForkOverwritesFromPropertiesModule());
    }
    install(new RadixEngineStateComputerModule());
    install(new RadixEngineModule());
    install(new RadixEngineStoreModule());
    // Checkpoints
    install(new RadixEngineCheckpointModule());
    // Storage
    install(new DatabasePropertiesModule());
    install(new PersistenceModule());
    install(new ConsensusRecoveryModule());
    install(new LedgerRecoveryModule());
    // System Info
    install(new SystemInfoModule());
    // Network
    install(new MessagingModule());
    install(new MessageCentralModule(properties));
    install(new HostIpModule(properties));
    install(new P2PModule(properties));
    install(new PeerDiscoveryModule());
    install(new PeerLivenessMonitorModule());
    // API
    var bindAddress = properties.get("api.bind.address", DEFAULT_BIND_ADDRESS);
    var port = properties.get("api.port", DEFAULT_CORE_PORT);
    var enableTransactions = properties.get("api.transactions.enable", false);
    var enableSign = properties.get("api.sign.enable", false);
    install(new ApiModule(bindAddress, port, enableTransactions, enableSign));
    // Substate Hash Accumulator
    boolean isUpdateEpochHashFileEnabled = properties.get(UPDATE_EPOCH_HASH_FILE_ENABLE_PROPERTY_NAME, false);
    boolean isVerifyEpochHashEnabled = properties.get(VERIFY_EPOCH_HASH_ENABLE_PROPERTY_NAME, false);
    if (isUpdateEpochHashFileEnabled || isVerifyEpochHashEnabled) {
        SubstateAccumulatorHashModule substateAccumulatorHashModule = new SubstateAccumulatorHashModule(isUpdateEpochHashFileEnabled, isVerifyEpochHashEnabled);
        log.info("Enabling Substate Hash Accumulator Module.");
        install(substateAccumulatorHashModule);
    }
}
Also used : RadixEngineModule(com.radixdlt.statecomputer.RadixEngineModule) ApiModule(com.radixdlt.api.ApiModule) GenericTestnetForksModule(com.radixdlt.statecomputer.forks.modules.GenericTestnetForksModule) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) ReleasenetForksModule(com.radixdlt.statecomputer.forks.modules.ReleasenetForksModule) StokenetForksModule(com.radixdlt.statecomputer.forks.modules.StokenetForksModule) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) RadixEngineStateComputerModule(com.radixdlt.statecomputer.RadixEngineStateComputerModule) SyncConfig(com.radixdlt.sync.SyncConfig) Addressing(com.radixdlt.networks.Addressing) MessageCentralModule(com.radixdlt.network.messaging.MessageCentralModule) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) GenericTestnetForksModule(com.radixdlt.statecomputer.forks.modules.GenericTestnetForksModule) SubstateAccumulatorHashModule(com.radixdlt.statecomputer.substatehash.SubstateAccumulatorHashModule) HostIpModule(com.radixdlt.network.hostip.HostIpModule) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) PeerLivenessMonitorModule(com.radixdlt.network.p2p.PeerLivenessMonitorModule) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) TestingForksLoader(com.radixdlt.statecomputer.forks.modules.testing.TestingForksLoader) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) PersistenceModule(com.radixdlt.store.PersistenceModule) NetworkId(com.radixdlt.networks.NetworkId) RxEnvironmentModule(com.radixdlt.environment.rx.RxEnvironmentModule) DatabasePropertiesModule(com.radixdlt.store.DatabasePropertiesModule) MempoolRelayerModule(com.radixdlt.mempool.MempoolRelayerModule) MessagingModule(com.radixdlt.network.messaging.MessagingModule) ForkOverwritesFromPropertiesModule(com.radixdlt.statecomputer.forks.ForkOverwritesFromPropertiesModule) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) P2PModule(com.radixdlt.network.p2p.P2PModule) PeerDiscoveryModule(com.radixdlt.network.p2p.PeerDiscoveryModule) PersistedBFTKeyModule(com.radixdlt.keys.PersistedBFTKeyModule) MempoolReceiverModule(com.radixdlt.mempool.MempoolReceiverModule)

Example 2 with P2PModule

use of com.radixdlt.network.p2p.P2PModule in project radixdlt by radixdlt.

the class P2PTestNetworkRunner method createInjector.

private static Injector createInjector(MockP2PNetwork p2pNetwork, DeterministicNetwork network, P2PConfig p2pConfig, ECKeyPair nodeKey, RadixNodeUri selfUri, int selfNodeIndex) throws ParseException {
    final var properties = new RuntimeProperties(new JSONObject(), new String[] {});
    return Guice.createInjector(Modules.override(new P2PModule(properties)).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(TestCounters.class).toInstance(new TestCounters());
            bind(P2PConfig.class).toInstance(p2pConfig);
            bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
            bind(SystemCounters.class).to(SystemCountersImpl.class).in(Scopes.SINGLETON);
        }

        @Provides
        public PeerOutboundBootstrap peerOutboundBootstrap(TestCounters testCounters) {
            return uri -> {
                testCounters.outboundChannelsBootstrapped += 1;
                p2pNetwork.createChannel(selfNodeIndex, uri);
            };
        }
    }), new PeerDiscoveryModule(), new PeerLivenessMonitorModule(), new DispatcherModule(), new AbstractModule() {

        @Override
        protected void configure() {
            final var dbDir = new TemporaryFolder();
            try {
                dbDir.create();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            bindConstant().annotatedWith(NetworkId.class).to(Network.LOCALNET.getId());
            bind(Addressing.class).toInstance(Addressing.ofNetwork(Network.LOCALNET));
            bindConstant().annotatedWith(DatabaseLocation.class).to(dbDir.getRoot().getAbsolutePath());
            bindConstant().annotatedWith(DatabaseCacheSize.class).to(100_000L);
            bind(ECKeyPair.class).annotatedWith(Self.class).toInstance(nodeKey);
            bind(ECPublicKey.class).annotatedWith(Self.class).toInstance(nodeKey.getPublicKey());
            bind(BFTNode.class).annotatedWith(Self.class).toInstance(BFTNode.create(nodeKey.getPublicKey()));
            bind(String.class).annotatedWith(Self.class).toInstance(Addressing.ofNetwork(Network.LOCALNET).forValidators().of(nodeKey.getPublicKey()).substring(0, 10));
            bind(ECKeyOps.class).toInstance(ECKeyOps.fromKeyPair(nodeKey));
            bind(Environment.class).toInstance(network.createSender(BFTNode.create(nodeKey.getPublicKey())));
            bind(RuntimeProperties.class).toInstance(properties);
            bind(Serialization.class).toInstance(DefaultSerialization.getInstance());
            bind(DeterministicProcessor.class);
            Multibinder.newSetBinder(binder(), StartProcessorOnRunner.class);
            bind(ForkConfig.class).annotatedWith(NewestForkConfig.class).toInstance(new FixedEpochForkConfig("genesis", null, 0L));
        }
    });
}
Also used : Key(com.google.inject.Key) DefaultSerialization(com.radixdlt.DefaultSerialization) DatabaseCacheSize(com.radixdlt.store.DatabaseCacheSize) DispatcherModule(com.radixdlt.modules.DispatcherModule) JSONObject(org.json.JSONObject) ForkConfig(com.radixdlt.statecomputer.forks.ForkConfig) PeerOutboundBootstrap(com.radixdlt.network.p2p.transport.PeerOutboundBootstrap) SystemCounters(com.radixdlt.counters.SystemCounters) DatabaseEnvironment(com.radixdlt.store.DatabaseEnvironment) Multibinder(com.google.inject.multibindings.Multibinder) Objects(java.util.Objects) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) P2PModule(com.radixdlt.network.p2p.P2PModule) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) ParseException(org.apache.commons.cli.ParseException) NetworkId(com.radixdlt.networks.NetworkId) StartProcessorOnRunner(com.radixdlt.environment.StartProcessorOnRunner) IntStream(java.util.stream.IntStream) PeerManager(com.radixdlt.network.p2p.PeerManager) Serialization(com.radixdlt.serialization.Serialization) Modules(com.google.inject.util.Modules) PeerLivenessMonitorModule(com.radixdlt.network.p2p.PeerLivenessMonitorModule) ECPublicKey(com.radixdlt.crypto.ECPublicKey) DeterministicNetwork(com.radixdlt.environment.deterministic.network.DeterministicNetwork) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) ImmutableList(com.google.common.collect.ImmutableList) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MessageSelector(com.radixdlt.environment.deterministic.network.MessageSelector) PeerDiscoveryModule(com.radixdlt.network.p2p.PeerDiscoveryModule) AddressBook(com.radixdlt.network.p2p.addressbook.AddressBook) Addressing(com.radixdlt.networks.Addressing) NewestForkConfig(com.radixdlt.statecomputer.forks.NewestForkConfig) Network(com.radixdlt.networks.Network) ECKeyOps(com.radixdlt.crypto.ECKeyOps) Environment(com.radixdlt.environment.Environment) RadixNodeUri(com.radixdlt.network.p2p.RadixNodeUri) IOException(java.io.IOException) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) Scopes(com.google.inject.Scopes) Injector(com.google.inject.Injector) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) P2PConfig(com.radixdlt.network.p2p.P2PConfig) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) DeterministicProcessor(com.radixdlt.environment.deterministic.DeterministicProcessor) Self(com.radixdlt.hotstuff.bft.Self) StartProcessorOnRunner(com.radixdlt.environment.StartProcessorOnRunner) TemporaryFolder(org.junit.rules.TemporaryFolder) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) PeerLivenessMonitorModule(com.radixdlt.network.p2p.PeerLivenessMonitorModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) ForkConfig(com.radixdlt.statecomputer.forks.ForkConfig) FixedEpochForkConfig(com.radixdlt.statecomputer.forks.FixedEpochForkConfig) NewestForkConfig(com.radixdlt.statecomputer.forks.NewestForkConfig) P2PConfig(com.radixdlt.network.p2p.P2PConfig) ECKeyPair(com.radixdlt.crypto.ECKeyPair) IOException(java.io.IOException) AbstractModule(com.google.inject.AbstractModule) JSONObject(org.json.JSONObject) ECPublicKey(com.radixdlt.crypto.ECPublicKey) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) DispatcherModule(com.radixdlt.modules.DispatcherModule) P2PModule(com.radixdlt.network.p2p.P2PModule) PeerDiscoveryModule(com.radixdlt.network.p2p.PeerDiscoveryModule)

Aggregations

P2PModule (com.radixdlt.network.p2p.P2PModule)2 PeerDiscoveryModule (com.radixdlt.network.p2p.PeerDiscoveryModule)2 PeerLivenessMonitorModule (com.radixdlt.network.p2p.PeerLivenessMonitorModule)2 Addressing (com.radixdlt.networks.Addressing)2 NetworkId (com.radixdlt.networks.NetworkId)2 RuntimeProperties (com.radixdlt.properties.RuntimeProperties)2 ImmutableList (com.google.common.collect.ImmutableList)1 AbstractModule (com.google.inject.AbstractModule)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 Provides (com.google.inject.Provides)1 Scopes (com.google.inject.Scopes)1 Multibinder (com.google.inject.multibindings.Multibinder)1 Modules (com.google.inject.util.Modules)1 DefaultSerialization (com.radixdlt.DefaultSerialization)1 ApiModule (com.radixdlt.api.ApiModule)1 SystemCounters (com.radixdlt.counters.SystemCounters)1 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)1 ECKeyOps (com.radixdlt.crypto.ECKeyOps)1