Skip to content

Commit

Permalink
Merge pull request #545 from 0xPolygonHermez/fractasy_hashdb_64
Browse files Browse the repository at this point in the history
Fractasy hashdb 64
  • Loading branch information
rickb80 authored Sep 7, 2023
2 parents 64b288f + f4499a0 commit 167e4ba
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 222 deletions.
22 changes: 11 additions & 11 deletions src/hashdb64/database_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ zkresult Database64::readKV(const Goldilocks::Element (&root)[4], vector<KeyValu
zkresult zkr;
for (uint64_t i=0; i<KVs.size(); i++)
{
zkr = readKV(root, KVs[i].key.fe, KVs[i].value, dbReadLog);
zkr = readKV(root, KVs[i].key, KVs[i].value, dbReadLog);
if (zkr != ZKR_SUCCESS)
{
zklog.error("Database64::readKV(KBs) failed calling read() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVs[i].key.fe[0], KVs[i].key.fe[1], KVs[i].key.fe[2], KVs[i].key.fe[3]) );
zklog.error("Database64::readKV(KBs) failed calling read() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVs[i].key) );
return zkr;
}
}
Expand Down Expand Up @@ -590,10 +590,10 @@ zkresult Database64::writeKV(const Goldilocks::Element (&root)[4], const vector<
zkresult zkr;
for (uint64_t i=0; i<KVs.size(); i++)
{
zkr = writeKV(root, KVs[i].key.fe, KVs[i].value, persistent);
zkr = writeKV(root, KVs[i].key, KVs[i].value, persistent);
if (zkr != ZKR_SUCCESS)
{
zklog.error("Database64::writeKV(KBs) failed calling write() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVs[i].key.fe[0], KVs[i].key.fe[1], KVs[i].key.fe[2], KVs[i].key.fe[3]) );
zklog.error("Database64::writeKV(KBs) failed calling write() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVs[i].key) );
return zkr;
}
}
Expand All @@ -604,10 +604,10 @@ zkresult Database64::writeKV(const uint64_t& version, const vector<KeyValue> &KV
zkresult zkr;
for (uint64_t i=0; i<KVs.size(); i++)
{
zkr = writeKV(version, KVs[i].key.fe, KVs[i].value, persistent);
zkr = writeKV(version, KVs[i].key, KVs[i].value, persistent);
if (zkr != ZKR_SUCCESS)
{
zklog.error("Database64::writeKV(KBs) failed calling write() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVs[i].key.fe[0], KVs[i].key.fe[1], KVs[i].key.fe[2], KVs[i].key.fe[3]) );
zklog.error("Database64::writeKV(KBs) failed calling write() result=" + zkresult2string(zkr) + " key=" + fea2string(fr, KVs[i].key) );
return zkr;
}
}
Expand Down Expand Up @@ -1341,10 +1341,10 @@ zkresult Database64::writeRemoteKV(const uint64_t version, const Goldilocks::Ele
{
multiWrite.Lock();
KeyValue auxKV;
auxKV.key.fe[0] = key[0];
auxKV.key.fe[1] = key[1];
auxKV.key.fe[2] = key[2];
auxKV.key.fe[3] = key[3];
auxKV.key[0] = key[0];
auxKV.key[1] = key[1];
auxKV.key[2] = key[2];
auxKV.key[3] = key[3];
auxKV.value = value;
multiWrite.data[multiWrite.pendingToFlushDataIndex].keyValueIntray[version] = auxKV;
#ifdef LOG_DB_WRITE_REMOTE
Expand Down Expand Up @@ -2329,7 +2329,7 @@ zkresult Database64::sendData (void)
unordered_map<uint64_t, KeyValue>::const_iterator it=data.keyValue.begin();
while (it != data.keyValue.end())
{
writeRemoteKV(it->first,it->second.key.fe,it->second.value, true);
writeRemoteKV(it->first,it->second.key,it->second.value, true);
}
}
// If there are versions add to db
Expand Down
12 changes: 0 additions & 12 deletions src/hashdb64/key.hpp

This file was deleted.

3 changes: 1 addition & 2 deletions src/hashdb64/key_value.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#ifndef KEY_VALUE_HPP
#define KEY_VALUE_HPP

#include "key.hpp"
#include "scalar.hpp"

class KeyValue
{
public:
Key key;
Goldilocks::Element key[4];
mpz_class value;
};

Expand Down
6 changes: 2 additions & 4 deletions src/hashdb64/smt_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "zklog.hpp"
#include <bitset>
#include "state_manager_64.hpp"
#include "key.hpp"
#include "key_utils.hpp"
#include "tree_chunk.hpp"

Expand All @@ -28,8 +27,7 @@ zkresult Smt64::set (const string &batchUUID, uint64_t tx, Database64 &db, const
// Set the old state root
string oldRootString;
oldRootString = fea2string(fr, oldRoot);
bool bIsVirtual = stateManager64.isVirtualStateRoot(oldRootString);
stateManager64.setOldStateRoot(batchUUID, tx, oldRootString, bIsVirtual, persistence);
stateManager64.setOldStateRoot(batchUUID, tx, oldRootString, persistence);

// Write the key-value pair
string hashString = NormalizeToNFormat(fea2string(fr, key), 64);
Expand All @@ -45,7 +43,7 @@ zkresult Smt64::set (const string &batchUUID, uint64_t tx, Database64 &db, const
stateManager64.getVirtualStateRoot(newRoot, newRootString);

// Set the new sttae root
stateManager64.setNewStateRoot(batchUUID, tx, newRootString, true, persistence);
stateManager64.setNewStateRoot(batchUUID, tx, newRootString, persistence);

result.newRoot[0] = newRoot[0];
result.newRoot[1] = newRoot[1];
Expand Down
1 change: 0 additions & 1 deletion src/hashdb64/smt_64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "smt_set_result.hpp"
#include "smt_get_result.hpp"
#include "tree_chunk.hpp"
#include "key.hpp"
#include "key_value.hpp"

using namespace std;
Expand Down
Loading

0 comments on commit 167e4ba

Please sign in to comment.