-
Notifications
You must be signed in to change notification settings - Fork 44
/
context.go
68 lines (56 loc) · 1.94 KB
/
context.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package miner
import (
"context"
"fmt"
"go.opentelemetry.io/otel"
miner "github.com/filecoin-project/lily/chain/actors/builtin/miner"
"github.com/filecoin-project/lily/tasks/actorstate"
"github.com/filecoin-project/lotus/chain/types"
)
func NewMinerStateExtractionContext(ctx context.Context, a actorstate.ActorInfo, node actorstate.ActorStateAPI) (*MinerStateExtractionContext, error) {
ctx, span := otel.Tracer("").Start(ctx, "NewMinerExtractionContext")
defer span.End()
curState, err := node.MinerLoad(node.Store(), &a.Actor)
if err != nil {
return nil, fmt.Errorf("loading current miner state: %w", err)
}
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
if err != nil {
// actor doesn't exist yet, may have just been created.
if err == types.ErrActorNotFound {
return &MinerStateExtractionContext{
PrevTs: a.Executed,
CurrActor: &a.Actor,
CurrState: curState,
CurrTs: a.Current,
PrevState: nil,
PreviousStatePresent: false,
}, nil
}
return nil, fmt.Errorf("loading previous miner %s at tipset %s epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err)
}
// actor exists in previous state, load it.
prevState, err := node.MinerLoad(node.Store(), prevActor)
if err != nil {
return nil, fmt.Errorf("loading previous miner actor state: %w", err)
}
return &MinerStateExtractionContext{
PrevState: prevState,
PrevTs: a.Executed,
CurrActor: &a.Actor,
CurrState: curState,
CurrTs: a.Current,
PreviousStatePresent: true,
}, nil
}
type MinerStateExtractionContext struct {
PrevState miner.State
PrevTs *types.TipSet
CurrActor *types.Actor
CurrState miner.State
CurrTs *types.TipSet
PreviousStatePresent bool
}
func (m *MinerStateExtractionContext) HasPreviousState() bool {
return m.PreviousStatePresent
}