From 69bb57029c9337e235171ad45aec60de904ddd8b Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Mon, 29 Jan 2024 15:10:35 +0100 Subject: [PATCH 01/22] Applying one "technically required but not really needed" DB write lock + Adding explanatory comment. --- .../protocol_updates/protocol_update_committer.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs index d85645c988..8b9f7a3c15 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs @@ -147,8 +147,11 @@ impl ProtocolUpdateTransactionCommitter { .next_committable_batch_idx() .expect("Can't commit next protocol update batch"); - let read_store = self.store.read_current(); - let latest_proof: LedgerProof = read_store + // We are performing a pretty classic "transaction", so (for pure correctness) we obtain the + // write lock. In practice, however, we execute this logic only during boot-up or within an + // explicit (Java-side) "advance ledger lock" anyway. + let write_store = self.store.write_current(); + let latest_proof: LedgerProof = write_store .get_latest_proof() .expect("Pre-genesis protocol updates are currently not supported"); let latest_header = latest_proof.ledger_header; @@ -177,7 +180,7 @@ impl ProtocolUpdateTransactionCommitter { }; let mut series_executor = TransactionSeriesExecutor::new( - read_store.deref(), + write_store.deref(), &execution_cache, &self.execution_configurator, dummy_protocol_state, @@ -261,8 +264,6 @@ impl ProtocolUpdateTransactionCommitter { new_substate_node_ancestry_records: new_node_ancestry_records, }; - drop(read_store); - - self.store.write_current().commit(commit_bundle); + write_store.commit(commit_bundle); } } From 00ee2e14a14b29901049aa2e8233ae34473c1446 Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Tue, 30 Jan 2024 14:44:24 +0100 Subject: [PATCH 02/22] Better logs/metrics when divergent vertex execution is detected --- .../java/com/radixdlt/monitoring/Metrics.java | 4 +- .../DivergentVertexExecutionDetector.java | 151 ++++++++++++++++++ .../com/radixdlt/consensus/PendingVotes.java | 110 +------------ .../radixdlt/consensus/bft/BFTBuilder.java | 3 +- .../bft/processor/BFTQuorumAssembler.java | 14 +- .../DivergentVertexExecutionDetectorTest.java | 139 ++++++++++++++++ .../radixdlt/consensus/PendingVotesTest.java | 65 +------- 7 files changed, 313 insertions(+), 173 deletions(-) create mode 100644 core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java create mode 100644 core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java diff --git a/common/src/main/java/com/radixdlt/monitoring/Metrics.java b/common/src/main/java/com/radixdlt/monitoring/Metrics.java index 2c34276f73..6ef6dba06c 100644 --- a/common/src/main/java/com/radixdlt/monitoring/Metrics.java +++ b/common/src/main/java/com/radixdlt/monitoring/Metrics.java @@ -192,7 +192,7 @@ public record Bft( Summary leaderTransactionBytesIncludedInProposal, Summary leaderTransactionBytesIncludedInProposalAndPreviousVertices, Summary numSignaturesInCertificate, - Counter divergentVertexExecutions) { + LabelledCounter divergentVertexExecutions) { public record SuccessfullyProcessedVote(boolean isTimeout, VoteProcessingResult result) {} @@ -234,6 +234,8 @@ public record Sync( public record VertexStore( Gauge size, Counter forks, Counter rebuilds, Counter indirectParents) {} + + public record DivergentVertexExecution(int numDistinctExecutionResults) {} } public record BerkeleyDb(AddressBook addressBook, SafetyState safetyState) { diff --git a/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java new file mode 100644 index 0000000000..7fd98215d8 --- /dev/null +++ b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java @@ -0,0 +1,151 @@ +/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands). + * + * Licensed under the Radix License, Version 1.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at: + * + * radixfoundation.org/licenses/LICENSE-v1 + * + * The Licensor hereby grants permission for the Canonical version of the Work to be + * published, distributed and used under or by reference to the Licensor’s trademark + * Radix ® and use of any unregistered trade names, logos or get-up. + * + * The Licensor provides the Work (and each Contributor provides its Contributions) on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, + * MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. + * + * Whilst the Work is capable of being deployed, used and adopted (instantiated) to create + * a distributed ledger it is your responsibility to test and validate the code, together + * with all logic and performance of that code under all foreseeable scenarios. + * + * The Licensor does not make or purport to make and hereby excludes liability for all + * and any representation, warranty or undertaking in any form whatsoever, whether express + * or implied, to any entity or person, including any representation, warranty or + * undertaking, as to the functionality security use, value or other characteristics of + * any distributed ledger nor in respect the functioning or value of any tokens which may + * be created stored or transferred using the Work. The Licensor does not warrant that the + * Work or any use of the Work complies with any law or regulation in any territory where + * it may be implemented or used or that it will be appropriate for any specific purpose. + * + * Neither the licensor nor any current or former employees, officers, directors, partners, + * trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor + * shall be liable for any direct or indirect, special, incidental, consequential or other + * losses of any kind, in tort, contract or otherwise (including but not limited to loss + * of revenue, income or profits, or loss of use or data, or loss of reputation, or loss + * of any economic or other opportunity of whatsoever nature or howsoever arising), arising + * out of or in connection with (without limitation of any use, misuse, of any ledger system + * or use made or its functionality or any performance or operation of any code or protocol + * caused by bugs or programming or logic errors or otherwise); + * + * A. any offer, purchase, holding, use, sale, exchange or transmission of any + * cryptographic keys, tokens or assets created, exchanged, stored or arising from any + * interaction with the Work; + * + * B. any failure in a transmission or loss of any token or assets keys or other digital + * artefacts due to errors in transmission; + * + * C. bugs, hacks, logic errors or faults in the Work or any communication; + * + * D. system software or apparatus including but not limited to losses caused by errors + * in holding or transmitting tokens by any third-party; + * + * E. breaches or failure of security including hacker attacks, loss or disclosure of + * password, loss of private key, unauthorised use or misuse of such passwords or keys; + * + * F. any losses including loss of anticipated savings or other benefits resulting from + * use of the Work or any changes to the Work (however implemented). + * + * You are solely responsible for; testing, validating and evaluation of all operation + * logic, functionality, security and appropriateness of using the Work for any commercial + * or non-commercial purpose and for any reproduction or redistribution by You of the + * Work. You assume all risks associated with Your use of the Work and the exercise of + * permissions under this License. + */ + +package com.radixdlt.consensus; + +import com.google.common.hash.HashCode; +import com.google.common.util.concurrent.RateLimiter; +import com.radixdlt.consensus.bft.BFTValidatorId; +import com.radixdlt.consensus.bft.Round; +import com.radixdlt.monitoring.Metrics; +import java.util.*; +import java.util.stream.Collectors; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * A utility for detecting divergent vertex execution, i.e. a situation where two (or more) + * validators from the validator set have voted for the same vertexId, but their resultant ledger + * headers were different. + */ +@SuppressWarnings("UnstableApiUsage") +public final class DivergentVertexExecutionDetector { + private static final Logger log = LogManager.getLogger(); + + private final RateLimiter logRatelimiter = RateLimiter.create(0.05); // at most one log every 20s + + // vertexId -> ledgerHeader -> validators who voted for (vertexId, ledgerHeader) + private final Map>> map = new HashMap<>(); + + /** + * Processes a received vote. No additional filtering is applied, the caller should ensure that + * only relevant votes are being processed (e.g. only votes from a single round). + */ + public void process(Vote vote) { + final var ledgerHeadersByVertexId = + map.computeIfAbsent( + vote.getVoteData().getProposed().getVertexId(), unused -> new HashMap<>()); + final var authorsByLedgerHeader = + ledgerHeadersByVertexId.computeIfAbsent( + vote.getVoteData().getProposed().getLedgerHeader(), unused -> new HashSet<>()); + authorsByLedgerHeader.add(vote.getAuthor()); + } + + public void logAndUpdateMetrics(Metrics metrics, Round round) { + // Divergent executions are the ones that have more than one resultant header + // for the same vertex ID. + final StringBuilder logBuilder = new StringBuilder(); + map.entrySet().stream() + .filter(e -> e.getValue().size() > 1) + .forEach( + e -> { + final var vertexId = e.getKey(); + final var distinctResults = e.getValue(); + + metrics + .bft() + .divergentVertexExecutions() + .label(new Metrics.Bft.DivergentVertexExecution(distinctResults.size())) + .inc(); + + logBuilder.append( + String.format( + "In round %s validators have voted for vertex %s but they've computed %s" + + " distinct results:\n", + round, vertexId, distinctResults.size())); + for (var result : distinctResults.entrySet()) { + // Let's list the actual validators if there's less than 10 of them + final var validatorsDetails = + result.getValue().size() <= 10 + ? " (" + + result.getValue().stream() + .map(BFTValidatorId::toString) + .collect(Collectors.joining(",")) + + ")" + : ""; + logBuilder.append( + String.format( + " * %s validator(s)%s computed %s\n", + result.getValue().size(), validatorsDetails, result.getKey())); + } + }); + + if (logBuilder.length() > 0 && logRatelimiter.tryAcquire()) { + logBuilder.append( + "This is informational only, this node is unaffected unless other error messages" + + " follow.\n"); + log.info(logBuilder.toString()); + } + } +} diff --git a/core/src/main/java/com/radixdlt/consensus/PendingVotes.java b/core/src/main/java/com/radixdlt/consensus/PendingVotes.java index adb3997db4..620210b5f1 100644 --- a/core/src/main/java/com/radixdlt/consensus/PendingVotes.java +++ b/core/src/main/java/com/radixdlt/consensus/PendingVotes.java @@ -67,7 +67,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Maps; import com.google.common.hash.HashCode; -import com.google.common.util.concurrent.RateLimiter; import com.radixdlt.SecurityCritical; import com.radixdlt.SecurityCritical.SecurityKind; import com.radixdlt.consensus.bft.BFTValidatorId; @@ -79,13 +78,10 @@ import com.radixdlt.crypto.ECDSASecp256k1Signature; import com.radixdlt.crypto.Hasher; import com.radixdlt.environment.EventDispatcher; -import com.radixdlt.monitoring.Metrics; import java.util.Map; import java.util.Objects; import java.util.Optional; import javax.annotation.concurrent.NotThreadSafe; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; /** * Manages pending votes for various vertices. @@ -97,120 +93,20 @@ @NotThreadSafe @SecurityCritical({SecurityKind.SIG_VERIFY, SecurityKind.GENERAL}) public final class PendingVotes { - private static final Logger log = LogManager.getLogger(); - - private final BFTValidatorId self; private final Map voteState = Maps.newHashMap(); private final Map timeoutVoteState = Maps.newHashMap(); private final Map previousVotes = Maps.newHashMap(); private final Hasher hasher; private final EventDispatcher doubleVoteEventDispatcher; private final BFTValidatorSet validatorSet; - private final Metrics metrics; - private final RateLimiter divergentVertexExecutionLogRateLimiter = RateLimiter.create(0.1); public PendingVotes( - BFTValidatorId self, Hasher hasher, EventDispatcher doubleVoteEventDispatcher, - BFTValidatorSet validatorSet, - Metrics metrics) { - this.self = self; + BFTValidatorSet validatorSet) { this.hasher = Objects.requireNonNull(hasher); this.doubleVoteEventDispatcher = Objects.requireNonNull(doubleVoteEventDispatcher); this.validatorSet = Objects.requireNonNull(validatorSet); - this.metrics = metrics; - } - - private void checkForDivergentVertexExecution(Vote incomingVote) { - final var voteVertexId = incomingVote.getVoteData().getProposed().getVertexId(); - final var voteLedgerHeader = incomingVote.getVoteData().getProposed().getLedgerHeader(); - for (var otherVote : this.previousVotes.entrySet()) { - final var otherVertexId = otherVote.getValue().proposedHeader().getVertexId(); - final var otherLedgerHeader = otherVote.getValue().proposedHeader().getLedgerHeader(); - if (voteVertexId.equals(otherVertexId) && !voteLedgerHeader.equals(otherLedgerHeader)) { - if (!voteLedgerHeader - .nextProtocolVersion() - .equals(otherLedgerHeader.nextProtocolVersion())) { - logDivergentProtocolUpdateVote(incomingVote, otherVote.getKey(), otherVote.getValue()); - } else { - if (divergentVertexExecutionLogRateLimiter.tryAcquire()) { - log.warn( - "Divergent vertex execution detected! An incoming vote (from {}) for vertex {}" - + " claims the following resultant ledger header: {}, while validator {} thinks" - + " that the resultant ledger header is {}. [this_vote={}, other_vote={}]", - incomingVote.getAuthor(), - voteVertexId, - voteLedgerHeader, - otherVote.getKey(), - otherLedgerHeader, - incomingVote, - otherVote); - } - } - - // Regardless of the reason and whether the divergence applies to this node, - // we're bumping the metrics. - this.metrics.bft().divergentVertexExecutions().inc(); - } - } - } - - private void logDivergentProtocolUpdateVote( - Vote incomingVote, BFTValidatorId otherVoteAuthor, PreviousVote otherVote) { - // Protocol update-related divergence is most likely caused by some nodes running an - // outdated version. This is somewhat expected, so we're not going to log these occurrences - // unless they apply to this node. - final var isIncomingVoteFromSelf = self.equals(incomingVote.getAuthor()); - final var isExistingVoteFromSelf = self.equals(otherVoteAuthor); - if (isIncomingVoteFromSelf || isExistingVoteFromSelf) { - final var selfProposedHeader = - isIncomingVoteFromSelf - ? incomingVote.getVoteData().getProposed() - : otherVote.proposedHeader(); - final var otherProposedHeader = - isIncomingVoteFromSelf - ? otherVote.proposedHeader() - : incomingVote.getVoteData().getProposed(); - final var selfNextVersion = selfProposedHeader.getLedgerHeader().nextProtocolVersion(); - final var otherNextVersion = otherProposedHeader.getLedgerHeader().nextProtocolVersion(); - final var otherAuthor = isIncomingVoteFromSelf ? otherVoteAuthor : incomingVote.getAuthor(); - if (selfNextVersion.isPresent() && otherNextVersion.isEmpty()) { - // We're enacting, they don't: just a debug log. - if (divergentVertexExecutionLogRateLimiter.tryAcquire()) { - log.debug( - """ - Received a BFT vote from {} that doesn't enact a protocol update, - while we're enacting {}. - This indicates that they're likely running an outdated node version. - This node is unaffected, unless other error messages follow.""", - otherAuthor, - selfNextVersion); - } else if (selfNextVersion.isEmpty() && otherNextVersion.isPresent()) { - // We're not enacting, but they are: we're potentially outdated, log an early warning - if (divergentVertexExecutionLogRateLimiter.tryAcquire()) { - log.warn( - """ - Received a BFT vote from {} that enacts a protocol update {}, but this node doesn't enact it. - This node might be running an outdated version (but it's not certain).""", - otherAuthor, - otherNextVersion); - } - } else if (selfNextVersion.isPresent() && otherNextVersion.isPresent()) { - // We're enacting a different version, one of us is likely outdated. - if (divergentVertexExecutionLogRateLimiter.tryAcquire()) { - log.warn( - "Received a BFT vote from {} that enacts a protocol update {}, but this node enacts" - + " {}. It is likely that one of the nodes (this node or {}) is running an" - + " outdated version.", - otherAuthor, - otherNextVersion, - selfNextVersion, - otherAuthor); - } - } - } /* else: no-op; we don't care about other cases */ - } /* else: no-op; we don't care if the vote doesn't affect this node */ } /** @@ -230,10 +126,6 @@ public VoteProcessingResult insertVote(Vote vote) { return VoteProcessingResult.rejected(VoteRejectedReason.INVALID_AUTHOR); } - // This doesn't do anything, other than logging and bumping the metrics, - // when divergent execution is detected (which should hopefully never happen). - checkForDivergentVertexExecution(vote); - if (!replacePreviousVote(author, vote, voteDataHash)) { return VoteProcessingResult.rejected(VoteRejectedReason.DUPLICATE_VOTE); } diff --git a/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java b/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java index c70e93c8bb..3bc998b10b 100644 --- a/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java +++ b/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java @@ -207,8 +207,7 @@ public BFTEventProcessor build() { if (!validatorSet.containsValidator(self)) { return EmptyBFTEventProcessor.INSTANCE; } - final PendingVotes pendingVotes = - new PendingVotes(self, hasher, doubleVoteDispatcher, validatorSet, metrics); + final PendingVotes pendingVotes = new PendingVotes(hasher, doubleVoteDispatcher, validatorSet); /* Setting up the following BFT event processing pipeline: ObsoleteEventsFilter (filters out obsolete events for past rounds) diff --git a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java index 4c768d1567..976a869f90 100644 --- a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java +++ b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java @@ -64,6 +64,7 @@ package com.radixdlt.consensus.bft.processor; +import com.radixdlt.consensus.DivergentVertexExecutionDetector; import com.radixdlt.consensus.PendingVotes; import com.radixdlt.consensus.Vote; import com.radixdlt.consensus.bft.BFTValidatorId; @@ -109,6 +110,7 @@ public record TimeoutQuorumDelayedResolution( private RoundUpdate latestRoundUpdate; private boolean hasCurrentRoundBeenResolved = false; private boolean hasTimeoutQuorumResolutionBeenDelayedInCurrentRound = false; + private DivergentVertexExecutionDetector divergentVertexExecutionDetector; public BFTQuorumAssembler( BFTEventProcessorAtCurrentRound forwardTo, @@ -129,13 +131,21 @@ public BFTQuorumAssembler( this.pendingVotes = Objects.requireNonNull(pendingVotes); this.latestRoundUpdate = Objects.requireNonNull(initialRoundUpdate); this.timeoutQuorumResolutionDelayMs = timeoutQuorumResolutionDelayMs; + this.divergentVertexExecutionDetector = new DivergentVertexExecutionDetector(); } @Override public void processRoundUpdate(RoundUpdate roundUpdate) { + final var previousRound = this.latestRoundUpdate.getCurrentRound(); this.latestRoundUpdate = roundUpdate; this.hasCurrentRoundBeenResolved = false; this.hasTimeoutQuorumResolutionBeenDelayedInCurrentRound = false; + + // Process the divergent vertex executions we've collected in the previous round + // and set up a fresh detector. + this.divergentVertexExecutionDetector.logAndUpdateMetrics(metrics, previousRound); + this.divergentVertexExecutionDetector = new DivergentVertexExecutionDetector(); + forwardTo.processRoundUpdate(roundUpdate); } @@ -162,7 +172,7 @@ private void processVoteInternal(Vote vote) { switch (this.pendingVotes.insertVote(vote)) { case VoteAccepted unused -> { log.trace("Vote has been processed but didn't form a quorum"); - + divergentVertexExecutionDetector.process(vote); yield Metrics.Bft.VoteProcessingResult.ACCEPTED_NO_QUORUM; } case VoteRejected voteRejected -> { @@ -174,8 +184,8 @@ yield switch (voteRejected.reason()) { }; } case QuorumReached quorumReached -> { + divergentVertexExecutionDetector.process(vote); this.processQuorum(quorumReached.roundQuorum(), vote); - yield switch (quorumReached.roundQuorum()) { case RoundQuorum.RegularRoundQuorum unused -> Metrics.Bft.VoteProcessingResult .ACCEPTED_FORMED_QC; diff --git a/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java b/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java new file mode 100644 index 0000000000..7d6d841c2b --- /dev/null +++ b/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java @@ -0,0 +1,139 @@ +/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands). + * + * Licensed under the Radix License, Version 1.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at: + * + * radixfoundation.org/licenses/LICENSE-v1 + * + * The Licensor hereby grants permission for the Canonical version of the Work to be + * published, distributed and used under or by reference to the Licensor’s trademark + * Radix ® and use of any unregistered trade names, logos or get-up. + * + * The Licensor provides the Work (and each Contributor provides its Contributions) on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, + * MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. + * + * Whilst the Work is capable of being deployed, used and adopted (instantiated) to create + * a distributed ledger it is your responsibility to test and validate the code, together + * with all logic and performance of that code under all foreseeable scenarios. + * + * The Licensor does not make or purport to make and hereby excludes liability for all + * and any representation, warranty or undertaking in any form whatsoever, whether express + * or implied, to any entity or person, including any representation, warranty or + * undertaking, as to the functionality security use, value or other characteristics of + * any distributed ledger nor in respect the functioning or value of any tokens which may + * be created stored or transferred using the Work. The Licensor does not warrant that the + * Work or any use of the Work complies with any law or regulation in any territory where + * it may be implemented or used or that it will be appropriate for any specific purpose. + * + * Neither the licensor nor any current or former employees, officers, directors, partners, + * trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor + * shall be liable for any direct or indirect, special, incidental, consequential or other + * losses of any kind, in tort, contract or otherwise (including but not limited to loss + * of revenue, income or profits, or loss of use or data, or loss of reputation, or loss + * of any economic or other opportunity of whatsoever nature or howsoever arising), arising + * out of or in connection with (without limitation of any use, misuse, of any ledger system + * or use made or its functionality or any performance or operation of any code or protocol + * caused by bugs or programming or logic errors or otherwise); + * + * A. any offer, purchase, holding, use, sale, exchange or transmission of any + * cryptographic keys, tokens or assets created, exchanged, stored or arising from any + * interaction with the Work; + * + * B. any failure in a transmission or loss of any token or assets keys or other digital + * artefacts due to errors in transmission; + * + * C. bugs, hacks, logic errors or faults in the Work or any communication; + * + * D. system software or apparatus including but not limited to losses caused by errors + * in holding or transmitting tokens by any third-party; + * + * E. breaches or failure of security including hacker attacks, loss or disclosure of + * password, loss of private key, unauthorised use or misuse of such passwords or keys; + * + * F. any losses including loss of anticipated savings or other benefits resulting from + * use of the Work or any changes to the Work (however implemented). + * + * You are solely responsible for; testing, validating and evaluation of all operation + * logic, functionality, security and appropriateness of using the Work for any commercial + * or non-commercial purpose and for any reproduction or redistribution by You of the + * Work. You assume all risks associated with Your use of the Work and the exercise of + * permissions under this License. + */ + +package com.radixdlt.consensus; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.google.common.hash.HashCode; +import com.radixdlt.consensus.bft.BFTValidatorId; +import com.radixdlt.consensus.bft.Round; +import com.radixdlt.crypto.HashUtils; +import com.radixdlt.monitoring.Metrics; +import com.radixdlt.monitoring.MetricsInitializer; +import org.junit.Test; + +public final class DivergentVertexExecutionDetectorTest { + @Test + public void when_divergent_execution__then_should_update_the_metrics() { + final var detector = new DivergentVertexExecutionDetector(); + final var author1 = BFTValidatorId.random(); + final var author2 = BFTValidatorId.random(); + final var author3 = BFTValidatorId.random(); + final var vertex1 = HashUtils.random256(); + final var vertex2 = HashUtils.random256(); + + // No divergence for vertex1 + detector.process(createVoteForVertexId(author1, vertex1, 1L)); + detector.process(createVoteForVertexId(author2, vertex1, 1L)); + + // Divergence for vertex2 + detector.process(createVoteForVertexId(author1, vertex2, 2L)); + detector.process(createVoteForVertexId(author2, vertex2, 2L)); + detector.process(createVoteForVertexId(author3, vertex2, 3L)); + + final var metrics = new MetricsInitializer().initialize(); + detector.logAndUpdateMetrics(metrics, Round.epochInitial()); + + assertEquals( + 1, // Expecting 1 divergent execution with 2 conflicting results (label) + (int) + metrics + .bft() + .divergentVertexExecutions() + .label(new Metrics.Bft.DivergentVertexExecution(2)) + .get()); + + assertEquals( + 1, // Expecting no more results from other labels + (int) metrics.bft().divergentVertexExecutions().getSum()); + } + + private Vote createVoteForVertexId( + BFTValidatorId author, HashCode vertexId, long resultDiscriminator) { + final var ledgerHeader = + LedgerHeader.create( + 0L, + Round.epochInitial(), + resultDiscriminator, // Using a different state version as a discriminator + LedgerHashes.zero(), + 0L, + 0L); + + final var bftHeader = mock(BFTHeader.class); + when(bftHeader.getVertexId()).thenReturn(vertexId); + when(bftHeader.getLedgerHeader()).thenReturn(ledgerHeader); + + final var voteData = mock(VoteData.class); + when(voteData.getProposed()).thenReturn(bftHeader); + + final var vote = mock(Vote.class); + when(vote.getAuthor()).thenReturn(author); + when(vote.getVoteData()).thenReturn(voteData); + + return vote; + } +} diff --git a/core/src/test/java/com/radixdlt/consensus/PendingVotesTest.java b/core/src/test/java/com/radixdlt/consensus/PendingVotesTest.java index 6b52b68c03..59a8ac4a31 100644 --- a/core/src/test/java/com/radixdlt/consensus/PendingVotesTest.java +++ b/core/src/test/java/com/radixdlt/consensus/PendingVotesTest.java @@ -78,9 +78,6 @@ import com.radixdlt.crypto.ECDSASecp256k1Signature; import com.radixdlt.crypto.HashUtils; import com.radixdlt.crypto.Hasher; -import com.radixdlt.lang.Option; -import com.radixdlt.monitoring.Metrics; -import com.radixdlt.monitoring.MetricsInitializer; import com.radixdlt.utils.RandomHasher; import com.radixdlt.utils.UInt192; import java.util.Arrays; @@ -91,15 +88,11 @@ import org.junit.Test; public class PendingVotesTest { - private BFTValidatorId self; private Hasher hasher; - private Metrics metrics; @Before public void setup() { - this.self = BFTValidatorId.random(); this.hasher = new RandomHasher(); - this.metrics = new MetricsInitializer().initialize(); } @Test @@ -118,7 +111,7 @@ public void when_inserting_valid_but_unaccepted_votes__then_no_qc_is_returned() BFTValidatorSet validatorSet = BFTValidatorSet.from( Collections.singleton(BFTValidator.from(vote1.getAuthor(), UInt192.ONE))); - final var pendingVotes = new PendingVotes(self, hasher, e -> {}, validatorSet, metrics); + final var pendingVotes = new PendingVotes(hasher, e -> {}, validatorSet); VoteData voteData = mock(VoteData.class); BFTHeader proposed = vote1.getVoteData().getProposed(); @@ -147,7 +140,7 @@ public void when_inserting_valid_and_accepted_votes__then_qc_is_formed() { BFTHeader proposed = vote.getVoteData().getProposed(); when(voteData.getProposed()).thenReturn(proposed); - final var pendingVotes = new PendingVotes(self, hasher, e -> {}, validatorSet, metrics); + final var pendingVotes = new PendingVotes(hasher, e -> {}, validatorSet); assertTrue(pendingVotes.insertVote(vote) instanceof VoteProcessingResult.QuorumReached); } @@ -169,7 +162,7 @@ public void when_inserting_valid_timeout_votes__then_tc_is_formed() { BFTValidator.from(vote1.getAuthor(), UInt192.ONE), BFTValidator.from(vote2.getAuthor(), UInt192.ONE))); - final var pendingVotes = new PendingVotes(self, hasher, e -> {}, validatorSet, metrics); + final var pendingVotes = new PendingVotes(hasher, e -> {}, validatorSet); assertTrue(pendingVotes.insertVote(vote1) instanceof VoteProcessingResult.VoteAccepted); @@ -199,7 +192,7 @@ public void when_voting_again__previous_vote_is_removed() { BFTHeader proposed = vote.getVoteData().getProposed(); when(voteData.getProposed()).thenReturn(proposed); - final var pendingVotes = new PendingVotes(self, hasher, e -> {}, validatorSet, metrics); + final var pendingVotes = new PendingVotes(hasher, e -> {}, validatorSet); // Preconditions assertEquals(VoteProcessingResult.accepted(), pendingVotes.insertVote(vote)); @@ -232,7 +225,7 @@ public void when_voting_again__previous_timeoutvote_is_removed() { BFTHeader proposed = vote.getVoteData().getProposed(); when(voteData.getProposed()).thenReturn(proposed); - final var pendingVotes = new PendingVotes(self, hasher, e -> {}, validatorSet, metrics); + final var pendingVotes = new PendingVotes(hasher, e -> {}, validatorSet); // Preconditions assertEquals(VoteProcessingResult.accepted(), pendingVotes.insertVote(vote)); @@ -267,7 +260,7 @@ public void when_submitting_a_duplicate_vote__then_can_be_replaced_if_has_timeou BFTValidator.from(vote1.getAuthor(), UInt192.ONE), BFTValidator.from(vote2.getAuthor(), UInt192.ONE))); - final var pendingVotes = new PendingVotes(self, hasher, e -> {}, validatorSet, metrics); + final var pendingVotes = new PendingVotes(hasher, e -> {}, validatorSet); assertTrue(pendingVotes.insertVote(vote1) instanceof VoteProcessingResult.VoteAccepted); @@ -294,52 +287,6 @@ public void when_submitting_a_duplicate_vote__then_can_be_replaced_if_has_timeou instanceof RoundQuorum.TimeoutRoundQuorum); } - @Test - public void divergent_vertex_execution_should_be_detected() { - // Arrange: create two votes on the same vertexId, but having - // different ledger headers - final var vertexId = HashUtils.random256(); - - final var ledgerHeader1 = mock(LedgerHeader.class); - when(ledgerHeader1.nextProtocolVersion()).thenReturn(Option.empty()); - final var bftHeader1 = mock(BFTHeader.class); - when(bftHeader1.getLedgerHeader()).thenReturn(ledgerHeader1); - when(bftHeader1.getVertexId()).thenReturn(vertexId); - final var voteData1 = mock(VoteData.class); - when(voteData1.getProposed()).thenReturn(bftHeader1); - final var vote1 = - makeVoteWithoutSignatureFor(mock(BFTValidatorId.class), Round.epochInitial(), vertexId); - when(vote1.getSignature()).thenReturn(ECDSASecp256k1Signature.zeroSignature()); - when(vote1.getVoteData()).thenReturn(voteData1); - - final var ledgerHeader2 = mock(LedgerHeader.class); - when(ledgerHeader2.nextProtocolVersion()).thenReturn(Option.empty()); - final var bftHeader2 = mock(BFTHeader.class); - when(bftHeader2.getLedgerHeader()).thenReturn(ledgerHeader2); - when(bftHeader2.getVertexId()).thenReturn(vertexId); - final var voteData2 = mock(VoteData.class); - when(voteData2.getProposed()).thenReturn(bftHeader2); - final var vote2 = - makeVoteWithoutSignatureFor(mock(BFTValidatorId.class), Round.epochInitial(), vertexId); - when(vote2.getSignature()).thenReturn(ECDSASecp256k1Signature.zeroSignature()); - when(vote2.getVoteData()).thenReturn(voteData2); - - final var validatorSet = - BFTValidatorSet.from( - Arrays.asList( - BFTValidator.from(vote1.getAuthor(), UInt192.ONE), - BFTValidator.from(vote2.getAuthor(), UInt192.ONE))); - - final var pendingVotes = new PendingVotes(self, hasher, e -> {}, validatorSet, metrics); - - // Should still accept both votes... - assertTrue(pendingVotes.insertVote(vote1) instanceof VoteProcessingResult.VoteAccepted); - assertTrue(pendingVotes.insertVote(vote2) instanceof VoteProcessingResult.VoteAccepted); - - // ...but produce a warning and bump the metrics - assertEquals((int) metrics.bft().divergentVertexExecutions().get(), 1); - } - private Vote makeSignedVoteFor(BFTValidatorId author, Round parentRound, HashCode vertexId) { Vote vote = makeVoteWithoutSignatureFor(author, parentRound, vertexId); when(vote.getSignature()).thenReturn(ECDSASecp256k1Signature.zeroSignature()); From 65648122c04a405f3c9d81804f822415ba6925ec Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Tue, 30 Jan 2024 15:01:57 +0100 Subject: [PATCH 03/22] Reuse a single instance of DivergentVertexExecutionDetector --- .../DivergentVertexExecutionDetector.java | 16 +++++++++++----- .../bft/processor/BFTQuorumAssembler.java | 10 +++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java index 7fd98215d8..9abd4be6f2 100644 --- a/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java +++ b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java @@ -83,10 +83,11 @@ public final class DivergentVertexExecutionDetector { private static final Logger log = LogManager.getLogger(); - private final RateLimiter logRatelimiter = RateLimiter.create(0.05); // at most one log every 20s + private final RateLimiter logRatelimiter = RateLimiter.create(0.05); // At most one log every 20s // vertexId -> ledgerHeader -> validators who voted for (vertexId, ledgerHeader) - private final Map>> map = new HashMap<>(); + private final Map>> votesByVertexId = + new HashMap<>(); /** * Processes a received vote. No additional filtering is applied, the caller should ensure that @@ -94,7 +95,7 @@ public final class DivergentVertexExecutionDetector { */ public void process(Vote vote) { final var ledgerHeadersByVertexId = - map.computeIfAbsent( + votesByVertexId.computeIfAbsent( vote.getVoteData().getProposed().getVertexId(), unused -> new HashMap<>()); final var authorsByLedgerHeader = ledgerHeadersByVertexId.computeIfAbsent( @@ -104,9 +105,9 @@ public void process(Vote vote) { public void logAndUpdateMetrics(Metrics metrics, Round round) { // Divergent executions are the ones that have more than one resultant header - // for the same vertex ID. + // for the same vertexId. final StringBuilder logBuilder = new StringBuilder(); - map.entrySet().stream() + votesByVertexId.entrySet().stream() .filter(e -> e.getValue().size() > 1) .forEach( e -> { @@ -148,4 +149,9 @@ public void logAndUpdateMetrics(Metrics metrics, Round round) { log.info(logBuilder.toString()); } } + + /** Resets this detector to its initial state (empty). */ + public void clear() { + this.votesByVertexId.clear(); + } } diff --git a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java index 976a869f90..5cdeb4ca44 100644 --- a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java +++ b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java @@ -88,7 +88,6 @@ * Processes BFT Vote events and assembles a quorum (either a regular or timeout quorum). Warning: * operates under the assumption that all received events are for the current round. */ -@SuppressWarnings("OptionalUsedAsFieldOrParameterType") public final class BFTQuorumAssembler implements BFTEventProcessorAtCurrentRound { private static final Logger log = LogManager.getLogger(); @@ -110,7 +109,9 @@ public record TimeoutQuorumDelayedResolution( private RoundUpdate latestRoundUpdate; private boolean hasCurrentRoundBeenResolved = false; private boolean hasTimeoutQuorumResolutionBeenDelayedInCurrentRound = false; - private DivergentVertexExecutionDetector divergentVertexExecutionDetector; + + private final DivergentVertexExecutionDetector divergentVertexExecutionDetector = + new DivergentVertexExecutionDetector(); public BFTQuorumAssembler( BFTEventProcessorAtCurrentRound forwardTo, @@ -131,7 +132,6 @@ public BFTQuorumAssembler( this.pendingVotes = Objects.requireNonNull(pendingVotes); this.latestRoundUpdate = Objects.requireNonNull(initialRoundUpdate); this.timeoutQuorumResolutionDelayMs = timeoutQuorumResolutionDelayMs; - this.divergentVertexExecutionDetector = new DivergentVertexExecutionDetector(); } @Override @@ -142,9 +142,9 @@ public void processRoundUpdate(RoundUpdate roundUpdate) { this.hasTimeoutQuorumResolutionBeenDelayedInCurrentRound = false; // Process the divergent vertex executions we've collected in the previous round - // and set up a fresh detector. + // and set it up for the next round. this.divergentVertexExecutionDetector.logAndUpdateMetrics(metrics, previousRound); - this.divergentVertexExecutionDetector = new DivergentVertexExecutionDetector(); + this.divergentVertexExecutionDetector.clear(); forwardTo.processRoundUpdate(roundUpdate); } From 4726660531afb77101961fb7bc69e1bf21d774ad Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Tue, 30 Jan 2024 16:11:32 +0100 Subject: [PATCH 04/22] Fix test (add missing fields to mock) --- .../consensus/bft/processor/BFTQuorumAssemblerTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java b/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java index b60a74de62..407e983741 100644 --- a/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java +++ b/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java @@ -118,6 +118,11 @@ public void when_process_vote_with_quorum__then_processed() { QuorumCertificate highestCommittedQc = mock(QuorumCertificate.class); when(highQc.highestCommittedQC()).thenReturn(highestCommittedQc); when(vote.getRound()).thenReturn(Round.of(1)); + final var bftHeader = mock(BFTHeader.class); + when(bftHeader.getLedgerHeader()).thenReturn(mock(LedgerHeader.class)); + final var voteData = mock(VoteData.class); + when(voteData.getProposed()).thenReturn(bftHeader); + when(vote.getVoteData()).thenReturn(voteData); when(this.pendingVotes.insertVote(any())).thenReturn(VoteProcessingResult.regularQuorum(qc)); when(this.vertexStore.highQC()).thenReturn(highQc); From 0fc64e9d86678dfc9bf41f88ac2099972fdf9a32 Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Tue, 30 Jan 2024 16:53:20 +0100 Subject: [PATCH 05/22] Introducing a common trait for "main RocksDB" and "snapshot". --- core-rust/node-common/src/locks.rs | 4 +- core-rust/state-manager/src/store/db.rs | 3 +- core-rust/state-manager/src/store/rocks_db.rs | 495 +++++++++++------- core-rust/state-manager/src/store/traits.rs | 4 - .../state-manager/src/store/typed_cf_api.rs | 315 +++++++---- 5 files changed, 508 insertions(+), 313 deletions(-) diff --git a/core-rust/node-common/src/locks.rs b/core-rust/node-common/src/locks.rs index 44cf1154f2..35814b28f5 100644 --- a/core-rust/node-common/src/locks.rs +++ b/core-rust/node-common/src/locks.rs @@ -251,10 +251,8 @@ impl RwLock { /// The assumption is that the current state needs a classic [`RwLock`] access, while the historical /// state can be accessed freely, without obtaining any lock. /// The lock caller is responsible for distinguishing proper current vs historical access. -// TODO(future refactoring): It seems like the "weird lock" should not be needed if we had a DB -// interface which is more aware of its "current vs historical" nature. Maybe we will naturally go -// in that direction when introducing DB snapshotting. pub struct StateLock { + // TODO(wip): Re-purpose to `SnapshotLock` underlying: RwLock<()>, // we use our own primitive to lock a marker for current state value: T, access_non_locked_historical_listener: ActualLockListener, // only for metrics diff --git a/core-rust/state-manager/src/store/db.rs b/core-rust/state-manager/src/store/db.rs index 0b257ae8b5..4d7427ffd0 100644 --- a/core-rust/state-manager/src/store/db.rs +++ b/core-rust/state-manager/src/store/db.rs @@ -80,6 +80,7 @@ use radix_engine_store_interface::interface::{ }; use transaction::model::*; +use crate::store::rocks_db::DirectRocks; use radix_engine_stores::hash_tree::tree_store::{NodeKey, ReadableTreeStore, TreeNode}; use sbor::{Categorize, Decode, Encode}; @@ -112,7 +113,7 @@ pub struct DatabaseBackendConfig { )] pub enum StateManagerDatabase { // TODO(clean-up): After InMemoryDb was deleted, we can get rid of this middle-man as well. - RocksDB(RocksDBStore), + RocksDB(RocksDBStore), } impl StateManagerDatabase { diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index f0f7c8db4a..6741076730 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -77,7 +77,10 @@ use radix_engine::types::*; use radix_engine_stores::hash_tree::tree_store::{ NodeKey, ReadableTreeStore, TreeNode, VersionedTreeNode, }; -use rocksdb::{ColumnFamilyDescriptor, Direction, Options, DB}; +use rocksdb::{ + AsColumnFamilyRef, ColumnFamily, ColumnFamilyDescriptor, DBPinnableSlice, Direction, + IteratorMode, Options, WriteBatch, DB, +}; use transaction::model::*; use radix_engine_store_interface::interface::*; @@ -489,7 +492,105 @@ impl fmt::Display for ExtensionsDataKey { } } -pub struct RocksDBStore { +/// A redefined RocksDB's "key and value bytes" tuple (the original one lives in a private module). +pub type KVBytes = (Box<[u8]>, Box<[u8]>); + +/// A trait capturing the common read methods present both in a "direct" RocksDB instance and in its +/// snapshots. +/// +/// The library we use (a thin C wrapper, really) does not introduce this trivial and natural trait +/// itself, while we desperately need it to abstract the DB-reading code from the actual source of +/// data. +/// +/// A note on changed error handling: +/// The original methods typically return [`Result`]s. Our trait assumes panics instead, since we +/// treat all database access errors as fatal anyways. +pub trait ReadableRocks { + /// Resolves the column family by name. + fn cf_handle(&self, name: &str) -> &ColumnFamily; + + /// Starts iteration over key-value pairs, according to the given [`IteratorMode`]. + fn iterator_cf( + &self, + cf_handle: &impl AsColumnFamilyRef, + mode: IteratorMode, + ) -> Box + '_>; + + /// Gets a single value by key. + fn get_pinned_cf( + &self, + cf: &impl AsColumnFamilyRef, + key: impl AsRef<[u8]>, + ) -> Option; + + /// Gets multiple values by keys. + /// + /// Syntax note: + /// The `<'a>` here is not special at all: it could technically be 100% inferred. Just the + /// compiler feature allowing to skip it from within the `` is not yet stable. + /// TODO(when the rustc feature mentioned above becomes stable): get rid of the `<'a>`. + fn multi_get_cf<'a>( + &'a self, + keys: impl IntoIterator)>, + ) -> Vec>>; +} + +/// A write-supporting extension of the [`ReadableRocks`]. +/// +/// Naturally, it is expected that only a "direct" RocksDB instance can implement this one. +pub trait WriteableRocks: ReadableRocks { + fn write(&self, batch: WriteBatch); +} + +/// Direct RocksDB instance. +pub struct DirectRocks { + db: DB, +} + +impl ReadableRocks for DirectRocks { + fn cf_handle(&self, name: &str) -> &ColumnFamily { + self.db.cf_handle(name).expect(name) + } + + fn iterator_cf( + &self, + cf_handle: &impl AsColumnFamilyRef, + mode: IteratorMode, + ) -> Box + '_> { + Box::new( + self.db + .iterator_cf(cf_handle, mode) + .map(|result| result.expect("reading from DB iterator")), + ) + } + + fn get_pinned_cf( + &self, + cf: &impl AsColumnFamilyRef, + key: impl AsRef<[u8]>, + ) -> Option { + self.db.get_pinned_cf(cf, key).expect("DB get by key") + } + + fn multi_get_cf<'a>( + &'a self, + keys: impl IntoIterator)>, + ) -> Vec>> { + self.db + .multi_get_cf(keys) + .into_iter() + .map(|result| result.expect("batch DB get by key")) + .collect() + } +} + +impl WriteableRocks for DirectRocks { + fn write(&self, batch: WriteBatch) { + self.db.write(batch).expect("DB write batch"); + } +} + +pub struct RocksDBStore { /// Database feature flags. /// /// These were passed during construction, validated and persisted. They are made available by @@ -497,19 +598,15 @@ pub struct RocksDBStore { config: DatabaseFlags, /// Underlying RocksDB instance. - /// - /// **Note on usage:** - /// A typical use-case should not need to access this field directly, but instead use a - /// type-safe, write-buffering [`RocksDBStore::open_db_context()`]. - db: DB, + rocks: R, } -impl RocksDBStore { +impl RocksDBStore { pub fn new( root: PathBuf, config: DatabaseFlags, network: &NetworkDefinition, - ) -> Result { + ) -> Result { let mut db_opts = Options::default(); db_opts.create_if_missing(true); db_opts.create_missing_column_families(true); @@ -523,7 +620,7 @@ impl RocksDBStore { let rocks_db_store = RocksDBStore { config: config.clone(), - db, + rocks: DirectRocks { db }, }; let current_database_config = rocks_db_store.read_flags_state(); @@ -550,7 +647,7 @@ impl RocksDBStore { /// way of making it clear that it only wants read lock and not a write lock. /// /// [`ledger-tools`]: https://github.com/radixdlt/ledger-tools - pub fn new_read_only(root: PathBuf) -> Result { + pub fn new_read_only(root: PathBuf) -> Result { let mut db_opts = Options::default(); db_opts.create_if_missing(false); db_opts.create_missing_column_families(false); @@ -569,16 +666,12 @@ impl RocksDBStore { enable_local_transaction_execution_index: false, enable_account_change_index: false, }, - db, + rocks: DirectRocks { db }, }) } /// Create a RocksDBStore as a secondary instance which may catch up with the primary - pub fn new_as_secondary( - root: PathBuf, - temp: PathBuf, - column_families: Vec<&str>, - ) -> RocksDBStore { + pub fn new_as_secondary(root: PathBuf, temp: PathBuf, column_families: Vec<&str>) -> Self { let mut db_opts = Options::default(); db_opts.create_if_missing(false); db_opts.create_missing_column_families(false); @@ -601,101 +694,32 @@ impl RocksDBStore { enable_local_transaction_execution_index: false, enable_account_change_index: false, }, - db, + rocks: DirectRocks { db }, } } pub fn try_catchup_with_primary(&self) { - self.db.try_catch_up_with_primary().unwrap(); + self.rocks.db.try_catch_up_with_primary().unwrap(); } +} - /// Starts a read/batch-write interaction with the DB through per-CF type-safe APIs. - fn open_db_context(&self) -> TypedDbContext { - TypedDbContext::new(&self.db) +impl RocksDBStore { + /// Starts a read-only interaction with the DB through per-CF type-safe APIs. + fn open_read_context(&self) -> TypedDbContext { + TypedDbContext::new(&self.rocks, NoWriteSupport) } +} - fn add_transaction_to_write_batch( - &self, - db_context: &TypedDbContext, - transaction_bundle: CommittedTransactionBundle, - ) { - if self.is_account_change_index_enabled() { - self.batch_update_account_change_index_from_committed_transaction( - db_context, - transaction_bundle.state_version, - &transaction_bundle, - ); - } - - let CommittedTransactionBundle { - state_version, - raw, - receipt, - identifiers, - } = transaction_bundle; - let ledger_transaction_hash = identifiers.payload.ledger_transaction_hash; - - // TEMPORARY until this is handled in the engine: we store both an intent lookup and the transaction itself - if let TypedTransactionIdentifiers::User { - intent_hash, - notarized_transaction_hash, - .. - } = &identifiers.payload.typed - { - /* For user transactions we only need to check for duplicate intent hashes to know - that user payload hash and ledger payload hash are also unique. */ - - let maybe_existing_state_version = db_context.cf(IntentHashesCf).get(intent_hash); - if let Some(existing_state_version) = maybe_existing_state_version { - panic!( - "Attempted to save intent hash {:?} which already exists at state version {:?}", - intent_hash, existing_state_version - ); - } - - db_context - .cf(IntentHashesCf) - .put(intent_hash, &state_version); - db_context - .cf(NotarizedTransactionHashesCf) - .put(notarized_transaction_hash, &state_version); - } else { - let maybe_existing_state_version = db_context - .cf(LedgerTransactionHashesCf) - .get(&ledger_transaction_hash); - if let Some(existing_state_version) = maybe_existing_state_version { - panic!( - "Attempted to save ledger transaction hash {:?} which already exists at state version {:?}", - ledger_transaction_hash, - existing_state_version - ); - } - } - - db_context - .cf(LedgerTransactionHashesCf) - .put(&ledger_transaction_hash, &state_version); - db_context - .cf(RawLedgerTransactionsCf) - .put(&state_version, &raw); - db_context - .cf(CommittedTransactionIdentifiersCf) - .put(&state_version, &identifiers); - db_context - .cf(TransactionReceiptsCf) - .put(&state_version, &receipt.on_ledger); - - if self.is_local_transaction_execution_index_enabled() { - db_context - .cf(LocalTransactionExecutionsCf) - .put(&state_version, &receipt.local_execution); - } +impl RocksDBStore { + /// Starts a read/buffered-write interaction with the DB through per-CF type-safe APIs. + fn open_rw_context(&self) -> TypedDbContext> { + TypedDbContext::new(&self.rocks, BufferedWriteSupport::new(&self.rocks)) } } -impl ConfigurableDatabase for RocksDBStore { +impl RocksDBStore { fn read_flags_state(&self) -> DatabaseFlagsState { - let db_context = self.open_db_context(); + let db_context = self.open_read_context(); let extension_data_cf = db_context.cf(ExtensionsDataCf); let account_change_index_enabled = extension_data_cf .get(&ExtensionsDataKey::AccountChangeIndexEnabled) @@ -710,7 +734,7 @@ impl ConfigurableDatabase for RocksDBStore { } fn write_flags(&self, database_config: &DatabaseFlags) { - let db_context = self.open_db_context(); + let db_context = self.open_rw_context(); let extension_data_cf = db_context.cf(ExtensionsDataCf); extension_data_cf.put( &ExtensionsDataKey::AccountChangeIndexEnabled, @@ -721,7 +745,9 @@ impl ConfigurableDatabase for RocksDBStore { &scrypto_encode(&database_config.enable_local_transaction_execution_index).unwrap(), ); } +} +impl ConfigurableDatabase for RocksDBStore { fn is_account_change_index_enabled(&self) -> bool { self.config.enable_account_change_index } @@ -731,7 +757,7 @@ impl ConfigurableDatabase for RocksDBStore { } } -impl MeasurableDatabase for RocksDBStore { +impl MeasurableDatabase for RocksDBStore { fn get_data_volume_statistics(&self) -> Vec { let mut statistics = ALL_COLUMN_FAMILIES .iter() @@ -742,7 +768,7 @@ impl MeasurableDatabase for RocksDBStore { ) }) .collect::>(); - let live_files = match self.db.live_files() { + let live_files = match self.rocks.db.live_files() { Ok(live_files) => live_files, Err(err) => { warn!("could not get DB live files; returning 0: {:?}", err); @@ -765,9 +791,9 @@ impl MeasurableDatabase for RocksDBStore { } } -impl CommitStore for RocksDBStore { +impl CommitStore for RocksDBStore { fn commit(&self, commit_bundle: CommitBundle) { - let db_context = self.open_db_context(); + let db_context = self.open_rw_context(); // Check for duplicate intent/payload hashes in the commit request let mut user_transactions_count = 0; @@ -884,33 +910,115 @@ impl CommitStore for RocksDBStore { } } -impl ExecutedGenesisScenarioStore for RocksDBStore { +impl RocksDBStore { + fn add_transaction_to_write_batch( + &self, + db_context: &TypedDbContext>, + transaction_bundle: CommittedTransactionBundle, + ) { + if self.is_account_change_index_enabled() { + self.batch_update_account_change_index_from_committed_transaction( + db_context, + transaction_bundle.state_version, + &transaction_bundle, + ); + } + + let CommittedTransactionBundle { + state_version, + raw, + receipt, + identifiers, + } = transaction_bundle; + let ledger_transaction_hash = identifiers.payload.ledger_transaction_hash; + + // TEMPORARY until this is handled in the engine: we store both an intent lookup and the transaction itself + if let TypedTransactionIdentifiers::User { + intent_hash, + notarized_transaction_hash, + .. + } = &identifiers.payload.typed + { + /* For user transactions we only need to check for duplicate intent hashes to know + that user payload hash and ledger payload hash are also unique. */ + + let maybe_existing_state_version = db_context.cf(IntentHashesCf).get(intent_hash); + if let Some(existing_state_version) = maybe_existing_state_version { + panic!( + "Attempted to save intent hash {:?} which already exists at state version {:?}", + intent_hash, existing_state_version + ); + } + + db_context + .cf(IntentHashesCf) + .put(intent_hash, &state_version); + db_context + .cf(NotarizedTransactionHashesCf) + .put(notarized_transaction_hash, &state_version); + } else { + let maybe_existing_state_version = db_context + .cf(LedgerTransactionHashesCf) + .get(&ledger_transaction_hash); + if let Some(existing_state_version) = maybe_existing_state_version { + panic!( + "Attempted to save ledger transaction hash {:?} which already exists at state version {:?}", + ledger_transaction_hash, + existing_state_version + ); + } + } + + db_context + .cf(LedgerTransactionHashesCf) + .put(&ledger_transaction_hash, &state_version); + db_context + .cf(RawLedgerTransactionsCf) + .put(&state_version, &raw); + db_context + .cf(CommittedTransactionIdentifiersCf) + .put(&state_version, &identifiers); + db_context + .cf(TransactionReceiptsCf) + .put(&state_version, &receipt.on_ledger); + + if self.is_local_transaction_execution_index_enabled() { + db_context + .cf(LocalTransactionExecutionsCf) + .put(&state_version, &receipt.local_execution); + } + } +} + +impl ExecutedGenesisScenarioStore for RocksDBStore { fn put_scenario(&self, number: ScenarioSequenceNumber, scenario: ExecutedGenesisScenario) { - self.open_db_context() + self.open_rw_context() .cf(ExecutedGenesisScenariosCf) .put(&number, &scenario); } fn list_all_scenarios(&self) -> Vec<(ScenarioSequenceNumber, ExecutedGenesisScenario)> { - self.open_db_context() + self.open_read_context() .cf(ExecutedGenesisScenariosCf) .iterate(Direction::Forward) .collect() } } -pub struct RocksDBCommittedTransactionBundleIterator<'db> { +pub struct RocksDBCommittedTransactionBundleIterator<'r> { state_version: StateVersion, - txns_iter: Box + 'db>, - ledger_receipts_iter: Box + 'db>, - local_executions_iter: - Box + 'db>, + txns_iter: Box + 'r>, + ledger_receipts_iter: Box + 'r>, + local_executions_iter: Box + 'r>, identifiers_iter: - Box + 'db>, + Box + 'r>, } -impl<'db> RocksDBCommittedTransactionBundleIterator<'db> { - fn new(from_state_version: StateVersion, db_context: TypedDbContext<'db>) -> Self { +impl<'r> RocksDBCommittedTransactionBundleIterator<'r> { + fn new( + from_state_version: StateVersion, + db_context: TypedDbContext<'r, R, W>, + ) -> Self { Self { state_version: from_state_version, txns_iter: db_context @@ -929,7 +1037,7 @@ impl<'db> RocksDBCommittedTransactionBundleIterator<'db> { } } -impl<'db> Iterator for RocksDBCommittedTransactionBundleIterator<'db> { +impl<'r> Iterator for RocksDBCommittedTransactionBundleIterator<'r> { type Item = CommittedTransactionBundle; fn next(&mut self) -> Option { @@ -979,7 +1087,7 @@ impl<'db> Iterator for RocksDBCommittedTransactionBundleIterator<'db> { } } -impl IterableTransactionStore for RocksDBStore { +impl IterableTransactionStore for RocksDBStore { fn get_committed_transaction_bundle_iter( &self, from_state_version: StateVersion, @@ -990,17 +1098,17 @@ impl IterableTransactionStore for RocksDBStore { Box::new(RocksDBCommittedTransactionBundleIterator::new( from_state_version, - self.open_db_context(), + self.open_read_context(), )) } } -impl QueryableTransactionStore for RocksDBStore { +impl QueryableTransactionStore for RocksDBStore { fn get_committed_transaction( &self, state_version: StateVersion, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(RawLedgerTransactionsCf) .get(&state_version) } @@ -1009,7 +1117,7 @@ impl QueryableTransactionStore for RocksDBStore { &self, state_version: StateVersion, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(CommittedTransactionIdentifiersCf) .get(&state_version) } @@ -1018,7 +1126,7 @@ impl QueryableTransactionStore for RocksDBStore { &self, state_version: StateVersion, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(TransactionReceiptsCf) .get(&state_version) } @@ -1027,7 +1135,7 @@ impl QueryableTransactionStore for RocksDBStore { &self, state_version: StateVersion, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(LocalTransactionExecutionsCf) .get(&state_version) } @@ -1057,54 +1165,54 @@ impl QueryableTransactionStore for RocksDBStore { } } -impl TransactionIndex<&IntentHash> for RocksDBStore { +impl TransactionIndex<&IntentHash> for RocksDBStore { fn get_txn_state_version_by_identifier( &self, intent_hash: &IntentHash, ) -> Option { - self.open_db_context().cf(IntentHashesCf).get(intent_hash) + self.open_read_context().cf(IntentHashesCf).get(intent_hash) } } -impl TransactionIndex<&NotarizedTransactionHash> for RocksDBStore { +impl TransactionIndex<&NotarizedTransactionHash> for RocksDBStore { fn get_txn_state_version_by_identifier( &self, notarized_transaction_hash: &NotarizedTransactionHash, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(NotarizedTransactionHashesCf) .get(notarized_transaction_hash) } } -impl TransactionIndex<&LedgerTransactionHash> for RocksDBStore { +impl TransactionIndex<&LedgerTransactionHash> for RocksDBStore { fn get_txn_state_version_by_identifier( &self, ledger_transaction_hash: &LedgerTransactionHash, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(LedgerTransactionHashesCf) .get(ledger_transaction_hash) } } -impl TransactionIdentifierLoader for RocksDBStore { +impl TransactionIdentifierLoader for RocksDBStore { fn get_top_transaction_identifiers( &self, ) -> Option<(StateVersion, CommittedTransactionIdentifiers)> { - self.open_db_context() + self.open_read_context() .cf(CommittedTransactionIdentifiersCf) .get_last() } } -impl IterableProofStore for RocksDBStore { +impl IterableProofStore for RocksDBStore { fn get_proof_iter( &self, from_state_version: StateVersion, ) -> Box + '_> { Box::new( - self.open_db_context() + self.open_read_context() .cf(LedgerProofsCf) .iterate_from(&from_state_version, Direction::Forward) .map(|(_, proof)| proof), @@ -1116,7 +1224,7 @@ impl IterableProofStore for RocksDBStore { from_epoch: Epoch, ) -> Box + '_> { Box::new( - self.open_db_context() + self.open_read_context() .cf(EpochLedgerProofsCf) .iterate_from(&from_epoch, Direction::Forward) .map(|(_, proof)| proof), @@ -1128,7 +1236,7 @@ impl IterableProofStore for RocksDBStore { from_state_version: StateVersion, ) -> Box + '_> { Box::new( - self.open_db_context() + self.open_read_context() .cf(ProtocolUpdateInitLedgerProofsCf) .iterate_from(&from_state_version, Direction::Forward) .map(|(_, proof)| proof), @@ -1140,7 +1248,7 @@ impl IterableProofStore for RocksDBStore { from_state_version: StateVersion, ) -> Box + '_> { Box::new( - self.open_db_context() + self.open_read_context() .cf(ProtocolUpdateExecutionLedgerProofsCf) .iterate_from(&from_state_version, Direction::Forward) .map(|(_, proof)| proof), @@ -1148,9 +1256,9 @@ impl IterableProofStore for RocksDBStore { } } -impl QueryableProofStore for RocksDBStore { +impl QueryableProofStore for RocksDBStore { fn max_state_version(&self) -> StateVersion { - self.open_db_context() + self.open_read_context() .cf(RawLedgerTransactionsCf) .get_last_key() .unwrap_or(StateVersion::pre_genesis()) @@ -1167,11 +1275,11 @@ impl QueryableProofStore for RocksDBStore { let mut txns = Vec::new(); let mut proofs_iter = self - .open_db_context() + .open_read_context() .cf(LedgerProofsCf) .iterate_from(&start_state_version_inclusive, Direction::Forward); let mut txns_iter = self - .open_db_context() + .open_read_context() .cf(RawLedgerTransactionsCf) .iterate_from(&start_state_version_inclusive, Direction::Forward); @@ -1303,25 +1411,27 @@ impl QueryableProofStore for RocksDBStore { } fn get_first_proof(&self) -> Option { - self.open_db_context().cf(LedgerProofsCf).get_first_value() + self.open_read_context() + .cf(LedgerProofsCf) + .get_first_value() } fn get_post_genesis_epoch_proof(&self) -> Option { - self.open_db_context() + self.open_read_context() .cf(EpochLedgerProofsCf) .get_first_value() } fn get_epoch_proof(&self, epoch: Epoch) -> Option { - self.open_db_context().cf(EpochLedgerProofsCf).get(&epoch) + self.open_read_context().cf(EpochLedgerProofsCf).get(&epoch) } fn get_latest_proof(&self) -> Option { - self.open_db_context().cf(LedgerProofsCf).get_last_value() + self.open_read_context().cf(LedgerProofsCf).get_last_value() } fn get_latest_epoch_proof(&self) -> Option { - self.open_db_context() + self.open_read_context() .cf(EpochLedgerProofsCf) .get_last_value() } @@ -1330,7 +1440,7 @@ impl QueryableProofStore for RocksDBStore { &self, state_version: StateVersion, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(LedgerProofsCf) .iterate_from(&state_version, Direction::Reverse) .map(|(_, proof)| proof) @@ -1338,25 +1448,25 @@ impl QueryableProofStore for RocksDBStore { } fn get_latest_protocol_update_init_proof(&self) -> Option { - self.open_db_context() + self.open_read_context() .cf(ProtocolUpdateInitLedgerProofsCf) .get_last_value() } fn get_latest_protocol_update_execution_proof(&self) -> Option { - self.open_db_context() + self.open_read_context() .cf(ProtocolUpdateExecutionLedgerProofsCf) .get_last_value() } } -impl SubstateDatabase for RocksDBStore { +impl SubstateDatabase for RocksDBStore { fn get_substate( &self, partition_key: &DbPartitionKey, sort_key: &DbSortKey, ) -> Option { - self.open_db_context() + self.open_read_context() .cf(SubstatesCf) .get(&(partition_key.clone(), sort_key.clone())) } @@ -1369,7 +1479,7 @@ impl SubstateDatabase for RocksDBStore { let partition_key = partition_key.clone(); let from_sort_key = from_sort_key.cloned().unwrap_or(DbSortKey(vec![])); Box::new( - self.open_db_context() + self.open_read_context() .cf(SubstatesCf) .iterate_group_from(&(partition_key.clone(), from_sort_key), Direction::Forward) .map(|((_, sort_key), value)| (sort_key, value)), @@ -1377,40 +1487,42 @@ impl SubstateDatabase for RocksDBStore { } } -impl ListableSubstateDatabase for RocksDBStore { +impl ListableSubstateDatabase for RocksDBStore { fn list_partition_keys(&self) -> Box + '_> { - self.open_db_context().cf(SubstatesCf).iterate_key_groups() + self.open_read_context() + .cf(SubstatesCf) + .iterate_key_groups() } } -impl SubstateNodeAncestryStore for RocksDBStore { +impl SubstateNodeAncestryStore for RocksDBStore { fn batch_get_ancestry<'a>( &self, node_ids: impl IntoIterator, ) -> Vec> { - self.open_db_context() + self.open_read_context() .cf(SubstateNodeAncestryRecordsCf) .get_many(Vec::from_iter(node_ids)) } } -impl ReadableTreeStore for RocksDBStore { +impl ReadableTreeStore for RocksDBStore { fn get_node(&self, key: &NodeKey) -> Option { - self.open_db_context().cf(StateHashTreeNodesCf).get(key) + self.open_read_context().cf(StateHashTreeNodesCf).get(key) } } -impl StateHashTreeGcStore for RocksDBStore { +impl StateHashTreeGcStore for RocksDBStore { fn get_stale_tree_parts_iter( &self, ) -> Box + '_> { - self.open_db_context() + self.open_read_context() .cf(StaleStateHashTreePartsCf) .iterate(Direction::Forward) } fn batch_delete_node<'a>(&self, keys: impl IntoIterator) { - let db_context = self.open_db_context(); + let db_context = self.open_rw_context(); for key in keys { db_context.cf(StateHashTreeNodesCf).delete(key); } @@ -1420,7 +1532,7 @@ impl StateHashTreeGcStore for RocksDBStore { &self, state_versions: impl IntoIterator, ) { - let db_context = self.open_db_context(); + let db_context = self.open_rw_context(); for state_version in state_versions { db_context .cf(StaleStateHashTreePartsCf) @@ -1429,61 +1541,65 @@ impl StateHashTreeGcStore for RocksDBStore { } } -impl LedgerProofsGcStore for RocksDBStore { +impl LedgerProofsGcStore for RocksDBStore { fn get_progress(&self) -> Option { - self.open_db_context().cf(LedgerProofsGcProgressCf).get(&()) + self.open_read_context() + .cf(LedgerProofsGcProgressCf) + .get(&()) } fn set_progress(&self, progress: LedgerProofsGcProgress) { - self.open_db_context() + self.open_rw_context() .cf(LedgerProofsGcProgressCf) .put(&(), &progress); } fn delete_ledger_proofs_range(&self, from: StateVersion, to: StateVersion) { - self.open_db_context() + self.open_rw_context() .cf(LedgerProofsCf) .delete_range(&from, &to); } } -impl ReadableAccuTreeStore for RocksDBStore { +impl ReadableAccuTreeStore + for RocksDBStore +{ fn get_tree_slice( &self, state_version: &StateVersion, ) -> Option> { - self.open_db_context() + self.open_read_context() .cf(TransactionAccuTreeSlicesCf) .get(state_version) .map(|slice| slice.0) } } -impl ReadableAccuTreeStore for RocksDBStore { +impl ReadableAccuTreeStore for RocksDBStore { fn get_tree_slice(&self, state_version: &StateVersion) -> Option> { - self.open_db_context() + self.open_read_context() .cf(ReceiptAccuTreeSlicesCf) .get(state_version) .map(|slice| slice.0) } } -impl WriteableVertexStore for RocksDBStore { +impl WriteableVertexStore for RocksDBStore { fn save_vertex_store(&self, blob: VertexStoreBlob) { - self.open_db_context().cf(VertexStoreCf).put(&(), &blob) + self.open_rw_context().cf(VertexStoreCf).put(&(), &blob) } } -impl RecoverableVertexStore for RocksDBStore { +impl RecoverableVertexStore for RocksDBStore { fn get_vertex_store(&self) -> Option { - self.open_db_context().cf(VertexStoreCf).get(&()) + self.open_read_context().cf(VertexStoreCf).get(&()) } } -impl RocksDBStore { +impl RocksDBStore { fn batch_update_account_change_index_from_receipt( &self, - db_context: &TypedDbContext, + db_context: &TypedDbContext>, state_version: StateVersion, execution: &LocalTransactionExecution, ) { @@ -1501,7 +1617,7 @@ impl RocksDBStore { fn batch_update_account_change_index_from_committed_transaction( &self, - db_context: &TypedDbContext, + db_context: &TypedDbContext>, state_version: StateVersion, transaction_bundle: &CommittedTransactionBundle, ) { @@ -1522,7 +1638,7 @@ impl RocksDBStore { start_state_version_inclusive: StateVersion, limit: u64, ) -> StateVersion { - let db_context = self.open_db_context(); + let db_context = self.open_rw_context(); let mut executions_iter = db_context .cf(LocalTransactionExecutionsCf) .iterate_from(&start_state_version_inclusive, Direction::Forward); @@ -1561,9 +1677,9 @@ impl RocksDBStore { } } -impl AccountChangeIndexExtension for RocksDBStore { +impl AccountChangeIndexExtension for RocksDBStore { fn account_change_index_last_processed_state_version(&self) -> StateVersion { - self.open_db_context() + self.open_read_context() .cf(ExtensionsDataCf) .get(&ExtensionsDataKey::AccountChangeIndexLastProcessedStateVersion) .map(StateVersion::from_be_bytes) @@ -1599,9 +1715,9 @@ impl AccountChangeIndexExtension for RocksDBStore { } } -impl RestoreDecember2023LostSubstates for RocksDBStore { +impl RestoreDecember2023LostSubstates for RocksDBStore { fn restore_december_2023_lost_substates(&self, network: &NetworkDefinition) { - let db_context = self.open_db_context(); + let db_context = self.open_rw_context(); let extension_data_cf = db_context.cf(ExtensionsDataCf); let december_2023_lost_substates_restored = extension_data_cf.get(&ExtensionsDataKey::December2023LostSubstatesRestored); @@ -1628,11 +1744,12 @@ impl RestoreDecember2023LostSubstates for RocksDBStore { }; let first_epoch = first_proof.ledger_header.epoch.number(); let last_epoch = latest_epoch_proof.ledger_header.epoch.number(); - let problem_at_end_of_epoch = first_epoch + 19099; // (256 * 3 / 4 - 1) * 100 - 1 - // Due to another bug, stokenet nodes may mistakenly believe that they already applied - // the fix. Thus, we have to ignore the `december_2023_lost_substates_restored` flag and - // make a decision based on "being stuck in the problematic epoch range". The fix is - // effectively idempotent, so we are fine with re-running it in an edge case. + // magic number below is: (256 * 3 / 4 - 1) * 100 - 1 + let problem_at_end_of_epoch = first_epoch + 19099; + // Due to another bug, stokenet nodes may mistakenly believe that they already applied + // the fix. Thus, we have to ignore the `december_2023_lost_substates_restored` flag and + // make a decision based on "being stuck in the problematic epoch range". The fix is + // effectively idempotent, so we are fine with re-running it in an edge case. last_epoch >= problem_at_end_of_epoch && last_epoch <= (problem_at_end_of_epoch + 2) }; @@ -1696,14 +1813,14 @@ impl RestoreDecember2023LostSubstates for RocksDBStore { } } -impl IterableAccountChangeIndex for RocksDBStore { +impl IterableAccountChangeIndex for RocksDBStore { fn get_state_versions_for_account_iter( &self, account: GlobalAddress, from_state_version: StateVersion, ) -> Box + '_> { Box::new( - self.open_db_context() + self.open_read_context() .cf(AccountChangeStateVersionsCf) .iterate_from(&(account, from_state_version), Direction::Forward) .take_while(move |((next_account, _), _)| next_account == &account) diff --git a/core-rust/state-manager/src/store/traits.rs b/core-rust/state-manager/src/store/traits.rs index 8af821954c..98117cd39e 100644 --- a/core-rust/state-manager/src/store/traits.rs +++ b/core-rust/state-manager/src/store/traits.rs @@ -136,10 +136,6 @@ impl DatabaseFlags { #[enum_dispatch] pub trait ConfigurableDatabase { - fn read_flags_state(&self) -> DatabaseFlagsState; - - fn write_flags(&self, flags: &DatabaseFlags); - fn is_account_change_index_enabled(&self) -> bool; fn is_local_transaction_execution_index_enabled(&self) -> bool; diff --git a/core-rust/state-manager/src/store/typed_cf_api.rs b/core-rust/state-manager/src/store/typed_cf_api.rs index 568da182c7..10e10a673a 100644 --- a/core-rust/state-manager/src/store/typed_cf_api.rs +++ b/core-rust/state-manager/src/store/typed_cf_api.rs @@ -62,133 +62,184 @@ * permissions under this License. */ +use crate::store::rocks_db::{ReadableRocks, WriteableRocks}; use itertools::Itertools; use radix_engine::types::*; -use rocksdb::{ColumnFamily, Direction, IteratorMode, WriteBatch, DB}; +use rocksdb::{ColumnFamily, Direction, IteratorMode, WriteBatch}; use std::ops::Range; -/// A higher-level database read/write context. +/// An optional-write-enabling marker trait to be used with [`TypedDbContext`]. /// -/// Operates with the following contract: -/// - All reads see the current DB state; -/// - All writes are accumulated in the internal buffer and are not visible to subsequent reads (of -/// this or other contexts), until [`TypedDbContext::flush()`] (either an explicit one, or an -/// implicit on [`Drop`]). -pub struct TypedDbContext<'db> { - db: &'db DB, - write_buffer: WriteBuffer, -} - -impl<'db> TypedDbContext<'db> { - /// Creates a new context, with an empty write buffer. - pub fn new(db: &'db DB) -> Self { +/// This trait is `pub` only so that the callers of [`TypedDbContext`] can properly reference it. +/// It should not be implemented by any structs other than internally known options below (because +/// the [`TypedDbContext`] has to be statically aware of them - we selectively expose the available +/// write methods based on that). +pub trait WriteSupport {} + +/// No write support. +pub struct NoWriteSupport; + +impl WriteSupport for NoWriteSupport {} + +/// Buffered write support. +/// +/// All writes are accumulated in the internal buffer and are not visible to any subsequent reads, +/// until [`BufferedWriteSupport::flush()`] happens (either an explicit one, likely propagated from +/// [`TypedDbContext::flush()`], or an implicit one on [`Drop`]). +pub struct BufferedWriteSupport<'r, R: WriteableRocks> { + buffer: WriteBuffer, + rocks: &'r R, +} + +impl<'r, R: WriteableRocks> BufferedWriteSupport<'r, R> { + /// Creates an instance that will flush to the given RocksDB. + pub fn new(rocks: &'r R) -> Self { Self { - db, - write_buffer: WriteBuffer::default(), + buffer: WriteBuffer::default(), + rocks, } } +} - /// Returns a typed helper scoped at the given column family. - pub fn cf(&self, cf: CF) -> TypedCfApi<'db, '_, CF> { - TypedCfApi::new(self.db, cf, &self.write_buffer) - } +impl<'r, R: WriteableRocks> WriteSupport for BufferedWriteSupport<'r, R> {} - /// Explicitly flushes the current contents of the write buffer (so that it is visible to - /// subsequent reads). - pub fn flush(&self) { - let write_batch = self.write_buffer.flip(); +impl<'r, R: WriteableRocks> BufferedWriteSupport<'r, R> { + /// Writes the batch to the RocksDB and flips the internal buffer. + fn flush(&self) { + let write_batch = self.buffer.flip(); if !write_batch.is_empty() { - self.db.write(write_batch).expect("DB write batch"); + self.rocks.write(write_batch); } } } -impl<'db> Drop for TypedDbContext<'db> { +impl<'r, R: WriteableRocks> Drop for BufferedWriteSupport<'r, R> { fn drop(&mut self) { self.flush(); } } +/// A higher-level database context. +/// +/// All reads see the current DB state. +/// All (optional) write capabilities depend upon the used [`WriteSupport`]. +pub struct TypedDbContext<'r, R: ReadableRocks, W: WriteSupport> { + rocks: &'r R, + write_support: W, +} + +impl<'r, R: ReadableRocks, W: WriteSupport> TypedDbContext<'r, R, W> { + /// Creates an instance using the given RocksDB. + /// The write capabilities depend on the given [`WriteSupport`] implementation. + pub fn new(rocks: &'r R, write_support: W) -> Self { + Self { + rocks, + write_support, + } + } +} + +impl<'r, R: WriteableRocks> TypedDbContext<'r, R, BufferedWriteSupport<'r, R>> { + /// Explicitly flushes the current contents of the write buffer (so that it is visible to + /// subsequent reads). + pub fn flush(&self) { + self.write_support.flush(); + } +} + +impl<'r, R: ReadableRocks, W: WriteSupport> TypedDbContext<'r, R, W> { + /// Returns a typed helper scoped at the given column family. + pub fn cf(&self, typed_cf: CF) -> TypedCfApi<'r, '_, CF, R, W> { + TypedCfApi::new( + ResolvedCf::resolve(self.rocks, typed_cf), + self.rocks, + &self.write_support, + ) + } +} + /// A higher-level DB access API bound to its [`TypedDbContext`] and scoped at a specific column /// family. -pub struct TypedCfApi<'db, 'wb, CF: TypedCf> { - db: &'db DB, - typed_cf: CF, - write_buffer: &'wb WriteBuffer, - cf_handle: &'db ColumnFamily, // only a cache - computable from `typed_cf` - key_codec: CF::KeyCodec, // only a cache - computable from `typed_cf` - value_codec: CF::ValueCodec, // only a cache - computable from `typed_cf` +pub struct TypedCfApi<'r, 'w, CF: TypedCf, R: ReadableRocks, W: WriteSupport> { + cf: ResolvedCf<'r, CF>, + rocks: &'r R, + write_support: &'w W, } -impl<'db, 'wb, CF: TypedCf> TypedCfApi<'db, 'wb, CF> { +impl<'r, 'w, CF: TypedCf, R: ReadableRocks, W: WriteSupport> TypedCfApi<'r, 'w, CF, R, W> { /// Creates an instance for the given column family. - fn new(db: &'db DB, typed_cf: CF, write_buffer: &'wb WriteBuffer) -> Self { - // cache a few values: - let cf_handle = db.cf_handle(CF::NAME).unwrap(); - let key_codec = typed_cf.key_codec(); - let value_codec = typed_cf.value_codec(); + fn new(cf: ResolvedCf<'r, CF>, rocks: &'r R, write_support: &'w W) -> Self { Self { - db, - typed_cf, - write_buffer, - cf_handle, - key_codec, - value_codec, + cf, + rocks, + write_support, } } /// Gets value by key. pub fn get(&self, key: &CF::Key) -> Option { - self.db - .get_pinned_cf(self.cf_handle, self.key_codec.encode(key).as_slice()) - .expect("database get by key") - .map(|pinnable_slice| self.value_codec.decode(pinnable_slice.as_ref())) + self.rocks + .get_pinned_cf(self.cf.handle, self.cf.key_codec.encode(key).as_slice()) + .map(|pinnable_slice| self.cf.value_codec.decode(pinnable_slice.as_ref())) } /// Gets multiple values by keys. /// The order of returned values (or [`None`]s) matches the order of requested keys. pub fn get_many(&self, keys: Vec<&CF::Key>) -> Vec> { - self.db + self.rocks .multi_get_cf( keys.into_iter() - .map(|key| (self.cf_handle, self.key_codec.encode(key))), + .map(|key| (self.cf.handle, self.cf.key_codec.encode(key))), ) .into_iter() - .map(|result| { - result - .expect("multi get") - .map(|bytes| self.value_codec.decode(&bytes)) - }) + .map(|result| result.map(|bytes| self.cf.value_codec.decode(&bytes))) .collect() } +} +impl<'r, 'w, CF: TypedCf, R: WriteableRocks> + TypedCfApi<'r, 'w, CF, R, BufferedWriteSupport<'r, R>> +{ /// Upserts the new value at the given key. pub fn put(&self, key: &CF::Key, value: &CF::Value) { - self.write_buffer.put( - self.cf_handle, - self.key_codec.encode(key), - self.value_codec.encode(value), + self.write_support.buffer.put( + self.cf.handle, + self.cf.key_codec.encode(key), + self.cf.value_codec.encode(value), ); } /// Deletes the entry of the given key. pub fn delete(&self, key: &CF::Key) { - self.write_buffer - .delete(self.cf_handle, self.key_codec.encode(key)); + self.write_support + .buffer + .delete(self.cf.handle, self.cf.key_codec.encode(key)); } } -impl<'db, 'wb, KC: GroupPreservingDbCodec, CF: TypedCf> TypedCfApi<'db, 'wb, CF> { +impl<'r, 'w, KC: GroupPreservingDbCodec, CF: TypedCf, R: WriteableRocks> + TypedCfApi<'r, 'w, CF, R, BufferedWriteSupport<'r, R>> +{ /// Deletes all the entries from the given group. pub fn delete_group(&self, group: &KC::Group) { - let prefix_range = self.key_codec.encode_group_range(group); - self.write_buffer - .delete_range(self.cf_handle, prefix_range.start, prefix_range.end); + let prefix_range = self.cf.key_codec.encode_group_range(group); + self.write_support.buffer.delete_range( + self.cf.handle, + prefix_range.start, + prefix_range.end, + ); } } -impl<'db, 'wb, K, KC: OrderPreservingDbCodec + DbCodec, CF: TypedCf> - TypedCfApi<'db, 'wb, CF> +impl< + 'r, + 'w, + K, + KC: OrderPreservingDbCodec + DbCodec, + CF: TypedCf, + R: ReadableRocks, + W: WriteSupport, + > TypedCfApi<'r, 'w, CF, R, W> { /// Gets the entry of the least key. pub fn get_first(&self) -> Option<(CF::Key, CF::Value)> { @@ -220,10 +271,10 @@ impl<'db, 'wb, K, KC: OrderPreservingDbCodec + DbCodec, CF: TypedCf Box + 'db> + ) -> Box + 'r> where - CF::KeyCodec: 'db, - CF::ValueCodec: 'db, + CF::KeyCodec: 'r, + CF::ValueCodec: 'r, { self.iterate_with_mode(match direction { Direction::Forward => IteratorMode::Start, @@ -237,46 +288,35 @@ impl<'db, 'wb, K, KC: OrderPreservingDbCodec + DbCodec, CF: TypedCf Box + 'db> + ) -> Box + 'r> where - CF::KeyCodec: 'db, - CF::ValueCodec: 'db, + CF::KeyCodec: 'r, + CF::ValueCodec: 'r, { self.iterate_with_mode(IteratorMode::From( - self.key_codec.encode(from).as_slice(), + self.cf.key_codec.encode(from).as_slice(), direction, )) } - /// Deletes all the entries from the given key range. - /// Follows the classic convention of "from inclusive, to exclusive". - pub fn delete_range(&self, from_key: &CF::Key, to_key: &CF::Key) { - self.write_buffer.delete_range( - self.cf_handle, - self.key_codec.encode(from_key), - self.key_codec.encode(to_key), - ); - } - /// Returns an iterator based on the [`IteratorMode`] (which already contains encoded key). /// /// This is an internal shared implementation detail for different iteration flavors. fn iterate_with_mode( &self, mode: IteratorMode, - ) -> Box + 'db> + ) -> Box + 'r> where - CF::KeyCodec: 'db, - CF::ValueCodec: 'db, + CF::KeyCodec: 'r, + CF::ValueCodec: 'r, { // create dedicated instances; do not reference those cached by `&self` from returned value: - let key_codec = self.typed_cf.key_codec(); - let value_codec = self.typed_cf.value_codec(); + let key_codec = self.cf.inner.key_codec(); + let value_codec = self.cf.inner.value_codec(); Box::new( - self.db - .iterator_cf(self.cf_handle, mode) - .map(move |result| { - let (key, value) = result.expect("starting iteration"); + self.rocks + .iterator_cf(self.cf.handle, mode) + .map(move |(key, value)| { ( key_codec.decode(key.as_ref()), value_codec.decode(value.as_ref()), @@ -287,12 +327,34 @@ impl<'db, 'wb, K, KC: OrderPreservingDbCodec + DbCodec, CF: TypedCf, + CF: TypedCf, + R: WriteableRocks, + > TypedCfApi<'r, 'w, CF, R, BufferedWriteSupport<'r, R>> +{ + /// Deletes all the entries from the given key range. + /// Follows the classic convention of "from inclusive, to exclusive". + pub fn delete_range(&self, from_key: &CF::Key, to_key: &CF::Key) { + self.write_support.buffer.delete_range( + self.cf.handle, + self.cf.key_codec.encode(from_key), + self.cf.key_codec.encode(to_key), + ); + } +} + +impl< + 'r, + 'w, K, KC: IntraGroupOrderPreservingDbCodec + DbCodec, CF: TypedCf, - > TypedCfApi<'db, 'wb, CF> + R: ReadableRocks, + W: WriteSupport, + > TypedCfApi<'r, 'w, CF, R, W> { /// Returns an iterator starting at the given key (inclusive) and traversing over (potentially) /// all the entries remaining *in this element's group*, in the requested direction. @@ -300,22 +362,21 @@ impl< &self, from: &CF::Key, direction: Direction, - ) -> Box + 'db> + ) -> Box + 'r> where - CF::KeyCodec: 'db, - CF::ValueCodec: 'db, + CF::KeyCodec: 'r, + CF::ValueCodec: 'r, { - let key_codec = self.typed_cf.key_codec(); - let value_codec = self.typed_cf.value_codec(); - let group = self.key_codec.resolve_group_of(from); - let group_range = self.key_codec.encode_group_range(&group); + let group = self.cf.key_codec.resolve_group_of(from); + let group_range = self.cf.key_codec.encode_group_range(&group); + let key_codec = self.cf.inner.key_codec(); + let value_codec = self.cf.inner.value_codec(); Box::new( - self.db + self.rocks .iterator_cf( - self.cf_handle, - IteratorMode::From(&self.key_codec.encode(from), direction), + self.cf.handle, + IteratorMode::From(&self.cf.key_codec.encode(from), direction), ) - .map(|result| result.expect("while iterating")) .take_while(move |(key, _value)| match direction { Direction::Forward => key.as_ref() < group_range.end.as_slice(), Direction::Reverse => key.as_ref() >= group_range.start.as_slice(), @@ -337,17 +398,16 @@ impl< /// involves a lot of "wasted" DB reads and thus makes it not suitable for production purposes /// (i.e. an index of groups should be used instead). /// Hence, this method is meant only for test / investigation / DB verification purposes. - pub fn iterate_key_groups(&self) -> Box + 'db> + pub fn iterate_key_groups(&self) -> Box + 'r> where - CF::KeyCodec: 'db, + CF::KeyCodec: 'r, KC::Group: PartialEq, { - let key_codec = self.typed_cf.key_codec(); + let key_codec = self.cf.inner.key_codec(); Box::new( - self.db - .iterator_cf(self.cf_handle, IteratorMode::Start) - .map(move |result| { - let key_bytes = result.expect("while iterating").0; + self.rocks + .iterator_cf(self.cf.handle, IteratorMode::Start) + .map(move |(key_bytes, _)| { let key = key_codec.decode(key_bytes.as_ref()); key_codec.resolve_group_of(&key) }) @@ -707,3 +767,26 @@ impl WriteBuffer { self.write_batch.replace(WriteBatch::default()) } } + +/// An internal wrapper for a [`TypedCf`] and dependencies resolved from it. +struct ResolvedCf<'r, CF: TypedCf> { + inner: CF, + handle: &'r ColumnFamily, // only a cache - computable from `typed_cf` + key_codec: CF::KeyCodec, // only a cache - computable from `typed_cf` + value_codec: CF::ValueCodec, // only a cache - computable from `typed_cf` +} + +impl<'r, CF: TypedCf> ResolvedCf<'r, CF> { + /// Resolves and caches properties of the given [`TypedCf`]. + pub fn resolve(rocks: &'r R, inner: CF) -> Self { + let handle = rocks.cf_handle(CF::NAME); + let key_codec = inner.key_codec(); + let value_codec = inner.value_codec(); + Self { + inner, + handle, + key_codec, + value_codec, + } + } +} From 79d3a6bcde7a024150a68f5637ef4596be4778bb Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Tue, 30 Jan 2024 20:01:09 +0100 Subject: [PATCH 06/22] Getting rid of the obsolete DB enum middleman + Drive-by fix for accidentally-unused `LoggingConfig`. --- .../protocol_update_definition.rs | 12 +- .../protocol_updates/protocol_updaters.rs | 5 +- core-rust/state-manager/src/state_manager.rs | 35 ++- core-rust/state-manager/src/store/db.rs | 230 ------------------ core-rust/state-manager/src/store/mod.rs | 11 +- core-rust/state-manager/src/store/rocks_db.rs | 133 +++++++--- core-rust/state-manager/src/store/traits.rs | 2 +- .../src/transaction/executable_logic.rs | 12 +- 8 files changed, 142 insertions(+), 298 deletions(-) delete mode 100644 core-rust/state-manager/src/store/db.rs diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs index 60af84a717..2e8c7236fa 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs @@ -5,7 +5,7 @@ use radix_engine::transaction::CostingParameters; use radix_engine::types::*; use crate::transaction::*; -use crate::LoggingConfig; + use transaction::validation::{NotarizedTransactionValidator, ValidationConfig}; /// A protocol update definition consists of two parts: @@ -79,7 +79,6 @@ impl ConfigurableProtocolUpdateDefinition for T { #[derive(Clone, Debug)] pub struct ProtocolStateComputerConfig { pub network: NetworkDefinition, - pub logging_config: LoggingConfig, pub validation_config: ValidationConfig, pub costing_parameters: CostingParameters, } @@ -89,7 +88,6 @@ impl ProtocolStateComputerConfig { let network_id = network.id; ProtocolStateComputerConfig { network, - logging_config: LoggingConfig::default(), validation_config: ValidationConfig::default(network_id), costing_parameters: CostingParameters::default(), } @@ -109,7 +107,11 @@ impl ProtocolStateComputerConfig { self.validation_config } - pub fn execution_configurator(&self, no_fees: bool) -> ExecutionConfigurator { + pub fn execution_configurator( + &self, + no_fees: bool, + engine_trace: bool, + ) -> ExecutionConfigurator { let mut costing_parameters = self.costing_parameters; if no_fees { costing_parameters.execution_cost_unit_price = Decimal::ZERO; @@ -117,6 +119,6 @@ impl ProtocolStateComputerConfig { costing_parameters.state_storage_price = Decimal::ZERO; costing_parameters.archive_storage_price = Decimal::ZERO; } - ExecutionConfigurator::new(&self.network, &self.logging_config, costing_parameters) + ExecutionConfigurator::new(&self.network, engine_trace, costing_parameters) } } diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs index cc097e3c98..e5e03c6716 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs @@ -46,7 +46,10 @@ impl ProtocolUpdater for BatchedUpdater { let mut txn_committer = ProtocolUpdateTransactionCommitter::new( self.new_protocol_version.clone(), store.clone(), - self.new_state_computer_config.execution_configurator(true), /* No fees for protocol updates */ + // The costing and logging parameters (of the Engine) are not really used for flash + // transactions; let's still pass sane values. + self.new_state_computer_config + .execution_configurator(true, false), self.new_state_computer_config .ledger_transaction_validator(), ); diff --git a/core-rust/state-manager/src/state_manager.rs b/core-rust/state-manager/src/state_manager.rs index bf837e94a3..6133524dda 100644 --- a/core-rust/state-manager/src/state_manager.rs +++ b/core-rust/state-manager/src/state_manager.rs @@ -63,6 +63,7 @@ */ use std::ops::Deref; +use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; @@ -80,6 +81,7 @@ use crate::protocol::{ProtocolConfig, ProtocolState, ProtocolVersionName}; use crate::store::jmt_gc::StateHashTreeGcConfig; use crate::store::proofs_gc::{LedgerProofsGc, LedgerProofsGcConfig}; use crate::store::traits::proofs::QueryableProofStore; +use crate::traits::DatabaseConfigValidationError; use crate::transaction::ExecutionConfigurator; use crate::{ mempool_manager::MempoolManager, @@ -90,7 +92,7 @@ use crate::{ StateManagerDatabase, }, transaction::{CachedCommittabilityValidator, CommittabilityValidator, TransactionPreviewer}, - PendingTransactionResultCache, ProtocolUpdateResult, StateComputer, + PendingTransactionResultCache, ProtocolUpdateResult, StateComputer, StateManagerRocksDb, }; /// An interval between time-intensive measurement of raw DB metrics. @@ -171,13 +173,21 @@ impl StateManager { // but for now just using a default let mempool_config = config.mempool_config.clone().unwrap_or_default(); let network = config.network_definition.clone(); - let _logging_config = config.logging_config.clone(); - let raw_db = StateManagerDatabase::from_config( - config.database_backend_config.clone(), - config.database_flags.clone(), - &network, - ); + let db_path = PathBuf::from(config.database_backend_config.rocks_db_path.clone()); + let raw_db = match StateManagerRocksDb::new(db_path, config.database_flags.clone(), &network) { + Ok(db) => db, + Err(error) => { + match error { + DatabaseConfigValidationError::AccountChangeIndexRequiresLocalTransactionExecutionIndex => { + panic!("Local transaction execution index needs to be enabled in order for account change index to work."); + }, + DatabaseConfigValidationError::LocalTransactionExecutionIndexChanged => { + panic!("Local transaction execution index can not be changed once configured.\nIf you need to change it, please wipe ledger data and resync."); + } + } + } + }; let database = Arc::new(lock_factory.named("database").new_state_lock(raw_db)); @@ -202,9 +212,10 @@ impl StateManager { }); let execution_configurator = Arc::new( - lock_factory - .named("execution_configurator") - .new_rwlock(initial_state_computer_config.execution_configurator(config.no_fees)), + lock_factory.named("execution_configurator").new_rwlock( + initial_state_computer_config + .execution_configurator(config.no_fees, config.logging_config.engine_trace), + ), ); let pending_transaction_result_cache = Arc::new( @@ -337,8 +348,8 @@ impl StateManager { ) }); - let new_execution_configurator = - new_state_computer_config.execution_configurator(self.config.no_fees); + let new_execution_configurator = new_state_computer_config + .execution_configurator(self.config.no_fees, self.config.logging_config.engine_trace); *self.execution_configurator.write() = new_execution_configurator; diff --git a/core-rust/state-manager/src/store/db.rs b/core-rust/state-manager/src/store/db.rs deleted file mode 100644 index 4d7427ffd0..0000000000 --- a/core-rust/state-manager/src/store/db.rs +++ /dev/null @@ -1,230 +0,0 @@ -/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands). - * - * Licensed under the Radix License, Version 1.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at: - * - * radixfoundation.org/licenses/LICENSE-v1 - * - * The Licensor hereby grants permission for the Canonical version of the Work to be - * published, distributed and used under or by reference to the Licensor’s trademark - * Radix ® and use of any unregistered trade names, logos or get-up. - * - * The Licensor provides the Work (and each Contributor provides its Contributions) on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, - * including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, - * MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. - * - * Whilst the Work is capable of being deployed, used and adopted (instantiated) to create - * a distributed ledger it is your responsibility to test and validate the code, together - * with all logic and performance of that code under all foreseeable scenarios. - * - * The Licensor does not make or purport to make and hereby excludes liability for all - * and any representation, warranty or undertaking in any form whatsoever, whether express - * or implied, to any entity or person, including any representation, warranty or - * undertaking, as to the functionality security use, value or other characteristics of - * any distributed ledger nor in respect the functioning or value of any tokens which may - * be created stored or transferred using the Work. The Licensor does not warrant that the - * Work or any use of the Work complies with any law or regulation in any territory where - * it may be implemented or used or that it will be appropriate for any specific purpose. - * - * Neither the licensor nor any current or former employees, officers, directors, partners, - * trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor - * shall be liable for any direct or indirect, special, incidental, consequential or other - * losses of any kind, in tort, contract or otherwise (including but not limited to loss - * of revenue, income or profits, or loss of use or data, or loss of reputation, or loss - * of any economic or other opportunity of whatsoever nature or howsoever arising), arising - * out of or in connection with (without limitation of any use, misuse, of any ledger system - * or use made or its functionality or any performance or operation of any code or protocol - * caused by bugs or programming or logic errors or otherwise); - * - * A. any offer, purchase, holding, use, sale, exchange or transmission of any - * cryptographic keys, tokens or assets created, exchanged, stored or arising from any - * interaction with the Work; - * - * B. any failure in a transmission or loss of any token or assets keys or other digital - * artefacts due to errors in transmission; - * - * C. bugs, hacks, logic errors or faults in the Work or any communication; - * - * D. system software or apparatus including but not limited to losses caused by errors - * in holding or transmitting tokens by any third-party; - * - * E. breaches or failure of security including hacker attacks, loss or disclosure of - * password, loss of private key, unauthorised use or misuse of such passwords or keys; - * - * F. any losses including loss of anticipated savings or other benefits resulting from - * use of the Work or any changes to the Work (however implemented). - * - * You are solely responsible for; testing, validating and evaluation of all operation - * logic, functionality, security and appropriateness of using the Work for any commercial - * or non-commercial purpose and for any reproduction or redistribution by You of the - * Work. You assume all risks associated with Your use of the Work and the exercise of - * permissions under this License. - */ - -use crate::store::traits::*; -use crate::store::RocksDBStore; -use crate::transaction::LedgerTransactionHash; -use std::path::PathBuf; - -use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice}; -use crate::query::TransactionIdentifierLoader; -use crate::{ - CommittedTransactionIdentifiers, LedgerHashes, ReceiptTreeHash, StateVersion, - TransactionTreeHash, -}; -use enum_dispatch::enum_dispatch; -use radix_engine_common::network::NetworkDefinition; -use radix_engine_store_interface::interface::{ - DbPartitionKey, DbSortKey, DbSubstateValue, PartitionEntry, SubstateDatabase, -}; -use transaction::model::*; - -use crate::store::rocks_db::DirectRocks; -use radix_engine_stores::hash_tree::tree_store::{NodeKey, ReadableTreeStore, TreeNode}; -use sbor::{Categorize, Decode, Encode}; - -#[derive(Debug, Categorize, Encode, Decode, Clone)] -pub struct DatabaseBackendConfig { - pub rocks_db_path: String, -} - -// As of May 2023, enum_dispatch does not work with generic traits (or other libraries that do the same). -// We can also extend code generation for remaining local (declared in this crate) traits once -// trait aliases/specialization makes it into stable Rust. -// Unfortunately this doesn't work across crates since it's a proc_macro (i.e. for ReadableSubstateStore). -#[enum_dispatch( - ConfigurableDatabase, - MeasurableDatabase, - QueryableProofStore, - TransactionIdentifierLoader, - WriteableVertexStore, - RecoverableVertexStore, - AccountChangeIndexExtension, - QueryableTransactionStore, - CommitStore, - SubstateNodeAncestryStore, - IterableAccountChangeIndex, - IterableTransactionStore, - IterableProofStore, - ExecutedGenesisScenarioStore, - StateHashTreeGcStore, - LedgerProofsGcStore -)] -pub enum StateManagerDatabase { - // TODO(clean-up): After InMemoryDb was deleted, we can get rid of this middle-man as well. - RocksDB(RocksDBStore), -} - -impl StateManagerDatabase { - pub fn from_config( - backend_config: DatabaseBackendConfig, - flags: DatabaseFlags, - network: &NetworkDefinition, - ) -> Self { - let db = { - match RocksDBStore::new(PathBuf::from(backend_config.rocks_db_path), flags, network) { - Ok(db) => db, - Err(error) => { - match error { - DatabaseConfigValidationError::AccountChangeIndexRequiresLocalTransactionExecutionIndex => { - panic!("Local transaction execution index needs to be enabled in order for account change index to work.") - }, - DatabaseConfigValidationError::LocalTransactionExecutionIndexChanged => { - panic!("Local transaction execution index can not be changed once configured.\n\ - If you need to change it, please wipe ledger data and resync.\n") - } - } - } - } - }; - StateManagerDatabase::RocksDB(db) - } -} - -impl SubstateDatabase for StateManagerDatabase { - fn get_substate( - &self, - partition_key: &DbPartitionKey, - sort_key: &DbSortKey, - ) -> Option { - match self { - StateManagerDatabase::RocksDB(store) => store.get_substate(partition_key, sort_key), - } - } - - fn list_entries_from( - &self, - partition_key: &DbPartitionKey, - from_sort_key: Option<&DbSortKey>, - ) -> Box + '_> { - match self { - StateManagerDatabase::RocksDB(store) => { - store.list_entries_from(partition_key, from_sort_key) - } - } - } -} - -impl ReadableTreeStore for StateManagerDatabase { - fn get_node(&self, key: &NodeKey) -> Option { - match self { - StateManagerDatabase::RocksDB(store) => store.get_node(key), - } - } -} - -impl ReadableAccuTreeStore for StateManagerDatabase { - fn get_tree_slice( - &self, - state_version: &StateVersion, - ) -> Option> { - match self { - StateManagerDatabase::RocksDB(store) => store.get_tree_slice(state_version), - } - } -} - -impl ReadableAccuTreeStore for StateManagerDatabase { - fn get_tree_slice(&self, state_version: &StateVersion) -> Option> { - match self { - StateManagerDatabase::RocksDB(store) => store.get_tree_slice(state_version), - } - } -} - -impl TransactionIndex<&IntentHash> for StateManagerDatabase { - fn get_txn_state_version_by_identifier(&self, identifier: &IntentHash) -> Option { - match self { - StateManagerDatabase::RocksDB(store) => { - store.get_txn_state_version_by_identifier(identifier) - } - } - } -} - -impl TransactionIndex<&NotarizedTransactionHash> for StateManagerDatabase { - fn get_txn_state_version_by_identifier( - &self, - identifier: &NotarizedTransactionHash, - ) -> Option { - match self { - StateManagerDatabase::RocksDB(store) => { - store.get_txn_state_version_by_identifier(identifier) - } - } - } -} - -impl TransactionIndex<&LedgerTransactionHash> for StateManagerDatabase { - fn get_txn_state_version_by_identifier( - &self, - identifier: &LedgerTransactionHash, - ) -> Option { - match self { - StateManagerDatabase::RocksDB(store) => { - store.get_txn_state_version_by_identifier(identifier) - } - } - } -} diff --git a/core-rust/state-manager/src/store/mod.rs b/core-rust/state-manager/src/store/mod.rs index 0e674f32f4..eaa04de830 100644 --- a/core-rust/state-manager/src/store/mod.rs +++ b/core-rust/state-manager/src/store/mod.rs @@ -63,7 +63,6 @@ */ mod codecs; -mod db; pub mod jmt_gc; pub mod proofs_gc; mod rocks_db; @@ -72,13 +71,19 @@ mod typed_cf_api; use crate::store::traits::measurement::MeasurableDatabase; use crate::RawDbMetrics; -pub use db::{DatabaseBackendConfig, StateManagerDatabase}; use node_common::locks::StateLock; use prometheus::Registry; -pub use rocks_db::RocksDBStore; +pub use rocks_db::StateManagerDatabase; +pub use rocks_db::StateManagerRocksDb; +use sbor::{Categorize, Decode, Encode}; use std::sync::Arc; pub use traits::DatabaseFlags; +#[derive(Debug, Categorize, Encode, Decode, Clone)] +pub struct DatabaseBackendConfig { + pub rocks_db_path: String, +} + /// A synchronous collector of costly (I/O-intensive) raw DB metrics. pub struct RawDbMetricsCollector { database: Arc>, diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index 6741076730..3af2260fc1 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -79,7 +79,7 @@ use radix_engine_stores::hash_tree::tree_store::{ }; use rocksdb::{ AsColumnFamilyRef, ColumnFamily, ColumnFamilyDescriptor, DBPinnableSlice, Direction, - IteratorMode, Options, WriteBatch, DB, + IteratorMode, Options, Snapshot, WriteBatch, DB, }; use transaction::model::*; @@ -590,7 +590,60 @@ impl WriteableRocks for DirectRocks { } } -pub struct RocksDBStore { +/// Snapshot of RocksDB. +/// +/// Implementation note: +/// The original [`DB`] reference is interestingly kept internally by the [`Snapshot`] as well. +/// However, we need direct access to it for the [`Self::cf_handle()`] reasons. +pub struct SnapshotRocks<'db> { + db: &'db DB, + snapshot: Snapshot<'db>, +} + +impl<'db> ReadableRocks for SnapshotRocks<'db> { + fn cf_handle(&self, name: &str) -> &ColumnFamily { + self.db.cf_handle(name).expect(name) + } + + fn iterator_cf( + &self, + cf_handle: &impl AsColumnFamilyRef, + mode: IteratorMode, + ) -> Box + '_> { + Box::new( + self.snapshot + .iterator_cf(cf_handle, mode) + .map(|result| result.expect("reading from snapshot DB iterator")), + ) + } + + fn get_pinned_cf( + &self, + cf: &impl AsColumnFamilyRef, + key: impl AsRef<[u8]>, + ) -> Option { + self.snapshot + .get_pinned_cf(cf, key) + .expect("snapshot DB get by key") + } + + fn multi_get_cf<'a>( + &'a self, + keys: impl IntoIterator)>, + ) -> Vec>> { + self.snapshot + .multi_get_cf(keys) + .into_iter() + .map(|result| result.expect("batch snapshot DB get by key")) + .collect() + } +} + +/// A convenience alias for the exact [`StateManagerRocksDb`] type owned by state manager. +pub type StateManagerDatabase = StateManagerRocksDb; + +/// A RocksDB-backed persistence layer for state manager. +pub struct StateManagerRocksDb { /// Database feature flags. /// /// These were passed during construction, validated and persisted. They are made available by @@ -601,7 +654,7 @@ pub struct RocksDBStore { rocks: R, } -impl RocksDBStore { +impl StateManagerRocksDb { pub fn new( root: PathBuf, config: DatabaseFlags, @@ -618,7 +671,7 @@ impl RocksDBStore { let db = DB::open_cf_descriptors(&db_opts, root.as_path(), column_families).unwrap(); - let rocks_db_store = RocksDBStore { + let rocks_db_store = StateManagerRocksDb { config: config.clone(), rocks: DirectRocks { db }, }; @@ -636,12 +689,12 @@ impl RocksDBStore { Ok(rocks_db_store) } - /// Creates a readonly [`RocksDBStore`] that allows reading from the store while some other + /// Creates a readonly [`StateManagerRocksDb`] that allows reading from the store while some other /// process is writing to it. Any write operation that happens against a read-only store leads /// to a panic. /// /// This is required for the [`ledger-tools`] CLI tool which only reads data from the database - /// and does not write anything to it. Without this constructor, if [`RocksDBStore::new`] is + /// and does not write anything to it. Without this constructor, if [`StateManagerRocksDb::new`] is /// used by the [`ledger-tools`] CLI then it leads to a lock contention as two threads would /// want to have a write lock over the database. This provides the [`ledger-tools`] CLI with a /// way of making it clear that it only wants read lock and not a write lock. @@ -661,7 +714,7 @@ impl RocksDBStore { DB::open_cf_descriptors_read_only(&db_opts, root.as_path(), column_families, false) .unwrap(); - Ok(RocksDBStore { + Ok(StateManagerRocksDb { config: DatabaseFlags { enable_local_transaction_execution_index: false, enable_account_change_index: false, @@ -670,7 +723,7 @@ impl RocksDBStore { }) } - /// Create a RocksDBStore as a secondary instance which may catch up with the primary + /// Create a [`StateManagerRocksDb`] as a secondary instance which may catch up with the primary pub fn new_as_secondary(root: PathBuf, temp: PathBuf, column_families: Vec<&str>) -> Self { let mut db_opts = Options::default(); db_opts.create_if_missing(false); @@ -689,7 +742,7 @@ impl RocksDBStore { ) .unwrap(); - RocksDBStore { + StateManagerRocksDb { config: DatabaseFlags { enable_local_transaction_execution_index: false, enable_account_change_index: false, @@ -703,21 +756,21 @@ impl RocksDBStore { } } -impl RocksDBStore { +impl StateManagerRocksDb { /// Starts a read-only interaction with the DB through per-CF type-safe APIs. fn open_read_context(&self) -> TypedDbContext { TypedDbContext::new(&self.rocks, NoWriteSupport) } } -impl RocksDBStore { +impl StateManagerRocksDb { /// Starts a read/buffered-write interaction with the DB through per-CF type-safe APIs. fn open_rw_context(&self) -> TypedDbContext> { TypedDbContext::new(&self.rocks, BufferedWriteSupport::new(&self.rocks)) } } -impl RocksDBStore { +impl StateManagerRocksDb { fn read_flags_state(&self) -> DatabaseFlagsState { let db_context = self.open_read_context(); let extension_data_cf = db_context.cf(ExtensionsDataCf); @@ -747,7 +800,7 @@ impl RocksDBStore { } } -impl ConfigurableDatabase for RocksDBStore { +impl ConfigurableDatabase for StateManagerRocksDb { fn is_account_change_index_enabled(&self) -> bool { self.config.enable_account_change_index } @@ -757,7 +810,7 @@ impl ConfigurableDatabase for RocksDBStore { } } -impl MeasurableDatabase for RocksDBStore { +impl MeasurableDatabase for StateManagerRocksDb { fn get_data_volume_statistics(&self) -> Vec { let mut statistics = ALL_COLUMN_FAMILIES .iter() @@ -791,7 +844,7 @@ impl MeasurableDatabase for RocksDBStore { } } -impl CommitStore for RocksDBStore { +impl CommitStore for StateManagerRocksDb { fn commit(&self, commit_bundle: CommitBundle) { let db_context = self.open_rw_context(); @@ -910,7 +963,7 @@ impl CommitStore for RocksDBStore { } } -impl RocksDBStore { +impl StateManagerRocksDb { fn add_transaction_to_write_batch( &self, db_context: &TypedDbContext>, @@ -990,7 +1043,7 @@ impl RocksDBStore { } } -impl ExecutedGenesisScenarioStore for RocksDBStore { +impl ExecutedGenesisScenarioStore for StateManagerRocksDb { fn put_scenario(&self, number: ScenarioSequenceNumber, scenario: ExecutedGenesisScenario) { self.open_rw_context() .cf(ExecutedGenesisScenariosCf) @@ -1087,7 +1140,7 @@ impl<'r> Iterator for RocksDBCommittedTransactionBundleIterator<'r> { } } -impl IterableTransactionStore for RocksDBStore { +impl IterableTransactionStore for StateManagerRocksDb { fn get_committed_transaction_bundle_iter( &self, from_state_version: StateVersion, @@ -1103,7 +1156,7 @@ impl IterableTransactionStore for RocksDBStore { } } -impl QueryableTransactionStore for RocksDBStore { +impl QueryableTransactionStore for StateManagerRocksDb { fn get_committed_transaction( &self, state_version: StateVersion, @@ -1165,7 +1218,7 @@ impl QueryableTransactionStore for RocksDBStore { } } -impl TransactionIndex<&IntentHash> for RocksDBStore { +impl TransactionIndex<&IntentHash> for StateManagerRocksDb { fn get_txn_state_version_by_identifier( &self, intent_hash: &IntentHash, @@ -1174,7 +1227,7 @@ impl TransactionIndex<&IntentHash> for RocksDBStore { } } -impl TransactionIndex<&NotarizedTransactionHash> for RocksDBStore { +impl TransactionIndex<&NotarizedTransactionHash> for StateManagerRocksDb { fn get_txn_state_version_by_identifier( &self, notarized_transaction_hash: &NotarizedTransactionHash, @@ -1185,7 +1238,7 @@ impl TransactionIndex<&NotarizedTransactionHash> for RocksDBSt } } -impl TransactionIndex<&LedgerTransactionHash> for RocksDBStore { +impl TransactionIndex<&LedgerTransactionHash> for StateManagerRocksDb { fn get_txn_state_version_by_identifier( &self, ledger_transaction_hash: &LedgerTransactionHash, @@ -1196,7 +1249,7 @@ impl TransactionIndex<&LedgerTransactionHash> for RocksDBStore } } -impl TransactionIdentifierLoader for RocksDBStore { +impl TransactionIdentifierLoader for StateManagerRocksDb { fn get_top_transaction_identifiers( &self, ) -> Option<(StateVersion, CommittedTransactionIdentifiers)> { @@ -1206,7 +1259,7 @@ impl TransactionIdentifierLoader for RocksDBStore { } } -impl IterableProofStore for RocksDBStore { +impl IterableProofStore for StateManagerRocksDb { fn get_proof_iter( &self, from_state_version: StateVersion, @@ -1256,7 +1309,7 @@ impl IterableProofStore for RocksDBStore { } } -impl QueryableProofStore for RocksDBStore { +impl QueryableProofStore for StateManagerRocksDb { fn max_state_version(&self) -> StateVersion { self.open_read_context() .cf(RawLedgerTransactionsCf) @@ -1460,7 +1513,7 @@ impl QueryableProofStore for RocksDBStore { } } -impl SubstateDatabase for RocksDBStore { +impl SubstateDatabase for StateManagerRocksDb { fn get_substate( &self, partition_key: &DbPartitionKey, @@ -1487,7 +1540,7 @@ impl SubstateDatabase for RocksDBStore { } } -impl ListableSubstateDatabase for RocksDBStore { +impl ListableSubstateDatabase for StateManagerRocksDb { fn list_partition_keys(&self) -> Box + '_> { self.open_read_context() .cf(SubstatesCf) @@ -1495,7 +1548,7 @@ impl ListableSubstateDatabase for RocksDBStore { } } -impl SubstateNodeAncestryStore for RocksDBStore { +impl SubstateNodeAncestryStore for StateManagerRocksDb { fn batch_get_ancestry<'a>( &self, node_ids: impl IntoIterator, @@ -1506,13 +1559,13 @@ impl SubstateNodeAncestryStore for RocksDBStore { } } -impl ReadableTreeStore for RocksDBStore { +impl ReadableTreeStore for StateManagerRocksDb { fn get_node(&self, key: &NodeKey) -> Option { self.open_read_context().cf(StateHashTreeNodesCf).get(key) } } -impl StateHashTreeGcStore for RocksDBStore { +impl StateHashTreeGcStore for StateManagerRocksDb { fn get_stale_tree_parts_iter( &self, ) -> Box + '_> { @@ -1541,7 +1594,7 @@ impl StateHashTreeGcStore for RocksDBStore { } } -impl LedgerProofsGcStore for RocksDBStore { +impl LedgerProofsGcStore for StateManagerRocksDb { fn get_progress(&self) -> Option { self.open_read_context() .cf(LedgerProofsGcProgressCf) @@ -1562,7 +1615,7 @@ impl LedgerProofsGcStore for RocksDBStore { } impl ReadableAccuTreeStore - for RocksDBStore + for StateManagerRocksDb { fn get_tree_slice( &self, @@ -1575,7 +1628,9 @@ impl ReadableAccuTreeStore } } -impl ReadableAccuTreeStore for RocksDBStore { +impl ReadableAccuTreeStore + for StateManagerRocksDb +{ fn get_tree_slice(&self, state_version: &StateVersion) -> Option> { self.open_read_context() .cf(ReceiptAccuTreeSlicesCf) @@ -1584,19 +1639,19 @@ impl ReadableAccuTreeStore for } } -impl WriteableVertexStore for RocksDBStore { +impl WriteableVertexStore for StateManagerRocksDb { fn save_vertex_store(&self, blob: VertexStoreBlob) { self.open_rw_context().cf(VertexStoreCf).put(&(), &blob) } } -impl RecoverableVertexStore for RocksDBStore { +impl RecoverableVertexStore for StateManagerRocksDb { fn get_vertex_store(&self) -> Option { self.open_read_context().cf(VertexStoreCf).get(&()) } } -impl RocksDBStore { +impl StateManagerRocksDb { fn batch_update_account_change_index_from_receipt( &self, db_context: &TypedDbContext>, @@ -1677,7 +1732,7 @@ impl RocksDBStore { } } -impl AccountChangeIndexExtension for RocksDBStore { +impl AccountChangeIndexExtension for StateManagerRocksDb { fn account_change_index_last_processed_state_version(&self) -> StateVersion { self.open_read_context() .cf(ExtensionsDataCf) @@ -1715,7 +1770,7 @@ impl AccountChangeIndexExtension for RocksDBStore { } } -impl RestoreDecember2023LostSubstates for RocksDBStore { +impl RestoreDecember2023LostSubstates for StateManagerRocksDb { fn restore_december_2023_lost_substates(&self, network: &NetworkDefinition) { let db_context = self.open_rw_context(); let extension_data_cf = db_context.cf(ExtensionsDataCf); @@ -1813,7 +1868,7 @@ impl RestoreDecember2023LostSubstates for RocksDBStore { } } -impl IterableAccountChangeIndex for RocksDBStore { +impl IterableAccountChangeIndex for StateManagerRocksDb { fn get_state_versions_for_account_iter( &self, account: GlobalAddress, diff --git a/core-rust/state-manager/src/store/traits.rs b/core-rust/state-manager/src/store/traits.rs index 98117cd39e..ffa8339f66 100644 --- a/core-rust/state-manager/src/store/traits.rs +++ b/core-rust/state-manager/src/store/traits.rs @@ -66,7 +66,7 @@ use std::cmp::Ordering; use std::iter::Peekable; use crate::staging::StateHashTreeDiff; -use crate::store::StateManagerDatabase; + use crate::transaction::*; use crate::{CommittedTransactionIdentifiers, LedgerProof, LocalTransactionReceipt, StateVersion}; pub use commit::*; diff --git a/core-rust/state-manager/src/transaction/executable_logic.rs b/core-rust/state-manager/src/transaction/executable_logic.rs index 44fdf21006..e299e4bbd0 100644 --- a/core-rust/state-manager/src/transaction/executable_logic.rs +++ b/core-rust/state-manager/src/transaction/executable_logic.rs @@ -16,7 +16,6 @@ use radix_engine_store_interface::interface::SubstateDatabase; use tracing::warn; -use crate::LoggingConfig; use transaction::model::*; use utils::prelude::index_map_new; @@ -70,10 +69,9 @@ pub struct ExecutionConfigurator { impl ExecutionConfigurator { pub fn new( network: &NetworkDefinition, - logging_config: &LoggingConfig, + engine_trace: bool, costing_parameters: CostingParameters, ) -> Self { - let trace = logging_config.engine_trace; Self { scrypto_vm: ScryptoVm::::default(), costing_parameters, @@ -81,26 +79,26 @@ impl ExecutionConfigurator { ( ConfigType::Genesis, ExecutionConfig::for_genesis_transaction(network.clone()) - .with_kernel_trace(trace), + .with_kernel_trace(engine_trace), ), ( ConfigType::OtherSystem, ExecutionConfig { max_number_of_events: 1_000_000, ..ExecutionConfig::for_system_transaction(network.clone()) - .with_kernel_trace(trace) + .with_kernel_trace(engine_trace) }, ), ( ConfigType::Regular, ExecutionConfig::for_notarized_transaction(network.clone()) - .with_kernel_trace(trace), + .with_kernel_trace(engine_trace), ), ( ConfigType::Pending, ExecutionConfig::for_notarized_transaction(network.clone()) .up_to_loan_repayment(true) - .with_kernel_trace(trace), + .with_kernel_trace(engine_trace), ), ( ConfigType::Preview, From 2f44167d212046035f1ca284b8d7428e9348f198 Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Wed, 31 Jan 2024 09:20:53 +0100 Subject: [PATCH 07/22] Removing the no-longer-needed `enum_dispatch` + Some renames. --- core-rust/Cargo.lock | 13 ------------- core-rust/state-manager/Cargo.toml | 1 - .../src/accumulator_tree/storage.rs | 2 -- .../src/query/transaction_identifiers.rs | 3 --- core-rust/state-manager/src/store/rocks_db.rs | 18 +++++++++--------- core-rust/state-manager/src/store/traits.rs | 19 +------------------ 6 files changed, 10 insertions(+), 46 deletions(-) diff --git a/core-rust/Cargo.lock b/core-rust/Cargo.lock index ca23882cae..cd534238fd 100644 --- a/core-rust/Cargo.lock +++ b/core-rust/Cargo.lock @@ -525,18 +525,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "enum_dispatch" -version = "0.3.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f33313078bb8d4d05a2733a94ac4c2d8a0df9a2b84424ebf4f33bfc224a890e" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.32", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -2178,7 +2166,6 @@ version = "0.1.0" dependencies = [ "blake2", "chrono", - "enum_dispatch", "hex", "im", "itertools 0.11.0", diff --git a/core-rust/state-manager/Cargo.toml b/core-rust/state-manager/Cargo.toml index 924ad43bf3..36c2363e94 100644 --- a/core-rust/state-manager/Cargo.toml +++ b/core-rust/state-manager/Cargo.toml @@ -31,7 +31,6 @@ lru = { version = "0.8.0", default-features = false } slotmap = { version = "1.0.6" } im = { version = "15.1.0" } rand = { version = "0.8.5" } -enum_dispatch = { version = "0.3.11" } [dev-dependencies] tempfile = { version = "3.4.0" } diff --git a/core-rust/state-manager/src/accumulator_tree/storage.rs b/core-rust/state-manager/src/accumulator_tree/storage.rs index ea68e03eee..539ee02cd9 100644 --- a/core-rust/state-manager/src/accumulator_tree/storage.rs +++ b/core-rust/state-manager/src/accumulator_tree/storage.rs @@ -62,12 +62,10 @@ * permissions under this License. */ -use enum_dispatch::enum_dispatch; use radix_engine::types::{ScryptoCategorize, ScryptoDecode, ScryptoEncode}; /// The "read" part of an accumulator tree storage SPI. /// Both the key type and node type are implementation-dependent. -#[enum_dispatch] pub trait ReadableAccuTreeStore { /// Gets a vertical `TreeSlice` by the given key. fn get_tree_slice(&self, key: &K) -> Option>; diff --git a/core-rust/state-manager/src/query/transaction_identifiers.rs b/core-rust/state-manager/src/query/transaction_identifiers.rs index f30d4c2133..edb046ab85 100644 --- a/core-rust/state-manager/src/query/transaction_identifiers.rs +++ b/core-rust/state-manager/src/query/transaction_identifiers.rs @@ -1,8 +1,5 @@ -use enum_dispatch::enum_dispatch; - use crate::{CommittedTransactionIdentifiers, LedgerHashes, StateVersion}; -#[enum_dispatch] pub trait TransactionIdentifierLoader { fn get_top_transaction_identifiers( &self, diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index 3af2260fc1..9a98354dee 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -654,7 +654,7 @@ pub struct StateManagerRocksDb { rocks: R, } -impl StateManagerRocksDb { +impl StateManagerDatabase { pub fn new( root: PathBuf, config: DatabaseFlags, @@ -671,22 +671,22 @@ impl StateManagerRocksDb { let db = DB::open_cf_descriptors(&db_opts, root.as_path(), column_families).unwrap(); - let rocks_db_store = StateManagerRocksDb { + let state_manager_database = StateManagerRocksDb { config: config.clone(), rocks: DirectRocks { db }, }; - let current_database_config = rocks_db_store.read_flags_state(); + let current_database_config = state_manager_database.read_flags_state(); config.validate(¤t_database_config)?; - rocks_db_store.write_flags(&config); + state_manager_database.write_flags(&config); - if rocks_db_store.config.enable_account_change_index { - rocks_db_store.catchup_account_change_index(); + if state_manager_database.config.enable_account_change_index { + state_manager_database.catchup_account_change_index(); } - rocks_db_store.restore_december_2023_lost_substates(network); + state_manager_database.restore_december_2023_lost_substates(network); - Ok(rocks_db_store) + Ok(state_manager_database) } /// Creates a readonly [`StateManagerRocksDb`] that allows reading from the store while some other @@ -810,7 +810,7 @@ impl ConfigurableDatabase for StateManagerRocksDb { } } -impl MeasurableDatabase for StateManagerRocksDb { +impl MeasurableDatabase for StateManagerDatabase { fn get_data_volume_statistics(&self) -> Vec { let mut statistics = ALL_COLUMN_FAMILIES .iter() diff --git a/core-rust/state-manager/src/store/traits.rs b/core-rust/state-manager/src/store/traits.rs index ffa8339f66..b5c303bfc8 100644 --- a/core-rust/state-manager/src/store/traits.rs +++ b/core-rust/state-manager/src/store/traits.rs @@ -70,7 +70,6 @@ use crate::staging::StateHashTreeDiff; use crate::transaction::*; use crate::{CommittedTransactionIdentifiers, LedgerProof, LocalTransactionReceipt, StateVersion}; pub use commit::*; -use enum_dispatch::enum_dispatch; pub use proofs::*; use radix_engine_common::{Categorize, Decode, Encode}; pub use substate::*; @@ -134,7 +133,6 @@ impl DatabaseFlags { } } -#[enum_dispatch] pub trait ConfigurableDatabase { fn is_account_change_index_enabled(&self) -> bool; @@ -152,12 +150,10 @@ pub struct CommittedTransactionBundle { pub mod vertex { use super::*; - #[enum_dispatch] pub trait RecoverableVertexStore { fn get_vertex_store(&self) -> Option; } - #[enum_dispatch] pub trait WriteableVertexStore { fn save_vertex_store(&self, blob: VertexStoreBlob); } @@ -186,7 +182,6 @@ pub mod substate { /// batch method. Both provide default implementations (which mutually reduce one problem to the /// other). The implementer must choose to implement at least one of the methods, based on its /// nature (though implementing both rarely makes sense). - #[enum_dispatch] pub trait SubstateNodeAncestryStore { /// Returns the [`SubstateNodeAncestryRecord`] for the given [`NodeId`], or [`None`] if: /// - the `node_id` happens to be a root Node (since they do not have "ancestry"); @@ -245,7 +240,6 @@ pub mod transactions { LocalTransactionExecution, LocalTransactionReceipt, }; - #[enum_dispatch] pub trait IterableTransactionStore { fn get_committed_transaction_bundle_iter( &self, @@ -253,7 +247,6 @@ pub mod transactions { ) -> Box + '_>; } - #[enum_dispatch] pub trait QueryableTransactionStore { fn get_committed_transaction( &self, @@ -296,7 +289,6 @@ pub mod proofs { use super::*; - #[enum_dispatch] pub trait IterableProofStore { fn get_proof_iter( &self, @@ -319,7 +311,6 @@ pub mod proofs { ) -> Box + '_>; } - #[enum_dispatch] pub trait QueryableProofStore { fn max_state_version(&self) -> StateVersion; fn max_completed_epoch(&self) -> Option { @@ -524,7 +515,6 @@ pub mod commit { #[derive(Debug, Clone, ScryptoCategorize, ScryptoEncode, ScryptoDecode)] pub struct ReceiptAccuTreeSliceV1(pub TreeSlice); - #[enum_dispatch] pub trait CommitStore { fn commit(&self, commit_bundle: CommitBundle); } @@ -565,7 +555,6 @@ pub mod scenario { /// A store of testing-specific [`ExecutedGenesisScenario`], meant to be as separated as /// possible from the production stores (e.g. the writes happening outside of the regular commit /// batch write). - #[enum_dispatch] pub trait ExecutedGenesisScenarioStore { /// Writes the given Scenario under a caller-managed sequence number (which means: it allows /// overwriting, writing out-of-order, leaving gaps, etc.). @@ -583,19 +572,16 @@ pub mod extensions { use radix_engine::types::GlobalAddress; use radix_engine_common::network::NetworkDefinition; - #[enum_dispatch] pub trait AccountChangeIndexExtension { fn account_change_index_last_processed_state_version(&self) -> StateVersion; fn catchup_account_change_index(&self); } - #[enum_dispatch] pub trait RestoreDecember2023LostSubstates { fn restore_december_2023_lost_substates(&self, network: &NetworkDefinition); } - #[enum_dispatch] pub trait IterableAccountChangeIndex { fn get_state_versions_for_account_iter( &self, @@ -606,11 +592,10 @@ pub mod extensions { } pub mod measurement { - use super::*; + use std::cmp::max; /// A database capable of returning some metrics describing itself. - #[enum_dispatch] pub trait MeasurableDatabase { /// Gets approximate data volume statistics per table/map/cf (i.e. a category of persisted /// items, however it is called by the specific database implementation). @@ -673,7 +658,6 @@ pub mod gc { use radix_engine_stores::hash_tree::tree_store::NodeKey; /// A storage API tailored for the [`StateHashTreeGc`]. - #[enum_dispatch] pub trait StateHashTreeGcStore { /// Returns an iterator of stale hash tree parts, ordered by the state version at which /// they became stale, ascending. @@ -692,7 +676,6 @@ pub mod gc { } /// A storage API tailored for the [`LedgerProofsGc`]. - #[enum_dispatch] pub trait LedgerProofsGcStore { /// Returns the current state of the GC's progress. fn get_progress(&self) -> Option; From f12729a705313276be993a9b4123302551af6fc4 Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Wed, 31 Jan 2024 18:37:33 +0100 Subject: [PATCH 08/22] Using ad-hock snapshots wherever applicable. --- .../src/core_api/conversions/lts.rs | 15 +- .../src/core_api/conversions/receipt.rs | 13 +- ..._account_all_fungible_resource_balances.rs | 2 +- .../lts/state_account_deposit_behaviour.rs | 2 +- .../lts/state_account_resource_balance.rs | 2 +- .../stream_account_transaction_outcomes.rs | 2 +- .../lts/stream_transaction_outcomes.rs | 2 +- .../handlers/lts/transaction_construction.rs | 2 +- .../handlers/lts/transaction_status.rs | 4 +- .../handlers/state_access_controller.rs | 2 +- .../src/core_api/handlers/state_account.rs | 2 +- .../src/core_api/handlers/state_component.rs | 2 +- .../handlers/state_consensus_manager.rs | 6 +- .../core_api/handlers/state_non_fungible.rs | 2 +- .../src/core_api/handlers/state_package.rs | 2 +- .../src/core_api/handlers/state_resource.rs | 2 +- .../src/core_api/handlers/state_validator.rs | 2 +- .../handlers/status_network_status.rs | 2 +- .../src/core_api/handlers/status_scenarios.rs | 2 +- .../src/core_api/handlers/stream_proofs.rs | 20 +- .../core_api/handlers/stream_transactions.rs | 13 +- .../core_api/handlers/transaction_parse.rs | 3 +- .../core_api/handlers/transaction_preview.rs | 10 +- .../core_api/handlers/transaction_receipt.rs | 2 +- .../core_api/handlers/transaction_status.rs | 2 +- .../core-api-server/src/core_api/helpers.rs | 21 +- core-rust/node-common/src/locks.rs | 77 ------- .../src/jni/node_rust_environment.rs | 14 +- .../state-manager/src/jni/state_reader.rs | 7 +- .../src/jni/test_state_reader.rs | 45 ++-- .../src/jni/transaction_store.rs | 26 +-- .../src/jni/vertex_store_recovery.rs | 4 +- .../src/mempool/mempool_manager.rs | 7 +- .../protocol_update_committer.rs | 34 ++- .../protocol_updates/protocol_updaters.rs | 21 +- core-rust/state-manager/src/protocol/test.rs | 19 +- core-rust/state-manager/src/state_computer.rs | 113 ++++----- core-rust/state-manager/src/state_manager.rs | 27 +-- core-rust/state-manager/src/store/jmt_gc.rs | 23 +- core-rust/state-manager/src/store/mod.rs | 15 +- .../state-manager/src/store/proofs_gc.rs | 89 ++++--- core-rust/state-manager/src/store/rocks_db.rs | 217 ++++++++++++++---- core-rust/state-manager/src/test/mod.rs | 9 +- .../state-manager/src/transaction/preview.rs | 41 ++-- .../src/transaction/validation.rs | 58 +++-- 45 files changed, 487 insertions(+), 498 deletions(-) diff --git a/core-rust/core-api-server/src/core_api/conversions/lts.rs b/core-rust/core-api-server/src/core_api/conversions/lts.rs index d66c43bea6..459944552c 100644 --- a/core-rust/core-api-server/src/core_api/conversions/lts.rs +++ b/core-rust/core-api-server/src/core_api/conversions/lts.rs @@ -1,14 +1,13 @@ -use models::*; use radix_engine::{ system::system_modules::costing::RoyaltyRecipient, transaction::BalanceChange, types::{Decimal, GlobalAddress, IndexMap, ResourceAddress}, }; -use state_manager::store::{traits::SubstateNodeAncestryStore, StateManagerDatabase}; +use state_manager::store::traits::SubstateNodeAncestryStore; use state_manager::{ CommittedTransactionIdentifiers, LedgerTransactionOutcome, LocalTransactionReceipt, - StateVersion, TransactionTreeHash, + ReadableRocks, StateManagerDatabase, StateVersion, TransactionTreeHash, }; use radix_engine::transaction::{FeeDestination, FeeSource, TransactionFeeSummary}; @@ -18,7 +17,7 @@ use crate::core_api::*; #[tracing::instrument(skip_all)] pub fn to_api_lts_committed_transaction_outcome( - database: &StateManagerDatabase, + database: &StateManagerDatabase, context: &MappingContext, state_version: StateVersion, receipt: LocalTransactionReceipt, @@ -89,14 +88,14 @@ pub fn to_api_lts_committed_transaction_outcome( pub fn to_api_lts_entity_non_fungible_balance_changes( context: &MappingContext, global_balance_summary: &IndexMap>, -) -> Result, MappingError> { +) -> Result, MappingError> { let mut changes = Vec::new(); for (address, balance_changes) in global_balance_summary.iter() { for (resource, balance_change) in balance_changes.iter() { match balance_change { BalanceChange::Fungible(_) => {} BalanceChange::NonFungible { added, removed } => { - changes.push(LtsEntityNonFungibleBalanceChanges { + changes.push(models::LtsEntityNonFungibleBalanceChanges { entity_address: to_api_global_address(context, address)?, resource_address: to_api_resource_address(context, resource)?, added: added @@ -116,7 +115,7 @@ pub fn to_api_lts_entity_non_fungible_balance_changes( } pub fn to_api_lts_fungible_balance_changes( - database: &StateManagerDatabase, + database: &StateManagerDatabase, context: &MappingContext, fee_summary: &TransactionFeeSummary, fee_source: &FeeSource, @@ -136,7 +135,7 @@ pub fn to_api_lts_fungible_balance_changes( /// Uses the [`SubstateNodeAncestryStore`] (from the given DB) to transform the input /// `vault ID -> payment` map into a `global address -> balance change` map. fn resolve_global_fee_balance_changes( - database: &StateManagerDatabase, + database: &StateManagerDatabase, fee_source: &FeeSource, ) -> Result, MappingError> { let paying_vaults = &fee_source.paying_vaults; diff --git a/core-rust/core-api-server/src/core_api/conversions/receipt.rs b/core-rust/core-api-server/src/core_api/conversions/receipt.rs index d2940cbed1..6d9c8a7312 100644 --- a/core-rust/core-api-server/src/core_api/conversions/receipt.rs +++ b/core-rust/core-api-server/src/core_api/conversions/receipt.rs @@ -15,17 +15,16 @@ use radix_engine::transaction::{ }; use radix_engine_queries::typed_substate_layout::*; use radix_engine_store_interface::db_key_mapper::{MappedSubstateDatabase, SpreadPrefixKeyMapper}; -use state_manager::store::StateManagerDatabase; use transaction::prelude::TransactionCostingParameters; use state_manager::{ ApplicationEvent, BySubstate, DetailedTransactionOutcome, LedgerStateChanges, - LocalTransactionReceipt, PartitionChangeAction, PartitionReference, SubstateChangeAction, - SubstateReference, + LocalTransactionReceipt, PartitionChangeAction, PartitionReference, ReadableRocks, + StateManagerDatabase, SubstateChangeAction, SubstateReference, }; pub fn to_api_receipt( - database: Option<&StateManagerDatabase>, + database: Option<&StateManagerDatabase>, context: &MappingContext, receipt: LocalTransactionReceipt, ) -> Result { @@ -311,7 +310,7 @@ pub fn to_api_next_epoch( #[tracing::instrument(skip_all)] pub fn to_api_state_updates( - database: Option<&StateManagerDatabase>, + database: Option<&StateManagerDatabase>, context: &MappingContext, system_structures: &BySubstate, state_changes: &LedgerStateChanges, @@ -468,7 +467,7 @@ pub struct StateMappingLookups { impl StateMappingLookups { pub fn create_from_database( - database: Option<&StateManagerDatabase>, + database: Option<&StateManagerDatabase>, changes_to_map: &[(SubstateReference, TypedSubstateKey, &SubstateChangeAction)], ) -> Result { let Some(database) = database else { @@ -516,7 +515,7 @@ impl StateMappingLookups { } fn create_blueprint_type_lookups( - database: &StateManagerDatabase, + database: &StateManagerDatabase, typed_values: &[TypedSubstateValue], ) -> Result>, MappingError> { // Step 1 - work out what database reads we need to do diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs index 455e96f278..288db202d9 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs @@ -32,7 +32,7 @@ pub(crate) async fn handle_lts_state_account_all_fungible_resource_balances( )); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let header = read_current_ledger_header(database.deref()); let type_info: Option = read_optional_substate::( diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs index 145d163a52..d8e17e2161 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs @@ -53,7 +53,7 @@ pub(crate) async fn handle_lts_state_account_deposit_behaviour( .map_err(|err| err.into_response_error("badge"))?; // If the above checks were al fine, open database (and capture the "at state" information): - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let header = read_current_ledger_header(database.deref()); // Read out the field that must exist for non-virtual addresses: diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs index ba6fb414dd..10abcd531a 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs @@ -43,7 +43,7 @@ pub(crate) async fn handle_lts_state_account_fungible_resource_balance( )); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); if !account_address.as_node_id().is_global_virtual() { read_optional_substate::( diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/stream_account_transaction_outcomes.rs b/core-rust/core-api-server/src/core_api/handlers/lts/stream_account_transaction_outcomes.rs index 9a37b96e16..781a72d41a 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/stream_account_transaction_outcomes.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/stream_account_transaction_outcomes.rs @@ -42,7 +42,7 @@ pub(crate) async fn handle_lts_stream_account_transaction_outcomes( ))); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); if !database.is_local_transaction_execution_index_enabled() { return Err(client_error( diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/stream_transaction_outcomes.rs b/core-rust/core-api-server/src/core_api/handlers/lts/stream_transaction_outcomes.rs index 1e154cad32..b8479fe5de 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/stream_transaction_outcomes.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/stream_transaction_outcomes.rs @@ -32,7 +32,7 @@ pub(crate) async fn handle_lts_stream_transaction_outcomes( let limit = limit.try_into().expect("limit out of usize bounds"); - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); if !database.is_local_transaction_execution_index_enabled() { return Err(client_error( diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs index 121200d2bb..274659c74b 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs @@ -11,7 +11,7 @@ pub(crate) async fn handle_lts_transaction_construction( assert_matching_network(&request.network, &state.network)?; let mapping_context = MappingContext::new(&state.network); - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let consensus_manager_substate = read_mandatory_main_field_substate::( diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs index 917b72dc34..b9db5b2dbf 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs @@ -30,9 +30,7 @@ pub(crate) async fn handle_lts_transaction_status( pending_transaction_result_cache.peek_all_known_payloads_for_intent(&intent_hash); drop(pending_transaction_result_cache); - // TODO(locks): consider this (and other) usages of DB "read current" lock. *Carefully* migrate - // all applicable ones to "historical, non-locked" DB access. - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); if !database.is_local_transaction_execution_index_enabled() { return Err(client_error( diff --git a/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs b/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs index f0fa60f182..f942495a45 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs @@ -27,7 +27,7 @@ pub(crate) async fn handle_state_access_controller( return Err(client_error("Only access controller addresses work for this endpoint. Try another endpoint instead.")); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let access_controller_state_substate = read_optional_main_field_substate( database.deref(), diff --git a/core-rust/core-api-server/src/core_api/handlers/state_account.rs b/core-rust/core-api-server/src/core_api/handlers/state_account.rs index f197f2e375..d8f7ba45cf 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_account.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_account.rs @@ -24,7 +24,7 @@ pub(crate) async fn handle_state_account( return Err(client_error("Only account addresses starting account_ currently work with this endpoint. Try another endpoint instead.")); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let type_info = read_optional_substate( database.deref(), component_address.as_node_id(), diff --git a/core-rust/core-api-server/src/core_api/handlers/state_component.rs b/core-rust/core-api-server/src/core_api/handlers/state_component.rs index d3a635c118..ceb699a6a1 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_component.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_component.rs @@ -26,7 +26,7 @@ pub(crate) async fn handle_state_component( return Err(client_error("Only component addresses starting component_ currently work with this endpoint. Try another endpoint instead.")); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let type_info_substate = read_optional_substate( database.deref(), component_address.as_node_id(), diff --git a/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs b/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs index b7b6682635..f96abf5283 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs @@ -3,7 +3,7 @@ use radix_engine::blueprints::consensus_manager::*; use radix_engine::types::*; use state_manager::protocol::ProtocolVersionName; -use state_manager::StateManagerDatabase; +use state_manager::{ReadableRocks, StateManagerDatabase}; use std::ops::Deref; #[tracing::instrument(skip(state))] @@ -13,7 +13,7 @@ pub(crate) async fn handle_state_consensus_manager( ) -> Result, ResponseError<()>> { assert_matching_network(&request.network, &state.network)?; let mapping_context = MappingContext::new(&state.network); - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let config_substate = read_mandatory_main_field_substate( database.deref(), @@ -85,7 +85,7 @@ pub(crate) async fn handle_state_consensus_manager( } fn collect_current_validators_by_signalled_protocol_version( - database: &StateManagerDatabase, + database: &StateManagerDatabase, substate: ConsensusManagerCurrentValidatorSetFieldSubstate, ) -> Result> { let mut validators = ValidatorsBySignalledProtocolVersion::default(); diff --git a/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs b/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs index 745dd110bc..99ea4dd25c 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs @@ -27,7 +27,7 @@ pub(crate) async fn handle_state_non_fungible( return Err(client_error("Resource is not a non-fungible resource")); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let id_type = read_optional_main_field_substate::( diff --git a/core-rust/core-api-server/src/core_api/handlers/state_package.rs b/core-rust/core-api-server/src/core_api/handlers/state_package.rs index a967678f62..d930fa9fc0 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_package.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_package.rs @@ -16,7 +16,7 @@ pub(crate) async fn handle_state_package( let package_address = extract_package_address(&extraction_context, &request.package_address) .map_err(|err| err.into_response_error("package_address"))?; - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let owner_role_substate = read_optional_substate( database.deref(), diff --git a/core-rust/core-api-server/src/core_api/handlers/state_resource.rs b/core-rust/core-api-server/src/core_api/handlers/state_resource.rs index 6b5f2b27a7..1520c6bc36 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_resource.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_resource.rs @@ -30,7 +30,7 @@ pub(crate) async fn handle_state_resource( let resource_address = extract_resource_address(&extraction_context, &request.resource_address) .map_err(|err| err.into_response_error("resource_address"))?; - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let resource_node_id = resource_address.as_node_id(); let is_fungible = diff --git a/core-rust/core-api-server/src/core_api/handlers/state_validator.rs b/core-rust/core-api-server/src/core_api/handlers/state_validator.rs index 3e595ecf85..55d03f25e1 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_validator.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_validator.rs @@ -28,7 +28,7 @@ pub(crate) async fn handle_state_validator( )); } - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let validator_state_substate = read_optional_main_field_substate( database.deref(), diff --git a/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs b/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs index 8a36af653a..a0fd049727 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs @@ -14,7 +14,7 @@ pub(crate) async fn handle_status_network_status( assert_matching_network(&request.network, &state.network)?; let mapping_context = MappingContext::new(&state.network); - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); let (current_state_version, current_ledger_hashes) = database.get_top_ledger_hashes(); let current_protocol_version = state .state_manager diff --git a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs index 02985bf0fd..5a25c08b8d 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs @@ -15,7 +15,7 @@ pub(crate) async fn handle_status_scenarios( assert_matching_network(&request.network, &state.network)?; let context = MappingContext::new(&state.network); - let database = state.state_manager.database.access_non_locked_historical(); + let database = state.state_manager.database.access(); let scenarios = database.list_all_scenarios(); Ok(Json(models::ScenariosResponse { diff --git a/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs b/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs index 2b04f326df..1a37de5ada 100644 --- a/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs +++ b/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs @@ -1,7 +1,9 @@ use crate::core_api::*; -use state_manager::store::{traits::*, StateManagerDatabase}; -use state_manager::{LedgerProof, LedgerProofOrigin, StateVersion}; +use state_manager::store::traits::*; +use state_manager::{ + LedgerProof, LedgerProofOrigin, ReadableRocks, StateManagerDatabase, StateVersion, +}; use transaction::prelude::*; @@ -31,7 +33,7 @@ pub(crate) async fn handle_stream_proofs( extract_continuation_token::(request.continuation_token) .map_err(|err| err.into_response_error("continuation_token"))?; - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); use models::StreamProofsFilter::*; let mut proofs_iter = match *filter { @@ -77,7 +79,7 @@ pub(crate) async fn handle_stream_proofs( } fn iterate_all_proofs<'a>( - database: &'a StateManagerDatabase, + database: &'a StateManagerDatabase, continue_from_state_version: Option, from_state_version: StateVersion, ) -> Result< @@ -90,7 +92,7 @@ fn iterate_all_proofs<'a>( } fn iterate_end_of_epoch_proofs<'a>( - database: &'a StateManagerDatabase, + database: &'a StateManagerDatabase, continue_from_state_version: Option, from_epoch: Epoch, ) -> Result< @@ -111,7 +113,7 @@ fn iterate_end_of_epoch_proofs<'a>( } fn iterate_protocol_update_initialization_proofs<'a>( - database: &'a StateManagerDatabase, + database: &'a StateManagerDatabase, continue_from_state_version: Option, from_state_version: StateVersion, ) -> Result< @@ -124,7 +126,7 @@ fn iterate_protocol_update_initialization_proofs<'a>( } fn iterate_protocol_update_execution_proofs<'a>( - database: &'a StateManagerDatabase, + database: &'a StateManagerDatabase, continue_from_state_version: Option, from_state_version: StateVersion, protocol_version: Option, @@ -152,7 +154,7 @@ fn iterate_protocol_update_execution_proofs<'a>( } fn extract_from_state_version( - database: &StateManagerDatabase, + database: &StateManagerDatabase, from_state_version: Option, ) -> Result> { let Some(from_state_version) = from_state_version else { @@ -180,7 +182,7 @@ fn extract_from_state_version( fn extract_from_epoch( mapping_context: &MappingContext, - database: &StateManagerDatabase, + database: &StateManagerDatabase, from_epoch: Option, ) -> Result> { let Some(from_epoch) = from_epoch else { diff --git a/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs b/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs index 8f7485c503..19ade869d0 100644 --- a/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs +++ b/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs @@ -2,17 +2,18 @@ use radix_engine::track::{ BatchPartitionStateUpdate, NodeStateUpdates, PartitionStateUpdates, StateUpdates, }; use std::iter; +use std::ops::Deref; use crate::core_api::*; use radix_engine::types::hash; use radix_engine_store_interface::interface::{DatabaseUpdate, DbSubstateValue}; -use state_manager::store::{traits::*, StateManagerDatabase}; +use state_manager::store::traits::*; use state_manager::transaction::*; use state_manager::{ CommittedTransactionIdentifiers, LedgerHeader, LedgerProof, LedgerProofOrigin, - LocalTransactionReceipt, StateVersion, + LocalTransactionReceipt, ReadableRocks, StateManagerDatabase, StateVersion, }; use transaction::manifest; @@ -54,7 +55,7 @@ pub(crate) async fn handle_stream_transactions( let limit = limit.try_into().expect("limit out of usize bounds"); - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); if !database.is_local_transaction_execution_index_enabled() { return Err(client_error( @@ -123,7 +124,7 @@ pub(crate) async fn handle_stream_transactions( } })?; let committed_transaction = to_api_committed_transaction( - &database, + database.deref(), &mapping_context, state_version, raw, @@ -277,7 +278,7 @@ pub fn to_api_ledger_header( #[tracing::instrument(skip_all)] pub fn to_api_committed_transaction( - database: &StateManagerDatabase, + database: &StateManagerDatabase, context: &MappingContext, state_version: StateVersion, raw_ledger_transaction: RawLedgerTransaction, @@ -623,7 +624,7 @@ pub fn to_api_system_transaction( } fn to_api_balance_changes( - database: &StateManagerDatabase, + database: &StateManagerDatabase, context: &MappingContext, receipt: &LocalTransactionReceipt, ) -> Result { diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs index 3686f6cb23..e7ff88f65b 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs @@ -11,7 +11,6 @@ use models::transaction_parse_response::TransactionParseResponse; use state_manager::mempool::pending_transaction_result_cache::RejectionReason; use state_manager::transaction::*; -use state_manager::store::StateManagerDatabase; use transaction::prelude::*; use super::{ @@ -23,7 +22,7 @@ pub struct ParseContext<'a> { response_mode: ResponseMode, validation_mode: ValidationMode, user_transaction_validator: NotarizedTransactionValidator, - committability_validator: &'a CommittabilityValidator, + committability_validator: &'a CommittabilityValidator, } pub(crate) async fn handle_transaction_parse( diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs index 6dbd291ca4..3b9a8dfa2e 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs @@ -4,7 +4,9 @@ use radix_engine::transaction::*; use std::ops::Range; use state_manager::transaction::ProcessedPreviewResult; -use state_manager::{ExecutionFeeData, LocalTransactionReceipt, PreviewRequest}; +use state_manager::{ + ActualStateManagerDatabase, ExecutionFeeData, LocalTransactionReceipt, PreviewRequest, +}; use transaction::manifest; use transaction::manifest::BlobProvider; use transaction::model::{ @@ -172,7 +174,11 @@ fn to_api_response( models::TransactionPreviewResponse { at_ledger_state, encoded_receipt, - receipt: Box::new(to_api_receipt(None, context, local_receipt)?), + receipt: Box::new(to_api_receipt( + None::<&ActualStateManagerDatabase>, + context, + local_receipt, + )?), instruction_resource_changes, logs, } diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_receipt.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_receipt.rs index 6efb61931d..bb5b4c5b81 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_receipt.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_receipt.rs @@ -17,7 +17,7 @@ pub(crate) async fn handle_transaction_receipt( let intent_hash = extract_intent_hash(&extraction_context, request.intent_hash) .map_err(|err| err.into_response_error("intent_hash"))?; - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); if !database.is_local_transaction_execution_index_enabled() { return Err(client_error( diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs index 6067edb5a9..b18741e3bc 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs @@ -30,7 +30,7 @@ pub(crate) async fn handle_transaction_status( pending_transaction_result_cache.peek_all_known_payloads_for_intent(&intent_hash); drop(pending_transaction_result_cache); - let database = state.state_manager.database.read_current(); + let database = state.state_manager.database.snapshot(); if !database.is_local_transaction_execution_index_enabled() { return Err(client_error( diff --git a/core-rust/core-api-server/src/core_api/helpers.rs b/core-rust/core-api-server/src/core_api/helpers.rs index 26d6a49d12..c72d4d3a3d 100644 --- a/core-rust/core-api-server/src/core_api/helpers.rs +++ b/core-rust/core-api-server/src/core_api/helpers.rs @@ -5,8 +5,7 @@ use radix_engine_interface::api::CollectionIndex; use radix_engine_store_interface::{db_key_mapper::*, interface::SubstateDatabase}; use serde::Serialize; use state_manager::store::traits::*; -use state_manager::store::StateManagerDatabase; -use state_manager::LedgerHeader; +use state_manager::{LedgerHeader, ReadableRocks, StateManagerDatabase}; use std::io::Write; use super::*; @@ -14,7 +13,7 @@ use super::*; #[allow(unused)] pub(crate) fn read_typed_substate( context: &MappingContext, - database: &StateManagerDatabase, + database: &StateManagerDatabase, node_id: &NodeId, partition_number: PartitionNumber, substate_key: &SubstateKey, @@ -39,7 +38,7 @@ pub(crate) fn read_typed_substate( #[tracing::instrument(skip_all)] pub(crate) fn read_mandatory_main_field_substate( - database: &StateManagerDatabase, + database: &StateManagerDatabase, node_id: &NodeId, substate_key: &SubstateKey, ) -> Result, ResponseError<()>> { @@ -53,7 +52,7 @@ pub(crate) fn read_mandatory_main_field_substate( #[tracing::instrument(skip_all)] pub(crate) fn read_mandatory_substate( - database: &StateManagerDatabase, + database: &StateManagerDatabase, node_id: &NodeId, partition_number: PartitionNumber, substate_key: &SubstateKey, @@ -77,7 +76,7 @@ pub(crate) fn read_mandatory_substate( #[tracing::instrument(skip_all)] pub(crate) fn read_optional_main_field_substate( - database: &StateManagerDatabase, + database: &StateManagerDatabase, node_id: &NodeId, substate_key: &SubstateKey, ) -> Option> { @@ -86,7 +85,7 @@ pub(crate) fn read_optional_main_field_substate( #[tracing::instrument(skip_all)] pub(crate) fn read_optional_collection_substate( - database: &StateManagerDatabase, + database: &StateManagerDatabase, node_id: &NodeId, collection_index: CollectionIndex, substate_key: &SubstateKey, @@ -107,7 +106,7 @@ pub(crate) fn read_optional_collection_substate( #[tracing::instrument(skip_all)] pub(crate) fn read_optional_collection_substate_value( - database: &StateManagerDatabase, + database: &StateManagerDatabase, node_id: &NodeId, collection_index: CollectionIndex, substate_key: &SubstateKey, @@ -118,7 +117,7 @@ pub(crate) fn read_optional_collection_substate_value( #[tracing::instrument(skip_all)] pub(crate) fn read_optional_substate( - database: &StateManagerDatabase, + database: &StateManagerDatabase, node_id: &NodeId, partition_number: PartitionNumber, substate_key: &SubstateKey, @@ -127,7 +126,9 @@ pub(crate) fn read_optional_substate( } #[tracing::instrument(skip_all)] -pub(crate) fn read_current_ledger_header(database: &StateManagerDatabase) -> LedgerHeader { +pub(crate) fn read_current_ledger_header( + database: &StateManagerDatabase, +) -> LedgerHeader { database .get_latest_proof() .expect("proof for outputted state must exist") diff --git a/core-rust/node-common/src/locks.rs b/core-rust/node-common/src/locks.rs index 35814b28f5..58200405c8 100644 --- a/core-rust/node-common/src/locks.rs +++ b/core-rust/node-common/src/locks.rs @@ -187,19 +187,6 @@ impl LockFactory { } } - /// Creates a new state lock with the current configuration. - /// Note: this is a custom lock primitive - please see its documentation. - pub fn new_state_lock(self, value: T) -> StateLock { - StateLock { - underlying: self.named("current").new_rwlock(()), - value, - access_non_locked_historical_listener: self - .named("historical") - .not_stopping_on_panic() - .into_listener(), - } - } - /// Turns the factory (i.e. its current configuration) into a [`LockListener`] which adds the /// requested features to the lock. fn into_listener(self) -> ActualLockListener { @@ -246,70 +233,6 @@ impl RwLock { } } -/// A custom lock primitive guarding a "current state" of a value composed from an (immutable) -/// "historical" and (live) "current" parts of state. -/// The assumption is that the current state needs a classic [`RwLock`] access, while the historical -/// state can be accessed freely, without obtaining any lock. -/// The lock caller is responsible for distinguishing proper current vs historical access. -pub struct StateLock { - // TODO(wip): Re-purpose to `SnapshotLock` - underlying: RwLock<()>, // we use our own primitive to lock a marker for current state - value: T, - access_non_locked_historical_listener: ActualLockListener, // only for metrics -} - -impl StateLock { - /// Locks the current state for reading. - /// This method should be used when caller needs a series of reads referring to the current - /// state (it "freezes" the notion of "current"). - pub fn read_current(&self) -> impl Deref + '_ { - StateLockGuard { - underlying: self.underlying.read(), - value: &self.value, - } - } - - /// Locks the current state for writing. - /// This method should be used when caller wants to update the guarded value in a way which - /// changes the notion of "current". - /// Please note that this method deliberately returns [`Deref`] (not [`DerefMut`]), since it - /// would create an undefined behaviour (`&` and `&mut` co-existing). The guarded value is - /// assumed to use an interior mutability (i.e. expose mutating methods via `&`). - pub fn write_current(&self) -> impl Deref + '_ { - StateLockGuard { - underlying: self.underlying.write(), - value: &self.value, - } - } - - /// Returns a reference to the guarded value, without locking anything. - /// This method should be used when the caller wants to interact selectively with pieces of the - /// historical state, in a way known to be safe. - /// Note: functionally, we could return a `&T` here directly, but returning a "guard" allows us - /// to measure usage of this method (in the same way as we do for lock guards). - pub fn access_non_locked_historical(&self) -> impl Deref + '_ { - LockGuard::new( - || &self.value, - self.access_non_locked_historical_listener.clone(), - ) - } -} - -/// A read guard of a [`StateLock`]. -pub struct StateLockGuard<'a, T, U> { - #[allow(dead_code)] // only held to release the lock when dropped - underlying: U, - value: &'a T, -} - -impl<'a, T: 'a, U> Deref for StateLockGuard<'a, T, U> { - type Target = T; - - fn deref(&self) -> &Self::Target { - self.value - } -} - // Only iternals below: /// A static type of a [`LockListener`] which provides the extra features to locks produced by our diff --git a/core-rust/state-manager/src/jni/node_rust_environment.rs b/core-rust/state-manager/src/jni/node_rust_environment.rs index fbb8fe5a89..dc7e21ea58 100644 --- a/core-rust/state-manager/src/jni/node_rust_environment.rs +++ b/core-rust/state-manager/src/jni/node_rust_environment.rs @@ -83,11 +83,9 @@ use crate::mempool_manager::MempoolManager; use crate::mempool_relay_dispatcher::MempoolRelayDispatcher; use crate::priority_mempool::PriorityMempool; -use crate::store::StateManagerDatabase; - use super::fatal_panic_handler::FatalPanicHandler; -use crate::{StateComputer, StateManager, StateManagerConfig}; +use crate::{StateComputer, StateManager, StateManagerConfig, StateManagerDatabaseLock}; const POINTER_JNI_FIELD_NAME: &str = "rustNodeRustEnvironmentPointer"; @@ -189,20 +187,14 @@ impl JNINodeRustEnvironment { .unwrap() } - pub fn get_state_computer( - env: &JNIEnv, - j_node_rust_env: JObject, - ) -> Arc> { + pub fn get_state_computer(env: &JNIEnv, j_node_rust_env: JObject) -> Arc { Self::get(env, j_node_rust_env) .state_manager .state_computer .clone() } - pub fn get_database( - env: &JNIEnv, - j_node_rust_env: JObject, - ) -> Arc> { + pub fn get_database(env: &JNIEnv, j_node_rust_env: JObject) -> Arc { Self::get(env, j_node_rust_env) .state_manager .database diff --git a/core-rust/state-manager/src/jni/state_reader.rs b/core-rust/state-manager/src/jni/state_reader.rs index b2a5caafdf..66de0f8a01 100644 --- a/core-rust/state-manager/src/jni/state_reader.rs +++ b/core-rust/state-manager/src/jni/state_reader.rs @@ -93,10 +93,9 @@ extern "system" fn Java_com_radixdlt_state_RustStateReader_getValidatorProtocolU &env, request_payload, |validator_address: ComponentAddress| -> JavaResult> { - let result = JNINodeRustEnvironment::get(&env, j_node_rust_env) - .state_manager - .database - .access_non_locked_historical() + let database = JNINodeRustEnvironment::get_database(&env, j_node_rust_env); + let result = database + .snapshot() .get_mapped::>( &validator_address.into_node_id(), MAIN_BASE_PARTITION, diff --git a/core-rust/state-manager/src/jni/test_state_reader.rs b/core-rust/state-manager/src/jni/test_state_reader.rs index 85d7a9a955..87137b813d 100644 --- a/core-rust/state-manager/src/jni/test_state_reader.rs +++ b/core-rust/state-manager/src/jni/test_state_reader.rs @@ -129,14 +129,14 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_getTransactionAtSt |state_version_number: u64| -> Option { let state_version = StateVersion::of(state_version_number); let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_database = database.access_non_locked_historical(); - let committed_transaction = read_database.get_committed_transaction(state_version)?; + let database = database.snapshot(); + let committed_transaction = database.get_committed_transaction(state_version)?; let committed_identifiers = - read_database.get_committed_transaction_identifiers(state_version)?; + database.get_committed_transaction_identifiers(state_version)?; let committed_ledger_transaction_receipt = - read_database.get_committed_ledger_transaction_receipt(state_version)?; + database.get_committed_ledger_transaction_receipt(state_version)?; let local_transaction_execution = - read_database.get_committed_local_transaction_execution(state_version)?; + database.get_committed_local_transaction_execution(state_version)?; Some(ExecutedTransaction { ledger_transaction_hash: committed_identifiers.payload.ledger_transaction_hash, @@ -171,9 +171,9 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_getTransactionDeta |state_version_number: u64| -> Option { let state_version = StateVersion::of(state_version_number); let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_database = database.access_non_locked_historical(); - let committed_local_transaction_execution = - read_database.get_committed_local_transaction_execution(state_version)?; + let committed_local_transaction_execution = database + .snapshot() + .get_committed_local_transaction_execution(state_version)?; Some(TransactionDetails { new_component_addresses: committed_local_transaction_execution @@ -200,10 +200,10 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_componentXrdAmount |component_address: ComponentAddress| -> Decimal { let node_id = component_address.as_node_id(); let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_store = database.read_current(); + let database = database.snapshot(); // a quick fix for handling virtual accounts - if read_store + if database .get_mapped::( node_id, TYPE_INFO_FIELD_PARTITION, @@ -211,7 +211,7 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_componentXrdAmount ) .is_some() { - let mut accounter = ResourceAccounter::new(read_store.deref()); + let mut accounter = ResourceAccounter::new(database.deref()); accounter.traverse(*node_id); let balances = accounter.close().balances; balances.get(&XRD).cloned().unwrap_or_else(Decimal::zero) @@ -234,8 +234,8 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_validatorInfo( request_payload, |validator_address: ComponentAddress| -> JavaValidatorInfo { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_store = database.read_current(); - let validator_state = read_store + let validator_state = database + .snapshot() .get_mapped::( validator_address.as_node_id(), MAIN_BASE_PARTITION, @@ -262,8 +262,8 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_epoch( ) -> jbyteArray { jni_sbor_coded_call(&env, request_payload, |_: ()| -> u64 { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_store = database.read_current(); - read_store.get_epoch().number() + let database = database.snapshot(); + database.get_epoch().number() }) } @@ -276,8 +276,8 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_leastStaleStateHas ) -> jbyteArray { jni_sbor_coded_call(&env, request_payload, |_: ()| -> u64 { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_store = database.access_non_locked_historical(); - let least_stale_state_version = read_store + let least_stale_state_version = database + .access() // the `get_stale_tree_parts_iter()` is inside a trait requiring writeability .get_stale_tree_parts_iter() .next() .map(|(state_version, _)| state_version) @@ -296,9 +296,9 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_countProofsWithinE jni_sbor_coded_call(&env, request_payload, |epoch_number: u64| -> usize { let epoch = Epoch::of(epoch_number); let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_store = database.access_non_locked_historical(); - let epoch_proof = read_store.get_epoch_proof(epoch).unwrap(); - read_store + let database = database.snapshot(); + let epoch_proof = database.get_epoch_proof(epoch).unwrap(); + database .get_proof_iter(epoch_proof.ledger_header.state_version.next().unwrap()) .take_while(|proof| proof.ledger_header.epoch == epoch) .count() @@ -317,8 +317,9 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_getNodeGlobalRoot( request_payload, |internal_address: InternalAddress| -> Option { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let read_store = database.access_non_locked_historical(); - let node_ancestry_record = read_store.get_ancestry(internal_address.as_node_id()); + let node_ancestry_record = database + .snapshot() + .get_ancestry(internal_address.as_node_id()); node_ancestry_record.map(|node_ancestry_record| { GlobalAddress::new_or_panic(node_ancestry_record.root.0 .0) }) diff --git a/core-rust/state-manager/src/jni/transaction_store.rs b/core-rust/state-manager/src/jni/transaction_store.rs index c9e50da2c0..11b7788c96 100644 --- a/core-rust/state-manager/src/jni/transaction_store.rs +++ b/core-rust/state-manager/src/jni/transaction_store.rs @@ -92,9 +92,7 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge request_payload, |request: TxnsAndProofRequest| -> Result { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - // Note: even though we read a strictly historical state here, we cannot use the - // "historical, non-locked" DB access - please see the TODO note at `LedgerProofsGc`. - let res = database.read_current().get_syncable_txns_and_proof( + let res = database.snapshot().get_syncable_txns_and_proof( StateVersion::of(request.start_state_version_inclusive), request .limits_config @@ -118,7 +116,7 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge request_payload, |_no_args: ()| -> Option { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let proof = database.read_current().get_latest_proof(); + let proof = database.snapshot().get_latest_proof(); proof }, ) @@ -136,7 +134,7 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge request_payload, |_no_args: ()| -> Option { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let proof = database.read_current().get_latest_epoch_proof(); + let proof = database.snapshot().get_latest_epoch_proof(); proof }, ) @@ -154,9 +152,7 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge request_payload, |_no_args: ()| -> Option { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let proof = database - .read_current() - .get_latest_protocol_update_init_proof(); + let proof = database.snapshot().get_latest_protocol_update_init_proof(); proof }, ) @@ -175,7 +171,7 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge |_no_args: ()| -> Option { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); let proof = database - .read_current() + .snapshot() .get_latest_protocol_update_execution_proof(); proof }, @@ -191,9 +187,7 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge ) -> jbyteArray { jni_sbor_coded_call(&env, request_payload, |_: ()| -> Option { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let proof = database - .access_non_locked_historical() - .get_post_genesis_epoch_proof(); + let proof = database.snapshot().get_post_genesis_epoch_proof(); proof }) } @@ -210,9 +204,7 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge request_payload, |epoch: Epoch| -> Option { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let proof = database - .access_non_locked_historical() - .get_epoch_proof(epoch); + let proof = database.snapshot().get_epoch_proof(epoch); proof }, ) @@ -230,8 +222,8 @@ extern "system" fn Java_com_radixdlt_transaction_REv2TransactionAndProofStore_ge request_payload, |epoch: Epoch| -> Option> { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let non_locked_db = database.access_non_locked_historical(); - let mut epoch_change_event_iter = epoch_change_iter(non_locked_db.deref(), epoch); + let database = database.snapshot(); + let mut epoch_change_event_iter = epoch_change_iter(database.deref(), epoch); let maybe_epoch_change = epoch_change_event_iter.next(); maybe_epoch_change .filter(|(_, epoch_change_event)| epoch_change_event.epoch == epoch) diff --git a/core-rust/state-manager/src/jni/vertex_store_recovery.rs b/core-rust/state-manager/src/jni/vertex_store_recovery.rs index 2509cb1d2f..119773d268 100644 --- a/core-rust/state-manager/src/jni/vertex_store_recovery.rs +++ b/core-rust/state-manager/src/jni/vertex_store_recovery.rs @@ -78,7 +78,7 @@ extern "system" fn Java_com_radixdlt_recovery_VertexStoreRecovery_getVertexStore ) -> jbyteArray { jni_sbor_coded_call(&env, request_payload, |_: ()| -> Option> { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let vertex_store_blob = database.read_current().get_vertex_store(); + let vertex_store_blob = database.access().get_vertex_store(); vertex_store_blob.map(|blob| blob.0) }) } @@ -93,7 +93,7 @@ extern "system" fn Java_com_radixdlt_recovery_VertexStoreRecovery_saveVertexStor jni_sbor_coded_call(&env, request_payload, |vertex_store_bytes: Vec| { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); database - .write_current() + .access() .save_vertex_store(VertexStoreBlobV1(vertex_store_bytes)); }) } diff --git a/core-rust/state-manager/src/mempool/mempool_manager.rs b/core-rust/state-manager/src/mempool/mempool_manager.rs index d2de8a0289..f9db16f5cf 100644 --- a/core-rust/state-manager/src/mempool/mempool_manager.rs +++ b/core-rust/state-manager/src/mempool/mempool_manager.rs @@ -76,7 +76,6 @@ use std::sync::Arc; use std::time::Instant; use crate::mempool_relay_dispatcher::MempoolRelayDispatcher; -use crate::store::StateManagerDatabase; use crate::transaction::{ CachedCommittabilityValidator, ForceRecalculation, PrevalidatedCheckMetadata, }; @@ -87,7 +86,7 @@ use tracing::warn; pub struct MempoolManager { mempool: Arc>, relay_dispatcher: Option, - cached_committability_validator: CachedCommittabilityValidator, + cached_committability_validator: CachedCommittabilityValidator, metrics: MempoolManagerMetrics, } @@ -96,7 +95,7 @@ impl MempoolManager { pub fn new( mempool: Arc>, relay_dispatcher: MempoolRelayDispatcher, - cached_committability_validator: CachedCommittabilityValidator, + cached_committability_validator: CachedCommittabilityValidator, metric_registry: &Registry, ) -> Self { Self { @@ -110,7 +109,7 @@ impl MempoolManager { /// Creates a testing manager (without the JNI-based relay dispatcher) and registers its metrics. pub fn new_for_testing( mempool: Arc>, - cached_committability_validator: CachedCommittabilityValidator, + cached_committability_validator: CachedCommittabilityValidator, metric_registry: &Registry, ) -> Self { Self { diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs index 8b9f7a3c15..af43282258 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs @@ -1,20 +1,18 @@ // This file contains the protocol update logic for specific protocol versions -use std::ops::Deref; -use std::sync::Arc; - -use node_common::locks::{LockFactory, RwLock, StateLock}; +use node_common::locks::{LockFactory, RwLock}; use radix_engine::prelude::*; use transaction::prelude::*; use crate::epoch_handling::EpochAwareAccuTreeFactory; use crate::protocol::*; +use crate::query::TransactionIdentifierLoader; use crate::traits::*; use crate::transaction::*; use crate::{ CommittedTransactionIdentifiers, ExecutionCache, LedgerHeader, LedgerProof, LedgerProofOrigin, - StateManagerDatabase, + ReadableStore, }; #[derive(Debug, Clone, PartialEq, Eq, Sbor)] @@ -46,23 +44,26 @@ enum ProtocolUpdateProgress { /// A helper that manages committing flash transactions state updates. /// It handles the logic to fulfill the resumability contract of "execute_remaining_state_updates" /// by storing the index of a previously committed transaction batch in the ledger proof. -pub struct ProtocolUpdateTransactionCommitter { +pub struct ProtocolUpdateTransactionCommitter<'s, S> { protocol_version_name: ProtocolVersionName, - store: Arc>, + database: &'s S, execution_configurator: RwLock, ledger_transaction_validator: LedgerTransactionValidator, } -impl ProtocolUpdateTransactionCommitter { +impl<'s, S> ProtocolUpdateTransactionCommitter<'s, S> +where + S: ReadableStore + QueryableProofStore + TransactionIdentifierLoader + CommitStore, +{ pub fn new( protocol_version_name: ProtocolVersionName, - store: Arc>, + database: &'s S, execution_configurator: ExecutionConfigurator, ledger_transaction_validator: LedgerTransactionValidator, ) -> Self { Self { protocol_version_name, - store, + database, execution_configurator: LockFactory::new("protocol_update") .new_rwlock(execution_configurator), ledger_transaction_validator, @@ -70,7 +71,7 @@ impl ProtocolUpdateTransactionCommitter { } fn read_protocol_update_progress(&self) -> ProtocolUpdateProgress { - let Some(latest_proof) = self.store.read_current().get_latest_proof() else { + let Some(latest_proof) = self.database.get_latest_proof() else { return ProtocolUpdateProgress::NotUpdating; }; @@ -147,11 +148,8 @@ impl ProtocolUpdateTransactionCommitter { .next_committable_batch_idx() .expect("Can't commit next protocol update batch"); - // We are performing a pretty classic "transaction", so (for pure correctness) we obtain the - // write lock. In practice, however, we execute this logic only during boot-up or within an - // explicit (Java-side) "advance ledger lock" anyway. - let write_store = self.store.write_current(); - let latest_proof: LedgerProof = write_store + let latest_proof: LedgerProof = self + .database .get_latest_proof() .expect("Pre-genesis protocol updates are currently not supported"); let latest_header = latest_proof.ledger_header; @@ -180,7 +178,7 @@ impl ProtocolUpdateTransactionCommitter { }; let mut series_executor = TransactionSeriesExecutor::new( - write_store.deref(), + self.database, &execution_cache, &self.execution_configurator, dummy_protocol_state, @@ -264,6 +262,6 @@ impl ProtocolUpdateTransactionCommitter { new_substate_node_ancestry_records: new_node_ancestry_records, }; - write_store.commit(commit_bundle); + self.database.commit(commit_bundle); } } diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs index e5e03c6716..a7d2285595 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs @@ -1,22 +1,21 @@ -use node_common::locks::StateLock; use std::ops::Deref; use std::sync::Arc; use crate::protocol::*; use crate::traits::*; -use crate::StateManagerDatabase; +use crate::StateManagerDatabaseLock; pub trait ProtocolUpdater { /// Executes these state updates associated with the given protocol version /// that haven't yet been applied /// (hence "remaining", e.g. if node is restarted mid-protocol update). - fn execute_remaining_state_updates(&self, store: Arc>); + fn execute_remaining_state_updates(&self, database: Arc); } pub struct NoOpProtocolUpdater; impl ProtocolUpdater for NoOpProtocolUpdater { - fn execute_remaining_state_updates(&self, _store: Arc>) { + fn execute_remaining_state_updates(&self, _database: Arc) { // no-op } } @@ -42,10 +41,11 @@ impl BatchedUpdater { } impl ProtocolUpdater for BatchedUpdater { - fn execute_remaining_state_updates(&self, store: Arc>) { + fn execute_remaining_state_updates(&self, database: Arc) { + let database = database.lock(); let mut txn_committer = ProtocolUpdateTransactionCommitter::new( self.new_protocol_version.clone(), - store.clone(), + database.deref(), // The costing and logging parameters (of the Engine) are not really used for flash // transactions; let's still pass sane values. self.new_state_computer_config @@ -55,12 +55,9 @@ impl ProtocolUpdater for BatchedUpdater { ); while let Some(next_batch_idx) = txn_committer.next_committable_batch_idx() { - let batch = { - // Put it in a scope to ensure the read lock is dropped before we attempt to commit - let read_store = store.read_current(); - self.resolver - .generate_batch(read_store.deref(), next_batch_idx) - }; + let batch = self + .resolver + .generate_batch(database.deref(), next_batch_idx); match batch { Some(flash_txns) => { txn_committer.commit_batch(flash_txns); diff --git a/core-rust/state-manager/src/protocol/test.rs b/core-rust/state-manager/src/protocol/test.rs index 9bb0b60c26..a7ca7ee55b 100644 --- a/core-rust/state-manager/src/protocol/test.rs +++ b/core-rust/state-manager/src/protocol/test.rs @@ -116,9 +116,8 @@ fn flash_protocol_update_test() { .state_computer .execute_genesis_for_unit_tests_with_default_config(); // Now we can prepare the state updates based on the initialized database - let state_updates = generate_validator_fee_fix_state_updates( - tmp_state_manager.database.read_current().deref(), - ); + let state_updates = + generate_validator_fee_fix_state_updates(tmp_state_manager.database.access().deref()); state_updates }; @@ -152,22 +151,20 @@ fn flash_protocol_update_test() { Some(custom_v2_protocol_version.clone()) ); - let pre_protocol_update_state_version = - state_manager.database.read_current().max_state_version(); + let database = state_manager.database.access(); + let pre_protocol_update_state_version = database.max_state_version(); // Now let's apply the protocol update (this would normally be called by Java) state_manager.apply_protocol_update(&custom_v2_protocol_version); - let read_db = state_manager.database.read_current(); - // Verify a transaction has been committed assert_eq!( - read_db.max_state_version(), + database.max_state_version(), pre_protocol_update_state_version.next().unwrap() ); // Verify that a new consensus manager config has been flashed - let config_substate = read_db.get_mapped::>( + let config_substate = database.get_mapped::>( CONSENSUS_MANAGER.as_node_id(), MAIN_BASE_PARTITION, &ConsensusManagerField::Configuration.into() @@ -183,10 +180,10 @@ fn flash_protocol_update_test() { ); // Verify the resultant protocol update execution proof - let latest_execution_proof: LedgerProof = read_db + let latest_execution_proof: LedgerProof = database .get_latest_protocol_update_execution_proof() .unwrap(); - let latest_proof_post_update: LedgerProof = read_db.get_latest_proof().unwrap(); + let latest_proof_post_update: LedgerProof = database.get_latest_proof().unwrap(); // Make sure that the latest protocol update execution proof // is the latest proof overall, as we expect. diff --git a/core-rust/state-manager/src/state_computer.rs b/core-rust/state-manager/src/state_computer.rs index c791af2152..c11816a7d7 100644 --- a/core-rust/state-manager/src/state_computer.rs +++ b/core-rust/state-manager/src/state_computer.rs @@ -85,7 +85,7 @@ use transaction_scenarios::scenario::DescribedAddress as ScenarioDescribedAddres use transaction_scenarios::scenario::*; use transaction_scenarios::scenarios::*; -use node_common::locks::{LockFactory, Mutex, RwLock, StateLock}; +use node_common::locks::{LockFactory, Mutex, RwLock}; use prometheus::Registry; use tracing::{debug, info, warn}; @@ -95,13 +95,14 @@ use crate::store::traits::scenario::{ ExecutedScenarioTransaction, ScenarioSequenceNumber, }; +use crate::accumulator_tree::storage::ReadableAccuTreeStore; use std::ops::Deref; use std::sync::Arc; use std::time::{Instant, SystemTime}; -pub struct StateComputer { +pub struct StateComputer { network: NetworkDefinition, - store: Arc>, + database: Arc, mempool_manager: Arc, execution_configurator: Arc>, pending_transaction_result_cache: Arc>, @@ -115,21 +116,13 @@ pub struct StateComputer { protocol_state: RwLock, } -impl< - S: QueryableProofStore - + IterableProofStore - + QueryableTransactionStore - + TransactionIdentifierLoader - + CommitStore - + ReadableStore, - > StateComputer -{ +impl StateComputer { // TODO: refactor and maybe make clippy happy too #[allow(clippy::too_many_arguments)] pub fn new( network: &NetworkDefinition, vertex_limits_config: VertexLimitsConfig, - store: Arc>, + database: Arc, mempool_manager: Arc, execution_configurator: Arc>, pending_transaction_result_cache: Arc>, @@ -137,9 +130,9 @@ impl< lock_factory: LockFactory, initial_updatable_config: &ProtocolStateComputerConfig, initial_protocol_state: ProtocolState, - ) -> StateComputer { - let (current_transaction_root, current_ledger_proposer_timestamp_ms) = store - .read_current() + ) -> Self { + let (current_transaction_root, current_ledger_proposer_timestamp_ms) = database + .lock() .get_latest_proof() .map(|proof| proof.ledger_header) .map(|header| (header.hashes.transaction_root, header.proposer_timestamp_ms)) @@ -152,7 +145,7 @@ impl< StateComputer { network: network.clone(), - store, + database, mempool_manager, execution_configurator, pending_transaction_result_cache, @@ -279,12 +272,7 @@ pub struct GenesisCommitRequest { require_success: bool, } -impl StateComputer -where - S: ReadableStore, - S: for<'a> TransactionIndex<&'a IntentHash>, - S: QueryableProofStore + TransactionIdentifierLoader, -{ +impl StateComputer { pub fn prepare_genesis(&self, genesis_transaction: GenesisTransaction) -> GenesisPrepareResult { let raw = LedgerTransaction::Genesis(Box::new(genesis_transaction)) .to_raw() @@ -296,8 +284,8 @@ where .read() .validate_genesis(prepared); - let read_store = self.store.read_current(); - let mut series_executor = self.start_series_execution(read_store.deref()); + let database = self.database.lock(); + let mut series_executor = self.start_series_execution(database.deref()); let commit = series_executor .execute_and_update_state(&validated, "genesis") @@ -332,15 +320,15 @@ where .validate_user_or_round_update(prepared_ledger_transaction) .unwrap_or_else(|_| panic!("Expected that {} was valid", qualified_name)); - let read_store = self.store.read_current(); + let database = self.database.lock(); // Note - we first create a basic receipt - because we need it for later let basic_receipt = self .execution_configurator .read() .wrap_ledger_transaction(&validated, "scenario transaction") - .execute_on(read_store.deref()); - let mut series_executor = self.start_series_execution(read_store.deref()); + .execute_on(database.deref()); + let mut series_executor = self.start_series_execution(database.deref()); let commit = series_executor.execute_and_update_state(&validated, "scenario transaction"); @@ -363,8 +351,8 @@ where // themselves, which is part of the validation process //======================================================================================== - let read_store = self.store.read_current(); - let mut series_executor = self.start_series_execution(read_store.deref()); + let database = self.database.snapshot(); + let mut series_executor = self.start_series_execution(database.deref()); if &prepare_request.committed_ledger_hashes != series_executor.latest_ledger_hashes() { panic!( @@ -726,7 +714,10 @@ where }) } - fn start_series_execution<'s>(&'s self, store: &'s S) -> TransactionSeriesExecutor<'s, S> { + fn start_series_execution<'s, S>(&'s self, store: &'s S) -> TransactionSeriesExecutor<'s, S> + where + S: ReadableStore + QueryableProofStore + TransactionIdentifierLoader, + { TransactionSeriesExecutor::new( store, &self.execution_cache, @@ -736,13 +727,7 @@ where } } -impl StateComputer -where - S: CommitStore + ExecutedGenesisScenarioStore, - S: ReadableStore, - S: for<'a> TransactionIndex<&'a IntentHash>, - S: QueryableProofStore + TransactionIdentifierLoader + QueryableTransactionStore, -{ +impl StateComputer { pub fn execute_genesis_for_unit_tests_with_config( &self, consensus_manager_config: ConsensusManagerConfig, @@ -811,12 +796,13 @@ where ) -> LedgerProof { let start_instant = Instant::now(); - let read_db = self.store.read_current(); - if read_db.get_post_genesis_epoch_proof().is_some() { + let database = self.database.lock(); + if database.get_post_genesis_epoch_proof().is_some() { panic!("Can't execute genesis: database already initialized") } - let maybe_top_txn_identifiers = read_db.get_top_transaction_identifiers(); - drop(read_db); + let maybe_top_txn_identifiers = database.get_top_transaction_identifiers(); + drop(database); + if let Some(top_txn_identifiers) = maybe_top_txn_identifiers { // No epoch proof, but there are some committed txns panic!( @@ -990,8 +976,8 @@ where .collect::>() .join("\n") ); - let write_store = self.store.write_current(); - write_store.put_scenario(sequence_number, executed_scenario); + let database = self.database.lock(); + database.put_scenario(sequence_number, executed_scenario); return end_state.next_unused_nonce; } } @@ -1030,15 +1016,17 @@ where let commit_ledger_header = &commit_request.proof.ledger_header; let commit_state_version = commit_ledger_header.state_version; let commit_request_start_state_version = - commit_state_version.relative(-(commit_transactions_len as i128)).expect("`commit_request_start_state_version` should be computable from `commit_state_version - commit_transactions_len` and valid."); + commit_state_version.relative(-(commit_transactions_len as i128)) + .expect("`commit_request_start_state_version` should be computable from `commit_state_version - commit_transactions_len` and valid."); + + // We advance the top-of-ledger, hence lock: + let database = self.database.lock(); // Step 1.: Parse the transactions (and collect specific metrics from them, as a drive-by) let mut prepared_transactions = Vec::new(); let mut leader_round_counters_builder = LeaderRoundCountersBuilder::default(); let mut proposer_timestamps = Vec::new(); - let mut proposer_timestamp_ms = self - .store - .read_current() + let mut proposer_timestamp_ms = database .get_latest_proof() .unwrap() .ledger_header @@ -1072,9 +1060,8 @@ where proposer_timestamps.push(proposer_timestamp_ms); } - // Step 2.: Start the write DB transaction, check invariants, set-up DB update structures - let write_store = self.store.write_current(); - let mut series_executor = self.start_series_execution(write_store.deref()); + // Step 2.: Check invariants, set-up DB update structures + let mut series_executor = self.start_series_execution(database.deref()); if commit_request_start_state_version != series_executor.latest_state_version() { panic!( @@ -1093,7 +1080,7 @@ where ) .unwrap_or_else(|| { Self::calculate_transaction_root( - write_store.deref(), + database.deref(), series_executor.epoch_identifiers(), series_executor.latest_state_version(), &prepared_transactions, @@ -1220,7 +1207,7 @@ where .as_ref() .map(|next_epoch| next_epoch.epoch); - write_store.commit(CommitBundle { + database.commit(CommitBundle { transactions: committed_transaction_bundles, proof: commit_request.proof, substate_store_update, @@ -1232,7 +1219,7 @@ where receipt_tree_slice: ReceiptAccuTreeSliceV1(receipt_tree_slice_merger.into_slice()), new_substate_node_ancestry_records: new_node_ancestry_records, }); - drop(write_store); + drop(database); let num_user_transactions = committed_user_transactions.len() as u32; @@ -1318,8 +1305,8 @@ where self.protocol_state.write().current_protocol_version = protocol_version_name.clone(); let current_header = self - .store - .read_current() + .database + .lock() .get_latest_proof() .map(|proof| proof.ledger_header) .expect("Can't apply a protocol update pre-genesis"); @@ -1332,8 +1319,8 @@ where /// This method accepts a pre-validated transaction and trusts its contents (i.e. skips some /// validations). fn commit_genesis(&self, request: GenesisCommitRequest) { - let write_store = self.store.write_current(); - let mut series_executor = self.start_series_execution(write_store.deref()); + let database = self.database.lock(); + let mut series_executor = self.start_series_execution(database.deref()); let mut commit = series_executor .execute_and_update_state(&request.validated, "genesis") @@ -1365,7 +1352,7 @@ where // for metrics only let hash_structures_diff = commit.hash_structures_diff; - write_store.commit(CommitBundle { + database.commit(CommitBundle { transactions: vec![committed_transaction_bundle], proof, substate_store_update: SubstateStoreUpdate::from_single(commit.database_updates), @@ -1390,7 +1377,7 @@ where *locked_protocol_state = series_executor.protocol_state(); drop(locked_protocol_state); - drop(write_store); + drop(database); self.ledger_metrics.update( 1, @@ -1420,7 +1407,7 @@ where Some(*transaction_root) } - fn calculate_transaction_root( + fn calculate_transaction_root>( store: &S, epoch_identifiers: &EpochTransactionIdentifiers, parent_version: StateVersion, @@ -1610,10 +1597,10 @@ mod tests { state_manager: &StateManager, prepare_request: PrepareRequest, ) -> u32 { - let read_store = state_manager.state_computer.store.read_current(); + let database = state_manager.state_computer.database.snapshot(); let mut series_executor = state_manager .state_computer - .start_series_execution(read_store.deref()); + .start_series_execution(database.deref()); let round_update = RoundUpdateTransactionV1::new( series_executor.epoch_header(), diff --git a/core-rust/state-manager/src/state_manager.rs b/core-rust/state-manager/src/state_manager.rs index 6133524dda..542d4ae521 100644 --- a/core-rust/state-manager/src/state_manager.rs +++ b/core-rust/state-manager/src/state_manager.rs @@ -89,10 +89,10 @@ use crate::{ priority_mempool::PriorityMempool, store::{ jmt_gc::StateHashTreeGc, DatabaseBackendConfig, DatabaseFlags, RawDbMetricsCollector, - StateManagerDatabase, + StateManagerDatabaseLock, }, transaction::{CachedCommittabilityValidator, CommittabilityValidator, TransactionPreviewer}, - PendingTransactionResultCache, ProtocolUpdateResult, StateComputer, StateManagerRocksDb, + PendingTransactionResultCache, ProtocolUpdateResult, StateComputer, StateManagerDatabase, }; /// An interval between time-intensive measurement of raw DB metrics. @@ -145,14 +145,14 @@ impl StateManagerConfig { #[derive(Clone)] pub struct StateManager { config: StateManagerConfig, - pub state_computer: Arc>, - pub database: Arc>, + pub state_computer: Arc, + pub database: Arc, pub pending_transaction_result_cache: Arc>, pub mempool: Arc>, pub mempool_manager: Arc, pub execution_configurator: Arc>, - pub committability_validator: Arc>>, - pub transaction_previewer: Arc>>, + pub committability_validator: Arc>, + pub transaction_previewer: Arc>, } impl StateManager { @@ -175,7 +175,7 @@ impl StateManager { let network = config.network_definition.clone(); let db_path = PathBuf::from(config.database_backend_config.rocks_db_path.clone()); - let raw_db = match StateManagerRocksDb::new(db_path, config.database_flags.clone(), &network) { + let raw_db = match StateManagerDatabase::new(db_path, config.database_flags.clone(), &network) { Ok(db) => db, Err(error) => { match error { @@ -189,16 +189,17 @@ impl StateManager { } }; - let database = Arc::new(lock_factory.named("database").new_state_lock(raw_db)); + let database = Arc::new(StateManagerDatabaseLock::new( + lock_factory.named("database"), + raw_db, + )); if let Err(err) = config.protocol_config.validate() { panic!("Protocol misconfiguration: {}", err); }; - let initial_protocol_state = ProtocolState::compute_initial( - database.read_current().deref(), - &config.protocol_config, - ); + let initial_protocol_state = + ProtocolState::compute_initial(database.access().deref(), &config.protocol_config); let initial_protocol_version = &initial_protocol_state.current_protocol_version; let (initial_state_computer_config, initial_protocol_updater) = config @@ -374,7 +375,7 @@ impl StateManager { ProtocolUpdateResult { post_update_proof: self .database - .read_current() + .lock() .get_latest_proof() .expect("Missing post protocol update proof"), } diff --git a/core-rust/state-manager/src/store/jmt_gc.rs b/core-rust/state-manager/src/store/jmt_gc.rs index 42af1994b1..f0ba96bee7 100644 --- a/core-rust/state-manager/src/store/jmt_gc.rs +++ b/core-rust/state-manager/src/store/jmt_gc.rs @@ -75,9 +75,7 @@ use tracing::info; use crate::store::traits::gc::StateHashTreeGcStore; use crate::store::traits::proofs::QueryableProofStore; use crate::store::traits::StaleTreePartsV1; -use crate::store::StateManagerDatabase; -use crate::{StateVersion, StateVersionDelta}; -use node_common::locks::StateLock; +use crate::{StateManagerDatabaseLock, StateVersion, StateVersionDelta}; /// A maximum number of JMT nodes collected into "batch delete" buffer. /// Needed only to avoid OOM problems. @@ -97,17 +95,14 @@ pub struct StateHashTreeGcConfig { /// A garbage collector of sufficiently-old stale state hash tree nodes. /// The implementation is suited for being driven by an external scheduler. pub struct StateHashTreeGc { - database: Arc>, + database: Arc, interval: Duration, history_len: StateVersionDelta, } impl StateHashTreeGc { /// Creates a new GC. - pub fn new( - database: Arc>, - config: StateHashTreeGcConfig, - ) -> Self { + pub fn new(database: Arc, config: StateHashTreeGcConfig) -> Self { Self { database, interval: Duration::from_secs(u64::from(config.interval_sec)), @@ -122,13 +117,13 @@ impl StateHashTreeGc { /// Performs a single GC run, which is supposed to permanently delete *all* old-enough state /// hash tree nodes marked as stale. - /// Note: despite the GC modifying the database, we only obtain the "historical" state lock (in - /// practice: not locking anything at all). This is valid, since we do not rely on the current - /// state's consistency here. + /// + /// *Note on concurrent database access:* + /// The JMT's GC process, by its nature, only accesses "old" (i.e. not "top-of-ledger" new) + /// JMT DB rows. For this reason, it can use the direct [`StateManagerDatabaseLock::access()`] + /// and effectively own these rows (for reads and deletes), without locking the database. pub fn run(&self) { - let database = self.database.access_non_locked_historical(); - // The line below technically reads the "current state" from a "non-locked, historical" DB; - // however, we are fine with the current state progressing while we do the GC. + let database = self.database.access(); let current_state_version = database.max_state_version(); let to_state_version = current_state_version .relative(-self.history_len) diff --git a/core-rust/state-manager/src/store/mod.rs b/core-rust/state-manager/src/store/mod.rs index eaa04de830..429f96e01d 100644 --- a/core-rust/state-manager/src/store/mod.rs +++ b/core-rust/state-manager/src/store/mod.rs @@ -71,10 +71,10 @@ mod typed_cf_api; use crate::store::traits::measurement::MeasurableDatabase; use crate::RawDbMetrics; -use node_common::locks::StateLock; use prometheus::Registry; -pub use rocks_db::StateManagerDatabase; -pub use rocks_db::StateManagerRocksDb; +pub use rocks_db::StateManagerDatabaseLock; +pub use rocks_db::{ActualStateManagerDatabase, StateManagerDatabase}; +pub use rocks_db::{ReadableRocks, WriteableRocks}; use sbor::{Categorize, Decode, Encode}; use std::sync::Arc; pub use traits::DatabaseFlags; @@ -86,13 +86,13 @@ pub struct DatabaseBackendConfig { /// A synchronous collector of costly (I/O-intensive) raw DB metrics. pub struct RawDbMetricsCollector { - database: Arc>, + database: Arc, raw_db_metrics: RawDbMetrics, } impl RawDbMetricsCollector { /// Creates a collector measuring the given DB and updating the metrics in the given registry. - pub fn new(database: Arc>, metric_registry: &Registry) -> Self { + pub fn new(database: Arc, metric_registry: &Registry) -> Self { Self { database, raw_db_metrics: RawDbMetrics::new(metric_registry), @@ -102,10 +102,7 @@ impl RawDbMetricsCollector { /// Performs a single "collect measurements + update metric primitives" run. /// Should be called periodically. pub fn run(&self) { - let statistics = self - .database - .access_non_locked_historical() - .get_data_volume_statistics(); + let statistics = self.database.get_data_volume_statistics(); self.raw_db_metrics.update(statistics); } } diff --git a/core-rust/state-manager/src/store/proofs_gc.rs b/core-rust/state-manager/src/store/proofs_gc.rs index 21367881f2..81c1b6397e 100644 --- a/core-rust/state-manager/src/store/proofs_gc.rs +++ b/core-rust/state-manager/src/store/proofs_gc.rs @@ -65,6 +65,7 @@ use radix_engine::types::{Categorize, Decode, Encode}; use radix_engine_common::types::Epoch; +use std::ops::Deref; use std::sync::Arc; use std::time::Duration; use tracing::{error, info}; @@ -74,15 +75,13 @@ use crate::store::traits::gc::{ }; use crate::store::traits::proofs::QueryableProofStore; -use crate::store::StateManagerDatabase; - use crate::jni::LedgerSyncLimitsConfig; +use crate::store::rocks_db::ReadableRocks; use crate::traits::GetSyncableTxnsAndProofError::{ FailedToPrepareAResponseWithinLimits, NothingToServeAtTheGivenStateVersion, RefusedToServeGenesis, RefusedToServeProtocolUpdate, }; -use crate::{LedgerProof, StateVersion}; -use node_common::locks::StateLock; +use crate::{LedgerProof, StateManagerDatabase, StateManagerDatabaseLock, StateVersion}; /// A configuration for [`LedgerProofsGc`]. #[derive(Debug, Categorize, Encode, Decode, Clone, Default)] @@ -104,7 +103,7 @@ pub struct LedgerProofsGcConfig { /// proof" logic (used e.g. for ledger-sync responses). /// The implementation is suited for being driven by an external scheduler. pub struct LedgerProofsGc { - database: Arc>, + database: Arc, interval: Duration, most_recent_full_resolution_epoch_count: u64, limits_config: LedgerSyncLimitsConfig, @@ -113,7 +112,7 @@ pub struct LedgerProofsGc { impl LedgerProofsGc { /// Creates a new GC. pub fn new( - database: Arc>, + database: Arc, gc_config: LedgerProofsGcConfig, limits_config: LedgerSyncLimitsConfig, ) -> Self { @@ -137,20 +136,18 @@ impl LedgerProofsGc { /// proofs of configured old-enough epochs. /// Returns proof ranges that have been pruned. /// TODO: the return value is only used in tests, consider refactoring + /// + /// *Note on concurrent database access:* + /// The proofs' GC process, by its nature, only accesses "old" (i.e. not "top-of-ledger" new) + /// proof DB rows. For this reason, it can use the direct [`StateManagerDatabaseLock::access()`] + /// and effectively own these rows (for reads and deletes), without locking the database. + /// Of course, a concurrent ledger sync may request a range of "old" proofs too, and thus it + /// should use a [`StateManagerDatabaseLock::snapshot()`] to avoid relying on proofs which are + /// about to be deleted. pub fn run(&self) -> Vec { - // TODO(locks/snapshots): The GC's operation does not interact with the "current state", and - // intuitively could use the "historical, non-locked" DB access. However, we have a (very - // related) use-case, which lists arbitrary past transactions and their proof - and it could - // happen that a concurrently-running GC deletes the very proof that has to be used to fit - // within the limits. For this reason, the logic below carefully acquires/releases the DB's - // read/write lock for relevant stages of the execution. - // A more robust solution should either use DB snapshots (a development direction we are - // considering anyway), or a more selective lock over the ledger proofs CF alone (or even - // over a selected *range* of the ledger proofs CF). - // Read the GC's persisted state and initialize the run: - let read_progress_database = self.database.read_current(); - let to_epoch = read_progress_database + let database = self.database.access(); + let to_epoch = database .max_completed_epoch() .map(|max_completed_epoch| max_completed_epoch.number()) .and_then(|number| number.checked_sub(self.most_recent_full_resolution_epoch_count)) @@ -160,15 +157,14 @@ impl LedgerProofsGc { return vec![]; }; let progress_started_at: LedgerProofsGcProgress = - read_progress_database.get_progress().unwrap_or_else(|| { + database.get_progress().unwrap_or_else(|| { LedgerProofsGcProgress::new( - read_progress_database + database .get_post_genesis_epoch_proof() .expect("we checked that there is some completed epoch above") .ledger_header, ) }); - drop(read_progress_database); if progress_started_at.last_pruned_epoch >= to_epoch { // Nothing to GC during this run. @@ -184,9 +180,12 @@ impl LedgerProofsGc { let mut pruned_proof_ranges = vec![]; let mut retained_proofs = 0; // only for logging purposes - while let Some(next_prune_range) = self.locate_next_prune_range(last_pruned_state_version) { - let delete_database = self.database.write_current(); - delete_database.delete_ledger_proofs_range( + while let Some(next_prune_range) = Self::locate_next_prune_range( + database.deref(), + last_pruned_state_version, + &self.limits_config, + ) { + database.delete_ledger_proofs_range( next_prune_range.from_state_version_inclusive, next_prune_range.to_state_version_exclusive(), ); @@ -204,7 +203,7 @@ impl LedgerProofsGc { retained_proofs ); retained_proofs = 0; - delete_database.set_progress(LedgerProofsGcProgressV1 { + database.set_progress(LedgerProofsGcProgressV1 { last_pruned_epoch: retained_header.epoch, epoch_proof_state_version: last_pruned_state_version, }); @@ -212,7 +211,6 @@ impl LedgerProofsGc { break; } } - drop(delete_database); } info!("Ledger proofs' GC run finished"); @@ -220,11 +218,12 @@ impl LedgerProofsGc { } /// Returns a range of proofs to delete. - /// A return value of `None` means that (for now) no more proofs should be deleted - /// and the current run should end. + /// A return value of `None` means that (for now) no more proofs should be deleted and the + /// current run should end. fn locate_next_prune_range( - &self, + database: &StateManagerDatabase, last_pruned_state_version: StateVersion, + limits_config: &LedgerSyncLimitsConfig, ) -> Option { let mut from_state_version_inclusive = last_pruned_state_version .next() @@ -232,14 +231,11 @@ impl LedgerProofsGc { let mut skipped_proofs = 0; loop { - let locate_proof_database = self.database.read_current(); - let syncable_txns_and_proof_result = locate_proof_database.get_syncable_txns_and_proof( + let syncable_txns_and_proof_result = database.get_syncable_txns_and_proof( from_state_version_inclusive, - self.limits_config - .max_txns_for_responses_spanning_more_than_one_proof, - self.limits_config.max_txn_bytes_for_single_response, + limits_config.max_txns_for_responses_spanning_more_than_one_proof, + limits_config.max_txn_bytes_for_single_response, ); - drop(locate_proof_database); match syncable_txns_and_proof_result { Ok(syncable_txns_and_proof) => { @@ -284,7 +280,7 @@ impl LedgerProofsGc { error!( "A chain of transactions-without-proof from state version {} does not fit within the limits {:?}; aborting the GC", from_state_version_inclusive, - self.limits_config + limits_config ); return None; } @@ -393,7 +389,8 @@ mod tests { commit_round_updates_until_epoch(&state_manager, Epoch::of(8)); - let post_genesis_epoch_proof = db.read_current().get_post_genesis_epoch_proof().unwrap(); + let database = db.access(); + let post_genesis_epoch_proof = database.get_post_genesis_epoch_proof().unwrap(); // The calculations below rely on this let first_post_genesis_state_version = post_genesis_epoch_proof .ledger_header @@ -427,9 +424,7 @@ mod tests { } // Verify that sync works as expected - let read_db = db.read_current(); - - let protocol_update_init_state_version = read_db + let protocol_update_init_state_version = database .get_latest_protocol_update_init_proof() .unwrap() .ledger_header @@ -438,7 +433,7 @@ mod tests { let first_protocol_update_txn = protocol_update_init_state_version.checked_add(1).unwrap(); - let last_protocol_update_state_version = read_db + let last_protocol_update_state_version = database .get_latest_protocol_update_execution_proof() .unwrap() .ledger_header @@ -448,12 +443,12 @@ mod tests { let first_post_protocol_update_state_version = last_protocol_update_state_version.checked_add(1).unwrap(); - let latest_state_version = read_db.max_state_version().number(); + let latest_state_version = database.max_state_version().number(); let mut total_state_versions_tried = 0; // 0 -> post genesis version (exclusive): unsyncable for state_version in 0..first_post_genesis_state_version { - let res = read_db.get_syncable_txns_and_proof( + let res = database.get_syncable_txns_and_proof( StateVersion::of(state_version), sync_limits_config.max_txns_for_responses_spanning_more_than_one_proof, sync_limits_config.max_txn_bytes_for_single_response, @@ -467,7 +462,7 @@ mod tests { // post genesis -> protocol update trigger (inclusive): syncable for state_version in first_post_genesis_state_version..=protocol_update_init_state_version { - let res = read_db.get_syncable_txns_and_proof( + let res = database.get_syncable_txns_and_proof( StateVersion::of(state_version), sync_limits_config.max_txns_for_responses_spanning_more_than_one_proof, sync_limits_config.max_txn_bytes_for_single_response, @@ -479,7 +474,7 @@ mod tests { // protocol update transactions (1): unsyncable for state_version in first_protocol_update_txn..=last_protocol_update_state_version { - let res = read_db.get_syncable_txns_and_proof( + let res = database.get_syncable_txns_and_proof( StateVersion::of(state_version), sync_limits_config.max_txns_for_responses_spanning_more_than_one_proof, sync_limits_config.max_txn_bytes_for_single_response, @@ -493,7 +488,7 @@ mod tests { // post-protocol update transactions: syncable for state_version in first_post_protocol_update_state_version..=latest_state_version { - let res = read_db.get_syncable_txns_and_proof( + let res = database.get_syncable_txns_and_proof( StateVersion::of(state_version), sync_limits_config.max_txns_for_responses_spanning_more_than_one_proof, sync_limits_config.max_txn_bytes_for_single_response, @@ -508,7 +503,5 @@ mod tests { total_state_versions_tried, latest_state_version + 1 /* starting at 0, so +1 here */ ); - - drop(read_db); } } diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index 9a98354dee..c3da2a55d9 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -64,6 +64,7 @@ use std::collections::HashSet; use std::fmt; +use std::ops::Deref; use crate::store::traits::*; use crate::{ @@ -88,6 +89,7 @@ use radix_engine_store_interface::interface::*; use radix_engine_store_interface::db_key_mapper::{DatabaseKeyMapper, SpreadPrefixKeyMapper}; use std::path::PathBuf; +use node_common::locks::{LockFactory, Mutex}; use tracing::{error, info, warn}; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice}; @@ -512,7 +514,7 @@ pub trait ReadableRocks { /// Starts iteration over key-value pairs, according to the given [`IteratorMode`]. fn iterator_cf( &self, - cf_handle: &impl AsColumnFamilyRef, + cf: &impl AsColumnFamilyRef, mode: IteratorMode, ) -> Box + '_>; @@ -539,7 +541,11 @@ pub trait ReadableRocks { /// /// Naturally, it is expected that only a "direct" RocksDB instance can implement this one. pub trait WriteableRocks: ReadableRocks { + /// Atomically writes the given batch of updates. fn write(&self, batch: WriteBatch); + + /// Returns a snapshot of the current state. + fn snapshot(&self) -> SnapshotRocks; } /// Direct RocksDB instance. @@ -554,12 +560,12 @@ impl ReadableRocks for DirectRocks { fn iterator_cf( &self, - cf_handle: &impl AsColumnFamilyRef, + cf: &impl AsColumnFamilyRef, mode: IteratorMode, ) -> Box + '_> { Box::new( self.db - .iterator_cf(cf_handle, mode) + .iterator_cf(cf, mode) .map(|result| result.expect("reading from DB iterator")), ) } @@ -588,6 +594,13 @@ impl WriteableRocks for DirectRocks { fn write(&self, batch: WriteBatch) { self.db.write(batch).expect("DB write batch"); } + + fn snapshot(&self) -> SnapshotRocks { + SnapshotRocks { + db: &self.db, + snapshot: self.db.snapshot(), + } + } } /// Snapshot of RocksDB. @@ -607,12 +620,12 @@ impl<'db> ReadableRocks for SnapshotRocks<'db> { fn iterator_cf( &self, - cf_handle: &impl AsColumnFamilyRef, + cf: &impl AsColumnFamilyRef, mode: IteratorMode, ) -> Box + '_> { Box::new( self.snapshot - .iterator_cf(cf_handle, mode) + .iterator_cf(cf, mode) .map(|result| result.expect("reading from snapshot DB iterator")), ) } @@ -639,11 +652,71 @@ impl<'db> ReadableRocks for SnapshotRocks<'db> { } } -/// A convenience alias for the exact [`StateManagerRocksDb`] type owned by state manager. -pub type StateManagerDatabase = StateManagerRocksDb; +pub type ActualStateManagerDatabase = StateManagerDatabase; + +// TODO(wip): doc +pub struct StateManagerDatabaseLock { + database: ActualStateManagerDatabase, + mutex: Mutex<()>, +} + +impl StateManagerDatabaseLock { + pub fn new(lock_factory: LockFactory, database: ActualStateManagerDatabase) -> Self { + Self { + database, + mutex: lock_factory.new_mutex(()), + } + } + + pub fn access( + &self, + ) -> impl Deref> + '_ { + &self.database // TODO(wip): return tracking wrap? + } + + pub fn lock(&self) -> impl Deref> + '_ { + DatabaseLockGuard { + underlying: self.mutex.lock(), + database: &self.database, + } + } + + pub fn snapshot( + &self, + ) -> impl Deref> + '_ { + let StateManagerDatabase { config, rocks } = &self.database; + StateManagerDatabase { + config: config.clone(), + rocks: rocks.snapshot(), + } + } +} + +pub struct DatabaseLockGuard<'d, D, U> { + #[allow(dead_code)] // only held to release the lock when dropped + underlying: U, + database: &'d D, +} + +impl<'d, D: 'd, U> Deref for DatabaseLockGuard<'d, D, U> { + type Target = D; + + fn deref(&self) -> &Self::Target { + self.database + } +} + +impl<'db> Deref for StateManagerDatabase> { + // TODO(wip): replace with a tracking wrap + type Target = StateManagerDatabase>; + + fn deref(&self) -> &Self::Target { + self + } +} /// A RocksDB-backed persistence layer for state manager. -pub struct StateManagerRocksDb { +pub struct StateManagerDatabase { /// Database feature flags. /// /// These were passed during construction, validated and persisted. They are made available by @@ -654,7 +727,7 @@ pub struct StateManagerRocksDb { rocks: R, } -impl StateManagerDatabase { +impl ActualStateManagerDatabase { pub fn new( root: PathBuf, config: DatabaseFlags, @@ -671,7 +744,7 @@ impl StateManagerDatabase { let db = DB::open_cf_descriptors(&db_opts, root.as_path(), column_families).unwrap(); - let state_manager_database = StateManagerRocksDb { + let state_manager_database = StateManagerDatabase { config: config.clone(), rocks: DirectRocks { db }, }; @@ -688,13 +761,50 @@ impl StateManagerDatabase { Ok(state_manager_database) } +} + +/// A wrapper for [`DirectRocks`] which only exposes it as [`ReadableRocks`]. +/// This is needed to restrict the writing capabilities in compile time (when opening RocksDB in +/// read-only or secondary mode). +pub struct ReadonlyRocks { + wrapped: DirectRocks, +} - /// Creates a readonly [`StateManagerRocksDb`] that allows reading from the store while some other - /// process is writing to it. Any write operation that happens against a read-only store leads - /// to a panic. +impl ReadableRocks for ReadonlyRocks { + fn cf_handle(&self, name: &str) -> &ColumnFamily { + self.wrapped.cf_handle(name) + } + + fn iterator_cf( + &self, + cf: &impl AsColumnFamilyRef, + mode: IteratorMode, + ) -> Box + '_> { + self.wrapped.iterator_cf(cf, mode) + } + + fn get_pinned_cf( + &self, + cf: &impl AsColumnFamilyRef, + key: impl AsRef<[u8]>, + ) -> Option { + self.wrapped.get_pinned_cf(cf, key) + } + + fn multi_get_cf<'a>( + &'a self, + keys: impl IntoIterator)>, + ) -> Vec>> { + self.wrapped.multi_get_cf(keys) + } +} + +impl StateManagerDatabase { + /// Creates a readonly [`StateManagerDatabase`] that allows only reading from the store, while + /// some other process is writing to it. /// /// This is required for the [`ledger-tools`] CLI tool which only reads data from the database - /// and does not write anything to it. Without this constructor, if [`StateManagerRocksDb::new`] is + /// and does not write anything to it. Without this constructor, if [`StateManagerDatabase::new`] is /// used by the [`ledger-tools`] CLI then it leads to a lock contention as two threads would /// want to have a write lock over the database. This provides the [`ledger-tools`] CLI with a /// way of making it clear that it only wants read lock and not a write lock. @@ -714,16 +824,19 @@ impl StateManagerDatabase { DB::open_cf_descriptors_read_only(&db_opts, root.as_path(), column_families, false) .unwrap(); - Ok(StateManagerRocksDb { + Ok(StateManagerDatabase { config: DatabaseFlags { enable_local_transaction_execution_index: false, enable_account_change_index: false, }, - rocks: DirectRocks { db }, + rocks: ReadonlyRocks { + wrapped: DirectRocks { db }, + }, }) } - /// Create a [`StateManagerRocksDb`] as a secondary instance which may catch up with the primary + /// Creates a [`StateManagerDatabase`] as a secondary instance which may catch up with the + /// primary. pub fn new_as_secondary(root: PathBuf, temp: PathBuf, column_families: Vec<&str>) -> Self { let mut db_opts = Options::default(); db_opts.create_if_missing(false); @@ -742,35 +855,37 @@ impl StateManagerDatabase { ) .unwrap(); - StateManagerRocksDb { + StateManagerDatabase { config: DatabaseFlags { enable_local_transaction_execution_index: false, enable_account_change_index: false, }, - rocks: DirectRocks { db }, + rocks: ReadonlyRocks { + wrapped: DirectRocks { db }, + }, } } pub fn try_catchup_with_primary(&self) { - self.rocks.db.try_catch_up_with_primary().unwrap(); + self.rocks.wrapped.db.try_catch_up_with_primary().unwrap(); } } -impl StateManagerRocksDb { +impl StateManagerDatabase { /// Starts a read-only interaction with the DB through per-CF type-safe APIs. fn open_read_context(&self) -> TypedDbContext { TypedDbContext::new(&self.rocks, NoWriteSupport) } } -impl StateManagerRocksDb { +impl StateManagerDatabase { /// Starts a read/buffered-write interaction with the DB through per-CF type-safe APIs. fn open_rw_context(&self) -> TypedDbContext> { TypedDbContext::new(&self.rocks, BufferedWriteSupport::new(&self.rocks)) } } -impl StateManagerRocksDb { +impl StateManagerDatabase { fn read_flags_state(&self) -> DatabaseFlagsState { let db_context = self.open_read_context(); let extension_data_cf = db_context.cf(ExtensionsDataCf); @@ -800,7 +915,7 @@ impl StateManagerRocksDb { } } -impl ConfigurableDatabase for StateManagerRocksDb { +impl ConfigurableDatabase for StateManagerDatabase { fn is_account_change_index_enabled(&self) -> bool { self.config.enable_account_change_index } @@ -810,7 +925,7 @@ impl ConfigurableDatabase for StateManagerRocksDb { } } -impl MeasurableDatabase for StateManagerDatabase { +impl MeasurableDatabase for StateManagerDatabaseLock { fn get_data_volume_statistics(&self) -> Vec { let mut statistics = ALL_COLUMN_FAMILIES .iter() @@ -821,7 +936,7 @@ impl MeasurableDatabase for StateManagerDatabase { ) }) .collect::>(); - let live_files = match self.rocks.db.live_files() { + let live_files = match self.database.rocks.db.live_files() { Ok(live_files) => live_files, Err(err) => { warn!("could not get DB live files; returning 0: {:?}", err); @@ -844,7 +959,7 @@ impl MeasurableDatabase for StateManagerDatabase { } } -impl CommitStore for StateManagerRocksDb { +impl CommitStore for StateManagerDatabase { fn commit(&self, commit_bundle: CommitBundle) { let db_context = self.open_rw_context(); @@ -963,7 +1078,7 @@ impl CommitStore for StateManagerRocksDb { } } -impl StateManagerRocksDb { +impl StateManagerDatabase { fn add_transaction_to_write_batch( &self, db_context: &TypedDbContext>, @@ -1043,7 +1158,7 @@ impl StateManagerRocksDb { } } -impl ExecutedGenesisScenarioStore for StateManagerRocksDb { +impl ExecutedGenesisScenarioStore for StateManagerDatabase { fn put_scenario(&self, number: ScenarioSequenceNumber, scenario: ExecutedGenesisScenario) { self.open_rw_context() .cf(ExecutedGenesisScenariosCf) @@ -1140,7 +1255,7 @@ impl<'r> Iterator for RocksDBCommittedTransactionBundleIterator<'r> { } } -impl IterableTransactionStore for StateManagerRocksDb { +impl IterableTransactionStore for StateManagerDatabase { fn get_committed_transaction_bundle_iter( &self, from_state_version: StateVersion, @@ -1156,7 +1271,7 @@ impl IterableTransactionStore for StateManagerRocksDb { } } -impl QueryableTransactionStore for StateManagerRocksDb { +impl QueryableTransactionStore for StateManagerDatabase { fn get_committed_transaction( &self, state_version: StateVersion, @@ -1218,7 +1333,7 @@ impl QueryableTransactionStore for StateManagerRocksDb { } } -impl TransactionIndex<&IntentHash> for StateManagerRocksDb { +impl TransactionIndex<&IntentHash> for StateManagerDatabase { fn get_txn_state_version_by_identifier( &self, intent_hash: &IntentHash, @@ -1227,7 +1342,7 @@ impl TransactionIndex<&IntentHash> for StateManagerRocksDb } } -impl TransactionIndex<&NotarizedTransactionHash> for StateManagerRocksDb { +impl TransactionIndex<&NotarizedTransactionHash> for StateManagerDatabase { fn get_txn_state_version_by_identifier( &self, notarized_transaction_hash: &NotarizedTransactionHash, @@ -1238,7 +1353,7 @@ impl TransactionIndex<&NotarizedTransactionHash> for StateMana } } -impl TransactionIndex<&LedgerTransactionHash> for StateManagerRocksDb { +impl TransactionIndex<&LedgerTransactionHash> for StateManagerDatabase { fn get_txn_state_version_by_identifier( &self, ledger_transaction_hash: &LedgerTransactionHash, @@ -1249,7 +1364,7 @@ impl TransactionIndex<&LedgerTransactionHash> for StateManager } } -impl TransactionIdentifierLoader for StateManagerRocksDb { +impl TransactionIdentifierLoader for StateManagerDatabase { fn get_top_transaction_identifiers( &self, ) -> Option<(StateVersion, CommittedTransactionIdentifiers)> { @@ -1259,7 +1374,7 @@ impl TransactionIdentifierLoader for StateManagerRocksDb { } } -impl IterableProofStore for StateManagerRocksDb { +impl IterableProofStore for StateManagerDatabase { fn get_proof_iter( &self, from_state_version: StateVersion, @@ -1309,7 +1424,7 @@ impl IterableProofStore for StateManagerRocksDb { } } -impl QueryableProofStore for StateManagerRocksDb { +impl QueryableProofStore for StateManagerDatabase { fn max_state_version(&self) -> StateVersion { self.open_read_context() .cf(RawLedgerTransactionsCf) @@ -1513,7 +1628,7 @@ impl QueryableProofStore for StateManagerRocksDb { } } -impl SubstateDatabase for StateManagerRocksDb { +impl SubstateDatabase for StateManagerDatabase { fn get_substate( &self, partition_key: &DbPartitionKey, @@ -1540,7 +1655,7 @@ impl SubstateDatabase for StateManagerRocksDb { } } -impl ListableSubstateDatabase for StateManagerRocksDb { +impl ListableSubstateDatabase for StateManagerDatabase { fn list_partition_keys(&self) -> Box + '_> { self.open_read_context() .cf(SubstatesCf) @@ -1548,7 +1663,7 @@ impl ListableSubstateDatabase for StateManagerRocksDb { } } -impl SubstateNodeAncestryStore for StateManagerRocksDb { +impl SubstateNodeAncestryStore for StateManagerDatabase { fn batch_get_ancestry<'a>( &self, node_ids: impl IntoIterator, @@ -1559,13 +1674,13 @@ impl SubstateNodeAncestryStore for StateManagerRocksDb { } } -impl ReadableTreeStore for StateManagerRocksDb { +impl ReadableTreeStore for StateManagerDatabase { fn get_node(&self, key: &NodeKey) -> Option { self.open_read_context().cf(StateHashTreeNodesCf).get(key) } } -impl StateHashTreeGcStore for StateManagerRocksDb { +impl StateHashTreeGcStore for StateManagerDatabase { fn get_stale_tree_parts_iter( &self, ) -> Box + '_> { @@ -1594,7 +1709,7 @@ impl StateHashTreeGcStore for StateManagerRocksDb { } } -impl LedgerProofsGcStore for StateManagerRocksDb { +impl LedgerProofsGcStore for StateManagerDatabase { fn get_progress(&self) -> Option { self.open_read_context() .cf(LedgerProofsGcProgressCf) @@ -1615,7 +1730,7 @@ impl LedgerProofsGcStore for StateManagerRocksDb { } impl ReadableAccuTreeStore - for StateManagerRocksDb + for StateManagerDatabase { fn get_tree_slice( &self, @@ -1629,7 +1744,7 @@ impl ReadableAccuTreeStore } impl ReadableAccuTreeStore - for StateManagerRocksDb + for StateManagerDatabase { fn get_tree_slice(&self, state_version: &StateVersion) -> Option> { self.open_read_context() @@ -1639,19 +1754,19 @@ impl ReadableAccuTreeStore } } -impl WriteableVertexStore for StateManagerRocksDb { +impl WriteableVertexStore for StateManagerDatabase { fn save_vertex_store(&self, blob: VertexStoreBlob) { self.open_rw_context().cf(VertexStoreCf).put(&(), &blob) } } -impl RecoverableVertexStore for StateManagerRocksDb { +impl RecoverableVertexStore for StateManagerDatabase { fn get_vertex_store(&self) -> Option { self.open_read_context().cf(VertexStoreCf).get(&()) } } -impl StateManagerRocksDb { +impl StateManagerDatabase { fn batch_update_account_change_index_from_receipt( &self, db_context: &TypedDbContext>, @@ -1732,7 +1847,7 @@ impl StateManagerRocksDb { } } -impl AccountChangeIndexExtension for StateManagerRocksDb { +impl AccountChangeIndexExtension for StateManagerDatabase { fn account_change_index_last_processed_state_version(&self) -> StateVersion { self.open_read_context() .cf(ExtensionsDataCf) @@ -1770,7 +1885,7 @@ impl AccountChangeIndexExtension for StateManagerRocksDb { } } -impl RestoreDecember2023LostSubstates for StateManagerRocksDb { +impl RestoreDecember2023LostSubstates for StateManagerDatabase { fn restore_december_2023_lost_substates(&self, network: &NetworkDefinition) { let db_context = self.open_rw_context(); let extension_data_cf = db_context.cf(ExtensionsDataCf); @@ -1868,7 +1983,7 @@ impl RestoreDecember2023LostSubstates for StateManagerRocksDb } } -impl IterableAccountChangeIndex for StateManagerRocksDb { +impl IterableAccountChangeIndex for StateManagerDatabase { fn get_state_versions_for_account_iter( &self, account: GlobalAddress, diff --git a/core-rust/state-manager/src/test/mod.rs b/core-rust/state-manager/src/test/mod.rs index eca3faf2da..3a9c3db51a 100644 --- a/core-rust/state-manager/src/test/mod.rs +++ b/core-rust/state-manager/src/test/mod.rs @@ -26,11 +26,10 @@ pub fn commit_round_updates_until_epoch(state_manager: &StateManager, epoch: Epo pub fn prepare_and_commit_round_update( state_manager: &StateManager, ) -> (PrepareResult, CommitSummary) { - let read_db = state_manager.database.read_current(); - let latest_proof: LedgerProof = read_db.get_latest_proof().unwrap(); - let latest_epoch_proof: LedgerProof = read_db.get_latest_epoch_proof().unwrap(); - let (top_state_version, top_identifiers) = read_db.get_top_transaction_identifiers().unwrap(); - drop(read_db); + let database = state_manager.database.access(); + let latest_proof: LedgerProof = database.get_latest_proof().unwrap(); + let latest_epoch_proof: LedgerProof = database.get_latest_epoch_proof().unwrap(); + let (top_state_version, top_identifiers) = database.get_top_transaction_identifiers().unwrap(); // Doesn't matter which one we use, we just need some validator from the current validator set let proposer_address = latest_epoch_proof diff --git a/core-rust/state-manager/src/transaction/preview.rs b/core-rust/state-manager/src/transaction/preview.rs index 7aace47232..8a8f88a0c3 100644 --- a/core-rust/state-manager/src/transaction/preview.rs +++ b/core-rust/state-manager/src/transaction/preview.rs @@ -1,15 +1,16 @@ -use node_common::locks::{RwLock, StateLock}; +use node_common::locks::RwLock; use radix_engine::transaction::{PreviewError, TransactionReceipt, TransactionResult}; use radix_engine_store_interface::db_key_mapper::SpreadPrefixKeyMapper; use std::ops::{Deref, Range}; use std::sync::Arc; -use crate::query::{StateManagerSubstateQueries, TransactionIdentifierLoader}; -use crate::staging::ReadableStore; +use crate::query::StateManagerSubstateQueries; + use crate::store::traits::QueryableProofStore; use crate::transaction::*; use crate::{ GlobalBalanceSummary, LedgerHeader, LedgerStateChanges, PreviewRequest, ProcessedCommitResult, + StateManagerDatabaseLock, }; use radix_engine_common::prelude::*; use transaction::model::*; @@ -18,8 +19,8 @@ use transaction::validation::NotarizedTransactionValidator; use transaction::validation::ValidationConfig; /// A transaction preview runner. -pub struct TransactionPreviewer { - store: Arc>, +pub struct TransactionPreviewer { + database: Arc, execution_configurator: Arc>, validation_config: ValidationConfig, } @@ -31,28 +32,28 @@ pub struct ProcessedPreviewResult { pub global_balance_summary: GlobalBalanceSummary, } -impl TransactionPreviewer { +impl TransactionPreviewer { pub fn new( - store: Arc>, + database: Arc, execution_configurator: Arc>, validation_config: ValidationConfig, ) -> Self { Self { - store, + database, execution_configurator, validation_config, } } } -impl TransactionPreviewer { +impl TransactionPreviewer { /// Executes the transaction compiled from the given request in a preview mode. pub fn preview( &self, preview_request: PreviewRequest, ) -> Result { - let read_store = self.store.read_current(); - let intent = self.create_intent(preview_request, read_store.deref()); + let database = self.database.snapshot(); + let intent = self.create_intent(preview_request, database.deref()); let validator = NotarizedTransactionValidator::new(self.validation_config); let validated = validator @@ -61,15 +62,15 @@ impl Trans let read_execution_configurator = self.execution_configurator.read(); let transaction_logic = read_execution_configurator.wrap_preview_transaction(&validated); - let receipt = transaction_logic.execute_on(read_store.deref()); + let receipt = transaction_logic.execute_on(database.deref()); let (state_changes, global_balance_summary) = match &receipt.result { TransactionResult::Commit(commit) => { let state_changes = ProcessedCommitResult::compute_ledger_state_changes::< - S, + _, SpreadPrefixKeyMapper, - >(read_store.deref(), &commit.state_updates); + >(database.deref(), &commit.state_updates); let global_balance_update = ProcessedCommitResult::compute_global_balance_update( - read_store.deref(), + database.deref(), &state_changes, &commit.state_update_summary.vault_balance_changes, ); @@ -81,7 +82,7 @@ impl Trans ), }; - let base_ledger_header = read_store + let base_ledger_header = database .get_latest_proof() .expect("proof for preview's base state") .ledger_header; @@ -94,12 +95,16 @@ impl Trans }) } - fn create_intent(&self, preview_request: PreviewRequest, read_store: &S) -> PreviewIntentV1 { + fn create_intent( + &self, + preview_request: PreviewRequest, + store: &S, + ) -> PreviewIntentV1 { let notary = preview_request.notary_public_key.unwrap_or_else(|| { PublicKey::Secp256k1(Secp256k1PrivateKey::from_u64(2).unwrap().public_key()) }); let effective_epoch_range = preview_request.explicit_epoch_range.unwrap_or_else(|| { - let current_epoch = read_store.get_epoch(); + let current_epoch = store.get_epoch(); Range { start: current_epoch, end: current_epoch diff --git a/core-rust/state-manager/src/transaction/validation.rs b/core-rust/state-manager/src/transaction/validation.rs index 2b0053f25a..d64eb7a46b 100644 --- a/core-rust/state-manager/src/transaction/validation.rs +++ b/core-rust/state-manager/src/transaction/validation.rs @@ -1,4 +1,4 @@ -use node_common::locks::{RwLock, StateLock}; +use node_common::locks::RwLock; use std::ops::Deref; use std::sync::Arc; use std::time::SystemTime; @@ -7,14 +7,16 @@ use transaction::errors::TransactionValidationError; use radix_engine::transaction::{AbortReason, RejectResult, TransactionReceipt, TransactionResult}; use radix_engine_common::network::NetworkDefinition; +use radix_engine_store_interface::interface::SubstateDatabase; use crate::query::StateManagerSubstateQueries; -use crate::staging::ReadableStore; + +use crate::store::traits::transactions::QueryableTransactionStore; use crate::store::traits::{QueryableProofStore, TransactionIndex}; use crate::transaction::{ExecutionConfigurator, TransactionLogic}; use crate::{ AlreadyCommittedError, AtState, ExecutionRejectionReason, PendingTransactionRecord, - PendingTransactionResultCache, RejectionReason, TransactionAttempt, + PendingTransactionResultCache, RejectionReason, StateManagerDatabaseLock, TransactionAttempt, }; use transaction::prelude::*; @@ -178,20 +180,20 @@ impl From for LedgerTransactionValidationError { /// A validator for `NotarizedTransaction`, deciding whether they would be rejected or not-rejected /// (i.e. "committable") at a specific state of the `store`. -pub struct CommittabilityValidator { - store: Arc>, +pub struct CommittabilityValidator { + database: Arc, execution_configurator: Arc>, user_transaction_validator: NotarizedTransactionValidator, } -impl CommittabilityValidator { +impl CommittabilityValidator { pub fn new( - store: Arc>, + database: Arc, execution_configurator: Arc>, user_transaction_validator: NotarizedTransactionValidator, ) -> Self { Self { - store, + database, execution_configurator, user_transaction_validator, } @@ -213,25 +215,21 @@ impl CommittabilityValidator { } } -impl CommittabilityValidator -where - S: ReadableStore + QueryableProofStore, - S: for<'a> TransactionIndex<&'a IntentHash>, -{ +impl CommittabilityValidator { /// Determine whether it would be rejected given the current state of the substate store. pub fn check_for_rejection( &self, transaction: &ValidatedNotarizedTransactionV1, timestamp: SystemTime, ) -> TransactionAttempt { - let read_store = self.store.read_current(); - let executed_at_state_version = read_store.max_state_version(); + let database = self.database.snapshot(); + let executed_at_state_version = database.max_state_version(); let existing = - read_store.get_txn_state_version_by_identifier(&transaction.prepared.intent_hash()); + database.get_txn_state_version_by_identifier(&transaction.prepared.intent_hash()); if let Some(state_version) = existing { - let committed_transaction_identifiers = read_store + let committed_transaction_identifiers = database .get_committed_transaction_identifiers(state_version) .expect("transaction of a state version obtained from an index"); @@ -253,7 +251,7 @@ where }; } - let receipt = self.test_execute_transaction_up_to_fee_loan(read_store.deref(), transaction); + let receipt = self.test_execute_transaction_up_to_fee_loan(database.deref(), transaction); let result = match receipt.result { TransactionResult::Reject(RejectResult { reason }) => { if matches!( @@ -285,7 +283,7 @@ where } } - fn test_execute_transaction_up_to_fee_loan( + fn test_execute_transaction_up_to_fee_loan( &self, root_store: &S, transaction: &ValidatedNotarizedTransactionV1, @@ -298,20 +296,20 @@ where } /// A caching wrapper for a `CommittabilityValidator`. -pub struct CachedCommittabilityValidator { - store: Arc>, - committability_validator: Arc>>, +pub struct CachedCommittabilityValidator { + database: Arc, + committability_validator: Arc>, pending_transaction_result_cache: Arc>, } -impl CachedCommittabilityValidator { +impl CachedCommittabilityValidator { pub fn new( - store: Arc>, - committability_validator: Arc>>, + database: Arc, + committability_validator: Arc>, pending_transaction_result_cache: Arc>, ) -> Self { Self { - store, + database, committability_validator, pending_transaction_result_cache, } @@ -413,11 +411,7 @@ pub enum ForceRecalculation { No, } -impl CachedCommittabilityValidator -where - S: ReadableStore + QueryableProofStore, - S: for<'a> TransactionIndex<&'a IntentHash>, -{ +impl CachedCommittabilityValidator { /// Reads the transaction rejection status from the cache, else calculates it fresh, using /// `CommittabilityValidator`. /// @@ -512,7 +506,7 @@ where return ShouldRecalculate::Yes; } - let current_epoch = self.store.read_current().get_epoch(); + let current_epoch = self.database.snapshot().get_epoch(); let record_option = self.read_record(prepared); if let Some(record) = record_option { From 4bbd084da3243132d0e9b82ca75e98d73294cba9 Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Wed, 31 Jan 2024 22:11:13 +0100 Subject: [PATCH 09/22] Extracting a generic `DbLock` + Better rustdocs. --- core-rust/node-common/src/locks.rs | 116 ++++++++++++++++++ .../src/jni/node_rust_environment.rs | 7 +- .../protocol_updates/protocol_updaters.rs | 9 +- core-rust/state-manager/src/state_computer.rs | 6 +- core-rust/state-manager/src/state_manager.rs | 15 +-- core-rust/state-manager/src/store/jmt_gc.rs | 14 ++- core-rust/state-manager/src/store/mod.rs | 11 +- .../state-manager/src/store/proofs_gc.rs | 15 +-- core-rust/state-manager/src/store/rocks_db.rs | 64 ++-------- .../state-manager/src/transaction/preview.rs | 10 +- .../src/transaction/validation.rs | 14 +-- 11 files changed, 177 insertions(+), 104 deletions(-) diff --git a/core-rust/node-common/src/locks.rs b/core-rust/node-common/src/locks.rs index 58200405c8..9f118c14ec 100644 --- a/core-rust/node-common/src/locks.rs +++ b/core-rust/node-common/src/locks.rs @@ -187,6 +187,23 @@ impl LockFactory { } } + /// Creates a new DB lock with the current configuration. + /// Note: this is a custom lock primitive - please see its documentation. + pub fn new_db_lock(self, database: D) -> DbLock { + DbLock { + exclusive_live_marker_lock: self.named("exclusive_live").new_mutex(()), + database, + shared_live_access_listener: self + .named("shared_live") + .not_stopping_on_panic() + .into_listener(), + on_demand_snapshot_listener: self + .named("snapshot") + .not_stopping_on_panic() + .into_listener(), + } + } + /// Turns the factory (i.e. its current configuration) into a [`LockListener`] which adds the /// requested features to the lock. fn into_listener(self) -> ActualLockListener { @@ -233,6 +250,68 @@ impl RwLock { } } +/// A custom lock primitive guarding a certain type of database. +/// +/// The database is assumed to be thread-safe on a physical level (i.e. it will not panic nor +/// destroy data when concurrent writes happen; on the contrary: it may offer some row-level or +/// batch-level atomicity guarantees). It may additionally support a cheap creation of its read-only +/// snapshots (by implementing the optional [`Snapshottable`] trait). +/// +/// With the above assumptions, this lock offers a couple of database access options. Please see the +/// linked methods to learn more about: +/// - a direct, non-locked, shared [`Self::access()`] to the live database. +/// - an exclusive [`Self::lock()`] on the live database. +/// - _(optional)_ an on-demand [`Self::snapshot()`] creation. +pub struct DbLock { + exclusive_live_marker_lock: Mutex<()>, + database: D, + shared_live_access_listener: ActualLockListener, // only for metrics of "raw access" + on_demand_snapshot_listener: ActualLockListener, // only for metrics of snapshot operations +} + +/// A (presumably cheap) snapshotting support that a database may have. +pub trait Snapshottable<'s> { + type Snapshot; + + /// Creates a snapshot that will enable continuous access to the frozen, current state of this + /// database. + fn snapshot(&'s self) -> Self::Snapshot; +} + +impl DbLock { + /// Immediately returns a reference to the database (disregarding any [`Self::lock()`])s. + pub fn access(&self) -> impl Deref + '_ { + LockGuard::new(|| &self.database, self.shared_live_access_listener.clone()) + } + + /// Acquires an internal lock and returns a lock guard allowing access to the database. + /// + /// This method should be used by clients who need to coordinate exclusive read/write access to + /// a known mutable region of the database. + // TODO(future enhancement): we really should have a set of `RwLock`s for independent regions? + pub fn lock(&self) -> impl Deref + '_ { + DbLockGuard { + underlying: self.exclusive_live_marker_lock.lock(), + database: &self.database, + } + } +} + +impl<'s, D: Snapshottable<'s>> DbLock { + /// Immediately returns a new snapshot of the database (disregarding any [`Self::lock()`])s. + /// + /// This method should be used by clients who need to see a consistent view of the database at + /// a given moment. Please note that it assumes that all writes happen in atomic batches which + /// do not leave database inconsistent. + // TODO(future enhancement): also provide something like `lock_snapshot_unlock()`? + pub fn snapshot(&'s self) -> impl Deref + '_ { + LockGuard::new( + || SnapshotGuard::new(&self.database), + self.on_demand_snapshot_listener.clone(), + ) + } +} + // Only iternals below: /// A static type of a [`LockListener`] which provides the extra features to locks produced by our @@ -286,6 +365,43 @@ impl Drop for LockGuard { } } +/// A guard for a [`DbLock::snapshot()`]. +/// Since no locking is needed for obtaining a snapshot, its only purpose is to implement [`Deref`]. +struct SnapshotGuard<'s, D: Snapshottable<'s>> { + snapshot: D::Snapshot, +} + +impl<'s, D: Snapshottable<'s>> SnapshotGuard<'s, D> { + fn new(database: &'s D) -> Self { + Self { + snapshot: database.snapshot(), + } + } +} + +impl<'s, D: Snapshottable<'s>> Deref for SnapshotGuard<'s, D> { + type Target = D::Snapshot; + + fn deref(&self) -> &Self::Target { + &self.snapshot + } +} + +/// A guard for a [`DbLock::lock()`]. +pub struct DbLockGuard<'d, D, U> { + #[allow(dead_code)] // only held to release the lock when dropped + underlying: U, + database: &'d D, +} + +impl<'d, D: 'd, U> Deref for DbLockGuard<'d, D, U> { + type Target = D; + + fn deref(&self) -> &Self::Target { + self.database + } +} + /// A wrapper around the complex "any thread-safe only-once function" type, used for the application /// stopper dependency of our facade. #[derive(Clone)] diff --git a/core-rust/state-manager/src/jni/node_rust_environment.rs b/core-rust/state-manager/src/jni/node_rust_environment.rs index dc7e21ea58..b3106fcab4 100644 --- a/core-rust/state-manager/src/jni/node_rust_environment.rs +++ b/core-rust/state-manager/src/jni/node_rust_environment.rs @@ -85,7 +85,7 @@ use crate::priority_mempool::PriorityMempool; use super::fatal_panic_handler::FatalPanicHandler; -use crate::{StateComputer, StateManager, StateManagerConfig, StateManagerDatabaseLock}; +use crate::{ActualStateManagerDatabase, StateComputer, StateManager, StateManagerConfig}; const POINTER_JNI_FIELD_NAME: &str = "rustNodeRustEnvironmentPointer"; @@ -194,7 +194,10 @@ impl JNINodeRustEnvironment { .clone() } - pub fn get_database(env: &JNIEnv, j_node_rust_env: JObject) -> Arc { + pub fn get_database( + env: &JNIEnv, + j_node_rust_env: JObject, + ) -> Arc> { Self::get(env, j_node_rust_env) .state_manager .database diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs index a7d2285595..6fb8d4fbee 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs @@ -1,21 +1,22 @@ +use crate::ActualStateManagerDatabase; +use node_common::locks::DbLock; use std::ops::Deref; use std::sync::Arc; use crate::protocol::*; use crate::traits::*; -use crate::StateManagerDatabaseLock; pub trait ProtocolUpdater { /// Executes these state updates associated with the given protocol version /// that haven't yet been applied /// (hence "remaining", e.g. if node is restarted mid-protocol update). - fn execute_remaining_state_updates(&self, database: Arc); + fn execute_remaining_state_updates(&self, database: Arc>); } pub struct NoOpProtocolUpdater; impl ProtocolUpdater for NoOpProtocolUpdater { - fn execute_remaining_state_updates(&self, _database: Arc) { + fn execute_remaining_state_updates(&self, _database: Arc>) { // no-op } } @@ -41,7 +42,7 @@ impl BatchedUpdater { } impl ProtocolUpdater for BatchedUpdater { - fn execute_remaining_state_updates(&self, database: Arc) { + fn execute_remaining_state_updates(&self, database: Arc>) { let database = database.lock(); let mut txn_committer = ProtocolUpdateTransactionCommitter::new( self.new_protocol_version.clone(), diff --git a/core-rust/state-manager/src/state_computer.rs b/core-rust/state-manager/src/state_computer.rs index c11816a7d7..abf5b0ca62 100644 --- a/core-rust/state-manager/src/state_computer.rs +++ b/core-rust/state-manager/src/state_computer.rs @@ -85,7 +85,7 @@ use transaction_scenarios::scenario::DescribedAddress as ScenarioDescribedAddres use transaction_scenarios::scenario::*; use transaction_scenarios::scenarios::*; -use node_common::locks::{LockFactory, Mutex, RwLock}; +use node_common::locks::{DbLock, LockFactory, Mutex, RwLock}; use prometheus::Registry; use tracing::{debug, info, warn}; @@ -102,7 +102,7 @@ use std::time::{Instant, SystemTime}; pub struct StateComputer { network: NetworkDefinition, - database: Arc, + database: Arc>, mempool_manager: Arc, execution_configurator: Arc>, pending_transaction_result_cache: Arc>, @@ -122,7 +122,7 @@ impl StateComputer { pub fn new( network: &NetworkDefinition, vertex_limits_config: VertexLimitsConfig, - database: Arc, + database: Arc>, mempool_manager: Arc, execution_configurator: Arc>, pending_transaction_result_cache: Arc>, diff --git a/core-rust/state-manager/src/state_manager.rs b/core-rust/state-manager/src/state_manager.rs index 542d4ae521..92c6e988e8 100644 --- a/core-rust/state-manager/src/state_manager.rs +++ b/core-rust/state-manager/src/state_manager.rs @@ -87,12 +87,10 @@ use crate::{ mempool_manager::MempoolManager, mempool_relay_dispatcher::MempoolRelayDispatcher, priority_mempool::PriorityMempool, - store::{ - jmt_gc::StateHashTreeGc, DatabaseBackendConfig, DatabaseFlags, RawDbMetricsCollector, - StateManagerDatabaseLock, - }, + store::{jmt_gc::StateHashTreeGc, DatabaseBackendConfig, DatabaseFlags, RawDbMetricsCollector}, transaction::{CachedCommittabilityValidator, CommittabilityValidator, TransactionPreviewer}, - PendingTransactionResultCache, ProtocolUpdateResult, StateComputer, StateManagerDatabase, + ActualStateManagerDatabase, PendingTransactionResultCache, ProtocolUpdateResult, StateComputer, + StateManagerDatabase, }; /// An interval between time-intensive measurement of raw DB metrics. @@ -146,7 +144,7 @@ impl StateManagerConfig { pub struct StateManager { config: StateManagerConfig, pub state_computer: Arc, - pub database: Arc, + pub database: Arc>, pub pending_transaction_result_cache: Arc>, pub mempool: Arc>, pub mempool_manager: Arc, @@ -189,10 +187,7 @@ impl StateManager { } }; - let database = Arc::new(StateManagerDatabaseLock::new( - lock_factory.named("database"), - raw_db, - )); + let database = Arc::new(lock_factory.named("database").new_db_lock(raw_db)); if let Err(err) = config.protocol_config.validate() { panic!("Protocol misconfiguration: {}", err); diff --git a/core-rust/state-manager/src/store/jmt_gc.rs b/core-rust/state-manager/src/store/jmt_gc.rs index f0ba96bee7..bba5d374c3 100644 --- a/core-rust/state-manager/src/store/jmt_gc.rs +++ b/core-rust/state-manager/src/store/jmt_gc.rs @@ -62,6 +62,7 @@ * permissions under this License. */ +use node_common::locks::DbLock; use radix_engine::types::{Categorize, Decode, Encode}; use radix_engine_stores::hash_tree::tree_store::{ NodeKey, ReadableTreeStore, StaleTreePart, TreeChildEntry, TreeNode, @@ -75,7 +76,7 @@ use tracing::info; use crate::store::traits::gc::StateHashTreeGcStore; use crate::store::traits::proofs::QueryableProofStore; use crate::store::traits::StaleTreePartsV1; -use crate::{StateManagerDatabaseLock, StateVersion, StateVersionDelta}; +use crate::{ActualStateManagerDatabase, StateVersion, StateVersionDelta}; /// A maximum number of JMT nodes collected into "batch delete" buffer. /// Needed only to avoid OOM problems. @@ -95,14 +96,17 @@ pub struct StateHashTreeGcConfig { /// A garbage collector of sufficiently-old stale state hash tree nodes. /// The implementation is suited for being driven by an external scheduler. pub struct StateHashTreeGc { - database: Arc, + database: Arc>, interval: Duration, history_len: StateVersionDelta, } impl StateHashTreeGc { /// Creates a new GC. - pub fn new(database: Arc, config: StateHashTreeGcConfig) -> Self { + pub fn new( + database: Arc>, + config: StateHashTreeGcConfig, + ) -> Self { Self { database, interval: Duration::from_secs(u64::from(config.interval_sec)), @@ -120,8 +124,8 @@ impl StateHashTreeGc { /// /// *Note on concurrent database access:* /// The JMT's GC process, by its nature, only accesses "old" (i.e. not "top-of-ledger" new) - /// JMT DB rows. For this reason, it can use the direct [`StateManagerDatabaseLock::access()`] - /// and effectively own these rows (for reads and deletes), without locking the database. + /// JMT DB rows. For this reason, it can use the direct [`DbLock::access()`] and effectively own + /// these rows (for reads and deletes), without locking the database. pub fn run(&self) { let database = self.database.access(); let current_state_version = database.max_state_version(); diff --git a/core-rust/state-manager/src/store/mod.rs b/core-rust/state-manager/src/store/mod.rs index 429f96e01d..84cef14cf0 100644 --- a/core-rust/state-manager/src/store/mod.rs +++ b/core-rust/state-manager/src/store/mod.rs @@ -71,8 +71,8 @@ mod typed_cf_api; use crate::store::traits::measurement::MeasurableDatabase; use crate::RawDbMetrics; +use node_common::locks::DbLock; use prometheus::Registry; -pub use rocks_db::StateManagerDatabaseLock; pub use rocks_db::{ActualStateManagerDatabase, StateManagerDatabase}; pub use rocks_db::{ReadableRocks, WriteableRocks}; use sbor::{Categorize, Decode, Encode}; @@ -86,13 +86,16 @@ pub struct DatabaseBackendConfig { /// A synchronous collector of costly (I/O-intensive) raw DB metrics. pub struct RawDbMetricsCollector { - database: Arc, + database: Arc>, raw_db_metrics: RawDbMetrics, } impl RawDbMetricsCollector { /// Creates a collector measuring the given DB and updating the metrics in the given registry. - pub fn new(database: Arc, metric_registry: &Registry) -> Self { + pub fn new( + database: Arc>, + metric_registry: &Registry, + ) -> Self { Self { database, raw_db_metrics: RawDbMetrics::new(metric_registry), @@ -102,7 +105,7 @@ impl RawDbMetricsCollector { /// Performs a single "collect measurements + update metric primitives" run. /// Should be called periodically. pub fn run(&self) { - let statistics = self.database.get_data_volume_statistics(); + let statistics = self.database.access().get_data_volume_statistics(); self.raw_db_metrics.update(statistics); } } diff --git a/core-rust/state-manager/src/store/proofs_gc.rs b/core-rust/state-manager/src/store/proofs_gc.rs index 81c1b6397e..170297a3e7 100644 --- a/core-rust/state-manager/src/store/proofs_gc.rs +++ b/core-rust/state-manager/src/store/proofs_gc.rs @@ -64,6 +64,7 @@ use radix_engine::types::{Categorize, Decode, Encode}; +use node_common::locks::DbLock; use radix_engine_common::types::Epoch; use std::ops::Deref; use std::sync::Arc; @@ -81,7 +82,7 @@ use crate::traits::GetSyncableTxnsAndProofError::{ FailedToPrepareAResponseWithinLimits, NothingToServeAtTheGivenStateVersion, RefusedToServeGenesis, RefusedToServeProtocolUpdate, }; -use crate::{LedgerProof, StateManagerDatabase, StateManagerDatabaseLock, StateVersion}; +use crate::{ActualStateManagerDatabase, LedgerProof, StateManagerDatabase, StateVersion}; /// A configuration for [`LedgerProofsGc`]. #[derive(Debug, Categorize, Encode, Decode, Clone, Default)] @@ -103,7 +104,7 @@ pub struct LedgerProofsGcConfig { /// proof" logic (used e.g. for ledger-sync responses). /// The implementation is suited for being driven by an external scheduler. pub struct LedgerProofsGc { - database: Arc, + database: Arc>, interval: Duration, most_recent_full_resolution_epoch_count: u64, limits_config: LedgerSyncLimitsConfig, @@ -112,7 +113,7 @@ pub struct LedgerProofsGc { impl LedgerProofsGc { /// Creates a new GC. pub fn new( - database: Arc, + database: Arc>, gc_config: LedgerProofsGcConfig, limits_config: LedgerSyncLimitsConfig, ) -> Self { @@ -139,11 +140,11 @@ impl LedgerProofsGc { /// /// *Note on concurrent database access:* /// The proofs' GC process, by its nature, only accesses "old" (i.e. not "top-of-ledger" new) - /// proof DB rows. For this reason, it can use the direct [`StateManagerDatabaseLock::access()`] - /// and effectively own these rows (for reads and deletes), without locking the database. + /// proof DB rows. For this reason, it can use the direct [`DbLock::access()`] and effectively + /// own these rows (for reads and deletes), without locking the database. /// Of course, a concurrent ledger sync may request a range of "old" proofs too, and thus it - /// should use a [`StateManagerDatabaseLock::snapshot()`] to avoid relying on proofs which are - /// about to be deleted. + /// should use a [`DbLock::snapshot()`] to avoid relying on proofs which are about to be + /// deleted. pub fn run(&self) -> Vec { // Read the GC's persisted state and initialize the run: let database = self.database.access(); diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index c3da2a55d9..dc78e2586a 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -64,7 +64,6 @@ use std::collections::HashSet; use std::fmt; -use std::ops::Deref; use crate::store::traits::*; use crate::{ @@ -89,7 +88,7 @@ use radix_engine_store_interface::interface::*; use radix_engine_store_interface::db_key_mapper::{DatabaseKeyMapper, SpreadPrefixKeyMapper}; use std::path::PathBuf; -use node_common::locks::{LockFactory, Mutex}; +use node_common::locks::Snapshottable; use tracing::{error, info, warn}; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice}; @@ -654,37 +653,11 @@ impl<'db> ReadableRocks for SnapshotRocks<'db> { pub type ActualStateManagerDatabase = StateManagerDatabase; -// TODO(wip): doc -pub struct StateManagerDatabaseLock { - database: ActualStateManagerDatabase, - mutex: Mutex<()>, -} - -impl StateManagerDatabaseLock { - pub fn new(lock_factory: LockFactory, database: ActualStateManagerDatabase) -> Self { - Self { - database, - mutex: lock_factory.new_mutex(()), - } - } - - pub fn access( - &self, - ) -> impl Deref> + '_ { - &self.database // TODO(wip): return tracking wrap? - } - - pub fn lock(&self) -> impl Deref> + '_ { - DatabaseLockGuard { - underlying: self.mutex.lock(), - database: &self.database, - } - } +impl<'db> Snapshottable<'db> for StateManagerDatabase { + type Snapshot = StateManagerDatabase>; - pub fn snapshot( - &self, - ) -> impl Deref> + '_ { - let StateManagerDatabase { config, rocks } = &self.database; + fn snapshot(&'db self) -> Self::Snapshot { + let StateManagerDatabase { config, rocks } = self; StateManagerDatabase { config: config.clone(), rocks: rocks.snapshot(), @@ -692,29 +665,6 @@ impl StateManagerDatabaseLock { } } -pub struct DatabaseLockGuard<'d, D, U> { - #[allow(dead_code)] // only held to release the lock when dropped - underlying: U, - database: &'d D, -} - -impl<'d, D: 'd, U> Deref for DatabaseLockGuard<'d, D, U> { - type Target = D; - - fn deref(&self) -> &Self::Target { - self.database - } -} - -impl<'db> Deref for StateManagerDatabase> { - // TODO(wip): replace with a tracking wrap - type Target = StateManagerDatabase>; - - fn deref(&self) -> &Self::Target { - self - } -} - /// A RocksDB-backed persistence layer for state manager. pub struct StateManagerDatabase { /// Database feature flags. @@ -925,7 +875,7 @@ impl ConfigurableDatabase for StateManagerDatabase { } } -impl MeasurableDatabase for StateManagerDatabaseLock { +impl MeasurableDatabase for ActualStateManagerDatabase { fn get_data_volume_statistics(&self) -> Vec { let mut statistics = ALL_COLUMN_FAMILIES .iter() @@ -936,7 +886,7 @@ impl MeasurableDatabase for StateManagerDatabaseLock { ) }) .collect::>(); - let live_files = match self.database.rocks.db.live_files() { + let live_files = match self.rocks.db.live_files() { Ok(live_files) => live_files, Err(err) => { warn!("could not get DB live files; returning 0: {:?}", err); diff --git a/core-rust/state-manager/src/transaction/preview.rs b/core-rust/state-manager/src/transaction/preview.rs index 8a8f88a0c3..8e59ffd643 100644 --- a/core-rust/state-manager/src/transaction/preview.rs +++ b/core-rust/state-manager/src/transaction/preview.rs @@ -1,4 +1,4 @@ -use node_common::locks::RwLock; +use node_common::locks::{DbLock, RwLock}; use radix_engine::transaction::{PreviewError, TransactionReceipt, TransactionResult}; use radix_engine_store_interface::db_key_mapper::SpreadPrefixKeyMapper; use std::ops::{Deref, Range}; @@ -9,8 +9,8 @@ use crate::query::StateManagerSubstateQueries; use crate::store::traits::QueryableProofStore; use crate::transaction::*; use crate::{ - GlobalBalanceSummary, LedgerHeader, LedgerStateChanges, PreviewRequest, ProcessedCommitResult, - StateManagerDatabaseLock, + ActualStateManagerDatabase, GlobalBalanceSummary, LedgerHeader, LedgerStateChanges, + PreviewRequest, ProcessedCommitResult, }; use radix_engine_common::prelude::*; use transaction::model::*; @@ -20,7 +20,7 @@ use transaction::validation::ValidationConfig; /// A transaction preview runner. pub struct TransactionPreviewer { - database: Arc, + database: Arc>, execution_configurator: Arc>, validation_config: ValidationConfig, } @@ -34,7 +34,7 @@ pub struct ProcessedPreviewResult { impl TransactionPreviewer { pub fn new( - database: Arc, + database: Arc>, execution_configurator: Arc>, validation_config: ValidationConfig, ) -> Self { diff --git a/core-rust/state-manager/src/transaction/validation.rs b/core-rust/state-manager/src/transaction/validation.rs index d64eb7a46b..7a00a4e6d3 100644 --- a/core-rust/state-manager/src/transaction/validation.rs +++ b/core-rust/state-manager/src/transaction/validation.rs @@ -1,4 +1,4 @@ -use node_common::locks::RwLock; +use node_common::locks::{DbLock, RwLock}; use std::ops::Deref; use std::sync::Arc; use std::time::SystemTime; @@ -15,8 +15,8 @@ use crate::store::traits::transactions::QueryableTransactionStore; use crate::store::traits::{QueryableProofStore, TransactionIndex}; use crate::transaction::{ExecutionConfigurator, TransactionLogic}; use crate::{ - AlreadyCommittedError, AtState, ExecutionRejectionReason, PendingTransactionRecord, - PendingTransactionResultCache, RejectionReason, StateManagerDatabaseLock, TransactionAttempt, + ActualStateManagerDatabase, AlreadyCommittedError, AtState, ExecutionRejectionReason, + PendingTransactionRecord, PendingTransactionResultCache, RejectionReason, TransactionAttempt, }; use transaction::prelude::*; @@ -181,14 +181,14 @@ impl From for LedgerTransactionValidationError { /// A validator for `NotarizedTransaction`, deciding whether they would be rejected or not-rejected /// (i.e. "committable") at a specific state of the `store`. pub struct CommittabilityValidator { - database: Arc, + database: Arc>, execution_configurator: Arc>, user_transaction_validator: NotarizedTransactionValidator, } impl CommittabilityValidator { pub fn new( - database: Arc, + database: Arc>, execution_configurator: Arc>, user_transaction_validator: NotarizedTransactionValidator, ) -> Self { @@ -297,14 +297,14 @@ impl CommittabilityValidator { /// A caching wrapper for a `CommittabilityValidator`. pub struct CachedCommittabilityValidator { - database: Arc, + database: Arc>, committability_validator: Arc>, pending_transaction_result_cache: Arc>, } impl CachedCommittabilityValidator { pub fn new( - database: Arc, + database: Arc>, committability_validator: Arc>, pending_transaction_result_cache: Arc>, ) -> Self { From 8e71cadaec1751e729f5f224329a7c11a9c04d73 Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Thu, 1 Feb 2024 08:45:49 +0100 Subject: [PATCH 10/22] Minor rustdoc enhancements + Cleanups. --- core-rust/node-common/src/locks.rs | 38 +++++++++---------- core-rust/state-manager/src/state_manager.rs | 6 --- core-rust/state-manager/src/store/rocks_db.rs | 7 ++++ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/core-rust/node-common/src/locks.rs b/core-rust/node-common/src/locks.rs index 9f118c14ec..40fa565d5b 100644 --- a/core-rust/node-common/src/locks.rs +++ b/core-rust/node-common/src/locks.rs @@ -280,14 +280,18 @@ pub trait Snapshottable<'s> { impl DbLock { /// Immediately returns a reference to the database (disregarding any [`Self::lock()`])s. + /// + /// This method should be used by clients who: + /// - read data known to be immutable, + /// - or read+write data which they exclusively own. pub fn access(&self) -> impl Deref + '_ { LockGuard::new(|| &self.database, self.shared_live_access_listener.clone()) } /// Acquires an internal lock and returns a lock guard allowing access to the database. /// - /// This method should be used by clients who need to coordinate exclusive read/write access to - /// a known mutable region of the database. + /// This method should be used by clients who need to coordinate an exclusive read+write access + /// to a known mutable region of the database. // TODO(future enhancement): we really should have a set of `RwLock`s for independent regions? pub fn lock(&self) -> impl Deref + '_ { DbLockGuard { @@ -303,10 +307,13 @@ impl<'s, D: Snapshottable<'s>> DbLock { /// This method should be used by clients who need to see a consistent view of the database at /// a given moment. Please note that it assumes that all writes happen in atomic batches which /// do not leave database inconsistent. - // TODO(future enhancement): also provide something like `lock_snapshot_unlock()`? + // TODO(future enhancement): also provide something like `lock_snapshot_unlock()`, which would + // not need the "writes are atomic+consistent" assumption? pub fn snapshot(&'s self) -> impl Deref + '_ { LockGuard::new( - || SnapshotGuard::new(&self.database), + || OwnedDeref { + owned: self.database.snapshot(), + }, self.on_demand_snapshot_listener.clone(), ) } @@ -365,31 +372,22 @@ impl Drop for LockGuard { } } -/// A guard for a [`DbLock::snapshot()`]. -/// Since no locking is needed for obtaining a snapshot, its only purpose is to implement [`Deref`]. -struct SnapshotGuard<'s, D: Snapshottable<'s>> { - snapshot: D::Snapshot, +/// A simple wrapper used only to implement [`Deref`] for an owned instance. +struct OwnedDeref { + owned: T, } -impl<'s, D: Snapshottable<'s>> SnapshotGuard<'s, D> { - fn new(database: &'s D) -> Self { - Self { - snapshot: database.snapshot(), - } - } -} - -impl<'s, D: Snapshottable<'s>> Deref for SnapshotGuard<'s, D> { - type Target = D::Snapshot; +impl Deref for OwnedDeref { + type Target = T; fn deref(&self) -> &Self::Target { - &self.snapshot + &self.owned } } /// A guard for a [`DbLock::lock()`]. pub struct DbLockGuard<'d, D, U> { - #[allow(dead_code)] // only held to release the lock when dropped + #[allow(dead_code)] // only held to release the marker lock when dropped underlying: U, database: &'d D, } diff --git a/core-rust/state-manager/src/state_manager.rs b/core-rust/state-manager/src/state_manager.rs index 92c6e988e8..d717da7a67 100644 --- a/core-rust/state-manager/src/state_manager.rs +++ b/core-rust/state-manager/src/state_manager.rs @@ -154,12 +154,6 @@ pub struct StateManager { } impl StateManager { - pub fn test(&self, metrics_registry: &Registry) { - let mut write_mempool = self.mempool.write(); - *write_mempool = PriorityMempool::new(MempoolConfig::default(), metrics_registry); - drop(write_mempool); - } - pub fn new( config: StateManagerConfig, mempool_relay_dispatcher: Option, diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index dc78e2586a..567ea920aa 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -656,6 +656,13 @@ pub type ActualStateManagerDatabase = StateManagerDatabase; impl<'db> Snapshottable<'db> for StateManagerDatabase { type Snapshot = StateManagerDatabase>; + // TODO(potential performance gain): This is the place where we could use a cached snapshot + // instead of creating a new one. There are a few options: e.g. cache on-demand (after + // detecting that DB version has grown) or actively hot-swap a snapshot after each batch-write. + // However, maybe it's not worth optimizing for at all: according to the measurements from + // RocksDB authors (https://github.com/facebook/rocksdb/issues/5083), rapid snapshotting *can* + // become a performance problem, but only at rates way above our use-cases (i.e. >10K snapshots + // per second). fn snapshot(&'db self) -> Self::Snapshot { let StateManagerDatabase { config, rocks } = self; StateManagerDatabase { From ed4e7ff5f5a0680715d4ece2ad90ed72e4e1cb59 Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Tue, 6 Feb 2024 17:57:16 +0100 Subject: [PATCH 11/22] Improvements to divergent vertex execution detector --- .../DivergentVertexExecutionDetector.java | 37 ++++++++++++++----- .../com/radixdlt/consensus/NextEpoch.java | 13 ++++++- .../radixdlt/consensus/bft/BFTBuilder.java | 1 + .../bft/processor/BFTQuorumAssembler.java | 12 +++--- .../DivergentVertexExecutionDetectorTest.java | 29 ++++++++++----- .../bft/processor/BFTQuorumAssemblerTest.java | 2 + 6 files changed, 68 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java index 9abd4be6f2..2b8ef0afdf 100644 --- a/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java +++ b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java @@ -67,8 +67,11 @@ import com.google.common.hash.HashCode; import com.google.common.util.concurrent.RateLimiter; import com.radixdlt.consensus.bft.BFTValidatorId; +import com.radixdlt.consensus.bft.BFTValidatorSet; import com.radixdlt.consensus.bft.Round; import com.radixdlt.monitoring.Metrics; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; @@ -85,15 +88,23 @@ public final class DivergentVertexExecutionDetector { private final RateLimiter logRatelimiter = RateLimiter.create(0.05); // At most one log every 20s + private final Metrics metrics; + private final BFTValidatorSet validatorSet; + // vertexId -> ledgerHeader -> validators who voted for (vertexId, ledgerHeader) private final Map>> votesByVertexId = new HashMap<>(); + public DivergentVertexExecutionDetector(Metrics metrics, BFTValidatorSet validatorSet) { + this.metrics = metrics; + this.validatorSet = validatorSet; + } + /** * Processes a received vote. No additional filtering is applied, the caller should ensure that * only relevant votes are being processed (e.g. only votes from a single round). */ - public void process(Vote vote) { + public void processVote(Vote vote) { final var ledgerHeadersByVertexId = votesByVertexId.computeIfAbsent( vote.getVoteData().getProposed().getVertexId(), unused -> new HashMap<>()); @@ -103,7 +114,7 @@ public void process(Vote vote) { authorsByLedgerHeader.add(vote.getAuthor()); } - public void logAndUpdateMetrics(Metrics metrics, Round round) { + public void finalizeAfterRoundAndReset(Round round) { // Divergent executions are the ones that have more than one resultant header // for the same vertexId. final StringBuilder logBuilder = new StringBuilder(); @@ -125,10 +136,17 @@ public void logAndUpdateMetrics(Metrics metrics, Round round) { "In round %s validators have voted for vertex %s but they've computed %s" + " distinct results:\n", round, vertexId, distinctResults.size())); + final var totalStakeDec = new BigDecimal(validatorSet.getTotalPower().toBigInt()); for (var result : distinctResults.entrySet()) { - // Let's list the actual validators if there's less than 10 of them + final var stakeVoted = + result.getValue().stream() + .map(v -> new BigDecimal(validatorSet.getPower(v).toBigInt())) + .reduce(BigDecimal.ZERO, BigDecimal::add); + final var stakeVotedProportion = + stakeVoted.divide(totalStakeDec, 4, RoundingMode.HALF_UP); + // Let's list the actual validators if they represent less than 10% stake final var validatorsDetails = - result.getValue().size() <= 10 + stakeVotedProportion.compareTo(BigDecimal.valueOf(0.1)) < 0 ? " (" + result.getValue().stream() .map(BFTValidatorId::toString) @@ -137,8 +155,11 @@ public void logAndUpdateMetrics(Metrics metrics, Round round) { : ""; logBuilder.append( String.format( - " * %s validator(s)%s computed %s\n", - result.getValue().size(), validatorsDetails, result.getKey())); + " * %s validator(s)%s representing %s stake computed %s\n", + result.getValue().size(), + validatorsDetails, + stakeVotedProportion, + result.getKey())); } }); @@ -148,10 +169,8 @@ public void logAndUpdateMetrics(Metrics metrics, Round round) { + " follow.\n"); log.info(logBuilder.toString()); } - } - /** Resets this detector to its initial state (empty). */ - public void clear() { + // Reset this detector to its initial (empty) state this.votesByVertexId.clear(); } } diff --git a/core/src/main/java/com/radixdlt/consensus/NextEpoch.java b/core/src/main/java/com/radixdlt/consensus/NextEpoch.java index 142282eb91..e178c9a7e7 100644 --- a/core/src/main/java/com/radixdlt/consensus/NextEpoch.java +++ b/core/src/main/java/com/radixdlt/consensus/NextEpoch.java @@ -133,6 +133,17 @@ public int hashCode() { @Override public String toString() { - return "NextEpoch{" + "validators=" + validators + ", epoch=" + epoch + '}'; + final StringBuilder builder = new StringBuilder("NextEpoch{epoch="); + builder.append(epoch); + builder.append(", stake_by_validator_id=["); + validators.forEach( + v -> { + builder.append(v.getValidatorId()); + builder.append("->"); + builder.append(v.getPower()); + builder.append(","); + }); + builder.append("]}"); + return builder.toString(); } } diff --git a/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java b/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java index 3bc998b10b..1f06396014 100644 --- a/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java +++ b/core/src/main/java/com/radixdlt/consensus/bft/BFTBuilder.java @@ -226,6 +226,7 @@ public BFTEventProcessor build() { roundQuorumResolutionDispatcher, timeoutQuorumDelayedResolutionDispatcher, metrics, + new DivergentVertexExecutionDetector(metrics, validatorSet), pendingVotes, roundUpdate, timeoutQuorumResolutionDelayMs); diff --git a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java index 5cdeb4ca44..91cb038882 100644 --- a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java +++ b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java @@ -110,8 +110,7 @@ public record TimeoutQuorumDelayedResolution( private boolean hasCurrentRoundBeenResolved = false; private boolean hasTimeoutQuorumResolutionBeenDelayedInCurrentRound = false; - private final DivergentVertexExecutionDetector divergentVertexExecutionDetector = - new DivergentVertexExecutionDetector(); + private final DivergentVertexExecutionDetector divergentVertexExecutionDetector; public BFTQuorumAssembler( BFTEventProcessorAtCurrentRound forwardTo, @@ -120,6 +119,7 @@ public BFTQuorumAssembler( ScheduledEventDispatcher timeoutQuorumDelayedResolutionDispatcher, Metrics metrics, + DivergentVertexExecutionDetector divergentVertexExecutionDetector, PendingVotes pendingVotes, RoundUpdate initialRoundUpdate, long timeoutQuorumResolutionDelayMs) { @@ -132,6 +132,7 @@ public BFTQuorumAssembler( this.pendingVotes = Objects.requireNonNull(pendingVotes); this.latestRoundUpdate = Objects.requireNonNull(initialRoundUpdate); this.timeoutQuorumResolutionDelayMs = timeoutQuorumResolutionDelayMs; + this.divergentVertexExecutionDetector = divergentVertexExecutionDetector; } @Override @@ -143,8 +144,7 @@ public void processRoundUpdate(RoundUpdate roundUpdate) { // Process the divergent vertex executions we've collected in the previous round // and set it up for the next round. - this.divergentVertexExecutionDetector.logAndUpdateMetrics(metrics, previousRound); - this.divergentVertexExecutionDetector.clear(); + this.divergentVertexExecutionDetector.finalizeAfterRoundAndReset(previousRound); forwardTo.processRoundUpdate(roundUpdate); } @@ -172,7 +172,7 @@ private void processVoteInternal(Vote vote) { switch (this.pendingVotes.insertVote(vote)) { case VoteAccepted unused -> { log.trace("Vote has been processed but didn't form a quorum"); - divergentVertexExecutionDetector.process(vote); + divergentVertexExecutionDetector.processVote(vote); yield Metrics.Bft.VoteProcessingResult.ACCEPTED_NO_QUORUM; } case VoteRejected voteRejected -> { @@ -184,7 +184,7 @@ yield switch (voteRejected.reason()) { }; } case QuorumReached quorumReached -> { - divergentVertexExecutionDetector.process(vote); + divergentVertexExecutionDetector.processVote(vote); this.processQuorum(quorumReached.roundQuorum(), vote); yield switch (quorumReached.roundQuorum()) { case RoundQuorum.RegularRoundQuorum unused -> Metrics.Bft.VoteProcessingResult diff --git a/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java b/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java index 7d6d841c2b..ea186d41d8 100644 --- a/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java +++ b/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java @@ -65,38 +65,47 @@ package com.radixdlt.consensus; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import com.google.common.hash.HashCode; +import com.radixdlt.consensus.bft.BFTValidator; import com.radixdlt.consensus.bft.BFTValidatorId; +import com.radixdlt.consensus.bft.BFTValidatorSet; import com.radixdlt.consensus.bft.Round; import com.radixdlt.crypto.HashUtils; import com.radixdlt.monitoring.Metrics; import com.radixdlt.monitoring.MetricsInitializer; +import com.radixdlt.utils.UInt192; +import java.util.List; import org.junit.Test; public final class DivergentVertexExecutionDetectorTest { @Test public void when_divergent_execution__then_should_update_the_metrics() { - final var detector = new DivergentVertexExecutionDetector(); + final var metrics = new MetricsInitializer().initialize(); final var author1 = BFTValidatorId.random(); final var author2 = BFTValidatorId.random(); final var author3 = BFTValidatorId.random(); + final var validatorSet = + BFTValidatorSet.from( + List.of( + BFTValidator.from(author1, UInt192.ONE), + BFTValidator.from(author2, UInt192.ONE), + BFTValidator.from(author3, UInt192.ONE))); + final var detector = new DivergentVertexExecutionDetector(metrics, validatorSet); final var vertex1 = HashUtils.random256(); final var vertex2 = HashUtils.random256(); // No divergence for vertex1 - detector.process(createVoteForVertexId(author1, vertex1, 1L)); - detector.process(createVoteForVertexId(author2, vertex1, 1L)); + detector.processVote(createVoteForVertexId(author1, vertex1, 1L)); + detector.processVote(createVoteForVertexId(author2, vertex1, 1L)); // Divergence for vertex2 - detector.process(createVoteForVertexId(author1, vertex2, 2L)); - detector.process(createVoteForVertexId(author2, vertex2, 2L)); - detector.process(createVoteForVertexId(author3, vertex2, 3L)); + detector.processVote(createVoteForVertexId(author1, vertex2, 2L)); + detector.processVote(createVoteForVertexId(author2, vertex2, 2L)); + detector.processVote(createVoteForVertexId(author3, vertex2, 3L)); - final var metrics = new MetricsInitializer().initialize(); - detector.logAndUpdateMetrics(metrics, Round.epochInitial()); + detector.finalizeAfterRoundAndReset(Round.epochInitial()); assertEquals( 1, // Expecting 1 divergent execution with 2 conflicting results (label) diff --git a/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java b/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java index 407e983741..229a2ad025 100644 --- a/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java +++ b/core/src/test/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssemblerTest.java @@ -84,6 +84,7 @@ public final class BFTQuorumAssemblerTest { private BFTValidatorId self = mock(BFTValidatorId.class); private Metrics metrics = new MetricsInitializer().initialize(); private PendingVotes pendingVotes = mock(PendingVotes.class); + private BFTValidatorSet validatorSet = mock(BFTValidatorSet.class); private VertexStoreAdapter vertexStore = mock(VertexStoreAdapter.class); private Pacemaker pacemaker = mock(Pacemaker.class); private EventDispatcher roundQuorumResolutionDispatcher = @@ -102,6 +103,7 @@ public void setUp() { this.roundQuorumResolutionDispatcher, this.timeoutQuorumDelayedResolutionDispatcher, this.metrics, + new DivergentVertexExecutionDetector(metrics, validatorSet), this.pendingVotes, mock(RoundUpdate.class), 1000L); From a80cc7551e3ce3d948788cdcb818fab15af933a4 Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Tue, 6 Feb 2024 17:59:16 +0100 Subject: [PATCH 12/22] Rename finalizeAfterRoundAndReset -> summarizeAfterRoundAndReset --- .../radixdlt/consensus/DivergentVertexExecutionDetector.java | 2 +- .../radixdlt/consensus/bft/processor/BFTQuorumAssembler.java | 2 +- .../consensus/DivergentVertexExecutionDetectorTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java index 2b8ef0afdf..a790e8fe1e 100644 --- a/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java +++ b/core/src/main/java/com/radixdlt/consensus/DivergentVertexExecutionDetector.java @@ -114,7 +114,7 @@ public void processVote(Vote vote) { authorsByLedgerHeader.add(vote.getAuthor()); } - public void finalizeAfterRoundAndReset(Round round) { + public void summarizeAfterRoundAndReset(Round round) { // Divergent executions are the ones that have more than one resultant header // for the same vertexId. final StringBuilder logBuilder = new StringBuilder(); diff --git a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java index 91cb038882..8055ea9431 100644 --- a/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java +++ b/core/src/main/java/com/radixdlt/consensus/bft/processor/BFTQuorumAssembler.java @@ -144,7 +144,7 @@ public void processRoundUpdate(RoundUpdate roundUpdate) { // Process the divergent vertex executions we've collected in the previous round // and set it up for the next round. - this.divergentVertexExecutionDetector.finalizeAfterRoundAndReset(previousRound); + this.divergentVertexExecutionDetector.summarizeAfterRoundAndReset(previousRound); forwardTo.processRoundUpdate(roundUpdate); } diff --git a/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java b/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java index ea186d41d8..e513494eac 100644 --- a/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java +++ b/core/src/test/java/com/radixdlt/consensus/DivergentVertexExecutionDetectorTest.java @@ -105,7 +105,7 @@ public void when_divergent_execution__then_should_update_the_metrics() { detector.processVote(createVoteForVertexId(author2, vertex2, 2L)); detector.processVote(createVoteForVertexId(author3, vertex2, 3L)); - detector.finalizeAfterRoundAndReset(Round.epochInitial()); + detector.summarizeAfterRoundAndReset(Round.epochInitial()); assertEquals( 1, // Expecting 1 divergent execution with 2 conflicting results (label) From 6eadef5a6a484d83d0f9d560dd28c2155db68f8a Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Wed, 7 Feb 2024 10:28:45 +0100 Subject: [PATCH 13/22] Addressing the CR comments (renames, more traits). --- .../src/core_api/handlers/status_scenarios.rs | 2 +- core-rust/node-common/src/locks.rs | 28 +++---- .../src/jni/test_state_reader.rs | 2 +- .../src/jni/vertex_store_recovery.rs | 4 +- .../protocol_updates/protocol_updaters.rs | 1 + core-rust/state-manager/src/protocol/test.rs | 7 +- core-rust/state-manager/src/state_manager.rs | 6 +- core-rust/state-manager/src/store/jmt_gc.rs | 6 +- core-rust/state-manager/src/store/mod.rs | 2 +- .../state-manager/src/store/proofs_gc.rs | 8 +- core-rust/state-manager/src/store/rocks_db.rs | 77 +++++++------------ core-rust/state-manager/src/test/mod.rs | 2 +- 12 files changed, 65 insertions(+), 80 deletions(-) diff --git a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs index 5a25c08b8d..4eb7855aff 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs @@ -15,7 +15,7 @@ pub(crate) async fn handle_status_scenarios( assert_matching_network(&request.network, &state.network)?; let context = MappingContext::new(&state.network); - let database = state.state_manager.database.access(); + let database = state.state_manager.database.access_direct(); let scenarios = database.list_all_scenarios(); Ok(Json(models::ScenariosResponse { diff --git a/core-rust/node-common/src/locks.rs b/core-rust/node-common/src/locks.rs index 40fa565d5b..026bc162bd 100644 --- a/core-rust/node-common/src/locks.rs +++ b/core-rust/node-common/src/locks.rs @@ -191,12 +191,9 @@ impl LockFactory { /// Note: this is a custom lock primitive - please see its documentation. pub fn new_db_lock(self, database: D) -> DbLock { DbLock { - exclusive_live_marker_lock: self.named("exclusive_live").new_mutex(()), + cooperative_marker_lock: self.named("cooperative").new_mutex(()), database, - shared_live_access_listener: self - .named("shared_live") - .not_stopping_on_panic() - .into_listener(), + direct_access_listener: self.named("direct").not_stopping_on_panic().into_listener(), on_demand_snapshot_listener: self .named("snapshot") .not_stopping_on_panic() @@ -259,13 +256,13 @@ impl RwLock { /// /// With the above assumptions, this lock offers a couple of database access options. Please see the /// linked methods to learn more about: -/// - a direct, non-locked, shared [`Self::access()`] to the live database. -/// - an exclusive [`Self::lock()`] on the live database. +/// - a completely-non-locked [`Self::access_direct()`] to the live database. +/// - a cooperative [`Self::lock()`] on the live database. /// - _(optional)_ an on-demand [`Self::snapshot()`] creation. pub struct DbLock { - exclusive_live_marker_lock: Mutex<()>, + cooperative_marker_lock: Mutex<()>, database: D, - shared_live_access_listener: ActualLockListener, // only for metrics of "raw access" + direct_access_listener: ActualLockListener, // only for metrics of "direct access" on_demand_snapshot_listener: ActualLockListener, // only for metrics of snapshot operations } @@ -284,18 +281,21 @@ impl DbLock { /// This method should be used by clients who: /// - read data known to be immutable, /// - or read+write data which they exclusively own. - pub fn access(&self) -> impl Deref + '_ { - LockGuard::new(|| &self.database, self.shared_live_access_listener.clone()) + pub fn access_direct(&self) -> impl Deref + '_ { + LockGuard::new(|| &self.database, self.direct_access_listener.clone()) } /// Acquires an internal lock and returns a lock guard allowing access to the database. + /// This can be thought of as a "cooperative locking" (since honest callers need to explicitly + /// choose it instead of [`Self::access_direct()`]). /// /// This method should be used by clients who need to coordinate an exclusive read+write access /// to a known mutable region of the database. - // TODO(future enhancement): we really should have a set of `RwLock`s for independent regions? + // TODO(future enhancement): instead of "direct access + [optional] cooperative locking", we + // really should have a set of *mandatory* locks for logically independent "database regions". pub fn lock(&self) -> impl Deref + '_ { DbLockGuard { - underlying: self.exclusive_live_marker_lock.lock(), + underlying: self.cooperative_marker_lock.lock(), database: &self.database, } } @@ -319,7 +319,7 @@ impl<'s, D: Snapshottable<'s>> DbLock { } } -// Only iternals below: +// Only internals below: /// A static type of a [`LockListener`] which provides the extra features to locks produced by our /// facade. diff --git a/core-rust/state-manager/src/jni/test_state_reader.rs b/core-rust/state-manager/src/jni/test_state_reader.rs index 87137b813d..c4d7374b1f 100644 --- a/core-rust/state-manager/src/jni/test_state_reader.rs +++ b/core-rust/state-manager/src/jni/test_state_reader.rs @@ -277,7 +277,7 @@ extern "system" fn Java_com_radixdlt_testutil_TestStateReader_leastStaleStateHas jni_sbor_coded_call(&env, request_payload, |_: ()| -> u64 { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); let least_stale_state_version = database - .access() // the `get_stale_tree_parts_iter()` is inside a trait requiring writeability + .access_direct() // the `get_stale_tree_parts_iter()` is inside a trait requiring writeability .get_stale_tree_parts_iter() .next() .map(|(state_version, _)| state_version) diff --git a/core-rust/state-manager/src/jni/vertex_store_recovery.rs b/core-rust/state-manager/src/jni/vertex_store_recovery.rs index 119773d268..9efc9422cc 100644 --- a/core-rust/state-manager/src/jni/vertex_store_recovery.rs +++ b/core-rust/state-manager/src/jni/vertex_store_recovery.rs @@ -78,7 +78,7 @@ extern "system" fn Java_com_radixdlt_recovery_VertexStoreRecovery_getVertexStore ) -> jbyteArray { jni_sbor_coded_call(&env, request_payload, |_: ()| -> Option> { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let vertex_store_blob = database.access().get_vertex_store(); + let vertex_store_blob = database.access_direct().get_vertex_store(); vertex_store_blob.map(|blob| blob.0) }) } @@ -93,7 +93,7 @@ extern "system" fn Java_com_radixdlt_recovery_VertexStoreRecovery_saveVertexStor jni_sbor_coded_call(&env, request_payload, |vertex_store_bytes: Vec| { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); database - .access() + .access_direct() .save_vertex_store(VertexStoreBlobV1(vertex_store_bytes)); }) } diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs index 6fb8d4fbee..8070dfe52a 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs @@ -49,6 +49,7 @@ impl ProtocolUpdater for BatchedUpdater { database.deref(), // The costing and logging parameters (of the Engine) are not really used for flash // transactions; let's still pass sane values. + // TODO(when we need non-flash transactions): pass the actually configured flags here. self.new_state_computer_config .execution_configurator(true, false), self.new_state_computer_config diff --git a/core-rust/state-manager/src/protocol/test.rs b/core-rust/state-manager/src/protocol/test.rs index a7ca7ee55b..1af80957b1 100644 --- a/core-rust/state-manager/src/protocol/test.rs +++ b/core-rust/state-manager/src/protocol/test.rs @@ -116,8 +116,9 @@ fn flash_protocol_update_test() { .state_computer .execute_genesis_for_unit_tests_with_default_config(); // Now we can prepare the state updates based on the initialized database - let state_updates = - generate_validator_fee_fix_state_updates(tmp_state_manager.database.access().deref()); + let state_updates = generate_validator_fee_fix_state_updates( + tmp_state_manager.database.access_direct().deref(), + ); state_updates }; @@ -151,7 +152,7 @@ fn flash_protocol_update_test() { Some(custom_v2_protocol_version.clone()) ); - let database = state_manager.database.access(); + let database = state_manager.database.access_direct(); let pre_protocol_update_state_version = database.max_state_version(); // Now let's apply the protocol update (this would normally be called by Java) diff --git a/core-rust/state-manager/src/state_manager.rs b/core-rust/state-manager/src/state_manager.rs index d717da7a67..3f8f96fc5d 100644 --- a/core-rust/state-manager/src/state_manager.rs +++ b/core-rust/state-manager/src/state_manager.rs @@ -187,8 +187,10 @@ impl StateManager { panic!("Protocol misconfiguration: {}", err); }; - let initial_protocol_state = - ProtocolState::compute_initial(database.access().deref(), &config.protocol_config); + let initial_protocol_state = ProtocolState::compute_initial( + database.access_direct().deref(), + &config.protocol_config, + ); let initial_protocol_version = &initial_protocol_state.current_protocol_version; let (initial_state_computer_config, initial_protocol_updater) = config diff --git a/core-rust/state-manager/src/store/jmt_gc.rs b/core-rust/state-manager/src/store/jmt_gc.rs index bba5d374c3..a4af15956b 100644 --- a/core-rust/state-manager/src/store/jmt_gc.rs +++ b/core-rust/state-manager/src/store/jmt_gc.rs @@ -124,10 +124,10 @@ impl StateHashTreeGc { /// /// *Note on concurrent database access:* /// The JMT's GC process, by its nature, only accesses "old" (i.e. not "top-of-ledger" new) - /// JMT DB rows. For this reason, it can use the direct [`DbLock::access()`] and effectively own - /// these rows (for reads and deletes), without locking the database. + /// JMT DB rows. For this reason, it can use the direct [`DbLock::access_direct()`] and + /// effectively own these rows (for reads and deletes), without locking the database. pub fn run(&self) { - let database = self.database.access(); + let database = self.database.access_direct(); let current_state_version = database.max_state_version(); let to_state_version = current_state_version .relative(-self.history_len) diff --git a/core-rust/state-manager/src/store/mod.rs b/core-rust/state-manager/src/store/mod.rs index 84cef14cf0..d3798e4b07 100644 --- a/core-rust/state-manager/src/store/mod.rs +++ b/core-rust/state-manager/src/store/mod.rs @@ -105,7 +105,7 @@ impl RawDbMetricsCollector { /// Performs a single "collect measurements + update metric primitives" run. /// Should be called periodically. pub fn run(&self) { - let statistics = self.database.access().get_data_volume_statistics(); + let statistics = self.database.access_direct().get_data_volume_statistics(); self.raw_db_metrics.update(statistics); } } diff --git a/core-rust/state-manager/src/store/proofs_gc.rs b/core-rust/state-manager/src/store/proofs_gc.rs index 170297a3e7..67fe1dfef7 100644 --- a/core-rust/state-manager/src/store/proofs_gc.rs +++ b/core-rust/state-manager/src/store/proofs_gc.rs @@ -140,14 +140,14 @@ impl LedgerProofsGc { /// /// *Note on concurrent database access:* /// The proofs' GC process, by its nature, only accesses "old" (i.e. not "top-of-ledger" new) - /// proof DB rows. For this reason, it can use the direct [`DbLock::access()`] and effectively - /// own these rows (for reads and deletes), without locking the database. + /// proof DB rows. For this reason, it can use the direct [`DbLock::access_direct()`] and + /// effectively own these rows (for reads and deletes), without locking the database. /// Of course, a concurrent ledger sync may request a range of "old" proofs too, and thus it /// should use a [`DbLock::snapshot()`] to avoid relying on proofs which are about to be /// deleted. pub fn run(&self) -> Vec { // Read the GC's persisted state and initialize the run: - let database = self.database.access(); + let database = self.database.access_direct(); let to_epoch = database .max_completed_epoch() .map(|max_completed_epoch| max_completed_epoch.number()) @@ -390,7 +390,7 @@ mod tests { commit_round_updates_until_epoch(&state_manager, Epoch::of(8)); - let database = db.access(); + let database = db.access_direct(); let post_genesis_epoch_proof = database.get_post_genesis_epoch_proof().unwrap(); // The calculations below rely on this let first_post_genesis_state_version = post_genesis_epoch_proof diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index 567ea920aa..dae96ad762 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -547,6 +547,13 @@ pub trait WriteableRocks: ReadableRocks { fn snapshot(&self) -> SnapshotRocks; } +/// A [`ReadableRocks`] instance opened as secondary instance. +pub trait SecondaryRocks: ReadableRocks { + /// Tries to catch up with the primary by reading as much as possible from the + /// log files. + fn try_catchup_with_primary(&self); +} + /// Direct RocksDB instance. pub struct DirectRocks { db: DB, @@ -602,6 +609,14 @@ impl WriteableRocks for DirectRocks { } } +impl SecondaryRocks for DirectRocks { + fn try_catchup_with_primary(&self) { + self.db + .try_catch_up_with_primary() + .expect("secondary DB catchup"); + } +} + /// Snapshot of RocksDB. /// /// Implementation note: @@ -720,43 +735,7 @@ impl ActualStateManagerDatabase { } } -/// A wrapper for [`DirectRocks`] which only exposes it as [`ReadableRocks`]. -/// This is needed to restrict the writing capabilities in compile time (when opening RocksDB in -/// read-only or secondary mode). -pub struct ReadonlyRocks { - wrapped: DirectRocks, -} - -impl ReadableRocks for ReadonlyRocks { - fn cf_handle(&self, name: &str) -> &ColumnFamily { - self.wrapped.cf_handle(name) - } - - fn iterator_cf( - &self, - cf: &impl AsColumnFamilyRef, - mode: IteratorMode, - ) -> Box + '_> { - self.wrapped.iterator_cf(cf, mode) - } - - fn get_pinned_cf( - &self, - cf: &impl AsColumnFamilyRef, - key: impl AsRef<[u8]>, - ) -> Option { - self.wrapped.get_pinned_cf(cf, key) - } - - fn multi_get_cf<'a>( - &'a self, - keys: impl IntoIterator)>, - ) -> Vec>> { - self.wrapped.multi_get_cf(keys) - } -} - -impl StateManagerDatabase { +impl StateManagerDatabase { /// Creates a readonly [`StateManagerDatabase`] that allows only reading from the store, while /// some other process is writing to it. /// @@ -767,7 +746,7 @@ impl StateManagerDatabase { /// way of making it clear that it only wants read lock and not a write lock. /// /// [`ledger-tools`]: https://github.com/radixdlt/ledger-tools - pub fn new_read_only(root: PathBuf) -> Result { + pub fn new_read_only(root: PathBuf) -> StateManagerDatabase { let mut db_opts = Options::default(); db_opts.create_if_missing(false); db_opts.create_missing_column_families(false); @@ -781,20 +760,24 @@ impl StateManagerDatabase { DB::open_cf_descriptors_read_only(&db_opts, root.as_path(), column_families, false) .unwrap(); - Ok(StateManagerDatabase { + StateManagerDatabase { config: DatabaseFlags { enable_local_transaction_execution_index: false, enable_account_change_index: false, }, - rocks: ReadonlyRocks { - wrapped: DirectRocks { db }, - }, - }) + rocks: DirectRocks { db }, + } } +} +impl StateManagerDatabase { /// Creates a [`StateManagerDatabase`] as a secondary instance which may catch up with the /// primary. - pub fn new_as_secondary(root: PathBuf, temp: PathBuf, column_families: Vec<&str>) -> Self { + pub fn new_as_secondary( + root: PathBuf, + temp: PathBuf, + column_families: Vec<&str>, + ) -> StateManagerDatabase { let mut db_opts = Options::default(); db_opts.create_if_missing(false); db_opts.create_missing_column_families(false); @@ -817,14 +800,12 @@ impl StateManagerDatabase { enable_local_transaction_execution_index: false, enable_account_change_index: false, }, - rocks: ReadonlyRocks { - wrapped: DirectRocks { db }, - }, + rocks: DirectRocks { db }, } } pub fn try_catchup_with_primary(&self) { - self.rocks.wrapped.db.try_catch_up_with_primary().unwrap(); + self.rocks.try_catchup_with_primary(); } } diff --git a/core-rust/state-manager/src/test/mod.rs b/core-rust/state-manager/src/test/mod.rs index 3a9c3db51a..c3d77b84cf 100644 --- a/core-rust/state-manager/src/test/mod.rs +++ b/core-rust/state-manager/src/test/mod.rs @@ -26,7 +26,7 @@ pub fn commit_round_updates_until_epoch(state_manager: &StateManager, epoch: Epo pub fn prepare_and_commit_round_update( state_manager: &StateManager, ) -> (PrepareResult, CommitSummary) { - let database = state_manager.database.access(); + let database = state_manager.database.access_direct(); let latest_proof: LedgerProof = database.get_latest_proof().unwrap(); let latest_epoch_proof: LedgerProof = database.get_latest_epoch_proof().unwrap(); let (top_state_version, top_identifiers) = database.get_top_transaction_identifiers().unwrap(); From 28aad02288454d883b87083da55161e66747835c Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Wed, 7 Feb 2024 16:14:20 +0100 Subject: [PATCH 14/22] Applying lock (instead of direct DB access) for get/save vertex store. --- core-rust/state-manager/src/jni/vertex_store_recovery.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-rust/state-manager/src/jni/vertex_store_recovery.rs b/core-rust/state-manager/src/jni/vertex_store_recovery.rs index 9efc9422cc..a5b8ca0a47 100644 --- a/core-rust/state-manager/src/jni/vertex_store_recovery.rs +++ b/core-rust/state-manager/src/jni/vertex_store_recovery.rs @@ -78,7 +78,7 @@ extern "system" fn Java_com_radixdlt_recovery_VertexStoreRecovery_getVertexStore ) -> jbyteArray { jni_sbor_coded_call(&env, request_payload, |_: ()| -> Option> { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); - let vertex_store_blob = database.access_direct().get_vertex_store(); + let vertex_store_blob = database.lock().get_vertex_store(); vertex_store_blob.map(|blob| blob.0) }) } @@ -93,7 +93,7 @@ extern "system" fn Java_com_radixdlt_recovery_VertexStoreRecovery_saveVertexStor jni_sbor_coded_call(&env, request_payload, |vertex_store_bytes: Vec| { let database = JNINodeRustEnvironment::get_database(&env, j_rust_global_context); database - .access_direct() + .lock() .save_vertex_store(VertexStoreBlobV1(vertex_store_bytes)); }) } From 004315953d097118543feaa4f7439163a64cf0d7 Mon Sep 17 00:00:00 2001 From: David Edey Date: Tue, 13 Feb 2024 13:51:45 +0000 Subject: [PATCH 15/22] Update contributing part of README.md --- README.md | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 88e67fedc3..961129fde6 100644 --- a/README.md +++ b/README.md @@ -32,17 +32,8 @@ some of our tests. ## Contribute -To contribute, you'll need to [setup development environment](docs/development/README.md). - -[Contributions](CONTRIBUTING.md) are welcome, we simply ask to: - -* Fork the codebase -* Make changes -* Submit a pull request for review - -When contributing to this repository, we recommend discussing with the development team the change you wish to make using a [GitHub issue](https://github.com/radixdlt/radixdlt/issues) before making changes. - Please follow our [Code of Conduct](CODE_OF_CONDUCT.md) in all your interactions with the project. +See the [Contributing Guide](CONTRIBUTING.md) for more details on how to get involved. ## Links @@ -55,9 +46,9 @@ Please follow our [Code of Conduct](CODE_OF_CONDUCT.md) in all your interactions ## License -The executable components of the Babylon Node Code are licensed under the [Radix Node EULA](http://www.radixdlt.com/terms/nodeEULA). +The executable components of the Babylon Node code are licensed under the [Radix Node EULA](http://www.radixdlt.com/terms/nodeEULA). -The Babylon Node Code is released under the [Radix License 1.0 (modified Apache 2.0)](LICENSE): +The Babylon Node code is released under the [Radix License 1.0 (modified Apache 2.0)](LICENSE): ``` Copyright 2023 Radix Publishing Ltd incorporated in Jersey, Channel Islands. @@ -130,4 +121,4 @@ operation logic, functionality, security and appropriateness of using the Work for any commercial or non-commercial purpose and for any reproduction or redistribution by You of the Work. You assume all risks associated with Your use of the Work and the exercise of permissions under this Licence. -``` \ No newline at end of file +``` From 1701e88a4c54601d8abfec7e47b64f489b782c6c Mon Sep 17 00:00:00 2001 From: David Edey Date: Tue, 13 Feb 2024 14:36:20 +0000 Subject: [PATCH 16/22] Update branching-strategy.md Fix branching strategy guidelines --- docs/branching-strategy.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/branching-strategy.md b/docs/branching-strategy.md index 519a15cc06..2d24949e88 100644 --- a/docs/branching-strategy.md +++ b/docs/branching-strategy.md @@ -4,13 +4,13 @@ Once you have read the [contributing guide](../CONTRIBUTING.md), if you want to > [!NOTE] > -> As of 2024-02-12, the strictly ordered list of supported base branches, starting from furthest upstream, is: +> As of 2024-02-12, the strictly ordered list of supported base branches, starting from earliest/furthest upstream, is: > > * `release/anemone` - This is currently running on mainnet. > * `main` > * `develop` > -> When clicking merge on a PR to one of these branches, it is your duty to ensure that PRs are raised to merge that branch into all downstream supported base branches. +> When clicking merge on a PR to one of these branches, it is your duty to ensure that PRs are raised to merge that branch into all later/downstream supported base branches. ## Summary of approach @@ -22,7 +22,7 @@ We use a variant of `git-flow`, where there are three types of base branches: th * The `develop` branch is the primary integration branch, for work targeting the next protocol version. * The `release/*` branches are for all named protocol versions (i.e. each 1.X in the naming scheme. Typically patch releases should re-use same branch). A subset of release branches are **currently supported** - typically these are those currently on a live environment, or under development. -At any given time, there is a strict ordering on the supported base branches, where the process aims to guarantee all work on previous branches is in the downstream branches. This order (from most upstream to most downstream) is as follows: +At any given time, there is a strict ordering on the supported base branches, where the process aims to guarantee all work on previous branches is in the later/downstream branches. This order (from earliest/most upstream to latest/most downstream) is as follows: * Released `release/*` branches still compatibile with a mainnet network * `main` @@ -58,13 +58,13 @@ Public facing docs change unrelated to another ticket should use a base branch o ### Workflow / CI changes -Workflow changes should branch from the _most downstream_ (earliest) supported branch. Typically this is a `release/*` branch. +Workflow changes should branch from the _most upstream_ (earliest) supported branch. Typically this is a `release/*` branch. -Once the post-merge process is followed, this change will find itself on all downstream base branches too. +Once the post-merge process is followed, this change will find itself on all later/downstream base branches too. This ensures that these changes are on all supported branches, so builds can be built on `develop` or on all supported branches. -## Merge or Rebase? +## Merge or Rebase/Cherry-pick? This strategy relies on the fact that we always merge. From 499b8059dd74de1dacde13179503eaadf24463d6 Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Wed, 14 Feb 2024 18:43:12 +0100 Subject: [PATCH 17/22] Add keygen to node dist --- core/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/build.gradle b/core/build.gradle index 07158f7d81..4b13ede5a3 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -210,6 +210,7 @@ dependencies { implementation project(':olympia-engine') implementation project(':common') implementation project(':core-rust-bridge') + implementation project(':keygen') implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'io.swagger:swagger-annotations:1.5.0' @@ -377,3 +378,7 @@ task deb4docker(dependsOn: buildDeb) { println "SUCCESS: deb package copied for the docker build to: $destinationLocation" } } + +applicationDistribution.from(new File(project(':keygen').buildDir, "scripts")) { + into "bin" +} From 912a08c54884e13cba9529bdab2621b4f27d2c12 Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Wed, 14 Feb 2024 19:06:54 +0100 Subject: [PATCH 18/22] Update RadixKeyStore comment --- .../src/main/java/com/radixdlt/crypto/RadixKeyStore.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java b/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java index dde8b0f13b..5fac7fef22 100644 --- a/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java +++ b/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java @@ -110,11 +110,9 @@ * store, * *

Implementation note:
- * This store uses a PKCS#12 representation for the underlying storage, and the store requires a - * non-empty password to protect it. In order to ease unattended use, note that where a password is - * required, a {@code null}, or zero length password may be provided, in which case the default 5 - * character password, "radix" is used. Clearly this is insecure, and clients should make an effort - * to specify passwords in a secure way. + * This store uses a PKCS#12 representation for the underlying storage. + * It's required to supply a non-null password for the keystore, but it can be empty. + * An empty password will be used as-is, without any replacement default. */ @SecurityCritical(SecurityKind.KEY_STORE) public final class RadixKeyStore implements Closeable { From 6659e6676100703e6f79614d76fcf26a14e63bb1 Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Wed, 14 Feb 2024 19:21:14 +0100 Subject: [PATCH 19/22] Update libc6 version to 2.36-9+deb12u4 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6db7b1749a..a052c7614e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -215,7 +215,7 @@ RUN apt-get update -y \ # Fixes CVE-2023-4911 can be removed when we update the base OS image to include this fix # docker run -it debian:12.1-slim ldd --version # This fix can be removed as long as the version printed in the above command is 2.36-9+deb12u3 or above - libc6=2.36-9+deb12u3 \ + libc6=2.36-9+deb12u4 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* From 46fa5ae7e9f2d12c8818b0a446a6fc12935b145c Mon Sep 17 00:00:00 2001 From: Lukasz Gasior Date: Wed, 14 Feb 2024 19:42:40 +0100 Subject: [PATCH 20/22] Apply code formatter --- common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java b/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java index 5fac7fef22..f136134e98 100644 --- a/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java +++ b/common/src/main/java/com/radixdlt/crypto/RadixKeyStore.java @@ -110,9 +110,9 @@ * store, * *

Implementation note:
- * This store uses a PKCS#12 representation for the underlying storage. - * It's required to supply a non-null password for the keystore, but it can be empty. - * An empty password will be used as-is, without any replacement default. + * This store uses a PKCS#12 representation for the underlying storage. It's required to supply a + * non-null password for the keystore, but it can be empty. An empty password will be used as-is, + * without any replacement default. */ @SecurityCritical(SecurityKind.KEY_STORE) public final class RadixKeyStore implements Closeable { From 8ece02e8a6e563b74d98e332472230db5f83bf9d Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Thu, 15 Feb 2024 12:41:30 +0100 Subject: [PATCH 21/22] Bump scrypto dep to `develop-839137f1` + Fix imports for good --- core-rust/Cargo.lock | 240 ++++++++---------- core-rust/Cargo.toml | 21 +- core-rust/core-api-server/Cargo.toml | 7 +- .../src/core_api/conversions/addressing.rs | 15 +- .../src/core_api/conversions/common.rs | 4 +- .../src/core_api/conversions/context.rs | 4 +- .../src/core_api/conversions/errors.rs | 7 +- .../src/core_api/conversions/hashes.rs | 3 +- .../src/core_api/conversions/keys_and_sigs.rs | 5 +- .../src/core_api/conversions/lts.rs | 15 +- .../src/core_api/conversions/numerics.rs | 5 +- .../src/core_api/conversions/pagination.rs | 3 +- .../src/core_api/conversions/receipt.rs | 15 +- .../substates/access_controller.rs | 5 +- .../substates/access_rules_module.rs | 5 +- .../core_api/conversions/substates/account.rs | 11 +- .../substates/consensus_manager.rs | 7 +- .../core_api/conversions/substates/generic.rs | 5 +- .../conversions/substates/metadata_module.rs | 4 +- .../src/core_api/conversions/substates/mod.rs | 2 +- .../core_api/conversions/substates/package.rs | 6 +- .../core_api/conversions/substates/pools.rs | 12 +- .../conversions/substates/resource.rs | 4 +- .../conversions/substates/royalty_module.rs | 4 +- .../conversions/substates/substate.rs | 20 +- .../substates/transaction_tracker.rs | 5 +- .../conversions/substates/type_info_module.rs | 4 +- .../core-api-server/src/core_api/errors.rs | 2 +- ..._account_all_fungible_resource_balances.rs | 4 +- .../lts/state_account_deposit_behaviour.rs | 8 +- .../lts/state_account_resource_balance.rs | 4 +- .../handlers/lts/transaction_construction.rs | 4 +- .../handlers/lts/transaction_status.rs | 6 +- .../handlers/lts/transaction_submit.rs | 2 +- .../handlers/state_access_controller.rs | 5 +- .../src/core_api/handlers/state_account.rs | 5 +- .../src/core_api/handlers/state_component.rs | 5 +- .../handlers/state_consensus_manager.rs | 3 +- .../core_api/handlers/state_non_fungible.rs | 5 +- .../src/core_api/handlers/state_package.rs | 4 +- .../src/core_api/handlers/state_resource.rs | 6 +- .../src/core_api/handlers/state_validator.rs | 4 +- .../handlers/status_network_configuration.rs | 4 +- .../handlers/status_network_status.rs | 2 +- .../src/core_api/handlers/status_scenarios.rs | 2 +- .../src/core_api/handlers/stream_proofs.rs | 4 +- .../core_api/handlers/stream_transactions.rs | 11 +- .../handlers/transaction_callpreview.rs | 46 ++-- .../core_api/handlers/transaction_parse.rs | 13 +- .../core_api/handlers/transaction_preview.rs | 12 +- .../core_api/handlers/transaction_status.rs | 6 +- .../core_api/handlers/transaction_submit.rs | 2 +- .../core-api-server/src/core_api/helpers.rs | 6 +- .../core-api-server/src/core_api/server.rs | 3 +- core-rust/core-api-server/src/jni/mod.rs | 4 +- core-rust/core-api-server/src/lib.rs | 35 +++ core-rust/jni-export/Cargo.toml | 6 +- core-rust/node-common/Cargo.toml | 6 +- core-rust/node-common/src/config/limits.rs | 2 +- core-rust/node-common/src/config/mod.rs | 2 +- core-rust/node-common/src/java/result.rs | 3 +- core-rust/node-common/src/java/structure.rs | 4 +- core-rust/node-common/src/java/types.rs | 2 +- core-rust/node-common/src/java/utils.rs | 3 +- core-rust/node-common/src/jni/addressing.rs | 5 +- .../node-common/src/jni/scrypto_constants.rs | 3 +- core-rust/node-common/src/lib.rs | 4 + core-rust/node-common/src/utils.rs | 3 +- core-rust/state-manager/Cargo.toml | 6 +- .../state-manager/src/accumulator_tree/mod.rs | 2 +- .../src/accumulator_tree/storage.rs | 2 +- .../src/accumulator_tree/test.rs | 2 +- .../src/jni/fatal_panic_handler.rs | 1 - core-rust/state-manager/src/jni/mempool.rs | 4 +- core-rust/state-manager/src/jni/mod.rs | 2 +- .../src/jni/node_rust_environment.rs | 2 +- .../state-manager/src/jni/protocol_update.rs | 2 +- .../state-manager/src/jni/state_computer.rs | 7 +- .../state-manager/src/jni/state_reader.rs | 9 +- .../src/jni/test_state_reader.rs | 8 +- .../src/jni/transaction_preparer.rs | 7 +- .../src/jni/transaction_store.rs | 2 +- core-rust/state-manager/src/lib.rs | 32 +++ core-rust/state-manager/src/limits.rs | 3 +- .../src/mempool/mempool_manager.rs | 1 - .../src/mempool/mempool_relay_dispatcher.rs | 2 +- .../state-manager/src/mempool/metrics.rs | 8 +- core-rust/state-manager/src/mempool/mod.rs | 7 +- .../pending_transaction_result_cache.rs | 76 +++--- .../src/mempool/priority_mempool.rs | 7 - core-rust/state-manager/src/metrics.rs | 4 +- .../src/protocol/protocol_config.rs | 9 +- .../protocol_configs/config_printer.rs | 3 +- .../dumunet_protocol_config.rs | 2 +- .../mainnet_protocol_config.rs | 2 +- .../src/protocol/protocol_configs/mod.rs | 2 +- .../stokenet_protocol_config.rs | 2 +- .../testnet_protocol_config.rs | 2 +- .../src/protocol/protocol_state.rs | 12 +- .../definitions/anemone_definition.rs | 7 +- .../definitions/custom_definition.rs | 3 +- .../definitions/default_definition.rs | 2 +- .../definitions/test_definition.rs | 2 +- .../protocol_content_overrides.rs | 6 +- .../protocol_update_committer.rs | 4 +- .../protocol_update_definition.rs | 4 +- .../protocol_updates/protocol_updaters.rs | 4 +- core-rust/state-manager/src/protocol/test.rs | 15 +- .../src/query/component_dumper.rs | 7 +- .../query/state_manager_substate_queries.rs | 8 +- core-rust/state-manager/src/receipt.rs | 16 +- core-rust/state-manager/src/staging/cache.rs | 20 +- core-rust/state-manager/src/staging/mod.rs | 3 +- .../src/staging/node_ancestry_resolver.rs | 4 +- .../state-manager/src/staging/overlays.rs | 4 +- core-rust/state-manager/src/staging/result.rs | 17 +- .../state-manager/src/staging/stage_tree.rs | 9 +- core-rust/state-manager/src/state_computer.rs | 22 +- core-rust/state-manager/src/state_manager.rs | 16 +- core-rust/state-manager/src/store/codecs.rs | 5 +- core-rust/state-manager/src/store/db.rs | 9 +- core-rust/state-manager/src/store/jmt_gc.rs | 12 +- .../state-manager/src/store/proofs_gc.rs | 9 +- core-rust/state-manager/src/store/rocks_db.rs | 9 +- core-rust/state-manager/src/store/traits.rs | 21 +- .../state-manager/src/store/typed_cf_api.rs | 2 +- core-rust/state-manager/src/test/mod.rs | 3 +- .../src/transaction/executable_logic.rs | 22 +- .../src/transaction/ledger_transaction.rs | 10 +- .../state-manager/src/transaction/preview.rs | 11 +- .../transaction/round_update_transaction.rs | 7 +- .../src/transaction/series_execution.rs | 3 +- .../src/transaction/validation.rs | 43 ++-- core-rust/state-manager/src/types.rs | 4 +- 134 files changed, 447 insertions(+), 824 deletions(-) diff --git a/core-rust/Cargo.lock b/core-rust/Cargo.lock index ca23882cae..7a10bfcde3 100644 --- a/core-rust/Cargo.lock +++ b/core-rust/Cargo.lock @@ -206,6 +206,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "blueprint-schema-init" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" +dependencies = [ + "bitflags 1.3.2", + "radix-engine-common", + "sbor", + "serde", +] + [[package]] name = "bnum" version = "0.7.0" @@ -366,6 +377,7 @@ version = "0.1.0" dependencies = [ "axum", "blake2", + "blueprint-schema-init", "chrono", "futures", "futures-util", @@ -378,13 +390,13 @@ dependencies = [ "radix-engine", "radix-engine-common", "radix-engine-interface", - "radix-engine-queries", - "radix-engine-store-interface", - "radix-engine-stores", "sbor", "serde", "serde_json", "state-manager", + "substate-store-impls", + "substate-store-interface", + "substate-store-queries", "tokio", "tower", "tower-http", @@ -949,11 +961,11 @@ dependencies = [ "radix-engine", "radix-engine-common", "radix-engine-interface", - "radix-engine-queries", - "radix-engine-store-interface", - "radix-engine-stores", "sbor", "state-manager", + "substate-store-impls", + "substate-store-interface", + "substate-store-queries", "transaction", "transaction-scenarios", "utils", @@ -1174,11 +1186,10 @@ dependencies = [ [[package]] name = "native-sdk" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "radix-engine-common", - "radix-engine-derive", "radix-engine-interface", "sbor", "utils", @@ -1198,10 +1209,10 @@ dependencies = [ "radix-engine", "radix-engine-common", "radix-engine-interface", - "radix-engine-queries", - "radix-engine-store-interface", - "radix-engine-stores", "sbor", + "substate-store-impls", + "substate-store-interface", + "substate-store-queries", "tokio", "tokio-util", "tracing", @@ -1521,10 +1532,11 @@ dependencies = [ [[package]] name = "radix-engine" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "bitflags 1.3.2", + "blueprint-schema-init", "colored", "const-sha1", "hex", @@ -1536,11 +1548,11 @@ dependencies = [ "radix-engine-common", "radix-engine-interface", "radix-engine-macros", - "radix-engine-store-interface", "resources-tracker-macro", "sbor", "serde_json", "strum", + "substate-store-interface", "syn 1.0.93", "transaction", "utils", @@ -1551,8 +1563,8 @@ dependencies = [ [[package]] name = "radix-engine-common" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "bech32", "blake2", @@ -1576,8 +1588,8 @@ dependencies = [ [[package]] name = "radix-engine-derive" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "proc-macro2", "quote", @@ -1587,20 +1599,19 @@ dependencies = [ [[package]] name = "radix-engine-interface" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "bitflags 1.3.2", + "blueprint-schema-init", "const-sha1", "hex", "lazy_static", "paste", "radix-engine-common", - "radix-engine-derive", "radix-engine-macros", "regex", "sbor", - "scrypto-schema", "serde", "serde_json", "strum", @@ -1609,8 +1620,8 @@ dependencies = [ [[package]] name = "radix-engine-macros" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "paste", "proc-macro2", @@ -1621,56 +1632,12 @@ dependencies = [ [[package]] name = "radix-engine-profiling" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "fixedstr", ] -[[package]] -name = "radix-engine-queries" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" -dependencies = [ - "hex", - "itertools 0.10.5", - "paste", - "radix-engine", - "radix-engine-interface", - "radix-engine-store-interface", - "sbor", - "transaction", - "utils", -] - -[[package]] -name = "radix-engine-store-interface" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" -dependencies = [ - "hex", - "itertools 0.10.5", - "radix-engine-common", - "radix-engine-derive", - "radix-engine-interface", - "sbor", - "utils", -] - -[[package]] -name = "radix-engine-stores" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" -dependencies = [ - "hex", - "itertools 0.10.5", - "radix-engine-common", - "radix-engine-derive", - "radix-engine-store-interface", - "sbor", - "utils", -] - [[package]] name = "rand" version = "0.7.3" @@ -1791,8 +1758,8 @@ checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "resources-tracker-macro" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "proc-macro2", "quote", @@ -1867,8 +1834,8 @@ dependencies = [ [[package]] name = "sbor" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "const-sha1", "hex", @@ -1881,8 +1848,8 @@ dependencies = [ [[package]] name = "sbor-derive" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "proc-macro2", "sbor-derive-common", @@ -1890,8 +1857,8 @@ dependencies = [ [[package]] name = "sbor-derive-common" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "const-sha1", "itertools 0.10.5", @@ -1915,54 +1882,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "scrypto" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" -dependencies = [ - "bech32", - "const-sha1", - "hex", - "num-bigint", - "num-traits", - "paste", - "radix-engine-common", - "radix-engine-derive", - "radix-engine-interface", - "sbor", - "scrypto-derive", - "scrypto-schema", - "strum", - "utils", -] - -[[package]] -name = "scrypto-derive" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" -dependencies = [ - "proc-macro2", - "quote", - "radix-engine-common", - "regex", - "sbor", - "scrypto-schema", - "serde", - "serde_json", - "syn 1.0.93", -] - -[[package]] -name = "scrypto-schema" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" -dependencies = [ - "bitflags 1.3.2", - "radix-engine-common", - "sbor", - "serde", -] - [[package]] name = "secp256k1" version = "0.24.3" @@ -2189,13 +2108,13 @@ dependencies = [ "radix-engine", "radix-engine-common", "radix-engine-interface", - "radix-engine-queries", - "radix-engine-store-interface", - "radix-engine-stores", "rand 0.8.5", "rocksdb", "sbor", "slotmap", + "substate-store-impls", + "substate-store-interface", + "substate-store-queries", "tempfile", "tokio", "tracing", @@ -2226,6 +2145,48 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "substate-store-impls" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" +dependencies = [ + "hex", + "itertools 0.10.5", + "radix-engine-common", + "sbor", + "substate-store-interface", + "utils", +] + +[[package]] +name = "substate-store-interface" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" +dependencies = [ + "hex", + "itertools 0.10.5", + "radix-engine-common", + "sbor", + "utils", +] + +[[package]] +name = "substate-store-queries" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" +dependencies = [ + "hex", + "itertools 0.10.5", + "paste", + "radix-engine", + "radix-engine-common", + "radix-engine-interface", + "sbor", + "substate-store-interface", + "transaction", + "utils", +] + [[package]] name = "subtle" version = "2.5.0" @@ -2517,8 +2478,8 @@ dependencies = [ [[package]] name = "transaction" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "bech32", "hex", @@ -2532,17 +2493,18 @@ dependencies = [ [[package]] name = "transaction-scenarios" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ + "blueprint-schema-init", "hex", "itertools 0.10.5", "radix-engine", + "radix-engine-common", "radix-engine-interface", - "radix-engine-store-interface", - "radix-engine-stores", "sbor", - "scrypto", + "substate-store-impls", + "substate-store-interface", "transaction", "utils", "walkdir", @@ -2589,8 +2551,8 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "utils" -version = "1.1.0-rc1" -source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=anemone-e212f2ea#e212f2ea33f05f7980ef6b4026edf60e162aaae3" +version = "1.2.0-dev" +source = "git+https://github.com/radixdlt/radixdlt-scrypto?tag=develop-839137f1#839137f1b34f45273c51429459221080b4d41b1d" dependencies = [ "indexmap 2.0.0-pre", "serde", diff --git a/core-rust/Cargo.toml b/core-rust/Cargo.toml index 6869b93b7e..8276747b14 100644 --- a/core-rust/Cargo.toml +++ b/core-rust/Cargo.toml @@ -22,16 +22,17 @@ resolver = "2" # $ git push origin "release_name-BLAH" # * Then use tag="release_name-BLAH" in the below dependencies. # -sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea", features = ["serde"] } -transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea" } -transaction-scenarios = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea" } -radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea", features = ["serde"] } -radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea" } -radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea" } -radix-engine-stores = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea" } -radix-engine-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea" } -radix-engine-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea" } -utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "anemone-e212f2ea", features = ["serde"] } +sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1", features = ["serde"] } +transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1" } +transaction-scenarios = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1" } +radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1", features = ["serde"] } +radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1" } +radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1" } +substate-store-impls = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1" } +substate-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1" } +substate-store-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1" } +utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1", features = ["serde"] } +blueprint-schema-init = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "develop-839137f1", features = ["serde"] } itertools = { version = "0.11.0" } jni = { version = "0.19.0" } diff --git a/core-rust/core-api-server/Cargo.toml b/core-rust/core-api-server/Cargo.toml index cadd7ac886..b75f9aa1f7 100644 --- a/core-rust/core-api-server/Cargo.toml +++ b/core-rust/core-api-server/Cargo.toml @@ -12,9 +12,10 @@ transaction = { workspace = true } radix-engine-common = { workspace = true } radix-engine-interface = { workspace = true } radix-engine = { workspace = true } -radix-engine-stores = { workspace = true } -radix-engine-store-interface = { workspace = true } -radix-engine-queries = { workspace = true } +substate-store-impls = { workspace = true } +substate-store-interface = { workspace = true } +substate-store-queries = { workspace = true } +blueprint-schema-init = { workspace = true } utils = { workspace = true } # Non-Radix Engine Dependencies: diff --git a/core-rust/core-api-server/src/core_api/conversions/addressing.rs b/core-rust/core-api-server/src/core_api/conversions/addressing.rs index 069fec52d2..c81a1d5fc5 100644 --- a/core-rust/core-api-server/src/core_api/conversions/addressing.rs +++ b/core-rust/core-api-server/src/core_api/conversions/addressing.rs @@ -1,20 +1,7 @@ use crate::core_api::models; use crate::core_api::*; +use crate::scrypto_prelude::*; use models::SubstateType; -use radix_engine::blueprints::account::{AccountField, AccountTypedSubstateKey}; -use radix_engine::blueprints::pool::v1::substates::multi_resource_pool::{ - MultiResourcePoolField, MultiResourcePoolTypedSubstateKey, -}; -use radix_engine::blueprints::pool::v1::substates::one_resource_pool::{ - OneResourcePoolField, OneResourcePoolTypedSubstateKey, -}; -use radix_engine::blueprints::pool::v1::substates::two_resource_pool::{ - TwoResourcePoolField, TwoResourcePoolTypedSubstateKey, -}; -use radix_engine::types::*; - -use radix_engine_queries::typed_substate_layout::*; -use radix_engine_store_interface::db_key_mapper::*; pub fn to_api_global_address( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/common.rs b/core-rust/core-api-server/src/core_api/conversions/common.rs index 23b1621a92..83ac0adf08 100644 --- a/core-rust/core-api-server/src/core_api/conversions/common.rs +++ b/core-rust/core-api-server/src/core_api/conversions/common.rs @@ -1,6 +1,4 @@ -use radix_engine::types::*; - -use sbor::representations::*; +use crate::scrypto_prelude::*; use state_manager::LedgerHeader; use crate::core_api::handlers::to_api_epoch_round; diff --git a/core-rust/core-api-server/src/core_api/conversions/context.rs b/core-rust/core-api-server/src/core_api/conversions/context.rs index 96c05299aa..2801ada471 100644 --- a/core-rust/core-api-server/src/core_api/conversions/context.rs +++ b/core-rust/core-api-server/src/core_api/conversions/context.rs @@ -1,6 +1,4 @@ -use radix_engine::types::{AddressBech32Decoder, AddressBech32Encoder}; -use radix_engine_interface::network::NetworkDefinition; -use transaction::model::{TransactionHashBech32Decoder, TransactionHashBech32Encoder}; +use crate::scrypto_prelude::*; use crate::core_api::models; diff --git a/core-rust/core-api-server/src/core_api/conversions/errors.rs b/core-rust/core-api-server/src/core_api/conversions/errors.rs index 9e8abea0d3..70351d319b 100644 --- a/core-rust/core-api-server/src/core_api/conversions/errors.rs +++ b/core-rust/core-api-server/src/core_api/conversions/errors.rs @@ -1,11 +1,6 @@ -use radix_engine::types::NonFungibleIdType; -use radix_engine_common::{address::AddressBech32EncodeError, types::PartitionNumber}; -use radix_engine_interface::data::scrypto::model::ParseNonFungibleLocalIdError; -use sbor::{DecodeError, EncodeError}; +use crate::scrypto_prelude::*; use state_manager::StateVersion; use tracing::warn; -use transaction::errors::TransactionValidationError; -use transaction::model::TransactionHashBech32EncodeError; use crate::core_api::*; diff --git a/core-rust/core-api-server/src/core_api/conversions/hashes.rs b/core-rust/core-api-server/src/core_api/conversions/hashes.rs index 73ef9ed00e..ec7b578be1 100644 --- a/core-rust/core-api-server/src/core_api/conversions/hashes.rs +++ b/core-rust/core-api-server/src/core_api/conversions/hashes.rs @@ -1,6 +1,5 @@ -use radix_engine_interface::blueprints::package::CodeHash; +use crate::scrypto_prelude::*; use state_manager::{transaction::*, ReceiptTreeHash, StateHash, TransactionTreeHash}; -use transaction::prelude::*; use crate::core_api::*; diff --git a/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs b/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs index 3727e2596b..aaca52228c 100644 --- a/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs +++ b/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs @@ -1,7 +1,4 @@ -use radix_engine::types::PublicKey; -use radix_engine_interface::crypto::{Ed25519PublicKey, Secp256k1PublicKey}; -use transaction::model::{SignatureV1, SignatureWithPublicKeyV1}; -use transaction::prelude::{Ed25519Signature, Secp256k1Signature}; +use crate::scrypto_prelude::*; use crate::core_api::*; diff --git a/core-rust/core-api-server/src/core_api/conversions/lts.rs b/core-rust/core-api-server/src/core_api/conversions/lts.rs index d66c43bea6..cbe9d3b4c8 100644 --- a/core-rust/core-api-server/src/core_api/conversions/lts.rs +++ b/core-rust/core-api-server/src/core_api/conversions/lts.rs @@ -1,19 +1,10 @@ -use models::*; -use radix_engine::{ - system::system_modules::costing::RoyaltyRecipient, - transaction::BalanceChange, - types::{Decimal, GlobalAddress, IndexMap, ResourceAddress}, -}; - +use crate::scrypto_prelude::*; use state_manager::store::{traits::SubstateNodeAncestryStore, StateManagerDatabase}; use state_manager::{ CommittedTransactionIdentifiers, LedgerTransactionOutcome, LocalTransactionReceipt, StateVersion, TransactionTreeHash, }; -use radix_engine::transaction::{FeeDestination, FeeSource, TransactionFeeSummary}; -use transaction::prelude::*; - use crate::core_api::*; #[tracing::instrument(skip_all)] @@ -89,14 +80,14 @@ pub fn to_api_lts_committed_transaction_outcome( pub fn to_api_lts_entity_non_fungible_balance_changes( context: &MappingContext, global_balance_summary: &IndexMap>, -) -> Result, MappingError> { +) -> Result, MappingError> { let mut changes = Vec::new(); for (address, balance_changes) in global_balance_summary.iter() { for (resource, balance_change) in balance_changes.iter() { match balance_change { BalanceChange::Fungible(_) => {} BalanceChange::NonFungible { added, removed } => { - changes.push(LtsEntityNonFungibleBalanceChanges { + changes.push(models::LtsEntityNonFungibleBalanceChanges { entity_address: to_api_global_address(context, address)?, resource_address: to_api_resource_address(context, resource)?, added: added diff --git a/core-rust/core-api-server/src/core_api/conversions/numerics.rs b/core-rust/core-api-server/src/core_api/conversions/numerics.rs index a659d794e2..3182ee31c3 100644 --- a/core-rust/core-api-server/src/core_api/conversions/numerics.rs +++ b/core-rust/core-api-server/src/core_api/conversions/numerics.rs @@ -1,9 +1,6 @@ use std::any::type_name; -use radix_engine_common::math::*; -use radix_engine_interface::blueprints::package::BlueprintVersion; -use radix_engine_interface::prelude::*; -use sbor::WellKnownTypeId; +use crate::scrypto_prelude::*; use state_manager::store::traits::scenario::ScenarioSequenceNumber; use state_manager::StateVersion; diff --git a/core-rust/core-api-server/src/core_api/conversions/pagination.rs b/core-rust/core-api-server/src/core_api/conversions/pagination.rs index 6914db6fbe..c78166479e 100644 --- a/core-rust/core-api-server/src/core_api/conversions/pagination.rs +++ b/core-rust/core-api-server/src/core_api/conversions/pagination.rs @@ -1,6 +1,5 @@ -use radix_engine::types::*; - use crate::core_api::*; +use crate::scrypto_prelude::*; pub struct SizeRange { pub min: usize, diff --git a/core-rust/core-api-server/src/core_api/conversions/receipt.rs b/core-rust/core-api-server/src/core_api/conversions/receipt.rs index d2940cbed1..188b22d603 100644 --- a/core-rust/core-api-server/src/core_api/conversions/receipt.rs +++ b/core-rust/core-api-server/src/core_api/conversions/receipt.rs @@ -2,21 +2,8 @@ use super::addressing::*; use crate::core_api::*; -use radix_engine::blueprints::models::KeyValueKeyPayload; -use radix_engine::types::*; - -use radix_engine::system::system_modules::costing::*; -use radix_engine::transaction::{ - CostingParameters, EventSystemStructure, FeeDestination, FeeSource, - IndexPartitionEntryStructure, KeyValuePartitionEntryStructure, KeyValueStoreEntryStructure, - ObjectInstanceTypeReference, ObjectSubstateTypeReference, PackageTypeReference, - SortedIndexPartitionEntryStructure, StateUpdateSummary, SubstateSystemStructure, - SystemFieldKind, SystemFieldStructure, TransactionFeeSummary, -}; -use radix_engine_queries::typed_substate_layout::*; -use radix_engine_store_interface::db_key_mapper::{MappedSubstateDatabase, SpreadPrefixKeyMapper}; +use crate::scrypto_prelude::*; use state_manager::store::StateManagerDatabase; -use transaction::prelude::TransactionCostingParameters; use state_manager::{ ApplicationEvent, BySubstate, DetailedTransactionOutcome, LedgerStateChanges, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs b/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs index a8ee8efd88..486671cc2a 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs @@ -1,10 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; - -use radix_engine::types::*; -use radix_engine_interface::blueprints::access_controller::{RecoveryProposal, RuleSet}; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_access_controller_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs index a51b7c1c6f..0b2d2f70db 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs @@ -1,10 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use radix_engine::system::system_substates::KeyValueEntrySubstate; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_owner_role_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/account.rs b/core-rust/core-api-server/src/core_api/conversions/substates/account.rs index bcec302d9a..17628f8e45 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/account.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/account.rs @@ -1,16 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use radix_engine::blueprints::account::{ - AccountAuthorizedDepositorEntrySubstate, AccountAuthorizedDepositorKeyPayload, - AccountDepositRuleFieldSubstate, AccountResourcePreferenceEntrySubstate, - AccountResourcePreferenceKeyPayload, AccountResourceVaultEntrySubstate, - AccountResourceVaultKeyPayload, AccountSubstate, AccountTypedSubstateKey, -}; - -use radix_engine::types::*; -use radix_engine_interface::blueprints::account::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_account_state_substate( _context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs b/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs index 8ba7ce8102..82ec43516f 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs @@ -1,12 +1,7 @@ -use radix_engine::blueprints::models::SortedIndexKeyPayload; - use super::super::*; use super::*; use crate::core_api::models; -use radix_engine_interface::blueprints::consensus_manager::*; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_registered_validators_by_stake_index_entry_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs b/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs index 8f59f8f0ff..cdf45f041b 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs @@ -1,10 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use radix_engine::system::system_substates::{FieldSubstate, KeyValueEntrySubstate}; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_generic_scrypto_component_state_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs index d1b580965e..ea15540072 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs @@ -1,9 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_metadata_value_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs b/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs index b85fe17e53..2818144cf7 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs @@ -31,7 +31,7 @@ pub use type_info_module::*; //==================================== use super::MappingError; -use radix_engine::system::system_substates::{KeyValueEntrySubstate, LockStatus}; +use crate::scrypto_prelude::*; macro_rules! assert_key_type { ( diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/package.rs b/core-rust/core-api-server/src/core_api/conversions/substates/package.rs index afb593a38e..18c8d81af8 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/package.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/package.rs @@ -1,11 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use radix_engine::system::system_substates::KeyValueEntrySubstate; -use radix_engine::transaction::PackageTypeReference; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_package_royalty_accumulator_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs b/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs index 6d3b51c9d4..ddfa9bb963 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs @@ -1,17 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use radix_engine::blueprints::pool::v1::substates::multi_resource_pool::{ - MultiResourcePoolState, MultiResourcePoolStateFieldSubstate, -}; -use radix_engine::blueprints::pool::v1::substates::one_resource_pool::{ - OneResourcePoolState, OneResourcePoolStateFieldSubstate, -}; -use radix_engine::blueprints::pool::v1::substates::two_resource_pool::{ - TwoResourcePoolState, TwoResourcePoolStateFieldSubstate, -}; - -use radix_engine::types::*; +use crate::scrypto_prelude::*; pub fn to_api_one_resource_pool_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs b/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs index e3c6d188a0..6fd7c49450 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs @@ -1,9 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_fungible_vault_balance_substate( _context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs index 58ff45bdc0..cfc44a4541 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs @@ -1,9 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_component_royalty_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs b/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs index c4e0331652..eae8a6ba7e 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs @@ -1,24 +1,8 @@ use super::super::*; +use super::*; use crate::core_api::models; -use radix_engine::blueprints::account::{ - AccountTypedFieldSubstateValue, AccountTypedSubstateValue, -}; -use radix_engine::blueprints::pool::v1::substates::multi_resource_pool::{ - MultiResourcePoolTypedFieldSubstateValue, MultiResourcePoolTypedSubstateValue, -}; -use radix_engine::blueprints::pool::v1::substates::one_resource_pool::{ - OneResourcePoolTypedFieldSubstateValue, OneResourcePoolTypedSubstateValue, -}; -use radix_engine::blueprints::pool::v1::substates::two_resource_pool::{ - TwoResourcePoolTypedFieldSubstateValue, TwoResourcePoolTypedSubstateValue, -}; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; - -use super::super::MappingError; -use super::*; +use crate::scrypto_prelude::*; pub fn to_api_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs b/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs index b5e5f7ca3e..33e83a4654 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs @@ -1,10 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use radix_engine::system::system_substates::{FieldSubstate, KeyValueEntrySubstate}; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_transaction_tracker_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs index 69fda0f0ff..a17ba78ac2 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs @@ -2,9 +2,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use radix_engine::types::*; -use radix_engine::vm::VmBoot; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; pub fn to_api_vm_boot_substate( _context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/errors.rs b/core-rust/core-api-server/src/core_api/errors.rs index 4deba49e2d..af9dea45ad 100644 --- a/core-rust/core-api-server/src/core_api/errors.rs +++ b/core-rust/core-api-server/src/core_api/errors.rs @@ -6,8 +6,8 @@ use axum::{ use models::stream_proofs_error_details::StreamProofsErrorDetails; use std::any::Any; +use crate::scrypto_prelude::*; use hyper::StatusCode; -use radix_engine_interface::network::NetworkDefinition; use tower_http::catch_panic::ResponseForPanic; use super::{models, CoreApiState}; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs index 455e96f278..72cf405365 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs @@ -1,6 +1,6 @@ use crate::core_api::*; -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; + use state_manager::query::{dump_component_state, VaultData}; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs index 145d163a52..872aba6d6c 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs @@ -1,16 +1,10 @@ use crate::core_api::*; -use radix_engine::blueprints::account::{ - AccountAuthorizedDepositorEntryPayload, AccountCollection, AccountDepositRuleFieldSubstate, - AccountField, AccountResourcePreference, AccountResourcePreferenceEntryPayload, - AccountResourcePreferenceV1, AccountResourceVaultEntryPayload, -}; -use radix_engine::types::*; +use crate::scrypto_prelude::*; use state_manager::LedgerHeader; use std::ops::Deref; use node_common::utils::IsAccountExt; -use radix_engine_interface::blueprints::account::{DefaultDepositRule, ResourcePreference}; /// Maximum number of resource addresses allowed in the request. /// Must be aligned with the `maxItems` in the API documentation. diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs index ba6fb414dd..ef38dd8f65 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs @@ -1,7 +1,5 @@ use crate::core_api::*; -use radix_engine::blueprints::account::{AccountCollection, AccountResourceVaultEntryPayload}; -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; use state_manager::LedgerHeader; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs index 121200d2bb..d5e4da97b0 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs @@ -1,6 +1,6 @@ use crate::core_api::*; -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; + use std::ops::Deref; #[tracing::instrument(skip(state))] diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs index 917b72dc34..4406213f34 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs @@ -1,15 +1,15 @@ use std::collections::{HashMap, HashSet}; use crate::core_api::*; +use crate::scrypto_prelude::*; use state_manager::{ - AlreadyCommittedError, DetailedTransactionOutcome, RejectionReason, StateVersion, + AlreadyCommittedError, DetailedTransactionOutcome, MempoolRejectionReason, StateVersion, }; use state_manager::mempool::pending_transaction_result_cache::PendingTransactionRecord; use state_manager::query::StateManagerSubstateQueries; use state_manager::store::traits::*; -use transaction::prelude::*; #[tracing::instrument(skip(state))] pub(crate) async fn handle_lts_transaction_status( @@ -223,7 +223,7 @@ fn map_rejected_payloads_due_to_known_commit( // commit, and we may see a "not-yet-updated" entry - luckily, in such case, we can // precisely tell the transaction's status ourselves: .unwrap_or_else(|| { - RejectionReason::AlreadyCommitted(AlreadyCommittedError { + MempoolRejectionReason::AlreadyCommitted(AlreadyCommittedError { notarized_transaction_hash, committed_state_version, committed_notarized_transaction_hash: *committed_notarized_transaction_hash, diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs index 0b6c15ff46..c8f6f5e2dd 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs @@ -1,10 +1,10 @@ use crate::core_api::*; +use crate::scrypto_prelude::*; use crate::core_api::handlers::to_api_committed_intent_metadata; use hyper::StatusCode; use models::lts_transaction_submit_error_details::LtsTransactionSubmitErrorDetails; use state_manager::{MempoolAddError, MempoolAddSource}; -use transaction::prelude::RawNotarizedTransaction; #[tracing::instrument(level = "debug", skip(state))] pub(crate) async fn handle_lts_transaction_submit( diff --git a/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs b/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs index f0fa60f182..47fc2cc973 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs @@ -1,8 +1,7 @@ use crate::core_api::*; -use radix_engine::blueprints::access_controller::AccessControllerField; -use radix_engine::system::attached_modules::role_assignment::RoleAssignmentField; -use radix_engine::types::*; +use crate::scrypto_prelude::*; + use state_manager::query::dump_component_state; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_account.rs b/core-rust/core-api-server/src/core_api/handlers/state_account.rs index f197f2e375..432a125f9a 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_account.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_account.rs @@ -1,7 +1,6 @@ use crate::core_api::*; -use radix_engine::blueprints::account::AccountField; -use radix_engine::system::attached_modules::role_assignment::RoleAssignmentField; -use radix_engine::types::*; +use crate::scrypto_prelude::*; + use state_manager::query::{dump_component_state, VaultData}; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_component.rs b/core-rust/core-api-server/src/core_api/handlers/state_component.rs index d3a635c118..28a265eecb 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_component.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_component.rs @@ -1,7 +1,6 @@ use crate::core_api::*; -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; -use radix_engine_store_interface::db_key_mapper::{DatabaseKeyMapper, SpreadPrefixKeyMapper}; +use crate::scrypto_prelude::*; + use state_manager::query::{dump_component_state, ComponentStateDump, DescendantParentOpt}; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs b/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs index b7b6682635..de5b7dcc75 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs @@ -1,6 +1,5 @@ use crate::core_api::*; -use radix_engine::blueprints::consensus_manager::*; -use radix_engine::types::*; +use crate::scrypto_prelude::*; use state_manager::protocol::ProtocolVersionName; use state_manager::StateManagerDatabase; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs b/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs index 745dd110bc..583ba07ddd 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs @@ -1,11 +1,8 @@ -use radix_engine::blueprints::resource::*; -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::{TypedMainModuleSubstateKey, TypedSubstateKey}; +use crate::scrypto_prelude::*; use std::ops::Deref; use crate::core_api::*; -use radix_engine_common::types::SubstateKey; use crate::core_api::models::StateNonFungibleResponse; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_package.rs b/core-rust/core-api-server/src/core_api/handlers/state_package.rs index a967678f62..e129d1fa35 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_package.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_package.rs @@ -1,7 +1,5 @@ use crate::core_api::*; -use radix_engine::blueprints::package::PackageField; -use radix_engine::system::attached_modules::role_assignment::RoleAssignmentField; -use radix_engine::types::*; +use crate::scrypto_prelude::*; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_resource.rs b/core-rust/core-api-server/src/core_api/handlers/state_resource.rs index 6b5f2b27a7..17f5428ba8 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_resource.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_resource.rs @@ -1,12 +1,8 @@ use crate::core_api::*; - -use radix_engine::types::*; -use radix_engine_queries::typed_substate_layout::*; +use crate::scrypto_prelude::*; use std::ops::Deref; -use radix_engine_common::types::EntityType; - enum ManagerByType { Fungible( FungibleResourceManagerDivisibilityFieldSubstate, diff --git a/core-rust/core-api-server/src/core_api/handlers/state_validator.rs b/core-rust/core-api-server/src/core_api/handlers/state_validator.rs index 3e595ecf85..7554452f2d 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_validator.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_validator.rs @@ -1,8 +1,6 @@ use crate::core_api::*; -use radix_engine::types::*; +use crate::scrypto_prelude::*; -use radix_engine::blueprints::consensus_manager::ValidatorField; -use radix_engine::system::attached_modules::role_assignment::RoleAssignmentField; use state_manager::query::dump_component_state; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs b/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs index bf721293b8..0cc054b0da 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs @@ -1,7 +1,5 @@ use crate::core_api::*; -use radix_engine::types::*; -use radix_engine_common::types::EntityType; -use radix_engine_interface::address::HrpSet; +use crate::scrypto_prelude::*; #[tracing::instrument(skip(state))] pub(crate) async fn handle_status_network_configuration( diff --git a/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs b/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs index 8a36af653a..d10fb0702b 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs @@ -1,6 +1,6 @@ use crate::core_api::*; -use radix_engine_interface::prelude::*; +use crate::scrypto_prelude::*; use state_manager::query::TransactionIdentifierLoader; use state_manager::store::traits::*; diff --git a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs index 02985bf0fd..b9b40a4801 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs @@ -1,6 +1,6 @@ use crate::core_api::*; -use radix_engine_interface::prelude::*; +use crate::scrypto_prelude::*; use state_manager::store::traits::scenario::{ ExecutedGenesisScenario, ExecutedGenesisScenarioStore, ExecutedScenarioTransaction, diff --git a/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs b/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs index 2b04f326df..7ec65ad6e3 100644 --- a/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs +++ b/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs @@ -1,10 +1,8 @@ use crate::core_api::*; - +use crate::scrypto_prelude::*; use state_manager::store::{traits::*, StateManagerDatabase}; use state_manager::{LedgerProof, LedgerProofOrigin, StateVersion}; -use transaction::prelude::*; - #[tracing::instrument(skip(state))] pub(crate) async fn handle_stream_proofs( state: State, diff --git a/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs b/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs index 8f7485c503..6713871ea3 100644 --- a/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs +++ b/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs @@ -1,13 +1,9 @@ -use radix_engine::track::{ - BatchPartitionStateUpdate, NodeStateUpdates, PartitionStateUpdates, StateUpdates, -}; +use crate::scrypto_prelude::*; + use std::iter; use crate::core_api::*; -use radix_engine::types::hash; -use radix_engine_store_interface::interface::{DatabaseUpdate, DbSubstateValue}; - use state_manager::store::{traits::*, StateManagerDatabase}; use state_manager::transaction::*; use state_manager::{ @@ -15,9 +11,6 @@ use state_manager::{ LocalTransactionReceipt, StateVersion, }; -use transaction::manifest; -use transaction::prelude::*; - use super::to_api_committed_state_identifiers; #[tracing::instrument(skip(state))] diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs index a239e66040..028a0625f7 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs @@ -1,29 +1,15 @@ use crate::core_api::*; -use models::{ - target_identifier::TargetIdentifier, - transaction_call_preview_response::TransactionCallPreviewResponse, - transaction_status::TransactionStatus, -}; -use radix_engine::{ - transaction::{PreviewError, TransactionOutcome, TransactionResult}, - types::Decimal, -}; +use crate::scrypto_prelude::*; -use radix_engine_interface::constants::FAUCET; -use radix_engine_interface::manifest_args; -use radix_engine_interface::{ - blueprints::transaction_processor::InstructionOutput, data::scrypto::scrypto_encode, -}; use state_manager::PreviewRequest; -use transaction::prelude::*; macro_rules! args_from_bytes_vec { ($args: expr) => {{ let mut fields = Vec::new(); for arg in $args { - fields.push(::radix_engine::types::manifest_decode(&arg).unwrap()); + fields.push(crate::scrypto_prelude::manifest_decode(&arg).unwrap()); } - ::radix_engine::types::ManifestValue::Tuple { fields } + crate::scrypto_prelude::ManifestValue::Tuple { fields } }}; } @@ -47,7 +33,7 @@ pub(crate) async fn handle_transaction_callpreview( .ok_or_else(|| client_error("Missing target from request".to_string()))?; let requested_call = match call_target { - TargetIdentifier::BlueprintFunctionTargetIdentifier { + models::TargetIdentifier::BlueprintFunctionTargetIdentifier { package_address, blueprint_name, function_name, @@ -63,7 +49,7 @@ pub(crate) async fn handle_transaction_callpreview( args: args_from_bytes_vec!(args), } } - TargetIdentifier::ComponentMethodTargetIdentifier { + models::TargetIdentifier::ComponentMethodTargetIdentifier { component_address, method_name, } => { @@ -93,7 +79,7 @@ pub(crate) async fn handle_transaction_callpreview( }, requested_call, ], - blobs: btreemap!(), + blobs: index_map_new(), }, explicit_epoch_range: None, notary_public_key: None, @@ -136,15 +122,19 @@ pub(crate) async fn handle_transaction_callpreview( Some(Err(err)) => Err(server_error(format!("{err:?}")))?, }; - (TransactionStatus::Succeeded, output, None) - } - TransactionOutcome::Failure(f) => { - (TransactionStatus::Failed, None, Some(format!("{f:?}"))) + (models::TransactionStatus::Succeeded, output, None) } + TransactionOutcome::Failure(f) => ( + models::TransactionStatus::Failed, + None, + Some(format!("{f:?}")), + ), }, - TransactionResult::Reject(r) => { - (TransactionStatus::Rejected, None, Some(format!("{r:?}"))) - } + TransactionResult::Reject(r) => ( + models::TransactionStatus::Rejected, + None, + Some(format!("{r:?}")), + ), TransactionResult::Abort(_) => { // TODO: Should remove this panic!("Should not be aborting"); @@ -152,7 +142,7 @@ pub(crate) async fn handle_transaction_callpreview( } }; - Ok(Json(TransactionCallPreviewResponse { + Ok(Json(models::TransactionCallPreviewResponse { at_ledger_state: Box::new(to_api_ledger_state_summary( &mapping_context, &result.base_ledger_header, diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs index 3686f6cb23..12ecc809db 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs @@ -1,18 +1,15 @@ use crate::core_api::*; use std::ops::Deref; use std::time::SystemTime; -use transaction::validation::{ - NotarizedTransactionValidator, TransactionValidator, ValidationConfig, -}; use models::transaction_parse_request::{ParseMode, ResponseMode, ValidationMode}; use models::transaction_parse_response::TransactionParseResponse; -use state_manager::mempool::pending_transaction_result_cache::RejectionReason; +use state_manager::mempool::pending_transaction_result_cache::MempoolRejectionReason; use state_manager::transaction::*; +use crate::scrypto_prelude::*; use state_manager::store::StateManagerDatabase; -use transaction::prelude::*; use super::{ to_api_intent, to_api_ledger_transaction, to_api_notarized_transaction, to_api_signed_intent, @@ -116,7 +113,7 @@ fn attempt_parsing_as_any_payload_type_and_map_for_api( struct ParsedNotarizedTransactionV1 { model: NotarizedTransactionV1, prepared: PreparedNotarizedTransactionV1, - validation: Option>, + validation: Option>, } fn attempt_parsing_as_notarized_transaction( @@ -147,7 +144,7 @@ fn attempt_parsing_as_notarized_transaction( .user_transaction_validator .validate(prepared.clone()) .map(|_| ()) - .map_err(RejectionReason::ValidationError), + .map_err(MempoolRejectionReason::ValidationError), ); ParsedNotarizedTransactionV1 { model, @@ -160,7 +157,7 @@ fn attempt_parsing_as_notarized_transaction( context .user_transaction_validator .validate(prepared.clone()) - .map_err(RejectionReason::ValidationError) + .map_err(MempoolRejectionReason::ValidationError) .and_then(|validated| { let rejection = context .committability_validator diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs index 6dbd291ca4..fa628e9483 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs @@ -1,18 +1,10 @@ use crate::core_api::*; -use radix_engine::prelude::*; -use radix_engine::transaction::*; +use crate::scrypto_prelude::*; + use std::ops::Range; use state_manager::transaction::ProcessedPreviewResult; use state_manager::{ExecutionFeeData, LocalTransactionReceipt, PreviewRequest}; -use transaction::manifest; -use transaction::manifest::BlobProvider; -use transaction::model::{ - AesGcmPayload, AesWrapped128BitKey, DecryptorsByCurve, EncryptedMessageV1, MessageV1, - PlaintextMessageV1, PreviewFlags, PublicKeyFingerprint, -}; -use transaction::prelude::MessageContentsV1; -use utils::copy_u8_array; pub(crate) async fn handle_transaction_preview( state: State, diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs index 6067edb5a9..7a03f494c2 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs @@ -1,15 +1,15 @@ use std::collections::{HashMap, HashSet}; use crate::core_api::*; +use crate::scrypto_prelude::*; use state_manager::{ - AlreadyCommittedError, DetailedTransactionOutcome, RejectionReason, StateVersion, + AlreadyCommittedError, DetailedTransactionOutcome, MempoolRejectionReason, StateVersion, }; use state_manager::mempool::pending_transaction_result_cache::PendingTransactionRecord; use state_manager::query::StateManagerSubstateQueries; use state_manager::store::traits::*; -use transaction::prelude::*; #[tracing::instrument(skip(state))] pub(crate) async fn handle_transaction_status( @@ -223,7 +223,7 @@ fn map_rejected_payloads_due_to_known_commit( // commit, and we may see a "not-yet-updated" entry - luckily, in such case, we can // precisely tell the transaction's status ourselves: .unwrap_or_else(|| { - RejectionReason::AlreadyCommitted(AlreadyCommittedError { + MempoolRejectionReason::AlreadyCommitted(AlreadyCommittedError { notarized_transaction_hash, committed_state_version, committed_notarized_transaction_hash: *committed_notarized_transaction_hash, diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs index 00a0f93bd9..7ca7fb25a9 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs @@ -1,9 +1,9 @@ use crate::core_api::*; +use crate::scrypto_prelude::*; use hyper::StatusCode; use models::transaction_submit_error_details::TransactionSubmitErrorDetails; use state_manager::{AlreadyCommittedError, MempoolAddError, MempoolAddSource}; -use transaction::prelude::*; #[tracing::instrument(level = "debug", skip(state))] pub(crate) async fn handle_transaction_submit( diff --git a/core-rust/core-api-server/src/core_api/helpers.rs b/core-rust/core-api-server/src/core_api/helpers.rs index 26d6a49d12..fb32ce56ba 100644 --- a/core-rust/core-api-server/src/core_api/helpers.rs +++ b/core-rust/core-api-server/src/core_api/helpers.rs @@ -1,8 +1,4 @@ -use radix_engine::types::*; - -use radix_engine::system::system_substates::{FieldSubstate, KeyValueEntrySubstate}; -use radix_engine_interface::api::CollectionIndex; -use radix_engine_store_interface::{db_key_mapper::*, interface::SubstateDatabase}; +use crate::scrypto_prelude::*; use serde::Serialize; use state_manager::store::traits::*; use state_manager::store::StateManagerDatabase; diff --git a/core-rust/core-api-server/src/core_api/server.rs b/core-rust/core-api-server/src/core_api/server.rs index 425b3ca1a9..2ddc3f3c97 100644 --- a/core-rust/core-api-server/src/core_api/server.rs +++ b/core-rust/core-api-server/src/core_api/server.rs @@ -77,9 +77,8 @@ use axum::{ Router, }; +use crate::scrypto_prelude::*; use prometheus::Registry; -use radix_engine_common::network::NetworkDefinition; -use radix_engine_common::ScryptoSbor; use state_manager::StateManager; use tower_http::catch_panic::CatchPanicLayer; use tracing::{debug, error, info, trace, warn, Level}; diff --git a/core-rust/core-api-server/src/jni/mod.rs b/core-rust/core-api-server/src/jni/mod.rs index 3b5b450e6d..13ea5790a7 100644 --- a/core-rust/core-api-server/src/jni/mod.rs +++ b/core-rust/core-api-server/src/jni/mod.rs @@ -63,20 +63,20 @@ */ use crate::core_api::{create_server, CoreApiServerConfig, CoreApiState}; +use crate::scrypto_prelude::*; use futures::channel::oneshot; use futures::channel::oneshot::Sender; use futures::FutureExt; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; +use node_common::java::*; use prometheus::*; use state_manager::jni::node_rust_environment::JNINodeRustEnvironment; use std::str; use std::sync::{Arc, MutexGuard}; use tokio::runtime::Runtime; -use node_common::java::*; - const POINTER_JNI_FIELD_NAME: &str = "rustCoreApiServerPointer"; pub struct RunningServer { diff --git a/core-rust/core-api-server/src/lib.rs b/core-rust/core-api-server/src/lib.rs index dadec04605..677c7d2ce6 100644 --- a/core-rust/core-api-server/src/lib.rs +++ b/core-rust/core-api-server/src/lib.rs @@ -67,3 +67,38 @@ extern crate serde_json; mod core_api; pub mod jni; + +pub(crate) mod scrypto_prelude { + pub use blueprint_schema_init::*; + pub use radix_engine::blueprints::account::*; + pub use radix_engine::blueprints::models::*; + pub use radix_engine::blueprints::transaction_tracker::*; + pub use radix_engine::object_modules::metadata::*; + pub use radix_engine::system::system_modules::costing::*; + pub use radix_engine::system::system_substates::*; + pub use radix_engine::transaction::*; + pub use radix_engine::vm::*; + pub use radix_engine_common::prelude::*; + pub use radix_engine_interface::blueprints::access_controller::*; + pub use radix_engine_interface::blueprints::account::*; + pub use radix_engine_interface::blueprints::transaction_processor::*; + pub use radix_engine_interface::prelude::*; + pub use sbor::representations::*; + pub use substate_store_impls::hash_tree::tree_store::*; + pub use substate_store_interface::db_key_mapper::*; + pub use substate_store_interface::interface::*; + pub use substate_store_queries::typed_substate_layout::multi_resource_pool::*; + pub use substate_store_queries::typed_substate_layout::one_resource_pool::*; + pub use substate_store_queries::typed_substate_layout::two_resource_pool::*; + pub use substate_store_queries::typed_substate_layout::*; + pub use transaction::errors::*; + pub use transaction::manifest::*; + pub use transaction::model::*; + pub use transaction::validation::*; + pub use transaction::*; + + // Note: plain `pub use radix_engine::track::*` would clash with the top-level `utils::prelude` + // (because it contains a private module of the same name) + pub use radix_engine::track::interface::*; + pub use radix_engine::track::state_updates::*; +} diff --git a/core-rust/jni-export/Cargo.toml b/core-rust/jni-export/Cargo.toml index 49c5cf8ed2..73741a740e 100644 --- a/core-rust/jni-export/Cargo.toml +++ b/core-rust/jni-export/Cargo.toml @@ -14,9 +14,9 @@ transaction-scenarios = { workspace = true } radix-engine-common = { workspace = true } radix-engine-interface = { workspace = true } radix-engine = { workspace = true } -radix-engine-stores = { workspace = true } -radix-engine-store-interface = { workspace = true } -radix-engine-queries = { workspace = true } +substate-store-impls = { workspace = true } +substate-store-interface = { workspace = true } +substate-store-queries = { workspace = true } utils = { workspace = true } # Non-Radix Engine Dependencies: diff --git a/core-rust/node-common/Cargo.toml b/core-rust/node-common/Cargo.toml index bde87f2402..5e01fb8914 100644 --- a/core-rust/node-common/Cargo.toml +++ b/core-rust/node-common/Cargo.toml @@ -9,9 +9,9 @@ transaction = { workspace = true } radix-engine-common = { workspace = true } radix-engine-interface = { workspace = true } radix-engine = { workspace = true } -radix-engine-stores = { workspace = true } -radix-engine-store-interface = { workspace = true } -radix-engine-queries = { workspace = true } +substate-store-impls = { workspace = true } +substate-store-interface = { workspace = true } +substate-store-queries = { workspace = true } utils = { workspace = true } # Non-Radix Engine Dependencies: diff --git a/core-rust/node-common/src/config/limits.rs b/core-rust/node-common/src/config/limits.rs index daefc615a6..3511813568 100644 --- a/core-rust/node-common/src/config/limits.rs +++ b/core-rust/node-common/src/config/limits.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use radix_engine_common::prelude::*; +use crate::scrypto_prelude::*; // TODO: revisit & tune before Babylon pub const DEFAULT_MAX_VERTEX_TRANSACTION_COUNT: u32 = 100; diff --git a/core-rust/node-common/src/config/mod.rs b/core-rust/node-common/src/config/mod.rs index eec01b1b94..c250af2a7c 100644 --- a/core-rust/node-common/src/config/mod.rs +++ b/core-rust/node-common/src/config/mod.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use sbor::*; +use crate::scrypto_prelude::*; pub mod limits; diff --git a/core-rust/node-common/src/java/result.rs b/core-rust/node-common/src/java/result.rs index 8e16fb296b..92516ba06f 100644 --- a/core-rust/node-common/src/java/result.rs +++ b/core-rust/node-common/src/java/result.rs @@ -62,8 +62,7 @@ * permissions under this License. */ -use radix_engine_interface::*; -use sbor::{DecodeError, EncodeError}; +use crate::scrypto_prelude::*; #[derive(Debug, ScryptoSbor)] pub struct JavaError(pub String); diff --git a/core-rust/node-common/src/java/structure.rs b/core-rust/node-common/src/java/structure.rs index 0498404d1d..2a477ff95b 100644 --- a/core-rust/node-common/src/java/structure.rs +++ b/core-rust/node-common/src/java/structure.rs @@ -63,9 +63,7 @@ */ use crate::java::result::JavaResult; -use radix_engine::types::{scrypto_decode, scrypto_encode, ScryptoDecode, ScryptoEncode}; - -pub use sbor::{Decode, Encode}; +use crate::scrypto_prelude::*; pub trait StructFromJava { fn from_java(data: &[u8]) -> JavaResult diff --git a/core-rust/node-common/src/java/types.rs b/core-rust/node-common/src/java/types.rs index d42531a227..cde150f447 100644 --- a/core-rust/node-common/src/java/types.rs +++ b/core-rust/node-common/src/java/types.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use sbor::{Categorize, Decode, Encode}; +use crate::scrypto_prelude::*; #[derive(Debug, PartialEq, Eq, Categorize, Encode, Decode)] pub struct JavaHashCode(Vec); diff --git a/core-rust/node-common/src/java/utils.rs b/core-rust/node-common/src/java/utils.rs index bed6c3807c..e4490e4427 100644 --- a/core-rust/node-common/src/java/utils.rs +++ b/core-rust/node-common/src/java/utils.rs @@ -62,10 +62,9 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use jni::sys::jbyteArray; use jni::JNIEnv; -use radix_engine::types::{ScryptoDecode, ScryptoEncode}; -use sbor::Sbor; use std::panic; use std::panic::AssertUnwindSafe; diff --git a/core-rust/node-common/src/jni/addressing.rs b/core-rust/node-common/src/jni/addressing.rs index f852f11d61..c73af2ed36 100644 --- a/core-rust/node-common/src/jni/addressing.rs +++ b/core-rust/node-common/src/jni/addressing.rs @@ -63,14 +63,11 @@ */ use crate::java::utils::jni_sbor_coded_call; +use crate::scrypto_prelude::*; use bech32::{FromBase32, ToBase32, Variant}; use jni::objects::JClass; use jni::sys::jbyteArray; use jni::JNIEnv; -use radix_engine::types::ComponentAddress; -use radix_engine_common::prelude::{AddressBech32Encoder, NetworkDefinition}; -use radix_engine_common::types::{EntityType, NodeId, ResourceAddress}; -use radix_engine_interface::crypto::Secp256k1PublicKey; #[no_mangle] extern "system" fn Java_com_radixdlt_identifiers_Bech32mCoder_encodeAddress( diff --git a/core-rust/node-common/src/jni/scrypto_constants.rs b/core-rust/node-common/src/jni/scrypto_constants.rs index 4f04d36168..b2084a2c8b 100644 --- a/core-rust/node-common/src/jni/scrypto_constants.rs +++ b/core-rust/node-common/src/jni/scrypto_constants.rs @@ -67,8 +67,7 @@ use jni::sys::jbyteArray; use jni::JNIEnv; use crate::java::utils::jni_sbor_coded_call; -use radix_engine::types::{CONSENSUS_MANAGER, VALIDATOR_OWNER_BADGE, XRD}; -use radix_engine_interface::constants::FAUCET; +use crate::scrypto_prelude::*; #[no_mangle] extern "system" fn Java_com_radixdlt_rev2_ScryptoConstants_getXrdResourceAddress( diff --git a/core-rust/node-common/src/lib.rs b/core-rust/node-common/src/lib.rs index fa9d2e4b13..1bffd524b9 100644 --- a/core-rust/node-common/src/lib.rs +++ b/core-rust/node-common/src/lib.rs @@ -70,3 +70,7 @@ pub mod locks; pub mod metrics; pub mod scheduler; pub mod utils; + +pub(crate) mod scrypto_prelude { + pub use radix_engine_common::prelude::*; +} diff --git a/core-rust/node-common/src/utils.rs b/core-rust/node-common/src/utils.rs index da92488070..d21c0e8c3f 100644 --- a/core-rust/node-common/src/utils.rs +++ b/core-rust/node-common/src/utils.rs @@ -62,8 +62,7 @@ * permissions under this License. */ -use radix_engine::types::GlobalAddress; -use radix_engine_common::types::EntityType; +use crate::scrypto_prelude::*; pub trait IsAccountExt { fn is_account(&self) -> bool; diff --git a/core-rust/state-manager/Cargo.toml b/core-rust/state-manager/Cargo.toml index 924ad43bf3..967fdf0438 100644 --- a/core-rust/state-manager/Cargo.toml +++ b/core-rust/state-manager/Cargo.toml @@ -12,9 +12,9 @@ transaction-scenarios = { workspace = true } radix-engine-common = { workspace = true } radix-engine-interface = { workspace = true } radix-engine = { workspace = true } -radix-engine-stores = { workspace = true } -radix-engine-store-interface = { workspace = true } -radix-engine-queries = { workspace = true } +substate-store-impls = { workspace = true } +substate-store-interface = { workspace = true } +substate-store-queries = { workspace = true } utils = { workspace = true } # Non-Radix Engine Dependencies: diff --git a/core-rust/state-manager/src/accumulator_tree/mod.rs b/core-rust/state-manager/src/accumulator_tree/mod.rs index 79ae1253da..6bf09f90bb 100644 --- a/core-rust/state-manager/src/accumulator_tree/mod.rs +++ b/core-rust/state-manager/src/accumulator_tree/mod.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use radix_engine_interface::prelude::*; +use crate::scrypto_prelude::*; use tree_builder::Merklizable; pub mod slice_merger; diff --git a/core-rust/state-manager/src/accumulator_tree/storage.rs b/core-rust/state-manager/src/accumulator_tree/storage.rs index ea68e03eee..f4826cdfdd 100644 --- a/core-rust/state-manager/src/accumulator_tree/storage.rs +++ b/core-rust/state-manager/src/accumulator_tree/storage.rs @@ -62,8 +62,8 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use enum_dispatch::enum_dispatch; -use radix_engine::types::{ScryptoCategorize, ScryptoDecode, ScryptoEncode}; /// The "read" part of an accumulator tree storage SPI. /// Both the key type and node type are implementation-dependent. diff --git a/core-rust/state-manager/src/accumulator_tree/test.rs b/core-rust/state-manager/src/accumulator_tree/test.rs index 5dd0ea3b0d..9e0b66679f 100644 --- a/core-rust/state-manager/src/accumulator_tree/test.rs +++ b/core-rust/state-manager/src/accumulator_tree/test.rs @@ -66,7 +66,7 @@ use super::slice_merger::AccuTreeSliceMerger; use super::storage::{ReadableAccuTreeStore, WriteableAccuTreeStore}; use super::storage::{TreeSlice, TreeSliceLevel}; use super::tree_builder::{AccuTree, Merklizable}; -use radix_engine_interface::crypto::{blake2b_256_hash, Hash}; +use crate::scrypto_prelude::*; use std::collections::HashMap; // Simple smoke tests using the actual hashing coming from our business use-cases: diff --git a/core-rust/state-manager/src/jni/fatal_panic_handler.rs b/core-rust/state-manager/src/jni/fatal_panic_handler.rs index 74a7953d4d..f7c05b56fd 100644 --- a/core-rust/state-manager/src/jni/fatal_panic_handler.rs +++ b/core-rust/state-manager/src/jni/fatal_panic_handler.rs @@ -67,7 +67,6 @@ use jni::objects::{GlobalRef, JObject}; use jni::{JNIEnv, JavaVM}; use std::ops::Deref; use tracing::error; -use transaction::prelude::*; /// An interface for notifying Java about a fatal panic. pub struct FatalPanicHandler { diff --git a/core-rust/state-manager/src/jni/mempool.rs b/core-rust/state-manager/src/jni/mempool.rs index 29063a1eb4..9a83c8bd74 100644 --- a/core-rust/state-manager/src/jni/mempool.rs +++ b/core-rust/state-manager/src/jni/mempool.rs @@ -72,11 +72,9 @@ use jni::sys::jbyteArray; use jni::JNIEnv; use crate::mempool::*; +use crate::scrypto_prelude::*; use crate::MempoolAddSource; use node_common::java::*; -use sbor::{Categorize, Decode, Encode}; -use transaction::errors::TransactionValidationError; -use transaction::model::*; use super::node_rust_environment::JNINodeRustEnvironment; use super::transaction_preparer::JavaPreparedNotarizedTransaction; diff --git a/core-rust/state-manager/src/jni/mod.rs b/core-rust/state-manager/src/jni/mod.rs index fefcce14ac..6d30eb8d6b 100644 --- a/core-rust/state-manager/src/jni/mod.rs +++ b/core-rust/state-manager/src/jni/mod.rs @@ -74,7 +74,7 @@ pub mod transaction_preparer; pub mod transaction_store; pub mod vertex_store_recovery; -use radix_engine::prelude::*; +use crate::scrypto_prelude::*; /// Limits regarding the granularity of ledger sync (and thus of ledger proofs kept in storage). /// This struct is defined publicly here, since it is used by the transaction store and the ledger diff --git a/core-rust/state-manager/src/jni/node_rust_environment.rs b/core-rust/state-manager/src/jni/node_rust_environment.rs index fbb8fe5a89..c881c67237 100644 --- a/core-rust/state-manager/src/jni/node_rust_environment.rs +++ b/core-rust/state-manager/src/jni/node_rust_environment.rs @@ -66,6 +66,7 @@ use std::ops::Deref; use std::str::FromStr; use std::sync::Arc; +use crate::scrypto_prelude::*; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; @@ -73,7 +74,6 @@ use node_common::environment::setup_tracing; use node_common::java::{jni_call, jni_jbytearray_to_vector, StructFromJava}; use node_common::locks::*; use prometheus::Registry; -use radix_engine_common::prelude::NetworkDefinition; use node_common::scheduler::{Scheduler, UntilDropTracker}; use tokio::runtime::Runtime; diff --git a/core-rust/state-manager/src/jni/protocol_update.rs b/core-rust/state-manager/src/jni/protocol_update.rs index 05742df131..481e36d4c5 100644 --- a/core-rust/state-manager/src/jni/protocol_update.rs +++ b/core-rust/state-manager/src/jni/protocol_update.rs @@ -62,11 +62,11 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use crate::{protocol::*, ProtocolUpdateResult}; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; -use radix_engine::types::*; use node_common::java::*; diff --git a/core-rust/state-manager/src/jni/state_computer.rs b/core-rust/state-manager/src/jni/state_computer.rs index a365b7bf69..72fa43dfc6 100644 --- a/core-rust/state-manager/src/jni/state_computer.rs +++ b/core-rust/state-manager/src/jni/state_computer.rs @@ -63,21 +63,16 @@ */ use crate::protocol::ProtocolVersionName; +use crate::scrypto_prelude::*; use crate::{protocol::ProtocolState, CommitSummary, LedgerProof}; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; -use radix_engine::types::*; -use radix_engine_interface::blueprints::consensus_manager::{ - ConsensusManagerConfig, EpochChangeCondition, -}; use node_common::java::*; use crate::types::{CommitRequest, InvalidCommitRequestError, PrepareRequest, PrepareResult}; -use radix_engine::system::bootstrap::GenesisDataChunk; - use super::node_rust_environment::JNINodeRustEnvironment; // diff --git a/core-rust/state-manager/src/jni/state_reader.rs b/core-rust/state-manager/src/jni/state_reader.rs index b2a5caafdf..6d2a61b9a1 100644 --- a/core-rust/state-manager/src/jni/state_reader.rs +++ b/core-rust/state-manager/src/jni/state_reader.rs @@ -62,17 +62,10 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; -use radix_engine::system::system_substates::FieldSubstate; -use radix_engine::types::*; - -use radix_engine_store_interface::db_key_mapper::*; - -use radix_engine::blueprints::consensus_manager::{ - ValidatorField, ValidatorProtocolUpdateReadinessSignalFieldPayload, -}; use node_common::java::*; diff --git a/core-rust/state-manager/src/jni/test_state_reader.rs b/core-rust/state-manager/src/jni/test_state_reader.rs index 85d7a9a955..2ec455a04a 100644 --- a/core-rust/state-manager/src/jni/test_state_reader.rs +++ b/core-rust/state-manager/src/jni/test_state_reader.rs @@ -62,28 +62,22 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use crate::{DetailedTransactionOutcome, LedgerTransactionOutcome, StateVersion}; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; -use radix_engine::types::*; - -use radix_engine_queries::query::ResourceAccounter; use std::ops::Deref; use crate::jni::node_rust_environment::JNINodeRustEnvironment; use crate::query::StateManagerSubstateQueries; use node_common::java::*; -use radix_engine::blueprints::consensus_manager::{ValidatorField, ValidatorStateFieldSubstate}; -use radix_engine::system::type_info::TypeInfoSubstate; - use crate::store::traits::{ gc::StateHashTreeGcStore, IterableProofStore, QueryableProofStore, QueryableTransactionStore, SubstateNodeAncestryStore, }; use crate::transaction::LedgerTransactionHash; -use radix_engine_store_interface::db_key_mapper::{MappedSubstateDatabase, SpreadPrefixKeyMapper}; // // JNI Interface (for test purposes only) diff --git a/core-rust/state-manager/src/jni/transaction_preparer.rs b/core-rust/state-manager/src/jni/transaction_preparer.rs index ff2591c268..67788f46d4 100644 --- a/core-rust/state-manager/src/jni/transaction_preparer.rs +++ b/core-rust/state-manager/src/jni/transaction_preparer.rs @@ -62,17 +62,12 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use crate::transaction::*; use jni::objects::JClass; use jni::sys::jbyteArray; use jni::JNIEnv; use node_common::java::*; -use radix_engine::types::PublicKey; -use radix_engine_common::types::Epoch; -use radix_engine_interface::network::NetworkDefinition; -use radix_engine_interface::*; -use transaction::manifest::{compile, BlobProvider}; -use transaction::model::*; #[derive(Debug, Clone, PartialEq, Eq, ScryptoCategorize, ScryptoEncode, ScryptoDecode)] struct PrepareIntentRequest { diff --git a/core-rust/state-manager/src/jni/transaction_store.rs b/core-rust/state-manager/src/jni/transaction_store.rs index c9e50da2c0..ec9876928d 100644 --- a/core-rust/state-manager/src/jni/transaction_store.rs +++ b/core-rust/state-manager/src/jni/transaction_store.rs @@ -65,13 +65,13 @@ use crate::jni::node_rust_environment::JNINodeRustEnvironment; use crate::jni::LedgerSyncLimitsConfig; use crate::protocol::epoch_change_iter; +use crate::scrypto_prelude::*; use crate::store::traits::*; use crate::{LedgerProof, StateVersion}; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; use node_common::java::*; -use radix_engine::types::*; use std::ops::Deref; #[derive(Debug, ScryptoCategorize, ScryptoEncode, ScryptoDecode)] diff --git a/core-rust/state-manager/src/lib.rs b/core-rust/state-manager/src/lib.rs index 552b8097e9..9bdc58dc0c 100644 --- a/core-rust/state-manager/src/lib.rs +++ b/core-rust/state-manager/src/lib.rs @@ -91,3 +91,35 @@ pub use crate::state_computer::*; pub use crate::state_manager::*; pub use crate::store::*; pub use crate::types::*; + +pub(crate) mod scrypto_prelude { + pub use radix_engine::errors::*; + pub use radix_engine::system::bootstrap::*; + pub use radix_engine::system::system_db_reader::*; + pub use radix_engine::system::system_substates::*; + pub use radix_engine::transaction::*; + pub use radix_engine::utils::*; + pub use radix_engine::vm::wasm::*; + pub use radix_engine::vm::*; + pub use radix_engine_common::prelude::*; + pub use radix_engine_interface::blueprints::transaction_processor::*; + pub use radix_engine_interface::prelude::*; + pub use substate_store_impls::hash_tree::tree_store::*; + pub use substate_store_impls::hash_tree::*; + pub use substate_store_interface::db_key_mapper::*; + pub use substate_store_interface::interface::*; + pub use substate_store_queries::query::*; + pub use substate_store_queries::typed_substate_layout::*; + pub use transaction::builder::*; + pub use transaction::errors::*; + pub use transaction::manifest::*; + pub use transaction::model::*; + pub use transaction::prelude::*; + pub use transaction::validation::*; + pub use transaction::*; + + // Note: plain `pub use radix_engine::track::*` would clash with the top-level `utils::prelude` + // (because it contains a private module of the same name) + pub use radix_engine::track::interface::*; + pub use radix_engine::track::state_updates::*; +} diff --git a/core-rust/state-manager/src/limits.rs b/core-rust/state-manager/src/limits.rs index 0fb63bf503..26ea1926ff 100644 --- a/core-rust/state-manager/src/limits.rs +++ b/core-rust/state-manager/src/limits.rs @@ -62,9 +62,8 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use node_common::config::limits::VertexLimitsConfig; -use radix_engine::transaction::TransactionFeeSummary; -use radix_engine::types::*; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum VertexLimitsExceeded { diff --git a/core-rust/state-manager/src/mempool/mempool_manager.rs b/core-rust/state-manager/src/mempool/mempool_manager.rs index d2de8a0289..40b6a0a72b 100644 --- a/core-rust/state-manager/src/mempool/mempool_manager.rs +++ b/core-rust/state-manager/src/mempool/mempool_manager.rs @@ -68,7 +68,6 @@ use crate::mempool::*; use crate::MempoolAddSource; use node_common::metrics::TakesMetricLabels; use prometheus::Registry; -use transaction::model::*; use std::cmp::max; use std::collections::HashSet; diff --git a/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs b/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs index 87cacd884f..47621fd987 100644 --- a/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs +++ b/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs @@ -62,11 +62,11 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use jni::errors::Result; use jni::objects::{GlobalRef, JObject, JValue}; use jni::{JNIEnv, JavaVM}; use std::ops::Deref; -use transaction::prelude::*; use node_common::java::*; diff --git a/core-rust/state-manager/src/mempool/metrics.rs b/core-rust/state-manager/src/mempool/metrics.rs index 61a3dcc1a0..7ff7e3dcc9 100644 --- a/core-rust/state-manager/src/mempool/metrics.rs +++ b/core-rust/state-manager/src/mempool/metrics.rs @@ -65,7 +65,7 @@ use node_common::metrics::*; use prometheus::*; -use crate::{MempoolAddError, MempoolAddSource, RejectionReason}; +use crate::{MempoolAddError, MempoolAddSource, MempoolRejectionReason}; pub struct MempoolMetrics { pub current_transactions: IntGauge, @@ -142,9 +142,9 @@ impl MetricLabel for MempoolAddError { match self { MempoolAddError::PriorityThresholdNotMet { .. } => "PriorityThresholdNotMet", MempoolAddError::Rejected(rejection) => match &rejection.reason { - RejectionReason::AlreadyCommitted(_) => "AlreadyCommitted", - RejectionReason::FromExecution(_) => "ExecutionError", - RejectionReason::ValidationError(_) => "ValidationError", + MempoolRejectionReason::AlreadyCommitted(_) => "AlreadyCommitted", + MempoolRejectionReason::FromExecution(_) => "ExecutionError", + MempoolRejectionReason::ValidationError(_) => "ValidationError", }, MempoolAddError::Duplicate(_) => "Duplicate", } diff --git a/core-rust/state-manager/src/mempool/mod.rs b/core-rust/state-manager/src/mempool/mod.rs index fda37aa12c..cb602f0e4c 100644 --- a/core-rust/state-manager/src/mempool/mod.rs +++ b/core-rust/state-manager/src/mempool/mod.rs @@ -62,8 +62,7 @@ * permissions under this License. */ -use radix_engine_common::types::Epoch; -use transaction::{errors::TransactionValidationError, prelude::NotarizedTransactionHash}; +use crate::scrypto_prelude::*; use std::string::ToString; @@ -87,7 +86,7 @@ pub enum MempoolAddError { #[derive(Debug)] pub struct MempoolAddRejection { - pub reason: RejectionReason, + pub reason: MempoolRejectionReason, pub against_state: AtState, pub retry_from: RetryFrom, pub was_cached: bool, @@ -99,7 +98,7 @@ pub struct MempoolAddRejection { impl MempoolAddRejection { pub fn for_static_rejection(validation_error: TransactionValidationError) -> Self { Self { - reason: RejectionReason::ValidationError(validation_error), + reason: MempoolRejectionReason::ValidationError(validation_error), against_state: AtState::Static, retry_from: RetryFrom::Never, was_cached: false, diff --git a/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs b/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs index 91154f4650..751c777e34 100644 --- a/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs +++ b/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs @@ -1,5 +1,4 @@ -use radix_engine_common::types::Epoch; -use transaction::{errors::TransactionValidationError, model::*}; +use crate::scrypto_prelude::*; use crate::{ transaction::{CheckMetadata, StaticValidation}, @@ -18,7 +17,7 @@ use std::{ pub type ExecutionRejectionReason = radix_engine::errors::RejectionReason; #[derive(Debug, Clone, PartialEq, Eq)] -pub enum RejectionReason { +pub enum MempoolRejectionReason { AlreadyCommitted(AlreadyCommittedError), FromExecution(Box), ValidationError(TransactionValidationError), @@ -31,13 +30,13 @@ pub struct AlreadyCommittedError { pub committed_notarized_transaction_hash: NotarizedTransactionHash, } -impl From for RejectionReason { +impl From for MempoolRejectionReason { fn from(value: TransactionValidationError) -> Self { Self::ValidationError(value) } } -impl RejectionReason { +impl MempoolRejectionReason { pub fn is_permanent_for_payload(&self) -> bool { self.permanence().is_permanent_for_payload() } @@ -48,8 +47,8 @@ impl RejectionReason { pub fn is_rejected_because_intent_already_committed(&self) -> bool { match self { - RejectionReason::AlreadyCommitted(_) => true, - RejectionReason::FromExecution(rejection_reason) => match **rejection_reason { + MempoolRejectionReason::AlreadyCommitted(_) => true, + MempoolRejectionReason::FromExecution(rejection_reason) => match **rejection_reason { ExecutionRejectionReason::SuccessButFeeLoanNotRepaid => false, ExecutionRejectionReason::ErrorBeforeLoanAndDeferredCostsRepaid(_) => false, ExecutionRejectionReason::TransactionEpochNotYetValid { .. } => false, @@ -57,25 +56,25 @@ impl RejectionReason { ExecutionRejectionReason::IntentHashPreviouslyCommitted => true, ExecutionRejectionReason::IntentHashPreviouslyCancelled => true, }, - RejectionReason::ValidationError(_) => false, + MempoolRejectionReason::ValidationError(_) => false, } } pub fn already_committed_error(&self) -> Option<&AlreadyCommittedError> { match self { - RejectionReason::AlreadyCommitted(error) => Some(error), + MempoolRejectionReason::AlreadyCommitted(error) => Some(error), _ => None, } } pub fn permanence(&self) -> RejectionPermanence { match self { - RejectionReason::AlreadyCommitted(_) => { + MempoolRejectionReason::AlreadyCommitted(_) => { // This is permanent for the intent - because even other, non-committed transactions // of the same intent will fail with `ExecutionRejectionReason::IntentHashPreviouslyCommitted` RejectionPermanence::PermanentForAnyPayloadWithThisIntent } - RejectionReason::FromExecution(rejection_error) => match **rejection_error { + MempoolRejectionReason::FromExecution(rejection_error) => match **rejection_error { ExecutionRejectionReason::SuccessButFeeLoanNotRepaid => { RejectionPermanence::Temporary { retry: RetrySettings::AfterDelay { @@ -105,7 +104,7 @@ impl RejectionReason { RejectionPermanence::PermanentForAnyPayloadWithThisIntent } }, - RejectionReason::ValidationError(validation_error) => match validation_error { + MempoolRejectionReason::ValidationError(validation_error) => match validation_error { // The size is a property of the payload, not the intent TransactionValidationError::TransactionTooLarge => { RejectionPermanence::PermanentForPayload @@ -174,12 +173,16 @@ pub enum RetrySettings { FromEpoch { epoch: Epoch }, } -impl fmt::Display for RejectionReason { +impl fmt::Display for MempoolRejectionReason { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - RejectionReason::AlreadyCommitted(error) => write!(f, "Already committed: {error:?}"), - RejectionReason::FromExecution(rejection_error) => write!(f, "{rejection_error}"), - RejectionReason::ValidationError(validation_error) => { + MempoolRejectionReason::AlreadyCommitted(error) => { + write!(f, "Already committed: {error:?}") + } + MempoolRejectionReason::FromExecution(rejection_error) => { + write!(f, "{rejection_error}") + } + MempoolRejectionReason::ValidationError(validation_error) => { write!(f, "Validation Error: {validation_error:?}") } } @@ -214,7 +217,7 @@ pub struct PendingTransactionRecord { #[derive(Debug, Clone, PartialEq, Eq)] pub struct TransactionAttempt { - pub rejection: Option, + pub rejection: Option, pub against_state: AtState, pub timestamp: SystemTime, } @@ -370,7 +373,7 @@ impl PendingTransactionRecord { } } - pub fn most_applicable_status(&self) -> Option<&RejectionReason> { + pub fn most_applicable_status(&self) -> Option<&MempoolRejectionReason> { self.earliest_permanent_rejection .as_ref() .and_then(|r| r.rejection.as_ref()) @@ -511,11 +514,13 @@ impl PendingTransactionResultCache { // We even overwrite the record for transaction which got committed here // because this is a cache for pending transactions, and it can't be re-committed record.track_attempt(TransactionAttempt { - rejection: Some(RejectionReason::AlreadyCommitted(AlreadyCommittedError { - notarized_transaction_hash: *cached_payload_hash, - committed_state_version: committed_transaction.state_version, - committed_notarized_transaction_hash, - })), + rejection: Some(MempoolRejectionReason::AlreadyCommitted( + AlreadyCommittedError { + notarized_transaction_hash: *cached_payload_hash, + committed_state_version: committed_transaction.state_version, + committed_notarized_transaction_hash, + }, + )), against_state: AtState::Committed { state_version: committed_transaction.state_version, }, @@ -544,12 +549,14 @@ impl PendingTransactionResultCache { *intent_hash, None, TransactionAttempt { - rejection: Some(RejectionReason::AlreadyCommitted(AlreadyCommittedError { - notarized_transaction_hash: *notarized_transaction_hash, - committed_state_version: committed_intent_record.state_version, - committed_notarized_transaction_hash: committed_intent_record - .notarized_transaction_hash, - })), + rejection: Some(MempoolRejectionReason::AlreadyCommitted( + AlreadyCommittedError { + notarized_transaction_hash: *notarized_transaction_hash, + committed_state_version: committed_intent_record.state_version, + committed_notarized_transaction_hash: committed_intent_record + .notarized_transaction_hash, + }, + )), against_state: AtState::Committed { state_version: committed_intent_record.state_version, }, @@ -629,7 +636,6 @@ struct CommittedIntentRecord { #[cfg(test)] mod tests { - use radix_engine_interface::crypto::blake2b_256_hash; use super::*; @@ -661,7 +667,7 @@ mod tests { let intent_hash_3 = intent_hash(3); let example_attempt_1 = TransactionAttempt { - rejection: Some(RejectionReason::ValidationError( + rejection: Some(MempoolRejectionReason::ValidationError( TransactionValidationError::TransactionTooLarge, )), against_state: AtState::Static, @@ -669,7 +675,7 @@ mod tests { }; let example_attempt_2 = TransactionAttempt { - rejection: Some(RejectionReason::FromExecution(Box::new( + rejection: Some(MempoolRejectionReason::FromExecution(Box::new( ExecutionRejectionReason::SuccessButFeeLoanNotRepaid, ))), against_state: AtState::Committed { @@ -837,7 +843,7 @@ mod tests { let intent_hash_2 = intent_hash(2); let attempt_with_temporary_rejection = TransactionAttempt { - rejection: Some(RejectionReason::FromExecution(Box::new( + rejection: Some(MempoolRejectionReason::FromExecution(Box::new( ExecutionRejectionReason::SuccessButFeeLoanNotRepaid, ))), against_state: AtState::Committed { @@ -846,7 +852,7 @@ mod tests { timestamp: start, }; let attempt_with_rejection_until_epoch_10 = TransactionAttempt { - rejection: Some(RejectionReason::FromExecution(Box::new( + rejection: Some(MempoolRejectionReason::FromExecution(Box::new( ExecutionRejectionReason::TransactionEpochNotYetValid { valid_from: Epoch::of(10), current_epoch: Epoch::of(9), @@ -858,7 +864,7 @@ mod tests { timestamp: start, }; let attempt_with_permanent_rejection = TransactionAttempt { - rejection: Some(RejectionReason::ValidationError( + rejection: Some(MempoolRejectionReason::ValidationError( TransactionValidationError::TransactionTooLarge, )), against_state: AtState::Committed { diff --git a/core-rust/state-manager/src/mempool/priority_mempool.rs b/core-rust/state-manager/src/mempool/priority_mempool.rs index 6e53c6cc27..25f5b164ac 100644 --- a/core-rust/state-manager/src/mempool/priority_mempool.rs +++ b/core-rust/state-manager/src/mempool/priority_mempool.rs @@ -67,8 +67,6 @@ use node_common::metrics::TakesMetricLabels; use prometheus::Registry; use rand::seq::index::sample; use tracing::warn; -use transaction::model::*; -use utils::prelude::indexmap::IndexMap; use crate::mempool::*; use itertools::Itertools; @@ -544,11 +542,6 @@ impl PriorityMempool { mod tests { use std::time::Duration; - use radix_engine::types::PublicKey; - use radix_engine_common::crypto::{Secp256k1PublicKey, Secp256k1Signature}; - use radix_engine_common::types::Epoch; - use transaction::model::*; - use crate::mempool::priority_mempool::*; fn create_fake_pub_key() -> PublicKey { diff --git a/core-rust/state-manager/src/metrics.rs b/core-rust/state-manager/src/metrics.rs index 81d9abbb1a..47367c0b03 100644 --- a/core-rust/state-manager/src/metrics.rs +++ b/core-rust/state-manager/src/metrics.rs @@ -75,14 +75,12 @@ use node_common::metrics::*; use prometheus::{ Gauge, GaugeVec, Histogram, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Opts, Registry, }; -use radix_engine::blueprints::consensus_manager::EpochChangeEvent; use crate::protocol::{ PendingProtocolUpdateState, ProtocolState, ProtocolUpdateEnactmentCondition, }; +use crate::scrypto_prelude::*; use crate::store::traits::measurement::CategoryDbVolumeStatistic; -use radix_engine::transaction::TransactionFeeSummary; -use radix_engine_common::prelude::*; pub struct LedgerMetrics { address_encoder: AddressBech32Encoder, // for label rendering only diff --git a/core-rust/state-manager/src/protocol/protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_config.rs index 9be1e3af57..e1c29f8657 100644 --- a/core-rust/state-manager/src/protocol/protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_config.rs @@ -1,13 +1,6 @@ -use radix_engine::prelude::ScryptoSbor; -use radix_engine_common::math::Decimal; -use radix_engine_common::network::NetworkDefinition; -use radix_engine_common::prelude::{hash, scrypto_encode}; - -use radix_engine_common::types::Epoch; -use sbor::Sbor; +use crate::scrypto_prelude::*; use crate::protocol::*; -use utils::prelude::*; // This file contains types for node's local static protocol configuration diff --git a/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs b/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs index 7aa23279b1..34bffbed5b 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs @@ -1,5 +1,4 @@ -use radix_engine::prelude::*; - +use crate::scrypto_prelude::*; use chrono::prelude::*; use chrono::Duration; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs index 668fbcefbc..cc4030889c 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs @@ -1,4 +1,4 @@ -use radix_engine::prelude::*; +use crate::scrypto_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs index ecee873afa..4f5a6d7fdc 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs @@ -1,4 +1,4 @@ -use radix_engine::prelude::*; +use crate::scrypto_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/mod.rs b/core-rust/state-manager/src/protocol/protocol_configs/mod.rs index ca8c4e4f82..a5cfb48f3d 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/mod.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/mod.rs @@ -6,7 +6,7 @@ mod stokenet_protocol_config; mod testnet_protocol_config; use crate::protocol::*; -use radix_engine_common::network::NetworkDefinition; +use crate::scrypto_prelude::*; pub fn resolve_protocol_config(network: &NetworkDefinition) -> ProtocolConfig { match network.logical_name.as_str() { diff --git a/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs index 343bab55fd..c1c50eb917 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs @@ -1,4 +1,4 @@ -use radix_engine::prelude::*; +use crate::scrypto_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs index fab239156b..6ef79569e5 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs @@ -1,4 +1,4 @@ -use radix_engine::prelude::*; +use crate::scrypto_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_state.rs b/core-rust/state-manager/src/protocol/protocol_state.rs index ba53c05451..ff5bfb9670 100644 --- a/core-rust/state-manager/src/protocol/protocol_state.rs +++ b/core-rust/state-manager/src/protocol/protocol_state.rs @@ -1,17 +1,7 @@ -use radix_engine::blueprints::consensus_manager::EpochChangeEvent; -use radix_engine::prelude::{ScryptoCategorize, ScryptoDecode, ScryptoEncode}; +use crate::scrypto_prelude::*; use std::cmp::Ordering; use std::collections::BTreeMap; -use radix_engine_common::constants::CONSENSUS_MANAGER; - -use radix_engine_common::math::Decimal; -use radix_engine_common::prelude::scrypto_decode; - -use radix_engine_common::types::Epoch; -use radix_engine_interface::api::ModuleId; -use radix_engine_interface::prelude::CheckedMul; -use radix_engine_interface::prelude::Emitter; use tracing::info; use crate::protocol::*; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs index 53f8bb6192..ead764c064 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs @@ -1,11 +1,6 @@ use crate::protocol::*; +use crate::scrypto_prelude::*; use crate::transaction::FlashTransactionV1; -use radix_engine::types::*; -use radix_engine::utils::{ - generate_pools_v1_1_state_updates, generate_seconds_precision_state_updates, - generate_validator_fee_fix_state_updates, generate_vm_boot_scrypto_minor_version_state_updates, -}; -use radix_engine_store_interface::interface::SubstateDatabase; pub struct AnemoneProtocolUpdateDefinition; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs index ab195bb1e0..abf9ef5d68 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs @@ -1,6 +1,5 @@ use crate::protocol::*; -use radix_engine::types::*; -use radix_engine_store_interface::interface::SubstateDatabase; +use crate::scrypto_prelude::*; /// Any protocol update beginning `custom-` can have content injected via config. pub struct CustomProtocolUpdateDefinition; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs index ee4a3d0a00..3079ad1b7d 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs @@ -1,5 +1,5 @@ use crate::protocol::*; -use radix_engine::types::*; +use crate::scrypto_prelude::*; pub struct DefaultConfigOnlyProtocolDefinition; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs index ef884a919b..eb91efe796 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs @@ -1,5 +1,5 @@ +use crate::scrypto_prelude::*; use crate::{protocol::*, transaction::FlashTransactionV1}; -use radix_engine::{track::StateUpdates, types::*}; /// Any protocol update beginning `test-` just injects a single transaction. pub struct TestProtocolUpdateDefinition; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs index baa400ab5a..8e8cf3eff3 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs @@ -1,10 +1,6 @@ use super::definitions::*; use crate::protocol::*; -use radix_engine::types::scrypto_encode; -use sbor::Sbor; - -use radix_engine_common::ScryptoSbor; -use utils::prelude::*; +use crate::scrypto_prelude::*; type Overrides = ::Overrides; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs index d85645c988..16a70dcea6 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs @@ -3,10 +3,8 @@ use std::ops::Deref; use std::sync::Arc; +use crate::scrypto_prelude::*; use node_common::locks::{LockFactory, RwLock, StateLock}; -use radix_engine::prelude::*; - -use transaction::prelude::*; use crate::epoch_handling::EpochAwareAccuTreeFactory; use crate::protocol::*; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs index 60af84a717..134b018fee 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs @@ -1,12 +1,10 @@ // This file contains the protocol update logic for specific protocol versions use crate::protocol::*; -use radix_engine::transaction::CostingParameters; -use radix_engine::types::*; +use crate::scrypto_prelude::*; use crate::transaction::*; use crate::LoggingConfig; -use transaction::validation::{NotarizedTransactionValidator, ValidationConfig}; /// A protocol update definition consists of two parts: /// 1) Updating the current (state computer) configuration ("transaction processing rules"). diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs index cc097e3c98..e2ca7e169e 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs @@ -2,8 +2,10 @@ use node_common::locks::StateLock; use std::ops::Deref; use std::sync::Arc; +use crate::scrypto_prelude::*; + use crate::protocol::*; -use crate::traits::*; + use crate::StateManagerDatabase; pub trait ProtocolUpdater { diff --git a/core-rust/state-manager/src/protocol/test.rs b/core-rust/state-manager/src/protocol/test.rs index 9bb0b60c26..262dda1dad 100644 --- a/core-rust/state-manager/src/protocol/test.rs +++ b/core-rust/state-manager/src/protocol/test.rs @@ -63,28 +63,15 @@ */ use prometheus::Registry; -use utils::prelude::*; +use crate::scrypto_prelude::*; use crate::traits::QueryableProofStore; -use radix_engine::blueprints::consensus_manager::{ - ConsensusManagerConfigurationFieldPayload, ConsensusManagerField, -}; -use radix_engine::prelude::dec; -use radix_engine::system::system_substates::FieldSubstate; -use radix_engine::utils::generate_validator_fee_fix_state_updates; - -use radix_engine_common::prelude::{Epoch, CONSENSUS_MANAGER}; -use radix_engine_interface::prelude::MAIN_BASE_PARTITION; -use radix_engine_store_interface::db_key_mapper::{MappedSubstateDatabase, SpreadPrefixKeyMapper}; - -use sbor::HasLatestVersion; use node_common::locks::LockFactory; use node_common::scheduler::Scheduler; use crate::protocol::*; use crate::{LedgerProof, LedgerProofOrigin, StateManager, StateManagerConfig}; -use radix_engine_common::types::Round; use std::ops::Deref; use crate::test::prepare_and_commit_round_update; diff --git a/core-rust/state-manager/src/query/component_dumper.rs b/core-rust/state-manager/src/query/component_dumper.rs index 72783254c1..1f38408d84 100644 --- a/core-rust/state-manager/src/query/component_dumper.rs +++ b/core-rust/state-manager/src/query/component_dumper.rs @@ -62,12 +62,7 @@ * permissions under this License. */ -use radix_engine::types::*; -use radix_engine_interface::blueprints::resource::{ - LiquidFungibleResource, LiquidNonFungibleVault, -}; -use radix_engine_queries::query::{StateTreeTraverser, StateTreeVisitor}; -use radix_engine_store_interface::interface::SubstateDatabase; +use crate::scrypto_prelude::*; pub enum VaultData { Fungible { diff --git a/core-rust/state-manager/src/query/state_manager_substate_queries.rs b/core-rust/state-manager/src/query/state_manager_substate_queries.rs index ec2cfd721e..2a7e69380c 100644 --- a/core-rust/state-manager/src/query/state_manager_substate_queries.rs +++ b/core-rust/state-manager/src/query/state_manager_substate_queries.rs @@ -1,10 +1,4 @@ -use radix_engine::blueprints::consensus_manager::{ - ConsensusManagerField, ConsensusManagerStateFieldSubstate, -}; -use radix_engine::types::*; - -use radix_engine_store_interface::db_key_mapper::{MappedSubstateDatabase, SpreadPrefixKeyMapper}; -use radix_engine_store_interface::interface::SubstateDatabase; +use crate::scrypto_prelude::*; pub trait StateManagerSubstateQueries { fn get_epoch(&self) -> Epoch; diff --git a/core-rust/state-manager/src/receipt.rs b/core-rust/state-manager/src/receipt.rs index 106d72c784..0c25ff605d 100644 --- a/core-rust/state-manager/src/receipt.rs +++ b/core-rust/state-manager/src/receipt.rs @@ -1,18 +1,4 @@ -use radix_engine_interface::blueprints::transaction_processor::InstructionOutput; -use radix_engine_queries::typed_substate_layout::EpochChangeEvent; - -use radix_engine::errors::RuntimeError; - -use radix_engine::transaction::{ - CommitResult, CostingParameters, EventSystemStructure, FeeDestination, FeeSource, - StateUpdateSummary, SubstateSystemStructure, TransactionFeeSummary, TransactionOutcome, -}; -use radix_engine::types::*; - -use radix_engine_interface::types::EventTypeIdentifier; -use radix_engine_store_interface::interface::DbSubstateValue; -use sbor::rust::collections::IndexMap; -use transaction::prelude::TransactionCostingParameters; +use crate::scrypto_prelude::*; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice, WriteableAccuTreeStore}; use crate::accumulator_tree::tree_builder::{AccuTree, Merklizable}; diff --git a/core-rust/state-manager/src/staging/cache.rs b/core-rust/state-manager/src/staging/cache.rs index c074ae80a0..5cd818045e 100644 --- a/core-rust/state-manager/src/staging/cache.rs +++ b/core-rust/state-manager/src/staging/cache.rs @@ -69,30 +69,20 @@ use super::ReadableStore; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice}; use crate::protocol::ProtocolState; +use crate::scrypto_prelude::*; +use crate::staging::overlays::{ + MapSubstateNodeAncestryStore, StagedSubstateNodeAncestryStore, SubstateOverlayIterator, +}; use crate::staging::{ AccuTreeDiff, HashStructuresDiff, HashUpdateContext, ProcessedTransactionReceipt, StateHashTreeDiff, }; +use crate::transaction::{LedgerTransactionHash, TransactionLogic}; use crate::{EpochTransactionIdentifiers, ReceiptTreeHash, StateVersion, TransactionTreeHash}; use im::hashmap::HashMap as ImmutableHashMap; use itertools::Itertools; -use radix_engine_common::prelude::NodeId; - -use radix_engine_store_interface::db_key_mapper::SpreadPrefixKeyMapper; - -use crate::staging::overlays::{ - MapSubstateNodeAncestryStore, StagedSubstateNodeAncestryStore, SubstateOverlayIterator, -}; -use crate::transaction::{LedgerTransactionHash, TransactionLogic}; -use radix_engine_store_interface::interface::{ - DatabaseUpdate, DbPartitionKey, DbSortKey, DbSubstateValue, PartitionDatabaseUpdates, - PartitionEntry, SubstateDatabase, -}; -use radix_engine_stores::hash_tree::tree_store::{NodeKey, ReadableTreeStore, TreeNode}; - use crate::store::traits::{SubstateNodeAncestryRecord, SubstateNodeAncestryStore}; -use sbor::rust::collections::HashMap; use slotmap::SecondaryMap; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd)] diff --git a/core-rust/state-manager/src/staging/mod.rs b/core-rust/state-manager/src/staging/mod.rs index b4c5b3bb8f..86877ba39c 100644 --- a/core-rust/state-manager/src/staging/mod.rs +++ b/core-rust/state-manager/src/staging/mod.rs @@ -70,9 +70,8 @@ mod result; mod stage_tree; use crate::accumulator_tree::storage::ReadableAccuTreeStore; +use crate::scrypto_prelude::*; use crate::{ReceiptTreeHash, StateVersion, TransactionTreeHash}; -use radix_engine_store_interface::interface::SubstateDatabase; -use radix_engine_stores::hash_tree::tree_store::ReadableTreeStore; use crate::store::traits::SubstateNodeAncestryStore; pub use cache::*; diff --git a/core-rust/state-manager/src/staging/node_ancestry_resolver.rs b/core-rust/state-manager/src/staging/node_ancestry_resolver.rs index 72a59e488e..7b047de2a3 100644 --- a/core-rust/state-manager/src/staging/node_ancestry_resolver.rs +++ b/core-rust/state-manager/src/staging/node_ancestry_resolver.rs @@ -62,13 +62,12 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use crate::store::traits::*; use crate::{SubstateChangeAction, SubstateReference}; use std::borrow::Borrow; use std::collections::hash_map::Entry; -use radix_engine::types::*; - /// A parent Substate and its owned Nodes. /// This structure may be used to represent only directly owned Nodes (i.e. all immediate children), /// or all transitively owned Nodes (i.e. all descendants: children, grand-children, grand-grand-...). @@ -297,7 +296,6 @@ impl NodeAncestryResolver { #[cfg(test)] mod tests { use super::*; - use sbor::Value; #[test] pub fn newly_created_child_nodes_are_recorded_under_their_existing_parents() { diff --git a/core-rust/state-manager/src/staging/overlays.rs b/core-rust/state-manager/src/staging/overlays.rs index 7312e29b44..182cd03011 100644 --- a/core-rust/state-manager/src/staging/overlays.rs +++ b/core-rust/state-manager/src/staging/overlays.rs @@ -1,11 +1,9 @@ -use radix_engine_store_interface::interface::{DatabaseUpdate, DbSortKey, PartitionEntry}; +use crate::scrypto_prelude::*; use std::cmp::Ordering; use std::hash::Hash; use std::iter::Peekable; use crate::store::traits::{SubstateNodeAncestryRecord, SubstateNodeAncestryStore}; -use radix_engine_common::types::NodeId; -use utils::prelude::NonIterMap; pub struct SubstateOverlayIterator<'a> { root_db: Peekable + 'a>>, diff --git a/core-rust/state-manager/src/staging/result.rs b/core-rust/state-manager/src/staging/result.rs index a2aaaf3df3..5983903187 100644 --- a/core-rust/state-manager/src/staging/result.rs +++ b/core-rust/state-manager/src/staging/result.rs @@ -66,6 +66,7 @@ use super::ReadableStateTreeStore; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice, WriteableAccuTreeStore}; use crate::protocol::{ProtocolState, ProtocolVersionName}; +use crate::scrypto_prelude::*; use crate::staging::epoch_handling::EpochAwareAccuTreeFactory; use crate::transaction::LedgerTransactionHash; use crate::{ @@ -74,29 +75,13 @@ use crate::{ NextEpoch, PartitionChangeAction, ReceiptTreeHash, StateHash, StateVersion, SubstateChangeAction, SubstateReference, TransactionTreeHash, }; -use radix_engine::blueprints::consensus_manager::EpochChangeEvent; -use radix_engine::blueprints::resource::{FungibleVaultBalanceFieldSubstate, FungibleVaultField}; -use radix_engine::transaction::{ - AbortResult, BalanceChange, CommitResult, CostingParameters, RejectResult, - TransactionFeeSummary, TransactionReceipt, TransactionResult, -}; -use radix_engine_interface::prelude::*; use crate::staging::ReadableStore; -use radix_engine::track::{ - BatchPartitionStateUpdate, NodeStateUpdates, PartitionStateUpdates, StateUpdates, -}; - use crate::staging::node_ancestry_resolver::NodeAncestryResolver; use crate::staging::overlays::{MapSubstateNodeAncestryStore, StagedSubstateNodeAncestryStore}; use crate::store::traits::{KeyedSubstateNodeAncestryRecord, SubstateNodeAncestryStore}; use node_common::utils::IsAccountExt; -use radix_engine_store_interface::db_key_mapper::*; -use radix_engine_store_interface::interface::*; -use radix_engine_stores::hash_tree::tree_store::*; -use radix_engine_stores::hash_tree::*; -use transaction::prelude::TransactionCostingParameters; pub enum ProcessedTransactionReceipt { Commit(ProcessedCommitResult), diff --git a/core-rust/state-manager/src/staging/stage_tree.rs b/core-rust/state-manager/src/staging/stage_tree.rs index ecba0c2e99..781df0a4d4 100644 --- a/core-rust/state-manager/src/staging/stage_tree.rs +++ b/core-rust/state-manager/src/staging/stage_tree.rs @@ -62,9 +62,7 @@ * permissions under this License. */ -use radix_engine::types::*; - -use sbor::rust::vec::Vec; +use crate::scrypto_prelude::*; use slotmap::{new_key_type, SlotMap}; new_key_type! { @@ -309,9 +307,8 @@ impl> StageTree { #[cfg(test)] mod tests { use super::*; - use radix_engine::types::rust::iter::zip; - use sbor::rust::collections::HashMap; - use sbor::rust::vec::Vec; + + use std::iter::zip; struct TestDelta(Vec<(u8, u32)>); diff --git a/core-rust/state-manager/src/state_computer.rs b/core-rust/state-manager/src/state_computer.rs index c791af2152..6fd7ae8e89 100644 --- a/core-rust/state-manager/src/state_computer.rs +++ b/core-rust/state-manager/src/state_computer.rs @@ -71,16 +71,11 @@ use crate::store::traits::*; use crate::transaction::*; use crate::types::{CommitRequest, PrepareRequest, PrepareResult}; use crate::*; -use ::transaction::errors::TransactionValidationError; -use ::transaction::model::{IntentHash, NotarizedTransactionHash}; -use ::transaction::prelude::*; use node_common::config::limits::VertexLimitsConfig; -use radix_engine::system::bootstrap::*; -use radix_engine::transaction::TransactionReceipt; -use radix_engine_interface::blueprints::consensus_manager::{ - ConsensusManagerConfig, EpochChangeCondition, -}; +use crate::scrypto_prelude::*; +use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude + use transaction_scenarios::scenario::DescribedAddress as ScenarioDescribedAddress; use transaction_scenarios::scenario::*; use transaction_scenarios::scenarios::*; @@ -556,7 +551,7 @@ where intent_hash, notarized_transaction_hash, invalid_at_epoch, - rejection_reason: Some(RejectionReason::ValidationError( + rejection_reason: Some(MempoolRejectionReason::ValidationError( error.into_user_validation_error(), )), }); @@ -639,7 +634,7 @@ where intent_hash, notarized_transaction_hash, invalid_at_epoch, - rejection_reason: Some(RejectionReason::FromExecution(Box::new( + rejection_reason: Some(MempoolRejectionReason::FromExecution(Box::new( result.reason, ))), }); @@ -1459,13 +1454,14 @@ struct PendingTransactionResult { pub intent_hash: IntentHash, pub notarized_transaction_hash: NotarizedTransactionHash, pub invalid_at_epoch: Epoch, - pub rejection_reason: Option, + pub rejection_reason: Option, } #[cfg(test)] mod tests { use std::ops::Deref; + use crate::scrypto_prelude::*; use crate::transaction::{LedgerTransaction, RoundUpdateTransactionV1}; use crate::{ LedgerProof, PrepareRequest, PrepareResult, RoundHistory, StateManager, StateManagerConfig, @@ -1474,11 +1470,7 @@ mod tests { use node_common::locks::LockFactory; use node_common::scheduler::Scheduler; use prometheus::Registry; - use radix_engine_common::prelude::NetworkDefinition; - use radix_engine_common::types::{Epoch, Round}; use tempfile::TempDir; - use transaction::builder::ManifestBuilder; - use transaction::prelude::*; // TODO: maybe move/refactor testing infra as we add more Rust tests fn build_unit_test_round_history(proof: &LedgerProof) -> RoundHistory { diff --git a/core-rust/state-manager/src/state_manager.rs b/core-rust/state-manager/src/state_manager.rs index bf837e94a3..097d2a45f8 100644 --- a/core-rust/state-manager/src/state_manager.rs +++ b/core-rust/state-manager/src/state_manager.rs @@ -66,17 +66,9 @@ use std::ops::Deref; use std::sync::Arc; use std::time::Duration; -use node_common::scheduler::{Metrics, Scheduler, Spawner, Tracker}; -use node_common::{ - config::{limits::VertexLimitsConfig, MempoolConfig}, - locks::*, -}; -use prometheus::Registry; - -use radix_engine_common::prelude::*; - use crate::jni::LedgerSyncLimitsConfig; use crate::protocol::{ProtocolConfig, ProtocolState, ProtocolVersionName}; +use crate::scrypto_prelude::*; use crate::store::jmt_gc::StateHashTreeGcConfig; use crate::store::proofs_gc::{LedgerProofsGc, LedgerProofsGcConfig}; use crate::store::traits::proofs::QueryableProofStore; @@ -92,6 +84,12 @@ use crate::{ transaction::{CachedCommittabilityValidator, CommittabilityValidator, TransactionPreviewer}, PendingTransactionResultCache, ProtocolUpdateResult, StateComputer, }; +use node_common::scheduler::{Metrics, Scheduler, Spawner, Tracker}; +use node_common::{ + config::{limits::VertexLimitsConfig, MempoolConfig}, + locks::*, +}; +use prometheus::Registry; /// An interval between time-intensive measurement of raw DB metrics. /// Some of our raw DB metrics take ~a few milliseconds to collect. We cannot afford the overhead of diff --git a/core-rust/state-manager/src/store/codecs.rs b/core-rust/state-manager/src/store/codecs.rs index 3cc0d1903e..34dff1ea15 100644 --- a/core-rust/state-manager/src/store/codecs.rs +++ b/core-rust/state-manager/src/store/codecs.rs @@ -66,10 +66,7 @@ use std::ops::Range; use crate::StateVersion; -use radix_engine::types::*; -use radix_engine_store_interface::interface::*; -use radix_engine_stores::hash_tree::tree_store::{encode_key, NodeKey}; - +use crate::scrypto_prelude::*; use crate::store::traits::scenario::ScenarioSequenceNumber; use crate::store::typed_cf_api::*; use crate::transaction::RawLedgerTransaction; diff --git a/core-rust/state-manager/src/store/db.rs b/core-rust/state-manager/src/store/db.rs index 0b257ae8b5..1b714e1b15 100644 --- a/core-rust/state-manager/src/store/db.rs +++ b/core-rust/state-manager/src/store/db.rs @@ -69,19 +69,12 @@ use std::path::PathBuf; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice}; use crate::query::TransactionIdentifierLoader; +use crate::scrypto_prelude::*; use crate::{ CommittedTransactionIdentifiers, LedgerHashes, ReceiptTreeHash, StateVersion, TransactionTreeHash, }; use enum_dispatch::enum_dispatch; -use radix_engine_common::network::NetworkDefinition; -use radix_engine_store_interface::interface::{ - DbPartitionKey, DbSortKey, DbSubstateValue, PartitionEntry, SubstateDatabase, -}; -use transaction::model::*; - -use radix_engine_stores::hash_tree::tree_store::{NodeKey, ReadableTreeStore, TreeNode}; -use sbor::{Categorize, Decode, Encode}; #[derive(Debug, Categorize, Encode, Decode, Clone)] pub struct DatabaseBackendConfig { diff --git a/core-rust/state-manager/src/store/jmt_gc.rs b/core-rust/state-manager/src/store/jmt_gc.rs index 42af1994b1..d47dec4032 100644 --- a/core-rust/state-manager/src/store/jmt_gc.rs +++ b/core-rust/state-manager/src/store/jmt_gc.rs @@ -62,10 +62,7 @@ * permissions under this License. */ -use radix_engine::types::{Categorize, Decode, Encode}; -use radix_engine_stores::hash_tree::tree_store::{ - NodeKey, ReadableTreeStore, StaleTreePart, TreeChildEntry, TreeNode, -}; +use crate::scrypto_prelude::*; use std::iter; use std::ops::Deref; use std::sync::Arc; @@ -260,13 +257,6 @@ fn recurse_children_and_append_parent<'s, S: ReadableTreeStore + 's>( mod tests { use super::*; - use radix_engine::types::indexmap::indexmap; - use radix_engine_store_interface::interface::{ - DatabaseUpdate, DatabaseUpdates, DbSortKey, NodeDatabaseUpdates, PartitionDatabaseUpdates, - }; - use radix_engine_stores::hash_tree::put_at_next_version; - use radix_engine_stores::hash_tree::tree_store::{NibblePath, TypedInMemoryTreeStore}; - use utils::prelude::{index_set_new, IndexSet}; #[test] fn iterates_substates_from_deleted_partition_in_dfs_order() { diff --git a/core-rust/state-manager/src/store/proofs_gc.rs b/core-rust/state-manager/src/store/proofs_gc.rs index 21367881f2..42f54374e3 100644 --- a/core-rust/state-manager/src/store/proofs_gc.rs +++ b/core-rust/state-manager/src/store/proofs_gc.rs @@ -62,9 +62,7 @@ * permissions under this License. */ -use radix_engine::types::{Categorize, Decode, Encode}; - -use radix_engine_common::types::Epoch; +use crate::scrypto_prelude::*; use std::sync::Arc; use std::time::Duration; use tracing::{error, info}; @@ -315,6 +313,7 @@ mod tests { use crate::jni::LedgerSyncLimitsConfig; use crate::proofs_gc::{LedgerProofsGc, LedgerProofsGcConfig}; use crate::protocol::*; + use crate::scrypto_prelude::*; use crate::store::traits::proofs::QueryableProofStore; use crate::test::commit_round_updates_until_epoch; use crate::traits::GetSyncableTxnsAndProofError; @@ -322,10 +321,6 @@ mod tests { use node_common::locks::LockFactory; use node_common::scheduler::Scheduler; use prometheus::Registry; - use radix_engine_common::prelude::*; - use radix_engine_interface::blueprints::consensus_manager::{ - ConsensusManagerConfig, EpochChangeCondition, - }; use std::time::Duration; #[test] diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index f0f7c8db4a..6af65558f9 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -65,6 +65,7 @@ use std::collections::HashSet; use std::fmt; +use crate::scrypto_prelude::*; use crate::store::traits::*; use crate::{ CommittedTransactionIdentifiers, LedgerProof, LedgerProofOrigin, LedgerTransactionReceipt, @@ -73,16 +74,8 @@ use crate::{ VersionedLedgerProof, VersionedLedgerTransactionReceipt, VersionedLocalTransactionExecution, }; use node_common::utils::IsAccountExt; -use radix_engine::types::*; -use radix_engine_stores::hash_tree::tree_store::{ - NodeKey, ReadableTreeStore, TreeNode, VersionedTreeNode, -}; use rocksdb::{ColumnFamilyDescriptor, Direction, Options, DB}; -use transaction::model::*; - -use radix_engine_store_interface::interface::*; -use radix_engine_store_interface::db_key_mapper::{DatabaseKeyMapper, SpreadPrefixKeyMapper}; use std::path::PathBuf; use tracing::{error, info, warn}; diff --git a/core-rust/state-manager/src/store/traits.rs b/core-rust/state-manager/src/store/traits.rs index 8af821954c..2bdbcaa858 100644 --- a/core-rust/state-manager/src/store/traits.rs +++ b/core-rust/state-manager/src/store/traits.rs @@ -65,6 +65,7 @@ use std::cmp::Ordering; use std::iter::Peekable; +use crate::scrypto_prelude::*; use crate::staging::StateHashTreeDiff; use crate::store::StateManagerDatabase; use crate::transaction::*; @@ -72,14 +73,10 @@ use crate::{CommittedTransactionIdentifiers, LedgerProof, LocalTransactionReceip pub use commit::*; use enum_dispatch::enum_dispatch; pub use proofs::*; -use radix_engine_common::{Categorize, Decode, Encode}; pub use substate::*; pub use transactions::*; pub use vertex::*; -use radix_engine::types::{ScryptoCategorize, ScryptoDecode, ScryptoEncode}; -use sbor::define_single_versioned; - #[derive(Debug, Clone)] pub enum DatabaseConfigValidationError { AccountChangeIndexRequiresLocalTransactionExecutionIndex, @@ -177,13 +174,9 @@ pub mod vertex { pub mod substate { use super::*; - use radix_engine_common::types::NodeId; use std::slice; use crate::SubstateReference; - pub use radix_engine_store_interface::interface::{ - CommittableSubstateDatabase, SubstateDatabase, - }; /// A low-level storage of [`SubstateNodeAncestryRecord`]. /// API note: this trait defines a simple "get by ID" method, and also a performance-driven @@ -296,7 +289,6 @@ pub mod transactions { } pub mod proofs { - use radix_engine_common::types::Epoch; use super::*; @@ -369,11 +361,6 @@ pub mod commit { use crate::accumulator_tree::storage::TreeSlice; use crate::{ReceiptTreeHash, StateVersion, TransactionTreeHash}; - use radix_engine_store_interface::interface::{ - DatabaseUpdate, DatabaseUpdates, NodeDatabaseUpdates, PartitionDatabaseUpdates, - }; - use radix_engine_stores::hash_tree::tree_store::{NodeKey, StaleTreePart, TreeNode}; - pub struct CommitBundle { pub transactions: Vec, pub proof: LedgerProof, @@ -537,8 +524,6 @@ pub mod commit { pub mod scenario { use super::*; - use transaction::model::IntentHash; - pub type ScenarioSequenceNumber = u32; define_single_versioned! { @@ -584,8 +569,6 @@ pub mod scenario { pub mod extensions { use super::*; - use radix_engine::types::GlobalAddress; - use radix_engine_common::network::NetworkDefinition; #[enum_dispatch] pub trait AccountChangeIndexExtension { @@ -673,8 +656,6 @@ pub mod measurement { pub mod gc { use super::*; use crate::LedgerHeader; - use radix_engine_common::types::Epoch; - use radix_engine_stores::hash_tree::tree_store::NodeKey; /// A storage API tailored for the [`StateHashTreeGc`]. #[enum_dispatch] diff --git a/core-rust/state-manager/src/store/typed_cf_api.rs b/core-rust/state-manager/src/store/typed_cf_api.rs index 568da182c7..5bcfc7ed93 100644 --- a/core-rust/state-manager/src/store/typed_cf_api.rs +++ b/core-rust/state-manager/src/store/typed_cf_api.rs @@ -62,8 +62,8 @@ * permissions under this License. */ +use crate::scrypto_prelude::*; use itertools::Itertools; -use radix_engine::types::*; use rocksdb::{ColumnFamily, Direction, IteratorMode, WriteBatch, DB}; use std::ops::Range; diff --git a/core-rust/state-manager/src/test/mod.rs b/core-rust/state-manager/src/test/mod.rs index eca3faf2da..e658b48f9a 100644 --- a/core-rust/state-manager/src/test/mod.rs +++ b/core-rust/state-manager/src/test/mod.rs @@ -1,11 +1,10 @@ use crate::query::TransactionIdentifierLoader; +use crate::scrypto_prelude::*; use crate::traits::QueryableProofStore; use crate::{ CommitRequest, CommitSummary, LedgerHeader, LedgerProof, LedgerProofOrigin, PrepareRequest, PrepareResult, RoundHistory, StateManager, }; -use radix_engine_common::crypto::Hash; -use radix_engine_common::prelude::{Epoch, Round}; /// A bunch of test utils diff --git a/core-rust/state-manager/src/transaction/executable_logic.rs b/core-rust/state-manager/src/transaction/executable_logic.rs index 44fdf21006..a16eb255f5 100644 --- a/core-rust/state-manager/src/transaction/executable_logic.rs +++ b/core-rust/state-manager/src/transaction/executable_logic.rs @@ -1,25 +1,13 @@ -use radix_engine::system::bootstrap::FlashReceipt; -use radix_engine::system::system_db_reader::SystemDatabaseReader; -use radix_engine::track::StateUpdates; -use radix_engine::transaction::{ - execute_transaction, CommitResult, CostingParameters, ExecutionConfig, SubstateSchemaMapper, - SystemStructure, TransactionOutcome, TransactionReceipt, -}; -use radix_engine::vm::wasm::DefaultWasmEngine; -use radix_engine::vm::{DefaultNativeVm, ScryptoVm, Vm}; -use radix_engine_common::network::NetworkDefinition; +use crate::scrypto_prelude::*; +// disambiguation needed because of a wide prelude + +use crate::LoggingConfig; use std::collections::HashMap; -use std::time::{Duration, Instant}; -use radix_engine_interface::*; -use radix_engine_store_interface::interface::SubstateDatabase; +use std::time::{Duration, Instant}; use tracing::warn; -use crate::LoggingConfig; -use transaction::model::*; -use utils::prelude::index_map_new; - use super::ValidatedLedgerTransaction; /// A logic of an already-validated transaction, ready to be executed against an arbitrary state of diff --git a/core-rust/state-manager/src/transaction/ledger_transaction.rs b/core-rust/state-manager/src/transaction/ledger_transaction.rs index 0770cd7198..3f80f4ca58 100644 --- a/core-rust/state-manager/src/transaction/ledger_transaction.rs +++ b/core-rust/state-manager/src/transaction/ledger_transaction.rs @@ -1,13 +1,7 @@ -use radix_engine::system::bootstrap::create_substate_flash_for_genesis; - -use radix_engine::track::StateUpdates; - -use radix_engine_interface::api::node_modules::auth::AuthAddresses; -use radix_engine_interface::prelude::*; +use crate::scrypto_prelude::*; +use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude use crate::transaction::{ConfigType, ConfiguredExecutable}; -use transaction::define_raw_transaction_payload; -use transaction::prelude::*; use super::{ HasRoundUpdateTransactionHash, PreparedRoundUpdateTransactionV1, RoundUpdateTransactionHash, diff --git a/core-rust/state-manager/src/transaction/preview.rs b/core-rust/state-manager/src/transaction/preview.rs index 7aace47232..2d633dc121 100644 --- a/core-rust/state-manager/src/transaction/preview.rs +++ b/core-rust/state-manager/src/transaction/preview.rs @@ -1,6 +1,5 @@ +use crate::scrypto_prelude::*; use node_common::locks::{RwLock, StateLock}; -use radix_engine::transaction::{PreviewError, TransactionReceipt, TransactionResult}; -use radix_engine_store_interface::db_key_mapper::SpreadPrefixKeyMapper; use std::ops::{Deref, Range}; use std::sync::Arc; @@ -11,11 +10,6 @@ use crate::transaction::*; use crate::{ GlobalBalanceSummary, LedgerHeader, LedgerStateChanges, PreviewRequest, ProcessedCommitResult, }; -use radix_engine_common::prelude::*; -use transaction::model::*; -use transaction::prelude::Secp256k1PrivateKey; -use transaction::validation::NotarizedTransactionValidator; -use transaction::validation::ValidationConfig; /// A transaction preview runner. pub struct TransactionPreviewer { @@ -132,12 +126,11 @@ impl Trans #[cfg(test)] mod tests { + use crate::scrypto_prelude::*; use crate::{PreviewRequest, StateManager, StateManagerConfig}; use node_common::locks::LockFactory; use node_common::scheduler::Scheduler; use prometheus::Registry; - use transaction::builder::ManifestBuilder; - use transaction::model::{MessageV1, PreviewFlags}; #[test] fn test_preview_processed_substate_changes() { diff --git a/core-rust/state-manager/src/transaction/round_update_transaction.rs b/core-rust/state-manager/src/transaction/round_update_transaction.rs index b4b40e35ef..93131c4b64 100644 --- a/core-rust/state-manager/src/transaction/round_update_transaction.rs +++ b/core-rust/state-manager/src/transaction/round_update_transaction.rs @@ -1,10 +1,7 @@ -use radix_engine::types::*; +use crate::scrypto_prelude::*; +use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude use crate::{LedgerHeader, RoundHistory, ValidatorId}; -use radix_engine_interface::api::node_modules::auth::AuthAddresses; -use radix_engine_interface::blueprints::consensus_manager::*; -use sbor::FixedEnumVariant; -use transaction::{define_raw_transaction_payload, model::*}; #[derive(Debug, Clone, Categorize, Encode, Decode, PartialEq, Eq)] pub struct RoundUpdateTransactionV1 { diff --git a/core-rust/state-manager/src/transaction/series_execution.rs b/core-rust/state-manager/src/transaction/series_execution.rs index 93d4759fe8..420c9a29aa 100644 --- a/core-rust/state-manager/src/transaction/series_execution.rs +++ b/core-rust/state-manager/src/transaction/series_execution.rs @@ -71,9 +71,8 @@ use crate::store::traits::*; use crate::transaction::*; use crate::*; -use ::transaction::prelude::*; +use crate::scrypto_prelude::*; use node_common::locks::{Mutex, RwLock}; -use radix_engine::blueprints::consensus_manager::EpochChangeEvent; /// An internal delegate for executing a series of consecutive transactions while tracking their /// progress. diff --git a/core-rust/state-manager/src/transaction/validation.rs b/core-rust/state-manager/src/transaction/validation.rs index 2b0053f25a..2da1ae833a 100644 --- a/core-rust/state-manager/src/transaction/validation.rs +++ b/core-rust/state-manager/src/transaction/validation.rs @@ -2,24 +2,19 @@ use node_common::locks::{RwLock, StateLock}; use std::ops::Deref; use std::sync::Arc; use std::time::SystemTime; -use transaction::errors::TransactionValidationError; -use radix_engine::transaction::{AbortReason, RejectResult, TransactionReceipt, TransactionResult}; - -use radix_engine_common::network::NetworkDefinition; +use crate::scrypto_prelude::*; +use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude use crate::query::StateManagerSubstateQueries; use crate::staging::ReadableStore; use crate::store::traits::{QueryableProofStore, TransactionIndex}; use crate::transaction::{ExecutionConfigurator, TransactionLogic}; use crate::{ - AlreadyCommittedError, AtState, ExecutionRejectionReason, PendingTransactionRecord, - PendingTransactionResultCache, RejectionReason, TransactionAttempt, + AlreadyCommittedError, AtState, ExecutionRejectionReason, MempoolRejectionReason, + PendingTransactionRecord, PendingTransactionResultCache, TransactionAttempt, }; -use transaction::prelude::*; -use transaction::validation::*; - use super::{ LedgerTransaction, PreparedLedgerTransaction, PreparedLedgerTransactionInner, RawLedgerTransaction, ValidatedLedgerTransaction, ValidatedLedgerTransactionInner, @@ -236,16 +231,20 @@ where .expect("transaction of a state version obtained from an index"); return TransactionAttempt { - rejection: Some(RejectionReason::AlreadyCommitted(AlreadyCommittedError { - notarized_transaction_hash: transaction.prepared.notarized_transaction_hash(), - committed_state_version: state_version, - committed_notarized_transaction_hash: *committed_transaction_identifiers - .payload - .typed - .user() - .expect("non-user transaction located by intent hash") - .notarized_transaction_hash, - })), + rejection: Some(MempoolRejectionReason::AlreadyCommitted( + AlreadyCommittedError { + notarized_transaction_hash: transaction + .prepared + .notarized_transaction_hash(), + committed_state_version: state_version, + committed_notarized_transaction_hash: *committed_transaction_identifiers + .payload + .typed + .user() + .expect("non-user transaction located by intent hash") + .notarized_transaction_hash, + }, + )), against_state: AtState::Committed { state_version: executed_at_state_version, }, @@ -265,7 +264,7 @@ where transaction.prepared.intent_hash() ); } - Err(RejectionReason::FromExecution(Box::new(reason))) + Err(MempoolRejectionReason::FromExecution(Box::new(reason))) } TransactionResult::Commit(..) => Ok(()), TransactionResult::Abort(abort_result) => { @@ -289,7 +288,7 @@ where &self, root_store: &S, transaction: &ValidatedNotarizedTransactionV1, - ) -> TransactionReceipt { + ) -> TransactionReceiptV1 { self.execution_configurator .read() .wrap_pending_transaction(transaction) @@ -456,7 +455,7 @@ where Err(validation_error) => { // The transaction is statically invalid let attempt = TransactionAttempt { - rejection: Some(RejectionReason::ValidationError(validation_error)), + rejection: Some(MempoolRejectionReason::ValidationError(validation_error)), against_state: AtState::Static, timestamp: current_time, }; diff --git a/core-rust/state-manager/src/types.rs b/core-rust/state-manager/src/types.rs index 75ef264e9d..e02e92614f 100644 --- a/core-rust/state-manager/src/types.rs +++ b/core-rust/state-manager/src/types.rs @@ -64,16 +64,14 @@ use crate::accumulator_tree::IsMerklizableHash; use crate::protocol::ProtocolVersionName; +use crate::scrypto_prelude::*; use crate::transaction::*; use crate::{LedgerTransactionOutcome, PartitionChange, SubstateChange}; -use radix_engine::types::*; -use radix_engine_common::prelude::IsHash; use std::fmt; use std::fmt::Formatter; use std::mem::size_of; use std::num::TryFromIntError; use std::ops::Range; -use transaction::prelude::*; /// A complete ID of a Substate. #[derive(Debug, Clone, Hash, Eq, PartialEq, ScryptoCategorize, ScryptoEncode, ScryptoDecode)] From f9ba2ce9ea1761d35f5365c5092bec9f9453fb53 Mon Sep 17 00:00:00 2001 From: Jakub Krawczyk Date: Thu, 15 Feb 2024 13:03:34 +0100 Subject: [PATCH 22/22] Rename scrypto_prelude -> engine_prelude. --- .../core-api-server/src/core_api/conversions/addressing.rs | 2 +- .../core-api-server/src/core_api/conversions/common.rs | 2 +- .../core-api-server/src/core_api/conversions/context.rs | 2 +- .../core-api-server/src/core_api/conversions/errors.rs | 2 +- .../core-api-server/src/core_api/conversions/hashes.rs | 2 +- .../src/core_api/conversions/keys_and_sigs.rs | 2 +- core-rust/core-api-server/src/core_api/conversions/lts.rs | 2 +- .../core-api-server/src/core_api/conversions/numerics.rs | 2 +- .../core-api-server/src/core_api/conversions/pagination.rs | 2 +- .../core-api-server/src/core_api/conversions/receipt.rs | 2 +- .../src/core_api/conversions/substates/access_controller.rs | 2 +- .../core_api/conversions/substates/access_rules_module.rs | 2 +- .../src/core_api/conversions/substates/account.rs | 2 +- .../src/core_api/conversions/substates/consensus_manager.rs | 2 +- .../src/core_api/conversions/substates/generic.rs | 2 +- .../src/core_api/conversions/substates/metadata_module.rs | 2 +- .../src/core_api/conversions/substates/mod.rs | 2 +- .../src/core_api/conversions/substates/package.rs | 2 +- .../src/core_api/conversions/substates/pools.rs | 2 +- .../src/core_api/conversions/substates/resource.rs | 2 +- .../src/core_api/conversions/substates/royalty_module.rs | 2 +- .../src/core_api/conversions/substates/substate.rs | 2 +- .../core_api/conversions/substates/transaction_tracker.rs | 2 +- .../src/core_api/conversions/substates/type_info_module.rs | 2 +- core-rust/core-api-server/src/core_api/errors.rs | 2 +- .../lts/state_account_all_fungible_resource_balances.rs | 2 +- .../handlers/lts/state_account_deposit_behaviour.rs | 2 +- .../core_api/handlers/lts/state_account_resource_balance.rs | 2 +- .../src/core_api/handlers/lts/transaction_construction.rs | 2 +- .../src/core_api/handlers/lts/transaction_status.rs | 2 +- .../src/core_api/handlers/lts/transaction_submit.rs | 2 +- .../src/core_api/handlers/state_access_controller.rs | 2 +- .../core-api-server/src/core_api/handlers/state_account.rs | 2 +- .../src/core_api/handlers/state_component.rs | 2 +- .../src/core_api/handlers/state_consensus_manager.rs | 2 +- .../src/core_api/handlers/state_non_fungible.rs | 2 +- .../core-api-server/src/core_api/handlers/state_package.rs | 2 +- .../core-api-server/src/core_api/handlers/state_resource.rs | 2 +- .../src/core_api/handlers/state_validator.rs | 2 +- .../src/core_api/handlers/status_network_configuration.rs | 2 +- .../src/core_api/handlers/status_network_status.rs | 2 +- .../src/core_api/handlers/status_scenarios.rs | 2 +- .../core-api-server/src/core_api/handlers/stream_proofs.rs | 2 +- .../src/core_api/handlers/stream_transactions.rs | 2 +- .../src/core_api/handlers/transaction_callpreview.rs | 6 +++--- .../src/core_api/handlers/transaction_parse.rs | 2 +- .../src/core_api/handlers/transaction_preview.rs | 2 +- .../src/core_api/handlers/transaction_status.rs | 2 +- .../src/core_api/handlers/transaction_submit.rs | 2 +- core-rust/core-api-server/src/core_api/helpers.rs | 2 +- core-rust/core-api-server/src/core_api/server.rs | 2 +- core-rust/core-api-server/src/jni/mod.rs | 2 +- core-rust/core-api-server/src/lib.rs | 2 +- core-rust/node-common/src/config/limits.rs | 2 +- core-rust/node-common/src/config/mod.rs | 2 +- core-rust/node-common/src/java/result.rs | 2 +- core-rust/node-common/src/java/structure.rs | 2 +- core-rust/node-common/src/java/types.rs | 2 +- core-rust/node-common/src/java/utils.rs | 2 +- core-rust/node-common/src/jni/addressing.rs | 2 +- core-rust/node-common/src/jni/scrypto_constants.rs | 2 +- core-rust/node-common/src/lib.rs | 2 +- core-rust/node-common/src/utils.rs | 2 +- core-rust/state-manager/src/accumulator_tree/mod.rs | 2 +- core-rust/state-manager/src/accumulator_tree/storage.rs | 2 +- core-rust/state-manager/src/accumulator_tree/test.rs | 2 +- core-rust/state-manager/src/jni/mempool.rs | 2 +- core-rust/state-manager/src/jni/mod.rs | 2 +- core-rust/state-manager/src/jni/node_rust_environment.rs | 2 +- core-rust/state-manager/src/jni/protocol_update.rs | 2 +- core-rust/state-manager/src/jni/state_computer.rs | 2 +- core-rust/state-manager/src/jni/state_reader.rs | 2 +- core-rust/state-manager/src/jni/test_state_reader.rs | 2 +- core-rust/state-manager/src/jni/transaction_preparer.rs | 2 +- core-rust/state-manager/src/jni/transaction_store.rs | 2 +- core-rust/state-manager/src/lib.rs | 2 +- core-rust/state-manager/src/limits.rs | 2 +- .../state-manager/src/mempool/mempool_relay_dispatcher.rs | 2 +- core-rust/state-manager/src/mempool/mod.rs | 2 +- .../src/mempool/pending_transaction_result_cache.rs | 2 +- core-rust/state-manager/src/metrics.rs | 2 +- core-rust/state-manager/src/protocol/protocol_config.rs | 2 +- .../src/protocol/protocol_configs/config_printer.rs | 2 +- .../protocol/protocol_configs/dumunet_protocol_config.rs | 2 +- .../protocol/protocol_configs/mainnet_protocol_config.rs | 2 +- .../state-manager/src/protocol/protocol_configs/mod.rs | 2 +- .../protocol/protocol_configs/stokenet_protocol_config.rs | 2 +- .../protocol/protocol_configs/testnet_protocol_config.rs | 2 +- core-rust/state-manager/src/protocol/protocol_state.rs | 2 +- .../protocol_updates/definitions/anemone_definition.rs | 2 +- .../protocol_updates/definitions/custom_definition.rs | 2 +- .../protocol_updates/definitions/default_definition.rs | 2 +- .../protocol_updates/definitions/test_definition.rs | 2 +- .../protocol/protocol_updates/protocol_content_overrides.rs | 2 +- .../protocol/protocol_updates/protocol_update_committer.rs | 2 +- .../protocol/protocol_updates/protocol_update_definition.rs | 2 +- .../src/protocol/protocol_updates/protocol_updaters.rs | 2 +- core-rust/state-manager/src/protocol/test.rs | 2 +- core-rust/state-manager/src/query/component_dumper.rs | 2 +- .../src/query/state_manager_substate_queries.rs | 2 +- core-rust/state-manager/src/receipt.rs | 2 +- core-rust/state-manager/src/staging/cache.rs | 2 +- core-rust/state-manager/src/staging/mod.rs | 2 +- .../state-manager/src/staging/node_ancestry_resolver.rs | 2 +- core-rust/state-manager/src/staging/overlays.rs | 2 +- core-rust/state-manager/src/staging/result.rs | 2 +- core-rust/state-manager/src/staging/stage_tree.rs | 2 +- core-rust/state-manager/src/state_computer.rs | 4 ++-- core-rust/state-manager/src/state_manager.rs | 2 +- core-rust/state-manager/src/store/codecs.rs | 2 +- core-rust/state-manager/src/store/db.rs | 2 +- core-rust/state-manager/src/store/jmt_gc.rs | 2 +- core-rust/state-manager/src/store/proofs_gc.rs | 4 ++-- core-rust/state-manager/src/store/rocks_db.rs | 2 +- core-rust/state-manager/src/store/traits.rs | 2 +- core-rust/state-manager/src/store/typed_cf_api.rs | 2 +- core-rust/state-manager/src/test/mod.rs | 2 +- core-rust/state-manager/src/transaction/executable_logic.rs | 2 +- .../state-manager/src/transaction/ledger_transaction.rs | 2 +- core-rust/state-manager/src/transaction/preview.rs | 4 ++-- .../src/transaction/round_update_transaction.rs | 2 +- core-rust/state-manager/src/transaction/series_execution.rs | 2 +- core-rust/state-manager/src/transaction/validation.rs | 2 +- core-rust/state-manager/src/types.rs | 2 +- 124 files changed, 129 insertions(+), 129 deletions(-) diff --git a/core-rust/core-api-server/src/core_api/conversions/addressing.rs b/core-rust/core-api-server/src/core_api/conversions/addressing.rs index c81a1d5fc5..f915b9ceb8 100644 --- a/core-rust/core-api-server/src/core_api/conversions/addressing.rs +++ b/core-rust/core-api-server/src/core_api/conversions/addressing.rs @@ -1,6 +1,6 @@ use crate::core_api::models; use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use models::SubstateType; pub fn to_api_global_address( diff --git a/core-rust/core-api-server/src/core_api/conversions/common.rs b/core-rust/core-api-server/src/core_api/conversions/common.rs index 83ac0adf08..0d00cea0be 100644 --- a/core-rust/core-api-server/src/core_api/conversions/common.rs +++ b/core-rust/core-api-server/src/core_api/conversions/common.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::LedgerHeader; use crate::core_api::handlers::to_api_epoch_round; diff --git a/core-rust/core-api-server/src/core_api/conversions/context.rs b/core-rust/core-api-server/src/core_api/conversions/context.rs index 2801ada471..8bc600fd25 100644 --- a/core-rust/core-api-server/src/core_api/conversions/context.rs +++ b/core-rust/core-api-server/src/core_api/conversions/context.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::core_api::models; diff --git a/core-rust/core-api-server/src/core_api/conversions/errors.rs b/core-rust/core-api-server/src/core_api/conversions/errors.rs index 70351d319b..64ce85fb63 100644 --- a/core-rust/core-api-server/src/core_api/conversions/errors.rs +++ b/core-rust/core-api-server/src/core_api/conversions/errors.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::StateVersion; use tracing::warn; diff --git a/core-rust/core-api-server/src/core_api/conversions/hashes.rs b/core-rust/core-api-server/src/core_api/conversions/hashes.rs index ec7b578be1..5aef7f647c 100644 --- a/core-rust/core-api-server/src/core_api/conversions/hashes.rs +++ b/core-rust/core-api-server/src/core_api/conversions/hashes.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::{transaction::*, ReceiptTreeHash, StateHash, TransactionTreeHash}; use crate::core_api::*; diff --git a/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs b/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs index aaca52228c..8d9aef2f6c 100644 --- a/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs +++ b/core-rust/core-api-server/src/core_api/conversions/keys_and_sigs.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::core_api::*; diff --git a/core-rust/core-api-server/src/core_api/conversions/lts.rs b/core-rust/core-api-server/src/core_api/conversions/lts.rs index cbe9d3b4c8..d8a30b9e00 100644 --- a/core-rust/core-api-server/src/core_api/conversions/lts.rs +++ b/core-rust/core-api-server/src/core_api/conversions/lts.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::store::{traits::SubstateNodeAncestryStore, StateManagerDatabase}; use state_manager::{ CommittedTransactionIdentifiers, LedgerTransactionOutcome, LocalTransactionReceipt, diff --git a/core-rust/core-api-server/src/core_api/conversions/numerics.rs b/core-rust/core-api-server/src/core_api/conversions/numerics.rs index 3182ee31c3..60caf7b648 100644 --- a/core-rust/core-api-server/src/core_api/conversions/numerics.rs +++ b/core-rust/core-api-server/src/core_api/conversions/numerics.rs @@ -1,6 +1,6 @@ use std::any::type_name; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::store::traits::scenario::ScenarioSequenceNumber; use state_manager::StateVersion; diff --git a/core-rust/core-api-server/src/core_api/conversions/pagination.rs b/core-rust/core-api-server/src/core_api/conversions/pagination.rs index c78166479e..9b545fb856 100644 --- a/core-rust/core-api-server/src/core_api/conversions/pagination.rs +++ b/core-rust/core-api-server/src/core_api/conversions/pagination.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub struct SizeRange { pub min: usize, diff --git a/core-rust/core-api-server/src/core_api/conversions/receipt.rs b/core-rust/core-api-server/src/core_api/conversions/receipt.rs index 188b22d603..0e915a3776 100644 --- a/core-rust/core-api-server/src/core_api/conversions/receipt.rs +++ b/core-rust/core-api-server/src/core_api/conversions/receipt.rs @@ -2,7 +2,7 @@ use super::addressing::*; use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::store::StateManagerDatabase; use state_manager::{ diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs b/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs index 486671cc2a..bce1fae150 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_access_controller_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs index 0b2d2f70db..fba157124a 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_owner_role_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/account.rs b/core-rust/core-api-server/src/core_api/conversions/substates/account.rs index 17628f8e45..6f0db9ae64 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/account.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/account.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_account_state_substate( _context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs b/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs index 82ec43516f..17fa0515b4 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_registered_validators_by_stake_index_entry_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs b/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs index cdf45f041b..595f41240c 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/generic.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_generic_scrypto_component_state_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs index ea15540072..8c2be435f5 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_metadata_value_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs b/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs index 2818144cf7..7090f53c3c 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs @@ -31,7 +31,7 @@ pub use type_info_module::*; //==================================== use super::MappingError; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; macro_rules! assert_key_type { ( diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/package.rs b/core-rust/core-api-server/src/core_api/conversions/substates/package.rs index 18c8d81af8..6c29516817 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/package.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/package.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_package_royalty_accumulator_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs b/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs index ddfa9bb963..efaa14e274 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_one_resource_pool_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs b/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs index 6fd7c49450..c81c3c4dda 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_fungible_vault_balance_substate( _context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs index cfc44a4541..bc76b4688f 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_component_royalty_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs b/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs index eae8a6ba7e..43d52ac7f2 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/substate.rs @@ -2,7 +2,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs b/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs index 33e83a4654..71effdc48a 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/transaction_tracker.rs @@ -1,7 +1,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_transaction_tracker_substate( context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs index a17ba78ac2..605b1e19a5 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/type_info_module.rs @@ -2,7 +2,7 @@ use super::super::*; use super::*; use crate::core_api::models; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub fn to_api_vm_boot_substate( _context: &MappingContext, diff --git a/core-rust/core-api-server/src/core_api/errors.rs b/core-rust/core-api-server/src/core_api/errors.rs index af9dea45ad..5be3348f72 100644 --- a/core-rust/core-api-server/src/core_api/errors.rs +++ b/core-rust/core-api-server/src/core_api/errors.rs @@ -6,7 +6,7 @@ use axum::{ use models::stream_proofs_error_details::StreamProofsErrorDetails; use std::any::Any; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use hyper::StatusCode; use tower_http::catch_panic::ResponseForPanic; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs index 72cf405365..5771cb49d5 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_all_fungible_resource_balances.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::query::{dump_component_state, VaultData}; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs index 872aba6d6c..a1351fc930 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_deposit_behaviour.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::LedgerHeader; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs index ef38dd8f65..0e5e800494 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/state_account_resource_balance.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::LedgerHeader; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs index d5e4da97b0..f89e191e29 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_construction.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs index 4406213f34..9dc0d95ca3 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_status.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::{ AlreadyCommittedError, DetailedTransactionOutcome, MempoolRejectionReason, StateVersion, diff --git a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs index c8f6f5e2dd..14e5ba1e1a 100644 --- a/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs +++ b/core-rust/core-api-server/src/core_api/handlers/lts/transaction_submit.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::core_api::handlers::to_api_committed_intent_metadata; use hyper::StatusCode; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs b/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs index 47fc2cc973..522de04942 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_access_controller.rs @@ -1,6 +1,6 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::query::dump_component_state; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_account.rs b/core-rust/core-api-server/src/core_api/handlers/state_account.rs index 432a125f9a..ff69c3ea0a 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_account.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_account.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::query::{dump_component_state, VaultData}; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_component.rs b/core-rust/core-api-server/src/core_api/handlers/state_component.rs index 28a265eecb..45ebf8b15a 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_component.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_component.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::query::{dump_component_state, ComponentStateDump, DescendantParentOpt}; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs b/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs index de5b7dcc75..830bd09bf2 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_consensus_manager.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::protocol::ProtocolVersionName; use state_manager::StateManagerDatabase; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs b/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs index 583ba07ddd..e657e46d0c 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_non_fungible.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_package.rs b/core-rust/core-api-server/src/core_api/handlers/state_package.rs index e129d1fa35..75389a3d8c 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_package.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_package.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_resource.rs b/core-rust/core-api-server/src/core_api/handlers/state_resource.rs index 17f5428ba8..6a3662a118 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_resource.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_resource.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::ops::Deref; diff --git a/core-rust/core-api-server/src/core_api/handlers/state_validator.rs b/core-rust/core-api-server/src/core_api/handlers/state_validator.rs index 7554452f2d..69dd1caaa1 100644 --- a/core-rust/core-api-server/src/core_api/handlers/state_validator.rs +++ b/core-rust/core-api-server/src/core_api/handlers/state_validator.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::query::dump_component_state; diff --git a/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs b/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs index 0cc054b0da..8d0e3a0afa 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_network_configuration.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; #[tracing::instrument(skip(state))] pub(crate) async fn handle_status_network_configuration( diff --git a/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs b/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs index d10fb0702b..c6b2d86050 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_network_status.rs @@ -1,6 +1,6 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::query::TransactionIdentifierLoader; use state_manager::store::traits::*; diff --git a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs index b9b40a4801..6fc6bfdd54 100644 --- a/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs +++ b/core-rust/core-api-server/src/core_api/handlers/status_scenarios.rs @@ -1,6 +1,6 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::store::traits::scenario::{ ExecutedGenesisScenario, ExecutedGenesisScenarioStore, ExecutedScenarioTransaction, diff --git a/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs b/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs index 7ec65ad6e3..02245004c7 100644 --- a/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs +++ b/core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::store::{traits::*, StateManagerDatabase}; use state_manager::{LedgerProof, LedgerProofOrigin, StateVersion}; diff --git a/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs b/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs index 6713871ea3..5c8beb3b9f 100644 --- a/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs +++ b/core-rust/core-api-server/src/core_api/handlers/stream_transactions.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::iter; diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs index 028a0625f7..800d794cb6 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_callpreview.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::PreviewRequest; @@ -7,9 +7,9 @@ macro_rules! args_from_bytes_vec { ($args: expr) => {{ let mut fields = Vec::new(); for arg in $args { - fields.push(crate::scrypto_prelude::manifest_decode(&arg).unwrap()); + fields.push(crate::engine_prelude::manifest_decode(&arg).unwrap()); } - crate::scrypto_prelude::ManifestValue::Tuple { fields } + crate::engine_prelude::ManifestValue::Tuple { fields } }}; } diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs index 12ecc809db..0dcb1d1b83 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_parse.rs @@ -8,7 +8,7 @@ use models::transaction_parse_response::TransactionParseResponse; use state_manager::mempool::pending_transaction_result_cache::MempoolRejectionReason; use state_manager::transaction::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::store::StateManagerDatabase; use super::{ diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs index fa628e9483..fd0ffda0b6 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_preview.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::ops::Range; diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs index 7a03f494c2..6a19ac874d 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_status.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use state_manager::{ AlreadyCommittedError, DetailedTransactionOutcome, MempoolRejectionReason, StateVersion, diff --git a/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs b/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs index 7ca7fb25a9..c557a9a680 100644 --- a/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs +++ b/core-rust/core-api-server/src/core_api/handlers/transaction_submit.rs @@ -1,5 +1,5 @@ use crate::core_api::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use hyper::StatusCode; use models::transaction_submit_error_details::TransactionSubmitErrorDetails; diff --git a/core-rust/core-api-server/src/core_api/helpers.rs b/core-rust/core-api-server/src/core_api/helpers.rs index fb32ce56ba..bdc9238ecc 100644 --- a/core-rust/core-api-server/src/core_api/helpers.rs +++ b/core-rust/core-api-server/src/core_api/helpers.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use serde::Serialize; use state_manager::store::traits::*; use state_manager::store::StateManagerDatabase; diff --git a/core-rust/core-api-server/src/core_api/server.rs b/core-rust/core-api-server/src/core_api/server.rs index 2ddc3f3c97..17c71e73e6 100644 --- a/core-rust/core-api-server/src/core_api/server.rs +++ b/core-rust/core-api-server/src/core_api/server.rs @@ -77,7 +77,7 @@ use axum::{ Router, }; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use prometheus::Registry; use state_manager::StateManager; use tower_http::catch_panic::CatchPanicLayer; diff --git a/core-rust/core-api-server/src/jni/mod.rs b/core-rust/core-api-server/src/jni/mod.rs index 13ea5790a7..4c83711c89 100644 --- a/core-rust/core-api-server/src/jni/mod.rs +++ b/core-rust/core-api-server/src/jni/mod.rs @@ -63,7 +63,7 @@ */ use crate::core_api::{create_server, CoreApiServerConfig, CoreApiState}; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use futures::channel::oneshot; use futures::channel::oneshot::Sender; use futures::FutureExt; diff --git a/core-rust/core-api-server/src/lib.rs b/core-rust/core-api-server/src/lib.rs index 677c7d2ce6..08ce258ac4 100644 --- a/core-rust/core-api-server/src/lib.rs +++ b/core-rust/core-api-server/src/lib.rs @@ -68,7 +68,7 @@ extern crate serde_json; mod core_api; pub mod jni; -pub(crate) mod scrypto_prelude { +pub(crate) mod engine_prelude { pub use blueprint_schema_init::*; pub use radix_engine::blueprints::account::*; pub use radix_engine::blueprints::models::*; diff --git a/core-rust/node-common/src/config/limits.rs b/core-rust/node-common/src/config/limits.rs index 3511813568..7e86eb4f00 100644 --- a/core-rust/node-common/src/config/limits.rs +++ b/core-rust/node-common/src/config/limits.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; // TODO: revisit & tune before Babylon pub const DEFAULT_MAX_VERTEX_TRANSACTION_COUNT: u32 = 100; diff --git a/core-rust/node-common/src/config/mod.rs b/core-rust/node-common/src/config/mod.rs index c250af2a7c..a7c74ab577 100644 --- a/core-rust/node-common/src/config/mod.rs +++ b/core-rust/node-common/src/config/mod.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub mod limits; diff --git a/core-rust/node-common/src/java/result.rs b/core-rust/node-common/src/java/result.rs index 92516ba06f..fe44c2ee1d 100644 --- a/core-rust/node-common/src/java/result.rs +++ b/core-rust/node-common/src/java/result.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; #[derive(Debug, ScryptoSbor)] pub struct JavaError(pub String); diff --git a/core-rust/node-common/src/java/structure.rs b/core-rust/node-common/src/java/structure.rs index 2a477ff95b..6b19c64bd6 100644 --- a/core-rust/node-common/src/java/structure.rs +++ b/core-rust/node-common/src/java/structure.rs @@ -62,8 +62,8 @@ * permissions under this License. */ +use crate::engine_prelude::*; use crate::java::result::JavaResult; -use crate::scrypto_prelude::*; pub trait StructFromJava { fn from_java(data: &[u8]) -> JavaResult diff --git a/core-rust/node-common/src/java/types.rs b/core-rust/node-common/src/java/types.rs index cde150f447..c70b34d836 100644 --- a/core-rust/node-common/src/java/types.rs +++ b/core-rust/node-common/src/java/types.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; #[derive(Debug, PartialEq, Eq, Categorize, Encode, Decode)] pub struct JavaHashCode(Vec); diff --git a/core-rust/node-common/src/java/utils.rs b/core-rust/node-common/src/java/utils.rs index e4490e4427..5af40d96c1 100644 --- a/core-rust/node-common/src/java/utils.rs +++ b/core-rust/node-common/src/java/utils.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use jni::sys::jbyteArray; use jni::JNIEnv; use std::panic; diff --git a/core-rust/node-common/src/jni/addressing.rs b/core-rust/node-common/src/jni/addressing.rs index c73af2ed36..2e362e0e75 100644 --- a/core-rust/node-common/src/jni/addressing.rs +++ b/core-rust/node-common/src/jni/addressing.rs @@ -62,8 +62,8 @@ * permissions under this License. */ +use crate::engine_prelude::*; use crate::java::utils::jni_sbor_coded_call; -use crate::scrypto_prelude::*; use bech32::{FromBase32, ToBase32, Variant}; use jni::objects::JClass; use jni::sys::jbyteArray; diff --git a/core-rust/node-common/src/jni/scrypto_constants.rs b/core-rust/node-common/src/jni/scrypto_constants.rs index b2084a2c8b..e4e60e6d23 100644 --- a/core-rust/node-common/src/jni/scrypto_constants.rs +++ b/core-rust/node-common/src/jni/scrypto_constants.rs @@ -66,8 +66,8 @@ use jni::objects::JClass; use jni::sys::jbyteArray; use jni::JNIEnv; +use crate::engine_prelude::*; use crate::java::utils::jni_sbor_coded_call; -use crate::scrypto_prelude::*; #[no_mangle] extern "system" fn Java_com_radixdlt_rev2_ScryptoConstants_getXrdResourceAddress( diff --git a/core-rust/node-common/src/lib.rs b/core-rust/node-common/src/lib.rs index 1bffd524b9..feffde036a 100644 --- a/core-rust/node-common/src/lib.rs +++ b/core-rust/node-common/src/lib.rs @@ -71,6 +71,6 @@ pub mod metrics; pub mod scheduler; pub mod utils; -pub(crate) mod scrypto_prelude { +pub(crate) mod engine_prelude { pub use radix_engine_common::prelude::*; } diff --git a/core-rust/node-common/src/utils.rs b/core-rust/node-common/src/utils.rs index d21c0e8c3f..eb4d836bbf 100644 --- a/core-rust/node-common/src/utils.rs +++ b/core-rust/node-common/src/utils.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub trait IsAccountExt { fn is_account(&self) -> bool; diff --git a/core-rust/state-manager/src/accumulator_tree/mod.rs b/core-rust/state-manager/src/accumulator_tree/mod.rs index 6bf09f90bb..994b221e37 100644 --- a/core-rust/state-manager/src/accumulator_tree/mod.rs +++ b/core-rust/state-manager/src/accumulator_tree/mod.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use tree_builder::Merklizable; pub mod slice_merger; diff --git a/core-rust/state-manager/src/accumulator_tree/storage.rs b/core-rust/state-manager/src/accumulator_tree/storage.rs index f4826cdfdd..55a2a089e3 100644 --- a/core-rust/state-manager/src/accumulator_tree/storage.rs +++ b/core-rust/state-manager/src/accumulator_tree/storage.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use enum_dispatch::enum_dispatch; /// The "read" part of an accumulator tree storage SPI. diff --git a/core-rust/state-manager/src/accumulator_tree/test.rs b/core-rust/state-manager/src/accumulator_tree/test.rs index 9e0b66679f..70b1759165 100644 --- a/core-rust/state-manager/src/accumulator_tree/test.rs +++ b/core-rust/state-manager/src/accumulator_tree/test.rs @@ -66,7 +66,7 @@ use super::slice_merger::AccuTreeSliceMerger; use super::storage::{ReadableAccuTreeStore, WriteableAccuTreeStore}; use super::storage::{TreeSlice, TreeSliceLevel}; use super::tree_builder::{AccuTree, Merklizable}; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::collections::HashMap; // Simple smoke tests using the actual hashing coming from our business use-cases: diff --git a/core-rust/state-manager/src/jni/mempool.rs b/core-rust/state-manager/src/jni/mempool.rs index 9a83c8bd74..c168258a23 100644 --- a/core-rust/state-manager/src/jni/mempool.rs +++ b/core-rust/state-manager/src/jni/mempool.rs @@ -71,8 +71,8 @@ use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; +use crate::engine_prelude::*; use crate::mempool::*; -use crate::scrypto_prelude::*; use crate::MempoolAddSource; use node_common::java::*; diff --git a/core-rust/state-manager/src/jni/mod.rs b/core-rust/state-manager/src/jni/mod.rs index 6d30eb8d6b..a5bd6d5c5d 100644 --- a/core-rust/state-manager/src/jni/mod.rs +++ b/core-rust/state-manager/src/jni/mod.rs @@ -74,7 +74,7 @@ pub mod transaction_preparer; pub mod transaction_store; pub mod vertex_store_recovery; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; /// Limits regarding the granularity of ledger sync (and thus of ledger proofs kept in storage). /// This struct is defined publicly here, since it is used by the transaction store and the ledger diff --git a/core-rust/state-manager/src/jni/node_rust_environment.rs b/core-rust/state-manager/src/jni/node_rust_environment.rs index c881c67237..ab0a3d5263 100644 --- a/core-rust/state-manager/src/jni/node_rust_environment.rs +++ b/core-rust/state-manager/src/jni/node_rust_environment.rs @@ -66,7 +66,7 @@ use std::ops::Deref; use std::str::FromStr; use std::sync::Arc; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; diff --git a/core-rust/state-manager/src/jni/protocol_update.rs b/core-rust/state-manager/src/jni/protocol_update.rs index 481e36d4c5..77e3d2f486 100644 --- a/core-rust/state-manager/src/jni/protocol_update.rs +++ b/core-rust/state-manager/src/jni/protocol_update.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::{protocol::*, ProtocolUpdateResult}; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; diff --git a/core-rust/state-manager/src/jni/state_computer.rs b/core-rust/state-manager/src/jni/state_computer.rs index 72fa43dfc6..bf05c25646 100644 --- a/core-rust/state-manager/src/jni/state_computer.rs +++ b/core-rust/state-manager/src/jni/state_computer.rs @@ -62,8 +62,8 @@ * permissions under this License. */ +use crate::engine_prelude::*; use crate::protocol::ProtocolVersionName; -use crate::scrypto_prelude::*; use crate::{protocol::ProtocolState, CommitSummary, LedgerProof}; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; diff --git a/core-rust/state-manager/src/jni/state_reader.rs b/core-rust/state-manager/src/jni/state_reader.rs index 6d2a61b9a1..dea9748291 100644 --- a/core-rust/state-manager/src/jni/state_reader.rs +++ b/core-rust/state-manager/src/jni/state_reader.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; use jni::JNIEnv; diff --git a/core-rust/state-manager/src/jni/test_state_reader.rs b/core-rust/state-manager/src/jni/test_state_reader.rs index 2ec455a04a..08d1050913 100644 --- a/core-rust/state-manager/src/jni/test_state_reader.rs +++ b/core-rust/state-manager/src/jni/test_state_reader.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::{DetailedTransactionOutcome, LedgerTransactionOutcome, StateVersion}; use jni::objects::{JClass, JObject}; use jni::sys::jbyteArray; diff --git a/core-rust/state-manager/src/jni/transaction_preparer.rs b/core-rust/state-manager/src/jni/transaction_preparer.rs index 67788f46d4..80c5acbf90 100644 --- a/core-rust/state-manager/src/jni/transaction_preparer.rs +++ b/core-rust/state-manager/src/jni/transaction_preparer.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::transaction::*; use jni::objects::JClass; use jni::sys::jbyteArray; diff --git a/core-rust/state-manager/src/jni/transaction_store.rs b/core-rust/state-manager/src/jni/transaction_store.rs index ec9876928d..31c9211b2c 100644 --- a/core-rust/state-manager/src/jni/transaction_store.rs +++ b/core-rust/state-manager/src/jni/transaction_store.rs @@ -62,10 +62,10 @@ * permissions under this License. */ +use crate::engine_prelude::*; use crate::jni::node_rust_environment::JNINodeRustEnvironment; use crate::jni::LedgerSyncLimitsConfig; use crate::protocol::epoch_change_iter; -use crate::scrypto_prelude::*; use crate::store::traits::*; use crate::{LedgerProof, StateVersion}; use jni::objects::{JClass, JObject}; diff --git a/core-rust/state-manager/src/lib.rs b/core-rust/state-manager/src/lib.rs index 9bdc58dc0c..c58fac7cb5 100644 --- a/core-rust/state-manager/src/lib.rs +++ b/core-rust/state-manager/src/lib.rs @@ -92,7 +92,7 @@ pub use crate::state_manager::*; pub use crate::store::*; pub use crate::types::*; -pub(crate) mod scrypto_prelude { +pub(crate) mod engine_prelude { pub use radix_engine::errors::*; pub use radix_engine::system::bootstrap::*; pub use radix_engine::system::system_db_reader::*; diff --git a/core-rust/state-manager/src/limits.rs b/core-rust/state-manager/src/limits.rs index 26ea1926ff..a8fb52481c 100644 --- a/core-rust/state-manager/src/limits.rs +++ b/core-rust/state-manager/src/limits.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use node_common::config::limits::VertexLimitsConfig; #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs b/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs index 47621fd987..516f6cabce 100644 --- a/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs +++ b/core-rust/state-manager/src/mempool/mempool_relay_dispatcher.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use jni::errors::Result; use jni::objects::{GlobalRef, JObject, JValue}; use jni::{JNIEnv, JavaVM}; diff --git a/core-rust/state-manager/src/mempool/mod.rs b/core-rust/state-manager/src/mempool/mod.rs index cb602f0e4c..3e3af71033 100644 --- a/core-rust/state-manager/src/mempool/mod.rs +++ b/core-rust/state-manager/src/mempool/mod.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::string::ToString; diff --git a/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs b/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs index 751c777e34..9af61dca4e 100644 --- a/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs +++ b/core-rust/state-manager/src/mempool/pending_transaction_result_cache.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::{ transaction::{CheckMetadata, StaticValidation}, diff --git a/core-rust/state-manager/src/metrics.rs b/core-rust/state-manager/src/metrics.rs index 47367c0b03..47e95bcc1a 100644 --- a/core-rust/state-manager/src/metrics.rs +++ b/core-rust/state-manager/src/metrics.rs @@ -76,10 +76,10 @@ use prometheus::{ Gauge, GaugeVec, Histogram, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Opts, Registry, }; +use crate::engine_prelude::*; use crate::protocol::{ PendingProtocolUpdateState, ProtocolState, ProtocolUpdateEnactmentCondition, }; -use crate::scrypto_prelude::*; use crate::store::traits::measurement::CategoryDbVolumeStatistic; pub struct LedgerMetrics { diff --git a/core-rust/state-manager/src/protocol/protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_config.rs index e1c29f8657..897881b40a 100644 --- a/core-rust/state-manager/src/protocol/protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_config.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::protocol::*; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs b/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs index 34bffbed5b..aa8a2a1453 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/config_printer.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use chrono::prelude::*; use chrono::Duration; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs index cc4030889c..d45594ec28 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/dumunet_protocol_config.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs index 4f5a6d7fdc..0fba12eb69 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/mainnet_protocol_config.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/mod.rs b/core-rust/state-manager/src/protocol/protocol_configs/mod.rs index a5cfb48f3d..56cdb1defa 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/mod.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/mod.rs @@ -5,8 +5,8 @@ mod mainnet_protocol_config; mod stokenet_protocol_config; mod testnet_protocol_config; +use crate::engine_prelude::*; use crate::protocol::*; -use crate::scrypto_prelude::*; pub fn resolve_protocol_config(network: &NetworkDefinition) -> ProtocolConfig { match network.logical_name.as_str() { diff --git a/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs index c1c50eb917..ef48a1339c 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/stokenet_protocol_config.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs b/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs index 6ef79569e5..502bcc5033 100644 --- a/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs +++ b/core-rust/state-manager/src/protocol/protocol_configs/testnet_protocol_config.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::protocol::*; use ProtocolUpdateEnactmentCondition::*; diff --git a/core-rust/state-manager/src/protocol/protocol_state.rs b/core-rust/state-manager/src/protocol/protocol_state.rs index ff5bfb9670..ce5f9bdd02 100644 --- a/core-rust/state-manager/src/protocol/protocol_state.rs +++ b/core-rust/state-manager/src/protocol/protocol_state.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::cmp::Ordering; use std::collections::BTreeMap; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs index ead764c064..d65e566ce8 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/anemone_definition.rs @@ -1,5 +1,5 @@ +use crate::engine_prelude::*; use crate::protocol::*; -use crate::scrypto_prelude::*; use crate::transaction::FlashTransactionV1; pub struct AnemoneProtocolUpdateDefinition; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs index abf9ef5d68..d7657f5a74 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/custom_definition.rs @@ -1,5 +1,5 @@ +use crate::engine_prelude::*; use crate::protocol::*; -use crate::scrypto_prelude::*; /// Any protocol update beginning `custom-` can have content injected via config. pub struct CustomProtocolUpdateDefinition; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs index 3079ad1b7d..99ef461f10 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/default_definition.rs @@ -1,5 +1,5 @@ +use crate::engine_prelude::*; use crate::protocol::*; -use crate::scrypto_prelude::*; pub struct DefaultConfigOnlyProtocolDefinition; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs index eb91efe796..615142abf2 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/definitions/test_definition.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::{protocol::*, transaction::FlashTransactionV1}; /// Any protocol update beginning `test-` just injects a single transaction. diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs index 8e8cf3eff3..a17e84e4c8 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_content_overrides.rs @@ -1,6 +1,6 @@ use super::definitions::*; +use crate::engine_prelude::*; use crate::protocol::*; -use crate::scrypto_prelude::*; type Overrides = ::Overrides; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs index 16a70dcea6..5d86651973 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_committer.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use std::sync::Arc; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use node_common::locks::{LockFactory, RwLock, StateLock}; use crate::epoch_handling::EpochAwareAccuTreeFactory; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs index 134b018fee..f2e9711b75 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_update_definition.rs @@ -1,7 +1,7 @@ // This file contains the protocol update logic for specific protocol versions +use crate::engine_prelude::*; use crate::protocol::*; -use crate::scrypto_prelude::*; use crate::transaction::*; use crate::LoggingConfig; diff --git a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs index e2ca7e169e..8313cb9510 100644 --- a/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs +++ b/core-rust/state-manager/src/protocol/protocol_updates/protocol_updaters.rs @@ -2,7 +2,7 @@ use node_common::locks::StateLock; use std::ops::Deref; use std::sync::Arc; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::protocol::*; diff --git a/core-rust/state-manager/src/protocol/test.rs b/core-rust/state-manager/src/protocol/test.rs index 262dda1dad..ab231268c8 100644 --- a/core-rust/state-manager/src/protocol/test.rs +++ b/core-rust/state-manager/src/protocol/test.rs @@ -64,7 +64,7 @@ use prometheus::Registry; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::traits::QueryableProofStore; use node_common::locks::LockFactory; diff --git a/core-rust/state-manager/src/query/component_dumper.rs b/core-rust/state-manager/src/query/component_dumper.rs index 1f38408d84..829c592716 100644 --- a/core-rust/state-manager/src/query/component_dumper.rs +++ b/core-rust/state-manager/src/query/component_dumper.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub enum VaultData { Fungible { diff --git a/core-rust/state-manager/src/query/state_manager_substate_queries.rs b/core-rust/state-manager/src/query/state_manager_substate_queries.rs index 2a7e69380c..c280570551 100644 --- a/core-rust/state-manager/src/query/state_manager_substate_queries.rs +++ b/core-rust/state-manager/src/query/state_manager_substate_queries.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; pub trait StateManagerSubstateQueries { fn get_epoch(&self) -> Epoch; diff --git a/core-rust/state-manager/src/receipt.rs b/core-rust/state-manager/src/receipt.rs index 0c25ff605d..edfa64a099 100644 --- a/core-rust/state-manager/src/receipt.rs +++ b/core-rust/state-manager/src/receipt.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice, WriteableAccuTreeStore}; use crate::accumulator_tree::tree_builder::{AccuTree, Merklizable}; diff --git a/core-rust/state-manager/src/staging/cache.rs b/core-rust/state-manager/src/staging/cache.rs index 5cd818045e..3563016f5f 100644 --- a/core-rust/state-manager/src/staging/cache.rs +++ b/core-rust/state-manager/src/staging/cache.rs @@ -68,8 +68,8 @@ use super::stage_tree::{Accumulator, Delta, DerivedStageKey, StageKey, StageTree use super::ReadableStore; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice}; +use crate::engine_prelude::*; use crate::protocol::ProtocolState; -use crate::scrypto_prelude::*; use crate::staging::overlays::{ MapSubstateNodeAncestryStore, StagedSubstateNodeAncestryStore, SubstateOverlayIterator, }; diff --git a/core-rust/state-manager/src/staging/mod.rs b/core-rust/state-manager/src/staging/mod.rs index 86877ba39c..b9a36c573e 100644 --- a/core-rust/state-manager/src/staging/mod.rs +++ b/core-rust/state-manager/src/staging/mod.rs @@ -70,7 +70,7 @@ mod result; mod stage_tree; use crate::accumulator_tree::storage::ReadableAccuTreeStore; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::{ReceiptTreeHash, StateVersion, TransactionTreeHash}; use crate::store::traits::SubstateNodeAncestryStore; diff --git a/core-rust/state-manager/src/staging/node_ancestry_resolver.rs b/core-rust/state-manager/src/staging/node_ancestry_resolver.rs index 7b047de2a3..05b367a28d 100644 --- a/core-rust/state-manager/src/staging/node_ancestry_resolver.rs +++ b/core-rust/state-manager/src/staging/node_ancestry_resolver.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::store::traits::*; use crate::{SubstateChangeAction, SubstateReference}; use std::borrow::Borrow; diff --git a/core-rust/state-manager/src/staging/overlays.rs b/core-rust/state-manager/src/staging/overlays.rs index 182cd03011..ac54cbdc0e 100644 --- a/core-rust/state-manager/src/staging/overlays.rs +++ b/core-rust/state-manager/src/staging/overlays.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::cmp::Ordering; use std::hash::Hash; use std::iter::Peekable; diff --git a/core-rust/state-manager/src/staging/result.rs b/core-rust/state-manager/src/staging/result.rs index 5983903187..2c4b540fcb 100644 --- a/core-rust/state-manager/src/staging/result.rs +++ b/core-rust/state-manager/src/staging/result.rs @@ -65,8 +65,8 @@ use super::ReadableStateTreeStore; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice, WriteableAccuTreeStore}; +use crate::engine_prelude::*; use crate::protocol::{ProtocolState, ProtocolVersionName}; -use crate::scrypto_prelude::*; use crate::staging::epoch_handling::EpochAwareAccuTreeFactory; use crate::transaction::LedgerTransactionHash; use crate::{ diff --git a/core-rust/state-manager/src/staging/stage_tree.rs b/core-rust/state-manager/src/staging/stage_tree.rs index 781df0a4d4..49c7d08bab 100644 --- a/core-rust/state-manager/src/staging/stage_tree.rs +++ b/core-rust/state-manager/src/staging/stage_tree.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use slotmap::{new_key_type, SlotMap}; new_key_type! { diff --git a/core-rust/state-manager/src/state_computer.rs b/core-rust/state-manager/src/state_computer.rs index 6fd7ae8e89..f2ac086b7d 100644 --- a/core-rust/state-manager/src/state_computer.rs +++ b/core-rust/state-manager/src/state_computer.rs @@ -73,7 +73,7 @@ use crate::types::{CommitRequest, PrepareRequest, PrepareResult}; use crate::*; use node_common::config::limits::VertexLimitsConfig; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude use transaction_scenarios::scenario::DescribedAddress as ScenarioDescribedAddress; @@ -1461,7 +1461,7 @@ struct PendingTransactionResult { mod tests { use std::ops::Deref; - use crate::scrypto_prelude::*; + use crate::engine_prelude::*; use crate::transaction::{LedgerTransaction, RoundUpdateTransactionV1}; use crate::{ LedgerProof, PrepareRequest, PrepareResult, RoundHistory, StateManager, StateManagerConfig, diff --git a/core-rust/state-manager/src/state_manager.rs b/core-rust/state-manager/src/state_manager.rs index 097d2a45f8..9fb95f071f 100644 --- a/core-rust/state-manager/src/state_manager.rs +++ b/core-rust/state-manager/src/state_manager.rs @@ -66,9 +66,9 @@ use std::ops::Deref; use std::sync::Arc; use std::time::Duration; +use crate::engine_prelude::*; use crate::jni::LedgerSyncLimitsConfig; use crate::protocol::{ProtocolConfig, ProtocolState, ProtocolVersionName}; -use crate::scrypto_prelude::*; use crate::store::jmt_gc::StateHashTreeGcConfig; use crate::store::proofs_gc::{LedgerProofsGc, LedgerProofsGcConfig}; use crate::store::traits::proofs::QueryableProofStore; diff --git a/core-rust/state-manager/src/store/codecs.rs b/core-rust/state-manager/src/store/codecs.rs index 34dff1ea15..ca5c44751d 100644 --- a/core-rust/state-manager/src/store/codecs.rs +++ b/core-rust/state-manager/src/store/codecs.rs @@ -66,7 +66,7 @@ use std::ops::Range; use crate::StateVersion; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::store::traits::scenario::ScenarioSequenceNumber; use crate::store::typed_cf_api::*; use crate::transaction::RawLedgerTransaction; diff --git a/core-rust/state-manager/src/store/db.rs b/core-rust/state-manager/src/store/db.rs index 1b714e1b15..2003a3310e 100644 --- a/core-rust/state-manager/src/store/db.rs +++ b/core-rust/state-manager/src/store/db.rs @@ -68,8 +68,8 @@ use crate::transaction::LedgerTransactionHash; use std::path::PathBuf; use crate::accumulator_tree::storage::{ReadableAccuTreeStore, TreeSlice}; +use crate::engine_prelude::*; use crate::query::TransactionIdentifierLoader; -use crate::scrypto_prelude::*; use crate::{ CommittedTransactionIdentifiers, LedgerHashes, ReceiptTreeHash, StateVersion, TransactionTreeHash, diff --git a/core-rust/state-manager/src/store/jmt_gc.rs b/core-rust/state-manager/src/store/jmt_gc.rs index d47dec4032..95268966c3 100644 --- a/core-rust/state-manager/src/store/jmt_gc.rs +++ b/core-rust/state-manager/src/store/jmt_gc.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::iter; use std::ops::Deref; use std::sync::Arc; diff --git a/core-rust/state-manager/src/store/proofs_gc.rs b/core-rust/state-manager/src/store/proofs_gc.rs index 42f54374e3..d62a8b2c2a 100644 --- a/core-rust/state-manager/src/store/proofs_gc.rs +++ b/core-rust/state-manager/src/store/proofs_gc.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use std::sync::Arc; use std::time::Duration; use tracing::{error, info}; @@ -310,10 +310,10 @@ impl ProofPruneRange { #[cfg(test)] mod tests { + use crate::engine_prelude::*; use crate::jni::LedgerSyncLimitsConfig; use crate::proofs_gc::{LedgerProofsGc, LedgerProofsGcConfig}; use crate::protocol::*; - use crate::scrypto_prelude::*; use crate::store::traits::proofs::QueryableProofStore; use crate::test::commit_round_updates_until_epoch; use crate::traits::GetSyncableTxnsAndProofError; diff --git a/core-rust/state-manager/src/store/rocks_db.rs b/core-rust/state-manager/src/store/rocks_db.rs index 6af65558f9..34563ab7b6 100644 --- a/core-rust/state-manager/src/store/rocks_db.rs +++ b/core-rust/state-manager/src/store/rocks_db.rs @@ -65,7 +65,7 @@ use std::collections::HashSet; use std::fmt; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::store::traits::*; use crate::{ CommittedTransactionIdentifiers, LedgerProof, LedgerProofOrigin, LedgerTransactionReceipt, diff --git a/core-rust/state-manager/src/store/traits.rs b/core-rust/state-manager/src/store/traits.rs index 2bdbcaa858..191a7d1e6c 100644 --- a/core-rust/state-manager/src/store/traits.rs +++ b/core-rust/state-manager/src/store/traits.rs @@ -65,7 +65,7 @@ use std::cmp::Ordering; use std::iter::Peekable; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use crate::staging::StateHashTreeDiff; use crate::store::StateManagerDatabase; use crate::transaction::*; diff --git a/core-rust/state-manager/src/store/typed_cf_api.rs b/core-rust/state-manager/src/store/typed_cf_api.rs index 5bcfc7ed93..70e0e0f42c 100644 --- a/core-rust/state-manager/src/store/typed_cf_api.rs +++ b/core-rust/state-manager/src/store/typed_cf_api.rs @@ -62,7 +62,7 @@ * permissions under this License. */ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use itertools::Itertools; use rocksdb::{ColumnFamily, Direction, IteratorMode, WriteBatch, DB}; use std::ops::Range; diff --git a/core-rust/state-manager/src/test/mod.rs b/core-rust/state-manager/src/test/mod.rs index e658b48f9a..de250c701e 100644 --- a/core-rust/state-manager/src/test/mod.rs +++ b/core-rust/state-manager/src/test/mod.rs @@ -1,5 +1,5 @@ +use crate::engine_prelude::*; use crate::query::TransactionIdentifierLoader; -use crate::scrypto_prelude::*; use crate::traits::QueryableProofStore; use crate::{ CommitRequest, CommitSummary, LedgerHeader, LedgerProof, LedgerProofOrigin, PrepareRequest, diff --git a/core-rust/state-manager/src/transaction/executable_logic.rs b/core-rust/state-manager/src/transaction/executable_logic.rs index a16eb255f5..663b23b571 100644 --- a/core-rust/state-manager/src/transaction/executable_logic.rs +++ b/core-rust/state-manager/src/transaction/executable_logic.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; // disambiguation needed because of a wide prelude use crate::LoggingConfig; diff --git a/core-rust/state-manager/src/transaction/ledger_transaction.rs b/core-rust/state-manager/src/transaction/ledger_transaction.rs index 3f80f4ca58..c0e4538d6b 100644 --- a/core-rust/state-manager/src/transaction/ledger_transaction.rs +++ b/core-rust/state-manager/src/transaction/ledger_transaction.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude use crate::transaction::{ConfigType, ConfiguredExecutable}; diff --git a/core-rust/state-manager/src/transaction/preview.rs b/core-rust/state-manager/src/transaction/preview.rs index 2d633dc121..b9ce02136f 100644 --- a/core-rust/state-manager/src/transaction/preview.rs +++ b/core-rust/state-manager/src/transaction/preview.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use node_common::locks::{RwLock, StateLock}; use std::ops::{Deref, Range}; use std::sync::Arc; @@ -126,7 +126,7 @@ impl Trans #[cfg(test)] mod tests { - use crate::scrypto_prelude::*; + use crate::engine_prelude::*; use crate::{PreviewRequest, StateManager, StateManagerConfig}; use node_common::locks::LockFactory; use node_common::scheduler::Scheduler; diff --git a/core-rust/state-manager/src/transaction/round_update_transaction.rs b/core-rust/state-manager/src/transaction/round_update_transaction.rs index 93131c4b64..369b1b5470 100644 --- a/core-rust/state-manager/src/transaction/round_update_transaction.rs +++ b/core-rust/state-manager/src/transaction/round_update_transaction.rs @@ -1,4 +1,4 @@ -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude use crate::{LedgerHeader, RoundHistory, ValidatorId}; diff --git a/core-rust/state-manager/src/transaction/series_execution.rs b/core-rust/state-manager/src/transaction/series_execution.rs index 420c9a29aa..3c54dcc18c 100644 --- a/core-rust/state-manager/src/transaction/series_execution.rs +++ b/core-rust/state-manager/src/transaction/series_execution.rs @@ -71,7 +71,7 @@ use crate::store::traits::*; use crate::transaction::*; use crate::*; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use node_common::locks::{Mutex, RwLock}; /// An internal delegate for executing a series of consecutive transactions while tracking their diff --git a/core-rust/state-manager/src/transaction/validation.rs b/core-rust/state-manager/src/transaction/validation.rs index 2da1ae833a..6ca0ef04e9 100644 --- a/core-rust/state-manager/src/transaction/validation.rs +++ b/core-rust/state-manager/src/transaction/validation.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use std::sync::Arc; use std::time::SystemTime; -use crate::scrypto_prelude::*; +use crate::engine_prelude::*; use ::transaction::model::PrepareError; // disambiguation needed because of a wide prelude use crate::query::StateManagerSubstateQueries; diff --git a/core-rust/state-manager/src/types.rs b/core-rust/state-manager/src/types.rs index e02e92614f..f334c5fbfa 100644 --- a/core-rust/state-manager/src/types.rs +++ b/core-rust/state-manager/src/types.rs @@ -63,8 +63,8 @@ */ use crate::accumulator_tree::IsMerklizableHash; +use crate::engine_prelude::*; use crate::protocol::ProtocolVersionName; -use crate::scrypto_prelude::*; use crate::transaction::*; use crate::{LedgerTransactionOutcome, PartitionChange, SubstateChange}; use std::fmt;