Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTKV classs #577

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/hashdb64/database_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ zkresult Database64::write(const vector<DB64Query> &dbQueries, const bool persis
return ZKR_SUCCESS;
}

zkresult Database64::readKV(const Goldilocks::Element (&root)[4], const Goldilocks::Element (&key)[4], mpz_class &value, DatabaseMap *dbReadLog)
zkresult Database64::readKV(const Goldilocks::Element (&root)[4], const Goldilocks::Element (&key)[4], mpz_class &value, uint64_t &level ,DatabaseMap *dbReadLog)
{
level = 128;
// Check that it has been initialized before
if (!bInitialized)
{
Expand Down Expand Up @@ -405,14 +406,14 @@ zkresult Database64::readKV(const Goldilocks::Element (&root)[4], const Goldiloc

}

zkresult Database64::readKV(const Goldilocks::Element (&root)[4], vector<KeyValue> &KVs, DatabaseMap *dbReadLog){
zkresult Database64::readKV(const Goldilocks::Element (&root)[4], vector<KeyValueLevel> &KVLs, DatabaseMap *dbReadLog){
zkresult zkr;
for (uint64_t i=0; i<KVs.size(); i++)
for (uint64_t i=0; i<KVLs.size(); i++)
{
zkr = readKV(root, KVs[i].key, KVs[i].value, dbReadLog);
zkr = readKV(root, KVLs[i].key, KVLs[i].value, KVLs[i].level, dbReadLog);
if (zkr != ZKR_SUCCESS)
{
zklog.error("Database64::readKV(KBs) failed calling read() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVs[i].key) );
zklog.error("Database64::readKV(KBs) failed calling read() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVLs[i].key) );
return zkr;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/hashdb64/database_64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "database_versions_associtive_cache.hpp"
#include "database_kv_associative_cache.hpp"
#include "key_value.hpp"
#include "key_value_level.hpp"

using namespace std;

Expand Down Expand Up @@ -120,8 +121,9 @@ class Database64
zkresult write(const vector<DB64Query> &dbQueries, const bool persistent);
zkresult getProgram(const string &_key, vector<uint8_t> &value, DatabaseMap *dbReadLog);
zkresult setProgram(const string &_key, const vector<uint8_t> &value, const bool persistent);
zkresult readKV(const Goldilocks::Element (&root)[4], const Goldilocks::Element (&key)[4], mpz_class &value, DatabaseMap *dbReadLog);
zkresult readKV(const Goldilocks::Element (&root)[4], vector<KeyValue> &KVs, DatabaseMap *dbReadLog);
zkresult readKV(const Goldilocks::Element (&root)[4], const Goldilocks::Element (&key)[4], mpz_class &value, uint64_t &level, DatabaseMap *dbReadLog);
zkresult readKV(const Goldilocks::Element (&root)[4], vector<KeyValueLevel> &KVLs, DatabaseMap *dbReadLog);
zkresult readLevel(const Goldilocks::Element (&key)[4], uint64_t &level){ level=128; return ZKR_SUCCESS;}
zkresult writeKV(const Goldilocks::Element (&root)[4], const Goldilocks::Element (&key)[4], const mpz_class &value, const bool persistent);
zkresult writeKV(const uint64_t& version, const Goldilocks::Element (&key)[4], const mpz_class &value, const bool persistent);
zkresult writeKV(const Goldilocks::Element (&root)[4], const vector<KeyValue> &KVs, const bool persistent);
Expand Down
14 changes: 14 additions & 0 deletions src/hashdb64/key_value_level.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef KEY_VALUE_LEVEL_HPP
#define KEY_VALUE_LEVEL_HPP

#include "scalar.hpp"

class KeyValueLevel
{
public:
Goldilocks::Element key[4];
mpz_class value;
uint64_t level;
};

#endif
3 changes: 2 additions & 1 deletion src/hashdb64/state_manager_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,13 +1054,14 @@ zkresult StateManager64::get (const string &batchUUID, Database64 &db, const Gol
string keyString = fea2string(fr, key);
mpz_class value;
zkresult zkr = ZKR_UNSPECIFIED;
uint64_t level = 0;
if (bUseStateManager)
{
zkr = stateManager64.read(batchUUID, keyString, value, dbReadLog);
}
if (zkr != ZKR_SUCCESS)
{
zkr = db.readKV(root, key, value, dbReadLog);
zkr = db.readKV(root, key, value, level, dbReadLog);
}
if (zkr != ZKR_SUCCESS)
{
Expand Down
9 changes: 5 additions & 4 deletions test/hashdb/database_kv_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ uint64_t DatabaseKVTest (const Config &config){

Goldilocks fr;
uint64_t numberOfFailedTests = 0;
uint64_t level;

TimerStart(DATABASE_KV_TEST);

Expand Down Expand Up @@ -87,27 +88,27 @@ uint64_t DatabaseKVTest (const Config &config){
mpz_class valueZero(0);
mpz_class valueOut;
pDatabase64->writeKV(root2, key, valueIn, true);
pDatabase64->readKV(root2, key, valueOut, NULL);
pDatabase64->readKV(root2, key, valueOut, level, NULL);
if(valueOut != valueIn)
{
zklog.error("DatabaseKVTest() failed calling Database64.readKV()");
numberOfFailedTests += 1;
}
pDatabase64->clearCache();
pDatabase64->readKV(root2, key, valueOut, NULL);
pDatabase64->readKV(root2, key, valueOut, level, NULL);
if(valueOut != valueIn)
{
zklog.error("DatabaseKVTest() failed calling Database64.readKV() no cache");
numberOfFailedTests += 1;
}

pDatabase64->readKV(root1, key, valueOut, NULL);
pDatabase64->readKV(root1, key, valueOut, level, NULL);
if(valueOut != valueZero)
{
zklog.error("DatabaseKVTest() failed calling Database64.readKV() should not be found");
numberOfFailedTests += 1;
}
pDatabase64->readKV(root3, key, valueOut, NULL);
pDatabase64->readKV(root3, key, valueOut, level, NULL);
if(valueOut != valueIn)
{
zklog.error("DatabaseKVTest() failed calling Database64.readKV() should be found with latter version");
Expand Down