diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-03-04 13:30:40 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-03-16 10:32:54 +0000 |
commit | 504428ab4a7aa7773832acdc3de0baad22d6b9b7 (patch) | |
tree | e0c46debfa497a3110e5fce39c0729f2c5f4aaf2 /src | |
parent | wallet: add a set_ring command (diff) | |
download | monero-504428ab4a7aa7773832acdc3de0baad22d6b9b7.tar.xz |
ringdb: use the genesis block as a db name
This will avoid careless forkers polluting the shared database
even if they make their own chain. They'll then automatically
start using another subdb, and any key-reusing fork of those
forks will reuse their subdbs.
Diffstat (limited to 'src')
-rw-r--r-- | src/blockchain_utilities/blockchain_blackball.cpp | 4 | ||||
-rw-r--r-- | src/wallet/ringdb.cpp | 6 | ||||
-rw-r--r-- | src/wallet/ringdb.h | 2 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 4 |
4 files changed, 10 insertions, 6 deletions
diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp index d065d61cb..40ce898d9 100644 --- a/src/blockchain_utilities/blockchain_blackball.cpp +++ b/src/blockchain_utilities/blockchain_blackball.cpp @@ -310,7 +310,9 @@ int main(int argc, char* argv[]) std::unordered_map<crypto::key_image, std::vector<uint64_t>> relative_rings; std::unordered_map<output_data, std::unordered_set<crypto::key_image>> outputs; std::unordered_set<output_data> spent, newly_spent; - tools::ringdb ringdb(output_file_path.string()); + + cryptonote::block b = core_storage[0]->get_db().get_block_from_height(0); + tools::ringdb ringdb(output_file_path.string(), epee::string_tools::pod_to_hex(get_block_hash(b))); for (size_t n = 0; n < inputs.size(); ++n) { diff --git a/src/wallet/ringdb.cpp b/src/wallet/ringdb.cpp index d2ed90e51..e4d3df30c 100644 --- a/src/wallet/ringdb.cpp +++ b/src/wallet/ringdb.cpp @@ -175,7 +175,7 @@ enum { BLACKBALL_BLACKBALL, BLACKBALL_UNBLACKBALL, BLACKBALL_QUERY, BLACKBALL_CL namespace tools { -ringdb::ringdb(std::string filename): +ringdb::ringdb(std::string filename, const std::string &genesis): filename(filename) { MDB_txn *txn; @@ -198,11 +198,11 @@ ringdb::ringdb(std::string filename): epee::misc_utils::auto_scope_leave_caller txn_dtor = epee::misc_utils::create_scope_leave_handler([&](){if (tx_active) mdb_txn_abort(txn);}); tx_active = true; - dbr = mdb_dbi_open(txn, "rings", MDB_CREATE, &dbi_rings); + dbr = mdb_dbi_open(txn, ("rings-" + genesis).c_str(), MDB_CREATE, &dbi_rings); THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to open LMDB dbi: " + std::string(mdb_strerror(dbr))); mdb_set_compare(txn, dbi_rings, compare_hash32); - dbr = mdb_dbi_open(txn, "blackballs", MDB_CREATE | MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED, &dbi_blackballs); + dbr = mdb_dbi_open(txn, ("blackballs-" + genesis).c_str(), MDB_CREATE | MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED, &dbi_blackballs); THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to open LMDB dbi: " + std::string(mdb_strerror(dbr))); mdb_set_dupsort(txn, dbi_blackballs, compare_hash32); diff --git a/src/wallet/ringdb.h b/src/wallet/ringdb.h index fb6b732a9..2bd1ac149 100644 --- a/src/wallet/ringdb.h +++ b/src/wallet/ringdb.h @@ -40,7 +40,7 @@ namespace tools class ringdb { public: - ringdb(std::string filename); + ringdb(std::string filename, const std::string &genesis); ~ringdb(); bool add_rings(const crypto::chacha_key &chacha_key, const cryptonote::transaction_prefix &tx); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b2cbd416b..3d28e80ef 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5454,8 +5454,10 @@ void wallet2::set_ring_database(const std::string &filename) m_ring_database = filename; MINFO("ringdb path set to " << filename); m_ringdb.reset(); + cryptonote::block b; + generate_genesis(b); if (!m_ring_database.empty()) - m_ringdb.reset(new tools::ringdb(m_ring_database)); + m_ringdb.reset(new tools::ringdb(m_ring_database, epee::string_tools::pod_to_hex(get_block_hash(b)))); } bool wallet2::add_rings(const crypto::chacha_key &key, const cryptonote::transaction_prefix &tx) |