QSP58, QSP59 - Fix DB spans (#6352)

* Fix spans
* Merge refs/heads/master into qsp58-59
This commit is contained in:
terence tsao 2020-06-22 19:22:22 -07:00 committed by GitHub
parent 368af7e53f
commit 5c8da7a1c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -92,7 +92,7 @@ func (k *Store) ArchivedBalances(ctx context.Context, epoch uint64) ([]uint64, e
if enc == nil { if enc == nil {
return nil return nil
} }
target = unmarshalBalances(enc) target = unmarshalBalances(ctx, enc)
return nil return nil
}) })
return target, err return target, err
@ -103,7 +103,7 @@ func (k *Store) SaveArchivedBalances(ctx context.Context, epoch uint64, balances
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveArchivedBalances") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveArchivedBalances")
defer span.End() defer span.End()
buf := bytesutil.Uint64ToBytes(epoch) buf := bytesutil.Uint64ToBytes(epoch)
enc := marshalBalances(balances) enc := marshalBalances(ctx, balances)
return k.db.Update(func(tx *bolt.Tx) error { return k.db.Update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(archivedBalancesBucket) bucket := tx.Bucket(archivedBalancesBucket)
return bucket.Put(buf, enc) return bucket.Put(buf, enc)
@ -144,7 +144,10 @@ func (k *Store) SaveArchivedValidatorParticipation(ctx context.Context, epoch ui
}) })
} }
func marshalBalances(bals []uint64) []byte { func marshalBalances(ctx context.Context, bals []uint64) []byte {
ctx, span := trace.StartSpan(ctx, "BeaconDB.marshalBalances")
defer span.End()
res := make([]byte, len(bals)*8) res := make([]byte, len(bals)*8)
offset := 0 offset := 0
for i := 0; i < len(bals); i++ { for i := 0; i < len(bals); i++ {
@ -154,7 +157,10 @@ func marshalBalances(bals []uint64) []byte {
return res return res
} }
func unmarshalBalances(bals []byte) []uint64 { func unmarshalBalances(ctx context.Context, bals []byte) []uint64 {
ctx, span := trace.StartSpan(ctx, "BeaconDB.unmarshalBalances")
defer span.End()
numItems := len(bals) / 8 numItems := len(bals) / 8
res := make([]uint64, numItems) res := make([]uint64, numItems)
offset := 0 offset := 0

View File

@ -22,7 +22,7 @@ func (k *Store) SaveArchivedPointRoot(ctx context.Context, blockRoot [32]byte, i
// SaveLastArchivedIndex to the db. // SaveLastArchivedIndex to the db.
func (k *Store) SaveLastArchivedIndex(ctx context.Context, index uint64) error { func (k *Store) SaveLastArchivedIndex(ctx context.Context, index uint64) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveHeadBlockRoot") ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveLastArchivedIndex")
defer span.End() defer span.End()
return k.db.Update(func(tx *bolt.Tx) error { return k.db.Update(func(tx *bolt.Tx) error {
bucket := tx.Bucket(archivedIndexRootBucket) bucket := tx.Bucket(archivedIndexRootBucket)
@ -72,7 +72,7 @@ func (k *Store) LastArchivedIndexRoot(ctx context.Context) [32]byte {
// ArchivedPointRoot returns the block root of an archived point from the DB. // ArchivedPointRoot returns the block root of an archived point from the DB.
// This is essential for cold state management and to restore a cold state. // This is essential for cold state management and to restore a cold state.
func (k *Store) ArchivedPointRoot(ctx context.Context, index uint64) [32]byte { func (k *Store) ArchivedPointRoot(ctx context.Context, index uint64) [32]byte {
ctx, span := trace.StartSpan(ctx, "BeaconDB.ArchivePointRoot") ctx, span := trace.StartSpan(ctx, "BeaconDB.ArchivedPointRoot")
defer span.End() defer span.End()
var blockRoot []byte var blockRoot []byte