From f5c8dfe7661a97cf4585af0c9aa56c26542d0038 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Mon, 31 Jul 2023 19:25:26 +0100 Subject: [PATCH 1/2] Added maxTransactionsPerBlock setting (default 25) to reduce minting load on slower machines. This is a short term limit, is well above current usage levels, and can be increased substantially in future once the block minter code has been improved. --- .../qortal/repository/TransactionRepository.java | 2 +- .../transaction/HSQLDBTransactionRepository.java | 13 ++++++++++--- src/main/java/org/qortal/settings/Settings.java | 7 +++++++ .../java/org/qortal/transaction/Transaction.java | 3 ++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/qortal/repository/TransactionRepository.java b/src/main/java/org/qortal/repository/TransactionRepository.java index 6cc88290..41986cad 100644 --- a/src/main/java/org/qortal/repository/TransactionRepository.java +++ b/src/main/java/org/qortal/repository/TransactionRepository.java @@ -314,7 +314,7 @@ public interface TransactionRepository { * @return list of transactions, or empty if none. * @throws DataException */ - public List getUnconfirmedTransactions(EnumSet excludedTxTypes) throws DataException; + public List getUnconfirmedTransactions(EnumSet excludedTxTypes, Integer limit) throws DataException; /** * Remove transaction from unconfirmed transactions pile. diff --git a/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBTransactionRepository.java b/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBTransactionRepository.java index 740b3e65..60b4e803 100644 --- a/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBTransactionRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/transaction/HSQLDBTransactionRepository.java @@ -1429,8 +1429,10 @@ public class HSQLDBTransactionRepository implements TransactionRepository { } @Override - public List getUnconfirmedTransactions(EnumSet excludedTxTypes) throws DataException { + public List getUnconfirmedTransactions(EnumSet excludedTxTypes, Integer limit) throws DataException { StringBuilder sql = new StringBuilder(1024); + List bindParams = new ArrayList<>(); + sql.append("SELECT signature FROM UnconfirmedTransactions "); sql.append("JOIN Transactions USING (signature) "); sql.append("WHERE type NOT IN ("); @@ -1446,12 +1448,17 @@ public class HSQLDBTransactionRepository implements TransactionRepository { } sql.append(")"); - sql.append("ORDER BY created_when, signature"); + sql.append("ORDER BY created_when, signature "); + + if (limit != null) { + sql.append("LIMIT ?"); + bindParams.add(limit); + } List transactions = new ArrayList<>(); // Find transactions with no corresponding row in BlockTransactions - try (ResultSet resultSet = this.repository.checkedExecute(sql.toString())) { + try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), bindParams.toArray())) { if (resultSet == null) return transactions; diff --git a/src/main/java/org/qortal/settings/Settings.java b/src/main/java/org/qortal/settings/Settings.java index c3d5a0c8..ac9b8857 100644 --- a/src/main/java/org/qortal/settings/Settings.java +++ b/src/main/java/org/qortal/settings/Settings.java @@ -146,6 +146,9 @@ public class Settings { /* How many blocks to cache locally. Defaulted to 10, which covers a typical Synchronizer request + a few spare */ private int blockCacheSize = 10; + /** Maximum number of transactions for the block minter to include in a block */ + private int maxTransactionsPerBlock = 25; + /** How long to keep old, full, AT state data (ms). */ private long atStatesMaxLifetime = 5 * 24 * 60 * 60 * 1000L; // milliseconds /** How often to attempt AT state trimming (ms). */ @@ -693,6 +696,10 @@ public class Settings { return this.blockCacheSize; } + public int getMaxTransactionsPerBlock() { + return this.maxTransactionsPerBlock; + } + public boolean isTestNet() { return this.isTestNet; } diff --git a/src/main/java/org/qortal/transaction/Transaction.java b/src/main/java/org/qortal/transaction/Transaction.java index f0e9b3f6..10834a06 100644 --- a/src/main/java/org/qortal/transaction/Transaction.java +++ b/src/main/java/org/qortal/transaction/Transaction.java @@ -641,7 +641,8 @@ public abstract class Transaction { BlockData latestBlockData = repository.getBlockRepository().getLastBlock(); EnumSet excludedTxTypes = EnumSet.of(TransactionType.CHAT, TransactionType.PRESENCE); - List unconfirmedTransactions = repository.getTransactionRepository().getUnconfirmedTransactions(excludedTxTypes); + int limit = Settings.getInstance().getMaxTransactionsPerBlock(); + List unconfirmedTransactions = repository.getTransactionRepository().getUnconfirmedTransactions(excludedTxTypes, limit); unconfirmedTransactions.sort(getDataComparator()); From 94d3664cb092877f8348bea1d6342dbe5a95993d Mon Sep 17 00:00:00 2001 From: CalDescent Date: Mon, 31 Jul 2023 19:30:45 +0100 Subject: [PATCH 2/2] Bump version to 4.2.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f236761e..1a046758 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.qortal qortal - 4.2.0 + 4.2.1 jar true