-
Notifications
You must be signed in to change notification settings - Fork 917
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
Add EIP-3076 Interchange JSON CLI command to validator #7880
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
18e1d16
Import JSON CLI
0xKiwi a4a3c50
CLI impotr
0xKiwi 4c6a80a
f
0xKiwi 2954ecd
Begin adding new commands in slashing protection
0xKiwi 7fc99a2
Move testing helpers to separate packae
0xKiwi 0efb884
Merge branch 'master' into sp-helpers
0xKiwi 801ad1e
Merge branch 'sp-helpers' of github.com:prysmaticlabs/prysm into cli-…
0xKiwi 7c0c4a8
Add command for importing slashing protection JSONs
0xKiwi ebe060b
fix import cycle
rauljordan 3f20e0d
fix test
rauljordan c8094f0
Merge branch 'master' of github.com:prysmaticlabs/prysm into cli-import
0xKiwi 8e0473b
Undo cleaning changes
0xKiwi 7cce70a
Improvements
0xKiwi 8073ecc
Add better prompts
0xKiwi 1b2be36
Merge branch 'master' into cli-import
0xKiwi d722e52
Fix prompt
0xKiwi 8d63ae9
Merge branch 'cli-import' of github.com:prysmaticlabs/prysm into cli-…
0xKiwi b17a7df
Merge branch 'master' of github.com:prysmaticlabs/prysm into cli-import
0xKiwi e5cf8bb
Merge branch 'master' of github.com:prysmaticlabs/prysm into cli-import
0xKiwi 65ea684
Fix
0xKiwi fe1ee0c
Fix
0xKiwi e18b846
Fix
0xKiwi b67184b
Merge branch 'master' of github.com:prysmaticlabs/prysm into cli-import
0xKiwi c4eb6d3
Fix conflict
0xKiwi 2697094
Fix
0xKiwi 094f5c5
Merge branch 'master' of github.com:prysmaticlabs/prysm into cli-import
0xKiwi 0350c09
Merge branch 'feature/slashing-interchange' into cli-import
rauljordan d1f97b1
Merge branch 'feature/slashing-interchange' of github.com:prysmaticla…
0xKiwi e361a14
Fixes
0xKiwi d676456
Fixes
0xKiwi c83d5d4
Merge branch 'feature/slashing-interchange' of github.com:prysmaticla…
0xKiwi 13da441
Fix exported func
0xKiwi dc1b255
test func
0xKiwi 5079d0f
Fixes
0xKiwi 574754f
fix test
0xKiwi 8156421
simplify import and standardize with export
rauljordan 9af20d5
add round trip test
rauljordan 3a1ed1d
true integration test works
rauljordan 830db55
fix up comments
rauljordan 917501f
logrus
rauljordan 5ec6a78
better error
rauljordan 51baff1
fix build
rauljordan 9e84af8
build fix
rauljordan ed1fee8
Merge branch 'feature/slashing-interchange' into cli-import
rauljordan dbf796a
Update validator/slashing-protection/cli_export.go
rauljordan 9d11dcd
Update validator/slashing-protection/cli_import.go
rauljordan 23de559
fmt
prestonvanloon File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package slashingprotection | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/prysmaticlabs/prysm/shared/cmd" | ||
"github.com/prysmaticlabs/prysm/shared/fileutil" | ||
"github.com/prysmaticlabs/prysm/validator/accounts/prompt" | ||
"github.com/prysmaticlabs/prysm/validator/db/kv" | ||
"github.com/prysmaticlabs/prysm/validator/flags" | ||
slashingProtectionFormat "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// ImportSlashingProtectionCLI reads an input slashing protection EIP-3076 | ||
// standard JSON file and attempts to insert its data into our validator DB. | ||
// | ||
// Steps: | ||
// 1. Parse a path to the validator's datadir from the CLI context. | ||
// 2. Open the validator database. | ||
// 3. Read the JSON file from user input. | ||
// 4. Call the function which actually imports the data from | ||
// from the standard slashing protection JSON file into our database. | ||
func ImportSlashingProtectionCLI(cliCtx *cli.Context) error { | ||
var err error | ||
dataDir := cliCtx.String(cmd.DataDirFlag.Name) | ||
if !cliCtx.IsSet(cmd.DataDirFlag.Name) { | ||
dataDir, err = prompt.InputDirectory(cliCtx, prompt.DataDirDirPromptText, cmd.DataDirFlag) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
valDB, err := kv.NewKVStore(dataDir, make([][48]byte, 0)) | ||
if err != nil { | ||
return errors.Wrapf(err, "could not access validator database at path: %s", dataDir) | ||
} | ||
defer func() { | ||
if err := valDB.Close(); err != nil { | ||
log.WithError(err).Errorf("Could not close validator DB") | ||
} | ||
}() | ||
protectionFilePath, err := prompt.InputDirectory(cliCtx, prompt.SlashingProtectionJSONPromptText, flags.SlashingProtectionJSONFileFlag) | ||
rauljordan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return errors.Wrap(err, "could not get slashing protection json file") | ||
} | ||
if protectionFilePath == "" { | ||
return fmt.Errorf( | ||
"No path to a slashing_protection.json file specified, please retry. "+ | ||
"You can also specify it with the %s flag", | ||
flags.SlashingProtectionJSONFileFlag.Name, | ||
) | ||
} | ||
enc, err := fileutil.ReadFileAsBytes(protectionFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
buf := bytes.NewBuffer(enc) | ||
if err := slashingProtectionFormat.ImportStandardProtectionJSON( | ||
cliCtx.Context, valDB, buf, | ||
); err != nil { | ||
return err | ||
} | ||
log.Info("Slashing protection JSON successfully imported") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Made export interactive to match the changes to import from this PR