Skip to content

Commit

Permalink
Added maxTransactionsPerBlock setting (default 25) to reduce minting …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
archived-2 committed Jul 31, 2023
1 parent f7e1f2f commit f5c8dfe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public default List<TransactionData> getUnconfirmedTransactions() throws DataExc
* @return list of transactions, or empty if none.
* @throws DataException
*/
public List<TransactionData> getUnconfirmedTransactions(EnumSet<TransactionType> excludedTxTypes) throws DataException;
public List<TransactionData> getUnconfirmedTransactions(EnumSet<TransactionType> excludedTxTypes, Integer limit) throws DataException;

/**
* Remove transaction from unconfirmed transactions pile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,10 @@ public List<TransactionData> getUnconfirmedTransactions(TransactionType txType,
}

@Override
public List<TransactionData> getUnconfirmedTransactions(EnumSet<TransactionType> excludedTxTypes) throws DataException {
public List<TransactionData> getUnconfirmedTransactions(EnumSet<TransactionType> excludedTxTypes, Integer limit) throws DataException {
StringBuilder sql = new StringBuilder(1024);
List<Object> bindParams = new ArrayList<>();

sql.append("SELECT signature FROM UnconfirmedTransactions ");
sql.append("JOIN Transactions USING (signature) ");
sql.append("WHERE type NOT IN (");
Expand All @@ -1446,12 +1448,17 @@ public List<TransactionData> getUnconfirmedTransactions(EnumSet<TransactionType>
}

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<TransactionData> 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;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/qortal/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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). */
Expand Down Expand Up @@ -693,6 +696,10 @@ public int getBlockCacheSize() {
return this.blockCacheSize;
}

public int getMaxTransactionsPerBlock() {
return this.maxTransactionsPerBlock;
}

public boolean isTestNet() {
return this.isTestNet;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/qortal/transaction/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ public static List<TransactionData> getUnconfirmedTransactions(Repository reposi
BlockData latestBlockData = repository.getBlockRepository().getLastBlock();

EnumSet<TransactionType> excludedTxTypes = EnumSet.of(TransactionType.CHAT, TransactionType.PRESENCE);
List<TransactionData> unconfirmedTransactions = repository.getTransactionRepository().getUnconfirmedTransactions(excludedTxTypes);
int limit = Settings.getInstance().getMaxTransactionsPerBlock();
List<TransactionData> unconfirmedTransactions = repository.getTransactionRepository().getUnconfirmedTransactions(excludedTxTypes, limit);

unconfirmedTransactions.sort(getDataComparator());

Expand Down

0 comments on commit f5c8dfe

Please sign in to comment.