github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/version_beacon.go (about) 1 package badger 2 3 import ( 4 "errors" 5 6 "github.com/dgraph-io/badger/v2" 7 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/storage" 10 "github.com/onflow/flow-go/storage/badger/operation" 11 ) 12 13 type VersionBeacons struct { 14 db *badger.DB 15 } 16 17 var _ storage.VersionBeacons = (*VersionBeacons)(nil) 18 19 func NewVersionBeacons(db *badger.DB) *VersionBeacons { 20 res := &VersionBeacons{ 21 db: db, 22 } 23 24 return res 25 } 26 27 func (r *VersionBeacons) Highest( 28 belowOrEqualTo uint64, 29 ) (*flow.SealedVersionBeacon, error) { 30 tx := r.db.NewTransaction(false) 31 defer tx.Discard() 32 33 var beacon flow.SealedVersionBeacon 34 35 err := operation.LookupLastVersionBeaconByHeight(belowOrEqualTo, &beacon)(tx) 36 if err != nil { 37 if errors.Is(err, storage.ErrNotFound) { 38 return nil, nil 39 } 40 return nil, err 41 } 42 return &beacon, nil 43 }