-
Notifications
You must be signed in to change notification settings - Fork 90
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
cmd: add create dkg command #484
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright © 2022 Obol Labs Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) | ||
// any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package cmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
func newCreateCmd(cmds ...*cobra.Command) *cobra.Command { | ||
root := &cobra.Command{ | ||
Use: "create", | ||
Short: "Create different artifacts required for running a Charon cluster", | ||
} | ||
|
||
root.AddCommand(cmds...) | ||
|
||
titledHelp(root) | ||
|
||
return root | ||
} |
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,97 @@ | ||
// Copyright © 2022 Obol Labs Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the Free | ||
// Software Foundation, either version 3 of the License, or (at your option) | ||
// any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
// more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
crand "crypto/rand" | ||
"encoding/json" | ||
"os" | ||
"path" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
|
||
"github.com/obolnetwork/charon/app/errors" | ||
"github.com/obolnetwork/charon/cluster" | ||
) | ||
|
||
type createDKGConfig struct { | ||
OutputDir string | ||
Name string | ||
NumValidators int | ||
Threshold int | ||
FeeRecipient string | ||
WithdrawalAddress string | ||
ForkVersion string | ||
OperatorENRs []string | ||
} | ||
|
||
func newCreateDKGCmd(runFunc func(context.Context, createDKGConfig) error) *cobra.Command { | ||
var config createDKGConfig | ||
|
||
cmd := &cobra.Command{ | ||
Use: "dkg", | ||
Short: "Configure DKG by creating a cluster definition file", | ||
Long: `Create a cluster definition file that will be used by all participants of a DKG.`, | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runFunc(cmd.Context(), config) | ||
}, | ||
} | ||
|
||
bindCreateDKGFlags(cmd.Flags(), &config) | ||
|
||
return cmd | ||
} | ||
|
||
func bindCreateDKGFlags(flags *pflag.FlagSet, config *createDKGConfig) { | ||
flags.StringVar(&config.Name, "name", "", "Optional cosmetic cluster name") | ||
flags.StringVar(&config.OutputDir, "output-dir", ".", "The folder to write the output cluster_definition.json file to.") | ||
flags.IntVar(&config.NumValidators, "num-validators", 1, "The number of distributed validators the cluster will manage (32ETH staked for each).") | ||
flags.IntVarP(&config.Threshold, "threshold", "t", 3, "The threshold required for signature reconstruction. Minimum is n-(ceil(n/3)-1).") | ||
flags.StringVar(&config.FeeRecipient, "fee_recipient_address", "", "Optional Ethereum address of the fee recipient") | ||
flags.StringVar(&config.WithdrawalAddress, "withdrawal_address", "", "Withdrawal Ethereum address") | ||
flags.StringVar(&config.ForkVersion, "fork_version", "", "Optional hex fork version identifying the target network/chain") | ||
flags.StringSliceVar(&config.OperatorENRs, "operator_enrs", nil, "Comma-separated list of each operator's Charon ENR address") | ||
} | ||
|
||
func runCreateDKG(_ context.Context, conf createDKGConfig) error { | ||
var operators []cluster.Operator | ||
for _, opENR := range conf.OperatorENRs { | ||
operators = append(operators, cluster.Operator{ | ||
ENR: opENR, | ||
}) | ||
} | ||
|
||
def := cluster.NewDefinition(conf.Name, conf.NumValidators, conf.Threshold, conf.FeeRecipient, conf.WithdrawalAddress, | ||
conf.ForkVersion, operators, crand.Reader) | ||
|
||
b, err := json.Marshal(def) | ||
if err != nil { | ||
return errors.Wrap(err, "marshal definition") | ||
} | ||
|
||
if err := os.MkdirAll(conf.OutputDir, 0o755); err != nil { | ||
return errors.Wrap(err, "create output dir") | ||
} | ||
|
||
if err := os.WriteFile(path.Join(conf.OutputDir, "cluster_definition.json"), b, 0o400); err != nil { | ||
return errors.Wrap(err, "write definition") | ||
} | ||
|
||
return nil | ||
} |
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.
charon create dkg
just doesn't feel right to meThere 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 mean you can
do
a dkg (distributed key gen) butcreating
a dkg doesn't make sense to meThere 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 pushed for:
charon define dkg
->cluster_definition.json
charon seal
->cluster_lock.json
charon run
Or for local cluster flow:
charon define local
charon seal
charon run
But this this was rejected for:
charon create dkg
->cluster_definition.json
charon dkg
->cluster_lock.json
charon run
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.
is building a
cluster_definition
even part of a dkg?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.
it's an input to a dkg, if i'm not wrong
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.
or we can do something like:
charon create dkg-cluster
or
charon create dkg-config
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.
Perhaps this should have been discussed as part of the ticket grooming. I don't think we should stop the merge of this because we do not agree on the command name. Let's create an issue and discuss it there the definete command name