Skip to content

Commit ef9ce18

Browse files
authored
Merge branch 'develop' into refactoring-SSZ-QL-Access-n-th-Element-in-list-vector
2 parents 80bff1e + 64ec665 commit ef9ce18

File tree

8 files changed

+47
-9
lines changed

8 files changed

+47
-9
lines changed

beacon-chain/node/clear_db.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package node
22

33
import (
44
"context"
5+
"os"
56

67
"github.com/OffchainLabs/prysm/v6/beacon-chain/db/filesystem"
78
"github.com/OffchainLabs/prysm/v6/beacon-chain/db/kv"
89
"github.com/OffchainLabs/prysm/v6/beacon-chain/db/slasherkv"
910
"github.com/OffchainLabs/prysm/v6/cmd"
11+
"github.com/OffchainLabs/prysm/v6/genesis"
1012
"github.com/pkg/errors"
1113
"github.com/urfave/cli/v2"
1214
)
@@ -36,6 +38,22 @@ func (c *dbClearer) clearKV(ctx context.Context, db *kv.Store) (*kv.Store, error
3638
return kv.NewKVStore(ctx, db.DatabasePath())
3739
}
3840

41+
func (c *dbClearer) clearGenesis(dir string) error {
42+
if !c.shouldProceed() {
43+
return nil
44+
}
45+
46+
gfile, err := genesis.FindStateFile(dir)
47+
if err != nil {
48+
return nil
49+
}
50+
51+
if err := os.Remove(gfile.FilePath()); err != nil {
52+
return errors.Wrapf(err, "genesis state file not removed: %s", gfile.FilePath())
53+
}
54+
return nil
55+
}
56+
3957
func (c *dbClearer) clearBlobs(bs *filesystem.BlobStorage) error {
4058
if !c.shouldProceed() {
4159
return nil

beacon-chain/node/node.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func New(cliCtx *cli.Context, cancel context.CancelFunc, opts ...Option) (*Beaco
177177
}
178178
beacon.db = kvdb
179179

180+
if err := dbClearer.clearGenesis(dataDir); err != nil {
181+
return nil, errors.Wrap(err, "could not clear genesis state")
182+
}
180183
providers := append(beacon.GenesisProviders, kv.NewLegacyGenesisProvider(kvdb))
181184
if err := genesis.Initialize(ctx, dataDir, providers...); err != nil {
182185
return nil, errors.Wrap(err, "could not initialize genesis state")

beacon-chain/rpc/eth/validator/handlers.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,18 @@ func (s *Server) SubmitSyncCommitteeSubscription(w http.ResponseWriter, r *http.
597597
epochDuration := time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) * time.Second
598598
totalDuration := epochDuration * time.Duration(epochsToWatch)
599599

600-
cache.SyncSubnetIDs.AddSyncCommitteeSubnets(pubkey48[:], startEpoch, sub.SyncCommitteeIndices, totalDuration)
600+
subcommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount
601+
seen := make(map[uint64]bool)
602+
var subnetIndices []uint64
603+
604+
for _, idx := range sub.SyncCommitteeIndices {
605+
subnetIdx := idx / subcommitteeSize
606+
if !seen[subnetIdx] {
607+
seen[subnetIdx] = true
608+
subnetIndices = append(subnetIndices, subnetIdx)
609+
}
610+
}
611+
cache.SyncSubnetIDs.AddSyncCommitteeSubnets(pubkey48[:], startEpoch, subnetIndices, totalDuration)
601612
}
602613
}
603614

beacon-chain/rpc/eth/validator/handlers_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,8 @@ func TestSubmitSyncCommitteeSubscription(t *testing.T) {
10491049
s.SubmitSyncCommitteeSubscription(writer, request)
10501050
assert.Equal(t, http.StatusOK, writer.Code)
10511051
subnets, _, _, _ := cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkeys[1], 0)
1052-
require.Equal(t, 2, len(subnets))
1052+
require.Equal(t, 1, len(subnets))
10531053
assert.Equal(t, uint64(0), subnets[0])
1054-
assert.Equal(t, uint64(2), subnets[1])
10551054
})
10561055
t.Run("multiple", func(t *testing.T) {
10571056
cache.SyncSubnetIDs.EmptyAllCaches()
@@ -1070,7 +1069,7 @@ func TestSubmitSyncCommitteeSubscription(t *testing.T) {
10701069
assert.Equal(t, uint64(0), subnets[0])
10711070
subnets, _, _, _ = cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkeys[1], 0)
10721071
require.Equal(t, 1, len(subnets))
1073-
assert.Equal(t, uint64(2), subnets[0])
1072+
assert.Equal(t, uint64(0), subnets[0])
10741073
})
10751074
t.Run("no body", func(t *testing.T) {
10761075
request := httptest.NewRequest(http.MethodPost, "http://example.com", nil)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Fixed
2+
- Delete the genesis state file when --clear-db / --force-clear-db is specified.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fix sync committee subscription to use subnet indices instead of committee indices

genesis/initialize.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func Initialize(ctx context.Context, dir string, providers ...Provider) error {
2323
setPkgVar(emb, true)
2424
return nil
2525
}
26-
gd, err := findGenesisFile(dir)
26+
gd, err := FindStateFile(dir)
2727
if err == nil {
2828
setPkgVar(gd, true)
2929
return nil
@@ -65,7 +65,8 @@ func newGenesisData(st state.BeaconState, dir string) (GenesisData, error) {
6565
}, nil
6666
}
6767

68-
func findGenesisFile(dir string) (GenesisData, error) {
68+
// FindStateFile searches for a valid genesis state file in the specified directory.
69+
func FindStateFile(dir string) (GenesisData, error) {
6970
if dir == "" {
7071
return GenesisData{}, ErrFilePathUnset
7172
}

genesis/storage.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ type GenesisData struct {
100100
initialized bool
101101
}
102102

103-
func (d GenesisData) filePath() string {
103+
// FilePath returns the full path to the genesis state file.
104+
func (d GenesisData) FilePath() string {
104105
parts := [3]string{}
105106
parts[genesisPart] = "genesis"
106107
parts[timePart] = strconv.FormatInt(d.Time.Unix(), 10)
@@ -115,7 +116,7 @@ func persist(d GenesisData) error {
115116
if d.FileDir == "" {
116117
return ErrFilePathUnset
117118
}
118-
fpath := d.filePath()
119+
fpath := d.FilePath()
119120
sb, err := d.State.MarshalSSZ()
120121
if err != nil {
121122
return errors.Wrap(err, "marshal ssz")
@@ -144,7 +145,7 @@ func loadState() (state.BeaconState, error) {
144145
stateMu.Lock()
145146
defer stateMu.Unlock()
146147

147-
s, err := stateFromFile(data.filePath())
148+
s, err := stateFromFile(data.FilePath())
148149
if err != nil {
149150
return nil, errors.Wrapf(err, "InitializeFromProtoUnsafePhase0")
150151
}

0 commit comments

Comments
 (0)