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: sealing: Avoid nil dereference in debug log #9822

Merged
merged 3 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/modules/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"time"

logging "github.com/ipfs/go-log/v2"
"github.com/libp2p/go-libp2p-core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub"
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
"github.com/libp2p/go-libp2p/core/peer"
)

var log = logging.Logger("lotus-tracer")
Expand Down
2 changes: 1 addition & 1 deletion node/modules/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub"
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/require"
)

Expand Down
7 changes: 3 additions & 4 deletions storage/pipeline/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ func (m *Sealing) updateInput(ctx context.Context, sp abi.RegisteredSealProof) e
if err != nil {
return 0, big.Zero(), err
}
if onChainInfo == nil {
return 0, big.Zero(), xerrors.Errorf("sector info for sector %d not found", sn)
}
Comment on lines +452 to +454
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of fixing this here, I think I would rather fix GetSector() in chain/actors/builtin/miner/vX.go (these are generated files). I think we should return an error from GetSector() if we fail to find it, instead of the nil, nil that we're currently returning. It's not idiomatic and is what caused this issue in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is documented behaviour, we want some way there to indicate “sector not found” that works over jsonrpc - Im pręty sure other parts of the codebase depend on this behaviour

Copy link
Contributor

Choose a reason for hiding this comment

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

Did Aayush get the typed json-rpc errors PR done? There are other parts of our code that aren't checking for nil, nil, such as warmpup.go that we should also fix if we're going to keep the behaviour the same. We should also throw comments in a couple more places just to make sure as well.

memo[sn] = struct {
e abi.ChainEpoch
p abi.TokenAmount
Expand Down Expand Up @@ -494,10 +497,6 @@ func (m *Sealing) updateInput(ctx context.Context, sp abi.RegisteredSealProof) e
continue
}
if !ok {
exp, _, _ := getExpirationCached(sector.number)

// todo move this log into checkDealAssignable, make more detailed about the reason
log.Debugf("CC update sector %d cannot fit deal, expiration %d before deal end epoch %d", id, exp, piece.deal.DealProposal.EndEpoch)
continue
}

Expand Down
26 changes: 25 additions & 1 deletion storage/pipeline/sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,21 @@ type openSector struct {
}

func (o *openSector) checkDealAssignable(piece *pendingPiece, expF expFn) (bool, error) {
log := log.With(
"sector", o.number,

"deal", piece.deal.DealID,
"dealEnd", piece.deal.DealProposal.EndEpoch,
"dealStart", piece.deal.DealProposal.StartEpoch,
"dealClaimEnd", piece.claimTerms.claimTermEnd,

"lastAssignedDealEnd", o.lastDealEnd,
"update", o.ccUpdate,
)

// if there are deals assigned, check that no assigned deal expires after termMax
if o.lastDealEnd > piece.claimTerms.claimTermEnd {
log.Debugw("deal not assignable to sector", "reason", "term end beyond last assigned deal end")
return false, nil
}

Expand All @@ -153,15 +166,26 @@ func (o *openSector) checkDealAssignable(piece *pendingPiece, expF expFn) (bool,
}
sectorExpiration, _, err := expF(o.number)
if err != nil {
log.Debugw("deal not assignable to sector", "reason", "error getting sector expiranion", "error", err)
return false, err
}

log = log.With(
"sectorExpiration", sectorExpiration,
)

// check that in case of upgrade sector, it's expiration isn't above deals claim TermMax
if sectorExpiration > piece.claimTerms.claimTermEnd {
log.Debugw("deal not assignable to sector", "reason", "term end beyond sector expiration")
return false, nil
}

if sectorExpiration < piece.deal.DealProposal.EndEpoch {
log.Debugw("deal not assignable to sector", "reason", "sector expiration less than deal expiration")
return false, nil
}

return sectorExpiration >= piece.deal.DealProposal.EndEpoch, nil
return true, nil
}

type pieceAcceptResp struct {
Expand Down