mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-03 17:35:51 +00:00
Split TransactionAcquire and DisputedTx
This commit is contained in:
@@ -1,21 +1,44 @@
|
|||||||
#ifndef RIPPLE_PROTOCOLTYPES_H
|
#ifndef RIPPLE_PROTOCOLTYPES_H
|
||||||
#define RIPPLE_PROTOCOLTYPES_H
|
#define RIPPLE_PROTOCOLTYPES_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
Hashes are used to uniquely identify objects like
|
||||||
|
transactions, peers, validators, and accounts.
|
||||||
|
|
||||||
|
For historical reasons, some hashes are 256 bits and some are 160.
|
||||||
|
|
||||||
|
David:
|
||||||
|
"The theory is that you may need to communicate public keys
|
||||||
|
to others, so having them be shorter is a good idea. plus,
|
||||||
|
you can't arbitrarily tweak them because you wouldn't know
|
||||||
|
the corresponding private key anyway. So the security
|
||||||
|
requirements aren't as great."
|
||||||
|
*/
|
||||||
|
|
||||||
/** A ledger hash.
|
/** A ledger hash.
|
||||||
*/
|
*/
|
||||||
typedef uint256 LedgerHash;
|
typedef uint256 LedgerHash;
|
||||||
|
|
||||||
/** A ledger index.
|
/** A ledger index.
|
||||||
*/
|
*/
|
||||||
|
// VFALCO TODO pick one. I like Index since its not an abbreviation
|
||||||
typedef uint32 LedgerIndex;
|
typedef uint32 LedgerIndex;
|
||||||
typedef uint32 LedgerSeq;
|
typedef uint32 LedgerSeq;
|
||||||
|
|
||||||
/** A transaction identifier.
|
/** A transaction identifier.
|
||||||
*/
|
*/
|
||||||
|
// VFALCO TODO maybe rename to TxHash
|
||||||
typedef uint256 TxID;
|
typedef uint256 TxID;
|
||||||
|
|
||||||
/** A transaction index.
|
/** A transaction index.
|
||||||
*/
|
*/
|
||||||
typedef uint32 TxSeq;
|
typedef uint32 TxSeq; // VFALCO NOTE Should read TxIndex or TxNum
|
||||||
|
|
||||||
|
/** An account hash.
|
||||||
|
|
||||||
|
The hash is used to uniquely identify the account.
|
||||||
|
*/
|
||||||
|
//typedef uint160 AccountHash;
|
||||||
|
//typedef uint260 ValidatorID;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,6 +24,21 @@
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
#include <openssl/rand.h>
|
||||||
|
#include <string>
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -64,6 +79,7 @@
|
|||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <boost/ptr_container/ptr_vector.hpp>
|
#include <boost/ptr_container/ptr_vector.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
@@ -219,6 +235,8 @@
|
|||||||
#include "src/cpp/ripple/HTTPRequest.h"
|
#include "src/cpp/ripple/HTTPRequest.h"
|
||||||
#include "src/cpp/ripple/HashPrefixes.h"
|
#include "src/cpp/ripple/HashPrefixes.h"
|
||||||
#include "src/cpp/ripple/HttpsClient.h"
|
#include "src/cpp/ripple/HttpsClient.h"
|
||||||
|
#include "src/cpp/ripple/ripple_TransactionAcquire.h"
|
||||||
|
#include "src/cpp/ripple/ripple_DisputedTx.h"
|
||||||
#include "src/cpp/ripple/LedgerConsensus.h"
|
#include "src/cpp/ripple/LedgerConsensus.h"
|
||||||
#include "src/cpp/ripple/LedgerTiming.h"
|
#include "src/cpp/ripple/LedgerTiming.h"
|
||||||
#include "src/cpp/ripple/Offer.h"
|
#include "src/cpp/ripple/Offer.h"
|
||||||
@@ -330,7 +348,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
|
|||||||
#include "src/cpp/ripple/SerializedValidation.cpp"
|
#include "src/cpp/ripple/SerializedValidation.cpp"
|
||||||
#include "src/cpp/ripple/SNTPClient.cpp"
|
#include "src/cpp/ripple/SNTPClient.cpp"
|
||||||
#include "src/cpp/ripple/Transaction.cpp"
|
#include "src/cpp/ripple/Transaction.cpp"
|
||||||
#include "src/cpp/ripple/TransactionAcquire.cpp"
|
|
||||||
#include "src/cpp/ripple/TransactionCheck.cpp"
|
#include "src/cpp/ripple/TransactionCheck.cpp"
|
||||||
#include "src/cpp/ripple/TransactionEngine.cpp"
|
#include "src/cpp/ripple/TransactionEngine.cpp"
|
||||||
#include "src/cpp/ripple/TransactionMaster.cpp" // no log
|
#include "src/cpp/ripple/TransactionMaster.cpp" // no log
|
||||||
@@ -366,6 +383,7 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
|
|||||||
#include "src/cpp/ripple/ripple_Application.cpp"
|
#include "src/cpp/ripple/ripple_Application.cpp"
|
||||||
#include "src/cpp/ripple/ripple_Config.cpp"
|
#include "src/cpp/ripple/ripple_Config.cpp"
|
||||||
#include "src/cpp/ripple/ripple_DatabaseCon.cpp"
|
#include "src/cpp/ripple/ripple_DatabaseCon.cpp"
|
||||||
|
#include "src/cpp/ripple/ripple_DisputedTx.cpp"
|
||||||
#include "src/cpp/ripple/ripple_Features.cpp"
|
#include "src/cpp/ripple/ripple_Features.cpp"
|
||||||
#include "src/cpp/ripple/ripple_FeeVote.cpp"
|
#include "src/cpp/ripple/ripple_FeeVote.cpp"
|
||||||
#include "src/cpp/ripple/ripple_HashedObjectStore.cpp"
|
#include "src/cpp/ripple/ripple_HashedObjectStore.cpp"
|
||||||
@@ -396,6 +414,7 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength)
|
|||||||
#include "src/cpp/ripple/ripple_ProofOfWorkFactory.cpp"
|
#include "src/cpp/ripple/ripple_ProofOfWorkFactory.cpp"
|
||||||
#include "src/cpp/ripple/ripple_SerializedLedger.cpp"
|
#include "src/cpp/ripple/ripple_SerializedLedger.cpp"
|
||||||
#include "src/cpp/ripple/ripple_SerializedTransaction.cpp"
|
#include "src/cpp/ripple/ripple_SerializedTransaction.cpp"
|
||||||
|
#include "src/cpp/ripple/ripple_TransactionAcquire.cpp"
|
||||||
#include "src/cpp/ripple/ripple_Validations.cpp"
|
#include "src/cpp/ripple/ripple_Validations.cpp"
|
||||||
#include "src/cpp/ripple/ripple_UniqueNodeList.cpp"
|
#include "src/cpp/ripple/ripple_UniqueNodeList.cpp"
|
||||||
|
|
||||||
|
|||||||
@@ -797,6 +797,12 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\cpp\ripple\ripple_DisputedTx.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="src\cpp\ripple\ripple_HashedObject.cpp">
|
<ClCompile Include="src\cpp\ripple\ripple_HashedObject.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
@@ -1237,7 +1243,7 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\cpp\ripple\TransactionAcquire.cpp">
|
<ClCompile Include="src\cpp\ripple\ripple_TransactionAcquire.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
@@ -1738,6 +1744,7 @@
|
|||||||
<ClInclude Include="src\cpp\ripple\ripple_AccountState.h" />
|
<ClInclude Include="src\cpp\ripple\ripple_AccountState.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\ripple_AccountItem.h" />
|
<ClInclude Include="src\cpp\ripple\ripple_AccountItem.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\ripple_AccountItems.h" />
|
<ClInclude Include="src\cpp\ripple\ripple_AccountItems.h" />
|
||||||
|
<ClInclude Include="src\cpp\ripple\ripple_DisputedTx.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\ripple_IApplication.h" />
|
<ClInclude Include="src\cpp\ripple\ripple_IApplication.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\AutoSocket.h" />
|
<ClInclude Include="src\cpp\ripple\AutoSocket.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\CallRPC.h" />
|
<ClInclude Include="src\cpp\ripple\CallRPC.h" />
|
||||||
@@ -1802,6 +1809,7 @@
|
|||||||
<ClInclude Include="src\cpp\ripple\ripple_SHAMapNode.h" />
|
<ClInclude Include="src\cpp\ripple\ripple_SHAMapNode.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\ripple_SHAMapSyncFilter.h" />
|
<ClInclude Include="src\cpp\ripple\ripple_SHAMapSyncFilter.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\ripple_SHAMapTreeNode.h" />
|
<ClInclude Include="src\cpp\ripple\ripple_SHAMapTreeNode.h" />
|
||||||
|
<ClInclude Include="src\cpp\ripple\ripple_TransactionAcquire.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\RPC.h" />
|
<ClInclude Include="src\cpp\ripple\RPC.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\RPCDoor.h" />
|
<ClInclude Include="src\cpp\ripple\RPCDoor.h" />
|
||||||
<ClInclude Include="src\cpp\ripple\RPCErr.h" />
|
<ClInclude Include="src\cpp\ripple\RPCErr.h" />
|
||||||
|
|||||||
@@ -139,6 +139,12 @@
|
|||||||
<Filter Include="1. Modules\ripple_data\utility">
|
<Filter Include="1. Modules\ripple_data\utility">
|
||||||
<UniqueIdentifier>{82b7f371-8bc6-474b-b10c-18c004467b46}</UniqueIdentifier>
|
<UniqueIdentifier>{82b7f371-8bc6-474b-b10c-18c004467b46}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="1. Modules\ripple_main\refactored\transactions">
|
||||||
|
<UniqueIdentifier>{babbb25a-e143-4140-bc6f-16b659d8098b}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="1. Modules\ripple_main\refactored\consensus">
|
||||||
|
<UniqueIdentifier>{8b88138b-e5bd-492b-bd34-012b9f43e544}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\cpp\database\sqlite3.c">
|
<ClCompile Include="src\cpp\database\sqlite3.c">
|
||||||
@@ -417,9 +423,6 @@
|
|||||||
<ClCompile Include="src\cpp\ripple\Transaction.cpp">
|
<ClCompile Include="src\cpp\ripple\Transaction.cpp">
|
||||||
<Filter>1. Modules\ripple_main\_unfactored\transactions</Filter>
|
<Filter>1. Modules\ripple_main\_unfactored\transactions</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\cpp\ripple\TransactionAcquire.cpp">
|
|
||||||
<Filter>1. Modules\ripple_main\_unfactored\transactions</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\cpp\ripple\TransactionCheck.cpp">
|
<ClCompile Include="src\cpp\ripple\TransactionCheck.cpp">
|
||||||
<Filter>1. Modules\ripple_main\_unfactored\transactions</Filter>
|
<Filter>1. Modules\ripple_main\_unfactored\transactions</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -870,6 +873,12 @@
|
|||||||
<ClCompile Include="build\proto\ripple.pb.cc">
|
<ClCompile Include="build\proto\ripple.pb.cc">
|
||||||
<Filter>1. Modules\ripple_data\protocol</Filter>
|
<Filter>1. Modules\ripple_data\protocol</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\cpp\ripple\ripple_TransactionAcquire.cpp">
|
||||||
|
<Filter>1. Modules\ripple_main\refactored\transactions</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\cpp\ripple\ripple_DisputedTx.cpp">
|
||||||
|
<Filter>1. Modules\ripple_main\refactored\consensus</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="database\sqlite3ext.h">
|
<ClInclude Include="database\sqlite3ext.h">
|
||||||
@@ -1622,6 +1631,12 @@
|
|||||||
<ClInclude Include="build\proto\ripple.pb.h">
|
<ClInclude Include="build\proto\ripple.pb.h">
|
||||||
<Filter>1. Modules\ripple_data\protocol</Filter>
|
<Filter>1. Modules\ripple_data\protocol</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\cpp\ripple\ripple_TransactionAcquire.h">
|
||||||
|
<Filter>1. Modules\ripple_main\refactored\transactions</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\cpp\ripple\ripple_DisputedTx.h">
|
||||||
|
<Filter>1. Modules\ripple_main\refactored\consensus</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="SConstruct" />
|
<None Include="SConstruct" />
|
||||||
|
|||||||
@@ -1,131 +1,12 @@
|
|||||||
|
|
||||||
#define LEDGER_TOTAL_PASSES 8
|
|
||||||
#define LEDGER_RETRY_PASSES 5
|
|
||||||
|
|
||||||
#define TRUST_NETWORK
|
#define TRUST_NETWORK
|
||||||
|
|
||||||
#define LC_DEBUG
|
#define LC_DEBUG
|
||||||
|
|
||||||
typedef std::map<uint160, LedgerProposal::pointer>::value_type u160_prop_pair;
|
|
||||||
typedef std::map<uint256, LCTransaction::pointer>::value_type u256_lct_pair;
|
|
||||||
|
|
||||||
SETUP_LOG (LedgerConsensus)
|
SETUP_LOG (LedgerConsensus)
|
||||||
|
|
||||||
DECLARE_INSTANCE(LedgerConsensus);
|
DECLARE_INSTANCE(LedgerConsensus);
|
||||||
|
|
||||||
// VFALCO TODO move LCTransaction to its own file and rename to ConsensusTransactor
|
|
||||||
//
|
|
||||||
void LCTransaction::setVote(const uint160& peer, bool votesYes)
|
|
||||||
{ // Track a peer's yes/no vote on a particular disputed transaction
|
|
||||||
std::pair<boost::unordered_map<const uint160, bool>::iterator, bool> res =
|
|
||||||
mVotes.insert(std::pair<const uint160, bool>(peer, votesYes));
|
|
||||||
|
|
||||||
if (res.second)
|
|
||||||
{ // new vote
|
|
||||||
if (votesYes)
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes YES on " << mTransactionID;
|
|
||||||
++mYays;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes NO on " << mTransactionID;
|
|
||||||
++mNays;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (votesYes && !res.first->second)
|
|
||||||
{ // changes vote to yes
|
|
||||||
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes YES on " << mTransactionID;
|
|
||||||
--mNays;
|
|
||||||
++mYays;
|
|
||||||
res.first->second = true;
|
|
||||||
}
|
|
||||||
else if (!votesYes && res.first->second)
|
|
||||||
{ // changes vote to no
|
|
||||||
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes NO on " << mTransactionID;
|
|
||||||
++mNays;
|
|
||||||
--mYays;
|
|
||||||
res.first->second = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LCTransaction::unVote(const uint160& peer)
|
|
||||||
{ // Remove a peer's vote on this disputed transasction
|
|
||||||
boost::unordered_map<uint160, bool>::iterator it = mVotes.find(peer);
|
|
||||||
if (it != mVotes.end())
|
|
||||||
{
|
|
||||||
if (it->second)
|
|
||||||
--mYays;
|
|
||||||
else
|
|
||||||
--mNays;
|
|
||||||
mVotes.erase(it);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LCTransaction::updateVote(int percentTime, bool proposing)
|
|
||||||
{
|
|
||||||
if (mOurVote && (mNays == 0))
|
|
||||||
return false;
|
|
||||||
if (!mOurVote && (mYays == 0))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
bool newPosition;
|
|
||||||
int weight;
|
|
||||||
if (proposing) // give ourselves full weight
|
|
||||||
{
|
|
||||||
// This is basically the percentage of nodes voting 'yes' (including us)
|
|
||||||
weight = (mYays * 100 + (mOurVote ? 100 : 0)) / (mNays + mYays + 1);
|
|
||||||
|
|
||||||
// To prevent avalanche stalls, we increase the needed weight slightly over time
|
|
||||||
if (percentTime < AV_MID_CONSENSUS_TIME)
|
|
||||||
newPosition = weight > AV_INIT_CONSENSUS_PCT;
|
|
||||||
else if (percentTime < AV_LATE_CONSENSUS_TIME)
|
|
||||||
newPosition = weight > AV_MID_CONSENSUS_PCT;
|
|
||||||
else if (percentTime < AV_STUCK_CONSENSUS_TIME)
|
|
||||||
newPosition = weight > AV_LATE_CONSENSUS_PCT;
|
|
||||||
else
|
|
||||||
newPosition = weight > AV_STUCK_CONSENSUS_PCT;
|
|
||||||
}
|
|
||||||
else // don't let us outweigh a proposing node, just recognize consensus
|
|
||||||
{
|
|
||||||
weight = -1;
|
|
||||||
newPosition = mYays > mNays;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newPosition == mOurVote)
|
|
||||||
{
|
|
||||||
WriteLog (lsINFO, LedgerConsensus) <<
|
|
||||||
"No change (" << (mOurVote ? "YES" : "NO") << ") : weight " << weight << ", percent " << percentTime;
|
|
||||||
WriteLog (lsDEBUG, LedgerConsensus) << getJson();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mOurVote = newPosition;
|
|
||||||
WriteLog (lsDEBUG, LedgerConsensus) << "We now vote " << (mOurVote ? "YES" : "NO") << " on " << mTransactionID;
|
|
||||||
WriteLog (lsDEBUG, LedgerConsensus) << getJson();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Json::Value LCTransaction::getJson()
|
|
||||||
{
|
|
||||||
Json::Value ret(Json::objectValue);
|
|
||||||
|
|
||||||
ret["yays"] = mYays;
|
|
||||||
ret["nays"] = mNays;
|
|
||||||
ret["our_vote"] = mOurVote;
|
|
||||||
if (!mVotes.empty())
|
|
||||||
{
|
|
||||||
Json::Value votesj(Json::objectValue);
|
|
||||||
typedef boost::unordered_map<uint160, bool>::value_type vt;
|
|
||||||
BOOST_FOREACH(vt& vote, mVotes)
|
|
||||||
{
|
|
||||||
votesj[vote.first.GetHex()] = vote.second;
|
|
||||||
}
|
|
||||||
ret["votes"] = votesj;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
LedgerConsensus::LedgerConsensus(uint256 const& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime)
|
LedgerConsensus::LedgerConsensus(uint256 const& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime)
|
||||||
: mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger),
|
: mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger),
|
||||||
mValPublic(theConfig.VALIDATION_PUB), mValPrivate(theConfig.VALIDATION_PRIV), mConsensusFail(false),
|
mValPublic(theConfig.VALIDATION_PUB), mValPrivate(theConfig.VALIDATION_PRIV), mConsensusFail(false),
|
||||||
@@ -848,7 +729,7 @@ void LedgerConsensus::addDisputedTransaction(uint256 const& txID, Blob const& tx
|
|||||||
assert(false); // We don't have our own position?
|
assert(false); // We don't have our own position?
|
||||||
}
|
}
|
||||||
|
|
||||||
LCTransaction::pointer txn = boost::make_shared<LCTransaction>(txID, tx, ourVote);
|
DisputedTx::pointer txn = boost::make_shared<DisputedTx>(txID, tx, ourVote);
|
||||||
mDisputes[txID] = txn;
|
mDisputes[txID] = txn;
|
||||||
|
|
||||||
BOOST_FOREACH(u160_prop_pair& pit, mPeerPositions)
|
BOOST_FOREACH(u160_prop_pair& pit, mPeerPositions)
|
||||||
@@ -1384,7 +1265,7 @@ Json::Value LedgerConsensus::getJson(bool full)
|
|||||||
|
|
||||||
if (!mDisputes.empty())
|
if (!mDisputes.empty())
|
||||||
{
|
{
|
||||||
typedef boost::unordered_map<uint256, LCTransaction::pointer>::value_type d_t;
|
typedef boost::unordered_map<uint256, DisputedTx::pointer>::value_type d_t;
|
||||||
Json::Value dsj(Json::objectValue);
|
Json::Value dsj(Json::objectValue);
|
||||||
BOOST_FOREACH(d_t& dt, mDisputes)
|
BOOST_FOREACH(d_t& dt, mDisputes)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,71 +1,11 @@
|
|||||||
#ifndef __LEDGER_CONSENSUS__
|
#ifndef RIPPLE_LEDGERCONSENSUS_H
|
||||||
#define __LEDGER_CONSENSUS__
|
#define RIPPLE_LEDGERCONSENSUS_H
|
||||||
|
|
||||||
#include "Transaction.h"
|
#include "Transaction.h"
|
||||||
#include "LedgerProposal.h"
|
#include "LedgerProposal.h"
|
||||||
#include "TransactionEngine.h"
|
#include "TransactionEngine.h"
|
||||||
|
|
||||||
DEFINE_INSTANCE(LedgerConsensus);
|
DEFINE_INSTANCE(LedgerConsensus);
|
||||||
DEFINE_INSTANCE(TransactionAcquire);
|
|
||||||
|
|
||||||
// VFALCO TODO rename to PeerTxRequest
|
|
||||||
// A transaction set we are trying to acquire
|
|
||||||
class TransactionAcquire
|
|
||||||
: private IS_INSTANCE (TransactionAcquire)
|
|
||||||
, public PeerSet
|
|
||||||
, public boost::enable_shared_from_this <TransactionAcquire>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef boost::shared_ptr<TransactionAcquire> pointer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit TransactionAcquire(uint256 const& hash);
|
|
||||||
virtual ~TransactionAcquire() { ; }
|
|
||||||
|
|
||||||
SHAMap::ref getMap() { return mMap; }
|
|
||||||
|
|
||||||
SHAMapAddNode takeNodes(const std::list<SHAMapNode>& IDs,
|
|
||||||
const std::list< Blob >& data, Peer::ref);
|
|
||||||
|
|
||||||
private:
|
|
||||||
SHAMap::pointer mMap;
|
|
||||||
bool mHaveRoot;
|
|
||||||
|
|
||||||
void onTimer(bool progress);
|
|
||||||
void newPeer(Peer::ref peer) { trigger(peer); }
|
|
||||||
|
|
||||||
void done();
|
|
||||||
void trigger(Peer::ref);
|
|
||||||
boost::weak_ptr<PeerSet> pmDowncast();
|
|
||||||
};
|
|
||||||
|
|
||||||
// A transaction that may be disputed
|
|
||||||
class LCTransaction
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef boost::shared_ptr<LCTransaction> pointer;
|
|
||||||
|
|
||||||
LCTransaction(uint256 const& txID, Blob const& tx, bool ourVote) :
|
|
||||||
mTransactionID(txID), mYays(0), mNays(0), mOurVote(ourVote), transaction(tx) { ; }
|
|
||||||
|
|
||||||
uint256 const& getTransactionID() const { return mTransactionID; }
|
|
||||||
bool getOurVote() const { return mOurVote; }
|
|
||||||
Serializer& peekTransaction() { return transaction; }
|
|
||||||
void setOurVote(bool o) { mOurVote = o; }
|
|
||||||
|
|
||||||
void setVote(const uint160& peer, bool votesYes);
|
|
||||||
void unVote(const uint160& peer);
|
|
||||||
|
|
||||||
bool updateVote(int percentTime, bool proposing);
|
|
||||||
Json::Value getJson();
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint256 mTransactionID;
|
|
||||||
int mYays, mNays;
|
|
||||||
bool mOurVote;
|
|
||||||
Serializer transaction;
|
|
||||||
boost::unordered_map<uint160, bool> mVotes;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum LCState
|
enum LCState
|
||||||
{
|
{
|
||||||
@@ -179,7 +119,7 @@ private:
|
|||||||
boost::unordered_map<uint256, std::vector< boost::weak_ptr<Peer> > > mPeerData;
|
boost::unordered_map<uint256, std::vector< boost::weak_ptr<Peer> > > mPeerData;
|
||||||
|
|
||||||
// Disputed transactions
|
// Disputed transactions
|
||||||
boost::unordered_map<uint256, LCTransaction::pointer> mDisputes;
|
boost::unordered_map<uint256, DisputedTx::pointer> mDisputes;
|
||||||
|
|
||||||
// Close time estimates
|
// Close time estimates
|
||||||
std::map<uint32, int> mCloseTimes;
|
std::map<uint32, int> mCloseTimes;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ACCEPTED_LEDGER_H
|
#ifndef RIPPLE_ACCEPTEDLEDGER_H
|
||||||
#define ACCEPTED_LEDGER_H
|
#define RIPPLE_ACCEPTEDLEDGER_H
|
||||||
|
|
||||||
/**
|
/** A ledger that has become irrevocable.
|
||||||
|
|
||||||
An accepted ledger is a ledger that has a sufficient number of
|
An accepted ledger is a ledger that has a sufficient number of
|
||||||
validations to convince the local server that it is irrevocable.
|
validations to convince the local server that it is irrevocable.
|
||||||
@@ -9,6 +9,14 @@
|
|||||||
The existence of an accepted ledger implies all preceding ledgers
|
The existence of an accepted ledger implies all preceding ledgers
|
||||||
are accepted.
|
are accepted.
|
||||||
*/
|
*/
|
||||||
|
/* VFALCO TODO digest this terminology clarification:
|
||||||
|
Closed and accepted refer to ledgers that have not passed the
|
||||||
|
validation threshold yet. Once they pass the threshold, they are
|
||||||
|
"Validated". Closed just means its close time has passed and no
|
||||||
|
new transactions can get in. "Accepted" means we believe it to be
|
||||||
|
the result of the a consensus process (though haven't validated
|
||||||
|
it yet).
|
||||||
|
*/
|
||||||
class AcceptedLedger
|
class AcceptedLedger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
128
src/cpp/ripple/ripple_DisputedTx.cpp
Normal file
128
src/cpp/ripple/ripple_DisputedTx.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
|
||||||
|
#define TRUST_NETWORK
|
||||||
|
|
||||||
|
// Track a peer's yes/no vote on a particular disputed transaction
|
||||||
|
void DisputedTx::setVote(const uint160& peer, bool votesYes)
|
||||||
|
{
|
||||||
|
// VFALCO TODO Simplify this declaration. It doesn't exactly roll off the tongue!
|
||||||
|
std::pair <boost::unordered_map <const uint160, bool>::iterator, bool> res =
|
||||||
|
mVotes.insert(std::pair<const uint160, bool>(peer, votesYes));
|
||||||
|
|
||||||
|
// new vote
|
||||||
|
if (res.second)
|
||||||
|
{
|
||||||
|
if (votesYes)
|
||||||
|
{
|
||||||
|
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes YES on " << mTransactionID;
|
||||||
|
++mYays;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes NO on " << mTransactionID;
|
||||||
|
++mNays;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// changes vote to yes
|
||||||
|
else if (votesYes && !res.first->second)
|
||||||
|
{
|
||||||
|
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes YES on " << mTransactionID;
|
||||||
|
--mNays;
|
||||||
|
++mYays;
|
||||||
|
res.first->second = true;
|
||||||
|
}
|
||||||
|
// changes vote to no
|
||||||
|
else if (!votesYes && res.first->second)
|
||||||
|
{
|
||||||
|
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes NO on " << mTransactionID;
|
||||||
|
++mNays;
|
||||||
|
--mYays;
|
||||||
|
res.first->second = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove a peer's vote on this disputed transasction
|
||||||
|
void DisputedTx::unVote(const uint160& peer)
|
||||||
|
{
|
||||||
|
boost::unordered_map<uint160, bool>::iterator it = mVotes.find(peer);
|
||||||
|
if (it != mVotes.end())
|
||||||
|
{
|
||||||
|
if (it->second)
|
||||||
|
--mYays;
|
||||||
|
else
|
||||||
|
--mNays;
|
||||||
|
mVotes.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DisputedTx::updateVote(int percentTime, bool proposing)
|
||||||
|
{
|
||||||
|
// VFALCO TODO Give the return value a descriptive local variable name
|
||||||
|
// and don't return from the middle.
|
||||||
|
|
||||||
|
if (mOurVote && (mNays == 0))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!mOurVote && (mYays == 0))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool newPosition;
|
||||||
|
int weight;
|
||||||
|
|
||||||
|
if (proposing) // give ourselves full weight
|
||||||
|
{
|
||||||
|
// This is basically the percentage of nodes voting 'yes' (including us)
|
||||||
|
weight = (mYays * 100 + (mOurVote ? 100 : 0)) / (mNays + mYays + 1);
|
||||||
|
|
||||||
|
// VFALCO TODO Rename these macros and turn them into language constructs.
|
||||||
|
// consolidate them into a class that collects all these related values.
|
||||||
|
//
|
||||||
|
// To prevent avalanche stalls, we increase the needed weight slightly over time
|
||||||
|
if (percentTime < AV_MID_CONSENSUS_TIME)
|
||||||
|
newPosition = weight > AV_INIT_CONSENSUS_PCT;
|
||||||
|
else if (percentTime < AV_LATE_CONSENSUS_TIME)
|
||||||
|
newPosition = weight > AV_MID_CONSENSUS_PCT;
|
||||||
|
else if (percentTime < AV_STUCK_CONSENSUS_TIME)
|
||||||
|
newPosition = weight > AV_LATE_CONSENSUS_PCT;
|
||||||
|
else
|
||||||
|
newPosition = weight > AV_STUCK_CONSENSUS_PCT;
|
||||||
|
}
|
||||||
|
else // don't let us outweigh a proposing node, just recognize consensus
|
||||||
|
{
|
||||||
|
weight = -1;
|
||||||
|
newPosition = mYays > mNays;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPosition == mOurVote)
|
||||||
|
{
|
||||||
|
WriteLog (lsINFO, LedgerConsensus) <<
|
||||||
|
"No change (" << (mOurVote ? "YES" : "NO") << ") : weight " << weight << ", percent " << percentTime;
|
||||||
|
WriteLog (lsDEBUG, LedgerConsensus) << getJson();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mOurVote = newPosition;
|
||||||
|
WriteLog (lsDEBUG, LedgerConsensus) << "We now vote " << (mOurVote ? "YES" : "NO") << " on " << mTransactionID;
|
||||||
|
WriteLog (lsDEBUG, LedgerConsensus) << getJson();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value DisputedTx::getJson()
|
||||||
|
{
|
||||||
|
Json::Value ret(Json::objectValue);
|
||||||
|
|
||||||
|
ret["yays"] = mYays;
|
||||||
|
ret["nays"] = mNays;
|
||||||
|
ret["our_vote"] = mOurVote;
|
||||||
|
if (!mVotes.empty())
|
||||||
|
{
|
||||||
|
Json::Value votesj(Json::objectValue);
|
||||||
|
typedef boost::unordered_map<uint160, bool>::value_type vt;
|
||||||
|
BOOST_FOREACH(vt& vote, mVotes)
|
||||||
|
{
|
||||||
|
votesj[vote.first.GetHex()] = vote.second;
|
||||||
|
}
|
||||||
|
ret["votes"] = votesj;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
54
src/cpp/ripple/ripple_DisputedTx.h
Normal file
54
src/cpp/ripple/ripple_DisputedTx.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#ifndef RIPPLE_DISPUTEDTX_H
|
||||||
|
#define RIPPLE_DISPUTEDTX_H
|
||||||
|
|
||||||
|
/** A transaction discovered to be in dispute during conensus.
|
||||||
|
|
||||||
|
During consensus, a @ref DisputedTx is created when a transaction
|
||||||
|
is discovered to be disputed. The object persists only as long as
|
||||||
|
the dispute.
|
||||||
|
|
||||||
|
Undisputed transactions have no corresponding @ref DisputedTx object.
|
||||||
|
*/
|
||||||
|
class DisputedTx
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef boost::shared_ptr <DisputedTx> pointer;
|
||||||
|
|
||||||
|
DisputedTx (uint256 const& txID,
|
||||||
|
Blob const& tx,
|
||||||
|
bool ourVote) :
|
||||||
|
mTransactionID(txID), mYays(0), mNays(0), mOurVote(ourVote), transaction(tx) { ; }
|
||||||
|
|
||||||
|
uint256 const& getTransactionID() const { return mTransactionID; }
|
||||||
|
|
||||||
|
bool getOurVote() const { return mOurVote; }
|
||||||
|
|
||||||
|
// VFALCO TODO make this const
|
||||||
|
Serializer& peekTransaction() { return transaction; }
|
||||||
|
|
||||||
|
void setOurVote(bool o) { mOurVote = o; }
|
||||||
|
|
||||||
|
// VFALCO NOTE its not really a peer, its the 160 bit hash of the validator's public key
|
||||||
|
//
|
||||||
|
void setVote(uint160 const& peer, bool votesYes);
|
||||||
|
void unVote (uint160 const& peer);
|
||||||
|
|
||||||
|
bool updateVote(int percentTime, bool proposing);
|
||||||
|
Json::Value getJson();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint256 mTransactionID;
|
||||||
|
int mYays;
|
||||||
|
int mNays;
|
||||||
|
bool mOurVote;
|
||||||
|
Serializer transaction;
|
||||||
|
boost::unordered_map <uint160, bool> mVotes;
|
||||||
|
};
|
||||||
|
|
||||||
|
// VFALCO TODO Rename and put these in a tidy place
|
||||||
|
typedef std::map<uint256, DisputedTx::pointer>::value_type u256_lct_pair;
|
||||||
|
typedef std::map<uint160, LedgerProposal::pointer>::value_type u160_prop_pair;
|
||||||
|
#define LEDGER_TOTAL_PASSES 8
|
||||||
|
#define LEDGER_RETRY_PASSES 5
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/bind.hpp>
|
|
||||||
#include <boost/thread.hpp>
|
|
||||||
|
|
||||||
SETUP_LOG (JobQueue)
|
SETUP_LOG (JobQueue)
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
/** Manages the lifetime of inbound ledgers.
|
/** Manages the lifetime of inbound ledgers.
|
||||||
*/
|
*/
|
||||||
// VFALCO TODO Rename to InboundLedgerManager
|
// VFALCO TODO Rename to InboundLedgers
|
||||||
// VFALCO TODO Create abstract interface
|
// VFALCO TODO Create abstract interface
|
||||||
class LedgerAcquireMaster
|
class LedgerAcquireMaster
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,4 @@
|
|||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
#include <boost/format.hpp>
|
|
||||||
#include <boost/regex.hpp>
|
|
||||||
|
|
||||||
#include <openssl/rand.h>
|
|
||||||
|
|
||||||
SETUP_LOG (ProofOfWork)
|
SETUP_LOG (ProofOfWork)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include <string>
|
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
class ProofOfWorkFactory : public IProofOfWorkFactory
|
class ProofOfWorkFactory : public IProofOfWorkFactory
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ SETUP_LOG (TransactionAcquire)
|
|||||||
#define TX_ACQUIRE_TIMEOUT 250
|
#define TX_ACQUIRE_TIMEOUT 250
|
||||||
|
|
||||||
typedef std::map<uint160, LedgerProposal::pointer>::value_type u160_prop_pair;
|
typedef std::map<uint160, LedgerProposal::pointer>::value_type u160_prop_pair;
|
||||||
typedef std::map<uint256, LCTransaction::pointer>::value_type u256_lct_pair;
|
typedef std::map<uint256, DisputedTx::pointer>::value_type u256_lct_pair;
|
||||||
|
|
||||||
DECLARE_INSTANCE(TransactionAcquire);
|
DECLARE_INSTANCE(TransactionAcquire);
|
||||||
|
|
||||||
37
src/cpp/ripple/ripple_TransactionAcquire.h
Normal file
37
src/cpp/ripple/ripple_TransactionAcquire.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef RIPPLE_TRANSACTIONACQUIRE_H
|
||||||
|
#define RIPPLE_TRANSACTIONACQUIRE_H
|
||||||
|
|
||||||
|
DEFINE_INSTANCE(TransactionAcquire);
|
||||||
|
|
||||||
|
// VFALCO TODO rename to PeerTxRequest
|
||||||
|
// A transaction set we are trying to acquire
|
||||||
|
class TransactionAcquire
|
||||||
|
: private IS_INSTANCE (TransactionAcquire)
|
||||||
|
, public PeerSet
|
||||||
|
, public boost::enable_shared_from_this <TransactionAcquire>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef boost::shared_ptr<TransactionAcquire> pointer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit TransactionAcquire (uint256 const& hash);
|
||||||
|
virtual ~TransactionAcquire() { ; }
|
||||||
|
|
||||||
|
SHAMap::ref getMap() { return mMap; }
|
||||||
|
|
||||||
|
SHAMapAddNode takeNodes(const std::list<SHAMapNode>& IDs,
|
||||||
|
const std::list< Blob >& data, Peer::ref);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SHAMap::pointer mMap;
|
||||||
|
bool mHaveRoot;
|
||||||
|
|
||||||
|
void onTimer(bool progress);
|
||||||
|
void newPeer(Peer::ref peer) { trigger(peer); }
|
||||||
|
|
||||||
|
void done();
|
||||||
|
void trigger(Peer::ref);
|
||||||
|
boost::weak_ptr<PeerSet> pmDowncast();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user