Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add syncMu to AlgorandFullNode OnNewBlock (algorand#1623)
separate synchronization primitive for updating the latest round reached timestamp to improve catchup performance.
  • Loading branch information
nicholasguoalgorand committed Oct 14, 2020
1 parent a156ba9 commit ebc90af
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions node/node.go
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ebc90af

Please sign in to comment.