fix reward actor and block reward application

This commit is contained in:
whyrusleeping 2020-03-04 13:21:24 -08:00
parent 37d5baf0b2
commit 5076b2b950
10 changed files with 100 additions and 43 deletions

View File

@ -6,7 +6,6 @@ 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/crypto"
@ -20,7 +19,6 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
@ -131,11 +129,12 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
}
// Setup reward
err = state.SetActor(builtin.RewardActorAddr, &types.Actor{
Code: builtin.RewardActorCodeID,
Balance: big.Int{Int: build.InitialReward},
Head: emptyobject, // TODO ?
})
rewact, err := SetupRewardActor(bs)
if err != nil {
return nil, xerrors.Errorf("setup init actor: %w", err)
}
err = state.SetActor(builtin.RewardActorAddr, rewact)
if err != nil {
return nil, xerrors.Errorf("set network account actor: %w", err)
}

View File

@ -1 +1,36 @@
package genesis
import (
"context"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/filecoin-project/specs-actors/actors/util/adt"
bstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
)
func SetupRewardActor(bs bstore.Blockstore) (*types.Actor, error) {
cst := cbor.NewCborStore(bs)
as := store.ActorStore(context.TODO(), bs)
emv, err := adt.MakeEmptyMultimap(as)
if err != nil {
return nil, err
}
st := reward.ConstructState(emv.Root())
hcid, err := cst.Put(context.TODO(), st)
if err != nil {
return nil, err
}
return &types.Actor{
Code: builtin.RewardActorCodeID,
Balance: types.BigInt{Int: build.InitialReward},
Head: hcid,
}, nil
}

View File

@ -8,6 +8,7 @@ import (
"github.com/filecoin-project/go-address"
amt "github.com/filecoin-project/go-amt-ipld/v2"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
@ -16,6 +17,7 @@ import (
"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/market"
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/filecoin-project/specs-actors/actors/util/adt"
cbg "github.com/whyrusleeping/cbor-gen"
@ -130,31 +132,6 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []B
}
/*
rewardActor, err := vmi.StateTree().GetActor(builtin.RewardActorAddr)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
}
reward := vm.MiningReward(rewardActor.Balance)
for _, b := range bms {
rewardActor, err = vmi.StateTree().GetActor(builtin.RewardActorAddr)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
}
vmi.SetBlockMiner(b.Miner)
owner, err := GetMinerOwner(ctx, sm, pstate, b.Miner)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get owner for miner %s: %w", b.Miner, err)
}
act, err := vmi.StateTree().GetActor(owner)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get miner owner actor")
}
if err := vm.Transfer(rewardActor, act, reward); err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to deduct funds from network actor: %w", err)
}
}
*/
@ -178,9 +155,10 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []B
for _, b := range bms {
vmi.SetBlockMiner(b.Miner)
cmsgs := append(b.BlsMessages, b.SecpkMessages...)
penalty := types.NewInt(0)
gasReward := types.NewInt(0)
for _, cm := range cmsgs {
for _, cm := range append(b.BlsMessages, b.SecpkMessages...) {
m := cm.VMMessage()
if err := preloadAddr(m.From); err != nil {
return cid.Undef, cid.Undef, err
@ -209,6 +187,43 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []B
}
}
}
owner, err := GetMinerOwner(ctx, sm, pstate, b.Miner)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get owner for miner %s: %w", b.Miner, err)
}
params, err := actors.SerializeParams(&reward.AwardBlockRewardParams{
MinerOwner: owner,
Penalty: penalty,
GasReward: gasReward,
})
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to serialize award params: %w", err)
}
sysAct, err := vmi.StateTree().GetActor(builtin.SystemActorAddr)
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get system actor: %w", err)
}
ret, err := vmi.ApplyMessage(ctx, &types.Message{
From: builtin.SystemActorAddr,
To: builtin.RewardActorAddr,
Nonce: sysAct.Nonce,
Value: types.NewInt(0),
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1 << 30),
Method: builtin.MethodsReward.AwardBlockReward,
Params: params,
})
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to apply reward message for miner %s: %w", b.Miner, err)
}
if ret.ExitCode != 0 {
return cid.Undef, cid.Undef, xerrors.Errorf("reward application message failed (exit %d): %s", ret.ExitCode, ret.ActorErr)
}
}
// TODO: this nonce-getting is a tiny bit ugly

View File

@ -19,6 +19,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/builtin/multisig"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
"github.com/filecoin-project/specs-actors/actors/builtin/system"
vmr "github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/filecoin-project/specs-actors/actors/util/adt"
@ -44,6 +45,7 @@ func NewInvoker() *invoker {
// add builtInCode using: register(cid, singleton)
inv.Register(builtin.SystemActorCodeID, system.Actor{}, adt.EmptyValue{})
inv.Register(builtin.InitActorCodeID, init_.Actor{}, init_.State{})
inv.Register(builtin.RewardActorCodeID, reward.Actor{}, reward.State{})
inv.Register(builtin.CronActorCodeID, cron.Actor{}, cron.State{})
inv.Register(builtin.StoragePowerActorCodeID, power.Actor{}, power.State{})
inv.Register(builtin.StorageMarketActorCodeID, market.Actor{}, market.State{})

View File

@ -58,10 +58,9 @@ func (rs *runtimeShim) shimCall(f func() interface{}) (rval []byte, aerr aerrors
aerr = ar
return
}
log.Warn("caught one of those actor errors: ", r)
debug.PrintStack()
log.Errorf("ERROR")
aerr = aerrors.Newf(1, "generic spec actors failure")
aerr = aerrors.Newf(1, "spec actors failure: %s", r)
}
}()

View File

@ -8,6 +8,7 @@ import (
suites "github.com/filecoin-project/chain-validation/suites"
"github.com/filecoin-project/chain-validation/suites/message"
"github.com/filecoin-project/chain-validation/suites/tipset"
factory "github.com/filecoin-project/lotus/chain/validation"
)
@ -34,6 +35,7 @@ var TestSuiteSkipper TestSkipper
func init() {
// initialize the test skipper with tests being skipped
TestSuiteSkipper = TestSkipper{testSkips: []suites.TestCase{
tipset.TestInternalMessageApplicationFailure,
// Fails due to gas mismatches
message.TestPaych,

View File

@ -526,15 +526,13 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
}
}
bfact, err := st.GetActor(builtin.BurntFundsActorAddr)
rwAct, err := st.GetActor(builtin.RewardActorAddr)
if err != nil {
return nil, xerrors.Errorf("getting burnt funds actor failed: %w", err)
}
// TODO: support multiple blocks in a tipset
// TODO: actually wire this up (miner is undef for now)
gasReward := types.BigMul(msg.GasPrice, gasUsed)
if err := Transfer(gasHolder, bfact, gasReward); err != nil {
if err := Transfer(gasHolder, rwAct, gasReward); err != nil {
return nil, xerrors.Errorf("failed to give miner gas reward: %w", err)
}

View File

@ -6,12 +6,14 @@ import (
"context"
"encoding/hex"
"encoding/json"
"github.com/filecoin-project/lotus/chain/types"
"fmt"
"io/ioutil"
"os"
"runtime/pprof"
"strings"
"github.com/filecoin-project/lotus/chain/types"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/go-sectorbuilder"
blockstore "github.com/ipfs/go-ipfs-blockstore"
@ -134,6 +136,7 @@ var DaemonCmd = &cli.Command{
return err
}
if cctx.Bool("halt-after-import") {
fmt.Println("Chain import complete, halting as requested...")
return nil
}
}

6
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/coreos/go-systemd/v22 v22.0.0
github.com/docker/go-units v0.4.0
github.com/filecoin-project/chain-validation v0.0.6-0.20200303230205-30309cc5d8eb
github.com/filecoin-project/chain-validation v0.0.6-0.20200304211828-4b541348b199
github.com/filecoin-project/filecoin-ffi v0.0.0-20200226205820-4da0bccccefb
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
@ -23,7 +23,7 @@ require (
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228181617-f00e2c4cc050
github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/specs-actors v0.0.0-20200302223606-0eaf97b10aaf
github.com/filecoin-project/specs-actors v0.0.0-20200304210626-21ee86aadcb9
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/google/uuid v1.1.1
@ -116,3 +116,5 @@ replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0
replace github.com/filecoin-project/specs-actors => ../specs-actors

2
go.sum
View File

@ -99,6 +99,8 @@ github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGj
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
github.com/filecoin-project/chain-validation v0.0.6-0.20200303230205-30309cc5d8eb h1:vGm95uLk+4ytckKQX8mfOwMzgBge9rqHbTfDsImUWIs=
github.com/filecoin-project/chain-validation v0.0.6-0.20200303230205-30309cc5d8eb/go.mod h1:6FYR4Xi26mfXkNlrHOo7fZjITZ9GrqqF8OKG4IQ4zWk=
github.com/filecoin-project/chain-validation v0.0.6-0.20200304211828-4b541348b199 h1:HIdN3/s/fda3kQYMawG8ysYC207LJ5GnH0XziyTgQJk=
github.com/filecoin-project/chain-validation v0.0.6-0.20200304211828-4b541348b199/go.mod h1:JU9alo66MwdCHkpk1kDXB8vT8A/oMkTkdZ4mQjA4I5E=
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E=
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=