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

Fix panic when BLS key is nothing & support multiple keys #81

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ var (
utils.BLSPasswordFileFlag,
utils.BLSWalletDirFlag,
utils.VoteJournalDirFlag,
utils.VoteKeyNameFlag,
utils.LogDebugFlag,
utils.LogBacktraceAtFlag,
}, utils.NetworkFlags, utils.DatabaseFlags)
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,11 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Usage: "Path for the voteJournal dir in fast finality feature (default = inside the datadir)",
Category: flags.FastFinalityCategory,
}
VoteKeyNameFlag = &cli.StringFlag{
Name: "vote-key-name",
Usage: "Name of the BLS public key used for voting (default = first found key)",
Category: flags.FastFinalityCategory,
}
)

var (
Expand Down Expand Up @@ -1450,6 +1455,9 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
if ctx.IsSet(BLSPasswordFileFlag.Name) {
cfg.BLSPasswordFile = ctx.String(BLSPasswordFileFlag.Name)
}
if ctx.IsSet(VoteKeyNameFlag.Name) {
cfg.VoteKeyName = ctx.String(VoteKeyNameFlag.Name)
}
if ctx.IsSet(DBEngineFlag.Name) {
dbEngine := ctx.String(DBEngineFlag.Name)
if dbEngine != "leveldb" && dbEngine != "pebble" {
Expand Down
4 changes: 2 additions & 2 deletions core/vote/vote_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type VoteManager struct {
engine consensus.PoS
}

func NewVoteManager(eth Backend, chain *core.BlockChain, pool *VotePool, journalPath, blsPasswordPath, blsWalletPath string, engine consensus.PoS) (*VoteManager, error) {
func NewVoteManager(eth Backend, chain *core.BlockChain, pool *VotePool, journalPath, blsPasswordPath, blsWalletPath, blsAccountName string, engine consensus.PoS) (*VoteManager, error) {
voteManager := &VoteManager{
eth: eth,
chain: chain,
Expand All @@ -55,7 +55,7 @@ func NewVoteManager(eth Backend, chain *core.BlockChain, pool *VotePool, journal
}

// Create voteSigner.
voteSigner, err := NewVoteSigner(blsPasswordPath, blsWalletPath)
voteSigner, err := NewVoteSigner(blsPasswordPath, blsWalletPath, blsAccountName)
if err != nil {
return nil, err
}
Expand Down
34 changes: 32 additions & 2 deletions core/vote/vote_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/validator/accounts/iface"
"github.com/prysmaticlabs/prysm/v5/validator/accounts/wallet"
"github.com/prysmaticlabs/prysm/v5/validator/keymanager"
"github.com/prysmaticlabs/prysm/v5/validator/keymanager/local"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -29,7 +30,7 @@ type VoteSigner struct {
PubKey [48]byte
}

func NewVoteSigner(blsPasswordPath, blsWalletPath string) (*VoteSigner, error) {
func NewVoteSigner(blsPasswordPath, blsWalletPath, blsAccountName string) (*VoteSigner, error) {
dirExists, err := wallet.Exists(blsWalletPath)
if err != nil {
log.Error("Check BLS wallet exists", "err", err)
Expand Down Expand Up @@ -71,10 +72,39 @@ func NewVoteSigner(blsPasswordPath, blsWalletPath string) (*VoteSigner, error) {
if err != nil {
return nil, errors.Wrap(err, "could not fetch validating public keys")
}
if len(pubKeys) == 0 {
return nil, errors.New("no public keys in the BLS wallet")
}

// The default uses the first found key.
pubKey := pubKeys[0]

// If a key name is specified, find for it, but use the first key if not found.
if blsAccountName != "" {
ikm, ok := km.(*local.Keymanager)
if !ok {
return nil, errors.New("could not assert BLS keymanager interface to concrete type")
}
accountNames, err := ikm.ValidatingAccountNames()
if err != nil {
return nil, errors.Wrap(err, "could not fetch BLS account names")
}
var found bool
for i := 0; i < len(accountNames) && !found; i++ {
found = accountNames[i] == blsAccountName
if found {
pubKey = pubKeys[i]
}
}
if !found {
log.Warn("Configured voting BLS public key was not found, so the default key will be used",
"configured", blsAccountName, "default", accountNames[0])
}
}

return &VoteSigner{
km: &km,
PubKey: pubKeys[0],
PubKey: pubKey,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
conf := stack.Config()
blsPasswordPath := stack.ResolvePath(conf.BLSPasswordFile)
blsWalletPath := stack.ResolvePath(conf.BLSWalletDir)
blsAccountName := conf.VoteKeyName
voteJournalPath := stack.ResolvePath(conf.VoteJournalDir)
if _, err := vote.NewVoteManager(eth, eth.blockchain, votePool, voteJournalPath, blsPasswordPath, blsWalletPath, posa); err != nil {
if _, err := vote.NewVoteManager(eth, eth.blockchain, votePool, voteJournalPath, blsPasswordPath, blsWalletPath, blsAccountName, posa); err != nil {
log.Error("Failed to Initialize voteManager", "err", err)
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ type Config struct {
// VoteJournalDir is the directory to store votes in the fast finality feature.
VoteJournalDir string `toml:",omitempty"`

// VoteKeyName is name of the BLS public key used for voting
VoteKeyName string `toml:",omitempty"`

// BatchRequestLimit is the maximum number of requests in a batch.
BatchRequestLimit int `toml:",omitempty"`

Expand Down