mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 23:03:04 +00:00
Add a few basic sanity checks on transactions received from the network at various points, to avoid syntactically invalid transactions from getting into the system (e.g. no inputs or outputs).
This commit is contained in:
parent
21ba7e0260
commit
d14ac586d7
@ -448,6 +448,8 @@ public class Peer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void processTransaction(Transaction tx) throws VerificationException, IOException {
|
private void processTransaction(Transaction tx) throws VerificationException, IOException {
|
||||||
|
// Check a few basic syntax issues to ensure the received TX isn't nonsense.
|
||||||
|
tx.verify();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
log.debug("{}: Received tx {}", vAddress, tx.getHashAsString());
|
log.debug("{}: Received tx {}", vAddress, tx.getHashAsString());
|
||||||
|
@ -883,6 +883,7 @@ public class Wallet implements Serializable, BlockChainListener {
|
|||||||
// Do a brief risk analysis of the transaction and its dependencies to check for any possible attacks.
|
// Do a brief risk analysis of the transaction and its dependencies to check for any possible attacks.
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
tx.verify();
|
||||||
// Repeat the check of relevancy here, even though the caller may have already done so - this is to avoid
|
// Repeat the check of relevancy here, even though the caller may have already done so - this is to avoid
|
||||||
// race conditions where receivePending may be being called in parallel.
|
// race conditions where receivePending may be being called in parallel.
|
||||||
if (!isPendingTransactionRelevant(tx))
|
if (!isPendingTransactionRelevant(tx))
|
||||||
@ -1440,6 +1441,7 @@ public class Wallet implements Serializable, BlockChainListener {
|
|||||||
* <p>Triggers an auto save.</p>
|
* <p>Triggers an auto save.</p>
|
||||||
*/
|
*/
|
||||||
public void commitTx(Transaction tx) throws VerificationException {
|
public void commitTx(Transaction tx) throws VerificationException {
|
||||||
|
tx.verify();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
checkArgument(!pending.containsKey(tx.getHash()), "commitTx called on the same transaction twice");
|
checkArgument(!pending.containsKey(tx.getHash()), "commitTx called on the same transaction twice");
|
||||||
|
@ -786,9 +786,12 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
connect();
|
connect();
|
||||||
Transaction t1 = new Transaction(unitTestParams);
|
Transaction t1 = new Transaction(unitTestParams);
|
||||||
t1.addInput(new TransactionInput(unitTestParams, t1, new byte[]{}));
|
t1.addInput(new TransactionInput(unitTestParams, t1, new byte[]{}));
|
||||||
t1.addOutput(Utils.toNanoCoins(1, 0), wallet.getChangeAddress());
|
t1.addOutput(Utils.toNanoCoins(1, 0), new ECKey().toAddress(unitTestParams));
|
||||||
inbound(peer, t1);
|
Transaction t2 = new Transaction(unitTestParams);
|
||||||
inbound(peer, new NotFoundMessage(unitTestParams, Lists.newArrayList(new InventoryItem(InventoryItem.Type.Transaction, t1.getInput(0).getHash()))));
|
t2.addInput(t1.getOutput(0));
|
||||||
|
t2.addOutput(Utils.toNanoCoins(1, 0), wallet.getChangeAddress());
|
||||||
|
inbound(peer, t2);
|
||||||
|
inbound(peer, new NotFoundMessage(unitTestParams, Lists.newArrayList(new InventoryItem(InventoryItem.Type.Transaction, t2.getInput(0).getHash()))));
|
||||||
assertTrue(throwables[0] instanceof NullPointerException);
|
assertTrue(throwables[0] instanceof NullPointerException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user