Search in sources :

Example 11 with TimestampedECDSASignatures

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

the class ProposalSerializeTest method get.

private static Proposal get() {
    View view = View.of(1234567891L);
    HashCode id = HashUtils.random256();
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    BFTHeader header = new BFTHeader(view, id, ledgerHeader);
    BFTHeader parent = new BFTHeader(View.of(1234567890L), HashUtils.random256(), ledgerHeader);
    VoteData voteData = new VoteData(header, parent, null);
    QuorumCertificate qc = new QuorumCertificate(voteData, new TimestampedECDSASignatures());
    var txn = Txn.create(new byte[] { 0, 1, 2, 3 });
    // add a particle to ensure atom is valid and has at least one shard
    BFTNode author = BFTNode.create(ECKeyPair.generateNew().getPublicKey());
    UnverifiedVertex vertex = UnverifiedVertex.create(qc, view, List.of(txn), author);
    return new Proposal(vertex, qc, ECDSASignature.zeroSignature(), Optional.empty());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) BFTHeader(com.radixdlt.hotstuff.BFTHeader) BFTNode(com.radixdlt.hotstuff.bft.BFTNode) HashCode(com.google.common.hash.HashCode) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) View(com.radixdlt.hotstuff.bft.View) VoteData(com.radixdlt.hotstuff.VoteData) UnverifiedVertex(com.radixdlt.hotstuff.UnverifiedVertex) Proposal(com.radixdlt.hotstuff.Proposal)

Example 12 with TimestampedECDSASignatures

use of com.radixdlt.hotstuff.TimestampedECDSASignatures 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 13 with TimestampedECDSASignatures

use of com.radixdlt.hotstuff.TimestampedECDSASignatures 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.hotstuff.TimestampedECDSASignatures) BFTHeader(com.radixdlt.hotstuff.BFTHeader) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate) Ledger(com.radixdlt.hotstuff.Ledger) AtomicReference(java.util.concurrent.atomic.AtomicReference) VoteData(com.radixdlt.hotstuff.VoteData) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) Before(org.junit.Before)

Example 14 with TimestampedECDSASignatures

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

the class StateComputerLedgerTest method should_do_nothing_if_committing_lower_state_version.

@Test
public void should_do_nothing_if_committing_lower_state_version() {
    // Arrange
    genesisIsEndOfEpoch(false);
    when(stateComputer.prepare(any(), any(), anyLong())).thenReturn(new StateComputerResult(ImmutableList.of(successfulNextCommand), ImmutableMap.of()));
    final AccumulatorState accumulatorState = new AccumulatorState(genesisStateVersion - 1, HashUtils.zero256());
    final LedgerHeader ledgerHeader = LedgerHeader.create(genesisEpoch, View.of(2), accumulatorState, 1234);
    final LedgerProof header = new LedgerProof(HashUtils.random256(), ledgerHeader, new TimestampedECDSASignatures());
    var verified = VerifiedTxnsAndProof.create(List.of(nextTxn), header);
    // Act
    sut.syncEventProcessor().process(verified);
    // Assert
    verify(stateComputer, never()).commit(any(), any());
    verify(mempool, never()).committed(any());
}
Also used : TimestampedECDSASignatures(com.radixdlt.hotstuff.TimestampedECDSASignatures) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) LedgerProof(com.radixdlt.hotstuff.LedgerProof) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) Test(org.junit.Test)

Example 15 with TimestampedECDSASignatures

use of com.radixdlt.hotstuff.TimestampedECDSASignatures 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)

Aggregations

TimestampedECDSASignatures (com.radixdlt.hotstuff.TimestampedECDSASignatures)18 QuorumCertificate (com.radixdlt.hotstuff.QuorumCertificate)9 VoteData (com.radixdlt.hotstuff.VoteData)9 Test (org.junit.Test)9 BFTHeader (com.radixdlt.hotstuff.BFTHeader)8 LedgerProof (com.radixdlt.hotstuff.LedgerProof)8 AccumulatorState (com.radixdlt.ledger.AccumulatorState)8 LedgerHeader (com.radixdlt.hotstuff.LedgerHeader)7 HashCode (com.google.common.hash.HashCode)3 View (com.radixdlt.hotstuff.bft.View)3 BFTNode (com.radixdlt.hotstuff.bft.BFTNode)2 Before (org.junit.Before)2 REEvent (com.radixdlt.constraintmachine.REEvent)1 EventDispatcher (com.radixdlt.environment.EventDispatcher)1 HighQC (com.radixdlt.hotstuff.HighQC)1 Ledger (com.radixdlt.hotstuff.Ledger)1 Proposal (com.radixdlt.hotstuff.Proposal)1 UnverifiedVertex (com.radixdlt.hotstuff.UnverifiedVertex)1 Vote (com.radixdlt.hotstuff.Vote)1 BFTValidatorSet (com.radixdlt.hotstuff.bft.BFTValidatorSet)1