Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Sep 10, 2024
1 parent bd36128 commit e89a005
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion e2etest/monitor_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (
"testing"
)

func TestMonitor(t *testing.T) {
// TestMonitorBootstrap - validates that after a restart monitor bootstraps from DB
func TestMonitorBootstrap(t *testing.T) {
numMatureOutputs := uint32(150)

tm := StartManager(t, numMatureOutputs, 2)
Expand Down
19 changes: 10 additions & 9 deletions monitor/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func NewMonitorStore(backend kvdb.Backend) (*MonitorStore, error) {
func (s *MonitorStore) createBuckets() error {
buckets := [][]byte{epochsBucketName, heightBucketName}
for _, bucket := range buckets {
if err := kvdb.Batch(s.db, func(tx kvdb.RwTx) error {
if err := s.db.Update(func(tx kvdb.RwTx) error {
_, err := tx.CreateTopLevelBucket(bucket)
if err != nil {
return err
}

return nil
}); err != nil {
}, func() {}); err != nil {
return err
}
}
Expand All @@ -73,26 +73,27 @@ func (s *MonitorStore) PutLatestHeight(height uint64) error {
func (s *MonitorStore) get(key, bucketName []byte) (uint64, bool, error) {
var returnVal uint64

if err := s.db.View(func(tx walletdb.ReadTx) error {
err := s.db.View(func(tx walletdb.ReadTx) error {
b := tx.ReadBucket(bucketName)
if b == nil {
return ErrCorruptedDb
}

value := b.Get(key)
if value == nil {
byteVal := b.Get(key)
if byteVal == nil {
return ErrNotFound
}

epoch, err := uint64FromBytes(value)
val, err := uint64FromBytes(byteVal)
if err != nil {
return err
}
returnVal = epoch
returnVal = val

return nil
}, func() {
}); err != nil {
}, func() {})

if err != nil {
if errors.Is(err, ErrNotFound) {
return 0, false, nil
}
Expand Down

0 comments on commit e89a005

Please sign in to comment.