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: add allocation check before sending commit message #11841

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
57 changes: 57 additions & 0 deletions storage/pipeline/commit_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/go-state-types/proof"

Expand Down Expand Up @@ -46,6 +47,7 @@ type CommitBatcherApi interface {
StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, types.TipSetKey) (big.Int, error)
StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error)
StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (big.Int, error)
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error)

// Address selector
WalletBalance(context.Context, address.Address) (types.BigInt, error)
Expand Down Expand Up @@ -348,6 +350,11 @@ func (b *CommitBatcher) processBatchV2(cfg sealiface.Config, sectors []abi.Secto
infos := make([]proof.AggregateSealVerifyInfo, 0, total)
collateral := big.Zero()

mid, err := address.IDFromAddress(b.maddr)
if err != nil {
return nil, err
}

for _, sector := range sectors {
if b.todo[sector].DealIDPrecommit {
// can't process sectors precommitted with deal IDs with ProveCommitSectors2
Expand All @@ -364,6 +371,21 @@ func (b *CommitBatcher) processBatchV2(cfg sealiface.Config, sectors []abi.Secto

collateral = big.Add(collateral, sc)

manifest := b.todo[sector].ActivationManifest
precomitInfo, err := b.api.StateSectorPreCommitInfo(b.mctx, b.maddr, sector, ts.Key())
if err != nil {
res.FailedSectors[sector] = err.Error()
continue
}
LexLuthr marked this conversation as resolved.
Show resolved Hide resolved

if len(manifest.Pieces) > 0 {
err = b.allocationCheck(manifest.Pieces, precomitInfo, abi.ActorID(mid), ts)
if err != nil {
res.FailedSectors[sector] = err.Error()
continue
}
}

params.SectorActivations = append(params.SectorActivations, b.todo[sector].ActivationManifest)
params.SectorProofs = append(params.SectorProofs, b.todo[sector].Proof)

Expand Down Expand Up @@ -901,3 +923,38 @@ func (b *CommitBatcher) aggregateProofType(nv network.Version) (abi.RegisteredAg
}
return abi.RegisteredAggregationProof_SnarkPackV2, nil
}

func (b *CommitBatcher) allocationCheck(Pieces []miner.PieceActivationManifest, precomitInfo *miner.SectorPreCommitOnChainInfo, miner abi.ActorID, ts *types.TipSet) error {
for _, p := range Pieces {
p := p
// skip filler pieces
LexLuthr marked this conversation as resolved.
Show resolved Hide resolved
if p.VerifiedAllocationKey == nil {
continue
}
addr, err := address.NewIDAddress(uint64(p.VerifiedAllocationKey.Client))
if err != nil {
return err
}

alloc, err := b.api.StateGetAllocation(b.mctx, addr, verifregtypes.AllocationId(p.VerifiedAllocationKey.ID), ts.Key())
if err != nil {
return err
}
if alloc == nil {
return xerrors.Errorf("no allocation found for piece %s with allocation ID %d", p.CID.String(), p.VerifiedAllocationKey.ID)
}
if alloc.Provider != miner {
return xerrors.Errorf("provider id mismatch for piece %s: expected %d and found %d", p.CID.String(), miner, alloc.Provider)
}
if alloc.Size != p.Size {
return xerrors.Errorf("size mismatch for piece %s: expected %d and found %d", p.CID.String(), p.Size, alloc.Size)
}
if precomitInfo.Info.Expiration < ts.Height()+alloc.TermMin {
return xerrors.Errorf("sector expiration %d is before than allocation TermMin %d for piece %s", precomitInfo.Info.Expiration, ts.Height()+alloc.TermMin, p.CID.String())
}
if precomitInfo.Info.Expiration > ts.Height()+alloc.TermMax {
return xerrors.Errorf("sector expiration %d is later than allocation TermMax %d for piece %s", precomitInfo.Info.Expiration, ts.Height()+alloc.TermMax, p.CID.String())
}
}
return nil
}
16 changes: 16 additions & 0 deletions storage/pipeline/mocks/mock_commit_batcher.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.