ethersphere / bee-backlog

zenhub epics repo
0 stars 0 forks source link

Depth Package - storage incentives #34

Closed istae closed 2 years ago

istae commented 2 years ago

reference https://hackmd.io/yzrmd3GhTDCyDnEkwzrjeg?view

Depth Package (needs a new name)

A new package that monitors the localstore and storage radius from batchstore to control puller syncing changes.

func init() {

    initiliazeDepthFromStatestore()

    waitNodeWarmup()

    if storage_depth == 0, 
        storage_depth = kademlia.connectionDepth()

    go manage()

}

func manage() {
    while {
        if reserve.Size() / reserve.Capacity() < 0.5 {
            storage_depth--
            kademlia.setDepth(storage_depth)
        }
        sleep(5 minutes)
    }
}

// reported by batchstore
func SetStorageRadius(storage_radius) {
    if oldStorageRadius >= storage_depth  && storage_radius < storage_depth {
        storage_depth = storage_radius
        kademlia.setDepth(storage_depth)
    }
    if storage_radius > storage_depth {
        storage_depth = storage_radius
        kademlia.setDepth(storage_depth)
    }
   oldStorageRadius = storage_radius
}

Notes from 23/6

NOTES:

func manage() {

secondsInHour := 60 * 60

adaptationPeriod := false

reserveNotHalfFull := func() bool {
    return reserve.Size() / reserve.Capacity() < 0.5
}

for {
    sleep(5 minutes)

    if reserveNotHalfFull() && !adaptationPeriod {
        adaptationPeriod = true
        timeAtStart := time.Now()
    } 

    if !reserveNotHalfFull() {
        adaptationPeriod = false
    }

    // given the current pull rate (chunks per second), and the time left (1 hour minus the seconds since we started), is the current rate enough to fill half of the reserve on top of what's already there
    if adaptationPeriod && pullsync.Rate() * (secondsInHour - seconds.Since(timeAtStart)) < (reserve.Capacity() / 2 - reserve.Size()) {
        storage_depth--
        kademlia.setDepth(storage_depth)
    }
}

}