-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
3,163 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package kv | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/prysmaticlabs/prysm/v4/proto/dbval" | ||
bolt "go.etcd.io/bbolt" | ||
"go.opencensus.io/trace" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
// SaveBackfillStatus encodes the given BackfillStatus protobuf struct and writes it to a single key in the db. | ||
// This value is used by the backfill service to keep track of the range of blocks that need to be synced. It is also used by the | ||
// code that serves blocks or regenerates states to keep track of what range of blocks are available. | ||
func (s *Store) SaveBackfillStatus(ctx context.Context, bf *dbval.BackfillStatus) error { | ||
_, span := trace.StartSpan(ctx, "BeaconDB.SaveBackfillStatus") | ||
defer span.End() | ||
bfb, err := proto.Marshal(bf) | ||
if err != nil { | ||
return err | ||
} | ||
return s.db.Update(func(tx *bolt.Tx) error { | ||
bucket := tx.Bucket(blocksBucket) | ||
return bucket.Put(backfillStatusKey, bfb) | ||
}) | ||
} | ||
|
||
// BackfillStatus retrieves the most recently saved version of the BackfillStatus protobuf struct. | ||
// This is used to persist information about backfill status across restarts. | ||
func (s *Store) BackfillStatus(ctx context.Context) (*dbval.BackfillStatus, error) { | ||
_, span := trace.StartSpan(ctx, "BeaconDB.BackfillStatus") | ||
defer span.End() | ||
bf := &dbval.BackfillStatus{} | ||
err := s.db.View(func(tx *bolt.Tx) error { | ||
bucket := tx.Bucket(blocksBucket) | ||
bs := bucket.Get(backfillStatusKey) | ||
if len(bs) == 0 { | ||
return errors.Wrap(ErrNotFound, "BackfillStatus not found") | ||
} | ||
return proto.Unmarshal(bs, bf) | ||
}) | ||
return bf, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kv | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil" | ||
"github.com/prysmaticlabs/prysm/v4/proto/dbval" | ||
"github.com/prysmaticlabs/prysm/v4/testing/require" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func TestBackfillRoundtrip(t *testing.T) { | ||
db := setupDB(t) | ||
b := &dbval.BackfillStatus{} | ||
b.LowSlot = 23 | ||
b.LowRoot = bytesutil.PadTo([]byte("low"), 32) | ||
b.LowParentRoot = bytesutil.PadTo([]byte("parent"), 32) | ||
m, err := proto.Marshal(b) | ||
require.NoError(t, err) | ||
ub := &dbval.BackfillStatus{} | ||
require.NoError(t, proto.Unmarshal(m, ub)) | ||
require.Equal(t, b.LowSlot, ub.LowSlot) | ||
require.DeepEqual(t, b.LowRoot, ub.LowRoot) | ||
require.DeepEqual(t, b.LowParentRoot, ub.LowParentRoot) | ||
|
||
ctx := context.Background() | ||
require.NoError(t, db.SaveBackfillStatus(ctx, b)) | ||
dbub, err := db.BackfillStatus(ctx) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, b.LowSlot, dbub.LowSlot) | ||
require.DeepEqual(t, b.LowRoot, dbub.LowRoot) | ||
require.DeepEqual(t, b.LowParentRoot, dbub.LowParentRoot) | ||
} |
Oops, something went wrong.