Skip to content

Commit 5b7c90b

Browse files
authored
Merge pull request #268 from CortexFoundation/dev
torrentfs/monitor | sync delay 12 blocks for security, reduce sync sa…
2 parents 6620899 + c5dc09d commit 5b7c90b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

torrentfs/monitor.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func NewMonitor(flag *Config) (m *Monitor, e error) {
125125
dirty: false,
126126
taskCh: make(chan *Block, batch),
127127
}
128-
m.blockCache, _ = lru.New(6)
128+
m.blockCache, _ = lru.New(delay)
129129
m.healthPeers, _ = lru.New(50)
130130
m.sizeCache, _ = lru.New(batch)
131131
e = nil
@@ -848,7 +848,7 @@ func (m *Monitor) listenLatestBlock() {
848848
case <-timer.C:
849849
progress = m.syncLastBlock()
850850
// Aviod sync in full mode, fresh interval may be less.
851-
if progress > batch {
851+
if progress >= batch {
852852
timer.Reset(time.Millisecond * 100)
853853
} else if progress > 6 {
854854
timer.Reset(time.Millisecond * 1000)
@@ -954,6 +954,7 @@ func (m *Monitor) batch_http_healthy(ip string, ports []string) ([]string, bool)
954954

955955
const (
956956
batch = 2048
957+
delay = 12
957958
)
958959

959960
func (m *Monitor) syncLastBlock() uint64 {
@@ -975,8 +976,8 @@ func (m *Monitor) syncLastBlock() uint64 {
975976

976977
minNumber := m.lastNumber + 1
977978
maxNumber := uint64(0)
978-
if uint64(currentNumber) > 3 {
979-
maxNumber = uint64(currentNumber)
979+
if uint64(currentNumber) > delay {
980+
maxNumber = uint64(currentNumber) - delay
980981
}
981982

982983
if m.lastNumber > uint64(currentNumber) {
@@ -989,9 +990,9 @@ func (m *Monitor) syncLastBlock() uint64 {
989990
maxNumber = minNumber + batch
990991
}
991992
if maxNumber >= minNumber {
992-
if minNumber > 5 {
993-
minNumber = minNumber - 5
994-
}
993+
/*if minNumber > delay {
994+
minNumber = minNumber - delay
995+
}*/
995996
log.Debug("Torrent scanning ... ...", "from", minNumber, "to", maxNumber, "current", uint64(currentNumber), "range", uint64(maxNumber-minNumber), "behind", uint64(currentNumber)-maxNumber, "progress", float64(maxNumber)/float64(currentNumber))
996997
} else {
997998
return 0

0 commit comments

Comments
 (0)