fixed RewardFunc

This commit is contained in:
Alfonso de la Rocha 2022-10-13 13:20:51 +02:00
parent 88d3de7afc
commit 9bfb73211e
3 changed files with 10 additions and 8 deletions

View File

@ -200,16 +200,12 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context,
processedMsgs[m.Cid()] = struct{}{} processedMsgs[m.Cid()] = struct{}{}
} }
params, err := actors.SerializeParams(&reward.AwardBlockRewardParams{ params := &reward.AwardBlockRewardParams{
Miner: b.Miner, Miner: b.Miner,
Penalty: penalty, Penalty: penalty,
GasReward: gasReward, GasReward: gasReward,
WinCount: b.WinCount, WinCount: b.WinCount,
})
if err != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("failed to serialize award params: %w", err)
} }
rErr := t.reward(ctx, vmi, em, epoch, ts, params) rErr := t.reward(ctx, vmi, em, epoch, ts, params)
if rErr != nil { if rErr != nil {
return cid.Undef, cid.Undef, xerrors.Errorf("error applying reward: %w", err) return cid.Undef, cid.Undef, xerrors.Errorf("error applying reward: %w", err)

View File

@ -21,6 +21,7 @@ import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain" "github.com/filecoin-project/lotus/chain"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/filecoin-project/lotus/chain/actors/builtin/reward"
@ -59,7 +60,11 @@ type FilecoinEC struct {
const MaxHeightDrift = 5 const MaxHeightDrift = 5
var RewardFunc = func(ctx context.Context, vmi vm.Interface, em stmgr.ExecMonitor, var RewardFunc = func(ctx context.Context, vmi vm.Interface, em stmgr.ExecMonitor,
epoch abi.ChainEpoch, ts *types.TipSet, params []byte) error { epoch abi.ChainEpoch, ts *types.TipSet, params *reward.AwardBlockRewardParams) error {
ser, err := actors.SerializeParams(params)
if err != nil {
return xerrors.Errorf("failed to serialize award params: %w", err)
}
rwMsg := &types.Message{ rwMsg := &types.Message{
From: builtin.SystemActorAddr, From: builtin.SystemActorAddr,
To: reward.Address, To: reward.Address,
@ -69,7 +74,7 @@ var RewardFunc = func(ctx context.Context, vmi vm.Interface, em stmgr.ExecMonito
GasPremium: types.NewInt(0), GasPremium: types.NewInt(0),
GasLimit: 1 << 30, GasLimit: 1 << 30,
Method: reward.Methods.AwardBlockReward, Method: reward.Methods.AwardBlockReward,
Params: params, Params: ser,
} }
ret, actErr := vmi.ApplyImplicitMessage(ctx, rwMsg) ret, actErr := vmi.ApplyImplicitMessage(ctx, rwMsg)
if actErr != nil { if actErr != nil {

View File

@ -10,6 +10,7 @@ import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
"github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/chain/vm"
@ -47,7 +48,7 @@ type Consensus interface {
// //
// Each consensus implementation can set their own reward function. // Each consensus implementation can set their own reward function.
type RewardFunc func(ctx context.Context, vmi vm.Interface, em stmgr.ExecMonitor, type RewardFunc func(ctx context.Context, vmi vm.Interface, em stmgr.ExecMonitor,
epoch abi.ChainEpoch, ts *types.TipSet, params []byte) error epoch abi.ChainEpoch, ts *types.TipSet, params *reward.AwardBlockRewardParams) error
// ValidateBlockPubsub implements the common checks performed by all consensus implementations // ValidateBlockPubsub implements the common checks performed by all consensus implementations
// when a block is received through the pubsub channel. // when a block is received through the pubsub channel.