{"action":"created","comment":{"url":"https://api.github.com/repos/ripple/rippled/pulls/comments/31536738","id":31536738,"diff_hunk":"@@ -964,112 +1020,227 @@ Transaction::pointer NetworkOPsImp::processTransactionCb (\n         // signature not checked\n         std::string reason;\n \n-        if (! trans->checkSign (reason))\n+        if (! transaction->checkSign (reason))\n         {\n             m_journal.info << \"Transaction has bad signature: \" << reason;\n-            trans->setStatus (INVALID);\n-            trans->setResult (temBAD_SIGNATURE);\n-            getApp().getHashRouter ().setFlag (trans->getID (), SF_BAD);\n-            return trans;\n+            transaction->setStatus (INVALID);\n+            transaction->setResult (temBAD_SIGNATURE);\n+            getApp().getHashRouter ().setFlag (transaction->getID (), SF_BAD);\n+            return;\n         }\n+    }\n+\n+    getApp().getHashRouter ().setFlag (transaction->getID (), SF_SIGGOOD);\n+\n+    if (bLocal)\n+        doTransactionSync (transaction, bAdmin, failType);\n+    else\n+        doTransactionAsync (transaction, bAdmin, failType);\n+}\n+\n+void NetworkOPsImp::doTransactionAsync (Transaction::pointer transaction,\n+        bool bAdmin, FailHard failType)\n+{\n+    std::lock_guard<std::mutex> lock (mMutex);\n \n-        getApp().getHashRouter ().setFlag (trans->getID (), SF_SIGGOOD);\n+    mTransactions.push_back (TransactionStatus (transaction, bAdmin, false,\n+        failType));\n+\n+    if (mDispatchState == DispatchState::none)\n+    {\n+        m_job_queue.addJob (jtBATCH, \"transactionBatch\",\n+                std::bind (&NetworkOPsImp::transactionBatch, this));\n+        mDispatchState = DispatchState::scheduled;\n     }\n+}\n+\n+void NetworkOPsImp::doTransactionSync (Transaction::pointer transaction,\n+        bool bAdmin, FailHard failType)\n+{\n+    std::unique_lock<std::mutex> lock (mMutex);\n \n+    mTransactions.push_back (TransactionStatus (transaction, bAdmin, true,\n+        failType));\n+\n+    do\n     {\n-        auto lock = beast::make_lock(getApp().getMasterMutex());\n+        if (mDispatchState == DispatchState::running)\n+        {\n+            // A batch processing job is already running, so wait.\n+            mCond.wait (lock);\n+        }\n+        else\n+        {\n+            std::vector<TransactionStatus> transactions;\n \n-        bool didApply;\n-        TER r = m_ledgerMaster.doTransaction (\n-            trans->getSTransaction (),\n-            bAdmin ? (tapOPEN_LEDGER | tapNO_CHECK_SIGN | tapADMIN)\n-            : (tapOPEN_LEDGER | tapNO_CHECK_SIGN), didApply);\n-        trans->setResult (r);\n+            mTransactions.swap (transactions);\n+            mDispatchState = DispatchState::running;\n+            lock.unlock();\n+            apply (transactions);\n+            lock.lock();\n+            mDispatchState = DispatchState::none;\n+            mCond.notify_all();\n \n-        if (isTemMalformed (r)) // malformed, cache bad\n-            getApp().getHashRouter ().setFlag (trans->getID (), SF_BAD);\n+            if (mTransactions.size())\n+            {\n+                // More transactions need to be applied, but by another job.\n+                m_job_queue.addJob (jtBATCH, \"transactionBatch\",\n+                        std::bind (&NetworkOPsImp::transactionBatch, this));\n+                mDispatchState = DispatchState::scheduled;\n+            }\n+        }\n+    }\n+    while (! transaction->getClearBatched());\n+}\n+\n+void NetworkOPsImp::transactionBatch()\n+{\n+    std::unique_lock<std::mutex> lock (mMutex);\n+\n+    if (mDispatchState == DispatchState::running)\n+        return;\n+\n+    mDispatchState = DispatchState::running;\n+\n+    while (mTransactions.size())\n+    {\n+        std::vector<TransactionStatus> transactions;\n+\n+        mTransactions.swap (transactions);\n+        lock.unlock();\n+        apply (transactions);\n+        lock.lock();\n+        mCond.notify_all();\n+    }\n+\n+    mDispatchState = DispatchState::none;\n+}\n+\n+void NetworkOPsImp::apply (std::vector<TransactionStatus>& transactions)\n+{\n+    Ledger::pointer ledger;\n+    TransactionEngine engine;","path":"src/ripple/app/misc/NetworkOPs.cpp","position":318,"original_position":318,"commit_id":"1b4ad87e37de7c250f2103489175c834292e28cb","original_commit_id":"fd5dff2ba7d2c2b519bb30063d250411f178786e","user":{"login":"mtrippled","id":7728157,"avatar_url":"https://avatars.githubusercontent.com/u/7728157?v=3","gravatar_id":"","url":"https://api.github.com/users/mtrippled","html_url":"https://github.com/mtrippled","followers_url":"https://api.github.com/users/mtrippled/followers","following_url":"https://api.github.com/users/mtrippled/following{/other_user}","gists_url":"https://api.github.com/users/mtrippled/gists{/gist_id}","starred_url":"https://api.github.com/users/mtrippled/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtrippled/subscriptions","organizations_url":"https://api.github.com/users/mtrippled/orgs","repos_url":"https://api.github.com/users/mtrippled/repos","events_url":"https://api.github.com/users/mtrippled/events{/privacy}","received_events_url":"https://api.github.com/users/mtrippled/received_events","type":"User","site_admin":false},"body":"Is that preferable to you?","created_at":"2015-06-02T15:41:04Z","updated_at":"2015-06-02T15:41:04Z","html_url":"https://github.com/ripple/rippled/pull/1078#discussion_r31536738","pull_request_url":"https://api.github.com/repos/ripple/rippled/pulls/1078","_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments/31536738"},"html":{"href":"https://github.com/ripple/rippled/pull/1078#discussion_r31536738"},"pull_request":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1078"}}},"pull_request":{"url":"https://api.github.com/repos/ripple/rippled/pulls/1078","id":36480192,"html_url":"https://github.com/ripple/rippled/pull/1078","diff_url":"https://github.com/ripple/rippled/pull/1078.diff","patch_url":"https://github.com/ripple/rippled/pull/1078.patch","issue_url":"https://api.github.com/repos/ripple/rippled/issues/1078","number":1078,"state":"open","locked":false,"title":"Batch multiple transactions to the open ledger within a","user":{"login":"mtrippled","id":7728157,"avatar_url":"https://avatars.githubusercontent.com/u/7728157?v=3","gravatar_id":"","url":"https://api.github.com/users/mtrippled","html_url":"https://github.com/mtrippled","followers_url":"https://api.github.com/users/mtrippled/followers","following_url":"https://api.github.com/users/mtrippled/following{/other_user}","gists_url":"https://api.github.com/users/mtrippled/gists{/gist_id}","starred_url":"https://api.github.com/users/mtrippled/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtrippled/subscriptions","organizations_url":"https://api.github.com/users/mtrippled/orgs","repos_url":"https://api.github.com/users/mtrippled/repos","events_url":"https://api.github.com/users/mtrippled/events{/privacy}","received_events_url":"https://api.github.com/users/mtrippled/received_events","type":"User","site_admin":false},"body":"single SHAMap modification.","created_at":"2015-05-29T07:26:58Z","updated_at":"2015-06-02T15:41:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cbe1488f2de55b3d82eb3961cb715a25d4368300","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ripple/rippled/pulls/1078/commits","review_comments_url":"https://api.github.com/repos/ripple/rippled/pulls/1078/comments","review_comment_url":"https://api.github.com/repos/ripple/rippled/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ripple/rippled/issues/1078/comments","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/1b4ad87e37de7c250f2103489175c834292e28cb","head":{"label":"mtrippled:batch","ref":"batch","sha":"1b4ad87e37de7c250f2103489175c834292e28cb","user":{"login":"mtrippled","id":7728157,"avatar_url":"https://avatars.githubusercontent.com/u/7728157?v=3","gravatar_id":"","url":"https://api.github.com/users/mtrippled","html_url":"https://github.com/mtrippled","followers_url":"https://api.github.com/users/mtrippled/followers","following_url":"https://api.github.com/users/mtrippled/following{/other_user}","gists_url":"https://api.github.com/users/mtrippled/gists{/gist_id}","starred_url":"https://api.github.com/users/mtrippled/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtrippled/subscriptions","organizations_url":"https://api.github.com/users/mtrippled/orgs","repos_url":"https://api.github.com/users/mtrippled/repos","events_url":"https://api.github.com/users/mtrippled/events{/privacy}","received_events_url":"https://api.github.com/users/mtrippled/received_events","type":"User","site_admin":false},"repo":{"id":21549222,"name":"rippled","full_name":"mtrippled/rippled","owner":{"login":"mtrippled","id":7728157,"avatar_url":"https://avatars.githubusercontent.com/u/7728157?v=3","gravatar_id":"","url":"https://api.github.com/users/mtrippled","html_url":"https://github.com/mtrippled","followers_url":"https://api.github.com/users/mtrippled/followers","following_url":"https://api.github.com/users/mtrippled/following{/other_user}","gists_url":"https://api.github.com/users/mtrippled/gists{/gist_id}","starred_url":"https://api.github.com/users/mtrippled/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtrippled/subscriptions","organizations_url":"https://api.github.com/users/mtrippled/orgs","repos_url":"https://api.github.com/users/mtrippled/repos","events_url":"https://api.github.com/users/mtrippled/events{/privacy}","received_events_url":"https://api.github.com/users/mtrippled/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mtrippled/rippled","description":"Ripple peer-to-peer network daemon","fork":true,"url":"https://api.github.com/repos/mtrippled/rippled","forks_url":"https://api.github.com/repos/mtrippled/rippled/forks","keys_url":"https://api.github.com/repos/mtrippled/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mtrippled/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mtrippled/rippled/teams","hooks_url":"https://api.github.com/repos/mtrippled/rippled/hooks","issue_events_url":"https://api.github.com/repos/mtrippled/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/mtrippled/rippled/events","assignees_url":"https://api.github.com/repos/mtrippled/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/mtrippled/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/mtrippled/rippled/tags","blobs_url":"https://api.github.com/repos/mtrippled/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mtrippled/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mtrippled/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/mtrippled/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mtrippled/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/mtrippled/rippled/languages","stargazers_url":"https://api.github.com/repos/mtrippled/rippled/stargazers","contributors_url":"https://api.github.com/repos/mtrippled/rippled/contributors","subscribers_url":"https://api.github.com/repos/mtrippled/rippled/subscribers","subscription_url":"https://api.github.com/repos/mtrippled/rippled/subscription","commits_url":"https://api.github.com/repos/mtrippled/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/mtrippled/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/mtrippled/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/mtrippled/rippled/issues/comments{/number}","contents_url":"https://api.github.com/repos/mtrippled/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/mtrippled/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mtrippled/rippled/merges","archive_url":"https://api.github.com/repos/mtrippled/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mtrippled/rippled/downloads","issues_url":"https://api.github.com/repos/mtrippled/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/mtrippled/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/mtrippled/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/mtrippled/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mtrippled/rippled/labels{/name}","releases_url":"https://api.github.com/repos/mtrippled/rippled/releases{/id}","created_at":"2014-07-06T21:44:01Z","updated_at":"2015-01-01T00:44:40Z","pushed_at":"2015-06-02T03:26:43Z","git_url":"git://github.com/mtrippled/rippled.git","ssh_url":"git@github.com:mtrippled/rippled.git","clone_url":"https://github.com/mtrippled/rippled.git","svn_url":"https://github.com/mtrippled/rippled","homepage":"https://ripple.com","size":53825,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"ripple:develop","ref":"develop","sha":"6675ee7f5cb52a898c63f99b7b232b6d1847f9e0","user":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?v=3","gravatar_id":"","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"repo":{"id":2724167,"name":"rippled","full_name":"ripple/rippled","owner":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?v=3","gravatar_id":"","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ripple/rippled","description":"Ripple peer-to-peer network daemon","fork":false,"url":"https://api.github.com/repos/ripple/rippled","forks_url":"https://api.github.com/repos/ripple/rippled/forks","keys_url":"https://api.github.com/repos/ripple/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ripple/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ripple/rippled/teams","hooks_url":"https://api.github.com/repos/ripple/rippled/hooks","issue_events_url":"https://api.github.com/repos/ripple/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/ripple/rippled/events","assignees_url":"https://api.github.com/repos/ripple/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/ripple/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/ripple/rippled/tags","blobs_url":"https://api.github.com/repos/ripple/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ripple/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ripple/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/ripple/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/ripple/rippled/languages","stargazers_url":"https://api.github.com/repos/ripple/rippled/stargazers","contributors_url":"https://api.github.com/repos/ripple/rippled/contributors","subscribers_url":"https://api.github.com/repos/ripple/rippled/subscribers","subscription_url":"https://api.github.com/repos/ripple/rippled/subscription","commits_url":"https://api.github.com/repos/ripple/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/ripple/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/ripple/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/ripple/rippled/issues/comments{/number}","contents_url":"https://api.github.com/repos/ripple/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/ripple/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ripple/rippled/merges","archive_url":"https://api.github.com/repos/ripple/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ripple/rippled/downloads","issues_url":"https://api.github.com/repos/ripple/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/ripple/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/ripple/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/ripple/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ripple/rippled/labels{/name}","releases_url":"https://api.github.com/repos/ripple/rippled/releases{/id}","created_at":"2011-11-07T04:40:15Z","updated_at":"2015-05-31T03:11:05Z","pushed_at":"2015-06-02T15:35:45Z","git_url":"git://github.com/ripple/rippled.git","ssh_url":"git@github.com:ripple/rippled.git","clone_url":"https://github.com/ripple/rippled.git","svn_url":"https://github.com/ripple/rippled","homepage":"https://ripple.com","size":116381,"stargazers_count":950,"watchers_count":950,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":269,"mirror_url":null,"open_issues_count":135,"forks":269,"open_issues":135,"watchers":950,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1078"},"html":{"href":"https://github.com/ripple/rippled/pull/1078"},"issue":{"href":"https://api.github.com/repos/ripple/rippled/issues/1078"},"comments":{"href":"https://api.github.com/repos/ripple/rippled/issues/1078/comments"},"review_comments":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1078/comments"},"review_comment":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ripple/rippled/pulls/1078/commits"},"statuses":{"href":"https://api.github.com/repos/ripple/rippled/statuses/1b4ad87e37de7c250f2103489175c834292e28cb"}}}}