diff --git a/node/node.go b/node/node.go index 02e5bc16b1..db198df34a 100644 --- a/node/node.go +++ b/node/node.go @@ -115,6 +115,9 @@ type AlgorandFullNode struct { log logging.Logger + // syncStatusMu used for locking lastRoundTimestamp and hasSyncedSinceStartup + // syncStatusMu added so OnNewBlock wouldn't be blocked by oldKeyDeletionThread during catchup + syncStatusMu deadlock.Mutex lastRoundTimestamp time.Time hasSyncedSinceStartup bool @@ -577,12 +580,13 @@ func (node *AlgorandFullNode) GetPendingTransaction(txID transactions.Txid) (res // Status returns a StatusReport structure reporting our status as Active and with our ledger's LastRound func (node *AlgorandFullNode) Status() (s StatusReport, err error) { - node.mu.Lock() - defer node.mu.Unlock() - + node.syncStatusMu.Lock() s.LastRoundTimestamp = node.lastRoundTimestamp s.HasSyncedSinceStartup = node.hasSyncedSinceStartup + node.syncStatusMu.Unlock() + node.mu.Lock() + defer node.mu.Unlock() if node.catchpointCatchupService != nil { // we're in catchpoint catchup mode. lastBlockHeader := node.catchpointCatchupService.GetLatestBlockHeader() @@ -755,10 +759,13 @@ func (node *AlgorandFullNode) IsArchival() bool { // OnNewBlock implements the BlockListener interface so we're notified after each block is written to the ledger func (node *AlgorandFullNode) OnNewBlock(block bookkeeping.Block, delta ledger.StateDelta) { - node.mu.Lock() + if node.ledger.Latest() > block.Round() { + return + } + node.syncStatusMu.Lock() node.lastRoundTimestamp = time.Now() node.hasSyncedSinceStartup = true - node.mu.Unlock() + node.syncStatusMu.Unlock() // Wake up oldKeyDeletionThread(), non-blocking. select {