Merge pull request #9843 from filecoin-project/gstuart/fix-sector-not-found

fix: miner: Check for nil returns from StateSectorGetInfo
This commit is contained in:
Aayush Rajasekaran 2022-12-12 21:24:00 -05:00 committed by GitHub
commit 59431631aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 29 additions and 0 deletions

View File

@ -79,6 +79,7 @@ type State interface {
LockedFunds() (LockedFunds, error)
FeeDebt() (abi.TokenAmount, error)
// Returns nil, nil if sector is not found
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
FindSector(abi.SectorNumber) (*SectorLocation, error)
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)

View File

@ -127,6 +127,7 @@ type State interface {
LockedFunds() (LockedFunds, error)
FeeDebt() (abi.TokenAmount, error)
// Returns nil, nil if sector is not found
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
FindSector(abi.SectorNumber) (*SectorLocation, error)
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)

View File

@ -100,6 +100,7 @@ func (s *state{{.v}}) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state{{.v}}) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state0) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state0) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state10) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state10) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -89,6 +89,7 @@ func (s *state2) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state2) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state3) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state3) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state4) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state4) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state5) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state5) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state6) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state6) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state7) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state7) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state8) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state8) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -90,6 +90,7 @@ func (s *state9) PreCommitDeposits() (abi.TokenAmount, error) {
return s.State.PreCommitDeposits, nil
}
// Returns nil, nil if sector is not found
func (s *state9) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
info, ok, err := s.State.GetSector(s.store, num)
if !ok || err != nil {

View File

@ -103,6 +103,7 @@ func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address,
return mas.GetPrecommittedSector(sid)
}
// Returns nil, nil if sector is not found
func MinerSectorInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (*miner.SectorOnChainInfo, error) {
act, err := sm.LoadActor(ctx, maddr, ts)
if err != nil {

View File

@ -71,6 +71,7 @@ func runTestCCUpgrade(t *testing.T) *kit.TestFullNode {
{
si, err := client.StateSectorGetInfo(ctx, maddr, CCUpgrade, types.EmptyTSK)
require.NoError(t, err)
require.NotNil(t, si)
require.Less(t, 50000, int(si.Expiration))
}
client.WaitForSectorActive(ctx, t, CCUpgrade, maddr)

View File

@ -44,6 +44,7 @@ func TestMakeAvailable(t *testing.T) {
{
si, err := client.StateSectorGetInfo(ctx, maddr, CCUpgrade, types.EmptyTSK)
require.NoError(t, err)
require.NotNil(t, si)
require.Less(t, 50000, int(si.Expiration))
}
client.WaitForSectorActive(ctx, t, CCUpgrade, maddr)

View File

@ -46,6 +46,7 @@ func TestPreferNoUpgrade(t *testing.T) {
{
si, err := client.StateSectorGetInfo(ctx, maddr, CCUpgrade, types.EmptyTSK)
require.NoError(t, err)
require.NotNil(t, si)
require.Less(t, 50000, int(si.Expiration))
}
client.WaitForSectorActive(ctx, t, CCUpgrade, maddr)

View File

@ -42,6 +42,7 @@ func TestAbortUpgradeAvailable(t *testing.T) {
{
si, err := client.StateSectorGetInfo(ctx, maddr, CCUpgrade, types.EmptyTSK)
require.NoError(t, err)
require.NotNil(t, si)
require.Less(t, 50000, int(si.Expiration))
}
client.WaitForSectorActive(ctx, t, CCUpgrade, maddr)

View File

@ -59,6 +59,9 @@ out:
if err != nil {
return xerrors.Errorf("getting sector info: %w", err)
}
if si == nil {
return xerrors.Errorf("sector not found %d", sector)
}
ts, err := m.api.ChainHead(ctx)
if err != nil {

View File

@ -1046,6 +1046,7 @@ func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.A
return pci, err
}
// Returns nil, nil if sector is not found
func (m *StateModule) StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error) {
ts, err := m.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {

View File

@ -143,6 +143,10 @@ func (m *Sealing) handleSubmitReplicaUpdate(ctx statemachine.Context, sector Sec
log.Errorf("handleSubmitReplicaUpdate: api error, not proceeding: %+v", err)
return nil
}
if onChainInfo == nil {
return xerrors.Errorf("sector not found %d", sector.SectorNumber)
}
sp, err := m.currentSealProof(ctx.Context())
if err != nil {
log.Errorf("sealer failed to return current seal proof not proceeding: %+v", err)

View File

@ -33,6 +33,9 @@ func (m *Sealing) MarkForUpgrade(ctx context.Context, id abi.SectorNumber) error
if err != nil {
return xerrors.Errorf("failed to read sector on chain info: %w", err)
}
if onChainInfo == nil {
return xerrors.Errorf("sector not found %d", id)
}
active, err := m.sectorActive(ctx, ts.Key(), id)
if err != nil {