Skip to content

Commit

Permalink
Merge pull request #1 from PowerLoom/feat/syncing-epoch-related-const…
Browse files Browse the repository at this point in the history
…ants

Feat/syncing epoch related constants
  • Loading branch information
Sulejman authored Sep 10, 2024
2 parents ed46898 + d868371 commit 76baa84
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
10 changes: 6 additions & 4 deletions pkgs/constants.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package pkgs

const (
CurrentEpoch = "CurrentEpoch"
CurrentBatchId = "CurrentBatchId"
EpochsInADay = "EpochsInADay"
SlotCounter = "SlotCounter"
CurrentEpoch = "CurrentEpoch"
CurrentBatchId = "CurrentBatchId"
EpochsInADay = "EpochsInADay"
SlotCounter = "SlotCounter"
EPOCH_SIZE = "EPOCH_SIZE"
SOURCE_CHAIN_BLOCK_TIME = "SOURCE_CHAIN_BLOCK_TIME"
)
13 changes: 12 additions & 1 deletion pkgs/prost/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
listenerCommon "protocol-state-cacher/pkgs/common"
"protocol-state-cacher/pkgs/contract"
"protocol-state-cacher/pkgs/redis"
"strconv"
"sync"
"time"
)
Expand Down Expand Up @@ -71,7 +72,7 @@ func MustQuery[K any](ctx context.Context, call func(opts *bind.CallOpts) (val K
func ColdSyncMappings() {
for {
coldSyncAllSlots()
time.Sleep(1 * time.Minute)
time.Sleep(60 * time.Minute)
}

}
Expand Down Expand Up @@ -170,6 +171,16 @@ func PopulateStateVars() {
key := redis.ContractStateVariable(pkgs.EpochsInADay)
PersistState(context.Background(), key, output.String())
}

if output, err := Instance.EPOCHSIZE(&bind.CallOpts{}, DataMarket); output != 0 && err == nil {
key := redis.ContractStateVariable(pkgs.EPOCH_SIZE)
PersistState(context.Background(), key, strconv.Itoa(int(output)))
}

if output, err := Instance.SOURCECHAINBLOCKTIME(&bind.CallOpts{}, DataMarket); output != nil && err == nil {
key := redis.ContractStateVariable(pkgs.SOURCE_CHAIN_BLOCK_TIME)
PersistState(context.Background(), key, strconv.Itoa(int(output.Int64())))
}
}

func PersistState(ctx context.Context, key string, val string) {
Expand Down
9 changes: 9 additions & 0 deletions protocol-state-cacher.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

0 comments on commit 76baa84

Please sign in to comment.