finish upgrading chainwatch

This commit is contained in:
Steven Allen 2020-09-18 13:43:14 -07:00
parent c3046f487c
commit fb2b25c297
11 changed files with 185 additions and 123 deletions

View File

@ -4,6 +4,7 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/cbor"
v0builtin "github.com/filecoin-project/specs-actors/actors/builtin" v0builtin "github.com/filecoin-project/specs-actors/actors/builtin"
@ -33,4 +34,6 @@ type State interface {
ResolveAddress(address address.Address) (address.Address, bool, error) ResolveAddress(address address.Address) (address.Address, bool, error)
MapAddressToNewID(address address.Address) (address.Address, error) MapAddressToNewID(address address.Address) (address.Address, error)
NetworkName() (dtypes.NetworkName, error) NetworkName() (dtypes.NetworkName, error)
ForEachActor(func(id abi.ActorID, address address.Address) error) error
} }

View File

@ -2,11 +2,15 @@ package init
import ( import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
cbg "github.com/whyrusleeping/cbor-gen"
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
"github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/dtypes"
v0adt "github.com/filecoin-project/specs-actors/actors/util/adt"
) )
type v0State struct { type v0State struct {
@ -22,6 +26,21 @@ func (s *v0State) MapAddressToNewID(address address.Address) (address.Address, e
return s.State.MapAddressToNewID(s.store, address) return s.State.MapAddressToNewID(s.store, address)
} }
func (s *v0State) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error {
addrs, err := v0adt.AsMap(s.store, s.State.AddressMap)
if err != nil {
return err
}
var actorID cbg.CborInt
return addrs.ForEach(&actorID, func(key string) error {
addr, err := address.NewFromBytes([]byte(key))
if err != nil {
return err
}
return cb(abi.ActorID(actorID), addr)
})
}
func (s *v0State) NetworkName() (dtypes.NetworkName, error) { func (s *v0State) NetworkName() (dtypes.NetworkName, error) {
return dtypes.NetworkName(s.State.NetworkName), nil return dtypes.NetworkName(s.State.NetworkName), nil
} }

View File

@ -33,8 +33,12 @@ type State interface {
TotalLocked() (abi.TokenAmount, error) TotalLocked() (abi.TokenAmount, error)
TotalPower() (Claim, error) TotalPower() (Claim, error)
TotalCommitted() (Claim, error)
TotalPowerSmoothed() (builtin.FilterEstimate, error) TotalPowerSmoothed() (builtin.FilterEstimate, error)
// MinerCounts returns the number of miners. Participating is the number
// with power above the minimum miner threshold.
MinerCounts() (participating, total uint64, err error)
MinerPower(address.Address) (Claim, bool, error) MinerPower(address.Address) (Claim, bool, error)
MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error)
ListAllMiners() ([]address.Address, error) ListAllMiners() ([]address.Address, error)

View File

@ -24,6 +24,14 @@ func (s *v0State) TotalPower() (Claim, error) {
}, nil }, nil
} }
// Committed power to the network. Includes miners below the minimum threshold.
func (s *v0State) TotalCommitted() (Claim, error) {
return Claim{
RawBytePower: s.TotalBytesCommitted,
QualityAdjPower: s.TotalQABytesCommitted,
}, nil
}
func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) { func (s *v0State) MinerPower(addr address.Address) (Claim, bool, error) {
claims, err := adt.AsMap(s.store, s.Claims) claims, err := adt.AsMap(s.store, s.Claims)
if err != nil { if err != nil {
@ -48,6 +56,10 @@ func (s *v0State) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
return *s.State.ThisEpochQAPowerSmoothed, nil return *s.State.ThisEpochQAPowerSmoothed, nil
} }
func (s *v0State) MinerCounts() (uint64, uint64, error) {
return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil
}
func (s *v0State) ListAllMiners() ([]address.Address, error) { func (s *v0State) ListAllMiners() ([]address.Address, error) {
claims, err := adt.AsMap(s.store, s.Claims) claims, err := adt.AsMap(s.store, s.Claims)
if err != nil { if err != nil {

View File

@ -30,8 +30,15 @@ func Load(store adt.Store, act *types.Actor) (st State, err error) {
type State interface { type State interface {
cbor.Er cbor.Er
RewardSmoothed() (builtin.FilterEstimate, error)
EffectiveBaselinePower() (abi.StoragePower, error)
ThisEpochBaselinePower() (abi.StoragePower, error) ThisEpochBaselinePower() (abi.StoragePower, error)
ThisEpochReward() (abi.StoragePower, error)
ThisEpochRewardSmoothed() (builtin.FilterEstimate, error)
EffectiveBaselinePower() (abi.StoragePower, error)
EffectiveNetworkTime() (abi.ChainEpoch, error)
TotalStoragePowerReward() (abi.TokenAmount, error) TotalStoragePowerReward() (abi.TokenAmount, error)
CumsumBaseline() (abi.StoragePower, error)
CumsumRealized() (abi.StoragePower, error)
} }

View File

@ -12,10 +12,18 @@ type v0State struct {
store adt.Store store adt.Store
} }
func (s *v0State) RewardSmoothed() (builtin.FilterEstimate, error) { func (s *v0State) ThisEpochReward() (abi.StoragePower, error) {
return s.State.ThisEpochReward, nil
}
func (s *v0State) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
return *s.State.ThisEpochRewardSmoothed, nil return *s.State.ThisEpochRewardSmoothed, nil
} }
func (s *v0State) ThisEpochBaselinePower() (abi.StoragePower, error) {
return s.State.ThisEpochBaselinePower, nil
}
func (s *v0State) TotalStoragePowerReward() (abi.TokenAmount, error) { func (s *v0State) TotalStoragePowerReward() (abi.TokenAmount, error) {
return s.State.TotalMined, nil return s.State.TotalMined, nil
} }
@ -24,6 +32,14 @@ func (s *v0State) EffectiveBaselinePower() (abi.StoragePower, error) {
return s.State.EffectiveBaselinePower, nil return s.State.EffectiveBaselinePower, nil
} }
func (s *v0State) ThisEpochBaselinePower() (abi.StoragePower, error) { func (s *v0State) EffectiveNetworkTime() (abi.ChainEpoch, error) {
return s.State.ThisEpochBaselinePower, nil return s.State.EffectiveNetworkTime, nil
}
func (s *v0State) CumsumBaseline() (abi.StoragePower, error) {
return s.State.CumsumBaseline, nil
}
func (s *v0State) CumsumRealized() (abi.StoragePower, error) {
return s.State.CumsumBaseline, nil
} }

View File

@ -1,7 +1,6 @@
package processor package processor
import ( import (
"bytes"
"context" "context"
"time" "time"
@ -9,14 +8,13 @@ import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
_init "github.com/filecoin-project/lotus/chain/actors/builtin/init"
"github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/events/state"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
cw_util "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/util" cw_util "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/util"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
_init "github.com/filecoin-project/specs-actors/actors/builtin/init"
"github.com/filecoin-project/specs-actors/actors/util/adt"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
typegen "github.com/whyrusleeping/cbor-gen"
) )
func (p *Processor) setupCommonActors() error { func (p *Processor) setupCommonActors() error {
@ -150,32 +148,17 @@ func (p Processor) storeActorAddresses(ctx context.Context, actors map[cid.Cid]A
return err return err
} }
initActorRaw, err := p.node.ChainReadObj(ctx, initActor.Head) initActorState, err := _init.Load(cw_util.NewAPIIpldStore(ctx, p.node), initActor)
if err != nil {
return err
}
var initActorState _init.State
if err := initActorState.UnmarshalCBOR(bytes.NewReader(initActorRaw)); err != nil {
return err
}
ctxStore := cw_util.NewAPIIpldStore(ctx, p.node)
addrMap, err := adt.AsMap(ctxStore, initActorState.AddressMap)
if err != nil { if err != nil {
return err return err
} }
// gross.. // gross..
var actorID typegen.CborInt if err := initActorState.ForEachActor(func(id abi.ActorID, addr address.Address) error {
if err := addrMap.ForEach(&actorID, func(key string) error { idAddr, err := address.NewIDAddress(uint64(id))
longAddr, err := address.NewFromBytes([]byte(key))
if err != nil { if err != nil {
return err return err
} }
shortAddr, err := address.NewIDAddress(uint64(actorID)) addressToID[addr] = idAddr
if err != nil {
return err
}
addressToID[longAddr] = shortAddr
return nil return nil
}); err != nil { }); err != nil {
return err return err

View File

@ -1,9 +1,7 @@
package processor package processor
import ( import (
"bytes"
"context" "context"
"fmt"
"strings" "strings"
"time" "time"
@ -15,13 +13,11 @@ import (
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/filecoin-project/specs-actors/actors/util/adt"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/api/apibstore"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/events/state"
"github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
@ -212,7 +208,7 @@ func (p *Processor) processMiners(ctx context.Context, minerTips map[types.TipSe
// TODO add parallel calls if this becomes slow // TODO add parallel calls if this becomes slow
for tipset, miners := range minerTips { for tipset, miners := range minerTips {
// get the power actors claims map // get the power actors claims map
minersClaims, err := getPowerActorClaimsMap(ctx, p.node, tipset) powerState, err := getPowerActorState(ctx, p.node, tipset)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -222,10 +218,9 @@ func (p *Processor) processMiners(ctx context.Context, minerTips map[types.TipSe
var mi minerActorInfo var mi minerActorInfo
mi.common = act mi.common = act
var claim power.Claim
// get miner claim from power actors claim map and store if found, else the miner had no claim at // get miner claim from power actors claim map and store if found, else the miner had no claim at
// this tipset // this tipset
found, err := minersClaims.Get(abi.AddrKey(act.addr), &claim) claim, found, err := powerState.MinerPower(act.addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1027,22 +1022,10 @@ func (p *Processor) storeMinersPower(miners []minerActorInfo) error {
} }
// load the power actor state clam as an adt.Map at the tipset `ts`. // load the power actor state clam as an adt.Map at the tipset `ts`.
func getPowerActorClaimsMap(ctx context.Context, api api.FullNode, ts types.TipSetKey) (*adt.Map, error) { func getPowerActorState(ctx context.Context, api api.FullNode, ts types.TipSetKey) (power.State, error) {
powerActor, err := api.StateGetActor(ctx, builtin.StoragePowerActorAddr, ts) powerActor, err := api.StateGetActor(ctx, power.Address, ts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return power.Load(cw_util.NewAPIIpldStore(ctx, api), powerActor)
powerRaw, err := api.ChainReadObj(ctx, powerActor.Head)
if err != nil {
return nil, err
}
var powerActorState power.State
if err := powerActorState.UnmarshalCBOR(bytes.NewReader(powerRaw)); err != nil {
return nil, fmt.Errorf("failed to unmarshal power actor state: %w", err)
}
s := cw_util.NewAPIIpldStore(ctx, api)
return adt.AsMap(s, powerActorState.Claims)
} }

View File

@ -1,16 +1,14 @@
package processor package processor
import ( import (
"bytes"
"context" "context"
"time" "time"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/util/smoothing"
) )
type powerActorInfo struct { type powerActorInfo struct {
@ -22,10 +20,7 @@ type powerActorInfo struct {
totalQualityAdjustedBytesCommitted big.Int totalQualityAdjustedBytesCommitted big.Int
totalPledgeCollateral big.Int totalPledgeCollateral big.Int
newRawBytes big.Int qaPowerSmoothed builtin.FilterEstimate
newQualityAdjustedBytes big.Int
newPledgeCollateral big.Int
newQAPowerSmoothed *smoothing.FilterEstimate
minerCount int64 minerCount int64
minerCountAboveMinimumPower int64 minerCountAboveMinimumPower int64
@ -44,10 +39,6 @@ create table if not exists chain_power
constraint power_smoothing_estimates_pk constraint power_smoothing_estimates_pk
primary key, primary key,
new_raw_bytes_power text not null,
new_qa_bytes_power text not null,
new_pledge_collateral text not null,
total_raw_bytes_power text not null, total_raw_bytes_power text not null,
total_raw_bytes_committed text not null, total_raw_bytes_committed text not null,
total_qa_bytes_power text not null, total_qa_bytes_power text not null,
@ -92,35 +83,49 @@ func (p *Processor) processPowerActors(ctx context.Context, powerTips ActorTips)
var pw powerActorInfo var pw powerActorInfo
pw.common = act pw.common = act
powerActor, err := p.node.StateGetActor(ctx, builtin.StoragePowerActorAddr, tipset) powerActorState, err := getPowerActorState(ctx, p.node, tipset)
if err != nil { if err != nil {
return nil, xerrors.Errorf("get power state (@ %s): %w", pw.common.stateroot.String(), err) return nil, xerrors.Errorf("get power state (@ %s): %w", pw.common.stateroot.String(), err)
} }
powerStateRaw, err := p.node.ChainReadObj(ctx, powerActor.Head) if totalPower, err := powerActorState.TotalPower(); err != nil {
if err != nil { return nil, xerrors.Errorf("failed to compute total power: %w", err)
return nil, xerrors.Errorf("read state obj (@ %s): %w", pw.common.stateroot.String(), err) } else {
pw.totalRawBytes = totalPower.RawBytePower
pw.totalQualityAdjustedBytes = totalPower.QualityAdjPower
} }
var powerActorState power.State if totalCommitted, err := powerActorState.TotalCommitted(); err != nil {
if err := powerActorState.UnmarshalCBOR(bytes.NewReader(powerStateRaw)); err != nil { return nil, xerrors.Errorf("failed to compute total committed: %w", err)
return nil, xerrors.Errorf("unmarshal state (@ %s): %w", pw.common.stateroot.String(), err) } else {
pw.totalRawBytesCommitted = totalCommitted.RawBytePower
pw.totalQualityAdjustedBytesCommitted = totalCommitted.QualityAdjPower
} }
pw.totalRawBytes = powerActorState.TotalRawBytePower if totalLocked, err := powerActorState.TotalLocked(); err != nil {
pw.totalRawBytesCommitted = powerActorState.TotalBytesCommitted return nil, xerrors.Errorf("failed to compute total locked: %w", err)
pw.totalQualityAdjustedBytes = powerActorState.TotalQualityAdjPower } else {
pw.totalQualityAdjustedBytesCommitted = powerActorState.TotalQABytesCommitted pw.totalPledgeCollateral = totalLocked
pw.totalPledgeCollateral = powerActorState.TotalPledgeCollateral }
pw.newRawBytes = powerActorState.ThisEpochRawBytePower if powerSmoothed, err := powerActorState.TotalPowerSmoothed(); err != nil {
pw.newQualityAdjustedBytes = powerActorState.ThisEpochQualityAdjPower return nil, xerrors.Errorf("failed to determine smoothed power: %w", err)
pw.newPledgeCollateral = powerActorState.ThisEpochPledgeCollateral } else {
pw.newQAPowerSmoothed = powerActorState.ThisEpochQAPowerSmoothed pw.qaPowerSmoothed = powerSmoothed
}
pw.minerCount = powerActorState.MinerCount // NOTE: this doesn't set new* fields. Previously, we
pw.minerCountAboveMinimumPower = powerActorState.MinerAboveMinPowerCount // filled these using ThisEpoch* fields from the actor
out = append(out, pw) // state, but these fields are effectively internal
// state and don't represent "new" power, as was
// assumed.
if participating, total, err := powerActorState.MinerCounts(); err != nil {
return nil, xerrors.Errorf("failed to count miners: %w", err)
} else {
pw.minerCountAboveMinimumPower = int64(participating)
pw.minerCount = int64(total)
}
} }
} }
@ -142,7 +147,7 @@ func (p *Processor) storePowerSmoothingEstimates(powerStates []powerActorInfo) e
return xerrors.Errorf("prep chain_power: %w", err) return xerrors.Errorf("prep chain_power: %w", err)
} }
stmt, err := tx.Prepare(`copy cp (state_root, new_raw_bytes_power, new_qa_bytes_power, new_pledge_collateral, total_raw_bytes_power, total_raw_bytes_committed, total_qa_bytes_power, total_qa_bytes_committed, total_pledge_collateral, qa_smoothed_position_estimate, qa_smoothed_velocity_estimate, miner_count, minimum_consensus_miner_count) from stdin;`) stmt, err := tx.Prepare(`copy cp (state_root, total_raw_bytes_power, total_raw_bytes_committed, total_qa_bytes_power, total_qa_bytes_committed, total_pledge_collateral, qa_smoothed_position_estimate, qa_smoothed_velocity_estimate, miner_count, minimum_consensus_miner_count) from stdin;`)
if err != nil { if err != nil {
return xerrors.Errorf("prepare tmp chain_power: %w", err) return xerrors.Errorf("prepare tmp chain_power: %w", err)
} }
@ -150,9 +155,6 @@ func (p *Processor) storePowerSmoothingEstimates(powerStates []powerActorInfo) e
for _, ps := range powerStates { for _, ps := range powerStates {
if _, err := stmt.Exec( if _, err := stmt.Exec(
ps.common.stateroot.String(), ps.common.stateroot.String(),
ps.newRawBytes.String(),
ps.newQualityAdjustedBytes.String(),
ps.newPledgeCollateral.String(),
ps.totalRawBytes.String(), ps.totalRawBytes.String(),
ps.totalRawBytesCommitted.String(), ps.totalRawBytesCommitted.String(),
@ -160,8 +162,8 @@ func (p *Processor) storePowerSmoothingEstimates(powerStates []powerActorInfo) e
ps.totalQualityAdjustedBytesCommitted.String(), ps.totalQualityAdjustedBytesCommitted.String(),
ps.totalPledgeCollateral.String(), ps.totalPledgeCollateral.String(),
ps.newQAPowerSmoothed.PositionEstimate.String(), ps.qaPowerSmoothed.PositionEstimate.String(),
ps.newQAPowerSmoothed.VelocityEstimate.String(), ps.qaPowerSmoothed.VelocityEstimate.String(),
ps.minerCount, ps.minerCount,
ps.minerCountAboveMinimumPower, ps.minerCountAboveMinimumPower,

View File

@ -1,18 +1,18 @@
package processor package processor
import ( import (
"bytes"
"context" "context"
"time" "time"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"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/smoothing"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
cw_util "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/util"
) )
type rewardActorInfo struct { type rewardActorInfo struct {
@ -24,13 +24,66 @@ type rewardActorInfo struct {
effectiveNetworkTime int64 effectiveNetworkTime int64
effectiveBaselinePower big.Int effectiveBaselinePower big.Int
// NOTE: These variables are wrong. Talk to @ZX about fixing. These _do
// not_ represent "new" anything.
newBaselinePower big.Int newBaselinePower big.Int
newBaseReward big.Int newBaseReward big.Int
newSmoothingEstimate *smoothing.FilterEstimate newSmoothingEstimate builtin.FilterEstimate
totalMinedReward big.Int totalMinedReward big.Int
} }
func (rw *rewardActorInfo) set(s reward.State) error {
if p, err := s.CumsumBaseline(); err != nil {
return xerrors.Errorf("getting cumsum baseline power (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.cumSumBaselinePower = p
}
if p, err := s.CumsumRealized(); err != nil {
return xerrors.Errorf("getting cumsum realized power (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.cumSumRealizedPower = p
}
if t, err := s.EffectiveNetworkTime(); err != nil {
return xerrors.Errorf("getting effective network time (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.effectiveNetworkTime = int64(t)
}
if p, err := s.EffectiveBaselinePower(); err != nil {
return xerrors.Errorf("getting effective baseline power (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.effectiveBaselinePower = p
}
if t, err := s.TotalStoragePowerReward(); err != nil {
return xerrors.Errorf("getting total mined (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.totalMinedReward = t
}
if p, err := s.ThisEpochBaselinePower(); err != nil {
return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.newBaselinePower = p
}
if t, err := s.ThisEpochReward(); err != nil {
return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.newBaseReward = t
}
if e, err := s.ThisEpochRewardSmoothed(); err != nil {
return xerrors.Errorf("getting this epoch baseline power (@ %s): %w", rw.common.stateroot.String(), err)
} else {
rw.newSmoothingEstimate = e
}
return nil
}
func (p *Processor) setupRewards() error { func (p *Processor) setupRewards() error {
tx, err := p.db.Begin() tx, err := p.db.Begin()
if err != nil { if err != nil {
@ -89,29 +142,19 @@ func (p *Processor) processRewardActors(ctx context.Context, rewardTips ActorTip
rw.common = act rw.common = act
// get reward actor states at each tipset once for all updates // get reward actor states at each tipset once for all updates
rewardActor, err := p.node.StateGetActor(ctx, builtin.RewardActorAddr, tipset) rewardActor, err := p.node.StateGetActor(ctx, reward.Address, tipset)
if err != nil { if err != nil {
return nil, xerrors.Errorf("get reward state (@ %s): %w", rw.common.stateroot.String(), err) return nil, xerrors.Errorf("get reward state (@ %s): %w", rw.common.stateroot.String(), err)
} }
rewardStateRaw, err := p.node.ChainReadObj(ctx, rewardActor.Head) rewardActorState, err := reward.Load(cw_util.NewAPIIpldStore(ctx, p.node), rewardActor)
if err != nil { if err != nil {
return nil, xerrors.Errorf("read state obj (@ %s): %w", rw.common.stateroot.String(), err) return nil, xerrors.Errorf("read state obj (@ %s): %w", rw.common.stateroot.String(), err)
} }
if err := rw.set(rewardActorState); err != nil {
var rewardActorState reward.State return nil, err
if err := rewardActorState.UnmarshalCBOR(bytes.NewReader(rewardStateRaw)); err != nil {
return nil, xerrors.Errorf("unmarshal state (@ %s): %w", rw.common.stateroot.String(), err)
} }
rw.cumSumBaselinePower = rewardActorState.CumsumBaseline
rw.cumSumRealizedPower = rewardActorState.CumsumRealized
rw.effectiveNetworkTime = int64(rewardActorState.EffectiveNetworkTime)
rw.effectiveBaselinePower = rewardActorState.EffectiveBaselinePower
rw.newBaselinePower = rewardActorState.ThisEpochBaselinePower
rw.newBaseReward = rewardActorState.ThisEpochReward
rw.newSmoothingEstimate = rewardActorState.ThisEpochRewardSmoothed
rw.totalMinedReward = rewardActorState.TotalMined
out = append(out, rw) out = append(out, rw)
} }
} }
@ -126,29 +169,19 @@ func (p *Processor) processRewardActors(ctx context.Context, rewardTips ActorTip
rw.common.stateroot = tipset.ParentState() rw.common.stateroot = tipset.ParentState()
rw.common.parentTsKey = tipset.Parents() rw.common.parentTsKey = tipset.Parents()
// get reward actor states at each tipset once for all updates // get reward actor states at each tipset once for all updates
rewardActor, err := p.node.StateGetActor(ctx, builtin.RewardActorAddr, tsKey) rewardActor, err := p.node.StateGetActor(ctx, reward.Address, tsKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
rewardStateRaw, err := p.node.ChainReadObj(ctx, rewardActor.Head) rewardActorState, err := reward.Load(cw_util.NewAPIIpldStore(ctx, p.node), rewardActor)
if err != nil { if err != nil {
return nil, err return nil, xerrors.Errorf("read state obj (@ %s): %w", rw.common.stateroot.String(), err)
} }
var rewardActorState reward.State if err := rw.set(rewardActorState); err != nil {
if err := rewardActorState.UnmarshalCBOR(bytes.NewReader(rewardStateRaw)); err != nil {
return nil, err return nil, err
} }
rw.cumSumBaselinePower = rewardActorState.CumsumBaseline
rw.cumSumRealizedPower = rewardActorState.CumsumRealized
rw.effectiveNetworkTime = int64(rewardActorState.EffectiveNetworkTime)
rw.effectiveBaselinePower = rewardActorState.EffectiveBaselinePower
rw.newBaselinePower = rewardActorState.ThisEpochBaselinePower
rw.newBaseReward = rewardActorState.ThisEpochReward
rw.newSmoothingEstimate = rewardActorState.ThisEpochRewardSmoothed
rw.totalMinedReward = rewardActorState.TotalMined
out = append(out, rw) out = append(out, rw)
} }

View File

@ -940,7 +940,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
} else if s, err := reward.Load(store, act); err != nil { } else if s, err := reward.Load(store, act); err != nil {
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
} else if r, err := s.RewardSmoothed(); err != nil { } else if r, err := s.ThisEpochRewardSmoothed(); err != nil {
return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err)
} else { } else {
rewardSmoothed = r rewardSmoothed = r
@ -1011,7 +1011,7 @@ func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr
return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err) return types.EmptyInt, xerrors.Errorf("loading miner actor: %w", err)
} else if s, err := reward.Load(store, act); err != nil { } else if s, err := reward.Load(store, act); err != nil {
return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err) return types.EmptyInt, xerrors.Errorf("loading reward actor state: %w", err)
} else if r, err := s.RewardSmoothed(); err != nil { } else if r, err := s.ThisEpochRewardSmoothed(); err != nil {
return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err) return types.EmptyInt, xerrors.Errorf("failed to determine total reward: %w", err)
} else if p, err := s.ThisEpochBaselinePower(); err != nil { } else if p, err := s.ThisEpochBaselinePower(); err != nil {
return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err) return types.EmptyInt, xerrors.Errorf("failed to determine baseline power: %w", err)