Merge pull request #2481 from filecoin-project/fix/reward-state

Make reward actor state in genesis more realistic
This commit is contained in:
Łukasz Magiera 2020-07-20 20:58:26 +02:00 committed by GitHub
commit deb1d6812e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View File

@ -39,8 +39,8 @@ func testGeneration(t testing.TB, n int, msgs int, sectors int) {
}
func TestChainGeneration(t *testing.T) {
testGeneration(t, 10, 20, 1)
testGeneration(t, 10, 20, 25)
t.Run("10-20-1", func(t *testing.T) { testGeneration(t, 10, 20, 1) })
t.Run("10-20-25", func(t *testing.T) { testGeneration(t, 10, 20, 25) })
}
func BenchmarkChainGeneration(b *testing.B) {

View File

@ -6,6 +6,7 @@ import (
"github.com/filecoin-project/go-amt-ipld/v2"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/account"
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
@ -62,6 +63,7 @@ The process:
- market.AddFunds with correct value
- market.PublishDeals for related sectors
- Set network power in the power actor to what we'll have after genesis creation
- Recreate reward actor state with the right power
- For each precommitted sector
- Get deal weight
- Calculate QA Power
@ -139,7 +141,8 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
}
// Setup reward
rewact, err := SetupRewardActor(bs)
// RewardActor's state is overrwritten by SetupStorageMiners
rewact, err := SetupRewardActor(bs, big.Zero())
if err != nil {
return nil, xerrors.Errorf("setup init actor: %w", err)
}

View File

@ -198,6 +198,11 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
if err != nil {
return cid.Undef, xerrors.Errorf("mutating state: %w", err)
}
err = vm.MutateState(ctx, builtin.RewardActorAddr, func(sct cbor.IpldStore, st *reward.State) error {
st = reward.ConstructState(qaPow)
return nil
})
}
for i, m := range miners {

View File

@ -2,6 +2,7 @@ package genesis
import (
"context"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/lotus/build"
@ -12,12 +13,10 @@ import (
cbor "github.com/ipfs/go-ipld-cbor"
)
func SetupRewardActor(bs bstore.Blockstore) (*types.Actor, error) {
func SetupRewardActor(bs bstore.Blockstore, qaPower big.Int) (*types.Actor, error) {
cst := cbor.NewCborStore(bs)
z := big.Zero()
st := reward.ConstructState(z)
st.ThisEpochReward = types.FromFil(100)
st := reward.ConstructState(qaPower)
hcid, err := cst.Put(context.TODO(), st)
if err != nil {