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
Save and load all preimages on the database #495
Conversation
5841a1f
to
7c89d29
Compare
Codecov Report
@@ Coverage Diff @@
## v0.x.x #495 +/- ##
==========================================
- Coverage 88.82% 87.71% -1.12%
==========================================
Files 58 57 -1
Lines 4143 4151 +8
==========================================
- Hits 3680 3641 -39
- Misses 463 510 +47
Continue to review full report at Codecov.
|
4f150d6
to
a8f9f2a
Compare
Ready for review |
public struct PreimageStore | ||
{ | ||
/// Preimages of hashes of random value | ||
public Hash[] data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid writing all this code if we added serialization support to Hash[]
in Serializer.d
and Deserializer.d
.
@Geod24 can you think of any drawbacks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After adding serialization support to Hash[]
in this PR, I will request a review again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndrejMitrovic : Actually for the binary protocol, I wrote a way to serialize ranges... Guess it's time to PR it.
a8f9f2a
to
06bdb9f
Compare
Ready for review. |
results = this.db.execute("SELECT val FROM node_enroll_data " ~ | ||
"WHERE key = ?", "preimages"); | ||
|
||
foreach (row; results) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe this would work too:
if (!results.empty)
this.preimages = results.oneValue!(ubyte[]).deserializeFull!(Hash[]);
Could be worth trying.
foreach (i; 0 .. this.data.cycle_length-1) | ||
this.data.random_seed = hashFull(this.data.random_seed); | ||
this.preimages ~= hashFull(this.preimages[i]); | ||
this.data.random_seed = this.preimages[this.data.cycle_length-1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just this.preimages[$ - 1];
? Is it not the same?
@@ -453,6 +506,38 @@ public class EnrollmentManager | |||
} | |||
} | |||
|
|||
/// test for serialization and deserialization of PreimageStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly outdated comment, as PreimageStore
doesn't exist anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small issues
06bdb9f
to
d2a0372
Compare
Ready for review. Thanks. |
@@ -453,6 +502,38 @@ public class EnrollmentManager | |||
} | |||
} | |||
|
|||
/// test for serialization and deserialization of a Hash array | |||
unittest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to just test serialization? It's not testing EnrollmentManager.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, It's not. I will make the unittest with EnrollmentManager.
6d55c73
to
97e99c4
Compare
Ready for review. |
@@ -587,4 +672,13 @@ unittest | |||
man.getUnregisteredEnrollments(enrolls); | |||
assert(enrolls.length == 3); | |||
assert(enrolls.isStrictlyMonotonic!("a.utxo_key < b.utxo_key")); | |||
|
|||
// test serialization/deserializetion for pre-images | |||
auto preimages_1 = man.getPreimages(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can access the field directly, because private allows access from the same module.
So just auto preimages_1 = man.preimages;
.
auto preimages_1 = man.getPreimages(); | ||
auto preimages_2 = man.loadPreimages(); | ||
int true_count; | ||
foreach (i; 0 .. 1008) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These few lines can be replaced with assert(preimages_1[] == preimages_2[]);
. This will check the length too.
foreach (i; 0 .. 1008) | ||
if (preimages_1[i] == preimages_2[i]) | ||
true_count++; | ||
assert(true_count == 1008); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a missing check that the preimages are actually preimages. You can use this:
import std.algorithm;
assert(equal!((a, b) => a.hashFull() == b)(preimages_1[0 .. $ - 1], preimages_1[1 .. $]));
97e99c4
to
a88d8f6
Compare
Ready for review after applying the suggestions of @AndrejMitrovic . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
A validator must periodically reveal the pre-images. For that requirement, the pre-images should be stored to database for a cycle.
a88d8f6
to
e494213
Compare
Ping @Geod24 |
A validator must periodically reveal the preimages.
For that requirement, the preimages should be stored to database for a cycle.
This implementation is the first definition of done of the issue #492