Search in sources :

Example 11 with AccumulatorState

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

the class BerkeleyLedgerEntryStoreTest method storeMetadataWithForks.

private void storeMetadataWithForks(long epoch, ImmutableSet<ForkVotingResult> forkVotingResults) throws RadixEngineException {
    final var fakeTx = mock(REProcessedTxn.class);
    final var txn = mock(Txn.class);
    when(txn.getId()).thenReturn(AID.from(HashUtils.random256().asBytes()));
    when(fakeTx.getTxn()).thenReturn(txn);
    when(fakeTx.getGroupedStateUpdates()).thenReturn(List.of());
    when(txn.getPayload()).thenReturn(HashUtils.random256().asBytes());
    final var proof1 = LedgerAndBFTProof.create(new LedgerProof(HashUtils.random256(), LedgerHeader.create(epoch, View.of(0L), new AccumulatorState(epoch, /* using same state version as epoch */
    HashCode.fromInt(1)), 0L), new TimestampedECDSASignatures(Map.of()))).withForksVotingResults(forkVotingResults);
    sut.transaction(tx -> {
        tx.storeTxn(fakeTx);
        tx.storeMetadata(proof1);
        return null;
    });
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LedgerProof(com.radixdlt.hotstuff.LedgerProof)

Example 12 with AccumulatorState

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

the class MockedRecoveryModule method configuration.

@Provides
private BFTConfiguration configuration(@LastEpochProof LedgerProof proof, BFTValidatorSet validatorSet, Hasher hasher) {
    var accumulatorState = new AccumulatorState(0, genesisHash);
    UnverifiedVertex genesis = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
    VerifiedVertex verifiedGenesis = new VerifiedVertex(genesis, genesisHash);
    LedgerHeader nextLedgerHeader = LedgerHeader.create(proof.getEpoch() + 1, View.genesis(), proof.getAccumulatorState(), proof.timestamp());
    var genesisQC = QuorumCertificate.ofGenesis(verifiedGenesis, nextLedgerHeader);
    var proposerElection = new WeightedRotatingLeaders(validatorSet);
    return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(genesisQC), verifiedGenesis, Optional.empty(), hasher));
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Provides(com.google.inject.Provides)

Example 13 with AccumulatorState

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

the class ConsensusModuleTest method createNextVertex.

private Pair<QuorumCertificate, VerifiedVertex> createNextVertex(QuorumCertificate parent, ECKeyPair proposerKeyPair, Txn txn) {
    final var proposerBftNode = BFTNode.create(proposerKeyPair.getPublicKey());
    var unverifiedVertex = UnverifiedVertex.create(parent, View.of(1), List.of(txn), proposerBftNode);
    var hash = hasher.hash(unverifiedVertex);
    var verifiedVertex = new VerifiedVertex(unverifiedVertex, hash);
    var next = new BFTHeader(View.of(1), verifiedVertex.getId(), LedgerHeader.create(1, View.of(1), new AccumulatorState(1, HashUtils.zero256()), 1));
    final var voteData = new VoteData(next, parent.getProposed(), parent.getParent());
    final var timestamp = 1;
    final var voteDataHash = Vote.getHashOfData(hasher, voteData, timestamp);
    final var qcSignature = proposerKeyPair.sign(voteDataHash);
    var unsyncedQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures(Map.of(proposerBftNode, TimestampedECDSASignature.from(timestamp, qcSignature))));
    return Pair.of(unsyncedQC, verifiedVertex);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) BFTHeader(com.radixdlt.hotstuff.BFTHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) VoteData(com.radixdlt.hotstuff.VoteData)

Example 14 with AccumulatorState

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

the class EpochManagerTest method getExternalModule.

private Module getExternalModule() {
    BFTNode self = BFTNode.create(ecKeyPair.getPublicKey());
    return new AbstractModule() {

        @Override
        protected void configure() {
            bind(HashSigner.class).toInstance(ecKeyPair::sign);
            bind(BFTNode.class).annotatedWith(Self.class).toInstance(self);
            bind(new TypeLiteral<EventDispatcher<LocalTimeoutOccurrence>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTInsertUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTRebuildUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTHighQCUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<BFTCommittedUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochLocalTimeoutOccurrence>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochView>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LocalSyncRequest>>() {
            }).toInstance(syncLedgerRequestSender);
            bind(new TypeLiteral<EventDispatcher<ViewQuorumReached>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<EpochViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<ViewUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<NoVote>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
            }).toInstance(rmock(EventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(timeoutScheduler);
            bind(new TypeLiteral<ScheduledEventDispatcher<ScheduledLocalTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<Epoched<ScheduledLocalTimeout>>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<ScheduledEventDispatcher<VertexRequestTimeout>>() {
            }).toInstance(rmock(ScheduledEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<Proposal>>() {
            }).toInstance(proposalDispatcher);
            bind(new TypeLiteral<RemoteEventDispatcher<Vote>>() {
            }).toInstance(voteDispatcher);
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesRequest>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesResponse>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<GetVerticesErrorResponse>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(new TypeLiteral<RemoteEventDispatcher<LedgerStatusUpdate>>() {
            }).toInstance(rmock(RemoteEventDispatcher.class));
            bind(PersistentSafetyStateStore.class).toInstance(mock(PersistentSafetyStateStore.class));
            bind(NextTxnsGenerator.class).toInstance(nextTxnsGenerator);
            bind(SystemCounters.class).toInstance(new SystemCountersImpl());
            bind(Mempool.class).toInstance(mempool);
            bind(StateComputer.class).toInstance(stateComputer);
            bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
            bind(RateLimiter.class).annotatedWith(GetVerticesRequestRateLimit.class).toInstance(RateLimiter.create(Double.MAX_VALUE));
            bindConstant().annotatedWith(BFTSyncPatienceMillis.class).to(50);
            bindConstant().annotatedWith(PacemakerTimeout.class).to(10L);
            bindConstant().annotatedWith(PacemakerRate.class).to(2.0);
            bindConstant().annotatedWith(PacemakerMaxExponent.class).to(0);
            bind(TimeSupplier.class).toInstance(System::currentTimeMillis);
            bind(new TypeLiteral<Consumer<EpochViewUpdate>>() {
            }).toInstance(rmock(Consumer.class));
        }

        @Provides
        private ViewUpdate view(BFTConfiguration bftConfiguration) {
            HighQC highQC = bftConfiguration.getVertexStoreState().getHighQC();
            View view = highQC.highestQC().getView().next();
            return ViewUpdate.create(view, highQC, self, self);
        }

        @Provides
        BFTValidatorSet validatorSet() {
            return BFTValidatorSet.from(Stream.of(BFTValidator.from(self, UInt256.ONE)));
        }

        @Provides
        @LastProof
        LedgerProof verifiedLedgerHeaderAndProof(BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            return LedgerProof.genesis(accumulatorState, validatorSet, 0);
        }

        @Provides
        @LastEpochProof
        LedgerProof lastEpochProof(BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            return LedgerProof.genesis(accumulatorState, validatorSet, 0);
        }

        @Provides
        BFTConfiguration bftConfiguration(@Self BFTNode self, Hasher hasher, BFTValidatorSet validatorSet) {
            var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
            var unverifiedVertex = UnverifiedVertex.createGenesis(LedgerHeader.genesis(accumulatorState, validatorSet, 0));
            var verifiedVertex = new VerifiedVertex(unverifiedVertex, hasher.hash(unverifiedVertex));
            var qc = QuorumCertificate.ofGenesis(verifiedVertex, LedgerHeader.genesis(accumulatorState, validatorSet, 0));
            var proposerElection = new WeightedRotatingLeaders(validatorSet);
            return new BFTConfiguration(proposerElection, validatorSet, VerifiedVertexStoreState.create(HighQC.from(qc), verifiedVertex, Optional.empty(), hasher));
        }
    };
}
Also used : HighQC(com.radixdlt.hotstuff.HighQC) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LocalSyncRequest(com.radixdlt.sync.messages.local.LocalSyncRequest) BFTCommittedUpdate(com.radixdlt.hotstuff.bft.BFTCommittedUpdate) VertexRequestTimeout(com.radixdlt.hotstuff.sync.VertexRequestTimeout) NextTxnsGenerator(com.radixdlt.hotstuff.liveness.NextTxnsGenerator) BFTInsertUpdate(com.radixdlt.hotstuff.bft.BFTInsertUpdate) PacemakerMaxExponent(com.radixdlt.hotstuff.bft.PacemakerMaxExponent) ViewUpdate(com.radixdlt.hotstuff.bft.ViewUpdate) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) Consumer(java.util.function.Consumer) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) Mempool(com.radixdlt.mempool.Mempool) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) Vote(com.radixdlt.hotstuff.Vote) NoVote(com.radixdlt.hotstuff.bft.NoVote) GetVerticesResponse(com.radixdlt.hotstuff.sync.GetVerticesResponse) HashSigner(com.radixdlt.hotstuff.HashSigner) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) Hasher(com.radixdlt.crypto.Hasher) NoVote(com.radixdlt.hotstuff.bft.NoVote) Proposal(com.radixdlt.hotstuff.Proposal) LedgerStatusUpdate(com.radixdlt.sync.messages.remote.LedgerStatusUpdate) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) GetVerticesRequest(com.radixdlt.hotstuff.sync.GetVerticesRequest) EpochLocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.EpochLocalTimeoutOccurrence) LocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.LocalTimeoutOccurrence) Self(com.radixdlt.hotstuff.bft.Self) TimeSupplier(com.radixdlt.utils.TimeSupplier) PersistentVertexStore(com.radixdlt.hotstuff.bft.PersistentVertexStore) EpochLocalTimeoutOccurrence(com.radixdlt.hotstuff.liveness.EpochLocalTimeoutOccurrence) PacemakerRate(com.radixdlt.hotstuff.bft.PacemakerRate) RemoteEventDispatcher(com.radixdlt.environment.RemoteEventDispatcher) ScheduledEventDispatcher(com.radixdlt.environment.ScheduledEventDispatcher) EventDispatcher(com.radixdlt.environment.EventDispatcher) TypeLiteral(com.google.inject.TypeLiteral) BFTSyncPatienceMillis(com.radixdlt.hotstuff.sync.BFTSyncPatienceMillis) BFTRebuildUpdate(com.radixdlt.hotstuff.bft.BFTRebuildUpdate) GetVerticesErrorResponse(com.radixdlt.hotstuff.sync.GetVerticesErrorResponse) SystemCounters(com.radixdlt.counters.SystemCounters) PacemakerTimeout(com.radixdlt.hotstuff.bft.PacemakerTimeout) BFTValidatorSet(com.radixdlt.hotstuff.bft.BFTValidatorSet) View(com.radixdlt.hotstuff.bft.View) AbstractModule(com.google.inject.AbstractModule) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) ViewQuorumReached(com.radixdlt.hotstuff.bft.ViewQuorumReached) ScheduledLocalTimeout(com.radixdlt.hotstuff.liveness.ScheduledLocalTimeout) BFTHighQCUpdate(com.radixdlt.hotstuff.bft.BFTHighQCUpdate) GetVerticesRequestRateLimit(com.radixdlt.middleware2.network.GetVerticesRequestRateLimit) PersistentSafetyStateStore(com.radixdlt.hotstuff.safety.PersistentSafetyStateStore)

Example 15 with AccumulatorState

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

the class MempoolTest method replay_command_to_mempool.

@Test
public void replay_command_to_mempool() throws Exception {
    // Arrange
    getInjector().injectMembers(this);
    ECKeyPair keyPair = ECKeyPair.generateNew();
    var txn = createTxn(keyPair);
    var proof = mock(LedgerProof.class);
    when(proof.getAccumulatorState()).thenReturn(new AccumulatorState(genesisTxns.getTxns().size() + 1, HashUtils.random256()));
    when(proof.getStateVersion()).thenReturn((long) genesisTxns.getTxns().size() + 1);
    when(proof.getView()).thenReturn(View.of(1));
    var commandsAndProof = VerifiedTxnsAndProof.create(List.of(txn), proof);
    stateComputer.commit(commandsAndProof, null);
    // Act
    MempoolAdd mempoolAdd = MempoolAdd.create(txn);
    processor.handleMessage(getFirstPeer(), mempoolAdd, null);
    // Assert
    assertThat(systemCounters.get(CounterType.MEMPOOL_CURRENT_SIZE)).isZero();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Test(org.junit.Test)

Aggregations

AccumulatorState (com.radixdlt.ledger.AccumulatorState)33 Test (org.junit.Test)19 LedgerProof (com.radixdlt.hotstuff.LedgerProof)10 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)9 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)7 ECKeyPair (com.radixdlt.crypto.ECKeyPair)6 RemoteEventDispatcher (com.radixdlt.environment.RemoteEventDispatcher)6 AbstractModule (com.google.inject.AbstractModule)5 TypeLiteral (com.google.inject.TypeLiteral)5 SystemCounters (com.radixdlt.counters.SystemCounters)5 SystemCountersImpl (com.radixdlt.counters.SystemCountersImpl)5 Hasher (com.radixdlt.crypto.Hasher)5 EventDispatcher (com.radixdlt.environment.EventDispatcher)5 WeightedRotatingLeaders (com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)5 LedgerUpdate (com.radixdlt.ledger.LedgerUpdate)5 Before (org.junit.Before)5 Inject (com.google.inject.Inject)4 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)4 ScheduledEventDispatcher (com.radixdlt.environment.ScheduledEventDispatcher)4 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)4