Since these are needed at the same time as the output pubkeys,
this is a whole lot faster, and takes less space. Only outputs
of 0 amount store the commitment. When reading other outputs,
a fake commitment is regenerated on the fly. This avoids having
to rewrite the database to add space for fake commitments for
existing outputs.
This code relies on two things:
- LMDB must support fixed size records per key, rather than
per database (ie, all records on key 0 are the same size, all
records for non 0 keys are same size, but records from key 0
and non 0 keys do have different sizes).
- the commitment must be directly after the rest of the data
in outkey and output_data_t.
lmdb_db_open(txn,LMDB_SPENT_KEYS,MDB_INTEGERKEY|MDB_CREATE|MDB_DUPSORT|MDB_DUPFIXED,m_spent_keys,"Failed to open db handle for m_spent_keys");
lmdb_db_open(txn,LMDB_RCT_COMMITMENTS,MDB_INTEGERKEY|MDB_CREATE|MDB_DUPSORT|MDB_DUPFIXED,m_rct_commitments,"Failed to open db handle for m_rct_commitments");
// this subdb is dropped on sight, so it may not be present when we open the DB.
// Since we use MDB_CREATE, we'll get an exception if we open read-only and it does not exist.
// So we don't open for read-only, and also not drop below. It is not used elsewhere.
@ -1261,8 +1277,6 @@ void BlockchainLMDB::reset()
throw0(DB_ERROR(lmdb_error("Failed to drop m_output_amounts: ",result).c_str()));
if(autoresult=mdb_drop(txn,m_spent_keys,0))
throw0(DB_ERROR(lmdb_error("Failed to drop m_spent_keys: ",result).c_str()));
if(autoresult=mdb_drop(txn,m_rct_commitments,0))
throw0(DB_ERROR(lmdb_error("Failed to drop m_rct_commitments: ",result).c_str()));
(void)mdb_drop(txn,m_hf_starting_heights,0);// this one is dropped in new code
if(autoresult=mdb_drop(txn,m_hf_versions,0))
throw0(DB_ERROR(lmdb_error("Failed to drop m_hf_versions: ",result).c_str()));
throw0(OUTPUT_DNE(lmdb_error("Error attempting to retrieve rct commitment for "+boost::lexical_cast<std::string>(idx)+" from the db: ",result).c_str()));
elseif(result)
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve rct commitment for "+boost::lexical_cast<std::string>(idx)+" from the db: ",result).c_str()));
throw0(OUTPUT_DNE(lmdb_error("Error attempting to retrieve rct commitment for "+boost::lexical_cast<std::string>(idx)+" from the db: ",result).c_str()));
elseif(result)
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve rct commitment for "+boost::lexical_cast<std::string>(idx)+" from the db: ",result).c_str()));
result=mdb_cursor_del(m_cur_rct_commitments,0);
if(result)
throw0(DB_ERROR(lmdb_error("Error attempting to remove rct commitment for "+boost::lexical_cast<std::string>(idx)+" from the db: ",result).c_str()));