mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-18 17:45:48 +00:00
.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#ifndef __APPLICATION__
|
||||
#define __APPLICATION__
|
||||
|
||||
#include "UniqueNodeList.h"
|
||||
#include "ConnectionPool.h"
|
||||
#include "KnownNodeList.h"
|
||||
@@ -5,7 +8,6 @@
|
||||
#include "TimingService.h"
|
||||
#include "ValidationCollection.h"
|
||||
#include "Wallet.h"
|
||||
#include "Serializer.h"
|
||||
#include "database/database.h"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
@@ -28,7 +30,7 @@ class Application
|
||||
ConnectionPool mConnectionPool;
|
||||
PeerDoor* mPeerDoor;
|
||||
RPCDoor* mRPCDoor;
|
||||
Serializer* mSerializer;
|
||||
//Serializer* mSerializer;
|
||||
|
||||
boost::asio::io_service mIOService;
|
||||
|
||||
@@ -46,8 +48,8 @@ public:
|
||||
|
||||
void setDB(Database* db){ mDatabase=db; }
|
||||
|
||||
Serializer* getSerializer(){ return(mSerializer); }
|
||||
void setSerializer(Serializer* ser){ mSerializer=ser; }
|
||||
//Serializer* getSerializer(){ return(mSerializer); }
|
||||
//void setSerializer(Serializer* ser){ mSerializer=ser; }
|
||||
|
||||
|
||||
void run();
|
||||
@@ -55,4 +57,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
extern Application* theApp;
|
||||
extern Application* theApp;
|
||||
|
||||
#endif
|
||||
@@ -1,3 +1,6 @@
|
||||
#ifndef __CONNECTION_POOL__
|
||||
#define __CONNECTION_POOL__
|
||||
|
||||
#include "Peer.h"
|
||||
#include "PackedMessage.h"
|
||||
#include "types.h"
|
||||
@@ -19,4 +22,6 @@ public:
|
||||
//bool isMessageKnown(PackedMessage::pointer msg);
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -28,12 +28,14 @@ bool LedgerHistory::loadLedger(uint256& hash)
|
||||
|
||||
bool LedgerHistory::loadAcceptedLedger(uint32 index)
|
||||
{
|
||||
// TODO: LedgerHistory::loadAcceptedLedger(uint32 index)
|
||||
/*
|
||||
Ledger::pointer ledger=theApp->getSerializer()->loadAcceptedLedger(index);
|
||||
if(ledger)
|
||||
{
|
||||
mAcceptedLedgers[index]=ledger;
|
||||
return(true);
|
||||
}
|
||||
}*/
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
7
Peer.cpp
7
Peer.cpp
@@ -291,10 +291,11 @@ void Peer::receiveValidation(newcoin::Validation& validation)
|
||||
|
||||
void Peer::receiveGetValidations(newcoin::GetValidations& request)
|
||||
{
|
||||
vector<newcoin::Validation>* validations=theApp->getValidationCollection().getValidations(request.ledgerindex());
|
||||
if(validations)
|
||||
vector<newcoin::Validation> validations;
|
||||
theApp->getValidationCollection().getValidations(request.ledgerindex(),validations);
|
||||
if(validations.size())
|
||||
{
|
||||
BOOST_FOREACH(newcoin::Validation& valid, *validations)
|
||||
BOOST_FOREACH(newcoin::Validation& valid, validations)
|
||||
{
|
||||
PackedMessage::pointer packet(new PackedMessage(PackedMessage::MessagePointer(new newcoin::Validation(valid)),newcoin::VALIDATION));
|
||||
sendPacket(packet);
|
||||
|
||||
@@ -28,29 +28,45 @@ void ValidationCollection::load()
|
||||
|
||||
}
|
||||
|
||||
void ValidationCollection::addToDB(newcoin::Validation& valid,bool weCare)
|
||||
void ValidationCollection::addToDB(newcoin::Validation& valid,int weCare)
|
||||
{
|
||||
Database* db=theApp->getDB();
|
||||
uint256 hash=protobufTo256(valid.hash());
|
||||
uint160 hanko=protobufTo160(valid.hanko());
|
||||
uint256 sig=protobufTo256(valid.sig());
|
||||
|
||||
string hashStr,hankoStr,sigStr;
|
||||
db->escape(hash.begin(),hash.GetSerializeSize(),hashStr);
|
||||
db->escape(hanko.begin(),hanko.GetSerializeSize(),hankoStr);
|
||||
db->escape(sig.begin(),sig.GetSerializeSize(),sigStr);
|
||||
string sql=strprintf("INSERT INTO Validations (LedgerIndex,Hash,Hanko,SeqNum,Sig,WeCare) values (%d,%s,%s,%d,%s,%d)",valid.ledgerindex(),hashStr.c_str(),hankoStr.c_str(),valid.seqnum(),sigStr.c_str(),weCare);
|
||||
db->executeSQL(sql.c_str());
|
||||
|
||||
}
|
||||
|
||||
bool ValidationCollection::hasValidation(uint256& ledgerHash,uint160& hanko,uint32 seqnum)
|
||||
bool ValidationCollection::hasValidation(uint32 ledgerIndex,uint160& hanko,uint32 seqnum)
|
||||
{
|
||||
if(mValidations.count(ledgerHash))
|
||||
string hankoStr;
|
||||
Database* db=theApp->getDB();
|
||||
db->escape(hanko.begin(),hanko.GetSerializeSize(),hankoStr);
|
||||
string sql=strprintf("SELECT ValidationID,seqnum from Validations where LedgerIndex=%d and hanko=%s",ledgerIndex,hankoStr);
|
||||
if(db->executeSQL(sql.c_str()))
|
||||
{
|
||||
BOOST_FOREACH(newcoin::Validation& valid,mValidations[ledgerHash])
|
||||
if(db->startIterRows())
|
||||
{
|
||||
if( valid.seqnum()==seqnum &&
|
||||
protobufTo160(valid.hanko()) == hanko) return(true);
|
||||
}
|
||||
}
|
||||
|
||||
if(mIgnoredValidations.count(ledgerHash))
|
||||
{
|
||||
BOOST_FOREACH(newcoin::Validation& valid,mIgnoredValidations[ledgerHash])
|
||||
{
|
||||
if( valid.seqnum()==seqnum &&
|
||||
protobufTo160(valid.hanko()) == hanko) return(true);
|
||||
if(db->getNextRow())
|
||||
{
|
||||
uint32 currentSeqNum=db->getInt(1);
|
||||
if(currentSeqNum>=seqnum)
|
||||
{
|
||||
db->endIterRows();
|
||||
return(true);
|
||||
}
|
||||
// delete the old validation we were storing
|
||||
sql=strprintf("DELETE FROM Validations where ValidationID=%d",db->getInt(0));
|
||||
db->endIterRows();
|
||||
db->executeSQL(sql.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
@@ -67,20 +83,17 @@ void ValidationCollection::addValidation(newcoin::Validation& valid)
|
||||
uint160 hanko=protobufTo160(valid.hanko());
|
||||
|
||||
// make sure we don't already have this validation
|
||||
if(hasValidation(hash,hanko,valid.seqnum())) return;
|
||||
if(hasValidation(valid.ledgerindex(),hanko,valid.seqnum())) return;
|
||||
|
||||
// check if we care about this hanko
|
||||
int validity=theApp->getUNL().checkValid(valid);
|
||||
if( validity==1 )
|
||||
{
|
||||
mValidations[hash].push_back(valid);
|
||||
mIndexValidations[valid.ledgerindex()].push_back(valid);
|
||||
addToGroup(valid);
|
||||
addToDB(valid,true);
|
||||
addToGroup(valid);
|
||||
theApp->getLedgerMaster().checkConsensus(valid.ledgerindex());
|
||||
}else if(validity==0)
|
||||
{
|
||||
mIgnoredValidations[hash].push_back(valid);
|
||||
addToDB(valid,false);
|
||||
}else
|
||||
{ // the signature wasn't valid
|
||||
@@ -147,7 +160,11 @@ void ValidationCollection::addToGroup(newcoin::Validation& newValid)
|
||||
newGroup.mValidations.push_back(newValid);
|
||||
newGroup.mSuperLedger=Ledger::pointer(new Ledger(newLedger)); // since this super ledger gets modified and we don't want to screw the original
|
||||
|
||||
BOOST_FOREACH(newcoin::Validation& valid,mIndexValidations[newValid.ledgerindex()])
|
||||
vector<newcoin::Validation> retVec;
|
||||
getValidations(newValid.ledgerindex(),retVec);
|
||||
|
||||
|
||||
BOOST_FOREACH(newcoin::Validation& valid,retVec)
|
||||
{
|
||||
uint256 hash=protobufTo256(valid.hash());
|
||||
Ledger::pointer ledger=theApp->getLedgerMaster().getLedger(hash);
|
||||
@@ -169,13 +186,12 @@ void ValidationCollection::addToGroup(newcoin::Validation& newValid)
|
||||
}
|
||||
}
|
||||
|
||||
vector<newcoin::Validation>* ValidationCollection::getValidations(uint32 ledgerIndex)
|
||||
void ValidationCollection::getValidations(uint32 ledgerIndex,vector<newcoin::Validation>& retVec)
|
||||
{
|
||||
if(mIndexValidations.count(ledgerIndex))
|
||||
{
|
||||
return(&(mIndexValidations[ledgerIndex]));
|
||||
}
|
||||
return(NULL);
|
||||
string sql=strprintf("SELECT * From Validations where LedgerIndex=%d and wecare=1",ledgerIndex);
|
||||
|
||||
// TODO: ValidationCollection::getValidations(uint32 ledgerIndex)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ class ValidationCollection
|
||||
std::map<uint32, std::vector< Group > > mIndexGroups; // all the groups at each index
|
||||
//std::map<uint32, std::vector< newcoin::Validation > > mIndexValidations; // all the validations at each index
|
||||
|
||||
bool hasValidation(uint256& ledgerHash,uint160& hanko,uint32 seqnum);
|
||||
bool hasValidation(uint32 ledgerIndex,uint160& hanko,uint32 seqnum);
|
||||
void addToGroup(newcoin::Validation& valid);
|
||||
void addToDB(newcoin::Validation& valid,bool weCare);
|
||||
void addToDB(newcoin::Validation& valid,int weCare);
|
||||
public:
|
||||
ValidationCollection();
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
void addValidation(newcoin::Validation& valid);
|
||||
|
||||
std::vector<newcoin::Validation>* getValidations(uint32 ledgerIndex);
|
||||
void getValidations(uint32 ledgerIndex,std::vector<newcoin::Validation>& retVec);
|
||||
|
||||
|
||||
// It can miss some compatible ledgers of course if you don't know them
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
CREATE TABLE UNL (Hanko BLOB PRIMARY KEY, PubKey BLOB);
|
||||
CREATE TABLE Transactions (TransactionID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, From BLOB, Dest BLOB, Amount BIGINT UNSIGNED, LedgerIndex INT UNSIGNED, SeqNum INT, PubKey BLOB, Sig BLOB);
|
||||
CREATE TABLE Ledgers (LedgerID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, LedgerIndex INT UNSIGNED, Hash BLOB, ParentHash BLOB,FeeHeld BIGINT UNSIGNED);
|
||||
CREATE TABLE Validations(LedgerIndex INT UNSIGNED, Hash BLOB, Hanko BLOB, SeqNum INT UNSIGNED, Sig BLOB, WeCare TINYINT);
|
||||
CREATE TABLE Validations(ValidationID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, LedgerIndex INT UNSIGNED, Hash BLOB, Hanko BLOB, SeqNum INT UNSIGNED, Sig BLOB, WeCare TINYINT);
|
||||
CREATE TABLE LedgerTransactionMap (LedgerID INT UNSIGNED, TransactionID INT UNSIGNED, Include TINYINT);
|
||||
CREATE TABLE LedgerAccountMap(LedgerID INT UNSIGNED,AccountID INT UNSIGNED);
|
||||
CREATE TABLE Accounts (AccountID INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, Address BLOB, Amount BIGINT UNSIGNED, SeqNum INT);
|
||||
|
||||
@@ -95,7 +95,6 @@
|
||||
<ClCompile Include="database\database.cpp" />
|
||||
<ClCompile Include="database\sqlite3.c" />
|
||||
<ClCompile Include="database\SqliteDatabase.cpp" />
|
||||
<ClCompile Include="DiskSerializer.cpp" />
|
||||
<ClCompile Include="HttpReply.cpp" />
|
||||
<ClCompile Include="json\json_spirit_reader.cpp" />
|
||||
<ClCompile Include="json\json_spirit_value.cpp" />
|
||||
@@ -105,7 +104,6 @@
|
||||
<ClCompile Include="Ledger.cpp" />
|
||||
<ClCompile Include="LedgerHistory.cpp" />
|
||||
<ClCompile Include="LedgerMaster.cpp" />
|
||||
<ClCompile Include="MySqlSerializer.cpp" />
|
||||
<ClCompile Include="newcoin.pb.cc" />
|
||||
<ClCompile Include="NewcoinAddress.cpp" />
|
||||
<ClCompile Include="PackedMessage.cpp" />
|
||||
|
||||
@@ -132,12 +132,6 @@
|
||||
<ClCompile Include="Transaction.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MySqlSerializer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DiskSerializer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="database\database.cpp">
|
||||
<Filter>Header Files\util</Filter>
|
||||
</ClCompile>
|
||||
|
||||
Reference in New Issue
Block a user