mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Ledger.h"
|
#include "Ledger.h"
|
||||||
|
#include "utils.h"
|
||||||
#include "../obj/src/newcoin.pb.h"
|
#include "../obj/src/newcoin.pb.h"
|
||||||
#include "PackedMessage.h"
|
#include "PackedMessage.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
@@ -50,9 +51,7 @@ Ledger::Ledger(Ledger::pointer prevLedger) : mParentHash(prevLedger->getHash()),
|
|||||||
prevLedger->setClosed();
|
prevLedger->setClosed();
|
||||||
prevLedger->updateHash();
|
prevLedger->updateHash();
|
||||||
mAccountStateMap->setSeq(mLedgerSeq);
|
mAccountStateMap->setSeq(mLedgerSeq);
|
||||||
if (prevLedger->mTimeStamp == 0)
|
mTimeStamp = prevLedger->getNextLedgerClose();
|
||||||
mTimeStamp = (theApp->getOPs().getNetworkTime() % mLedgerInterval) + mLedgerInterval;
|
|
||||||
else mTimeStamp = prevLedger->mTimeStamp + prevLedger->mLedgerInterval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mTotCoins(0), mTimeStamp(0),
|
Ledger::Ledger(const std::vector<unsigned char>& rawLedger) : mTotCoins(0), mTimeStamp(0),
|
||||||
@@ -426,4 +425,22 @@ bool Ledger::isAcquiringAS(void)
|
|||||||
{
|
{
|
||||||
return mAccountStateMap->isSynching();
|
return mAccountStateMap->isSynching();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::posix_time::ptime Ledger::getCloseTime() const
|
||||||
|
{
|
||||||
|
return ptFromSeconds(mTimeStamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ledger::setCloseTime(boost::posix_time::ptime ptm)
|
||||||
|
{
|
||||||
|
mTimeStamp = iToSeconds(ptm);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 Ledger::getNextLedgerClose() const
|
||||||
|
{
|
||||||
|
if (mTimeStamp == 0)
|
||||||
|
return theApp->getOPs().getNetworkTimeNC() + 2 * mLedgerInterval - 1;
|
||||||
|
return mTimeStamp + mLedgerInterval;
|
||||||
|
}
|
||||||
|
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
13
src/Ledger.h
13
src/Ledger.h
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
#include "../json/value.h"
|
#include "../json/value.h"
|
||||||
|
|
||||||
@@ -56,7 +57,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
uint256 mHash, mParentHash, mTransHash, mAccountHash;
|
uint256 mHash, mParentHash, mTransHash, mAccountHash;
|
||||||
uint64 mTotCoins, mTimeStamp;
|
uint64 mTotCoins;
|
||||||
|
uint64 mTimeStamp; // when this ledger closes
|
||||||
uint32 mLedgerSeq;
|
uint32 mLedgerSeq;
|
||||||
uint16 mLedgerInterval;
|
uint16 mLedgerInterval;
|
||||||
bool mClosed, mValidHash, mAccepted, mImmutable;
|
bool mClosed, mValidHash, mAccepted, mImmutable;
|
||||||
@@ -81,7 +83,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
Ledger(const NewcoinAddress& masterID, uint64 startAmount); // used for the starting bootstrap ledger
|
Ledger(const NewcoinAddress& masterID, uint64 startAmount); // used for the starting bootstrap ledger
|
||||||
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
Ledger(const uint256 &parentHash, const uint256 &transHash, const uint256 &accountHash,
|
||||||
uint64 totCoins, uint64 timeStamp, uint32 ledgerSeq); // used for received ledgers
|
uint64 totCoins, uint64 timeStamp, uint32 ledgerSeq); // used for database ledgers
|
||||||
Ledger(const std::vector<unsigned char>& rawLedger);
|
Ledger(const std::vector<unsigned char>& rawLedger);
|
||||||
Ledger(const std::string& rawLedger);
|
Ledger(const std::string& rawLedger);
|
||||||
Ledger(Ledger::pointer previous); // ledger after this one
|
Ledger(Ledger::pointer previous); // ledger after this one
|
||||||
@@ -100,10 +102,15 @@ public:
|
|||||||
const uint256& getTransHash() const { return mTransHash; }
|
const uint256& getTransHash() const { return mTransHash; }
|
||||||
const uint256& getAccountHash() const { return mAccountHash; }
|
const uint256& getAccountHash() const { return mAccountHash; }
|
||||||
uint64 getTotalCoins() const { return mTotCoins; }
|
uint64 getTotalCoins() const { return mTotCoins; }
|
||||||
uint64 getTimeStamp() const { return mTimeStamp; }
|
uint64 getRawTimeStamp() const { return mTimeStamp; }
|
||||||
uint32 getLedgerSeq() const { return mLedgerSeq; }
|
uint32 getLedgerSeq() const { return mLedgerSeq; }
|
||||||
uint16 getInterval() const { return mLedgerInterval; }
|
uint16 getInterval() const { return mLedgerInterval; }
|
||||||
|
|
||||||
|
// close time functions
|
||||||
|
boost::posix_time::ptime getCloseTime() const;
|
||||||
|
void setCloseTime(boost::posix_time::ptime);
|
||||||
|
uint64 getNextLedgerClose() const;
|
||||||
|
|
||||||
// low level functions
|
// low level functions
|
||||||
SHAMap::pointer peekTransactionMap() { return mTransactionMap; }
|
SHAMap::pointer peekTransactionMap() { return mTransactionMap; }
|
||||||
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
|
SHAMap::pointer peekAccountStateMap() { return mAccountStateMap; }
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Transaction.h"
|
#include "Transaction.h"
|
||||||
|
|
||||||
@@ -24,11 +25,21 @@ NetworkOPs::NetworkOPs(boost::asio::io_service& io_service) : mMode(omDISCONNECT
|
|||||||
setStateTimer(5);
|
setStateTimer(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 NetworkOPs::getNetworkTime()
|
time_t NetworkOPs::getNetworkTimeTT()
|
||||||
{
|
{
|
||||||
return time(NULL);
|
return time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::posix_time::ptime NetworkOPs::getNetworkTimePT()
|
||||||
|
{
|
||||||
|
return boost::posix_time::from_time_t(getNetworkTimeTT());
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 NetworkOPs::getNetworkTimeNC()
|
||||||
|
{
|
||||||
|
return iToSeconds(getNetworkTimePT());
|
||||||
|
}
|
||||||
|
|
||||||
uint32 NetworkOPs::getCurrentLedgerID()
|
uint32 NetworkOPs::getCurrentLedgerID()
|
||||||
{
|
{
|
||||||
return theApp->getMasterLedger().getCurrentLedger()->getLedgerSeq();
|
return theApp->getMasterLedger().getCurrentLedger()->getLedgerSeq();
|
||||||
@@ -89,7 +100,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans,
|
|||||||
trans->getSTransaction()->getTransaction(*s, false);
|
trans->getSTransaction()->getTransaction(*s, false);
|
||||||
tx->set_rawtransaction(&s->getData().front(), s->getLength());
|
tx->set_rawtransaction(&s->getData().front(), s->getLength());
|
||||||
tx->set_status(newcoin::tsCURRENT);
|
tx->set_status(newcoin::tsCURRENT);
|
||||||
tx->set_receivetimestamp(getNetworkTime());
|
tx->set_receivetimestamp(getNetworkTimeNC());
|
||||||
tx->set_ledgerindexpossible(trans->getLedger());
|
tx->set_ledgerindexpossible(trans->getLedger());
|
||||||
|
|
||||||
PackedMessage::pointer packet(new PackedMessage(PackedMessage::MessagePointer(tx), newcoin::mtTRANSACTION));
|
PackedMessage::pointer packet(new PackedMessage(PackedMessage::MessagePointer(tx), newcoin::mtTRANSACTION));
|
||||||
@@ -280,8 +291,19 @@ void NetworkOPs::checkState()
|
|||||||
|
|
||||||
void NetworkOPs::switchLastClosedLedger(Ledger::pointer newLedger)
|
void NetworkOPs::switchLastClosedLedger(Ledger::pointer newLedger)
|
||||||
{ // set the newledger as our last closed ledger
|
{ // set the newledger as our last closed ledger
|
||||||
// FIXME: Must recover transactions
|
// FIXME: Correct logic is:
|
||||||
|
// 1) Mark this ledger closed, schedule it to be saved
|
||||||
|
// 2) Open a new subsequent ledger
|
||||||
|
// 3) Walk back the previous ledger chain from our current ledger and the new last closed ledger
|
||||||
|
// find a common previous ledger, if possible. Try to insert any transactions in our ledger
|
||||||
|
// chain into the new open ledger. Broadcast any that make it in.
|
||||||
|
|
||||||
Ledger::pointer openLedger = boost::make_shared<Ledger>(newLedger);
|
Ledger::pointer openLedger = boost::make_shared<Ledger>(newLedger);
|
||||||
theApp->getMasterLedger().switchLedgers(newLedger, openLedger);
|
theApp->getMasterLedger().switchLedgers(newLedger, openLedger);
|
||||||
// FIXME: Set close timer
|
|
||||||
|
#if 0
|
||||||
|
if (getNetworkTime() > openLedger->getCloseTime())
|
||||||
|
{ // this ledger has already closed
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ public:
|
|||||||
NetworkOPs(boost::asio::io_service& io_service);
|
NetworkOPs(boost::asio::io_service& io_service);
|
||||||
|
|
||||||
// network information
|
// network information
|
||||||
uint64 getNetworkTime();
|
uint64 getNetworkTimeNC();
|
||||||
|
time_t getNetworkTimeTT();
|
||||||
|
boost::posix_time::ptime getNetworkTimePT();
|
||||||
uint32 getCurrentLedgerID();
|
uint32 getCurrentLedgerID();
|
||||||
OperatingMode getOperatingMode() { return mMode; }
|
OperatingMode getOperatingMode() { return mMode; }
|
||||||
|
|
||||||
|
|||||||
@@ -774,7 +774,7 @@ void Peer::sendHello()
|
|||||||
|
|
||||||
h->set_version(theConfig.VERSION);
|
h->set_version(theConfig.VERSION);
|
||||||
h->set_ledgerindex(theApp->getOPs().getCurrentLedgerID());
|
h->set_ledgerindex(theApp->getOPs().getCurrentLedgerID());
|
||||||
h->set_nettime(theApp->getOPs().getNetworkTime());
|
h->set_nettime(theApp->getOPs().getNetworkTimeNC());
|
||||||
h->set_nodepublic(theApp->getWallet().getNodePublic().humanNodePublic());
|
h->set_nodepublic(theApp->getWallet().getNodePublic().humanNodePublic());
|
||||||
h->set_nodeproof(&vchSig[0], vchSig.size());
|
h->set_nodeproof(&vchSig[0], vchSig.size());
|
||||||
h->set_ipv4port(theConfig.PEER_PORT);
|
h->set_ipv4port(theConfig.PEER_PORT);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void SHAMap::dirtyUp(std::stack<SHAMapTreeNode::pointer>& stack, const uint256&
|
|||||||
{ // walk the tree up from through the inner nodes to the root
|
{ // walk the tree up from through the inner nodes to the root
|
||||||
// update linking hashes and add nodes to dirty list
|
// update linking hashes and add nodes to dirty list
|
||||||
|
|
||||||
assert(mState!=Synching && mState!=Immutable);
|
assert((mState != Synching) && (mState != Immutable));
|
||||||
|
|
||||||
while (!stack.empty())
|
while (!stack.empty())
|
||||||
{
|
{
|
||||||
@@ -166,7 +166,7 @@ SHAMapItem::pointer SHAMap::firstBelow(SHAMapTreeNode::pointer node)
|
|||||||
if (node->hasItem()) return node->peekItem();
|
if (node->hasItem()) return node->peekItem();
|
||||||
|
|
||||||
bool foundNode = false;
|
bool foundNode = false;
|
||||||
for(int i=0; i<16; i++)
|
for (int i = 0; i < 16; ++i)
|
||||||
if (!node->isEmptyBranch(i))
|
if (!node->isEmptyBranch(i))
|
||||||
{
|
{
|
||||||
#ifdef ST_DEBUG
|
#ifdef ST_DEBUG
|
||||||
@@ -194,7 +194,7 @@ SHAMapItem::pointer SHAMap::lastBelow(SHAMapTreeNode::pointer node)
|
|||||||
if (node->hasItem()) return node->peekItem();
|
if (node->hasItem()) return node->peekItem();
|
||||||
|
|
||||||
bool foundNode = false;
|
bool foundNode = false;
|
||||||
for(int i=15; i>=0; i++)
|
for (int i = 15; i >= 0; ++i)
|
||||||
if (!node->isEmptyBranch(i))
|
if (!node->isEmptyBranch(i))
|
||||||
{
|
{
|
||||||
node = getNode(node->getChildNodeID(i), node->getChildHash(i), false);
|
node = getNode(node->getChildNodeID(i), node->getChildHash(i), false);
|
||||||
@@ -215,7 +215,7 @@ SHAMapItem::pointer SHAMap::onlyBelow(SHAMapTreeNode::pointer node)
|
|||||||
found = false;
|
found = false;
|
||||||
SHAMapTreeNode::pointer nextNode;
|
SHAMapTreeNode::pointer nextNode;
|
||||||
|
|
||||||
for(int i=0; i<16; i++)
|
for (int i = 0; i < 16; ++i)
|
||||||
if (!node->isEmptyBranch(i))
|
if (!node->isEmptyBranch(i))
|
||||||
{
|
{
|
||||||
if( found) return SHAMapItem::pointer(); // two leaves below
|
if( found) return SHAMapItem::pointer(); // two leaves below
|
||||||
@@ -618,11 +618,11 @@ void SHAMap::dump(bool hash)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<unsigned char>IntToVUC(int i)
|
static std::vector<unsigned char>IntToVUC(int v)
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> vuc;
|
std::vector<unsigned char> vuc;
|
||||||
for(int i=0; i<32; i++)
|
for (int i = 0; i < 32; ++i)
|
||||||
vuc.push_back((unsigned char) i);
|
vuc.push_back(static_cast<unsigned char>(v));
|
||||||
return vuc;
|
return vuc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ public:
|
|||||||
// status functions
|
// status functions
|
||||||
void setImmutable(void) { assert(mState != Invalid); mState = Immutable; }
|
void setImmutable(void) { assert(mState != Invalid); mState = Immutable; }
|
||||||
void clearImmutable(void) { mState = Modifying; }
|
void clearImmutable(void) { mState = Modifying; }
|
||||||
bool isSynching(void) const { return mState == Floating || mState == Synching; }
|
bool isSynching(void) const { return (mState == Floating) || (mState == Synching); }
|
||||||
void setSynching(void) { mState = Synching; }
|
void setSynching(void) { mState = Synching; }
|
||||||
void setFloating(void) { mState = Floating; }
|
void setFloating(void) { mState = Floating; }
|
||||||
void clearSynching(void) { mState = Modifying; }
|
void clearSynching(void) { mState = Modifying; }
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ int SHAMapNode::selectBranch(const uint256& hash) const
|
|||||||
if (mDepth % 2) branch >>= 4;
|
if (mDepth % 2) branch >>= 4;
|
||||||
else branch &= 0xf;
|
else branch &= 0xf;
|
||||||
|
|
||||||
assert(branch>=0 && branch<16);
|
assert((branch >= 0) && (branch < 16));
|
||||||
return branch;
|
return branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,13 +202,13 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
|||||||
else if (type == 2)
|
else if (type == 2)
|
||||||
{ // full inner
|
{ // full inner
|
||||||
if (len != 512) throw SHAMapException(InvalidNode);
|
if (len != 512) throw SHAMapException(InvalidNode);
|
||||||
for(int i=0; i<16; i++)
|
for (int i = 0; i < 16; ++i)
|
||||||
s.get256(mHashes[i], i * 32);
|
s.get256(mHashes[i], i * 32);
|
||||||
mType = tnINNER;
|
mType = tnINNER;
|
||||||
}
|
}
|
||||||
else if (type == 3)
|
else if (type == 3)
|
||||||
{ // compressed inner
|
{ // compressed inner
|
||||||
for(int i=0; i<(len/33); i++)
|
for (int i = 0; i < (len / 33); ++i)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
s.get8(pos, 32 + (i * 33));
|
s.get8(pos, 32 + (i * 33));
|
||||||
@@ -243,7 +243,7 @@ void SHAMapTreeNode::addRaw(Serializer &s)
|
|||||||
|
|
||||||
if (getBranchCount() < 12)
|
if (getBranchCount() < 12)
|
||||||
{ // compressed node
|
{ // compressed node
|
||||||
for(int i=0; i<16; i++)
|
for (int i = 0; i < 16; ++i)
|
||||||
if (mHashes[i].isNonZero())
|
if (mHashes[i].isNonZero())
|
||||||
{
|
{
|
||||||
s.add256(mHashes[i]);
|
s.add256(mHashes[i]);
|
||||||
@@ -253,7 +253,7 @@ void SHAMapTreeNode::addRaw(Serializer &s)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0; i<16; i++)
|
for (int i = 0; i < 16; ++i)
|
||||||
s.add256(mHashes[i]);
|
s.add256(mHashes[i]);
|
||||||
s.add8(2);
|
s.add8(2);
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ bool SHAMapTreeNode::updateHash()
|
|||||||
if (mType == tnINNER)
|
if (mType == tnINNER)
|
||||||
{
|
{
|
||||||
bool empty = true;
|
bool empty = true;
|
||||||
for(int i=0; i<16; i++)
|
for (int i = 0; i < 16; ++i)
|
||||||
if (mHashes[i].isNonZero())
|
if (mHashes[i].isNonZero())
|
||||||
{
|
{
|
||||||
empty = false;
|
empty = false;
|
||||||
@@ -339,7 +339,7 @@ std::string SHAMapTreeNode::getString() const
|
|||||||
ret += ")";
|
ret += ")";
|
||||||
if (isInner())
|
if (isInner())
|
||||||
{
|
{
|
||||||
for(int i=0; i<16; i++)
|
for(int i = 0; i < 16; ++i)
|
||||||
if (!isEmptyBranch(i))
|
if (!isEmptyBranch(i))
|
||||||
{
|
{
|
||||||
ret += ",b";
|
ret += ",b";
|
||||||
|
|||||||
Reference in New Issue
Block a user