use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class LedgerProofTest method testComparsionBetweenDifferentStateVersions.
@Test
public void testComparsionBetweenDifferentStateVersions() {
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);
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);
LedgerProof s1 = new LedgerProof(HashUtils.random256(), l1, mock(TimestampedECDSASignatures.class));
assertThat(headerComparator.compare(s0, s1)).isNegative();
assertThat(headerComparator.compare(s1, s0)).isPositive();
}
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();
}
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 setupGenesis.
private void setupGenesis() throws RadixEngineException {
var branch = radixEngine.transientBranch();
var processed = branch.execute(genesisTxns.getTxns(), PermissionLevel.SYSTEM);
var genesisValidatorSet = processed.getProcessedTxns().get(0).getEvents().stream().filter(REEvent.NextValidatorSetEvent.class::isInstance).map(REEvent.NextValidatorSetEvent.class::cast).findFirst().map(e -> BFTValidatorSet.from(e.nextValidators().stream().map(v -> BFTValidator.from(BFTNode.create(v.validatorKey()), v.amount())))).orElseThrow(() -> new IllegalStateException("No validator set in genesis."));
radixEngine.deleteBranches();
var genesisLedgerHeader = LedgerProof.genesis(new AccumulatorState(0, hasher.hash(genesisTxns.getTxns().get(0).getId())), genesisValidatorSet, 0);
if (!genesisLedgerHeader.isEndOfEpoch()) {
throw new IllegalStateException("Genesis must be end of epoch");
}
radixEngine.execute(genesisTxns.getTxns(), LedgerAndBFTProof.create(genesisLedgerHeader), PermissionLevel.SYSTEM);
}
use of com.radixdlt.ledger.AccumulatorState in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method committing_epoch_change_with_additional_cmds_should_fail.
// TODO: should catch this and log it somewhere as proof of byzantine quorum
@Test
public void committing_epoch_change_with_additional_cmds_should_fail() throws Exception {
// Arrange
var keyPair = ECKeyPair.generateNew();
var cmd0 = systemUpdateCommand(0, 2);
var cmd1 = registerCommand(keyPair);
var ledgerProof = new LedgerProof(HashUtils.random256(), LedgerHeader.create(0, View.of(9), new AccumulatorState(3, HashUtils.zero256()), 0), new TimestampedECDSASignatures());
var commandsAndProof = VerifiedTxnsAndProof.create(ImmutableList.of(cmd0, cmd1), ledgerProof);
// Act
// Assert
assertThatThrownBy(() -> sut.commit(commandsAndProof, null)).isInstanceOf(ByzantineQuorumException.class);
}
Aggregations