Fix inSync state
This commit is contained in:
parent
5a6e672fca
commit
927fd0aaea
@ -45,12 +45,14 @@ type InternalState struct {
|
|||||||
// IS is a singleton holding internal state of the application
|
// IS is a singleton holding internal state of the application
|
||||||
var IS *InternalState
|
var IS *InternalState
|
||||||
|
|
||||||
|
// StartedSync signals start of synchronization
|
||||||
func (is *InternalState) StartedSync() {
|
func (is *InternalState) StartedSync() {
|
||||||
is.mux.Lock()
|
is.mux.Lock()
|
||||||
defer is.mux.Unlock()
|
defer is.mux.Unlock()
|
||||||
is.IsSynchronized = false
|
is.IsSynchronized = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FinishedSync marks end of synchronization, bestHeight specifies new best block height
|
||||||
func (is *InternalState) FinishedSync(bestHeight uint32) {
|
func (is *InternalState) FinishedSync(bestHeight uint32) {
|
||||||
is.mux.Lock()
|
is.mux.Lock()
|
||||||
defer is.mux.Unlock()
|
defer is.mux.Unlock()
|
||||||
@ -59,18 +61,28 @@ func (is *InternalState) FinishedSync(bestHeight uint32) {
|
|||||||
is.LastSync = time.Now()
|
is.LastSync = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FinishedSyncNoChange marks end of synchronization in case no index update was necessary, it does not update lastSync time
|
||||||
|
func (is *InternalState) FinishedSyncNoChange() {
|
||||||
|
is.mux.Lock()
|
||||||
|
defer is.mux.Unlock()
|
||||||
|
is.IsSynchronized = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSyncState gets the state of synchronization
|
||||||
func (is *InternalState) GetSyncState() (bool, uint32, time.Time) {
|
func (is *InternalState) GetSyncState() (bool, uint32, time.Time) {
|
||||||
is.mux.Lock()
|
is.mux.Lock()
|
||||||
defer is.mux.Unlock()
|
defer is.mux.Unlock()
|
||||||
return is.IsSynchronized, is.BestHeight, is.LastSync
|
return is.IsSynchronized, is.BestHeight, is.LastSync
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartedMempoolSync signals start of mempool synchronization
|
||||||
func (is *InternalState) StartedMempoolSync() {
|
func (is *InternalState) StartedMempoolSync() {
|
||||||
is.mux.Lock()
|
is.mux.Lock()
|
||||||
defer is.mux.Unlock()
|
defer is.mux.Unlock()
|
||||||
is.IsMempoolSynchronized = false
|
is.IsMempoolSynchronized = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FinishedMempoolSync marks end of mempool synchronization
|
||||||
func (is *InternalState) FinishedMempoolSync() {
|
func (is *InternalState) FinishedMempoolSync() {
|
||||||
is.mux.Lock()
|
is.mux.Lock()
|
||||||
defer is.mux.Unlock()
|
defer is.mux.Unlock()
|
||||||
@ -78,6 +90,7 @@ func (is *InternalState) FinishedMempoolSync() {
|
|||||||
is.LastMempoolSync = time.Now()
|
is.LastMempoolSync = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMempoolSyncState gets the state of mempool synchronization
|
||||||
func (is *InternalState) GetMempoolSyncState() (bool, time.Time) {
|
func (is *InternalState) GetMempoolSyncState() (bool, time.Time) {
|
||||||
is.mux.Lock()
|
is.mux.Lock()
|
||||||
defer is.mux.Unlock()
|
defer is.mux.Unlock()
|
||||||
|
|||||||
@ -61,9 +61,10 @@ func (w *SyncWorker) ResyncIndex(onNewBlock func(hash string)) error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
common.IS.FinishedSync(bh)
|
common.IS.FinishedSync(bh)
|
||||||
}
|
}
|
||||||
fallthrough
|
return nil
|
||||||
case errSynced:
|
case errSynced:
|
||||||
// this is not actually error but flag that resync wasn't necessary
|
// this is not actually error but flag that resync wasn't necessary
|
||||||
|
common.IS.FinishedSyncNoChange()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user