Search in sources :

Example 1 with RadixEngineForksLatestOnlyModule

use of com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule in project radixdlt by radixdlt.

the class ApiTest method setup.

@Before
public void setup() {
    var injector = Guice.createInjector(MempoolConfig.asModule(mempoolMaxSize, 10), new MainnetForkConfigsModule(), new RadixEngineForksLatestOnlyModule(RERulesConfig.testingDefault().overrideFeeTable(FeeTable.create(Amount.ofSubunits(UInt256.ONE), Map.of(ValidatorRegisteredCopy.class, Amount.ofSubunits(UInt256.ONE))))), new ForksModule(), new SingleNodeAndPeersDeterministicNetworkModule(TEST_KEY, 1), new MockedGenesisModule(Set.of(TEST_KEY.getPublicKey()), totalTokenAmount, stakeAmount), new AbstractModule() {

        @Override
        protected void configure() {
            bind(BerkeleyRecoverableProcessedTxnStore.class).in(Scopes.SINGLETON);
            Multibinder.newSetBinder(binder(), BerkeleyAdditionalStore.class).addBinding().to(BerkeleyRecoverableProcessedTxnStore.class);
            bindConstant().annotatedWith(DatabaseLocation.class).to(folder.getRoot().getAbsolutePath());
            bindConstant().annotatedWith(NetworkId.class).to(99);
            bind(P2PConfig.class).toInstance(mock(P2PConfig.class));
            bind(AddressBook.class).in(Scopes.SINGLETON);
            var selfUri = RadixNodeUri.fromPubKeyAndAddress(99, TEST_KEY.getPublicKey(), "localhost", 23456);
            bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
            var addressBookPersistence = mock(AddressBookPersistence.class);
            when(addressBookPersistence.getAllEntries()).thenReturn(ImmutableList.of());
            bind(AddressBookPersistence.class).toInstance(addressBookPersistence);
            var runtimeProperties = mock(RuntimeProperties.class);
            when(runtimeProperties.get(eq("api.transactions.enable"), anyBoolean())).thenReturn(true);
            bind(RuntimeProperties.class).toInstance(runtimeProperties);
        }
    });
    injector.injectMembers(this);
}
Also used : SingleNodeAndPeersDeterministicNetworkModule(com.radixdlt.SingleNodeAndPeersDeterministicNetworkModule) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) AddressBookPersistence(com.radixdlt.network.p2p.addressbook.AddressBookPersistence) BerkeleyAdditionalStore(com.radixdlt.store.berkeley.BerkeleyAdditionalStore) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) AbstractModule(com.google.inject.AbstractModule) BerkeleyRecoverableProcessedTxnStore(com.radixdlt.api.core.reconstruction.BerkeleyRecoverableProcessedTxnStore) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) RadixNodeUri(com.radixdlt.network.p2p.RadixNodeUri) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) Before(org.junit.Before)

Example 2 with RadixEngineForksLatestOnlyModule

use of com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule in project radixdlt by radixdlt.

the class RadixEngineStateComputerTest method getExternalModule.

private Module getExternalModule() {
    return new AbstractModule() {

        @Override
        public void configure() {
            var validatorSet = BFTValidatorSet.from(registeredNodes.stream().map(ECKeyPair::getPublicKey).map(BFTNode::create).map(n -> BFTValidator.from(n, UInt256.ONE)));
            bind(ProposerElection.class).toInstance(new WeightedRotatingLeaders(validatorSet));
            bind(Serialization.class).toInstance(serialization);
            bind(Hasher.class).toInstance(Sha256Hasher.withDefaultSerialization());
            bind(new TypeLiteral<EngineStore<LedgerAndBFTProof>>() {
            }).toInstance(engineStore);
            bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
            install(MempoolConfig.asModule(10, 10));
            install(new MainnetForkConfigsModule());
            install(new ForksModule());
            install(new RadixEngineForksLatestOnlyModule());
            // HACK
            bind(CommittedReader.class).toInstance(CommittedReader.mocked());
            bind(LedgerAccumulator.class).to(SimpleLedgerAccumulatorAndVerifier.class);
            bind(new TypeLiteral<EventDispatcher<MempoolAddSuccess>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<InvalidProposedTxn>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<TxnsRemovedFromMempool>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<REOutput>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<MempoolRelayTrigger>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
            }).toInstance(TypedMocks.rmock(EventDispatcher.class));
            bind(SystemCounters.class).to(SystemCountersImpl.class);
        }
    };
}
Also used : Module(com.google.inject.Module) RERules(com.radixdlt.statecomputer.forks.RERules) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) RadixEngineException(com.radixdlt.engine.RadixEngineException) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) TypedMocks(com.radixdlt.utils.TypedMocks) DefaultSerialization(com.radixdlt.DefaultSerialization) Hasher(com.radixdlt.crypto.Hasher) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) RoundData(com.radixdlt.application.system.state.RoundData) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.consensus.LedgerProof) View(com.radixdlt.consensus.bft.View) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) EngineStore(com.radixdlt.store.EngineStore) Collectors(java.util.stream.Collectors) LedgerHeader(com.radixdlt.consensus.LedgerHeader) ProposerElection(com.radixdlt.consensus.liveness.ProposerElection) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) CommittedReader(com.radixdlt.sync.CommittedReader) Amount(com.radixdlt.application.tokens.Amount) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) Serialization(com.radixdlt.serialization.Serialization) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) com.radixdlt.atom(com.radixdlt.atom) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) BFTValidator(com.radixdlt.consensus.bft.BFTValidator) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) MempoolConfig(com.radixdlt.mempool.MempoolConfig) AccumulatorState(com.radixdlt.ledger.AccumulatorState) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) BFTHeader(com.radixdlt.consensus.BFTHeader) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) BFTNode(com.radixdlt.consensus.bft.BFTNode) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) BFTNode(com.radixdlt.consensus.bft.BFTNode) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) SystemCounters(com.radixdlt.counters.SystemCounters) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) AbstractModule(com.google.inject.AbstractModule) DefaultSerialization(com.radixdlt.DefaultSerialization) Serialization(com.radixdlt.serialization.Serialization) Hasher(com.radixdlt.crypto.Hasher) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) EventDispatcher(com.radixdlt.environment.EventDispatcher) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) TypeLiteral(com.google.inject.TypeLiteral) CommittedReader(com.radixdlt.sync.CommittedReader) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) ProposerElection(com.radixdlt.consensus.liveness.ProposerElection) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders)

Example 3 with RadixEngineForksLatestOnlyModule

use of com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule in project radixdlt by radixdlt.

the class AbstractRadixEngineTest method setup.

@Before
public void setup() {
    var injector = Guice.createInjector(MempoolConfig.asModule(mempoolMaxSize, 10), new MainnetForkConfigsModule(), new RadixEngineForksLatestOnlyModule(RERulesConfig.testingDefault().overrideFeeTable(FeeTable.create(Amount.ofSubunits(UInt256.ONE), Map.of(ValidatorRegisteredCopy.class, Amount.ofSubunits(UInt256.ONE)))).overrideMaxMessageLen(maxMessageLen)), new ForksModule(), new SingleNodeAndPeersDeterministicNetworkModule(TEST_KEY, 1), new MockedGenesisModule(Set.of(TEST_KEY.getPublicKey()), totalTokenAmount, stakeAmount), new AbstractModule() {

        @Override
        protected void configure() {
            bind(BerkeleyRecoverableProcessedTxnStore.class).in(Scopes.SINGLETON);
            Multibinder.newSetBinder(binder(), BerkeleyAdditionalStore.class).addBinding().to(BerkeleyRecoverableProcessedTxnStore.class);
            bindConstant().annotatedWith(DatabaseLocation.class).to(folder.getRoot().getAbsolutePath());
            bindConstant().annotatedWith(NetworkId.class).to(99);
            bind(P2PConfig.class).toInstance(mock(P2PConfig.class));
            bind(AddressBook.class).in(Scopes.SINGLETON);
            var selfUri = RadixNodeUri.fromPubKeyAndAddress(99, TEST_KEY.getPublicKey(), "localhost", 23456);
            bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
            var addressBookPersistence = mock(AddressBookPersistence.class);
            when(addressBookPersistence.getAllEntries()).thenReturn(ImmutableList.of());
            bind(AddressBookPersistence.class).toInstance(addressBookPersistence);
            var runtimeProperties = mock(RuntimeProperties.class);
            when(runtimeProperties.get(eq("api.transactions.enable"), anyBoolean())).thenReturn(true);
            bind(RuntimeProperties.class).toInstance(runtimeProperties);
        }
    });
    injector.injectMembers(this);
}
Also used : SingleNodeAndPeersDeterministicNetworkModule(com.radixdlt.SingleNodeAndPeersDeterministicNetworkModule) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) AddressBookPersistence(com.radixdlt.network.p2p.addressbook.AddressBookPersistence) BerkeleyAdditionalStore(com.radixdlt.store.berkeley.BerkeleyAdditionalStore) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) AbstractModule(com.google.inject.AbstractModule) ValidatorRegisteredCopy(com.radixdlt.application.validators.state.ValidatorRegisteredCopy) BerkeleyRecoverableProcessedTxnStore(com.radixdlt.api.core.reconstruction.BerkeleyRecoverableProcessedTxnStore) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) RadixNodeUri(com.radixdlt.network.p2p.RadixNodeUri) RuntimeProperties(com.radixdlt.properties.RuntimeProperties) Before(org.junit.Before)

Aggregations

AbstractModule (com.google.inject.AbstractModule)3 MockedGenesisModule (com.radixdlt.statecomputer.checkpoint.MockedGenesisModule)3 ForksModule (com.radixdlt.statecomputer.forks.ForksModule)3 MainnetForkConfigsModule (com.radixdlt.statecomputer.forks.MainnetForkConfigsModule)3 RadixEngineForksLatestOnlyModule (com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule)3 Before (org.junit.Before)3 SingleNodeAndPeersDeterministicNetworkModule (com.radixdlt.SingleNodeAndPeersDeterministicNetworkModule)2 BerkeleyRecoverableProcessedTxnStore (com.radixdlt.api.core.reconstruction.BerkeleyRecoverableProcessedTxnStore)2 ImmutableList (com.google.common.collect.ImmutableList)1 HashCode (com.google.common.hash.HashCode)1 Guice (com.google.inject.Guice)1 Inject (com.google.inject.Inject)1 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 DefaultSerialization (com.radixdlt.DefaultSerialization)1 RoundData (com.radixdlt.application.system.state.RoundData)1 Amount (com.radixdlt.application.tokens.Amount)1 ValidatorRegisteredCopy (com.radixdlt.application.validators.state.ValidatorRegisteredCopy)1 com.radixdlt.atom (com.radixdlt.atom)1 TxAction (com.radixdlt.atom.TxAction)1