Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2012-05-15 18:21:51 -07:00
6 changed files with 38 additions and 42 deletions

View File

@@ -48,7 +48,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>BOOST_TEST_NO_MAIN;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=0x0501;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>BOOST_TEST_ALTERNATIVE_INIT_API;BOOST_TEST_NO_MAIN;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=0x0501;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\OpenSSL\include;..\boost_1_47_0;..\protobuf-2.4.1\src\</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\OpenSSL\include;..\boost_1_47_0;..\protobuf-2.4.1\src\</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>

View File

@@ -557,7 +557,7 @@ Json::Value RPCServer::doLedger(Json::Value& params)
int paramCount = getParamCount(params); int paramCount = getParamCount(params);
if (paramCount == 0); if (paramCount == 0)
{ {
Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue); Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue);
theApp->getMasterLedger().getCurrentLedger()->addJson(current); theApp->getMasterLedger().getCurrentLedger()->addJson(current);

View File

@@ -56,7 +56,7 @@ void SHAMap::dirtyUp(std::stack<SHAMapTreeNode::pointer>& stack, const uint256&
while (!stack.empty()) while (!stack.empty())
{ {
SHAMapTreeNode::pointer node=stack.top(); SHAMapTreeNode::pointer node = stack.top();
stack.pop(); stack.pop();
assert(node->isInnerNode()); assert(node->isInnerNode());
@@ -111,7 +111,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has
SHAMapTreeNode::pointer node = checkCacheNode(id); SHAMapTreeNode::pointer node = checkCacheNode(id);
if (node) if (node)
{ {
if (node->getNodeHash()!=hash) if (node->getNodeHash() != hash)
{ {
#ifdef DEBUG #ifdef DEBUG
std::cerr << "Attempt to get node, hash not in tree" << std::endl; std::cerr << "Attempt to get node, hash not in tree" << std::endl;
@@ -127,7 +127,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has
} }
std::vector<unsigned char> nodeData; std::vector<unsigned char> nodeData;
if(!fetchNode(hash, nodeData)) return SHAMapTreeNode::pointer(); if (!fetchNode(hash, nodeData)) return SHAMapTreeNode::pointer();
node = boost::make_shared<SHAMapTreeNode>(id, nodeData, mSeq); node = boost::make_shared<SHAMapTreeNode>(id, nodeData, mSeq);
if (node->getNodeHash() != hash) throw SHAMapException(InvalidNode); if (node->getNodeHash() != hash) throw SHAMapException(InvalidNode);
@@ -140,7 +140,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has
void SHAMap::returnNode(SHAMapTreeNode::pointer& node, bool modify) void SHAMap::returnNode(SHAMapTreeNode::pointer& node, bool modify)
{ // make sure the node is suitable for the intended operation (copy on write) { // make sure the node is suitable for the intended operation (copy on write)
assert(node->isValid()); assert(node->isValid());
if (node && modify && (node->getSeq()!=mSeq)) if (node && modify && (node->getSeq() != mSeq))
{ {
#ifdef DEBUG #ifdef DEBUG
std::cerr << "returnNode COW" << std::endl; std::cerr << "returnNode COW" << std::endl;
@@ -344,10 +344,10 @@ SHAMapItem::pointer SHAMap::peekItem(const uint256& id)
bool SHAMap::hasItem(const uint256& id) bool SHAMap::hasItem(const uint256& id)
{ // does the tree have an item with this ID { // does the tree have an item with this ID
boost::recursive_mutex::scoped_lock sl(mLock); boost::recursive_mutex::scoped_lock sl(mLock);
SHAMapTreeNode::pointer leaf=walkTo(id, false); SHAMapTreeNode::pointer leaf = walkTo(id, false);
if(!leaf) return false; if (!leaf) return false;
SHAMapItem::pointer item=leaf->peekItem(); SHAMapItem::pointer item = leaf->peekItem();
if(!item || item->getTag()!=id) return false; if (!item || item->getTag() != id) return false;
return true; return true;
} }
@@ -424,22 +424,19 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction)
std::cerr << "aGI " << item->getTag().GetHex() << std::endl; std::cerr << "aGI " << item->getTag().GetHex() << std::endl;
#endif #endif
uint256 tag=item->getTag(); uint256 tag = item->getTag();
SHAMapTreeNode::TNType type=isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE; SHAMapTreeNode::TNType type = isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE;
boost::recursive_mutex::scoped_lock sl(mLock); boost::recursive_mutex::scoped_lock sl(mLock);
std::stack<SHAMapTreeNode::pointer> stack=getStack(tag, true); std::stack<SHAMapTreeNode::pointer> stack = getStack(tag, true);
if(stack.empty()) throw SHAMapException(MissingNode); if (stack.empty()) throw SHAMapException(MissingNode);
SHAMapTreeNode::pointer node=stack.top(); SHAMapTreeNode::pointer node=stack.top();
stack.pop(); stack.pop();
if( node->isLeaf() && (node->peekItem()->getTag()==tag) ) if (node->isLeaf() && (node->peekItem()->getTag() == tag))
{ throw std::runtime_error("addGiveItem ends on leaf with same tag");
std::cerr << "addGiveItem ends on leaf with same tag" << std::endl;
return false;
}
uint256 prevHash; uint256 prevHash;
returnNode(node, true); returnNode(node, true);
@@ -449,9 +446,9 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction)
#ifdef ST_DEBUG #ifdef ST_DEBUG
std::cerr << "aGI inner " << node->getString() << std::endl; std::cerr << "aGI inner " << node->getString() << std::endl;
#endif #endif
int branch=node->selectBranch(tag); int branch = node->selectBranch(tag);
assert(node->isEmptyBranch(branch)); assert(node->isEmptyBranch(branch));
SHAMapTreeNode::pointer newNode= SHAMapTreeNode::pointer newNode =
boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(branch), item, type, mSeq); boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(branch), item, type, mSeq);
if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second)
{ {
@@ -467,45 +464,44 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction)
#ifdef ST_DEBUG #ifdef ST_DEBUG
std::cerr << "aGI leaf " << node->getString() << std::endl; std::cerr << "aGI leaf " << node->getString() << std::endl;
#endif #endif
SHAMapItem::pointer otherItem=node->peekItem(); SHAMapItem::pointer otherItem = node->peekItem();
assert(otherItem && (tag!=otherItem->getTag()) ); assert(otherItem && (tag != otherItem->getTag()) );
node->makeInner(); node->makeInner();
int b1, b2; int b1, b2;
while( (b1=node->selectBranch(tag)) == (b2=node->selectBranch(otherItem->getTag())) ) while ((b1 = node->selectBranch(tag)) == (b2 = node->selectBranch(otherItem->getTag())))
{ // we need a new inner node, since both go on same branch at this level { // we need a new inner node, since both go on same branch at this level
#ifdef ST_DEBUG #ifdef ST_DEBUG
std::cerr << "need new inner node at " << node->getDepth() << std::endl; std::cerr << "need new inner node at " << node->getDepth() << std::endl;
#endif #endif
SHAMapTreeNode::pointer newNode=boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b1), mSeq); SHAMapTreeNode::pointer newNode =
boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b1), mSeq);
newNode->makeInner(); newNode->makeInner();
if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second)
assert(false); assert(false);
stack.push(node); stack.push(node);
node=newNode; node = newNode;
} }
// we can add the two leaf nodes here // we can add the two leaf nodes here
assert(node->isInner()); assert(node->isInner());
SHAMapTreeNode::pointer newNode= SHAMapTreeNode::pointer newNode =
boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b1), item, type, mSeq); boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b1), item, type, mSeq);
assert(newNode->isValid() && newNode->isLeaf()); assert(newNode->isValid() && newNode->isLeaf());
if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) if (!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second)
assert(false); assert(false);
node->setChildHash(b1, newNode->getNodeHash()); // OPTIMIZEME hash op not needed node->setChildHash(b1, newNode->getNodeHash()); // OPTIMIZEME hash op not needed
newNode=boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b2), otherItem, type, mSeq); newNode = boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b2), otherItem, type, mSeq);
assert(newNode->isValid() && newNode->isLeaf()); assert(newNode->isValid() && newNode->isLeaf());
if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second)
assert(false); assert(false);
node->setChildHash(b2, newNode->getNodeHash()); node->setChildHash(b2, newNode->getNodeHash());
} }
prevHash=node->getNodeHash(); dirtyUp(stack, tag, node->getNodeHash());
assert(prevHash.isNonZero());
dirtyUp(stack, tag, prevHash);
return true; return true;
} }
@@ -516,17 +512,17 @@ bool SHAMap::addItem(const SHAMapItem& i, bool isTransaction)
bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction) bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction)
{ // can't change the tag but can change the hash { // can't change the tag but can change the hash
uint256 tag=item->getTag(); uint256 tag = item->getTag();
boost::recursive_mutex::scoped_lock sl(mLock); boost::recursive_mutex::scoped_lock sl(mLock);
std::stack<SHAMapTreeNode::pointer> stack = getStack(tag, true); std::stack<SHAMapTreeNode::pointer> stack = getStack(tag, true);
if (stack.empty()) throw SHAMapException(MissingNode); if (stack.empty()) throw SHAMapException(MissingNode);
SHAMapTreeNode::pointer node=stack.top(); SHAMapTreeNode::pointer node = stack.top();
stack.pop(); stack.pop();
if (!node->isLeaf() || (node->peekItem()->getTag() != tag) ) if (!node->isLeaf() || (node->peekItem()->getTag() != tag))
{ {
assert(false); assert(false);
return false; return false;
@@ -534,7 +530,7 @@ bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction)
returnNode(node, true); returnNode(node, true);
if (!node->setItem(item, isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE)) if (!node->setItem(item, isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE))
return true; return false;
dirtyUp(stack, tag, node->getNodeHash()); dirtyUp(stack, tag, node->getNodeHash());
return true; return true;

View File

@@ -278,7 +278,7 @@ bool SHAMapTreeNode::updateHash()
{ {
Serializer s; Serializer s;
mItem->addRaw(s); mItem->addRaw(s);
s.add160(mItem->getTag().to160()); s.add256(mItem->getTag());
nh = s.getSHA512Half(); nh = s.getSHA512Half();
} }
else if (mType == tnTRANSACTION) else if (mType == tnTRANSACTION)
@@ -299,7 +299,7 @@ bool SHAMapTreeNode::setItem(SHAMapItem::pointer& i, TNType type)
mItem = i; mItem = i;
assert(isLeaf()); assert(isLeaf());
updateHash(); updateHash();
return getNodeHash() == hash; return getNodeHash() != hash;
} }
SHAMapItem::pointer SHAMapTreeNode::getItem() const SHAMapItem::pointer SHAMapTreeNode::getItem() const

View File

@@ -189,7 +189,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran
if (result == terSUCCESS) if (result == terSUCCESS)
{ // Write back the account states and add the transaction to the ledger { // Write back the account states and add the transaction to the ledger
// WRITEME: Special case code for changing transaction key // WRITEME: Special case code for changing transaction key
for (std::vector<AffectedAccount>::iterator it=accounts.begin(), end=accounts.end(); for (std::vector<AffectedAccount>::iterator it = accounts.begin(), end = accounts.end();
it != end; ++it) it != end; ++it)
{ {
if (it->first == taaCREATE) if (it->first == taaCREATE)

View File

@@ -70,10 +70,10 @@ int main(int argc, char* argv[])
("help,h", "Display this message.") ("help,h", "Display this message.")
("rpc", "Perform rpc command (default).") ("rpc", "Perform rpc command (default).")
("test,t", "Perform unit tests.") ("test,t", "Perform unit tests.")
("parameters", po::value< vector<string> >(), "Specify comma seperated parameters.") ("parameters", po::value< vector<string> >(), "Specify comma separated parameters.")
; ;
// Interpert positional arguments as --parameters. // Interpret positional arguments as --parameters.
po::positional_options_description p; po::positional_options_description p;
p.add("parameters", -1); p.add("parameters", -1);
@@ -124,7 +124,7 @@ int main(int argc, char* argv[])
pvCmd.push_back(const_cast<char*>(param.c_str())); pvCmd.push_back(const_cast<char*>(param.c_str()));
} }
// iResult = unit_test_main(init_unit_test, iCmd, &pvCmd[0]); iResult = unit_test_main(init_unit_test, iCmd, &pvCmd[0]);
} }
else if (!vm.count("parameters")) else if (!vm.count("parameters"))
{ {