Skip to content

Commit

Permalink
Sync epoch related values
Browse files Browse the repository at this point in the history
- EPOCH_SIZE
- SOURCE_CHAIN_BLOCK_TIME
  • Loading branch information
Sulejman committed Aug 26, 2024
1 parent 9f1c75c commit d868371
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
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 d868371

Please sign in to comment.