mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
c5c039fd6b
* Unify `GenesisValidator(s)Root` throughout the codebase * comments and literals Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
37 lines
935 B
Go
37 lines
935 B
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
bolt "go.etcd.io/bbolt"
|
|
)
|
|
|
|
// SaveGenesisValidatorsRoot saves the genesis validators root to db.
|
|
func (s *Store) SaveGenesisValidatorsRoot(ctx context.Context, genValRoot []byte) error {
|
|
err := s.db.Update(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(genesisInfoBucket)
|
|
enc := bkt.Get(genesisValidatorsRootKey)
|
|
if len(enc) != 0 {
|
|
return fmt.Errorf("cannot overwite existing genesis validators root: %#x", enc)
|
|
}
|
|
return bkt.Put(genesisValidatorsRootKey, genValRoot)
|
|
})
|
|
return err
|
|
}
|
|
|
|
// GenesisValidatorsRoot retrieves the genesis validators root from db.
|
|
func (s *Store) GenesisValidatorsRoot(ctx context.Context) ([]byte, error) {
|
|
var genValRoot []byte
|
|
err := s.db.View(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(genesisInfoBucket)
|
|
enc := bkt.Get(genesisValidatorsRootKey)
|
|
if len(enc) == 0 {
|
|
return nil
|
|
}
|
|
genValRoot = enc
|
|
return nil
|
|
})
|
|
return genValRoot, err
|
|
}
|