Search in sources :

Example 6 with VoteData

use of com.radixdlt.consensus.VoteData in project radixdlt by radixdlt.

the class VertexStoreTest method setUp.

@Before
public void setUp() {
    // No type check issues with mocking generic here
    Ledger ssc = mock(Ledger.class);
    this.ledger = ssc;
    // TODO: replace mock with the real thing
    doAnswer(invocation -> {
        VerifiedVertex verifiedVertex = invocation.getArgument(1);
        return Optional.of(new PreparedVertex(verifiedVertex, MOCKED_HEADER, ImmutableList.of(), ImmutableMap.of(), 1L));
    }).when(ledger).prepare(any(), any());
    this.bftUpdateSender = rmock(EventDispatcher.class);
    this.rebuildUpdateEventDispatcher = rmock(EventDispatcher.class);
    this.bftHighQCUpdateEventDispatcher = rmock(EventDispatcher.class);
    this.committedSender = rmock(EventDispatcher.class);
    this.genesisHash = HashUtils.zero256();
    this.genesisVertex = new VerifiedVertex(UnverifiedVertex.createGenesis(MOCKED_HEADER), genesisHash);
    this.rootQC = QuorumCertificate.ofGenesis(genesisVertex, MOCKED_HEADER);
    this.sut = VertexStore.create(VerifiedVertexStoreState.create(HighQC.from(rootQC), genesisVertex, Optional.empty(), hasher), ledger, hasher, bftUpdateSender, rebuildUpdateEventDispatcher, bftHighQCUpdateEventDispatcher, committedSender);
    AtomicReference<BFTHeader> lastParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    AtomicReference<BFTHeader> lastGrandParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    AtomicReference<BFTHeader> lastGreatGrandParentHeader = new AtomicReference<>(new BFTHeader(View.genesis(), genesisHash, MOCKED_HEADER));
    this.nextSkippableVertex = (skipOne) -> {
        BFTHeader parentHeader = lastParentHeader.get();
        BFTHeader grandParentHeader = lastGrandParentHeader.get();
        BFTHeader greatGrandParentHeader = lastGreatGrandParentHeader.get();
        final QuorumCertificate qc;
        if (!parentHeader.getView().equals(View.genesis())) {
            VoteData data = new VoteData(parentHeader, grandParentHeader, skipOne ? null : greatGrandParentHeader);
            qc = new QuorumCertificate(data, new TimestampedECDSASignatures());
        } else {
            qc = rootQC;
        }
        View view = parentHeader.getView().next();
        if (skipOne) {
            view = view.next();
        }
        var rawVertex = UnverifiedVertex.create(qc, view, List.of(Txn.create(new byte[0])), BFTNode.random());
        HashCode hash = hasher.hash(rawVertex);
        VerifiedVertex vertex = new VerifiedVertex(rawVertex, hash);
        lastParentHeader.set(new BFTHeader(view, hash, MOCKED_HEADER));
        lastGrandParentHeader.set(parentHeader);
        lastGreatGrandParentHeader.set(grandParentHeader);
        return vertex;
    };
    this.nextVertex = () -> nextSkippableVertex.apply(false);
}
Also used : TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) BFTHeader(com.radixdlt.consensus.BFTHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) Ledger(com.radixdlt.consensus.Ledger) AtomicReference(java.util.concurrent.atomic.AtomicReference) VoteData(com.radixdlt.consensus.VoteData) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) Before(org.junit.Before)

Example 7 with VoteData

use of com.radixdlt.consensus.VoteData in project radixdlt by radixdlt.

the class VerifiedVertexStoreStateCreationTest method creating_vertex_store_with_qc_not_matching_vertex_should_fail.

@Test
public void creating_vertex_store_with_qc_not_matching_vertex_should_fail() {
    BFTHeader genesisHeader = new BFTHeader(View.of(0), HashUtils.random256(), mock(LedgerHeader.class));
    VoteData voteData = new VoteData(genesisHeader, genesisHeader, genesisHeader);
    QuorumCertificate badRootQC = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    assertThatThrownBy(() -> VerifiedVertexStoreState.create(HighQC.from(badRootQC), genesisVertex, Optional.empty(), hasher)).isInstanceOf(IllegalStateException.class);
}
Also used : TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) BFTHeader(com.radixdlt.consensus.BFTHeader) LedgerHeader(com.radixdlt.consensus.LedgerHeader) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) VoteData(com.radixdlt.consensus.VoteData) Test(org.junit.Test)

Aggregations

VoteData (com.radixdlt.consensus.VoteData)7 BFTHeader (com.radixdlt.consensus.BFTHeader)6 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)5 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)5 LedgerHeader (com.radixdlt.consensus.LedgerHeader)3 Test (org.junit.Test)3 HashCode (com.google.common.hash.HashCode)1 Ledger (com.radixdlt.consensus.Ledger)1 Vote (com.radixdlt.consensus.Vote)1 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)1 ECDSASignature (com.radixdlt.crypto.ECDSASignature)1 EventDispatcher (com.radixdlt.environment.EventDispatcher)1 AccumulatorState (com.radixdlt.ledger.AccumulatorState)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Before (org.junit.Before)1