Skip to content

Commit

Permalink
fix: add warmup allowing pullsync to commence
Browse files Browse the repository at this point in the history
  • Loading branch information
martinconic committed Nov 10, 2024
1 parent daefec6 commit 00b3a76
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func createRedistributionAgentService(
postageContract,
stakingContract,
mockstorer.NewReserve(),
func() bool { return true },
func(time.Time) bool { return true },
time.Millisecond*10,
blocksPerRound,
blocksPerPhase,
Expand Down
4 changes: 2 additions & 2 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,9 +1062,9 @@ func NewBee(
redistributionContractAddress = common.HexToAddress(o.RedistributionContractAddress)
}

isFullySynced := func() bool {
isFullySynced := func(startWarmupPeriod time.Time) bool {
reserveTreshold := reserveCapacity * 5 / 10
return localStore.ReserveSize() >= reserveTreshold && pullerService.SyncRate() == 0
return localStore.ReserveSize() >= reserveTreshold && pullerService.SyncRate() == 0 && time.Now().After(startWarmupPeriod.Add(warmupTime))
}

redistributionContract := redistribution.New(swarmAddress, overlayEthAddress, logger, transactionService, redistributionContractAddress, abiutil.MustParseABI(chainCfg.RedistributionABI), o.TrxDebugMode)
Expand Down
12 changes: 7 additions & 5 deletions pkg/storageincentives/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type Agent struct {
batchExpirer postagecontract.PostageBatchExpirer
redistributionStatuser staking.RedistributionStatuser
store storer.Reserve
fullSyncedFunc func() bool
fullSyncedFunc func(time.Time) bool
overlay swarm.Address
quit chan struct{}
wg sync.WaitGroup
Expand All @@ -79,7 +79,7 @@ func New(overlay swarm.Address,
batchExpirer postagecontract.PostageBatchExpirer,
redistributionStatuser staking.RedistributionStatuser,
store storer.Reserve,
fullSyncedFunc func() bool,
fullSyncedFunc func(time.Time) bool,
blockTime time.Duration,
blocksPerRound,
blocksPerPhase uint64,
Expand Down Expand Up @@ -113,8 +113,10 @@ func New(overlay swarm.Address,

a.state = state

startWarmupPeriod := time.Now()

a.wg.Add(1)
go a.start(blockTime, a.blocksPerRound, blocksPerPhase)
go a.start(blockTime, a.blocksPerRound, blocksPerPhase, startWarmupPeriod)

return a, nil
}
Expand All @@ -125,7 +127,7 @@ func New(overlay swarm.Address,
// If our neighborhood is selected to participate, a sample is created during the sample phase. In the commit phase,
// the sample is submitted, and in the reveal phase, the obfuscation key from the commit phase is submitted.
// Next, in the claim phase, we check if we've won, and the cycle repeats. The cycle must occur in the length of one round.
func (a *Agent) start(blockTime time.Duration, blocksPerRound, blocksPerPhase uint64) {
func (a *Agent) start(blockTime time.Duration, blocksPerRound, blocksPerPhase uint64, startWarmup time.Time) {
defer a.wg.Done()

phaseEvents := newEvents()
Expand Down Expand Up @@ -218,7 +220,7 @@ func (a *Agent) start(blockTime time.Duration, blocksPerRound, blocksPerPhase ui
a.logger.Info("entered new phase", "phase", currentPhase.String(), "round", round, "block", block)

a.state.SetCurrentEvent(currentPhase, round)
a.state.SetFullySynced(a.fullSyncedFunc())
a.state.SetFullySynced(a.fullSyncedFunc(startWarmup))
a.state.SetHealthy(a.health.IsHealthy())
go a.state.purgeStaleRoundData()

Expand Down
2 changes: 1 addition & 1 deletion pkg/storageincentives/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func createService(
postageContract,
stakingContract,
reserve,
func() bool { return true },
func(time.Time) bool { return true },
time.Millisecond*100,
blocksPerRound,
blocksPerPhase,
Expand Down

0 comments on commit 00b3a76

Please sign in to comment.