mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 02:02:18 +00:00
d6fb8c29c9
* refactoring how proposer settings load * fixing tests and moving test data * fixing linting and adding comments * accidently removed a function, adding it back in * fixing usage of dependency * gaz * fixing package visibility * gaz * iface config gaz * adding visibility for db * fix ineffectual assignment to err * adding in log for when the builder is set but ignored due to no fee recipient * Update config/validator/service/proposer_settings.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/validator/service/proposer_settings.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/client/validator.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/validator/service/proposer_settings.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/proposer/loader.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/proposer/loader.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/proposer/loader.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/proposer/loader.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/proposer/loader.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/validator/service/proposer_settings.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update config/util.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * some of the review feedback * more review comments * adding more test coverage * Update config/proposer/loader.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * Update config/proposer/loader.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * Update config/proposer/loader.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * Update config/proposer/loader.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * updating based on feedback * renaming variable * fixing unhandled errors * fixing tests * gaz * adding in gaslimit log * fixing log * some more review comments * renaming and moving proposer settings file --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com>
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v5/config/proposer"
|
|
validatorpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/validator-client"
|
|
bolt "go.etcd.io/bbolt"
|
|
"go.opencensus.io/trace"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// ErrNoProposerSettingsFound is an error thrown when no settings are found in bucket
|
|
var ErrNoProposerSettingsFound = errors.New("no proposer settings found in bucket")
|
|
|
|
// ProposerSettings gets the current proposer settings
|
|
func (s *Store) ProposerSettings(ctx context.Context) (*proposer.Settings, error) {
|
|
_, span := trace.StartSpan(ctx, "validator.db.Settings")
|
|
defer span.End()
|
|
to := &validatorpb.ProposerSettingsPayload{}
|
|
if err := s.db.View(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(proposerSettingsBucket)
|
|
b := bkt.Get(proposerSettingsKey)
|
|
if len(b) == 0 {
|
|
return ErrNoProposerSettingsFound
|
|
}
|
|
if err := proto.Unmarshal(b, to); err != nil {
|
|
return errors.Wrap(err, "failed to unmarshal proposer settings")
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
return proposer.SettingFromConsensus(to)
|
|
}
|
|
|
|
// ProposerSettingsExists returns true or false if the settings exist or not
|
|
func (s *Store) ProposerSettingsExists(ctx context.Context) (bool, error) {
|
|
ps, err := s.ProposerSettings(ctx)
|
|
if err != nil {
|
|
if errors.Is(err, ErrNoProposerSettingsFound) {
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|
|
if ps == nil {
|
|
return false, nil
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
// SaveProposerSettings saves the entire proposer setting overriding the existing settings
|
|
func (s *Store) SaveProposerSettings(ctx context.Context, settings *proposer.Settings) error {
|
|
_, span := trace.StartSpan(ctx, "validator.db.SaveProposerSettings")
|
|
defer span.End()
|
|
// nothing to save
|
|
if !settings.ShouldBeSaved() {
|
|
log.Warn("proposer settings are empty, nothing has been saved")
|
|
return nil
|
|
}
|
|
return s.db.Update(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(proposerSettingsBucket)
|
|
m, err := proto.Marshal(settings.ToConsensus())
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to marshal proposer settings")
|
|
}
|
|
return bkt.Put(proposerSettingsKey, m)
|
|
})
|
|
}
|