Search in sources :

Example 1 with LedgerUpdate

use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.

the class EpochManagerTest method should_not_send_consensus_messages_if_not_part_of_new_epoch.

@Test
public void should_not_send_consensus_messages_if_not_part_of_new_epoch() {
    // Arrange
    epochManager.start();
    BFTValidatorSet nextValidatorSet = BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)));
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    LedgerHeader header = LedgerHeader.genesis(accumulatorState, nextValidatorSet, 0);
    UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header);
    VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
    LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
    var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
    var proposerElection = new WeightedRotatingLeaders(nextValidatorSet);
    var bftConfiguration = new BFTConfiguration(proposerElection, nextValidatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher));
    LedgerProof proof = mock(LedgerProof.class);
    when(proof.getEpoch()).thenReturn(header.getEpoch() + 1);
    var epochChange = new EpochChange(proof, bftConfiguration);
    var ledgerUpdate = new LedgerUpdate(mock(VerifiedTxnsAndProof.class), ImmutableClassToInstanceMap.of(EpochChange.class, epochChange));
    // Act
    epochManager.epochsLedgerUpdateEventProcessor().process(ledgerUpdate);
    // Assert
    verify(proposalDispatcher, never()).dispatch(any(Iterable.class), argThat(p -> p.getEpoch() == epochChange.getEpoch()));
    verify(voteDispatcher, never()).dispatch(any(BFTNode.class), any());
}
Also used : LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Module(com.google.inject.Module) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) GetVerticesRequest(com.radixdlt.consensus.sync.GetVerticesRequest) EpochsConsensusModule(com.radixdlt.EpochsConsensusModule) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Inject(com.google.inject.Inject) PacemakerTimeout(com.radixdlt.consensus.bft.PacemakerTimeout) Hasher(com.radixdlt.crypto.Hasher) HashSigner(com.radixdlt.consensus.HashSigner) BFTCommittedUpdate(com.radixdlt.consensus.bft.BFTCommittedUpdate) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) VertexRequestTimeout(com.radixdlt.consensus.sync.VertexRequestTimeout) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) Map(java.util.Map) ViewQuorumReached(com.radixdlt.consensus.bft.ViewQuorumReached) LedgerProof(com.radixdlt.consensus.LedgerProof) View(com.radixdlt.consensus.bft.View) HashUtils(com.radixdlt.crypto.HashUtils) SystemCounters(com.radixdlt.counters.SystemCounters) LedgerModule(com.radixdlt.LedgerModule) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) PersistentSafetyStateStore(com.radixdlt.consensus.safety.PersistentSafetyStateStore) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) BFTRebuildUpdate(com.radixdlt.consensus.bft.BFTRebuildUpdate) LedgerHeader(com.radixdlt.consensus.LedgerHeader) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) BFTHighQCUpdate(com.radixdlt.consensus.bft.BFTHighQCUpdate) PacemakerMaxExponent(com.radixdlt.consensus.bft.PacemakerMaxExponent) Optional(java.util.Optional) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) TypeLiteral(com.google.inject.TypeLiteral) BFTSyncPatienceMillis(com.radixdlt.consensus.sync.BFTSyncPatienceMillis) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) HighQC(com.radixdlt.consensus.HighQC) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) Proposal(com.radixdlt.consensus.Proposal) LocalTimeoutOccurrence(com.radixdlt.consensus.liveness.LocalTimeoutOccurrence) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) NextTxnsGenerator(com.radixdlt.consensus.liveness.NextTxnsGenerator) PreparedTxn(com.radixdlt.ledger.StateComputerLedger.PreparedTxn) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) LedgerStatusUpdate(com.radixdlt.sync.messages.remote.LedgerStatusUpdate) BFTValidator(com.radixdlt.consensus.bft.BFTValidator) CryptoModule(com.radixdlt.CryptoModule) Vote(com.radixdlt.consensus.Vote) LastEpochProof(com.radixdlt.store.LastEpochProof) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) ViewUpdate(com.radixdlt.consensus.bft.ViewUpdate) AccumulatorState(com.radixdlt.ledger.AccumulatorState) UInt256(com.radixdlt.utils.UInt256) Nullable(javax.annotation.Nullable) Before(org.junit.Before) TimeSupplier(com.radixdlt.utils.TimeSupplier) EventDispatcher(com.radixdlt.environment.EventDispatcher) ConsensusModule(com.radixdlt.ConsensusModule) Txn(com.radixdlt.atom.Txn) BFTInsertUpdate(com.radixdlt.consensus.bft.BFTInsertUpdate) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Mockito.verify(org.mockito.Mockito.verify) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Consumer(java.util.function.Consumer) Mockito.never(org.mockito.Mockito.never) Provides(com.google.inject.Provides) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) ECKeyPair(com.radixdlt.crypto.ECKeyPair) NoVote(com.radixdlt.consensus.bft.NoVote) PacemakerRate(com.radixdlt.consensus.bft.PacemakerRate) Self(com.radixdlt.consensus.bft.Self) Guice(com.google.inject.Guice) BFTNode(com.radixdlt.consensus.bft.BFTNode) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) EpochLocalTimeoutOccurrence(com.radixdlt.consensus.liveness.EpochLocalTimeoutOccurrence) Mempool(com.radixdlt.mempool.Mempool) LastProof(com.radixdlt.store.LastProof) GetVerticesErrorResponse(com.radixdlt.consensus.sync.GetVerticesErrorResponse) GetVerticesResponse(com.radixdlt.consensus.sync.GetVerticesResponse) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.consensus.bft.BFTNode) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) LedgerHeader(com.radixdlt.consensus.LedgerHeader) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.consensus.LedgerProof) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) Test(org.junit.Test)

Example 2 with LedgerUpdate

use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.

the class InMemorySystemInfoTest method createLedgerUpdate.

private LedgerUpdate createLedgerUpdate(BFTNode self) {
    var events = List.<REEvent>of(new ValidatorBFTDataEvent(self.getKey(), 10, 1));
    var txn = new REProcessedTxn(null, null, null, events);
    var output = ImmutableClassToInstanceMap.<Object, REOutput>of(REOutput.class, REOutput.create(List.of(txn)));
    return new LedgerUpdate(mock(VerifiedTxnsAndProof.class), output);
}
Also used : REOutput(com.radixdlt.statecomputer.REOutput) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) REEvent(com.radixdlt.constraintmachine.REEvent) ValidatorBFTDataEvent(com.radixdlt.constraintmachine.REEvent.ValidatorBFTDataEvent) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn)

Example 3 with LedgerUpdate

use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.

the class MockedStateComputer method commit.

@Override
public void commit(VerifiedTxnsAndProof txnsAndProof, VerifiedVertexStoreState vertexStoreState) {
    var output = txnsAndProof.getProof().getNextValidatorSet().map(validatorSet -> {
        LedgerProof header = txnsAndProof.getProof();
        UnverifiedVertex genesisVertex = UnverifiedVertex.createGenesis(header.getRaw());
        VerifiedVertex verifiedGenesisVertex = new VerifiedVertex(genesisVertex, hasher.hash(genesisVertex));
        LedgerHeader nextLedgerHeader = LedgerHeader.create(header.getEpoch() + 1, View.genesis(), header.getAccumulatorState(), header.timestamp());
        QuorumCertificate genesisQC = QuorumCertificate.ofGenesis(verifiedGenesisVertex, nextLedgerHeader);
        final var initialState = VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesisVertex, Optional.empty(), hasher);
        var proposerElection = new WeightedRotatingLeaders(validatorSet);
        var bftConfiguration = new BFTConfiguration(proposerElection, validatorSet, initialState);
        return new EpochChange(header, bftConfiguration);
    }).map(e -> ImmutableClassToInstanceMap.<Object, EpochChange>of(EpochChange.class, e)).orElse(ImmutableClassToInstanceMap.of());
    var ledgerUpdate = new LedgerUpdate(txnsAndProof, output);
    ledgerUpdateDispatcher.dispatch(ledgerUpdate);
}
Also used : VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) HighQC(com.radixdlt.consensus.HighQC) Inject(com.google.inject.Inject) Hasher(com.radixdlt.crypto.Hasher) MempoolAdd(com.radixdlt.mempool.MempoolAdd) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) Map(java.util.Map) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) MockPrepared(com.radixdlt.ledger.MockPrepared) LedgerProof(com.radixdlt.consensus.LedgerProof) View(com.radixdlt.consensus.bft.View) Nullable(javax.annotation.Nullable) EventDispatcher(com.radixdlt.environment.EventDispatcher) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) Txn(com.radixdlt.atom.Txn) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Collectors(java.util.stream.Collectors) EpochChange(com.radixdlt.consensus.epoch.EpochChange) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) LedgerHeader(com.radixdlt.consensus.LedgerHeader) StateComputerLedger(com.radixdlt.ledger.StateComputerLedger) List(java.util.List) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) BFTNode(com.radixdlt.consensus.bft.BFTNode) Optional(java.util.Optional) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) LedgerHeader(com.radixdlt.consensus.LedgerHeader) EpochChange(com.radixdlt.consensus.epoch.EpochChange) BFTConfiguration(com.radixdlt.consensus.BFTConfiguration) LedgerProof(com.radixdlt.consensus.LedgerProof) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders)

Example 4 with LedgerUpdate

use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.

the class RxEnvironmentModule method configure.

@Override
public void configure() {
    ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(ThreadFactories.daemonThreads("TimeoutSender"));
    bind(Environment.class).to(RxEnvironment.class);
    bind(ScheduledExecutorService.class).toInstance(ses);
    // TODO: Remove, still required by SimulationNodes.java
    bind(new TypeLiteral<Observable<LedgerUpdate>>() {
    }).toProvider(new ObservableProvider<>(LedgerUpdate.class));
    bind(new TypeLiteral<Observable<BFTHighQCUpdate>>() {
    }).toProvider(new ObservableProvider<>(BFTHighQCUpdate.class));
    Multibinder.newSetBinder(binder(), new TypeLiteral<RxRemoteDispatcher<?>>() {
    });
    Multibinder.newSetBinder(binder(), new TypeLiteral<EventProcessorOnRunner<?>>() {
    });
    Multibinder.newSetBinder(binder(), new TypeLiteral<RemoteEventProcessorOnRunner<?>>() {
    });
    Multibinder.newSetBinder(binder(), new TypeLiteral<ScheduledEventProducerOnRunner<?>>() {
    });
}
Also used : LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RemoteEventProcessorOnRunner(com.radixdlt.environment.RemoteEventProcessorOnRunner) ScheduledEventProducerOnRunner(com.radixdlt.environment.ScheduledEventProducerOnRunner) TypeLiteral(com.google.inject.TypeLiteral) EventProcessorOnRunner(com.radixdlt.environment.EventProcessorOnRunner) RemoteEventProcessorOnRunner(com.radixdlt.environment.RemoteEventProcessorOnRunner) Environment(com.radixdlt.environment.Environment) BFTHighQCUpdate(com.radixdlt.consensus.bft.BFTHighQCUpdate)

Example 5 with LedgerUpdate

use of com.radixdlt.ledger.LedgerUpdate in project radixdlt by radixdlt.

the class LedgerInOrderInvariant method check.

@Override
public Observable<TestInvariantError> check(RunningNetwork network) {
    Map<BFTNode, List<Txn>> commandsPerNode = new HashMap<>();
    network.getNodes().forEach(n -> commandsPerNode.put(n, new ArrayList<>()));
    return network.ledgerUpdates().flatMap(nodeAndCommand -> {
        BFTNode node = nodeAndCommand.getFirst();
        LedgerUpdate ledgerUpdate = nodeAndCommand.getSecond();
        List<Txn> nodeTxns = commandsPerNode.get(node);
        nodeTxns.addAll(ledgerUpdate.getNewTxns());
        return commandsPerNode.values().stream().filter(list -> nodeTxns != list).filter(list -> list.size() >= nodeTxns.size()).findFirst().flatMap(list -> {
            if (Collections.indexOfSubList(list, nodeTxns) != 0) {
                TestInvariantError err = new TestInvariantError("Two nodes don't agree on commands: " + list + " " + nodeTxns);
                return Optional.of(Observable.just(err));
            }
            return Optional.empty();
        }).orElse(Observable.empty());
    });
}
Also used : LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) TestInvariant(com.radixdlt.harness.simulation.TestInvariant) List(java.util.List) Observable(io.reactivex.rxjava3.core.Observable) Map(java.util.Map) Txn(com.radixdlt.atom.Txn) BFTNode(com.radixdlt.consensus.bft.BFTNode) Optional(java.util.Optional) RunningNetwork(com.radixdlt.harness.simulation.network.SimulationNodes.RunningNetwork) HashMap(java.util.HashMap) Collections(java.util.Collections) ArrayList(java.util.ArrayList) BFTNode(com.radixdlt.consensus.bft.BFTNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Txn(com.radixdlt.atom.Txn)

Aggregations

LedgerUpdate (com.radixdlt.ledger.LedgerUpdate)7 BFTNode (com.radixdlt.consensus.bft.BFTNode)5 TypeLiteral (com.google.inject.TypeLiteral)4 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)4 View (com.radixdlt.consensus.bft.View)4 VerifiedTxnsAndProof (com.radixdlt.ledger.VerifiedTxnsAndProof)4 AbstractModule (com.google.inject.AbstractModule)3 Inject (com.google.inject.Inject)3 Txn (com.radixdlt.atom.Txn)3 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)3 HighQC (com.radixdlt.consensus.HighQC)3 LedgerHeader (com.radixdlt.consensus.LedgerHeader)3 LedgerProof (com.radixdlt.consensus.LedgerProof)3 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)3 UnverifiedVertex (com.radixdlt.consensus.UnverifiedVertex)3 BFTHighQCUpdate (com.radixdlt.consensus.bft.BFTHighQCUpdate)3 BFTValidatorSet (com.radixdlt.consensus.bft.BFTValidatorSet)3 PersistentVertexStore (com.radixdlt.consensus.bft.PersistentVertexStore)3 WeightedRotatingLeaders (com.radixdlt.consensus.liveness.WeightedRotatingLeaders)3 Hasher (com.radixdlt.crypto.Hasher)3