Skip to content

Commit f8a98b0

Browse files
committed
go/worker/compute/executor: Simplify prune handler
Removes dependency on common node's current block height.
1 parent 3547120 commit f8a98b0

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

.changelog/6384.trivial.md

Whitespace-only changes.

go/worker/compute/executor/committee/node.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,9 +1568,6 @@ func NewNode(
15681568
logger: logging.GetLogger("worker/executor/committee").With("runtime_id", commonNode.Runtime.ID()),
15691569
}
15701570

1571-
// Register prune handler.
1572-
commonNode.Runtime.History().Pruner().RegisterHandler(&pruneHandler{commonNode: commonNode})
1573-
15741571
// Register committee message handler.
15751572
commonNode.P2P.RegisterHandler(committeeTopic, &committeeMsgHandler{n})
15761573

go/worker/compute/executor/committee/prune.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

go/worker/compute/executor/worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ func (w *Worker) registerRuntime(commonNode *committeeCommon.Node) error {
155155
return err
156156
}
157157

158+
// Register prune handler.
159+
pruner := committee.NewPruneHandler(commonNode.Runtime.ID(), commonNode.Consensus)
160+
commonNode.Runtime.History().Pruner().RegisterHandler(pruner)
161+
158162
commonNode.AddHooks(node)
159163
w.runtimes[id] = node
160164

0 commit comments

Comments
 (0)