Skip to content

Commit

Permalink
chore(state): use types.EmptyInt as err return instead of big.Zero()
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Aug 15, 2024
1 parent 697cc69 commit 4357d93
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1439,18 +1439,18 @@ var initialPledgeDen = types.NewInt(100)
func (a *StateAPI) calculateSectorWeight(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, height abi.ChainEpoch, state *state.StateTree) (abi.StoragePower, error) {
ssize, err := pci.SealProof.SectorSize()
if err != nil {
return big.Zero(), xerrors.Errorf("failed to resolve sector size for seal proof: %w", err)
return types.EmptyInt, xerrors.Errorf("failed to resolve sector size for seal proof: %w", err)
}

store := a.Chain.ActorStore(ctx)

var sectorWeight abi.StoragePower
if act, err := state.GetActor(market.Address); err != nil {
return big.Zero(), xerrors.Errorf("loading market actor: %w", err)
return types.EmptyInt, xerrors.Errorf("loading market actor: %w", err)
} else if s, err := market.Load(store, act); err != nil {
return big.Zero(), xerrors.Errorf("loading market actor state: %w", err)
return types.EmptyInt, xerrors.Errorf("loading market actor state: %w", err)
} else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, height, pci.Expiration); err != nil {
return big.Zero(), xerrors.Errorf("verifying deals for activation: %w", err)
return types.EmptyInt, xerrors.Errorf("verifying deals for activation: %w", err)
} else {
// NB: not exactly accurate, but should always lead us to *over* estimate, not under
duration := pci.Expiration - height
Expand All @@ -1468,13 +1468,13 @@ func (a *StateAPI) pledgeCalculationInputs(ctx context.Context, state *state.Sta
pledgeCollateral abi.TokenAmount
)
if act, err := state.GetActor(power.Address); err != nil {
return big.Zero(), nil, xerrors.Errorf("loading power actor: %w", err)
return types.EmptyInt, nil, xerrors.Errorf("loading power actor: %w", err)
} else if s, err := power.Load(store, act); err != nil {
return big.Zero(), nil, xerrors.Errorf("loading power actor state: %w", err)
return types.EmptyInt, nil, xerrors.Errorf("loading power actor state: %w", err)
} else if p, err := s.TotalPowerSmoothed(); err != nil {
return big.Zero(), nil, xerrors.Errorf("failed to determine total power: %w", err)
return types.EmptyInt, nil, xerrors.Errorf("failed to determine total power: %w", err)
} else if c, err := s.TotalLocked(); err != nil {
return big.Zero(), nil, xerrors.Errorf("failed to determine pledge collateral: %w", err)
return types.EmptyInt, nil, xerrors.Errorf("failed to determine pledge collateral: %w", err)
} else {
powerSmoothed = p
pledgeCollateral = c
Expand Down Expand Up @@ -1506,17 +1506,17 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr

sectorWeight, err := a.calculateSectorWeight(ctx, maddr, pci, ts.Height(), state)
if err != nil {
return big.Zero(), err
return types.EmptyInt, err
}

_, powerSmoothed, err := a.pledgeCalculationInputs(ctx, state)
if err != nil {
return big.Zero(), err
return types.EmptyInt, err
}

deposit, err := rewardState.PreCommitDepositForPower(*powerSmoothed, sectorWeight)
if err != nil {
return big.Zero(), xerrors.Errorf("calculating precommit deposit: %w", err)
return types.EmptyInt, xerrors.Errorf("calculating precommit deposit: %w", err)
}

return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil
Expand Down Expand Up @@ -1545,17 +1545,17 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr

sectorWeight, err := a.calculateSectorWeight(ctx, maddr, pci, ts.Height(), state)
if err != nil {
return big.Zero(), err
return types.EmptyInt, err
}

pledgeCollateral, powerSmoothed, err := a.pledgeCalculationInputs(ctx, state)
if err != nil {
return big.Zero(), err
return types.EmptyInt, err
}

circSupply, err := a.StateVMCirculatingSupplyInternal(ctx, ts.Key())
if err != nil {
return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err)
return types.EmptyInt, xerrors.Errorf("getting circulating supply: %w", err)
}

initialPledge, err := rewardState.InitialPledgeForPower(
Expand All @@ -1565,7 +1565,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
circSupply.FilCirculating,
)
if err != nil {
return big.Zero(), xerrors.Errorf("calculating initial pledge: %w", err)
return types.EmptyInt, xerrors.Errorf("calculating initial pledge: %w", err)
}

return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil
Expand Down Expand Up @@ -1604,12 +1604,12 @@ func (a *StateAPI) StateMinerInitialPledgeForSector(ctx context.Context, sectorD

circSupply, err := a.StateVMCirculatingSupplyInternal(ctx, ts.Key())
if err != nil {
return big.Zero(), xerrors.Errorf("getting circulating supply: %w", err)
return types.EmptyInt, xerrors.Errorf("getting circulating supply: %w", err)
}

pledgeCollateral, powerSmoothed, err := a.pledgeCalculationInputs(ctx, state)
if err != nil {
return big.Zero(), err
return types.EmptyInt, err
}

verifiedWeight := big.Mul(big.NewIntUnsigned(verifiedSize), big.NewInt(int64(sectorDuration)))
Expand All @@ -1622,7 +1622,7 @@ func (a *StateAPI) StateMinerInitialPledgeForSector(ctx context.Context, sectorD
circSupply.FilCirculating,
)
if err != nil {
return big.Zero(), xerrors.Errorf("calculating initial pledge: %w", err)
return types.EmptyInt, xerrors.Errorf("calculating initial pledge: %w", err)
}

return types.BigDiv(types.BigMul(initialPledge, initialPledgeNum), initialPledgeDen), nil
Expand Down

0 comments on commit 4357d93

Please sign in to comment.