forked from Qortal/qortal
Temporary fix to Controller to only try to acquire blockchain for incoming new unconfirmed transactions
This commit is contained in:
parent
c03a5c3d0e
commit
680361daa6
@ -77,7 +77,7 @@ public class Controller extends Thread {
|
|||||||
private final long buildTimestamp; // seconds
|
private final long buildTimestamp; // seconds
|
||||||
|
|
||||||
/** Lock for only allowing one blockchain-modifying codepath at a time. e.g. synchronization or newly generated block. */
|
/** Lock for only allowing one blockchain-modifying codepath at a time. e.g. synchronization or newly generated block. */
|
||||||
private final ReentrantLock blockchainLock;
|
private final ReentrantLock blockchainLock = new ReentrantLock();;
|
||||||
|
|
||||||
private Controller() {
|
private Controller() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
@ -100,8 +100,6 @@ public class Controller extends Thread {
|
|||||||
|
|
||||||
this.buildVersion = VERSION_PREFIX + buildVersion;
|
this.buildVersion = VERSION_PREFIX + buildVersion;
|
||||||
LOGGER.info(String.format("Build version: %s", this.buildVersion));
|
LOGGER.info(String.format("Build version: %s", this.buildVersion));
|
||||||
|
|
||||||
blockchainLock = new ReentrantLock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Controller getInstance() {
|
public static Controller getInstance() {
|
||||||
@ -583,26 +581,26 @@ public class Controller extends Thread {
|
|||||||
|
|
||||||
// Blockchain lock required to prevent multiple threads trying to save the same transaction simultaneously
|
// Blockchain lock required to prevent multiple threads trying to save the same transaction simultaneously
|
||||||
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||||
blockchainLock.lock();
|
if (blockchainLock.tryLock())
|
||||||
try {
|
try {
|
||||||
// Do we have it already?
|
// Do we have it already?
|
||||||
if (repository.getTransactionRepository().exists(transactionData.getSignature())) {
|
if (repository.getTransactionRepository().exists(transactionData.getSignature())) {
|
||||||
LOGGER.trace(String.format("Ignoring existing TRANSACTION %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
|
LOGGER.trace(String.format("Ignoring existing TRANSACTION %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it valid?
|
// Is it valid?
|
||||||
ValidationResult validationResult = transaction.isValidUnconfirmed();
|
ValidationResult validationResult = transaction.isValidUnconfirmed();
|
||||||
if (validationResult != ValidationResult.OK) {
|
if (validationResult != ValidationResult.OK) {
|
||||||
LOGGER.trace(String.format("Ignoring invalid (%s) TRANSACTION %s from peer %s", validationResult.name(), Base58.encode(transactionData.getSignature()), peer));
|
LOGGER.trace(String.format("Ignoring invalid (%s) TRANSACTION %s from peer %s", validationResult.name(), Base58.encode(transactionData.getSignature()), peer));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seems ok - add to unconfirmed pile
|
// Seems ok - add to unconfirmed pile
|
||||||
transaction.importAsUnconfirmed();
|
transaction.importAsUnconfirmed();
|
||||||
} finally {
|
} finally {
|
||||||
blockchainLock.unlock();
|
blockchainLock.unlock();
|
||||||
}
|
}
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
LOGGER.error(String.format("Repository issue while processing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer), e);
|
LOGGER.error(String.format("Repository issue while processing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer), e);
|
||||||
}
|
}
|
||||||
@ -689,9 +687,6 @@ public class Controller extends Thread {
|
|||||||
// Remove peers that have "misbehaved" recently
|
// Remove peers that have "misbehaved" recently
|
||||||
peers.removeIf(hasPeerMisbehaved);
|
peers.removeIf(hasPeerMisbehaved);
|
||||||
|
|
||||||
for (Peer peer : peers)
|
|
||||||
LOGGER.debug(String.format("Not up to date due to peer %s at height %d with block sig %s", peer, peer.getPeerData().getLastHeight(), Base58.encode(peer.getPeerData().getLastBlockSignature())));
|
|
||||||
|
|
||||||
// If we have any peers left, then they would be candidates for synchronization therefore we're not up to date.
|
// If we have any peers left, then they would be candidates for synchronization therefore we're not up to date.
|
||||||
return peers.isEmpty();
|
return peers.isEmpty();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user