Search in sources :

Example 16 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.

the class RadixEngineStateComputerTest method committing_epoch_change_with_different_validator_signed_should_fail.

// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
public void committing_epoch_change_with_different_validator_signed_should_fail() throws Exception {
    // Arrange
    var cmd1 = systemUpdateCommand(0, 2);
    var ledgerProof = new LedgerProof(HashUtils.random256(), LedgerHeader.create(0, View.of(9), new AccumulatorState(3, HashUtils.zero256()), 0, BFTValidatorSet.from(Stream.of(BFTValidator.from(BFTNode.random(), UInt256.ONE)))), new TimestampedECDSASignatures());
    var commandsAndProof = VerifiedTxnsAndProof.create(ImmutableList.of(cmd1), ledgerProof);
    // Act
    // Assert
    assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Test(org.junit.Test)

Example 17 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.

the class RecoveryTest method on_reboot_should_load_same_last_epoch_header.

@Test
public void on_reboot_should_load_same_last_epoch_header() {
    // Arrange
    processForCount(processForCount);
    var epochView = getLastEpochView();
    // Act
    restartNode();
    // Assert
    LedgerProof restartedEpochProof = currentInjector.getInstance(Key.get(LedgerProof.class, LastEpochProof.class));
    assertThat(restartedEpochProof.isEndOfEpoch()).isTrue();
    assertThat(restartedEpochProof.getEpoch() == epochView.getEpoch() - 1 || (restartedEpochProof.getEpoch() == epochView.getEpoch() && epochView.getView().number() > epochCeilingView + 3)).isTrue();
}
Also used : LedgerProof(com.radixdlt.hotstuff.LedgerProof) LastEpochProof(com.radixdlt.store.LastEpochProof) Test(org.junit.Test)

Example 18 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.

the class StateComputerLedger method commit.

private void commit(VerifiedTxnsAndProof verifiedTxnsAndProof, VerifiedVertexStoreState vertexStoreState) {
    synchronized (lock) {
        final LedgerProof nextHeader = verifiedTxnsAndProof.getProof();
        if (headerComparator.compare(nextHeader, this.currentLedgerHeader) <= 0) {
            return;
        }
        var verifiedExtension = verifier.verifyAndGetExtension(this.currentLedgerHeader.getAccumulatorState(), verifiedTxnsAndProof.getTxns(), txn -> txn.getId().asHashCode(), verifiedTxnsAndProof.getProof().getAccumulatorState());
        if (verifiedExtension.isEmpty()) {
            throw new ByzantineQuorumException("Accumulator failure " + currentLedgerHeader + " " + verifiedTxnsAndProof);
        }
        var txns = verifiedExtension.get();
        if (vertexStoreState == null) {
            this.counters.add(CounterType.LEDGER_SYNC_COMMANDS_PROCESSED, txns.size());
        } else {
            this.counters.add(CounterType.LEDGER_BFT_COMMANDS_PROCESSED, txns.size());
        }
        var txnsAndProof = VerifiedTxnsAndProof.create(txns, verifiedTxnsAndProof.getProof());
        // persist
        this.stateComputer.commit(txnsAndProof, vertexStoreState);
        // TODO: move all of the following to post-persist event handling
        this.currentLedgerHeader = nextHeader;
        this.counters.set(CounterType.LEDGER_STATE_VERSION, this.currentLedgerHeader.getStateVersion());
    }
}
Also used : LedgerProof(com.radixdlt.hotstuff.LedgerProof)

Example 19 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof 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) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Inject(com.google.inject.Inject) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) EpochLocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.EpochLocalTimeoutOccurrence) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) MempoolAdd(com.radixdlt.mempool.MempoolAdd) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) EpochsConsensusModule(com.radixdlt.modules.EpochsConsensusModule) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) Map(java.util.Map) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) HashUtils(com.radixdlt.crypto.HashUtils) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) SystemCounters(com.radixdlt.counters.SystemCounters) Vote(com.radixdlt.hotstuff.Vote) ConsensusModule(com.radixdlt.modules.ConsensusModule) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) LedgerModule(com.radixdlt.modules.LedgerModule) Optional(java.util.Optional) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) TypeLiteral(com.google.inject.TypeLiteral) Proposal(com.radixdlt.hotstuff.Proposal) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) CryptoModule(com.radixdlt.modules.CryptoModule) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) PreparedTxn(com.radixdlt.ledger.StateComputerLedger.PreparedTxn) RateLimiter(com.google.common.util.concurrent.RateLimiter) TypedMocks.rmock(com.radixdlt.utils.TypedMocks.rmock) HashSigner(com.radixdlt.hotstuff.HashSigner) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) LedgerStatusUpdate(com.radixdlt.sync.messages.remote.LedgerStatusUpdate) View(com.radixdlt.hotstuff.bft.View) LastEpochProof(com.radixdlt.store.LastEpochProof) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) 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) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) NoVote(com.radixdlt.hotstuff.bft.NoVote) Txn(com.radixdlt.atom.Txn) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) Consumer(java.util.function.Consumer) Mockito.never(org.mockito.Mockito.never) Provides(com.google.inject.Provides) ECKeyPair(com.radixdlt.crypto.ECKeyPair) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) BFTValidator(com.radixdlt.hotstuff.bft.BFTValidator) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Guice(com.google.inject.Guice) Self(com.radixdlt.hotstuff.bft.Self) Mempool(com.radixdlt.mempool.Mempool) LastProof(com.radixdlt.store.LastProof) AbstractModule(com.google.inject.AbstractModule) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.hotstuff.LedgerProof) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Test(org.junit.Test)

Example 20 with LedgerProof

use of com.radixdlt.hotstuff.LedgerProof in project radixdlt by radixdlt.

the class MempoolRunnerTest method createModule.

@SuppressWarnings(// The mock method doesn't support type-safe generics due to type erasure
"unchecked")
public Module createModule() {
    return new AbstractModule() {

        @Override
        public void configure() {
            bind(BFTNode.class).annotatedWith(Self.class).toInstance(BFTNode.random());
            bind(LedgerProof.class).annotatedWith(LastProof.class).toInstance(mock(LedgerProof.class));
            bind(StateComputer.class).toInstance(stateComputer);
            bind(SystemCounters.class).toInstance(new SystemCountersImpl());
            bind(RxRemoteEnvironment.class).toInstance(new RxRemoteEnvironment() {

                @Override
                public <T> Flowable<RemoteEvent<T>> remoteEvents(Class<T> remoteEventClass) {
                    return Flowable.never();
                }
            });
            bind(LedgerAccumulator.class).toInstance(mock(LedgerAccumulator.class));
            bind(LedgerAccumulatorVerifier.class).toInstance(mock(LedgerAccumulatorVerifier.class));
            bind(new TypeLiteral<Comparator<LedgerProof>>() {
            }).toInstance(mock(Comparator.class));
            bind(Addressing.class).toInstance(Addressing.ofNetwork(Network.LOCALNET));
            bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
            Multibinder.newSetBinder(binder(), StartProcessorOnRunner.class);
            install(MempoolConfig.asModule(100, 10));
            install(new MockedKeyModule());
            install(new MockedCryptoModule());
            install(new RxEnvironmentModule());
            install(new DispatcherModule());
            install(new MempoolReceiverModule());
            install(new EventLoggerModule());
        }
    };
}
Also used : MockedKeyModule(com.radixdlt.modules.MockedKeyModule) Self(com.radixdlt.hotstuff.bft.Self) TimeSupplier(com.radixdlt.utils.TimeSupplier) Addressing(com.radixdlt.networks.Addressing) Comparator(java.util.Comparator) LedgerAccumulatorVerifier(com.radixdlt.ledger.LedgerAccumulatorVerifier) TypeLiteral(com.google.inject.TypeLiteral) LedgerProof(com.radixdlt.hotstuff.LedgerProof) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) RxRemoteEnvironment(com.radixdlt.environment.rx.RxRemoteEnvironment) SystemCounters(com.radixdlt.counters.SystemCounters) MockedCryptoModule(com.radixdlt.modules.MockedCryptoModule) RxEnvironmentModule(com.radixdlt.environment.rx.RxEnvironmentModule) AbstractModule(com.google.inject.AbstractModule) LastProof(com.radixdlt.store.LastProof) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) DispatcherModule(com.radixdlt.modules.DispatcherModule) EventLoggerModule(com.radixdlt.modules.EventLoggerModule) Flowable(io.reactivex.rxjava3.core.Flowable)

Aggregations

LedgerProof (com.radixdlt.hotstuff.LedgerProof)28 Test (org.junit.Test)17 DtoLedgerProof (com.radixdlt.ledger.DtoLedgerProof)13 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)9 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)9 AccumulatorState (com.radixdlt.ledger.AccumulatorState)9 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)4 AbstractModule (com.google.inject.AbstractModule)3 TypeLiteral (com.google.inject.TypeLiteral)3 Txn (com.radixdlt.atom.Txn)3 SystemCounters (com.radixdlt.counters.SystemCounters)3 EventDispatcher (com.radixdlt.environment.EventDispatcher)3 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)3 HighQC (com.radixdlt.hotstuff.HighQC)3 Self (com.radixdlt.hotstuff.bft.Self)3 View (com.radixdlt.hotstuff.bft.View)3 StateComputer (com.radixdlt.ledger.StateComputerLedger.StateComputer)3 VerifiedTxnsAndProof (com.radixdlt.ledger.VerifiedTxnsAndProof)3 ImmutableClassToInstanceMap (com.google.common.collect.ImmutableClassToInstanceMap)2 Inject (com.google.inject.Inject)2