Skip to content

Commit

Permalink
feat: supply: only grab genesis msig locks for writes
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Mar 29, 2023
1 parent 2438141 commit 3120852
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions chain/stmgr/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (sm *StateManager) setupGenesisVestingSchedule(ctx context.Context) error {
return xerrors.Errorf("setting up genesis pledge: %w", err)
}

sm.genesisMsigLk.Lock()
defer sm.genesisMsigLk.Unlock()
sm.genesisPledge = gp

totalsByEpoch := make(map[abi.ChainEpoch]abi.TokenAmount)
Expand Down Expand Up @@ -122,6 +124,8 @@ func (sm *StateManager) setupPostIgnitionVesting(ctx context.Context) error {
totalsByEpoch[sixYears] = big.NewInt(100_000_000)
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000))

sm.genesisMsigLk.Lock()
defer sm.genesisMsigLk.Unlock()
sm.postIgnitionVesting = make([]msig0.State, 0, len(totalsByEpoch))
for k, v := range totalsByEpoch {
ns := msig0.State{
Expand Down Expand Up @@ -172,6 +176,9 @@ func (sm *StateManager) setupPostCalicoVesting(ctx context.Context) error {
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000))
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(9_805_053))

sm.genesisMsigLk.Lock()
defer sm.genesisMsigLk.Unlock()

sm.postCalicoVesting = make([]msig0.State, 0, len(totalsByEpoch))
for k, v := range totalsByEpoch {
ns := msig0.State{
Expand All @@ -192,21 +199,20 @@ func (sm *StateManager) setupPostCalicoVesting(ctx context.Context) error {
func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch) (abi.TokenAmount, error) {
vf := big.Zero()

sm.genesisMsigLk.Lock()
defer sm.genesisMsigLk.Unlock()

// TODO: combine all this?
if sm.preIgnitionVesting == nil || sm.genesisPledge.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)
Expand Down

0 comments on commit 3120852

Please sign in to comment.