remove unused leveldb code.

This commit is contained in:
Christopher Jeffrey 2014-12-01 14:57:18 -08:00
parent 4a6a3b1243
commit e1722b0a63
1 changed files with 0 additions and 634 deletions

View File

@ -188,8 +188,6 @@ using namespace v8;
// LevelDB options
#define USE_LDB_ADDR 0
#define USE_LDB_FILES 1
#define USE_LDB_BLOCK 1
/**
* Node.js Exposed Function Templates
@ -5867,43 +5865,6 @@ jstx_to_ctx(const Local<Object> jstx, CTransaction& ctx_) {
}
#if USE_LDB_ADDR
static leveldb::Options
GetOptions(size_t nCacheSize) {
leveldb::Options options;
options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
options.write_buffer_size = nCacheSize / 4; // up to two write buffers may be held in memory simultaneously
options.filter_policy = leveldb::NewBloomFilterPolicy(10);
options.compression = leveldb::kNoCompression;
options.max_open_files = 64;
if (leveldb::kMajorVersion > 1 || (leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16)) {
// LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
// on corruption in later versions.
options.paranoid_checks = true;
}
return options;
}
// http://leveldb.googlecode.com/svn/tags/1.17/doc/index.html
#if 0
class TwoPartComparator : public leveldb::Comparator {
public:
int Compare(const leveldb::Slice& key, const leveldb::Slice& end) const {
std::string key_ = key.ToString();
const char *k = key_.c_str();
#if USE_LDB_BLOCK
if (k[0] == 'b') return -1;
#else
if (k[0] == 't') return -1;
#endif
return 1;
}
const char* Name() const { return "TwoPartComparator"; }
void FindShortestSeparator(std::string*, const leveldb::Slice&) const { }
void FindShortSuccessor(std::string*) const { }
};
#endif
static ctx_list *
read_addr(const std::string addr) {
ctx_list *head = new ctx_list();
@ -5982,70 +5943,6 @@ read_addr(const std::string addr) {
}
}
}
#if 0
if (k[0] == 't') {
char *txhash_ = strdup(k);
txhash_++;
std::string stxhash = std::string(txhash_);
uint256 txhash(stxhash);
leveldb::Slice slValue = pcursor->value();
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
CTransaction ctx;
ssValue >> ctx;
BOOST_FOREACH(const CTxIn& txin, ctx.vin) {
if (txin.scriptSig.ToString() != expectedScriptSig.ToString()) {
continue;
}
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
goto found;
}
for (unsigned int vo = 0; vo < ctx.vout.size(); vo++) {
const CTxOut& txout = ctx.vout[vo];
const CScript& scriptPubKey = txout.scriptPubKey;
int nRequired;
txnouttype type;
vector<CTxDestination> addresses;
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
continue;
}
BOOST_FOREACH(const CTxDestination& address, addresses) {
if (CBitcoinAddress(address).ToString() != addr) {
continue;
}
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
goto found;
}
}
}
#endif
found:
pcursor->Next();
}
@ -6053,537 +5950,6 @@ found:
return head;
}
#if 0
static ctx_list *
read_addr(const std::string addr) {
ctx_list *head = new ctx_list();
ctx_list *cur = NULL;
#if 0
// XXX TEST
const CBlock& cblock = Params().GenesisBlock();
CTransaction ctx = cblock.vtx[0];
if (cur == NULL) {
head->ctx = ctx;
//uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
//head->blockhash = hash;
head->blockhash = cblock.GetHash();
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
//uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
//item->blockhash = hash;
item->blockhash = cblock.GetHash();
item->next = NULL;
cur->next = item;
cur = item;
}
return head;
#endif
// custom environment this database is using (may be NULL in case of default environment)
leveldb::Env* penv;
// database options used
leveldb::Options options;
// options used when reading from the database
leveldb::ReadOptions readoptions;
// options used when iterating over values of the database
leveldb::ReadOptions iteroptions;
// options used when writing to the database
leveldb::WriteOptions writeoptions;
// options used when sync writing to the database
leveldb::WriteOptions syncoptions;
// the database itself
leveldb::DB* pdb;
size_t nCacheSize = 0x100000;
bool fMemory = false;
bool fWipe = false;
// Options:
// https://code.google.com/p/leveldb/source/browse/include/leveldb/options.h
penv = NULL;
readoptions.verify_checksums = true;
iteroptions.verify_checksums = true;
iteroptions.fill_cache = false;
syncoptions.sync = true;
options = GetOptions(nCacheSize);
//options.create_if_missing = true;
options.create_if_missing = false;
#if 0
TwoPartComparator cmp;
options.comparator = &cmp;
#endif
#if 0
int64_t nMaxDbCache = sizeof(void*) > 4 ? 4096 : 1024;
size_t nTotalCache = (100 << 20);
if (nTotalCache < (4 << 20)) {
nTotalCache = (4 << 20);
} else if (nTotalCache > (nMaxDbCache << 20)) {
nTotalCache = (nMaxDbCache << 20);
}
size_t nBlockTreeDBCache = nTotalCache / 8;
if (nBlockTreeDBCache > (1 << 21)) {
nBlockTreeDBCache = (1 << 21);
}
UnloadBlockIndex();
pblocktree->Flush();
delete pblocktree;
// after:
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
#endif
do {
// ~/bitcoin/src/txdb.cpp
// pblocktree = 'CBlockTreeDB'
// ~/bitcoin/src/init.cpp
// ~/bitcoin/src/main.cpp
// const boost::filesystem::path path = GetDataDir() / "chainstate";
// CLevelDBWrapper db(path, nCacheSize, fMemory, fWipe);
// leveldb::Iterator *pcursor = const_cast<CLevelDBWrapper*>(&db)->NewIterator();
const boost::filesystem::path path = GetDataDir() / "chainstate";
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
if (!status.ok()) break;
leveldb::Iterator* pcursor = pdb->NewIterator(iteroptions);
pcursor->SeekToFirst();
while (pcursor->Valid()) {
boost::this_thread::interruption_point();
try {
leveldb::Slice slKey = pcursor->key();
CDataStream ssKey(slKey.data(), slKey.data() + slKey.size(), SER_DISK, CLIENT_VERSION);
char chType;
ssKey >> chType;
if (chType == 'c') {
leveldb::Slice slValue = pcursor->value();
CDataStream ssValue(slValue.data(), slValue.data() + slValue.size(), SER_DISK, CLIENT_VERSION);
CCoins coins;
ssValue >> coins;
uint256 txhash;
ssKey >> txhash;
#if 0
// XXX TEST
const CBlock& cblock = Params().GenesisBlock();
CTransaction ctx = cblock.vtx[0];
if (cur == NULL) {
head->ctx = ctx;
//uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
//head->blockhash = hash;
head->blockhash = cblock.GetHash();
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
//uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
//item->blockhash = hash;
item->blockhash = cblock.GetHash();
item->next = NULL;
cur->next = item;
cur = item;
}
goto done;
#endif
#if 0
// XXX TEST
CTransaction ctx;
CBlock cblock;
uint256 blockhash = 0;
if (GetTransaction(txhash, ctx, blockhash, true)) {
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
}
goto done;
#endif
for (unsigned int i = 0; i < coins.vout.size(); i++) {
const CTxOut &out = coins.vout[i];
if (out.IsNull()) {
continue;
}
const CScript& scriptPubKey = out.scriptPubKey;
int nRequired;
txnouttype type;
vector<CTxDestination> addresses;
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
continue;
}
CTransaction ctx;
CBlock cblock;
BOOST_FOREACH(const CTxDestination& address, addresses) {
if (CBitcoinAddress(address).ToString() != addr) {
continue;
}
uint256 blockhash = 0;
if (GetTransaction(txhash, ctx, blockhash, true)) {
goto found_tx;
} else {
int64_t i = 0;
int64_t height = chainActive.Height();
for (; i <= height; i++) {
CBlockIndex* pblockindex = chainActive[i];
if (ReadBlockFromDisk(cblock, pblockindex)) {
BOOST_FOREACH(const CTransaction& tx, cblock.vtx) {
if (tx.GetHash() == txhash) {
ctx = tx;
goto found_tx;
}
}
}
}
continue;
}
found_tx:
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
goto found;
}
}
}
found:
pcursor->Next();
} catch (std::exception &e) {
//return error("%s : Deserialize or I/O error - %s", __func__, e.what());
delete pcursor;
return head;
}
}
//found:
done:
// XXX Maybe put delete it before continue below too:
//assert(pcursor->status().ok());
delete pcursor;
continue;
} while (0);
return head;
#if 0
CScript expectedScriptSig = GetScriptForDestination(CBitcoinAddress(addr).Get());
#if USE_LDB_FILES
unsigned int nFile = 0;
unsigned int tryFiles = chainActive.Height();
for (; nFile <= tryFiles; nFile++) {
const boost::filesystem::path path = GetDataDir() / "blocks" / strprintf("%s%05u.dat", "blk", nFile);
#else
do {
const boost::filesystem::path path = GetDataDir() / "blocks" / "index";
#endif
#if 1
if (fMemory) {
penv = leveldb::NewMemEnv(leveldb::Env::Default());
options.env = penv;
}
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
if (!status.ok()) {
continue;
//break;
}
//leveldb::Iterator* it = pdb->NewIterator(leveldb::ReadOptions());
leveldb::Iterator* it = pdb->NewIterator(iteroptions);
#else
// ~/bitcoin/src/txdb.cpp
CLevelDBWrapper db(path, nCacheSize, fMemory, fWipe);
leveldb::Iterator *it = const_cast<CLevelDBWrapper*>(&db)->NewIterator();
#endif
for (it->SeekToFirst(); it->Valid(); it->Next()) {
boost::this_thread::interruption_point();
#if USE_LDB_BLOCK
// if (it->key().ToString().c_str()[0] != 'b') continue;
CBlock cblock;
#else
// if (it->key().ToString().c_str()[0] != 't') continue;
CTransaction ctx;
#endif
std::string strValue = it->value().ToString();
try {
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
#if USE_LDB_BLOCK
ssValue >> cblock;
#else
ssValue >> ctx;
#endif
} catch (const std::exception&) {
// delete it;
// return NULL;
continue;
}
#if USE_LDB_BLOCK
BOOST_FOREACH(const CTransaction& ctx, cblock.vtx) {
#endif
// vin
BOOST_FOREACH(const CTxIn& txin, ctx.vin) {
if (txin.scriptSig.ToString() != expectedScriptSig.ToString()) {
continue;
}
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
goto found;
}
// vout
for (unsigned int vo = 0; vo < ctx.vout.size(); vo++) {
const CTxOut& txout = ctx.vout[vo];
const CScript& scriptPubKey = txout.scriptPubKey;
int nRequired;
txnouttype type;
vector<CTxDestination> addresses;
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
continue;
}
BOOST_FOREACH(const CTxDestination& address, addresses) {
if (CBitcoinAddress(address).ToString() != addr) {
continue;
}
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
goto found;
}
}
#if USE_LDB_BLOCK
}
#endif
found:
continue;
}
assert(it->status().ok());
delete it;
#if USE_LDB_FILES
}
#else
} while (0);
#endif
#if 0
#if USE_LDB_FILES
unsigned int nFile = 0;
unsigned int tryFiles = chainActive.Height();
for (; nFile <= tryFiles; nFile++) {
const boost::filesystem::path path = GetDataDir() / "blocks" / strprintf("%s%05u.dat", "blk", nFile);
#else
do {
const boost::filesystem::path path = GetDataDir() / "blocks" / "index";
#endif
if (fMemory) {
penv = leveldb::NewMemEnv(leveldb::Env::Default());
options.env = penv;
}
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
if (!status.ok()) {
break;
}
leveldb::Slice start = "t";
leveldb::Slice end = "t\xFF";
//leveldb::Options options;
leveldb::Iterator* it = pdb->NewIterator(leveldb::ReadOptions());
for (it->Seek(start); it->Valid(); it->Next()) {
leveldb::Slice key = it->key();
leveldb::Slice value = it->value();
if (options.comparator->Compare(key, end) > 0) {
break;
} else {
#if USE_LDB_BLOCK
CBlock cblock;
#else
CTransaction ctx;
#endif
std::string strValue = value.ToString();
try {
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
#if USE_LDB_BLOCK
ssValue >> cblock;
#else
ssValue >> ctx;
#endif
} catch (const std::exception&) {
// delete it;
// return NULL;
continue;
}
#if USE_LDB_BLOCK
BOOST_FOREACH(const CTransaction& ctx, cblock.vtx) {
#endif
// vin
BOOST_FOREACH(const CTxIn& txin, ctx.vin) {
if (txin.scriptSig.ToString() != expectedScriptSig.ToString()) {
continue;
}
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
goto found;
}
// vout
for (unsigned int vo = 0; vo < ctx.vout.size(); vo++) {
const CTxOut& txout = ctx.vout[vo];
const CScript& scriptPubKey = txout.scriptPubKey;
int nRequired;
txnouttype type;
vector<CTxDestination> addresses;
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
continue;
}
BOOST_FOREACH(const CTxDestination& address, addresses) {
if (CBitcoinAddress(address).ToString() != addr) {
continue;
}
if (cur == NULL) {
head->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
head->blockhash = hash;
head->next = NULL;
cur = head;
} else {
ctx_list *item = new ctx_list();
item->ctx = ctx;
uint256 hash(((CMerkleTx)ctx).hashBlock.GetHex());
item->blockhash = hash;
item->next = NULL;
cur->next = item;
cur = item;
}
goto found;
}
}
#if USE_LDB_BLOCK
}
#endif
found:
continue;
}
}
delete it;
#if USE_LDB_FILES
}
#else
} while (0);
#endif
#endif
return head;
#endif
}
#endif
#endif
static int64_t