Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: many incorrect pointer equality comparisons #1018

Merged
merged 2 commits into from
Jul 5, 2022

Conversation

frrist
Copy link
Member

@frrist frrist commented Jul 5, 2022

This PR fixes a bug which was causing lily to export redundant data from models which had not actually changed state. The impact is limited to the same state being persisted over and over on multiple subsequent epochs.

The following models are impacted:

  • miner_*
  • multisig_*
  • power_actor_claims
  • verified_registry_*

fixes #1017

  • the hardest of facepalms

@frrist frrist requested review from hsanjuan, kasteph and placer14 July 5, 2022 21:24
@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2022

Codecov Report

Merging #1018 (dbfc140) into frrist/update-lotusv1.16.0-rc (b01176d) will decrease coverage by 0.0%.
The diff coverage is 0.0%.

@@                       Coverage Diff                       @@
##           frrist/update-lotusv1.16.0-rc   #1018     +/-   ##
===============================================================
- Coverage                           35.6%   35.6%   -0.1%     
===============================================================
  Files                                 44      44             
  Lines                               2877    2879      +2     
===============================================================
  Hits                                1025    1025             
- Misses                              1748    1750      +2     
  Partials                             104     104             

Copy link
Contributor

@placer14 placer14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits for safety and clarity. Otherwise, LGTM

CurrActor *types.Actor
CurrState miner.State
CurrTs *types.TipSet
PreviousState bool
Copy link
Contributor

@placer14 placer14 Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: A slightly more expressive name:

Suggested change
PreviousState bool
HasPreviousState bool

if prevDeadlineInfo == currDeadlineInfo {
// TODO implement equality function
// dereference pointers to check equality
if *prevDeadlineInfo == *currDeadlineInfo {
Copy link
Contributor

@placer14 placer14 Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is brittle. We have to be sure that err == nil guarantees we're protected from a nil-deref panic here and forever into the future. How is that being guaranteed? I would prefer this check is explicit here instead of expecting it inside the called method. If we have a local equality function doing that, that could work just a well.

if prevDeadlineInfo == currDeadlineInfo {
// TODO implement equality function
// dereference pointers to check equality
if *prevDeadlineInfo == *currDeadlineInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is brittle. We have to be sure that err == nil guarantees we're protected from a nil-deref panic here and forever into the future. How is that being guaranteed? I would prefer this check is explicit here instead of expecting it inside the caller. If we have a local equality function doing that, that could work just a well.

Suggested change
if *prevDeadlineInfo == *currDeadlineInfo {
if prevDeadlineInfo != nil &&
currDeadlineInfo != nil &&
*prevDeadlineInfo == *currDeadlineInfo {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we know the miner has state we can safely assume it has non-nil deadline information. (the method that creates deadline info will never return null: https://github.com/filecoin-project/specs-actors/blob/v8.0.1/actors/builtin/miner/deadlines.go#L15

// if all values are equal there is no change.
if prevLocked.VestingFunds.Equals(currLocked.VestingFunds) &&
prevLocked.PreCommitDeposits.Equals(currLocked.PreCommitDeposits) &&
prevLocked.InitialPledgeRequirement.Equals(currLocked.InitialPledgeRequirement) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protect against nil-deref panic here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the LockedFunds type isn't a pointer, nor are its fields so we can safely use them here.

@@ -119,11 +119,12 @@ type MsigExtractionContext struct {
CurrState multisig.State
CurrTs *types.TipSet

Store adt.Store
Store adt.Store
PreviousState bool
Copy link
Contributor

@placer14 placer14 Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
PreviousState bool
HasPreviousState bool

@@ -20,11 +20,12 @@ type VerifiedRegistryExtractionContext struct {
PrevState, CurrState verifreg.State
PrevTs, CurrTs *types.TipSet

Store adt.Store
Store adt.Store
PreviousState bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
PreviousState bool
HasPreviousState bool

@frrist frrist merged commit 2efb5f7 into frrist/update-lotusv1.16.0-rc Jul 5, 2022
@frrist frrist deleted the frrist/bug-stomp branch July 5, 2022 22:38
frrist added a commit that referenced this pull request Jul 5, 2022
* deps: update to lotus v0.16.0

* refactor: remove unused actor gen code

* chore: update actor code generator for v8

* gen: init actor accessors

* gen: market actor accessors

* gen: multisig actor accessors

* gen: power actor accessors

* gen: reward actor accessors

* gen verifreg actor accessors

* gen: miner actor accessors

* chore: update miner state extractors

- required due to changes in miner actor gen accessors

* chore: update market actor extractors

- required for market actor gen accessors

* gen: builtin accessors

* refactor: remove unused map opts lookup

- actor accessors now return map opt values

* chore: update message test deps

- use v8 actor structs

* feat: add actor CID lookups

- replace with filecoin-project/lotus#8941 when lotus v1.17.0 is cut

* chore: update lens interface to match lotus api

- required due to lotus update v1.16.0

* refactor: register new actor code in processor

* fix: update parsed message extractor with new exitcode

* fix: only init VM for network version prior to 13

- ensures we can process message on FVM upgrade boundary

* Add is_string column to market_deal_proposal model (#1015)

* chore: add is_string column to market_deal_proposal model

* fix: many incorrect pointer equality comparisons (#1018)

* fix: many incorrect pointer equality comparisons
@frrist frrist mentioned this pull request Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants