From 00b3a7695f0228fbc75a194455575a454beef6a4 Mon Sep 17 00:00:00 2001 From: Calin Martinconi Date: Sun, 10 Nov 2024 22:04:49 +0200 Subject: [PATCH] fix: add warmup allowing pullsync to commence --- pkg/api/api_test.go | 2 +- pkg/node/node.go | 4 ++-- pkg/storageincentives/agent.go | 12 +++++++----- pkg/storageincentives/agent_test.go | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index e480fd0d862..bcf0c8c156d 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -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, diff --git a/pkg/node/node.go b/pkg/node/node.go index bd68ada5f26..780599315f6 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -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) diff --git a/pkg/storageincentives/agent.go b/pkg/storageincentives/agent.go index 3be9ebb28ea..8cbc13a537c 100644 --- a/pkg/storageincentives/agent.go +++ b/pkg/storageincentives/agent.go @@ -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 @@ -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, @@ -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 } @@ -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() @@ -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() diff --git a/pkg/storageincentives/agent_test.go b/pkg/storageincentives/agent_test.go index 8af6b1d463e..17e6269f202 100644 --- a/pkg/storageincentives/agent_test.go +++ b/pkg/storageincentives/agent_test.go @@ -192,7 +192,7 @@ func createService( postageContract, stakingContract, reserve, - func() bool { return true }, + func(time.Time) bool { return true }, time.Millisecond*100, blocksPerRound, blocksPerPhase,