|
|
|
@@ -356,13 +356,13 @@ public class Controller extends Thread {
|
|
|
|
|
case NO_BLOCKCHAIN_LOCK:
|
|
|
|
|
case REPOSITORY_ISSUE:
|
|
|
|
|
// These are minor failure results so fine to try again
|
|
|
|
|
LOGGER.info(String.format("Failed to synchronize with peer %s (%s)", peer, syncResult.name()));
|
|
|
|
|
LOGGER.debug(() -> String.format("Failed to synchronize with peer %s (%s)", peer, syncResult.name()));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OK:
|
|
|
|
|
updateSysTray();
|
|
|
|
|
case NOTHING_TO_DO:
|
|
|
|
|
LOGGER.debug(String.format("Synchronized with peer %s (%s)", peer, syncResult.name()));
|
|
|
|
|
LOGGER.debug(() -> String.format("Synchronized with peer %s (%s)", peer, syncResult.name()));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -510,7 +510,7 @@ public class Controller extends Thread {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onNetworkMessage(Peer peer, Message message) {
|
|
|
|
|
LOGGER.trace(String.format("Processing %s message from %s", message.getType().name(), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Processing %s message from %s", message.getType().name(), peer));
|
|
|
|
|
|
|
|
|
|
switch (message.getType()) {
|
|
|
|
|
case HEIGHT: {
|
|
|
|
@@ -624,7 +624,7 @@ public class Controller extends Thread {
|
|
|
|
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
|
|
|
|
BlockData blockData = repository.getBlockRepository().fromSignature(signature);
|
|
|
|
|
if (blockData == null) {
|
|
|
|
|
LOGGER.debug(String.format("Ignoring GET_BLOCK request from peer %s for unknown block %s", peer, Base58.encode(signature)));
|
|
|
|
|
LOGGER.debug(() -> String.format("Ignoring GET_BLOCK request from peer %s for unknown block %s", peer, Base58.encode(signature)));
|
|
|
|
|
// Send no response at all???
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@@ -649,7 +649,7 @@ public class Controller extends Thread {
|
|
|
|
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
|
|
|
|
TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature);
|
|
|
|
|
if (transactionData == null) {
|
|
|
|
|
LOGGER.debug(String.format("Ignoring GET_TRANSACTION request from peer %s for unknown transaction %s", peer, Base58.encode(signature)));
|
|
|
|
|
LOGGER.debug(() -> String.format("Ignoring GET_TRANSACTION request from peer %s for unknown transaction %s", peer, Base58.encode(signature)));
|
|
|
|
|
// Send no response at all???
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@@ -674,28 +674,28 @@ public class Controller extends Thread {
|
|
|
|
|
|
|
|
|
|
// Check signature
|
|
|
|
|
if (!transaction.isSignatureValid()) {
|
|
|
|
|
LOGGER.trace(String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValidationResult validationResult = transaction.importAsUnconfirmed();
|
|
|
|
|
|
|
|
|
|
if (validationResult == ValidationResult.TRANSACTION_ALREADY_EXISTS) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (validationResult == ValidationResult.NO_BLOCKCHAIN_LOCK) {
|
|
|
|
|
LOGGER.trace(String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (validationResult != ValidationResult.OK) {
|
|
|
|
|
LOGGER.trace(String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGGER.debug(String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.debug(() -> String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
} catch (DataException e) {
|
|
|
|
|
LOGGER.error(String.format("Repository issue while processing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer), e);
|
|
|
|
|
}
|
|
|
|
@@ -725,7 +725,7 @@ public class Controller extends Thread {
|
|
|
|
|
for (byte[] signature : signatures) {
|
|
|
|
|
// Do we have it already? (Before requesting transaction data itself)
|
|
|
|
|
if (repository.getTransactionRepository().exists(signature)) {
|
|
|
|
|
LOGGER.trace(String.format("Ignoring existing transaction %s from peer %s", Base58.encode(signature), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Ignoring existing transaction %s from peer %s", Base58.encode(signature), peer));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -738,7 +738,7 @@ public class Controller extends Thread {
|
|
|
|
|
Message responseMessage = peer.getResponse(getTransactionMessage);
|
|
|
|
|
if (responseMessage == null || !(responseMessage instanceof TransactionMessage)) {
|
|
|
|
|
// Maybe peer no longer has this transaction
|
|
|
|
|
LOGGER.trace(String.format("Peer %s didn't send transaction %s", peer, Base58.encode(signature)));
|
|
|
|
|
LOGGER.trace(() -> String.format("Peer %s didn't send transaction %s", peer, Base58.encode(signature)));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -752,29 +752,29 @@ public class Controller extends Thread {
|
|
|
|
|
|
|
|
|
|
// Check signature
|
|
|
|
|
if (!transaction.isSignatureValid()) {
|
|
|
|
|
LOGGER.trace(String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValidationResult validationResult = transaction.importAsUnconfirmed();
|
|
|
|
|
|
|
|
|
|
if (validationResult == ValidationResult.TRANSACTION_ALREADY_EXISTS) {
|
|
|
|
|
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));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (validationResult == ValidationResult.NO_BLOCKCHAIN_LOCK) {
|
|
|
|
|
LOGGER.trace(String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
// Some other thread (e.g. Synchronizer) might have blockchain lock for a while so might as well give up for now
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (validationResult != ValidationResult.OK) {
|
|
|
|
|
LOGGER.trace(String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.trace(() -> String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGGER.debug(String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
LOGGER.debug(() -> String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
|
|
|
|
|
|
|
|
|
|
// We could collate signatures that are new to us and broadcast them to our peers too
|
|
|
|
|
newSignatures.add(signature);
|
|
|
|
|