Skip to content

Commit

Permalink
Merge pull request stratisproject#254 from codingupastorm/fix-throw
Browse files Browse the repository at this point in the history
Throw exceptions in mempool rules
  • Loading branch information
codingupastorm authored Mar 9, 2020
2 parents 14c66b6 + 5887af3 commit 3374ff1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public override void CheckTransaction(MempoolValidationContext context)

// We also need to check that the sender given is indeed the one who signed the transaction.
if (!this.tokenlessSigner.Verify(context.Transaction))
context.State.Fail(new MempoolError(MempoolErrors.RejectInvalid, $"The signature for transaction {context.Transaction.GetHash()} is invalid."));
context.State.Fail(new MempoolError(MempoolErrors.RejectInvalid, $"The signature for transaction {context.Transaction.GetHash()} is invalid.")).Throw();

// Now that we have the sender address, lets get their certificate and check they have necessary permissions.
if (!this.certificatePermissionsChecker.CheckSenderCertificateHasPermission(getSenderResult.Sender, TransactionSendingPermission.Send))
context.State.Fail(new MempoolError(MempoolErrors.RejectInvalid, "The sender of this transaction is not authorised by the CA to send transactions."));
context.State.Fail(new MempoolError(MempoolErrors.RejectInvalid, "The sender of this transaction is not authorised by the CA to send transactions.")).Throw();

// Not a smart contract, no further validation to do.
if (!context.Transaction.IsSmartContractExecTransaction())
Expand All @@ -54,7 +54,7 @@ public override void CheckTransaction(MempoolValidationContext context)
: TransactionSendingPermission.CallContract;

if (!this.certificatePermissionsChecker.CheckSenderCertificateHasPermission(getSenderResult.Sender, permission))
context.State.Fail(new MempoolError(MempoolErrors.RejectInvalid, $"The sender of this transaction does not have the {permission.ToString()} permission."));
context.State.Fail(new MempoolError(MempoolErrors.RejectInvalid, $"The sender of this transaction does not have the {permission.ToString()} permission.")).Throw();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CertificateAuthority;
using CertificateAuthority.Models;
Expand Down Expand Up @@ -169,8 +170,9 @@ public async Task TokenlessNodesFunctionIfCATurnsOffAsync()
// Node1 should still let it in the mempool as it's from himself.
TestBase.WaitLoop(() => node1.FullNode.MempoolManager().GetMempoolAsync().Result.Count > 0);

// Node2 won't be able to get the certificate so will decline the transaction but still work.
TestBase.WaitLoop(() => node2.FullNode.MempoolManager().GetMempoolAsync().Result.Count > 0);
// Node2 won't be able to get the certificate so will decline the transaction.
Thread.Sleep(2000);
Assert.Empty(node2.FullNode.MempoolManager().GetMempoolAsync().Result);

// First node mines a block so the transaction is in a block, which the other guy then also trusts.
await node1.MineBlocksAsync(1);
Expand Down

0 comments on commit 3374ff1

Please sign in to comment.