Fixes for indentation and local variable names.

This commit is contained in:
Sean Bowe
2016-07-16 16:45:41 -06:00
parent 28173cd0de
commit 22de160219
11 changed files with 113 additions and 113 deletions

View File

@@ -11,7 +11,7 @@ import os
import shutil import shutil
import sys import sys
class PourTxTest(BitcoinTestFramework): class JoinSplitTest(BitcoinTestFramework):
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []
self.is_network_split = False self.is_network_split = False
@@ -47,4 +47,4 @@ class PourTxTest(BitcoinTestFramework):
assert_equal(receive_result["exists"], True) assert_equal(receive_result["exists"], True)
if __name__ == '__main__': if __name__ == '__main__':
PourTxTest().main() JoinSplitTest().main()

View File

@@ -12,10 +12,10 @@ import shutil
import sys import sys
import time import time
class PourTxTest(BitcoinTestFramework): class JoinSplitTest(BitcoinTestFramework):
def setup_network(self): def setup_network(self):
# Start with split network: # Start with split network:
return super(PourTxTest, self).setup_network(True) return super(JoinSplitTest, self).setup_network(True)
def txid_in_mempool(self, node, txid): def txid_in_mempool(self, node, txid):
exception_triggered = False exception_triggered = False
@@ -89,27 +89,27 @@ class PourTxTest(BitcoinTestFramework):
blank_tx = self.nodes[0].createrawtransaction([], {}) blank_tx = self.nodes[0].createrawtransaction([], {})
# Create pour {A, B}->{*} # Create pour {A, B}->{*}
pour_AB = self.nodes[0].zcrawjoinsplit(blank_tx, pour_AB = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[0] : zcsecretkey, pool[1] : zcsecretkey}, {pool[0] : zcsecretkey, pool[1] : zcsecretkey},
{zcaddress:(39.9*2)-0.1}, {zcaddress:(39.9*2)-0.1},
0, 0.1) 0, 0.1)
# Create pour {B, C}->{*} # Create pour {B, C}->{*}
pour_BC = self.nodes[0].zcrawjoinsplit(blank_tx, pour_BC = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[1] : zcsecretkey, pool[2] : zcsecretkey}, {pool[1] : zcsecretkey, pool[2] : zcsecretkey},
{zcaddress:(39.9*2)-0.1}, {zcaddress:(39.9*2)-0.1},
0, 0.1) 0, 0.1)
# Create pour {C, D}->{*} # Create pour {C, D}->{*}
pour_CD = self.nodes[0].zcrawjoinsplit(blank_tx, pour_CD = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[2] : zcsecretkey, pool[3] : zcsecretkey}, {pool[2] : zcsecretkey, pool[3] : zcsecretkey},
{zcaddress:(39.9*2)-0.1}, {zcaddress:(39.9*2)-0.1},
0, 0.1) 0, 0.1)
# Create pour {A, D}->{*} # Create pour {A, D}->{*}
pour_AD = self.nodes[0].zcrawjoinsplit(blank_tx, pour_AD = self.nodes[0].zcrawjoinsplit(blank_tx,
{pool[0] : zcsecretkey, pool[3] : zcsecretkey}, {pool[0] : zcsecretkey, pool[3] : zcsecretkey},
{zcaddress:(39.9*2)-0.1}, {zcaddress:(39.9*2)-0.1},
0, 0.1) 0, 0.1)
# (a) Node 0 will spend pour AB, then attempt to # (a) Node 0 will spend pour AB, then attempt to
# double-spend it with BC. It should fail before and # double-spend it with BC. It should fail before and
@@ -180,4 +180,4 @@ class PourTxTest(BitcoinTestFramework):
sync_blocks(self.nodes) sync_blocks(self.nodes)
if __name__ == '__main__': if __name__ == '__main__':
PourTxTest().main() JoinSplitTest().main()

View File

@@ -91,10 +91,10 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "estimatepriority", 0 }, { "estimatepriority", 0 },
{ "prioritisetransaction", 1 }, { "prioritisetransaction", 1 },
{ "prioritisetransaction", 2 }, { "prioritisetransaction", 2 },
{ "zcrawpour", 1 }, { "zcrawjoinsplit", 1 },
{ "zcrawpour", 2 }, { "zcrawjoinsplit", 2 },
{ "zcrawpour", 3 }, { "zcrawjoinsplit", 3 },
{ "zcrawpour", 4 }, { "zcrawjoinsplit", 4 },
{ "zcbenchmark", 1 }, { "zcbenchmark", 1 },
{ "getblocksubsidy", 0} { "getblocksubsidy", 0}
}; };

View File

@@ -99,8 +99,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{ {
Array nullifiers; Array nullifiers;
BOOST_FOREACH(const uint256 serial, jsdescription.nullifiers) { BOOST_FOREACH(const uint256 nf, jsdescription.nullifiers) {
nullifiers.push_back(serial.GetHex()); nullifiers.push_back(nf.GetHex());
} }
joinsplit.push_back(Pair("nullifiers", nullifiers)); joinsplit.push_back(Pair("nullifiers", nullifiers));
} }

View File

@@ -217,78 +217,78 @@ BOOST_AUTO_TEST_CASE(anchors_flush_test)
} }
} }
BOOST_AUTO_TEST_CASE(chained_pours) BOOST_AUTO_TEST_CASE(chained_joinsplits)
{ {
CCoinsViewTest base; CCoinsViewTest base;
CCoinsViewCacheTest cache(&base); CCoinsViewCacheTest cache(&base);
ZCIncrementalMerkleTree tree; ZCIncrementalMerkleTree tree;
JSDescription ptx1; JSDescription js1;
ptx1.anchor = tree.root(); js1.anchor = tree.root();
ptx1.commitments[0] = appendRandomCommitment(tree); js1.commitments[0] = appendRandomCommitment(tree);
ptx1.commitments[1] = appendRandomCommitment(tree); js1.commitments[1] = appendRandomCommitment(tree);
// Although it's not possible given our assumptions, if // Although it's not possible given our assumptions, if
// two pours create the same treestate twice, we should // two joinsplits create the same treestate twice, we should
// still be able to anchor to it. // still be able to anchor to it.
JSDescription ptx1b; JSDescription js1b;
ptx1b.anchor = tree.root(); js1b.anchor = tree.root();
ptx1b.commitments[0] = ptx1.commitments[0]; js1b.commitments[0] = js1.commitments[0];
ptx1b.commitments[1] = ptx1.commitments[1]; js1b.commitments[1] = js1.commitments[1];
JSDescription ptx2; JSDescription js2;
JSDescription ptx3; JSDescription js3;
ptx2.anchor = tree.root(); js2.anchor = tree.root();
ptx3.anchor = tree.root(); js3.anchor = tree.root();
ptx2.commitments[0] = appendRandomCommitment(tree); js2.commitments[0] = appendRandomCommitment(tree);
ptx2.commitments[1] = appendRandomCommitment(tree); js2.commitments[1] = appendRandomCommitment(tree);
ptx3.commitments[0] = appendRandomCommitment(tree); js3.commitments[0] = appendRandomCommitment(tree);
ptx3.commitments[1] = appendRandomCommitment(tree); js3.commitments[1] = appendRandomCommitment(tree);
{ {
CMutableTransaction mtx; CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx2); mtx.vjoinsplit.push_back(js2);
BOOST_CHECK(!cache.HaveJoinSplitRequirements(mtx)); BOOST_CHECK(!cache.HaveJoinSplitRequirements(mtx));
} }
{ {
// ptx2 is trying to anchor to ptx1 but ptx1 // js2 is trying to anchor to js1 but js1
// appears afterwards -- not a permitted ordering // appears afterwards -- not a permitted ordering
CMutableTransaction mtx; CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx2); mtx.vjoinsplit.push_back(js2);
mtx.vjoinsplit.push_back(ptx1); mtx.vjoinsplit.push_back(js1);
BOOST_CHECK(!cache.HaveJoinSplitRequirements(mtx)); BOOST_CHECK(!cache.HaveJoinSplitRequirements(mtx));
} }
{ {
CMutableTransaction mtx; CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx1); mtx.vjoinsplit.push_back(js1);
mtx.vjoinsplit.push_back(ptx2); mtx.vjoinsplit.push_back(js2);
BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx)); BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx));
} }
{ {
CMutableTransaction mtx; CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx1); mtx.vjoinsplit.push_back(js1);
mtx.vjoinsplit.push_back(ptx2); mtx.vjoinsplit.push_back(js2);
mtx.vjoinsplit.push_back(ptx3); mtx.vjoinsplit.push_back(js3);
BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx)); BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx));
} }
{ {
CMutableTransaction mtx; CMutableTransaction mtx;
mtx.vjoinsplit.push_back(ptx1); mtx.vjoinsplit.push_back(js1);
mtx.vjoinsplit.push_back(ptx1b); mtx.vjoinsplit.push_back(js1b);
mtx.vjoinsplit.push_back(ptx2); mtx.vjoinsplit.push_back(js2);
mtx.vjoinsplit.push_back(ptx3); mtx.vjoinsplit.push_back(js3);
BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx)); BOOST_CHECK(cache.HaveJoinSplitRequirements(mtx));
} }

View File

@@ -105,7 +105,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0; tx.nLockTime = (insecure_rand() % 2) ? insecure_rand() : 0;
int ins = (insecure_rand() % 4) + 1; int ins = (insecure_rand() % 4) + 1;
int outs = fSingle ? ins : (insecure_rand() % 4) + 1; int outs = fSingle ? ins : (insecure_rand() % 4) + 1;
int pours = (insecure_rand() % 4); int joinsplits = (insecure_rand() % 4);
for (int in = 0; in < ins; in++) { for (int in = 0; in < ins; in++) {
tx.vin.push_back(CTxIn()); tx.vin.push_back(CTxIn());
CTxIn &txin = tx.vin.back(); CTxIn &txin = tx.vin.back();
@@ -121,26 +121,26 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
RandomScript(txout.scriptPubKey); RandomScript(txout.scriptPubKey);
} }
if (tx.nVersion >= 2) { if (tx.nVersion >= 2) {
for (int pour = 0; pour < pours; pour++) { for (int js = 0; js < joinsplits; js++) {
JSDescription pourtx; JSDescription jsdesc;
if (insecure_rand() % 2 == 0) { if (insecure_rand() % 2 == 0) {
pourtx.vpub_old = insecure_rand() % 100000000; jsdesc.vpub_old = insecure_rand() % 100000000;
} else { } else {
pourtx.vpub_new = insecure_rand() % 100000000; jsdesc.vpub_new = insecure_rand() % 100000000;
} }
pourtx.anchor = GetRandHash(); jsdesc.anchor = GetRandHash();
pourtx.nullifiers[0] = GetRandHash(); jsdesc.nullifiers[0] = GetRandHash();
pourtx.nullifiers[1] = GetRandHash(); jsdesc.nullifiers[1] = GetRandHash();
pourtx.ephemeralKey = GetRandHash(); jsdesc.ephemeralKey = GetRandHash();
pourtx.randomSeed = GetRandHash(); jsdesc.randomSeed = GetRandHash();
randombytes_buf(pourtx.ciphertexts[0].begin(), pourtx.ciphertexts[0].size()); randombytes_buf(jsdesc.ciphertexts[0].begin(), jsdesc.ciphertexts[0].size());
randombytes_buf(pourtx.ciphertexts[1].begin(), pourtx.ciphertexts[1].size()); randombytes_buf(jsdesc.ciphertexts[1].begin(), jsdesc.ciphertexts[1].size());
randombytes_buf(pourtx.proof.begin(), pourtx.proof.size()); randombytes_buf(jsdesc.proof.begin(), jsdesc.proof.size());
pourtx.macs[0] = GetRandHash(); jsdesc.macs[0] = GetRandHash();
pourtx.macs[1] = GetRandHash(); jsdesc.macs[1] = GetRandHash();
tx.vjoinsplit.push_back(pourtx); tx.vjoinsplit.push_back(jsdesc);
} }
unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES]; unsigned char joinSplitPrivKey[crypto_sign_SECRETKEYBYTES];

View File

@@ -18,7 +18,7 @@
using namespace std; using namespace std;
static const char DB_ANCHOR = 'A'; static const char DB_ANCHOR = 'A';
static const char DB_SERIAL = 's'; static const char DB_NULLIFIER = 's';
static const char DB_COINS = 'c'; static const char DB_COINS = 'c';
static const char DB_BLOCK_FILES = 'f'; static const char DB_BLOCK_FILES = 'f';
static const char DB_TXINDEX = 't'; static const char DB_TXINDEX = 't';
@@ -43,11 +43,11 @@ void static BatchWriteAnchor(CLevelDBBatch &batch,
} }
} }
void static BatchWriteSerial(CLevelDBBatch &batch, const uint256 &serial, const bool &entered) { void static BatchWriteNullifier(CLevelDBBatch &batch, const uint256 &nf, const bool &entered) {
if (!entered) if (!entered)
batch.Erase(make_pair(DB_SERIAL, serial)); batch.Erase(make_pair(DB_NULLIFIER, nf));
else else
batch.Write(make_pair(DB_SERIAL, serial), true); batch.Write(make_pair(DB_NULLIFIER, nf), true);
} }
void static BatchWriteCoins(CLevelDBBatch &batch, const uint256 &hash, const CCoins &coins) { void static BatchWriteCoins(CLevelDBBatch &batch, const uint256 &hash, const CCoins &coins) {
@@ -81,9 +81,9 @@ bool CCoinsViewDB::GetAnchorAt(const uint256 &rt, ZCIncrementalMerkleTree &tree)
return read; return read;
} }
bool CCoinsViewDB::GetNullifier(const uint256 &serial) const { bool CCoinsViewDB::GetNullifier(const uint256 &nf) const {
bool spent = false; bool spent = false;
bool read = db.Read(make_pair(DB_SERIAL, serial), spent); bool read = db.Read(make_pair(DB_NULLIFIER, nf), spent);
return read; return read;
} }
@@ -139,7 +139,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
for (CNullifiersMap::iterator it = mapNullifiers.begin(); it != mapNullifiers.end();) { for (CNullifiersMap::iterator it = mapNullifiers.begin(); it != mapNullifiers.end();) {
if (it->second.flags & CNullifiersCacheEntry::DIRTY) { if (it->second.flags & CNullifiersCacheEntry::DIRTY) {
BatchWriteSerial(batch, it->first, it->second.entered); BatchWriteNullifier(batch, it->first, it->second.entered);
// TODO: changed++? // TODO: changed++?
} }
CNullifiersMap::iterator itOld = it++; CNullifiersMap::iterator itOld = it++;

View File

@@ -100,8 +100,8 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
for (unsigned int i = 0; i < tx.vin.size(); i++) for (unsigned int i = 0; i < tx.vin.size(); i++)
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i); mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &serial, joinsplit.nullifiers) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
mapNullifiers[serial] = &tx; mapNullifiers[nf] = &tx;
} }
} }
nTransactionsUpdated++; nTransactionsUpdated++;
@@ -149,8 +149,8 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
BOOST_FOREACH(const CTxIn& txin, tx.vin) BOOST_FOREACH(const CTxIn& txin, tx.vin)
mapNextTx.erase(txin.prevout); mapNextTx.erase(txin.prevout);
BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256& serial, joinsplit.nullifiers) { BOOST_FOREACH(const uint256& nf, joinsplit.nullifiers) {
mapNullifiers.erase(serial); mapNullifiers.erase(nf);
} }
} }
@@ -231,8 +231,8 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
} }
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &serial, joinsplit.nullifiers) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
std::map<uint256, const CTransaction*>::iterator it = mapNullifiers.find(serial); std::map<uint256, const CTransaction*>::iterator it = mapNullifiers.find(nf);
if (it != mapNullifiers.end()) { if (it != mapNullifiers.end()) {
const CTransaction &txConflict = *it->second; const CTransaction &txConflict = *it->second;
if (txConflict != tx) if (txConflict != tx)
@@ -318,8 +318,8 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates; boost::unordered_map<uint256, ZCIncrementalMerkleTree, CCoinsKeyHasher> intermediates;
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &serial, joinsplit.nullifiers) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
assert(!pcoins->GetNullifier(serial)); assert(!pcoins->GetNullifier(nf));
} }
ZCIncrementalMerkleTree tree; ZCIncrementalMerkleTree tree;
@@ -484,11 +484,11 @@ bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const
CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { } CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView *baseIn, CTxMemPool &mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { }
bool CCoinsViewMemPool::GetNullifier(const uint256 &serial) const { bool CCoinsViewMemPool::GetNullifier(const uint256 &nf) const {
if (mempool.mapNullifiers.count(serial)) if (mempool.mapNullifiers.count(nf))
return true; return true;
return base->GetNullifier(serial); return base->GetNullifier(nf);
} }
bool CCoinsViewMemPool::GetCoins(const uint256 &txid, CCoins &coins) const { bool CCoinsViewMemPool::GetCoins(const uint256 &txid, CCoins &coins) const {

View File

@@ -2644,17 +2644,17 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
mtx.nVersion = 2; mtx.nVersion = 2;
mtx.joinSplitPubKey = joinSplitPubKey; mtx.joinSplitPubKey = joinSplitPubKey;
JSDescription jsdescription(*pzcashParams, JSDescription jsdesc(*pzcashParams,
joinSplitPubKey, joinSplitPubKey,
anchor, anchor,
{vjsin[0], vjsin[1]}, {vjsin[0], vjsin[1]},
{vjsout[0], vjsout[1]}, {vjsout[0], vjsout[1]},
vpub_old, vpub_old,
vpub_new); vpub_new);
assert(jsdescription.Verify(*pzcashParams, joinSplitPubKey)); assert(jsdesc.Verify(*pzcashParams, joinSplitPubKey));
mtx.vjoinsplit.push_back(jsdescription); mtx.vjoinsplit.push_back(jsdesc);
// TODO: #966. // TODO: #966.
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001")); static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
@@ -2688,18 +2688,18 @@ Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp)
{ {
CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION);
ss2 << ((unsigned char) 0x00); ss2 << ((unsigned char) 0x00);
ss2 << jsdescription.ephemeralKey; ss2 << jsdesc.ephemeralKey;
ss2 << jsdescription.ciphertexts[0]; ss2 << jsdesc.ciphertexts[0];
ss2 << jsdescription.h_sig(*pzcashParams, joinSplitPubKey); ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey);
encryptedNote1 = HexStr(ss2.begin(), ss2.end()); encryptedNote1 = HexStr(ss2.begin(), ss2.end());
} }
{ {
CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss2(SER_NETWORK, PROTOCOL_VERSION);
ss2 << ((unsigned char) 0x01); ss2 << ((unsigned char) 0x01);
ss2 << jsdescription.ephemeralKey; ss2 << jsdesc.ephemeralKey;
ss2 << jsdescription.ciphertexts[1]; ss2 << jsdesc.ciphertexts[1];
ss2 << jsdescription.h_sig(*pzcashParams, joinSplitPubKey); ss2 << jsdesc.h_sig(*pzcashParams, joinSplitPubKey);
encryptedNote2 = HexStr(ss2.begin(), ss2.end()); encryptedNote2 = HexStr(ss2.begin(), ss2.end());
} }

View File

@@ -1065,9 +1065,9 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
BOOST_FOREACH(const CTransaction& tx, block.vtx) BOOST_FOREACH(const CTransaction& tx, block.vtx)
{ {
BOOST_FOREACH(const JSDescription& pour, tx.vjoinsplit) BOOST_FOREACH(const JSDescription& jsdesc, tx.vjoinsplit)
{ {
BOOST_FOREACH(const uint256 &note_commitment, pour.commitments) BOOST_FOREACH(const uint256 &note_commitment, jsdesc.commitments)
{ {
tree.append(note_commitment); tree.append(note_commitment);

View File

@@ -76,16 +76,16 @@ double benchmark_create_joinsplit()
uint256 anchor = ZCIncrementalMerkleTree().root(); uint256 anchor = ZCIncrementalMerkleTree().root();
timer_start(); timer_start();
JSDescription jsdescription(*pzcashParams, JSDescription jsdesc(*pzcashParams,
pubKeyHash, pubKeyHash,
anchor, anchor,
{JSInput(), JSInput()}, {JSInput(), JSInput()},
{JSOutput(), JSOutput()}, {JSOutput(), JSOutput()},
0, 0,
0); 0);
double ret = timer_stop(); double ret = timer_stop();
assert(jsdescription.Verify(*pzcashParams, pubKeyHash)); assert(jsdesc.Verify(*pzcashParams, pubKeyHash));
return ret; return ret;
} }