diff --git a/src/main/java/org/qortal/api/resource/TransactionsResource.java b/src/main/java/org/qortal/api/resource/TransactionsResource.java index bdd7dbd0..585dac0b 100644 --- a/src/main/java/org/qortal/api/resource/TransactionsResource.java +++ b/src/main/java/org/qortal/api/resource/TransactionsResource.java @@ -539,6 +539,8 @@ public class TransactionsResource { } finally { blockchainLock.unlock(); } + + return "true"; } catch (NumberFormatException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_DATA, e); } catch (DataException e) { @@ -546,11 +548,6 @@ public class TransactionsResource { } catch (InterruptedException e) { throw createTransactionInvalidException(request, ValidationResult.NO_BLOCKCHAIN_LOCK); } - - // Notify controller of new transaction - Controller.getInstance().onNewTransaction(transactionData, null); - - return "true"; } @POST diff --git a/src/main/java/org/qortal/controller/Controller.java b/src/main/java/org/qortal/controller/Controller.java index 4a1b3b55..08a1e6a8 100644 --- a/src/main/java/org/qortal/controller/Controller.java +++ b/src/main/java/org/qortal/controller/Controller.java @@ -1048,11 +1048,16 @@ public class Controller extends Thread { } } - /** Callback for when we've received a new transaction via API or peer. */ - public void onNewTransaction(TransactionData transactionData, Peer peer) { + /** + * Callback for when we've received a new transaction via API or peer. + *
+ * @implSpec performs actions in a new thread + */ + public void onNewTransaction(TransactionData transactionData) { this.callbackExecutor.execute(() -> { - // Notify all peers (except maybe peer that sent it to us if applicable) - Network.getInstance().broadcast(broadcastPeer -> broadcastPeer == peer ? null : new TransactionSignaturesMessage(Arrays.asList(transactionData.getSignature()))); + // Notify all peers + Message newTransactionSignatureMessage = new TransactionSignaturesMessage(Arrays.asList(transactionData.getSignature())); + Network.getInstance().broadcast(broadcastPeer -> newTransactionSignatureMessage); // Notify listeners EventBus.INSTANCE.notify(new NewTransactionEvent(transactionData)); @@ -1234,9 +1239,6 @@ public class Controller extends Thread { } catch (DataException e) { LOGGER.error(String.format("Repository issue while processing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer), e); } - - // Notify controller so it can notify other peers, etc. - Controller.getInstance().onNewTransaction(transactionData, peer); } private void onNetworkGetBlockSummariesMessage(Peer peer, Message message) { diff --git a/src/main/java/org/qortal/transaction/Transaction.java b/src/main/java/org/qortal/transaction/Transaction.java index 3b57e520..80c064a2 100644 --- a/src/main/java/org/qortal/transaction/Transaction.java +++ b/src/main/java/org/qortal/transaction/Transaction.java @@ -765,7 +765,13 @@ public abstract class Transaction { /** * Import into our repository as a new, unconfirmed transaction. *
- * Calls repository.saveChanges() + * @implSpec tries to obtain blockchain lock + *
+ * If transaction is valid, then: + *