From 890f56ac38f374a33e2405437ad90dad326d494b Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 28 Jul 2020 17:36:59 -0400 Subject: [PATCH] Lock before setting up genesis msigs --- build/params_testground.go | 6 +++--- chain/stmgr/stmgr.go | 14 ++++++++------ chain/vm/runtime.go | 7 +++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/build/params_testground.go b/build/params_testground.go index ab7c16436..2802943a5 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -49,13 +49,13 @@ var ( TicketRandomnessLookback = abi.ChainEpoch(1) WinningPoStSectorSetLookback = abi.ChainEpoch(10) - TotalFilecoin uint64 = 2_000_000_000 - MiningRewardTotal uint64 = 1_400_000_000 + FilBase uint64 = 2_000_000_000 + FilAllocStorageMining uint64 = 1_400_000_000 FilecoinPrecision uint64 = 1_000_000_000_000_000_000 InitialRewardBalance = func() *big.Int { - v := big.NewInt(int64(MiningRewardTotal)) + v := big.NewInt(int64(FilAllocStorageMining)) v = v.Mul(v, big.NewInt(int64(FilecoinPrecision))) return v }() diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 95c911988..1acacba17 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -36,11 +36,12 @@ var log = logging.Logger("statemgr") type StateManager struct { cs *store.ChainStore - stCache map[string][]cid.Cid - compWait map[string]chan struct{} - stlk sync.Mutex - newVM func(cid.Cid, abi.ChainEpoch, vm.Rand, blockstore.Blockstore, vm.SyscallBuilder, vm.VestedCalculator) (*vm.VM, error) - genesisMsigs []multisig.State + stCache map[string][]cid.Cid + compWait map[string]chan struct{} + stlk sync.Mutex + genesisMsigLk sync.Mutex + newVM func(cid.Cid, abi.ChainEpoch, vm.Rand, blockstore.Blockstore, vm.SyscallBuilder, vm.VestedCalculator) (*vm.VM, error) + genesisMsigs []multisig.State } func NewStateManager(cs *store.ChainStore) *StateManager { @@ -852,7 +853,8 @@ func (sm *StateManager) setupGenesisMsigs(ctx context.Context) error { } func (sm *StateManager) GetVestedFunds(ctx context.Context, height abi.ChainEpoch) (abi.TokenAmount, error) { - + sm.genesisMsigLk.Lock() + defer sm.genesisMsigLk.Unlock() if sm.genesisMsigs == nil { err := sm.setupGenesisMsigs(ctx) if err != nil { diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index c2ca936a7..b4f6c6b9a 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -73,6 +73,9 @@ func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount { } filMined := types.BigSub(types.FromFil(build.FilAllocStorageMining), rew.Balance) + if filMined.LessThan(big.Zero()) { + filMined = big.Zero() + } burnt, err := rt.state.GetActor(builtin.BurntFundsActorAddr) if err != nil { @@ -109,6 +112,10 @@ func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount { ret := types.BigAdd(filVested, filMined) ret = types.BigSub(ret, filBurned) ret = types.BigSub(ret, filLocked) + + if ret.LessThan(big.Zero()) { + ret = big.Zero() + } return ret }