mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
87ca73d605
* added in logic * latest countdown * fixed up formatting and add tests * ready for review * Merge branch 'master' into countdown-genesis * no log if after genesis * Merge branch 'countdown-genesis' of github.com:prysmaticlabs/prysm into countdown-genesis * countdown * smarter logging * added buffer period for countdown * Merge refs/heads/master into countdown-genesis
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package slotutil
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/roughtime"
|
|
"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) {
|
|
ticker := time.NewTicker(params.BeaconConfig().GenesisCountdownInterval)
|
|
timeTillGenesis := genesisTime.Sub(roughtime.Now())
|
|
logFields := logrus.Fields{
|
|
"genesisValidators": fmt.Sprintf("%d", genesisValidatorCount),
|
|
"genesisTime": fmt.Sprintf("%v", genesisTime),
|
|
}
|
|
for {
|
|
select {
|
|
case <-time.After(timeTillGenesis):
|
|
log.WithFields(logFields).Info("Chain genesis time reached")
|
|
return
|
|
case <-ticker.C:
|
|
currentTime := roughtime.Now()
|
|
if currentTime.After(genesisTime) {
|
|
log.WithFields(logFields).Info("Chain genesis time reached")
|
|
return
|
|
}
|
|
timeRemaining := genesisTime.Sub(currentTime)
|
|
if timeRemaining <= 2*time.Minute {
|
|
ticker = time.NewTicker(time.Second)
|
|
}
|
|
if timeRemaining >= time.Second {
|
|
log.WithFields(logFields).Infof(
|
|
"%s until chain genesis",
|
|
timeRemaining.Truncate(time.Second),
|
|
)
|
|
}
|
|
case <-ctx.Done():
|
|
return
|
|
}
|
|
}
|
|
}
|