Skip to content

Commit 2efb5f7

Browse files
authored
fix: many incorrect pointer equality comparisons (#1018)
* fix: many incorrect pointer equality comparisons
1 parent b01176d commit 2efb5f7

File tree

7 files changed

+121
-114
lines changed

7 files changed

+121
-114
lines changed

tasks/actorstate/miner/context.go

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,48 @@ func NewMinerStateExtractionContext(ctx context.Context, a actorstate.ActorInfo,
2121
return nil, fmt.Errorf("loading current miner state: %w", err)
2222
}
2323

24-
prevTipset := a.Current
25-
prevState := curState
26-
if a.Current.Height() != 1 {
27-
prevTipset = a.Executed
28-
29-
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
30-
if err != nil {
31-
// if the actor exists in the current state and not in the parent state then the
32-
// actor was created in the current state.
33-
if err == types.ErrActorNotFound {
34-
return &MinerStateExtractionContext{
35-
PrevState: prevState,
36-
PrevTs: prevTipset,
37-
CurrActor: &a.Actor,
38-
CurrState: curState,
39-
CurrTs: a.Current,
40-
}, nil
41-
}
42-
return nil, fmt.Errorf("loading previous miner %s at tipset %s epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err)
24+
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
25+
if err != nil {
26+
// actor doesn't exist yet, may have just been created.
27+
if err == types.ErrActorNotFound {
28+
return &MinerStateExtractionContext{
29+
PrevTs: a.Executed,
30+
CurrActor: &a.Actor,
31+
CurrState: curState,
32+
CurrTs: a.Current,
33+
PrevState: nil,
34+
PreviousStatePresent: false,
35+
}, nil
4336
}
37+
return nil, fmt.Errorf("loading previous miner %s at tipset %s epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err)
38+
}
4439

45-
prevState, err = node.MinerLoad(node.Store(), prevActor)
46-
if err != nil {
47-
return nil, fmt.Errorf("loading previous miner actor state: %w", err)
48-
}
40+
// actor exists in previous state, load it.
41+
prevState, err := node.MinerLoad(node.Store(), prevActor)
42+
if err != nil {
43+
return nil, fmt.Errorf("loading previous miner actor state: %w", err)
4944
}
5045

5146
return &MinerStateExtractionContext{
52-
PrevState: prevState,
53-
PrevTs: prevTipset,
54-
CurrActor: &a.Actor,
55-
CurrState: curState,
56-
CurrTs: a.Current,
47+
PrevState: prevState,
48+
PrevTs: a.Executed,
49+
CurrActor: &a.Actor,
50+
CurrState: curState,
51+
CurrTs: a.Current,
52+
PreviousStatePresent: true,
5753
}, nil
5854
}
5955

6056
type MinerStateExtractionContext struct {
6157
PrevState miner.State
6258
PrevTs *types.TipSet
6359

64-
CurrActor *types.Actor
65-
CurrState miner.State
66-
CurrTs *types.TipSet
60+
CurrActor *types.Actor
61+
CurrState miner.State
62+
CurrTs *types.TipSet
63+
PreviousStatePresent bool
6764
}
6865

6966
func (m *MinerStateExtractionContext) HasPreviousState() bool {
70-
return !(m.CurrTs.Height() == 1 || m.PrevState == m.CurrState)
67+
return m.PreviousStatePresent
7168
}

tasks/actorstate/miner/deadline_info.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ func (DeadlineInfoExtractor) Extract(ctx context.Context, a actorstate.ActorInfo
3636
if err != nil {
3737
return nil, err
3838
}
39-
if prevDeadlineInfo == currDeadlineInfo {
39+
// TODO implement equality function
40+
// dereference pointers to check equality
41+
// if these are different then return a model in the bottom of function
42+
if prevDeadlineInfo != nil &&
43+
currDeadlineInfo != nil &&
44+
*prevDeadlineInfo == *currDeadlineInfo {
4045
return nil, nil
4146
}
4247
}
4348

49+
// if there is no previous state and the deadlines have changed, return a model
4450
return &minermodel.MinerCurrentDeadlineInfo{
4551
Height: int64(ec.CurrTs.Height()),
4652
MinerID: a.Address.String(),

tasks/actorstate/miner/fee_debt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (FeeDebtExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, nod
3636
if err != nil {
3737
return nil, fmt.Errorf("loading previous miner fee debt: %w", err)
3838
}
39-
if prevDebt == currDebt {
39+
if prevDebt.Equals(currDebt) {
4040
return nil, nil
4141
}
4242
}

tasks/actorstate/miner/locked_funds.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ func (LockedFundsExtractor) Extract(ctx context.Context, a actorstate.ActorInfo,
3636
if err != nil {
3737
return nil, fmt.Errorf("loading previous miner locked funds: %w", err)
3838
}
39-
if prevLocked == currLocked {
39+
40+
// if all values are equal there is no change.
41+
if prevLocked.VestingFunds.Equals(currLocked.VestingFunds) &&
42+
prevLocked.PreCommitDeposits.Equals(currLocked.PreCommitDeposits) &&
43+
prevLocked.InitialPledgeRequirement.Equals(currLocked.InitialPledgeRequirement) {
4044
return nil, nil
4145
}
4246
}

tasks/actorstate/multisig/multisig.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ type MsigExtractionContext struct {
119119
CurrState multisig.State
120120
CurrTs *types.TipSet
121121

122-
Store adt.Store
122+
Store adt.Store
123+
PreviousStatePresent bool
123124
}
124125

125126
func (m *MsigExtractionContext) HasPreviousState() bool {
126-
return !(m.CurrTs.Height() == 1 || m.CurrState == m.PrevState)
127+
return m.PreviousStatePresent
127128
}
128129

129130
func NewMultiSigExtractionContext(ctx context.Context, a actorstate.ActorInfo, node actorstate.ActorStateAPI) (*MsigExtractionContext, error) {
@@ -132,35 +133,34 @@ func NewMultiSigExtractionContext(ctx context.Context, a actorstate.ActorInfo, n
132133
return nil, fmt.Errorf("loading current multisig state at head %s: %w", a.Actor.Head, err)
133134
}
134135

135-
prevState := curState
136-
if a.Current.Height() != 1 {
137-
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
138-
if err != nil {
139-
// if the actor exists in the current state and not in the parent state then the
140-
// actor was created in the current state.
141-
if err == types.ErrActorNotFound {
142-
return &MsigExtractionContext{
143-
PrevState: prevState,
144-
CurrActor: &a.Actor,
145-
CurrState: curState,
146-
CurrTs: a.Current,
147-
Store: node.Store(),
148-
}, nil
149-
}
150-
return nil, fmt.Errorf("loading previous multisig %s at tipset %s epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err)
136+
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
137+
if err != nil {
138+
// actor doesn't exist yet, may have just been created.
139+
if err == types.ErrActorNotFound {
140+
return &MsigExtractionContext{
141+
CurrActor: &a.Actor,
142+
CurrState: curState,
143+
CurrTs: a.Current,
144+
Store: node.Store(),
145+
PrevState: nil,
146+
PreviousStatePresent: false,
147+
}, nil
151148
}
149+
return nil, fmt.Errorf("loading previous multisig %s from parent tipset %s current epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err)
150+
}
152151

153-
prevState, err = multisig.Load(node.Store(), prevActor)
154-
if err != nil {
155-
return nil, fmt.Errorf("loading previous multisig actor state: %w", err)
156-
}
152+
// actor exists in previous state, load it.
153+
prevState, err := multisig.Load(node.Store(), prevActor)
154+
if err != nil {
155+
return nil, fmt.Errorf("loading previous multisig actor state: %w", err)
157156
}
158157

159158
return &MsigExtractionContext{
160-
PrevState: prevState,
161-
CurrActor: &a.Actor,
162-
CurrState: curState,
163-
CurrTs: a.Current,
164-
Store: node.Store(),
159+
PrevState: prevState,
160+
CurrActor: &a.Actor,
161+
CurrState: curState,
162+
CurrTs: a.Current,
163+
Store: node.Store(),
164+
PreviousStatePresent: true,
165165
}, nil
166166
}

tasks/actorstate/power/power.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,32 @@ func NewPowerStateExtractionContext(ctx context.Context, a actorstate.ActorInfo,
2525
return nil, fmt.Errorf("loading current power state: %w", err)
2626
}
2727

28-
prevState := curState
29-
if a.Current.Height() != 1 {
30-
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
31-
if err != nil {
32-
// if the actor exists in the current state and not in the parent state then the
33-
// actor was created in the current state.
34-
if err == types.ErrActorNotFound {
35-
return &PowerStateExtractionContext{
36-
PrevState: prevState,
37-
CurrState: curState,
38-
CurrTs: a.Current,
39-
Store: node.Store(),
40-
}, nil
41-
}
42-
return nil, fmt.Errorf("loading previous power actor at tipset %s epoch %d: %w", a.Executed.Key(), a.Current.Height(), err)
28+
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
29+
if err != nil {
30+
// actor doesn't exist yet, may have just been created.
31+
if err == types.ErrActorNotFound {
32+
return &PowerStateExtractionContext{
33+
CurrState: curState,
34+
CurrTs: a.Current,
35+
Store: node.Store(),
36+
PrevState: nil,
37+
PreviousStatePresent: false,
38+
}, nil
4339
}
40+
return nil, fmt.Errorf("loading previous power actor from parent tipset %s current epoch %d: %w", a.Executed.Key(), a.Current.Height(), err)
41+
}
4442

45-
prevState, err = power.Load(node.Store(), prevActor)
46-
if err != nil {
47-
return nil, fmt.Errorf("loading previous power actor state: %w", err)
48-
}
43+
// actor exists in previous state, load it.
44+
prevState, err := power.Load(node.Store(), prevActor)
45+
if err != nil {
46+
return nil, fmt.Errorf("loading previous power actor state: %w", err)
4947
}
5048
return &PowerStateExtractionContext{
51-
PrevState: prevState,
52-
CurrState: curState,
53-
CurrTs: a.Current,
54-
Store: node.Store(),
49+
PrevState: prevState,
50+
CurrState: curState,
51+
CurrTs: a.Current,
52+
Store: node.Store(),
53+
PreviousStatePresent: true,
5554
}, nil
5655
}
5756

@@ -60,11 +59,12 @@ type PowerStateExtractionContext struct {
6059
CurrState power.State
6160
CurrTs *types.TipSet
6261

63-
Store adt.Store
62+
Store adt.Store
63+
PreviousStatePresent bool
6464
}
6565

6666
func (p *PowerStateExtractionContext) HasPreviousState() bool {
67-
return !(p.CurrTs.Height() == 1 || p.PrevState == p.CurrState)
67+
return p.PreviousStatePresent
6868
}
6969

7070
func (StoragePowerExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, node actorstate.ActorStateAPI) (model.Persistable, error) {

tasks/actorstate/verifreg/verifreg.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ type VerifiedRegistryExtractionContext struct {
2020
PrevState, CurrState verifreg.State
2121
PrevTs, CurrTs *types.TipSet
2222

23-
Store adt.Store
23+
Store adt.Store
24+
PreviousStatePresent bool
2425
}
2526

2627
func (v *VerifiedRegistryExtractionContext) HasPreviousState() bool {
27-
return !(v.CurrTs.Height() == 1 || v.PrevState == v.CurrState)
28+
return v.PreviousStatePresent
2829
}
2930

3031
func NewVerifiedRegistryExtractorContext(ctx context.Context, a actorstate.ActorInfo, node actorstate.ActorStateAPI) (*VerifiedRegistryExtractionContext, error) {
@@ -33,35 +34,34 @@ func NewVerifiedRegistryExtractorContext(ctx context.Context, a actorstate.Actor
3334
return nil, fmt.Errorf("loading current verified registry state: %w", err)
3435
}
3536

36-
prevState := curState
37-
if a.Current.Height() != 0 {
38-
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
39-
if err != nil {
40-
// if the actor exists in the current state and not in the parent state then the
41-
// actor was created in the current state.
42-
if err == types.ErrActorNotFound {
43-
return &VerifiedRegistryExtractionContext{
44-
PrevState: prevState,
45-
CurrState: curState,
46-
PrevTs: a.Executed,
47-
CurrTs: a.Current,
48-
Store: node.Store(),
49-
}, nil
50-
}
51-
return nil, fmt.Errorf("loading previous verified registry actor at tipset %s epoch %d: %w", a.Executed.Key(), a.Current.Height(), err)
37+
prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key())
38+
if err != nil {
39+
// actor doesn't exist yet, may have just been created.
40+
if err == types.ErrActorNotFound {
41+
return &VerifiedRegistryExtractionContext{
42+
CurrState: curState,
43+
PrevTs: a.Executed,
44+
CurrTs: a.Current,
45+
Store: node.Store(),
46+
PrevState: nil,
47+
PreviousStatePresent: false,
48+
}, nil
5249
}
50+
return nil, fmt.Errorf("loading previous verified registry actor from parent tipset %s current height epoch %d: %w", a.Executed.Key(), a.Current.Height(), err)
51+
}
5352

54-
prevState, err = verifreg.Load(node.Store(), prevActor)
55-
if err != nil {
56-
return nil, fmt.Errorf("loading previous verified registry state: %w", err)
57-
}
53+
// actor exists in previous state, load it.
54+
prevState, err := verifreg.Load(node.Store(), prevActor)
55+
if err != nil {
56+
return nil, fmt.Errorf("loading previous verified registry state: %w", err)
5857
}
5958
return &VerifiedRegistryExtractionContext{
60-
PrevState: prevState,
61-
CurrState: curState,
62-
PrevTs: a.Executed,
63-
CurrTs: a.Current,
64-
Store: node.Store(),
59+
PrevState: prevState,
60+
CurrState: curState,
61+
PrevTs: a.Executed,
62+
CurrTs: a.Current,
63+
Store: node.Store(),
64+
PreviousStatePresent: true,
6565
}, nil
6666
}
6767

0 commit comments

Comments
 (0)