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

Recursively Find Validator Database File In Slashing Protection Commands #8518

Merged
merged 13 commits into from
Feb 26, 2021

Conversation

ahadda5
Copy link
Contributor

@ahadda5 ahadda5 commented Feb 25, 2021

What type of PR is this?

Feature

What does this PR do? Why is it needed?
It ensures that the validator.db is found in the specified datadir or its subdirectories before the slashing export commences. Want to avoid going through the process if validator.db is not there.

Which issues(s) does this PR fix?
Fixes #8500

@ahadda5 ahadda5 requested a review from a team as a code owner February 25, 2021 16:26
@ahadda5
Copy link
Contributor Author

ahadda5 commented Feb 25, 2021

I need some pointers before i proceed to make further changes ExportSlashingProtectionJSONCli /ImportSlashingProtectionJSONCli

A util func was added.

  1. It returns a bool if a file is found in a dir or its sub and the path of that file. While we do not need the path for our issue 8500, i kept it for future usage?!
  2. When unit testing , the found flag (bool) works however it is worth noting that once creating tmp dir the full path cannot be pre - determined so i commented that assert. See below.
  3. If that is fair, i can proceed to make the change to ExportSlashingProtectionJSONCli /ImportSlashingProtectionJSONCli ensuring that validator.db exists in the dir/sub_dir and stop with an error if that is not the case.

//assert.DeepEqual(t, tt.path, fpath)

FAIL: TestRecursiveFileFind (0.00s)
    --- FAIL: TestRecursiveFileFind/file1 (0.00s)
        assertions.go:48: fileutil_test.go:289 Values are not equal, want: "subfolder1/subfolder11/file1", got: "/tmp/TestRecursiveFileFind269727708/001/subfolder1/subfolder11/file1", diff: modified:  = "/tmp/TestRecursiveFileFind269727708/001/subfolder1/subfolder11/file1"
    --- FAIL: TestRecursiveFileFind/file2 (0.00s)
        assertions.go:48: fileutil_test.go:289 Values are not equal, want: "subfolder2/file2", got: "/tmp/TestRecursiveFileFind269727708/001/subfolder2/file2", diff: modified:  = "/tmp/TestRecursiveFileFind269727708/001/subfolder2/file2"
    --- FAIL: TestRecursiveFileFind/file1#01 (0.00s)
        assertions.go:48: fileutil_test.go:289 Values are not equal, want: "subfolder11/file1", got: "/tmp/TestRecursiveFileFind269727708/001/subfolder1/subfolder11/file1", diff: modified:  = "/tmp/TestRecursiveFileFind269727708/001/subfolder1/subfolder11/file1"
    --- FAIL: TestRecursiveFileFind/file3 (0.00s)
        assertions.go:48: fileutil_test.go:289 Values are not equal, want: "file3", got: "/tmp/TestRecursiveFileFind269727708/001/file3", diff: modified:  = "/tmp/TestRecursiveFileFind269727708/001/file3"
FAIL

@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #8518 (c9f91bd) into develop (878bc15) will decrease coverage by 0.03%.
The diff coverage is 73.33%.

@@             Coverage Diff             @@
##           develop    #8518      +/-   ##
===========================================
- Coverage    58.15%   58.12%   -0.04%     
===========================================
  Files          459      459              
  Lines        32918    32905      -13     
===========================================
- Hits         19144    19126      -18     
- Misses       10872    10883      +11     
+ Partials      2902     2896       -6     

Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far!

require.NoError(t, err)

assert.DeepEqual(t, tt.found, found)
//assert.DeepEqual(t, tt.path, fpath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will do.

@rauljordan
Copy link
Contributor

@ahadda5 we should make the title share more context. Something like: "Recursively Find Validator Database File In Slashing Protection Commands". Additionally, this PR just adds a utility function but does not integrate it where it is needed. Since this PR is quite small, it is OK to do both things in this single PR. Please revise at your own convenience and then we can review again

@ahadda5
Copy link
Contributor Author

ahadda5 commented Feb 26, 2021

Sorry what title are you referring to? code commentary and/or the func name ?

@ahadda5 we should make the title share more context. Something like: "Recursively Find Validator Database File In Slashing Protection Commands". Additionally, this PR just adds a utility function but does not integrate it where it is needed. Since this PR is quite small, it is OK to do both things in this single PR. Please revise at your own convenience and then we can review again

@ahadda5
Copy link
Contributor Author

ahadda5 commented Feb 26, 2021

unit tested the slashing

bazel test //validator/slashing-protection:cli_import_export_test.go --test_output=streamed

However i need to test the actual export/import , how can i make sure the shell script is calling my build (read somewhere that it downloads the latest and greatest build).

prysm.sh validator slashing-protection export --datadir=/home/ahaddad/eth2validators --slashing-protection-export-dir=/home/ahaddad

}
// checks if its a file and has the exact name as the filename
// need to break the walk function by using a non-fatal error
if !info.IsDir() && filename == info.Name() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the best way to check if its a file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this is a fine approach

@rauljordan
Copy link
Contributor

prysm.sh validator slashing-protection export --datadir=/home/ahaddad/eth2validators --slashing-protection-export-dir=/home/ahaddad

bazel run //validator -- slashing-protection export --datadir=/home/ahaddad/eth2validators --slashing-protection-export-dir=/home/ahaddad

@rauljordan rauljordan changed the title Find validator automatically Recursively Find Validator Database File In Slashing Protection Commands Feb 26, 2021
Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another great contribution, thanks so much @ahadda5

@rauljordan rauljordan merged commit 29d1959 into prysmaticlabs:develop Feb 26, 2021
@ahadda5
Copy link
Contributor Author

ahadda5 commented Feb 26, 2021

oops @rauljordan i didn't want you to merge it before i finished the test.

Now as expected one has to specify the full path (./ or C:) to make sure it is not read relative otherwise it errors. So
bazel run //validator -- slashing-protection export --datadir=/home/.eth2validators --slashing-protection-export-dir=/home/ahaddad
Versus
bazel run //validator -- slashing-protection export --datadir=./home/.eth2validators --slashing-protection-export-dir=./home/ahaddad

with the first resulting in "error finding validator database at path" which is ok albeit added "feature"/warning.

Secondly and more importantly, my validator.db is a juicy testnet db of 20 MB yet exporting it does not result in the slashing.json. Hmm..

I'm just afraid this was not tested thoroughly.
Cheers

@rauljordan
Copy link
Contributor

Sorry for merging so quickly @ahadda5, we should open these concerns in your message above as an issue that should be resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Slashing Protection Export Find validator.db Automatically Inside of Wallet Directory
2 participants