@@ -4,29 +4,36 @@ import (
44 "context"
55 "fmt"
66
7+ "github.com/oasisprotocol/oasis-core/go/common"
8+ consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
79 roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
8- "github.com/oasisprotocol/oasis-core/go/worker/common/committee"
910)
1011
11- // pruneHandler is a prune handler that prevents pruning of the last normal round.
12- type pruneHandler struct {
13- commonNode * committee.Node
12+ // PruneHandler is a prune handler that prevents pruning of the last normal round.
13+ type PruneHandler struct {
14+ runtimeID common.Namespace
15+ consensus consensus.Service
1416}
1517
16- func (p * pruneHandler ) Prune (rounds []uint64 ) error {
17- p .commonNode .CrossNode .Lock ()
18- height := p .commonNode .CurrentBlockHeight
19- p .commonNode .CrossNode .Unlock ()
18+ // NewPruneHandler creates a new prune handler.
19+ func NewPruneHandler (runtimeID common.Namespace , consensus consensus.Service ) * PruneHandler {
20+ return & PruneHandler {
21+ runtimeID : runtimeID ,
22+ consensus : consensus ,
23+ }
24+ }
2025
26+ // Prune verifies that no rounds beyond the last normal round are pruned.
27+ func (p * PruneHandler ) Prune (rounds []uint64 ) error {
2128 // Make sure we never prune past the last normal round, as some runtimes will do historic queries
2229 // for things that are not available in the last consensus state (e.g. delegation/undelegation
2330 // events that happened while the runtime was suspended or not producing blocks).
24- state , err := p .commonNode . Consensus . RootHash ().GetRuntimeState (context .Background (), & roothash.RuntimeRequest {
25- RuntimeID : p .commonNode . Runtime . ID () ,
26- Height : height ,
31+ state , err := p .consensus . RootHash ().GetRuntimeState (context .TODO (), & roothash.RuntimeRequest {
32+ RuntimeID : p .runtimeID ,
33+ Height : consensus . HeightLatest ,
2734 })
2835 if err != nil {
29- return fmt .Errorf ("worker/executor: failed to fetch runtime state at %d : %w" , height , err )
36+ return fmt .Errorf ("worker/executor: failed to fetch runtime state: %w" , err )
3037 }
3138
3239 for _ , round := range rounds {
0 commit comments