The transaction sequences reshape now fetches transactions from the archive.

This is required as it's the only place that holds the original order of each block's transactions. We cannot sort them, because the comparator function for transactions has some dependencies on the existing order for AT transactions. As a result, topOnly nodes cannot perform this reshape, and will be unable to run this version.
This commit is contained in:
CalDescent 2023-03-10 21:29:35 +00:00
parent b89a35ac69
commit bc44b998dc

View File

@ -2,9 +2,12 @@ package org.qortal.repository;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.qortal.block.Block;
import org.qortal.data.block.BlockData;
import org.qortal.data.transaction.TransactionData; import org.qortal.data.transaction.TransactionData;
import org.qortal.settings.Settings; import org.qortal.settings.Settings;
import org.qortal.transaction.Transaction; import org.qortal.transaction.Transaction;
import org.qortal.transform.block.BlockTransformation;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -66,6 +69,10 @@ public abstract class RepositoryManager {
// Lite nodes have no blockchain // Lite nodes have no blockchain
return false; return false;
} }
if (Settings.getInstance().isTopOnly()) {
// topOnly nodes are unable to perform this reindex, and so are temporarily unsupported
throw new DataException("topOnly nodes are now unsupported, as they are missing data required for a db reshape");
}
try { try {
// Check if we have any unpopulated block_sequence values for the first 1000 blocks // Check if we have any unpopulated block_sequence values for the first 1000 blocks
@ -78,24 +85,30 @@ public abstract class RepositoryManager {
return false; return false;
} }
LOGGER.info("Rebuilding transaction sequences - this will take a while...");
int blockchainHeight = repository.getBlockRepository().getBlockchainHeight(); int blockchainHeight = repository.getBlockRepository().getBlockchainHeight();
int totalTransactionCount = 0; int totalTransactionCount = 0;
for (int height = 1; height < blockchainHeight; height++) { for (int height = 1; height < blockchainHeight; height++) {
List<TransactionData> transactions = new ArrayList<>(); List<TransactionData> transactions = new ArrayList<>();
// Fetch transactions for height // Fetch block and transactions
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, height, height); BlockData blockData = repository.getBlockRepository().fromHeight(height);
for (byte[] signature : signatures) { if (blockData == null) {
TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature); // Try the archive
if (transactionData != null) { BlockTransformation blockTransformation = BlockArchiveReader.getInstance().fetchBlockAtHeight(height);
transactions.add(transactionData); transactions = blockTransformation.getTransactions();
}
else {
// Get transactions from db
Block block = new Block(repository, blockData);
for (Transaction transaction : block.getTransactions()) {
transactions.add(transaction.getTransactionData());
} }
} }
totalTransactionCount += transactions.size();
// Sort the transactions for this height totalTransactionCount += transactions.size();
transactions.sort(Transaction.getDataComparator());
// Loop through and update sequences // Loop through and update sequences
for (int sequence = 0; sequence < transactions.size(); ++sequence) { for (int sequence = 0; sequence < transactions.size(); ++sequence) {