chore: cleanup fil vested calculation
1. Move lock, loading, etc into GetFilVested. 2. Call it directly when creating the FVM. 3. Detach GetFilLocked from state manager. Really, this just makes it a bit easier to reason about this code.
This commit is contained in:
parent
e8d771fcac
commit
e8bdf8171b
@ -94,11 +94,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.VMI, error) {
|
makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.VMI, error) {
|
||||||
st, err := sm.StateTree(base)
|
filVested, err := sm.GetFilVested(ctx, e)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
supply, err := sm.GetVMCirculatingSupplyDetailed(ctx, e, st)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -111,7 +107,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager
|
|||||||
Actors: NewActorRegistry(),
|
Actors: NewActorRegistry(),
|
||||||
Syscalls: sm.Syscalls,
|
Syscalls: sm.Syscalls,
|
||||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||||
FilVested: supply.FilVested,
|
FilVested: filVested,
|
||||||
NetworkVersion: sm.GetNetworkVersion(ctx, e),
|
NetworkVersion: sm.GetNetworkVersion(ctx, e),
|
||||||
BaseFee: baseFee,
|
BaseFee: baseFee,
|
||||||
LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts),
|
LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts),
|
||||||
|
@ -196,8 +196,32 @@ func (sm *StateManager) setupPostCalicoVesting(ctx context.Context) error {
|
|||||||
// GetVestedFunds returns all funds that have "left" actors that are in the genesis state:
|
// GetVestedFunds returns all funds that have "left" actors that are in the genesis state:
|
||||||
// - For Multisigs, it counts the actual amounts that have vested at the given epoch
|
// - For Multisigs, it counts the actual amounts that have vested at the given epoch
|
||||||
// - For Accounts, it counts max(currentBalance - genesisBalance, 0).
|
// - For Accounts, it counts max(currentBalance - genesisBalance, 0).
|
||||||
func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (abi.TokenAmount, error) {
|
func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||||
vf := big.Zero()
|
vf := big.Zero()
|
||||||
|
|
||||||
|
sm.genesisMsigLk.Lock()
|
||||||
|
defer sm.genesisMsigLk.Unlock()
|
||||||
|
|
||||||
|
// TODO: combine all this?
|
||||||
|
if sm.preIgnitionVesting == nil || sm.genesisPledge.IsZero() || sm.genesisMarketFunds.IsZero() {
|
||||||
|
err := sm.setupGenesisVestingSchedule(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return vf, xerrors.Errorf("failed to setup pre-ignition vesting schedule: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sm.postIgnitionVesting == nil {
|
||||||
|
err := sm.setupPostIgnitionVesting(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return vf, xerrors.Errorf("failed to setup post-ignition vesting schedule: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sm.postCalicoVesting == nil {
|
||||||
|
err := sm.setupPostCalicoVesting(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return vf, xerrors.Errorf("failed to setup post-calico vesting schedule: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if height <= build.UpgradeIgnitionHeight {
|
if height <= build.UpgradeIgnitionHeight {
|
||||||
for _, v := range sm.preIgnitionVesting {
|
for _, v := range sm.preIgnitionVesting {
|
||||||
au := big.Sub(v.InitialBalance, v.AmountLocked(height))
|
au := big.Sub(v.InitialBalance, v.AmountLocked(height))
|
||||||
@ -282,7 +306,7 @@ func getFilPowerLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmoun
|
|||||||
return pst.TotalLocked()
|
return pst.TotalLocked()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) GetFilLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) {
|
func GetFilLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) {
|
||||||
|
|
||||||
filMarketLocked, err := getFilMarketLocked(ctx, st)
|
filMarketLocked, err := getFilMarketLocked(ctx, st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -315,29 +339,12 @@ func (sm *StateManager) GetVMCirculatingSupply(ctx context.Context, height abi.C
|
|||||||
return cs.FilCirculating, err
|
return cs.FilCirculating, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) GetVMCirculatingSupplyDetailed(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (api.CirculatingSupply, error) {
|
func (sm *StateManager) loadGenesisMsigs(ctx context.Context) error {
|
||||||
sm.genesisMsigLk.Lock()
|
return nil
|
||||||
defer sm.genesisMsigLk.Unlock()
|
}
|
||||||
if sm.preIgnitionVesting == nil || sm.genesisPledge.IsZero() || sm.genesisMarketFunds.IsZero() {
|
|
||||||
err := sm.setupGenesisVestingSchedule(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return api.CirculatingSupply{}, xerrors.Errorf("failed to setup pre-ignition vesting schedule: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if sm.postIgnitionVesting == nil {
|
|
||||||
err := sm.setupPostIgnitionVesting(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return api.CirculatingSupply{}, xerrors.Errorf("failed to setup post-ignition vesting schedule: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if sm.postCalicoVesting == nil {
|
|
||||||
err := sm.setupPostCalicoVesting(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return api.CirculatingSupply{}, xerrors.Errorf("failed to setup post-calico vesting schedule: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
filVested, err := sm.GetFilVested(ctx, height, st)
|
func (sm *StateManager) GetVMCirculatingSupplyDetailed(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (api.CirculatingSupply, error) {
|
||||||
|
filVested, err := sm.GetFilVested(ctx, height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filVested: %w", err)
|
return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filVested: %w", err)
|
||||||
}
|
}
|
||||||
@ -360,7 +367,7 @@ func (sm *StateManager) GetVMCirculatingSupplyDetailed(ctx context.Context, heig
|
|||||||
return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filBurnt: %w", err)
|
return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filBurnt: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filLocked, err := sm.GetFilLocked(ctx, st)
|
filLocked, err := GetFilLocked(ctx, st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filLocked: %w", err)
|
return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filLocked: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user