Search in sources :

Example 1 with AccumulatorState

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();
}
Also used : AccumulatorState(com.radixdlt.ledger.AccumulatorState) Test(org.junit.Test)

Example 2 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)

Example 3 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 4 with AccumulatorState

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);
}
Also used : Module(com.google.inject.Module) RERules(com.radixdlt.statecomputer.forks.RERules) SimpleLedgerAccumulatorAndVerifier(com.radixdlt.ledger.SimpleLedgerAccumulatorAndVerifier) TxAction(com.radixdlt.atom.TxAction) RadixEngineException(com.radixdlt.engine.RadixEngineException) RadixEngineForksLatestOnlyModule(com.radixdlt.statecomputer.forks.RadixEngineForksLatestOnlyModule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Inject(com.google.inject.Inject) TypedMocks(com.radixdlt.utils.TypedMocks) DefaultSerialization(com.radixdlt.DefaultSerialization) Hasher(com.radixdlt.crypto.Hasher) TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) RoundData(com.radixdlt.application.system.state.RoundData) UnverifiedVertex(com.radixdlt.consensus.UnverifiedVertex) ByzantineQuorumException(com.radixdlt.ledger.ByzantineQuorumException) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) LedgerProof(com.radixdlt.consensus.LedgerProof) View(com.radixdlt.consensus.bft.View) HashUtils(com.radixdlt.crypto.HashUtils) Genesis(com.radixdlt.statecomputer.checkpoint.Genesis) SystemCounters(com.radixdlt.counters.SystemCounters) WeightedRotatingLeaders(com.radixdlt.consensus.liveness.WeightedRotatingLeaders) Sha256Hasher(com.radixdlt.consensus.Sha256Hasher) REEvent(com.radixdlt.constraintmachine.REEvent) StateComputerResult(com.radixdlt.ledger.StateComputerLedger.StateComputerResult) EngineStore(com.radixdlt.store.EngineStore) Collectors(java.util.stream.Collectors) LedgerHeader(com.radixdlt.consensus.LedgerHeader) ProposerElection(com.radixdlt.consensus.liveness.ProposerElection) SystemCountersImpl(com.radixdlt.counters.SystemCountersImpl) List(java.util.List) Stream(java.util.stream.Stream) ConstraintMachineException(com.radixdlt.constraintmachine.exceptions.ConstraintMachineException) CommittedReader(com.radixdlt.sync.CommittedReader) Amount(com.radixdlt.application.tokens.Amount) MainnetForkConfigsModule(com.radixdlt.statecomputer.forks.MainnetForkConfigsModule) TypeLiteral(com.google.inject.TypeLiteral) LedgerAccumulator(com.radixdlt.ledger.LedgerAccumulator) Mockito.mock(org.mockito.Mockito.mock) Serialization(com.radixdlt.serialization.Serialization) PermissionLevel(com.radixdlt.constraintmachine.PermissionLevel) BFTValidatorSet(com.radixdlt.consensus.bft.BFTValidatorSet) com.radixdlt.atom(com.radixdlt.atom) MockedGenesisModule(com.radixdlt.statecomputer.checkpoint.MockedGenesisModule) BFTValidator(com.radixdlt.consensus.bft.BFTValidator) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) MempoolConfig(com.radixdlt.mempool.MempoolConfig) AccumulatorState(com.radixdlt.ledger.AccumulatorState) RadixEngineCheckpointModule(com.radixdlt.statecomputer.checkpoint.RadixEngineCheckpointModule) UInt256(com.radixdlt.utils.UInt256) Before(org.junit.Before) MempoolAddSuccess(com.radixdlt.mempool.MempoolAddSuccess) EventDispatcher(com.radixdlt.environment.EventDispatcher) HashCode(com.google.common.hash.HashCode) RadixEngine(com.radixdlt.engine.RadixEngine) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MempoolRelayTrigger(com.radixdlt.mempool.MempoolRelayTrigger) QuorumCertificate(com.radixdlt.consensus.QuorumCertificate) ForksModule(com.radixdlt.statecomputer.forks.ForksModule) LedgerUpdate(com.radixdlt.ledger.LedgerUpdate) BFTHeader(com.radixdlt.consensus.BFTHeader) InMemoryEngineStore(com.radixdlt.store.InMemoryEngineStore) VerifiedVertex(com.radixdlt.consensus.bft.VerifiedVertex) ECKeyPair(com.radixdlt.crypto.ECKeyPair) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Condition(org.assertj.core.api.Condition) Guice(com.google.inject.Guice) BFTNode(com.radixdlt.consensus.bft.BFTNode) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) InvalidPermissionException(com.radixdlt.constraintmachine.exceptions.InvalidPermissionException) TemporaryFolder(org.junit.rules.TemporaryFolder) AbstractModule(com.google.inject.AbstractModule) AccumulatorState(com.radixdlt.ledger.AccumulatorState) REEvent(com.radixdlt.constraintmachine.REEvent)

Example 5 with AccumulatorState

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);
}
Also used : TimestampedECDSASignatures(com.radixdlt.consensus.TimestampedECDSASignatures) AccumulatorState(com.radixdlt.ledger.AccumulatorState) LedgerProof(com.radixdlt.consensus.LedgerProof) Test(org.junit.Test)

Aggregations

AccumulatorState (com.radixdlt.ledger.AccumulatorState)23 Test (org.junit.Test)14 LedgerProof (com.radixdlt.consensus.LedgerProof)8 TimestampedECDSASignatures (com.radixdlt.consensus.TimestampedECDSASignatures)7 VerifiedVertex (com.radixdlt.consensus.bft.VerifiedVertex)7 ECKeyPair (com.radixdlt.crypto.ECKeyPair)5 BFTConfiguration (com.radixdlt.consensus.BFTConfiguration)4 LedgerHeader (com.radixdlt.consensus.LedgerHeader)4 QuorumCertificate (com.radixdlt.consensus.QuorumCertificate)4 View (com.radixdlt.consensus.bft.View)4 WeightedRotatingLeaders (com.radixdlt.consensus.liveness.WeightedRotatingLeaders)4 AbstractModule (com.google.inject.AbstractModule)3 Inject (com.google.inject.Inject)3 TypeLiteral (com.google.inject.TypeLiteral)3 HighQC (com.radixdlt.consensus.HighQC)3 UnverifiedVertex (com.radixdlt.consensus.UnverifiedVertex)3 BFTNode (com.radixdlt.consensus.bft.BFTNode)3 BFTValidatorSet (com.radixdlt.consensus.bft.BFTValidatorSet)3 Before (org.junit.Before)3 Guice (com.google.inject.Guice)2