Skip to content

Commit

Permalink
Merge branch 'issue62' into issue357_upgrade
Browse files Browse the repository at this point in the history
# Conflicts:
#	baseapp/options.go
#	store/iavlstore.go
#	types/store.go
  • Loading branch information
ackratos committed Feb 27, 2019
2 parents 63b6bf9 + 395855f commit 79e7fa3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 10 additions & 4 deletions store/iavlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ func (st *IavlStore) Commit() CommitID {
}

// Release an old version of history, if not a sync waypoint.
for v, _ := range st.Tree.GetVersions() {
if st.pruningStrategy.Prune(v, version) {
st.Tree.DeleteVersion(v)
}
//for v, _ := range st.tree.GetVersions() {
// if st.pruningStrategy.ShouldPrune(v, version) {
// st.tree.DeleteVersion(v)
// }
//}

// this is a special optimization for binance chain, 10001 should keep consistent with
// `numRecent` field of KeepRecentAndBreatheBlock
if version > 10001 && st.pruningStrategy.ShouldPrune(version-10001, version) {
st.tree.DeleteVersion(version - 10001)
}

return CommitID{
Expand Down
11 changes: 6 additions & 5 deletions types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (

// PruningStrategy specfies how old states will be deleted over time
type PruningStrategy interface {
Prune(version, latestVersion int64) bool
ShouldPrune(version, latestVersion int64) bool
}

// PruneSyncable means only those states not needed for state syncing will be deleted (keeps last 100 + every 10000th)
// PruneSyncable defines the frequency (how many) of states would be saved,
// while all the others are not needed for state syncing and would be deleted.
type PruneSyncable struct {
// How many old versions we hold onto.
// A value of 0 means keep no recent states.
Expand All @@ -31,21 +32,21 @@ type PruneSyncable struct {
StoreEvery int64
}

func (strategy PruneSyncable) Prune(version, latestVersion int64) bool {
func (strategy PruneSyncable) ShouldPrune(version, latestVersion int64) bool {
return (latestVersion-version > strategy.NumRecent) && (version%strategy.StoreEvery != 0)
}

// PruneEverything means all saved states will be deleted, storing only the current state
type PruneEverything struct{}

func (strategy PruneEverything) Prune(version, latestVersion int64) bool {
func (strategy PruneEverything) ShouldPrune(version, latestVersion int64) bool {
return true
}

// PruneNothing means all historic states will be saved, nothing will be deleted
type PruneNothing struct{}

func (strategy PruneNothing) Prune(version, latestVersion int64) bool {
func (strategy PruneNothing) ShouldPrune(version, latestVersion int64) bool {
return false
}

Expand Down

0 comments on commit 79e7fa3

Please sign in to comment.