diff --git a/interfaces/params/network.go b/interfaces/params/network.go index d3ee2fd39f4dd528bcb62a972c135c9725eb9768..4860eaefb91b1261a88f6222ce369c8127ab7093 100644 --- a/interfaces/params/network.go +++ b/interfaces/params/network.go @@ -31,6 +31,9 @@ type Network struct { FastPolling bool // Messages will not be sent to Rounds containing these Nodes BlacklistedNodes []string + // Determines if the state of every round processed is tracked in ram. + // This is very memory intensive and is primarily used for debugging + VerboseRoundTracking bool Rounds Messages @@ -50,6 +53,7 @@ func GetDefaultNetwork() Network { KnownRoundsThreshold: 1500, //5 rounds/sec * 60 sec/min * 5 min FastPolling: true, BlacklistedNodes: make([]string, 0), + VerboseRoundTracking: false, } n.Rounds = GetDefaultRounds() n.Messages = GetDefaultMessage() diff --git a/storage/rounds/unknownRounds.go b/storage/rounds/unknownRounds.go index 6fe15191e9eb3cbf535314092046b85f4de7fc86..98e863d2b911c5ad7cd7cd9d1eed68ba9e4edc2b 100644 --- a/storage/rounds/unknownRounds.go +++ b/storage/rounds/unknownRounds.go @@ -113,8 +113,9 @@ func LoadUnknownRounds(kv *versioned.KV, // in params, it removes from the map // Afterwards it adds the roundToAdd to the map if an entry isn't present // Finally it saves the modified map to disk. +// The abandon function can be used to pass the abandoned round somewhere else func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool, - roundsToAdd []id.Round) []id.Round { + roundsToAdd []id.Round, abandon func(round id.Round)) []id.Round { returnSlice := make([]id.Round, 0) urs.mux.Lock() defer urs.mux.Unlock() @@ -132,6 +133,8 @@ func (urs *UnknownRounds) Iterate(checker func(rid id.Round) bool, // If the round has been checked the maximum amount, // the rond is removed from the map if totalChecks > urs.params.MaxChecks { + localRnd := rnd + go abandon(localRnd) delete(urs.rounds, rnd) } } diff --git a/storage/rounds/unknownRounds_test.go b/storage/rounds/unknownRounds_test.go index f437e0839f7d37208f2d7b5c826e6a6cfeb7d5b2..7611579bf84dc6cb1e23c67f8b0c7e68ea765c2e 100644 --- a/storage/rounds/unknownRounds_test.go +++ b/storage/rounds/unknownRounds_test.go @@ -86,7 +86,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { } // Iterate over initial map - received := store.Iterate(mockChecker, nil) + received := store.Iterate(mockChecker, nil, func(round id.Round) { return }) // Check the received list for 2 conditions: // a) that returned rounds are no longer in the map @@ -106,7 +106,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { } // Add even round list to map - received = store.Iterate(mockChecker, roundListEven) + received = store.Iterate(mockChecker, roundListEven, func(round id.Round) { return }) if len(received) != 0 { t.Errorf("Second iteration should return an empty list (no even rounds are left)."+ @@ -116,7 +116,7 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { // Iterate over map until all rounds have checks incremented over // maxCheck for i := 0; i < defaultMaxCheck+1; i++ { - _ = store.Iterate(mockChecker, []id.Round{}) + _ = store.Iterate(mockChecker, []id.Round{}, func(round id.Round) { return }) } @@ -172,7 +172,7 @@ func TestLoadUnknownRoundsStore(t *testing.T) { // Check that LoadStore works after iterate call (which implicitly saves) mockChecker := func(round id.Round) bool { return false } - received := store.Iterate(mockChecker, nil) + received := store.Iterate(mockChecker, nil, func(round id.Round) { return }) // Iterate is being called as a dummy, should not return anything if len(received) != 0 {