mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
* WIP * broken and still wip * more wip improving saving * wip * removing cyclic dependency * gaz * fixes * fixing more tests and how files load * fixing wallet tests * fixing test * updating keymanager tests * improving how the web3signer keymanager works * WIP * updated keymanager to read from file * gaz * reuse readkeyfile function and add in duplicate keys check * adding in locks to increase safety * refactored how saving keys work, more tests needed: * fix test * fix tests * adding unit tests and cleaning up locks * fixing tests * tests were not fixed properly * removing unneeded files * Update cmd/validator/accounts/wallet_utils.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * Update validator/accounts/wallet/wallet.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * review feedback * updating flags and e2e * deepsource fix * resolving feedback * removing fatal test for now * addressing manu's feedback * gofmt * fixing tests * fixing unit tests * more idomatic feedback * updating log files * updating based on preston's suggestion * improving logs and event triggers * addressing comments from manu * truncating was not triggering key file reload * fixing unit test * removing wrong dependency * fix another broken unit test * fixing bad pathing on file * handle errors in test * fixing testdata dependency * resolving deepsource and comment around logs * removing unneeded buffer * reworking ux of web3signer file, unit tests to come * adding unit tests for file change retries * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> * updating based on review feedback * missed err check * adding some aliases to make running easier * Update validator/keymanager/remote-web3signer/log.go Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * radek's review * Update validator/keymanager/remote-web3signer/internal/client.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/keymanager/remote-web3signer/keymanager.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * addressing more review feedback and linting * fixing tests * adding log * adding 1 more test * improving logs --------- Co-authored-by: Sammy Rosso <15244892+saolyn@users.noreply.github.com> Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
272 lines
7.0 KiB
Go
272 lines
7.0 KiB
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/api/client/beacon"
|
|
"github.com/prysmaticlabs/prysm/v5/api/client/event"
|
|
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/v5/config/proposer"
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v5/validator/accounts/iface"
|
|
iface2 "github.com/prysmaticlabs/prysm/v5/validator/client/iface"
|
|
"github.com/prysmaticlabs/prysm/v5/validator/keymanager"
|
|
)
|
|
|
|
// Wallet contains an in-memory, simulated wallet implementation.
|
|
type Wallet struct {
|
|
InnerAccountsDir string
|
|
Directories []string
|
|
Files map[string]map[string][]byte
|
|
EncryptedSeedFile []byte
|
|
AccountPasswords map[string]string
|
|
WalletPassword string
|
|
UnlockAccounts bool
|
|
lock sync.RWMutex
|
|
HasWriteFileError bool
|
|
WalletDir string
|
|
Kind keymanager.Kind
|
|
}
|
|
|
|
// AccountNames --
|
|
func (w *Wallet) AccountNames() ([]string, error) {
|
|
w.lock.RLock()
|
|
defer w.lock.RUnlock()
|
|
names := make([]string, 0)
|
|
for name := range w.AccountPasswords {
|
|
names = append(names, name)
|
|
}
|
|
return names, nil
|
|
}
|
|
|
|
// AccountsDir --
|
|
func (w *Wallet) AccountsDir() string {
|
|
return w.InnerAccountsDir
|
|
}
|
|
|
|
// Dir for the wallet.
|
|
func (w *Wallet) Dir() string {
|
|
return w.WalletDir
|
|
}
|
|
|
|
// KeymanagerKind --
|
|
func (w *Wallet) KeymanagerKind() keymanager.Kind {
|
|
return w.Kind
|
|
}
|
|
|
|
// Exists --
|
|
func (w *Wallet) Exists() (bool, error) {
|
|
return len(w.Directories) > 0, nil
|
|
}
|
|
|
|
// Password --
|
|
func (w *Wallet) Password() string {
|
|
return w.WalletPassword
|
|
}
|
|
|
|
// WriteFileAtPath --
|
|
func (w *Wallet) WriteFileAtPath(_ context.Context, pathName, fileName string, data []byte) (bool, error) {
|
|
w.lock.Lock()
|
|
defer w.lock.Unlock()
|
|
if w.HasWriteFileError {
|
|
// reset the flag to not contaminate other tests
|
|
w.HasWriteFileError = false
|
|
return false, errors.New("could not write keystore file for accounts")
|
|
}
|
|
if w.Files[pathName] == nil {
|
|
w.Files[pathName] = make(map[string][]byte)
|
|
}
|
|
w.Files[pathName][fileName] = data
|
|
return true, nil
|
|
}
|
|
|
|
// ReadFileAtPath --
|
|
func (w *Wallet) ReadFileAtPath(_ context.Context, pathName, fileName string) ([]byte, error) {
|
|
w.lock.RLock()
|
|
defer w.lock.RUnlock()
|
|
for f, v := range w.Files[pathName] {
|
|
if strings.Contains(fileName, f) {
|
|
return v, nil
|
|
}
|
|
}
|
|
return nil, errors.New("no files found")
|
|
}
|
|
|
|
// InitializeKeymanager --
|
|
func (_ *Wallet) InitializeKeymanager(_ context.Context, _ iface.InitKeymanagerConfig) (keymanager.IKeymanager, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
type Validator struct {
|
|
Km keymanager.IKeymanager
|
|
graffiti string
|
|
proposerSettings *proposer.Settings
|
|
}
|
|
|
|
func (_ *Validator) LogSubmittedSyncCommitteeMessages() {}
|
|
|
|
func (_ *Validator) Done() {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) WaitForChainStart(_ context.Context) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) WaitForSync(_ context.Context) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) WaitForActivation(_ context.Context, _ chan [][48]byte) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) CanonicalHeadSlot(_ context.Context) (primitives.Slot, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) NextSlot() <-chan primitives.Slot {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) SlotDeadline(_ primitives.Slot) time.Time {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) LogValidatorGainsAndLosses(_ context.Context, _ primitives.Slot) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) UpdateDuties(_ context.Context, _ primitives.Slot) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) RolesAt(_ context.Context, _ primitives.Slot) (map[[48]byte][]iface2.ValidatorRole, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) SubmitAttestation(_ context.Context, _ primitives.Slot, _ [48]byte) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) ProposeBlock(_ context.Context, _ primitives.Slot, _ [48]byte) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) SubmitAggregateAndProof(_ context.Context, _ primitives.Slot, _ [48]byte) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) SubmitSyncCommitteeMessage(_ context.Context, _ primitives.Slot, _ [48]byte) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) SubmitSignedContributionAndProof(_ context.Context, _ primitives.Slot, _ [48]byte) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) LogSubmittedAtts(_ primitives.Slot) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) UpdateDomainDataCaches(_ context.Context, _ primitives.Slot) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) WaitForKeymanagerInitialization(_ context.Context) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (m *Validator) Keymanager() (keymanager.IKeymanager, error) {
|
|
return m.Km, nil
|
|
}
|
|
|
|
func (_ *Validator) ReceiveSlots(_ context.Context, _ chan<- error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) HandleKeyReload(_ context.Context, _ [][48]byte) (bool, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (_ *Validator) CheckDoppelGanger(_ context.Context) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
// HasProposerSettings for mocking
|
|
func (*Validator) HasProposerSettings() bool {
|
|
panic("implement me")
|
|
}
|
|
|
|
// PushProposerSettings for mocking
|
|
func (_ *Validator) PushProposerSettings(_ context.Context, _ keymanager.IKeymanager, _ primitives.Slot, _ time.Time) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
// SetPubKeyToValidatorIndexMap for mocking
|
|
func (_ *Validator) SetPubKeyToValidatorIndexMap(_ context.Context, _ keymanager.IKeymanager) error {
|
|
panic("implement me")
|
|
}
|
|
|
|
// SignValidatorRegistrationRequest for mocking
|
|
func (_ *Validator) SignValidatorRegistrationRequest(_ context.Context, _ iface2.SigningFunc, _ *ethpb.ValidatorRegistrationV1) (*ethpb.SignedValidatorRegistrationV1, error) {
|
|
panic("implement me")
|
|
}
|
|
|
|
// ProposerSettings for mocking
|
|
func (m *Validator) ProposerSettings() *proposer.Settings {
|
|
return m.proposerSettings
|
|
}
|
|
|
|
// SetProposerSettings for mocking
|
|
func (m *Validator) SetProposerSettings(_ context.Context, settings *proposer.Settings) error {
|
|
m.proposerSettings = settings
|
|
return nil
|
|
}
|
|
|
|
// Graffiti for mocking
|
|
func (m *Validator) Graffiti(_ context.Context, _ [fieldparams.BLSPubkeyLength]byte) ([]byte, error) {
|
|
return []byte(m.graffiti), nil
|
|
}
|
|
|
|
// SetGraffiti for mocking
|
|
func (m *Validator) SetGraffiti(_ context.Context, _ [fieldparams.BLSPubkeyLength]byte, graffiti []byte) error {
|
|
m.graffiti = string(graffiti)
|
|
return nil
|
|
}
|
|
|
|
// DeleteGraffiti for mocking
|
|
func (m *Validator) DeleteGraffiti(_ context.Context, _ [fieldparams.BLSPubkeyLength]byte) error {
|
|
m.graffiti = ""
|
|
return nil
|
|
}
|
|
|
|
func (*Validator) StartEventStream(_ context.Context, _ []string, _ chan<- *event.Event) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (*Validator) ProcessEvent(event *event.Event) {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (*Validator) EventStreamIsRunning() bool {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (*Validator) HealthTracker() *beacon.NodeHealthTracker {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (*Validator) Host() string {
|
|
panic("implement me")
|
|
}
|
|
|
|
func (*Validator) ChangeHost() {
|
|
panic("implement me")
|
|
}
|