Search in sources :

Example 16 with AccumulatorState

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

the class GetVerticesErrorResponseMessageSerializeTest method get.

private static GetVerticesErrorResponseMessage get() {
    var accumulatorState = new AccumulatorState(0, HashUtils.zero256());
    LedgerHeader ledgerHeader = LedgerHeaderMock.get();
    VerifiedVertex verifiedVertex = new VerifiedVertex(UnverifiedVertex.createGenesis(ledgerHeader), HashUtils.zero256());
    QuorumCertificate qc = QuorumCertificate.ofGenesis(verifiedVertex, ledgerHeader);
    HighQC highQC = HighQC.from(qc, qc, Optional.empty());
    final var request = new GetVerticesRequestMessage(HashUtils.random256(), 3);
    return new GetVerticesErrorResponseMessage(highQC, request);
}
Also used : VerifiedVertex(com.radixdlt.hotstuff.bft.VerifiedVertex) HighQC(com.radixdlt.hotstuff.HighQC) LedgerHeader(com.radixdlt.hotstuff.LedgerHeader) AccumulatorState(com.radixdlt.ledger.AccumulatorState) QuorumCertificate(com.radixdlt.hotstuff.QuorumCertificate)

Example 17 with AccumulatorState

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

the class BerkeleyRecoverableProcessedTxnStore method open.

@Override
public void open(DatabaseEnvironment dbEnv) {
    recoverableTransactionsDatabase = dbEnv.getEnvironment().openDatabase(null, RECOVERABLE_TRANSACTIONS_DB_NAME, new DatabaseConfig().setAllowCreate(true).setTransactional(true).setKeyPrefixing(true).setBtreeComparator(lexicographicalComparator()));
    accumulatorDatabase = dbEnv.getEnvironment().openDatabase(null, ACCUMULATOR_HASH_DB_NAME, new DatabaseConfig().setAllowCreate(true).setTransactional(true).setKeyPrefixing(true).setBtreeComparator(lexicographicalComparator()));
    try (var cursor = accumulatorDatabase.openCursor(null, null)) {
        var key = new DatabaseEntry(Longs.toByteArray(Long.MAX_VALUE));
        var value = new DatabaseEntry();
        cursor.getSearchKeyRange(key, value, null);
        var status = cursor.getPrev(key, value, null);
        if (status == SUCCESS) {
            var accumulatorHash = HashCode.fromBytes(value.getData());
            var stateVersion = Longs.fromByteArray(key.getData());
            this.accumulatorState = new AccumulatorState(stateVersion, accumulatorHash);
        } else {
            this.accumulatorState = new AccumulatorState(0, HashUtils.zero256());
        }
    }
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 18 with AccumulatorState

use of com.radixdlt.ledger.AccumulatorState 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 19 with AccumulatorState

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

the class LedgerProofTest method testGetters.

@Test
public void testGetters() {
    LedgerHeader l0 = mock(LedgerHeader.class);
    HashCode accumulatorHash = mock(HashCode.class);
    View view = mock(View.class);
    when(l0.getEpoch()).thenReturn(3L);
    AccumulatorState accumulatorState = mock(AccumulatorState.class);
    when(accumulatorState.getAccumulatorHash()).thenReturn(accumulatorHash);
    when(accumulatorState.getStateVersion()).thenReturn(12345L);
    when(l0.getAccumulatorState()).thenReturn(accumulatorState);
    when(l0.getView()).thenReturn(view);
    when(l0.timestamp()).thenReturn(2468L);
    when(l0.isEndOfEpoch()).thenReturn(true);
    var ledgerHeaderAndProof = new LedgerProof(HashUtils.random256(), l0, mock(TimestampedECDSASignatures.class));
    assertThat(ledgerHeaderAndProof.getEpoch()).isEqualTo(3L);
    assertThat(ledgerHeaderAndProof.getStateVersion()).isEqualTo(12345L);
    assertThat(ledgerHeaderAndProof.getView()).isEqualTo(view);
    assertThat(ledgerHeaderAndProof.timestamp()).isEqualTo(2468L);
    assertThat(ledgerHeaderAndProof.isEndOfEpoch()).isTrue();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) HashCode(com.google.common.hash.HashCode) View(com.radixdlt.hotstuff.bft.View) Test(org.junit.Test)

Example 20 with AccumulatorState

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

the class LedgerProofTest method testComparsionWithEndOfEpoch.

@Test
public void testComparsionWithEndOfEpoch() {
    LedgerHeader l0 = mock(LedgerHeader.class);
    when(l0.getEpoch()).thenReturn(2L);
    AccumulatorState accumulatorState = mock(AccumulatorState.class);
    when(accumulatorState.getStateVersion()).thenReturn(2L);
    when(l0.getAccumulatorState()).thenReturn(accumulatorState);
    when(l0.isEndOfEpoch()).thenReturn(false);
    LedgerProof s0 = new LedgerProof(HashUtils.random256(), l0, mock(TimestampedECDSASignatures.class));
    LedgerHeader l1 = mock(LedgerHeader.class);
    when(l1.getEpoch()).thenReturn(2L);
    AccumulatorState accumulatorState1 = mock(AccumulatorState.class);
    when(accumulatorState1.getStateVersion()).thenReturn(3L);
    when(l1.getAccumulatorState()).thenReturn(accumulatorState1);
    when(l1.isEndOfEpoch()).thenReturn(true);
    LedgerProof s1 = new LedgerProof(HashUtils.random256(), l1, mock(TimestampedECDSASignatures.class));
    assertThat(headerComparator.compare(s0, s1)).isNegative();
    assertThat(headerComparator.compare(s1, s0)).isPositive();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) 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