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);
}
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());
}
}
}
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);
}
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();
}
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();
}
Aggregations