prysm-pulse/time/slots/countdown.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

58 lines
1.7 KiB
Go

package slots
import (
"context"
"fmt"
"time"
"github.com/prysmaticlabs/prysm/v3/config/params"
prysmTime "github.com/prysmaticlabs/prysm/v3/time"
"github.com/sirupsen/logrus"
)
var log = logrus.WithField("prefix", "slotutil")
// CountdownToGenesis starts a ticker at the specified duration
// logging the remaining minutes until the genesis chainstart event
// along with important genesis state metadata such as number
// of genesis validators.
func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValidatorCount uint64, genesisStateRoot [32]byte) {
ticker := time.NewTicker(params.BeaconConfig().GenesisCountdownInterval)
defer func() {
// Used in anonymous function to make sure that updated (per second) ticker is stopped.
ticker.Stop()
}()
logFields := logrus.Fields{
"genesisValidators": fmt.Sprintf("%d", genesisValidatorCount),
"genesisTime": fmt.Sprintf("%v", genesisTime),
"genesisStateRoot": fmt.Sprintf("%x", genesisStateRoot),
}
secondTimerActivated := false
for {
currentTime := prysmTime.Now()
if currentTime.After(genesisTime) {
log.WithFields(logFields).Info("Chain genesis time reached")
return
}
timeRemaining := genesisTime.Sub(currentTime)
if !secondTimerActivated && timeRemaining <= 2*time.Minute {
ticker.Stop()
// Replace ticker with a one having higher granularity.
ticker = time.NewTicker(time.Second)
secondTimerActivated = true
}
if timeRemaining >= time.Second {
log.WithFields(logFields).Infof(
"%s until chain genesis",
timeRemaining.Truncate(time.Second),
)
}
select {
case <-ticker.C:
case <-ctx.Done():
log.Debug("Context closed, exiting routine")
return
}
}
}