From d9eaca5527fc56dddbeabfffdb476908a0c1b3da Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Fri, 16 Aug 2019 13:24:37 -0700 Subject: [PATCH] fix UpdateStorage to write back state --- chain/actors/actor_storagemarket.go | 13 ++++++++++++- chain/gen/utils.go | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/chain/actors/actor_storagemarket.go b/chain/actors/actor_storagemarket.go index ee0795968..2fd0ad592 100644 --- a/chain/actors/actor_storagemarket.go +++ b/chain/actors/actor_storagemarket.go @@ -116,7 +116,8 @@ type UpdateStorageParams struct { func (sma StorageMarketActor) UpdateStorage(act *types.Actor, vmctx types.VMContext, params *UpdateStorageParams) ([]byte, ActorError) { var self StorageMarketState - if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil { + old := vmctx.Storage().GetHead() + if err := vmctx.Storage().Get(old, &self); err != nil { return nil, err } @@ -126,6 +127,16 @@ func (sma StorageMarketActor) UpdateStorage(act *types.Actor, vmctx types.VMCont } self.TotalStorage = types.BigAdd(self.TotalStorage, params.Delta) + + nroot, err := vmctx.Storage().Put(self) + if err != nil { + return nil, err + } + + if err := vmctx.Storage().Commit(old, nroot); err != nil { + return nil, err + } + return nil, nil } diff --git a/chain/gen/utils.go b/chain/gen/utils.go index e912d35a5..f3a7b4565 100644 --- a/chain/gen/utils.go +++ b/chain/gen/utils.go @@ -187,6 +187,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid params = mustEnc(actors.UpdateStorageParams{Delta: types.NewInt(5000)}) _, err = doExec(ctx, vm, actors.StorageMarketAddress, maddr, actors.SMAMethods.UpdateStorage, params) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to update total storage: %w", err) + } // UGLY HACKY MODIFICATION OF MINER POWER