core: added updateMsg to ChainSectionProcessorBackend interface

This commit is contained in:
Zsolt Felfoldi 2017-05-05 21:25:06 +02:00
parent 8bcf1c5ff2
commit 712b17a019

View file

@ -59,6 +59,7 @@ type ChainSectionProcessorBackend interface {
Process(idx uint64) bool Process(idx uint64) bool
GetStored() uint64 GetStored() uint64
SetStored(count uint64) SetStored(count uint64)
UpdateMsg(done, all uint64)
} }
// NewChainSectionProcessor creates a new ChainSectionProcessor // NewChainSectionProcessor creates a new ChainSectionProcessor
@ -80,6 +81,7 @@ func (csp *ChainSectionProcessor) updateLoop() {
tryUpdate := make(chan struct{}, 1) tryUpdate := make(chan struct{}, 1)
updating := false updating := false
var targetCnt uint64 var targetCnt uint64
updateMsg := false
for { for {
select { select {
@ -93,6 +95,10 @@ func (csp *ChainSectionProcessor) updateLoop() {
case <-tryUpdate: case <-tryUpdate:
csp.lock.Lock() csp.lock.Lock()
if targetCnt > csp.stored { if targetCnt > csp.stored {
if !updateMsg && targetCnt > csp.stored+1 {
updateMsg = true
csp.backend.UpdateMsg(csp.stored, targetCnt)
}
csp.calcValid = true csp.calcValid = true
csp.calcIdx = csp.stored csp.calcIdx = csp.stored
@ -103,12 +109,16 @@ func (csp *ChainSectionProcessor) updateLoop() {
if ok && csp.calcValid { if ok && csp.calcValid {
csp.stored = csp.calcIdx + 1 csp.stored = csp.calcIdx + 1
csp.backend.SetStored(csp.stored) csp.backend.SetStored(csp.stored)
if updateMsg {
csp.backend.UpdateMsg(csp.stored, targetCnt)
if csp.stored >= targetCnt {
updateMsg = false
}
}
csp.lastForwarded = csp.stored*csp.sectionSize - 1 csp.lastForwarded = csp.stored*csp.sectionSize - 1
for _, cp := range csp.childProcessors { for _, cp := range csp.childProcessors {
cp.NewHead(csp.lastForwarded, false) cp.NewHead(csp.lastForwarded, false)
} }
} }
csp.calcValid = false csp.calcValid = false
} }