Search in sources :

Example 1 with Network

use of com.radixdlt.networks.Network in project radixdlt by radixdlt.

the class DeterministicActorsTest method setup.

@SuppressWarnings("UnstableApiUsage")
@Before
public void setup() {
    var allNodes = nodeKeys.stream().map(k -> BFTNode.create(k.getPublicKey())).toList();
    this.network = new DeterministicNetwork(allNodes, MessageSelector.firstSelector(), MessageMutator.nothing());
    var nodeCreators = Streams.mapWithIndex(nodeKeys.stream(), (k, i) -> (Supplier<Injector>) () -> createRunner(i == 1, k, allNodes)).toList();
    deterministicRunner = new MultiNodeDeterministicRunner(nodeCreators, this::stopDatabase, network);
    deterministicRunner.start();
}
Also used : Module(com.google.inject.Module) Key(com.google.inject.Key) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) BerkeleyAdditionalStore(com.radixdlt.store.berkeley.BerkeleyAdditionalStore) SubstateAccumulatorHashModule(com.radixdlt.statecomputer.substatehash.SubstateAccumulatorHashModule) After(org.junit.After) PersistedNodeForTestingModule(com.radixdlt.modules.PersistedNodeForTestingModule) DatabaseEnvironment(com.radixdlt.store.DatabaseEnvironment) Streams(com.google.common.collect.Streams) Multibinder(com.google.inject.multibindings.Multibinder) LastEventsModule(com.radixdlt.environment.deterministic.LastEventsModule) Collectors(java.util.stream.Collectors) Logger(org.apache.logging.log4j.Logger) MainnetForksModule(com.radixdlt.statecomputer.forks.modules.MainnetForksModule) InvalidProposedTxn(com.radixdlt.statecomputer.InvalidProposedTxn) Amount(com.radixdlt.application.tokens.Amount) NetworkId(com.radixdlt.networks.NetworkId) java.util(java.util) Modules(com.google.inject.util.Modules) SyncCheckTrigger(com.radixdlt.sync.messages.local.SyncCheckTrigger) Supplier(java.util.function.Supplier) DeterministicNetwork(com.radixdlt.environment.deterministic.network.DeterministicNetwork) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) ImmutableList(com.google.common.collect.ImmutableList) DatabaseLocation(com.radixdlt.store.DatabaseLocation) MessageSelector(com.radixdlt.environment.deterministic.network.MessageSelector) MempoolConfig(com.radixdlt.mempool.MempoolConfig) EvictingQueue(com.google.common.collect.EvictingQueue) BerkeleyLedgerEntryStore(com.radixdlt.store.berkeley.BerkeleyLedgerEntryStore) BerkeleyRecoverableProcessedTxnStore(com.radixdlt.api.core.reconstruction.BerkeleyRecoverableProcessedTxnStore) Before(org.junit.Before) PrivateKeys(com.radixdlt.utils.PrivateKeys) EventDispatcher(com.radixdlt.environment.EventDispatcher) Network(com.radixdlt.networks.Network) Environment(com.radixdlt.environment.Environment) Test(org.junit.Test) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) Scopes(com.google.inject.Scopes) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) Injector(com.google.inject.Injector) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) FailOnEvent(com.radixdlt.harness.FailOnEvent) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) MultiNodeDeterministicRunner(com.radixdlt.environment.deterministic.MultiNodeDeterministicRunner) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) PeersView(com.radixdlt.network.p2p.PeersView) LogManager(org.apache.logging.log4j.LogManager) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) MultiNodeDeterministicRunner(com.radixdlt.environment.deterministic.MultiNodeDeterministicRunner) DeterministicNetwork(com.radixdlt.environment.deterministic.network.DeterministicNetwork) Supplier(java.util.function.Supplier) Before(org.junit.Before)

Example 2 with Network

use of com.radixdlt.networks.Network 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

ImmutableList (com.google.common.collect.ImmutableList)2 AbstractModule (com.google.inject.AbstractModule)2 Guice (com.google.inject.Guice)2 Injector (com.google.inject.Injector)2 Key (com.google.inject.Key)2 Provides (com.google.inject.Provides)2 Scopes (com.google.inject.Scopes)2 Multibinder (com.google.inject.multibindings.Multibinder)2 Modules (com.google.inject.util.Modules)2 ECKeyPair (com.radixdlt.crypto.ECKeyPair)2 Environment (com.radixdlt.environment.Environment)2 DeterministicNetwork (com.radixdlt.environment.deterministic.network.DeterministicNetwork)2 MessageMutator (com.radixdlt.environment.deterministic.network.MessageMutator)2 MessageSelector (com.radixdlt.environment.deterministic.network.MessageSelector)2 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)2 Self (com.radixdlt.hotstuff.bft.Self)2 Network (com.radixdlt.networks.Network)2 NetworkId (com.radixdlt.networks.NetworkId)2 EvictingQueue (com.google.common.collect.EvictingQueue)1 Streams (com.google.common.collect.Streams)1