aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ringct/rctSigs.cpp136
1 files changed, 119 insertions, 17 deletions
diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp
index 71aec558b..f7ea3729d 100644
--- a/src/ringct/rctSigs.cpp
+++ b/src/ringct/rctSigs.cpp
@@ -28,14 +28,26 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include <boost/asio.hpp>
#include "misc_log_ex.h"
#include "common/perf_timer.h"
+#include "common/util.h"
#include "rctSigs.h"
#include "cryptonote_core/cryptonote_format_utils.h"
using namespace crypto;
using namespace std;
+#define KILL_IOSERVICE() \
+ if(ioservice_active) \
+ { \
+ work.reset(); \
+ while (!ioservice.stopped()) ioservice.poll(); \
+ threadpool.join_all(); \
+ ioservice.stop(); \
+ ioservice_active = false; \
+ }
+
namespace rct {
//Schnorr Non-linkable
@@ -348,6 +360,10 @@ namespace rct {
return true;
}
+ void verRangeWrapper(const key & C, const rangeSig & as, bool &result) {
+ result = verRange(C, as);
+ }
+
key get_pre_mlsag_hash(const rctSig &rv)
{
keyV hashes;
@@ -528,6 +544,10 @@ namespace rct {
return MLSAG_Ver(message, M, mg, rows);
}
+ void verRctMGSimpleWrapper(const key &message, const mgSig &mg, const ctkeyV & pubs, const key & C, bool &result) {
+ result = verRctMGSimple(message, mg, pubs, C);
+ }
+
//These functions get keys from blockchain
//replace these when connecting blockchain
//getKeyFromBlockchain grabs a key from the blockchain at "reference_index" to mix with
@@ -745,17 +765,41 @@ namespace rct {
// some rct ops can throw
try
{
- size_t i = 0;
- bool tmp;
+ boost::asio::io_service ioservice;
+ boost::thread_group threadpool;
+ std::unique_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ioservice));
+ size_t threads = tools::get_max_concurrency();
+ threads = std::min(threads, rv.outPk.size());
+ for (size_t i = 0; i < threads; ++i)
+ threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioservice));
+ bool ioservice_active = threads > 1;
+ std::deque<bool> results(rv.outPk.size(), false);
+ epee::misc_utils::auto_scope_leave_caller ioservice_killer = epee::misc_utils::create_scope_leave_handler([&]() { KILL_IOSERVICE(); });
+
DP("range proofs verified?");
- for (i = 0; i < rv.outPk.size(); i++) {
- tmp = verRange(rv.outPk[i].mask, rv.p.rangeSigs[i]);
- DP(tmp);
- if (!tmp) {
- LOG_ERROR("Range proof verification failed for input " << i);
+ for (size_t i = 0; i < rv.outPk.size(); i++) {
+ if (threads > 1) {
+ ioservice.dispatch(boost::bind(&verRangeWrapper, std::cref(rv.outPk[i].mask), std::cref(rv.p.rangeSigs[i]), std::ref(results[i])));
+ }
+ else {
+ bool tmp = verRange(rv.outPk[i].mask, rv.p.rangeSigs[i]);
+ DP(tmp);
+ if (!tmp) {
+ LOG_ERROR("Range proof verification failed for input " << i);
+ return false;
+ }
+ }
+ }
+ KILL_IOSERVICE();
+ if (threads > 1) {
+ for (size_t i = 0; i < rv.outPk.size(); ++i) {
+ if (!results[i]) {
+ LOG_ERROR("Range proof verified failed for input " << i);
return false;
}
+ }
}
+
//compute txn fee
key txnFeeKey = scalarmultH(d2h(rv.txnFee));
bool mgVerd = verRctMG(rv.p.MGs[0], rv.mixRing, rv.outPk, txnFeeKey, get_pre_mlsag_hash(rv));
@@ -786,29 +830,87 @@ namespace rct {
CHECK_AND_ASSERT_MES(rv.pseudoOuts.size() == rv.p.MGs.size(), false, "Mismatched sizes of rv.pseudoOuts and rv.p.MGs");
CHECK_AND_ASSERT_MES(rv.pseudoOuts.size() == rv.mixRing.size(), false, "Mismatched sizes of rv.pseudoOuts and mixRing");
- key sumOutpks = identity();
- for (i = 0; i < rv.outPk.size(); i++) {
- if (!verRange(rv.outPk[i].mask, rv.p.rangeSigs[i])) {
+ {
+ boost::asio::io_service ioservice;
+ boost::thread_group threadpool;
+ std::unique_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ioservice));
+ size_t threads = tools::get_max_concurrency();
+ threads = std::min(threads, rv.outPk.size());
+ for (size_t i = 0; i < threads; ++i)
+ threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioservice));
+ bool ioservice_active = threads > 1;
+ std::deque<bool> results(rv.outPk.size(), false);
+ epee::misc_utils::auto_scope_leave_caller ioservice_killer = epee::misc_utils::create_scope_leave_handler([&]() { KILL_IOSERVICE(); });
+
+ for (i = 0; i < rv.outPk.size(); i++) {
+ if (threads > 1) {
+ ioservice.dispatch(boost::bind(&verRangeWrapper, std::cref(rv.outPk[i].mask), std::cref(rv.p.rangeSigs[i]), std::ref(results[i])));
+ }
+ else if (!verRange(rv.outPk[i].mask, rv.p.rangeSigs[i])) {
LOG_ERROR("Range proof verified failed for input " << i);
return false;
}
+ }
+ KILL_IOSERVICE();
+ if (threads > 1) {
+ for (size_t i = 0; i < rv.outPk.size(); ++i) {
+ if (!results[i]) {
+ LOG_ERROR("Range proof verified failed for input " << i);
+ return false;
+ }
+ }
+ }
+ }
+
+ key sumOutpks = identity();
+ for (i = 0; i < rv.outPk.size(); i++) {
addKeys(sumOutpks, sumOutpks, rv.outPk[i].mask);
}
DP(sumOutpks);
key txnFeeKey = scalarmultH(d2h(rv.txnFee));
addKeys(sumOutpks, txnFeeKey, sumOutpks);
- bool tmpb = false;
key message = get_pre_mlsag_hash(rv);
- key sumPseudoOuts = identity();
- for (i = 0 ; i < rv.mixRing.size() ; i++) {
- tmpb = verRctMGSimple(message, rv.p.MGs[i], rv.mixRing[i], rv.pseudoOuts[i]);
- addKeys(sumPseudoOuts, sumPseudoOuts, rv.pseudoOuts[i]);
- DP(tmpb);
- if (!tmpb) {
+
+ {
+ boost::asio::io_service ioservice;
+ boost::thread_group threadpool;
+ std::unique_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ioservice));
+ size_t threads = tools::get_max_concurrency();
+ threads = std::min(threads, rv.mixRing.size());
+ for (size_t i = 0; i < threads; ++i)
+ threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioservice));
+ bool ioservice_active = threads > 1;
+ std::deque<bool> results(rv.mixRing.size(), false);
+ epee::misc_utils::auto_scope_leave_caller ioservice_killer = epee::misc_utils::create_scope_leave_handler([&]() { KILL_IOSERVICE(); });
+
+ for (i = 0 ; i < rv.mixRing.size() ; i++) {
+ if (threads > 1) {
+ ioservice.dispatch(boost::bind(&verRctMGSimpleWrapper, std::cref(message), std::cref(rv.p.MGs[i]), std::cref(rv.mixRing[i]), std::cref(rv.pseudoOuts[i]), std::ref(results[i])));
+ }
+ else {
+ bool tmpb = verRctMGSimple(message, rv.p.MGs[i], rv.mixRing[i], rv.pseudoOuts[i]);
+ DP(tmpb);
+ if (!tmpb) {
+ LOG_ERROR("verRctMGSimple failed for input " << i);
+ return false;
+ }
+ }
+ }
+ KILL_IOSERVICE();
+ if (threads > 1) {
+ for (size_t i = 0; i < results.size(); ++i) {
+ if (!results[i]) {
LOG_ERROR("verRctMGSimple failed for input " << i);
return false;
+ }
}
+ }
+ }
+
+ key sumPseudoOuts = identity();
+ for (i = 0 ; i < rv.mixRing.size() ; i++) {
+ addKeys(sumPseudoOuts, sumPseudoOuts, rv.pseudoOuts[i]);
}
DP(sumPseudoOuts);