Skip to content

Commit

Permalink
snap: Obey collateral-from-miner config (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored Aug 26, 2024
1 parent 6b0f5d1 commit d7fa878
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tasks/snap/task_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type SubmitTaskNodeAPI interface {
StateSectorGetInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error)

StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error)
StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (big.Int, error)
StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error)
StateVMCirculatingSupplyInternal(ctx context.Context, tsk types.TipSetKey) (api.CirculatingSupply, error)
}
Expand All @@ -65,6 +66,8 @@ type submitConfig struct {
maxFee types.FIL
RequireActivationSuccess bool
RequireNotificationSuccess bool
CollateralFromMinerBalance bool
DisableCollateralFallback bool
}

type SubmitTask struct {
Expand Down Expand Up @@ -92,6 +95,9 @@ func NewSubmitTask(db *harmonydb.DB, api SubmitTaskNodeAPI, bstore curiochain.Cu
maxFee: cfg.Fees.MaxCommitGasFee, // todo snap-specific
RequireActivationSuccess: cfg.Subsystems.RequireActivationSuccess,
RequireNotificationSuccess: cfg.Subsystems.RequireNotificationSuccess,

CollateralFromMinerBalance: cfg.Fees.CollateralFromMinerBalance,
DisableCollateralFallback: cfg.Fees.DisableCollateralFallback,
},
}
}
Expand Down Expand Up @@ -255,6 +261,22 @@ func (s *SubmitTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done
collateral = big.Zero()
}

if s.cfg.CollateralFromMinerBalance {
if s.cfg.DisableCollateralFallback {
collateral = big.Zero()
}
balance, err := s.api.StateMinerAvailableBalance(ctx, maddr, types.EmptyTSK)
if err != nil {
if err != nil {
return false, xerrors.Errorf("getting miner balance: %w", err)
}
}
collateral = big.Sub(collateral, balance)
if collateral.LessThan(big.Zero()) {
collateral = big.Zero()
}
}

a, _, err := s.as.AddressFor(ctx, s.api, maddr, mi, api.CommitAddr, collateral, big.Zero())
if err != nil {
return false, xerrors.Errorf("getting address for precommit: %w", err)
Expand Down

0 comments on commit d7fa878

Please sign in to comment.