address review feedback

This commit is contained in:
whyrusleeping 2019-09-09 13:03:10 -07:00
parent 3ab711d133
commit 512da42cde
7 changed files with 63 additions and 97 deletions

View File

@ -15,7 +15,6 @@ import (
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain"
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/stmgr"
"github.com/filecoin-project/go-lotus/chain/store"
@ -364,7 +363,7 @@ func (mca mca) ChainGetRandomness(ctx context.Context, pts *types.TipSet, ticks
}
func (mca mca) StateMinerPower(ctx context.Context, maddr address.Address, ts *types.TipSet) (api.MinerPower, error) {
mpow, tpow, err := chain.GetPower(ctx, mca.sm, ts, maddr)
mpow, tpow, err := stmgr.GetPower(ctx, mca.sm, ts, maddr)
if err != nil {
return api.MinerPower{}, err
}

View File

@ -11,7 +11,7 @@ import (
"golang.org/x/xerrors"
)
func CallRaw(ctx context.Context, sm *StateManager, msg *types.Message, bstate cid.Cid, bheight uint64) (*types.MessageReceipt, error) {
func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate cid.Cid, bheight uint64) (*types.MessageReceipt, error) {
vmi, err := vm.NewVM(bstate, bheight, actors.NetworkAddress, sm.cs)
if err != nil {
return nil, xerrors.Errorf("failed to set up vm: %w", err)
@ -53,7 +53,7 @@ func CallRaw(ctx context.Context, sm *StateManager, msg *types.Message, bstate c
}
func Call(ctx context.Context, sm *StateManager, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
if ts == nil {
ts = sm.cs.GetHeaviestTipSet()
}
@ -63,5 +63,5 @@ func Call(ctx context.Context, sm *StateManager, msg *types.Message, ts *types.T
return nil, err
}
return CallRaw(ctx, sm, msg, state, ts.Height())
return sm.CallRaw(ctx, msg, state, ts.Height())
}

View File

@ -11,7 +11,7 @@ import (
)
func GetMinerWorker(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) {
recp, err := CallRaw(ctx, sm, &types.Message{
recp, err := sm.CallRaw(ctx, &types.Message{
To: maddr,
From: maddr,
Method: actors.MAMethods.GetWorkerAddr,
@ -37,7 +37,7 @@ func GetMinerWorker(ctx context.Context, sm *StateManager, st cid.Cid, maddr add
}
func GetMinerOwner(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) {
recp, err := CallRaw(ctx, sm, &types.Message{
recp, err := sm.CallRaw(ctx, &types.Message{
To: maddr,
From: maddr,
Method: actors.MAMethods.GetOwner,
@ -61,3 +61,46 @@ func GetMinerOwner(ctx context.Context, sm *StateManager, st cid.Cid, maddr addr
return owner, nil
}
func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (types.BigInt, types.BigInt, error) {
var err error
enc, err := actors.SerializeParams(&actors.PowerLookupParams{maddr})
if err != nil {
return types.EmptyInt, types.EmptyInt, err
}
var mpow types.BigInt
if maddr != address.Undef {
ret, err := sm.Call(ctx, &types.Message{
From: maddr,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.PowerLookup,
Params: enc,
}, ts)
if err != nil {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get miner power from chain: %w", err)
}
if ret.ExitCode != 0 {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get miner power from chain (exit code %d)", ret.ExitCode)
}
mpow = types.BigFromBytes(ret.Return)
}
ret, err := sm.Call(ctx, &types.Message{
From: actors.StorageMarketAddress,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.GetTotalStorage,
}, ts)
if err != nil {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain: %w", err)
}
if ret.ExitCode != 0 {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain (exit code %d)", ret.ExitCode)
}
tpow := types.BigFromBytes(ret.Return)
return mpow, tpow, nil
}

View File

@ -705,7 +705,8 @@ func (cs *ChainStore) TryFillTipSet(ts *types.TipSet) (*FullTipSet, error) {
func (cs *ChainStore) GetRandomness(ctx context.Context, pts *types.TipSet, tickets []*types.Ticket, lb int) ([]byte, error) {
if lb < len(tickets) {
panic("self sampling is bad")
log.Warn("self sampling randomness. this should be extremely rare, if you see this often it may be a bug")
t := tickets[len(tickets)-(1+lb)]
return t.VDFResult, nil

View File

@ -325,7 +325,7 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b
return err
}
ret, err := stmgr.Call(ctx, syncer.sm, &types.Message{
ret, err := syncer.sm.Call(ctx, &types.Message{
To: actors.StorageMarketAddress,
From: maddr,
Method: actors.SMAMethods.IsMiner,
@ -417,7 +417,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return xerrors.Errorf("checking eproof failed: %w", err)
}
mpow, tpow, err := GetPower(ctx, syncer.sm, baseTs, h.Miner)
mpow, tpow, err := stmgr.GetPower(ctx, syncer.sm, baseTs, h.Miner)
if err != nil {
return xerrors.Errorf("failed getting power: %w", err)
}
@ -510,7 +510,11 @@ loop:
// NB: GetBlocks validates that the blocks are in-fact the ones we
// requested, and that they are correctly linked to eachother. It does
// not validate any state transitions
blks, err := syncer.Bsync.GetBlocks(context.TODO(), at, 10)
window := 10
if gap := int(blockSet[len(blockSet)-1].Height() - untilHeight); gap < window {
window = gap
}
blks, err := syncer.Bsync.GetBlocks(context.TODO(), at, window)
if err != nil {
// Most likely our peers aren't fully synced yet, but forwarded
// new block message (ideally we'd find better peers)
@ -523,10 +527,6 @@ loop:
for _, b := range blks {
if b.Height() < untilHeight {
// REVIEW: this was an existing bug I think, if this got hit
// we would not append the remaining blocks to our blockset, but
// we would keep looping, and the outer for loop condition wouldnt trigger
// causing us to request the parents of the genesis block (aka, an empty cid set)
break loop
}
blockSet = append(blockSet, b)
@ -688,46 +688,3 @@ func VerifyElectionProof(ctx context.Context, eproof []byte, rand []byte, worker
return nil
}
func GetPower(ctx context.Context, sm *stmgr.StateManager, ts *types.TipSet, maddr address.Address) (types.BigInt, types.BigInt, error) {
var err error
enc, err := actors.SerializeParams(&actors.PowerLookupParams{maddr})
if err != nil {
return types.EmptyInt, types.EmptyInt, err
}
var mpow types.BigInt
if maddr != address.Undef {
ret, err := stmgr.Call(ctx, sm, &types.Message{
From: maddr,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.PowerLookup,
Params: enc,
}, ts)
if err != nil {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get miner power from chain: %w", err)
}
if ret.ExitCode != 0 {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get miner power from chain (exit code %d)", ret.ExitCode)
}
mpow = types.BigFromBytes(ret.Return)
}
ret, err := stmgr.Call(ctx, sm, &types.Message{
From: actors.StorageMarketAddress,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.GetTotalStorage,
}, ts)
if err != nil {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain: %w", err)
}
if ret.ExitCode != 0 {
return types.EmptyInt, types.EmptyInt, xerrors.Errorf("failed to get total power from chain (exit code %d)", ret.ExitCode)
}
tpow := types.BigFromBytes(ret.Return)
return mpow, tpow, nil
}

View File

@ -153,45 +153,11 @@ func (a *StateAPI) StateMinerProvingSet(ctx context.Context, addr address.Addres
}
func (a *StateAPI) StateMinerPower(ctx context.Context, maddr address.Address, ts *types.TipSet) (api.MinerPower, error) {
var err error
enc, err := actors.SerializeParams(&actors.PowerLookupParams{maddr})
mpow, tpow, err := stmgr.GetPower(ctx, a.StateManager, ts, maddr)
if err != nil {
return api.MinerPower{}, err
}
var mpow types.BigInt
if maddr != address.Undef {
ret, err := stmgr.Call(ctx, a.StateManager, &types.Message{
From: maddr,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.PowerLookup,
Params: enc,
}, ts)
if err != nil {
return api.MinerPower{}, xerrors.Errorf("failed to get miner power from chain: %w", err)
}
if ret.ExitCode != 0 {
return api.MinerPower{}, xerrors.Errorf("failed to get miner power from chain (exit code %d)", ret.ExitCode)
}
mpow = types.BigFromBytes(ret.Return)
}
ret, err := stmgr.Call(ctx, a.StateManager, &types.Message{
From: actors.StorageMarketAddress,
To: actors.StorageMarketAddress,
Method: actors.SMAMethods.GetTotalStorage,
}, ts)
if err != nil {
return api.MinerPower{}, xerrors.Errorf("failed to get total power from chain: %w", err)
}
if ret.ExitCode != 0 {
return api.MinerPower{}, xerrors.Errorf("failed to get total power from chain (exit code %d)", ret.ExitCode)
}
tpow := types.BigFromBytes(ret.Return)
return api.MinerPower{
MinerPower: mpow,
TotalPower: tpow,
@ -199,7 +165,7 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, maddr address.Address, t
}
func (a *StateAPI) StateMinerWorker(ctx context.Context, m address.Address, ts *types.TipSet) (address.Address, error) {
ret, err := stmgr.Call(ctx, a.StateManager, &types.Message{
ret, err := a.StateManager.Call(ctx, &types.Message{
From: m,
To: m,
Method: actors.MAMethods.GetWorkerAddr,
@ -221,7 +187,7 @@ func (a *StateAPI) StateMinerWorker(ctx context.Context, m address.Address, ts *
}
func (a *StateAPI) StateCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
return stmgr.Call(ctx, a.StateManager, msg, ts)
return a.StateManager.Call(ctx, msg, ts)
}
func (a *StateAPI) stateForTs(ts *types.TipSet) (*state.StateTree, error) {

View File

@ -145,7 +145,7 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address
return false, err
}
ret, err := stmgr.Call(ctx, pm.sm, &types.Message{
ret, err := pm.sm.Call(ctx, &types.Message{
From: owner,
To: ch,
Method: actors.PCAMethods.UpdateChannelState,
@ -173,7 +173,7 @@ func (pm *Manager) loadPaychState(ctx context.Context, ch address.Address) (*typ
}
func (pm *Manager) getPaychOwner(ctx context.Context, ch address.Address) (address.Address, error) {
ret, err := stmgr.Call(ctx, pm.sm, &types.Message{
ret, err := pm.sm.Call(ctx, &types.Message{
From: ch,
To: ch,
Method: actors.PCAMethods.GetOwner,