remove unnecessary code

This commit is contained in:
whyrusleeping 2019-12-03 12:05:54 -08:00
parent 0e4c59d6a7
commit d0448287a9
5 changed files with 7 additions and 71 deletions

View File

@ -29,7 +29,6 @@ type FullNode interface {
ChainGetBlockMessages(context.Context, cid.Cid) (*BlockMessages, error)
ChainGetParentReceipts(context.Context, cid.Cid) ([]*types.MessageReceipt, error)
ChainGetParentMessages(context.Context, cid.Cid) ([]Message, error)
ChainGetTipSetMessages(context.Context, types.TipSetKey) ([]Message, error)
ChainGetTipSetByHeight(context.Context, uint64, *types.TipSet) (*types.TipSet, error)
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
ChainSetHead(context.Context, *types.TipSet) error

View File

@ -45,7 +45,6 @@ type FullNodeStruct struct {
ChainGetBlockMessages func(context.Context, cid.Cid) (*BlockMessages, error) `perm:"read"`
ChainGetParentReceipts func(context.Context, cid.Cid) ([]*types.MessageReceipt, error) `perm:"read"`
ChainGetParentMessages func(context.Context, cid.Cid) ([]Message, error) `perm:"read"`
ChainGetTipSetMessages func(context.Context, types.TipSetKey) ([]Message, error) `perm:"read"`
ChainGetTipSetByHeight func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) `perm:"read"`
ChainReadObj func(context.Context, cid.Cid) ([]byte, error) `perm:"read"`
ChainSetHead func(context.Context, *types.TipSet) error `perm:"admin"`
@ -311,10 +310,6 @@ func (c *FullNodeStruct) ChainGetParentMessages(ctx context.Context, b cid.Cid)
return c.Internal.ChainGetParentMessages(ctx, b)
}
func (c *FullNodeStruct) ChainGetTipSetMessages(ctx context.Context, tsk types.TipSetKey) ([]Message, error) {
return c.Internal.ChainGetTipSetMessages(ctx, tsk)
}
func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan []*store.HeadChange, error) {
return c.Internal.ChainNotify(ctx)
}

View File

@ -346,43 +346,8 @@ func (m *Miner) computeTicket(ctx context.Context, addr address.Address, base *M
}, nil
}
func (m *Miner) actorLookup(ctx context.Context, addr address.Address, ts *types.TipSet) (uint64, *types.BigInt, error) {
// TODO: strong opportunities for some caching in this method
act, err := m.api.StateGetActor(ctx, addr, ts)
if err != nil {
return 0, nil, xerrors.Errorf("looking up actor failed: %w", err)
}
msgs, err := m.api.ChainGetTipSetMessages(ctx, ts.Key())
if err != nil {
return 0, nil, xerrors.Errorf("failed to get tipset messages: %w", err)
}
curnonce := act.Nonce
sort.Slice(msgs, func(i, j int) bool { // TODO: is this actually needed?
return msgs[i].Message.Nonce < msgs[j].Message.Nonce
})
max := int64(-2)
for _, m := range msgs {
if m.Message.From == addr {
max = int64(m.Message.Nonce)
}
}
max++ // next unapplied nonce
if max != -1 && uint64(max) != curnonce {
return 0, nil, xerrors.Errorf("tipset messages from %s have too low nonce %d, expected %d, h: %d", addr, max, curnonce, ts.Height())
}
return curnonce, &act.Balance, nil
}
func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *types.Ticket, proof *types.EPostProof, pending []*types.SignedMessage) (*types.BlockMsg, error) {
msgs, err := selectMessages(context.TODO(), m.actorLookup, base, pending)
msgs, err := selectMessages(context.TODO(), m.api.StateGetActor, base, pending)
if err != nil {
return nil, xerrors.Errorf("message filtering failed: %w", err)
}
@ -395,7 +360,7 @@ func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *type
return m.api.MinerCreateBlock(context.TODO(), addr, base.ts, ticket, proof, msgs, nheight, uint64(uts))
}
type actorLookup func(context.Context, address.Address, *types.TipSet) (uint64, *types.BigInt, error)
type actorLookup func(context.Context, address.Address, *types.TipSet) (*types.Actor, error)
func countFrom(msgs []*types.SignedMessage, from address.Address) (out int) {
for _, msg := range msgs {
@ -424,13 +389,13 @@ func selectMessages(ctx context.Context, al actorLookup, base *MiningBase, msgs
from := msg.Message.From
if _, ok := inclNonces[from]; !ok {
nonce, balance, err := al(ctx, from, base.ts)
act, err := al(ctx, from, base.ts)
if err != nil {
return nil, xerrors.Errorf("failed to check message sender balance: %w", err)
}
inclNonces[from] = nonce
inclBalances[from] = *balance
inclNonces[from] = act.Nonce
inclBalances[from] = act.Balance
}
if inclBalances[from].LessThan(msg.Message.RequiredFunds()) {

View File

@ -33,8 +33,8 @@ func TestMessageFiltering(t *testing.T) {
},
}
af := func(ctx context.Context, addr address.Address, ts *types.TipSet) (uint64, *types.BigInt, error) {
return actors[addr].Nonce, &actors[addr].Balance, nil
af := func(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, error) {
return actors[addr], nil
}
msgs := []types.Message{

View File

@ -68,7 +68,6 @@ func (a *ChainAPI) ChainGetBlockMessages(ctx context.Context, msg cid.Cid) (*api
}, nil
}
// TODO: Maybe deprecate in favor of just using ChainGetTipSetMessages?
func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]api.Message, error) {
b, err := a.Chain.GetBlock(bcid)
if err != nil {
@ -102,28 +101,6 @@ func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]
return out, nil
}
func (a *ChainAPI) ChainGetTipSetMessages(ctx context.Context, tsk types.TipSetKey) ([]api.Message, error) {
ts, err := a.Chain.LoadTipSet(tsk.Cids())
if err != nil {
return nil, xerrors.Errorf("failed to load tipset from key: %w", err)
}
messages, err := a.Chain.MessagesForTipset(ts)
if err != nil {
return nil, xerrors.Errorf("getting messages for tipset: %w", err)
}
var out []api.Message
for _, m := range messages {
out = append(out, api.Message{
Cid: m.Cid(),
Message: m.VMMessage(),
})
}
return out, nil
}
func (a *ChainAPI) ChainGetParentReceipts(ctx context.Context, bcid cid.Cid) ([]*types.MessageReceipt, error) {
b, err := a.Chain.GetBlock(bcid)
if err != nil {