Search in sources :

Example 1 with SystemCounters

use of com.radixdlt.counters.SystemCounters in project radixdlt by radixdlt.

the class OneProposalTimeoutResponsiveTest method run.

private void run(int numNodes, long numViews, long dropPeriod) {
    DeterministicTest test = DeterministicTest.builder().numNodes(numNodes).messageSelector(MessageSelector.randomSelector(random)).messageMutator(dropSomeProposals(dropPeriod)).buildWithoutEpochs().runUntil(DeterministicTest.hasReachedView(View.of(numViews)));
    long requiredIndirectParents = numNodes <= 3 ? // there are no indirect parents for 3 nodes (QC is always formed)
    0 : // Edge case if dropPeriod a factor of numViews
    (numViews - 1) / dropPeriod;
    long requiredTimeouts = numViews / dropPeriod * 2;
    long timeoutQuorums = numNodes <= 3 ? // no timeout quorums for 3 nodes
    0 : // otherwise, every 2nd timeout forms a TC
    requiredTimeouts / 2;
    for (int nodeIndex = 0; nodeIndex < numNodes; ++nodeIndex) {
        SystemCounters counters = test.getSystemCounters(nodeIndex);
        long numberOfIndirectParents = counters.get(CounterType.BFT_VERTEX_STORE_INDIRECT_PARENTS);
        long totalNumberOfTimeouts = counters.get(CounterType.BFT_PACEMAKER_TIMEOUTS_SENT);
        long totalNumberOfTimeoutQuorums = counters.get(CounterType.BFT_TIMEOUT_QUORUMS);
        assertThat(numberOfIndirectParents).isEqualTo(requiredIndirectParents);
        assertThat(totalNumberOfTimeouts).isEqualTo(requiredTimeouts);
        assertThat(totalNumberOfTimeoutQuorums).isBetween(timeoutQuorums - 1, timeoutQuorums);
    }
}
Also used : DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) SystemCounters(com.radixdlt.counters.SystemCounters)

Example 2 with SystemCounters

use of com.radixdlt.counters.SystemCounters in project radixdlt by radixdlt.

the class QuorumWithoutALeaderWithTimeoutsTest method run.

private void run(int numNodes, long numViews) {
    final DeterministicTest test = DeterministicTest.builder().numNodes(numNodes).messageSelector(MessageSelector.randomSelector(random)).messageMutator(dropAllNonTimeoutVotes()).buildWithoutEpochs().runUntil(DeterministicTest.hasReachedView(View.of(numViews)));
    for (int nodeIndex = 0; nodeIndex < numNodes; ++nodeIndex) {
        final SystemCounters counters = test.getSystemCounters(nodeIndex);
        final long numberOfIndirectParents = counters.get(CounterType.BFT_VERTEX_STORE_INDIRECT_PARENTS);
        final long totalNumberOfTimeouts = counters.get(CounterType.BFT_PACEMAKER_TIMEOUTS_SENT);
        final long totalNumberOfTimeoutQuorums = counters.get(CounterType.BFT_TIMEOUT_QUORUMS);
        final long totalNumberOfVoteQuorums = counters.get(CounterType.BFT_VOTE_QUORUMS);
        // no TCs
        assertThat(totalNumberOfTimeoutQuorums).isEqualTo(0);
        // no indirect parents
        assertThat(numberOfIndirectParents).isEqualTo(0);
        // a timeout for each view
        assertThat(totalNumberOfTimeouts).isEqualTo(numViews - 1);
        assertThat(totalNumberOfVoteQuorums).isBetween(numViews - 2, // quorum count matches views
        numViews);
    }
}
Also used : DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) SystemCounters(com.radixdlt.counters.SystemCounters)

Example 3 with SystemCounters

use of com.radixdlt.counters.SystemCounters in project radixdlt by radixdlt.

the class MovingWindowValidatorsTest method run.

private void run(int numNodes, int windowSize, long maxEpoch, View highView) {
    DeterministicTest bftTest = DeterministicTest.builder().numNodes(numNodes).messageMutator(mutator()).messageSelector(firstSelector()).epochNodeIndexesMapping(windowedEpochToNodesMapper(windowSize, numNodes)).buildWithEpochs(highView).runUntil(DeterministicTest.hasReachedEpochView(EpochView.of(maxEpoch, highView)));
    LinkedList<SystemCounters> testCounters = systemCounters(bftTest);
    assertThat(testCounters).extracting(sc -> sc.get(CounterType.BFT_VERTEX_STORE_INDIRECT_PARENTS)).containsOnly(0L);
    assertThat(testCounters).extracting(sc -> sc.get(CounterType.BFT_PACEMAKER_TIMEOUTS_SENT)).containsOnly(0L);
    long maxCount = maxProcessedFor(numNodes, windowSize, maxEpoch, highView.number());
    assertThat(testCounters).extracting(sc -> sc.get(CounterType.BFT_COMMITTED_VERTICES)).allMatch(between(maxCount - maxEpoch, maxCount));
}
Also used : IntStream(java.util.stream.IntStream) ControlledMessage(com.radixdlt.environment.deterministic.network.ControlledMessage) ScheduledLocalTimeout(com.radixdlt.consensus.liveness.ScheduledLocalTimeout) SystemCounters(com.radixdlt.counters.SystemCounters) Epoched(com.radixdlt.consensus.epoch.Epoched) LongFunction(java.util.function.LongFunction) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Collectors(java.util.stream.Collectors) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) EpochView(com.radixdlt.consensus.epoch.EpochView) MessageSelector(com.radixdlt.environment.deterministic.network.MessageSelector) MessageMutator(com.radixdlt.environment.deterministic.network.MessageMutator) ChannelId(com.radixdlt.environment.deterministic.network.ChannelId) LinkedList(java.util.LinkedList) CounterType(com.radixdlt.counters.SystemCounters.CounterType) View(com.radixdlt.consensus.bft.View) DeterministicTest(com.radixdlt.harness.deterministic.DeterministicTest) SystemCounters(com.radixdlt.counters.SystemCounters)

Example 4 with SystemCounters

use of com.radixdlt.counters.SystemCounters in project radixdlt by radixdlt.

the class BerkeleyLedgerEntryStore method open.

private void open() {
    var primaryConfig = buildPrimaryConfig();
    var rriConfig = buildRriConfig();
    var pendingConfig = buildPendingConfig();
    try {
        // This SuppressWarnings here is valid, as ownership of the underlying
        // resource is not changed here, the resource is just accessed.
        @SuppressWarnings("resource") var env = dbEnv.getEnvironment();
        txnDatabase = env.openDatabase(null, TXN_DB_NAME, primaryConfig);
        resourceDatabase = env.openDatabase(null, RESOURCE_DB_NAME, rriConfig);
        mapDatabase = env.openDatabase(null, MAP_DB_NAME, rriConfig);
        substatesDatabase = env.openDatabase(null, SUBSTATE_DB_NAME, primaryConfig);
        indexedSubstatesDatabase = env.openSecondaryDatabase(null, INDEXED_SUBSTATE_DB_NAME, substatesDatabase, (SecondaryConfig) new SecondaryConfig().setKeyCreator((secondary, key, data, result) -> {
            if (entryToSpin(data) != REOp.UP) {
                return false;
            }
            var substateTypeId = data.getData()[data.getOffset()];
            final int prefixIndexSize;
            if (substateTypeId == SubstateTypeId.TOKENS.id()) {
                // Indexing not necessary for verification at the moment but useful
                // for construction
                // 0: Type Byte
                // 1: Reserved Byte
                // 2-37: Account Address
                prefixIndexSize = 2 + (1 + ECPublicKey.COMPRESSED_BYTES);
            } else if (substateTypeId == SubstateTypeId.STAKE_OWNERSHIP.id()) {
                // Indexing not necessary for verification at the moment but useful
                // for construction
                // This should have had validator keys and account addresses switched
                // so that
                // prefix indexing could be done against account addresses rather than
                // validators
                // so that actions like "Unstake Everything" could be implemented and
                // queries against
                // accounts. A later to do...
                // 0: Type Byte
                // 1: Reserved Byte
                // 2-36: Validator Key
                // 37-69: Account Address
                prefixIndexSize = 2 + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
            } else if (substateTypeId == SubstateTypeId.EXITING_STAKE.id()) {
                // 0: Type Byte
                // 1: Reserved Byte
                // 2-5: Epoch
                // 6-40: Validator Key
                // 41-73: Account Address
                prefixIndexSize = 2 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
            } else if (substateTypeId == SubstateTypeId.PREPARED_STAKE.id()) {
                // 0: Type Byte
                // 1: Reserved Byte
                // 2-36: Validator Key
                // 37-69: Account Address
                prefixIndexSize = 2 + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
            } else if (substateTypeId == SubstateTypeId.PREPARED_UNSTAKE.id()) {
                // 0: Type Byte
                // 1: Reserved Byte
                // 2-36: Validator Key
                // 37-69: Account Address
                prefixIndexSize = 2 + ECPublicKey.COMPRESSED_BYTES + (1 + ECPublicKey.COMPRESSED_BYTES);
            } else if (substateTypeId == SubstateTypeId.VALIDATOR_OWNER_COPY.id()) {
                // 0: Type Byte
                // 1: Reserved Byte
                // 2: Optional flag
                // 3-6: Epoch
                // 7-41: Validator Key
                prefixIndexSize = 3 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES;
            } else if (substateTypeId == SubstateTypeId.VALIDATOR_REGISTERED_FLAG_COPY.id()) {
                // 0: Type Byte
                // 1: Reserved Byte
                // 2: Optional flag
                // 3-6: Epoch
                // 7-41: Validator Key
                prefixIndexSize = 3 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES;
            } else if (substateTypeId == SubstateTypeId.VALIDATOR_RAKE_COPY.id()) {
                // 0: Type Byte
                // 1: Reserved Byte
                // 2: Optional flag
                // 3-6: Epoch
                // 7-41: Validator Key
                prefixIndexSize = 3 + Long.BYTES + ECPublicKey.COMPRESSED_BYTES;
            } else if (substateTypeId == SubstateTypeId.VALIDATOR_STAKE_DATA.id()) {
                // 0: Type Byte
                // 1: Reserved Byte
                // 2: Registered Byte
                // 3-34: Stake amount
                // 35-67: Validator key
                prefixIndexSize = 3 + UInt256.BYTES + ECPublicKey.COMPRESSED_BYTES;
            } else {
                // 0: Type Byte
                prefixIndexSize = 1;
            }
            // Index by substate type
            result.setData(data.getData(), data.getOffset(), prefixIndexSize);
            return true;
        }).setBtreeComparator(lexicographicalComparator()).setSortedDuplicates(true).setAllowCreate(true).setTransactional(true));
        proofDatabase = env.openDatabase(null, PROOF_DB_NAME, primaryConfig);
        vertexStoreDatabase = env.openDatabase(null, VERTEX_STORE_DB_NAME, pendingConfig);
        epochProofDatabase = env.openSecondaryDatabase(null, EPOCH_PROOF_DB_NAME, proofDatabase, buildEpochProofConfig());
        txnLog = AppendLog.openCompressed(new File(env.getHome(), LEDGER_NAME).getAbsolutePath(), systemCounters);
    } catch (Exception e) {
        throw new BerkeleyStoreException("Error while opening databases", e);
    }
    this.additionalStores.forEach(b -> b.open(dbEnv));
    if (System.getProperty("db.check_integrity", "1").equals("1")) {
    // TODO implement integrity check
    // TODO perhaps we should implement recovery instead?
    // TODO recovering should be integrated with recovering of ClientApiStore
    }
}
Also used : AppendLog(com.radixdlt.store.berkeley.atom.AppendLog) Arrays(java.util.Arrays) RadixEngineException(com.radixdlt.engine.RadixEngineException) LedgerAndBFTProof(com.radixdlt.statecomputer.LedgerAndBFTProof) Inject(com.google.inject.Inject) ByteBuffer(java.nio.ByteBuffer) DEFAULT(com.sleepycat.je.LockMode.DEFAULT) VerifiedTxnsAndProof(com.radixdlt.ledger.VerifiedTxnsAndProof) BigInteger(java.math.BigInteger) LedgerProof(com.radixdlt.consensus.LedgerProof) SystemMapKey(com.radixdlt.constraintmachine.SystemMapKey) Get(com.sleepycat.je.Get) SystemCounters(com.radixdlt.counters.SystemCounters) DatabaseEnvironment(com.radixdlt.store.DatabaseEnvironment) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Set(java.util.Set) Output(com.radixdlt.serialization.DsonOutput.Output) ResourceStore(com.radixdlt.store.ResourceStore) REAddr(com.radixdlt.identifiers.REAddr) Streams(com.google.common.collect.Streams) EngineStore(com.radixdlt.store.EngineStore) Objects(java.util.Objects) VirtualSubstateAlreadyDownException(com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException) List(java.util.List) DatabaseConfig(com.sleepycat.je.DatabaseConfig) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) VirtualParentStateDoesNotExist(com.radixdlt.constraintmachine.exceptions.VirtualParentStateDoesNotExist) StoreConfig(com.radixdlt.store.StoreConfig) CommittedReader(com.radixdlt.sync.CommittedReader) ResourceData(com.radixdlt.application.tokens.state.ResourceData) Optional(java.util.Optional) SystemData(com.radixdlt.application.system.state.SystemData) CounterType(com.radixdlt.counters.SystemCounters.CounterType) SubstateId(com.radixdlt.atom.SubstateId) SubstateTypeId(com.radixdlt.atom.SubstateTypeId) REStateUpdate(com.radixdlt.constraintmachine.REStateUpdate) OperationStatus(com.sleepycat.je.OperationStatus) AID(com.radixdlt.identifiers.AID) Stopwatch(com.google.common.base.Stopwatch) Serialization(com.radixdlt.serialization.Serialization) UnsignedBytes.lexicographicalComparator(com.google.common.primitives.UnsignedBytes.lexicographicalComparator) ECPublicKey(com.radixdlt.crypto.ECPublicKey) Supplier(java.util.function.Supplier) RawSubstateBytes(com.radixdlt.constraintmachine.RawSubstateBytes) Longs(com.radixdlt.utils.Longs) OptionalLong(java.util.OptionalLong) ImmutableList(com.google.common.collect.ImmutableList) REOp(com.radixdlt.constraintmachine.REOp) Database(com.sleepycat.je.Database) SecondaryConfig(com.sleepycat.je.SecondaryConfig) NoSuchElementException(java.util.NoSuchElementException) UInt256(com.radixdlt.utils.UInt256) REProcessedTxn(com.radixdlt.constraintmachine.REProcessedTxn) Iterator(java.util.Iterator) SubstateIndex(com.radixdlt.constraintmachine.SubstateIndex) DtoLedgerProof(com.radixdlt.ledger.DtoLedgerProof) TokenResource(com.radixdlt.application.tokens.state.TokenResource) Txn(com.radixdlt.atom.Txn) IOException(java.io.IOException) SUCCESS(com.sleepycat.je.OperationStatus.SUCCESS) VerifiedVertexStoreState(com.radixdlt.consensus.bft.VerifiedVertexStoreState) Longs.fromByteArray(com.radixdlt.utils.Longs.fromByteArray) SecondaryDatabase(com.sleepycat.je.SecondaryDatabase) File(java.io.File) NOTFOUND(com.sleepycat.je.OperationStatus.NOTFOUND) ValidatorData(com.radixdlt.application.validators.state.ValidatorData) Cursor(com.sleepycat.je.Cursor) VirtualParent(com.radixdlt.application.system.state.VirtualParent) TimeUnit(java.util.concurrent.TimeUnit) CloseableCursor(com.radixdlt.atom.CloseableCursor) SecondaryCursor(com.sleepycat.je.SecondaryCursor) PersistentVertexStore(com.radixdlt.consensus.bft.PersistentVertexStore) DeserializeException(com.radixdlt.serialization.DeserializeException) Transaction(com.sleepycat.je.Transaction) LogManager(org.apache.logging.log4j.LogManager) SecondaryConfig(com.sleepycat.je.SecondaryConfig) File(java.io.File) RadixEngineException(com.radixdlt.engine.RadixEngineException) VirtualSubstateAlreadyDownException(com.radixdlt.constraintmachine.exceptions.VirtualSubstateAlreadyDownException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) DeserializeException(com.radixdlt.serialization.DeserializeException)

Aggregations

SystemCounters (com.radixdlt.counters.SystemCounters)4 DeterministicTest (com.radixdlt.harness.deterministic.DeterministicTest)3 CounterType (com.radixdlt.counters.SystemCounters.CounterType)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 Streams (com.google.common.collect.Streams)1 UnsignedBytes.lexicographicalComparator (com.google.common.primitives.UnsignedBytes.lexicographicalComparator)1 Inject (com.google.inject.Inject)1 SystemData (com.radixdlt.application.system.state.SystemData)1 VirtualParent (com.radixdlt.application.system.state.VirtualParent)1 ResourceData (com.radixdlt.application.tokens.state.ResourceData)1 TokenResource (com.radixdlt.application.tokens.state.TokenResource)1 ValidatorData (com.radixdlt.application.validators.state.ValidatorData)1 CloseableCursor (com.radixdlt.atom.CloseableCursor)1 SubstateId (com.radixdlt.atom.SubstateId)1 SubstateTypeId (com.radixdlt.atom.SubstateTypeId)1 Txn (com.radixdlt.atom.Txn)1 LedgerProof (com.radixdlt.consensus.LedgerProof)1 PersistentVertexStore (com.radixdlt.consensus.bft.PersistentVertexStore)1 VerifiedVertexStoreState (com.radixdlt.consensus.bft.VerifiedVertexStoreState)1