From e32f70600f98c06d3fd65f3550e6c0d8180dc90f Mon Sep 17 00:00:00 2001 From: matejmlejnek <97440610+matejmlejnek@users.noreply.github.com> Date: Sat, 16 Dec 2023 22:03:10 +0100 Subject: [PATCH] Add md setters for updateset interval and size (#885) * Add md setters for updateset interval and size --- cmd/util-db/db/insert.go | 16 ++++++++++++++++ utildb/utils.go | 1 - utils/metadata.go | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cmd/util-db/db/insert.go b/cmd/util-db/db/insert.go index 241118b35..67fbd19b5 100644 --- a/cmd/util-db/db/insert.go +++ b/cmd/util-db/db/insert.go @@ -144,6 +144,22 @@ func insertMetadata(ctx *cli.Context) error { if err = md.SetDbHash(hash); err != nil { return err } + case substate.UpdatesetIntervalKey: + val, err = strconv.ParseUint(valArg, 10, 64) + if err != nil { + return fmt.Errorf("cannot parse uint %v; %v", valArg, err) + } + if err = md.SetUpdatesetInterval(val); err != nil { + return err + } + case substate.UpdatesetSizeKey: + val, err = strconv.ParseUint(valArg, 10, 64) + if err != nil { + return fmt.Errorf("cannot parse uint %v; %v", valArg, err) + } + if err = md.SetUpdatesetSize(val); err != nil { + return err + } default: return fmt.Errorf("incorrect keyArg: %v", keyArg) } diff --git a/utildb/utils.go b/utildb/utils.go index b80f6c51d..ca73d5455 100644 --- a/utildb/utils.go +++ b/utildb/utils.go @@ -442,7 +442,6 @@ func printUpdateSetInfo(m *utils.AidaDbMetadata) { } else { u := bigendian.BytesToUint64(sizeBytes) - // todo convert to mb log.Infof("Size: %.1f MB", float64(u)/float64(1_000_000)) } } diff --git a/utils/metadata.go b/utils/metadata.go index effb0d26c..2a83ca777 100644 --- a/utils/metadata.go +++ b/utils/metadata.go @@ -1139,3 +1139,26 @@ func HasStateHashPatch(path string) (bool, error) { func (md *AidaDbMetadata) SetHasHashPatch() error { return md.Db.Put([]byte(HasStateHashPatchPrefix), []byte{1}) } + +func (md *AidaDbMetadata) SetUpdatesetInterval(val uint64) error { + byteInterval := make([]byte, 8) + binary.BigEndian.PutUint64(byteInterval, val) + + if err := md.Db.Put([]byte(substate.UpdatesetIntervalKey), byteInterval); err != nil { + return err + } + md.log.Info("METADATA: Updateset interval saved successfully") + + return nil +} + +func (md *AidaDbMetadata) SetUpdatesetSize(val uint64) error { + sizeInterval := make([]byte, 8) + binary.BigEndian.PutUint64(sizeInterval, val) + + if err := md.Db.Put([]byte(substate.UpdatesetSizeKey), sizeInterval); err != nil { + return err + } + md.log.Info("METADATA: Updateset size saved successfully") + return nil +}