forked from onflow/flow-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.go
51 lines (39 loc) · 1.19 KB
/
cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package consensus
import (
"fmt"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/mempool"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/storage"
)
// CleanupFunc is called after a block was finalized to allow other components
// to execute cleanup operations.
type CleanupFunc func(blockID flow.Identifier) error
func CleanupNothing() CleanupFunc {
return func(flow.Identifier) error {
return nil
}
}
func CleanupMempools(
collector module.MempoolMetrics,
spans module.ConsensusMetrics,
payloads storage.Payloads,
guarantees mempool.Guarantees,
seals mempool.IncorporatedResultSeals) CleanupFunc {
return func(blockID flow.Identifier) error {
payload, err := payloads.ByBlockID(blockID)
if err != nil {
return fmt.Errorf("could not retrieve payload (%x): %w", blockID, err)
}
for _, guarantee := range payload.Guarantees {
_ = guarantees.Remove(guarantee.ID())
}
collector.MempoolEntries(metrics.ResourceGuarantee, guarantees.Size())
for _, seal := range payload.Seals {
_ = seals.Remove(seal.ID())
}
collector.MempoolEntries(metrics.ResourceSeal, seals.Size())
return nil
}
}