Search in sources :

Example 1 with VerifiedTxnsAndProof

use of com.radixdlt.ledger.VerifiedTxnsAndProof 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.hotstuff.bft.VerifiedVertex) LedgerProof(com.radixdlt.hotstuff.LedgerProof) Inject(com.google.inject.Inject) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders) Hasher(com.radixdlt.crypto.Hasher) HighQC(com.radixdlt.hotstuff.HighQC) VerifiedVertexStoreState(com.radixdlt.hotstuff.bft.VerifiedVertexStoreState) MempoolAdd(com.radixdlt.mempool.MempoolAdd) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) View(com.radixdlt.hotstuff.bft.View) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) Map(java.util.Map) MockPrepared(com.radixdlt.ledger.MockPrepared) Nullable(javax.annotation.Nullable) EventDispatcher(com.radixdlt.environment.EventDispatcher) Txn(com.radixdlt.atom.Txn) VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) StateComputer(com.radixdlt.ledger.StateComputerLedger.StateComputer) EpochChange(com.radixdlt.hotstuff.epoch.EpochChange) Collectors(java.util.stream.Collectors) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) StateComputerLedger(com.radixdlt.ledger.StateComputerLedger) List(java.util.List) Optional(java.util.Optional) ImmutableClassToInstanceMap(com.google.common.collect.ImmutableClassToInstanceMap) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) EpochChange(com.radixdlt.hotstuff.epoch.EpochChange) BFTConfiguration(com.radixdlt.hotstuff.BFTConfiguration) LedgerProof(com.radixdlt.hotstuff.LedgerProof) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) WeightedRotatingLeaders(com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)

Example 2 with VerifiedTxnsAndProof

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

the class RemoteSyncServiceTest method when_remote_sync_request__then_process_it.

@Test
public void when_remote_sync_request__then_process_it() {
    SyncRequest request = mock(SyncRequest.class);
    DtoLedgerProof header = mock(DtoLedgerProof.class);
    when(header.getOpaque()).thenReturn(HashUtils.zero256());
    when(header.getLedgerHeader()).thenReturn(mock(LedgerHeader.class));
    when(header.getSignatures()).thenReturn(mock(TimestampedECDSASignatures.class));
    when(request.getHeader()).thenReturn(header);
    BFTNode node = mock(BFTNode.class);
    VerifiedTxnsAndProof verifiedTxnsAndProof = mock(VerifiedTxnsAndProof.class);
    LedgerProof verifiedHeader = mock(LedgerProof.class);
    when(verifiedHeader.toDto()).thenReturn(header);
    when(verifiedTxnsAndProof.getProof()).thenReturn(verifiedHeader);
    when(reader.getNextCommittedTxns(any())).thenReturn(verifiedTxnsAndProof);
    processor.syncRequestEventProcessor().process(node, SyncRequest.create(header));
    verify(syncResponseDispatcher, times(1)).dispatch(eq(node), any());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) SyncRequest(com.radixdlt.sync.messages.remote.SyncRequest) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.hotstuff.LedgerProof) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) Test(org.junit.Test)

Aggregations

LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)2 LedgerProof (com.radixdlt.hotstuff.LedgerProof)2 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)2 VerifiedTxnsAndProof (com.radixdlt.ledger.VerifiedTxnsAndProof)2 ImmutableClassToInstanceMap (com.google.common.collect.ImmutableClassToInstanceMap)1 Inject (com.google.inject.Inject)1 Txn (com.radixdlt.atom.Txn)1 Hasher (com.radixdlt.crypto.Hasher)1 EventDispatcher (com.radixdlt.environment.EventDispatcher)1 BFTConfiguration (com.radixdlt.hotstuff.BFTConfiguration)1 HighQC (com.radixdlt.hotstuff.HighQC)1 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)1 TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)1 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)1 VerifiedVertex (com.radixdlt.hotstuff.bft.VerifiedVertex)1 VerifiedVertexStoreState (com.radixdlt.hotstuff.bft.VerifiedVertexStoreState)1 View (com.radixdlt.hotstuff.bft.View)1 EpochChange (com.radixdlt.hotstuff.epoch.EpochChange)1 WeightedRotatingLeaders (com.radixdlt.hotstuff.liveness.WeightedRotatingLeaders)1 DtoLedgerProof (com.radixdlt.ledger.DtoLedgerProof)1