address some review

This commit is contained in:
Jeromy 2020-04-08 17:24:10 -07:00
parent ef6fb1b756
commit c5c18659a4
8 changed files with 57 additions and 43 deletions

View File

@ -73,7 +73,7 @@ type FullNode interface {
// miner // miner
MinerGetBaseInfo(context.Context, address.Address, types.TipSetKey) (*MiningBaseInfo, error) MinerGetBaseInfo(context.Context, address.Address, types.TipSetKey) (*MiningBaseInfo, error)
MinerCreateBlock(context.Context, address.Address, types.TipSetKey, *types.Ticket, *types.ElectionProof, []types.BeaconEntry, []*types.SignedMessage, abi.ChainEpoch, uint64) (*types.BlockMsg, error) MinerCreateBlock(context.Context, *BlockTemplate) (*types.BlockMsg, error)
// // UX ? // // UX ?
@ -387,3 +387,14 @@ type MiningBaseInfo struct {
Worker address.Address Worker address.Address
SectorSize abi.SectorSize SectorSize abi.SectorSize
} }
type BlockTemplate struct {
Miner address.Address
Parents types.TipSetKey
Ticket *types.Ticket
Eproof *types.ElectionProof
BeaconValues []types.BeaconEntry
Messages []*types.SignedMessage
Epoch abi.ChainEpoch
Timestamp uint64
}

View File

@ -89,7 +89,7 @@ type FullNodeStruct struct {
MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"` MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"`
MinerGetBaseInfo func(context.Context, address.Address, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"` MinerGetBaseInfo func(context.Context, address.Address, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"`
MinerCreateBlock func(context.Context, address.Address, types.TipSetKey, *types.Ticket, *types.ElectionProof, []types.BeaconEntry, []*types.SignedMessage, abi.ChainEpoch, uint64) (*types.BlockMsg, error) `perm:"write"` MinerCreateBlock func(context.Context, *api.BlockTemplate) (*types.BlockMsg, error) `perm:"write"`
WalletNew func(context.Context, crypto.SigType) (address.Address, error) `perm:"write"` WalletNew func(context.Context, crypto.SigType) (address.Address, error) `perm:"write"`
WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"` WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"`
@ -330,8 +330,8 @@ func (c *FullNodeStruct) MinerGetBaseInfo(ctx context.Context, maddr address.Add
return c.Internal.MinerGetBaseInfo(ctx, maddr, tsk) return c.Internal.MinerGetBaseInfo(ctx, maddr, tsk)
} }
func (c *FullNodeStruct) MinerCreateBlock(ctx context.Context, addr address.Address, base types.TipSetKey, ticket *types.Ticket, eproof *types.ElectionProof, bvals []types.BeaconEntry, msgs []*types.SignedMessage, height abi.ChainEpoch, ts uint64) (*types.BlockMsg, error) { func (c *FullNodeStruct) MinerCreateBlock(ctx context.Context, bt *api.BlockTemplate) (*types.BlockMsg, error) {
return c.Internal.MinerCreateBlock(ctx, addr, base, ticket, eproof, bvals, msgs, height, ts) return c.Internal.MinerCreateBlock(ctx, bt)
} }
func (c *FullNodeStruct) ChainHead(ctx context.Context) (*types.TipSet, error) { func (c *FullNodeStruct) ChainHead(ctx context.Context) (*types.TipSet, error) {

View File

@ -288,9 +288,6 @@ func (cg *ChainGen) nextBlockProof(ctx context.Context, pts *types.TipSet, m add
if err != nil { if err != nil {
return nil, nil, nil, xerrors.Errorf("get beacon entries for block: %w", err) return nil, nil, nil, xerrors.Errorf("get beacon entries for block: %w", err)
} }
if len(entries) == 0 {
panic("no drand")
}
rbase := *prev rbase := *prev
if len(entries) > 0 { if len(entries) > 0 {
@ -359,9 +356,6 @@ func (cg *ChainGen) NextTipSetFromMiners(base *types.TipSet, miners []address.Ad
if err != nil { if err != nil {
return nil, xerrors.Errorf("next block proof: %w", err) return nil, xerrors.Errorf("next block proof: %w", err)
} }
if len(bvals) == 0 {
panic("no drand")
}
if et != nil { if et != nil {
// TODO: winning post proof // TODO: winning post proof
@ -399,7 +393,16 @@ func (cg *ChainGen) makeBlock(parents *types.TipSet, m address.Address, vrfticke
ts = parents.MinTimestamp() + uint64((height-parents.Height())*build.BlockDelay) ts = parents.MinTimestamp() + uint64((height-parents.Height())*build.BlockDelay)
} }
fblk, err := MinerCreateBlock(context.TODO(), cg.sm, cg.w, m, parents, vrfticket, eticket, bvals, msgs, height, ts) fblk, err := MinerCreateBlock(context.TODO(), cg.sm, cg.w, &api.BlockTemplate{
Miner: m,
Parents: parents.Key(),
Ticket: vrfticket,
Eproof: eticket,
BeaconValues: bvals,
Messages: msgs,
Epoch: height,
Timestamp: ts,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -5,14 +5,13 @@ import (
bls "github.com/filecoin-project/filecoin-ffi" bls "github.com/filecoin-project/filecoin-ffi"
amt "github.com/filecoin-project/go-amt-ipld/v2" amt "github.com/filecoin-project/go-amt-ipld/v2"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/crypto"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor" cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/state"
"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"
@ -20,30 +19,32 @@ import (
"github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/chain/wallet"
) )
func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wallet, miner address.Address, func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wallet, bt *api.BlockTemplate) (*types.FullBlock, error) {
parents *types.TipSet, vrfticket *types.Ticket, eproof *types.ElectionProof,
bvals []types.BeaconEntry, msgs []*types.SignedMessage, height abi.ChainEpoch,
timestamp uint64) (*types.FullBlock, error) {
st, recpts, err := sm.TipSetState(ctx, parents) pts, err := sm.ChainStore().LoadTipSet(bt.Parents)
if err != nil {
return nil, xerrors.Errorf("failed to load parent tipset: %w", err)
}
st, recpts, err := sm.TipSetState(ctx, pts)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to load tipset state: %w", err) return nil, xerrors.Errorf("failed to load tipset state: %w", err)
} }
worker, err := stmgr.GetMinerWorkerRaw(ctx, sm, st, miner) worker, err := stmgr.GetMinerWorkerRaw(ctx, sm, st, bt.Miner)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed to get miner worker: %w", err) return nil, xerrors.Errorf("failed to get miner worker: %w", err)
} }
next := &types.BlockHeader{ next := &types.BlockHeader{
Miner: miner, Miner: bt.Miner,
Parents: parents.Cids(), Parents: bt.Parents.Cids(),
Ticket: vrfticket, Ticket: bt.Ticket,
ElectionProof: eproof, ElectionProof: bt.Eproof,
BeaconEntries: bvals, BeaconEntries: bt.BeaconValues,
Height: height, Height: bt.Epoch,
Timestamp: timestamp, Timestamp: bt.Timestamp,
//EPostProof: *proof, //EPostProof: *proof,
ParentStateRoot: st, ParentStateRoot: st,
ParentMessageReceipts: recpts, ParentMessageReceipts: recpts,
@ -54,7 +55,7 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
var blsMsgCids, secpkMsgCids []cid.Cid var blsMsgCids, secpkMsgCids []cid.Cid
var blsSigs []crypto.Signature var blsSigs []crypto.Signature
for _, msg := range msgs { for _, msg := range bt.Messages {
if msg.Signature.Type == crypto.SigTypeBLS { if msg.Signature.Type == crypto.SigTypeBLS {
blsSigs = append(blsSigs, msg.Signature) blsSigs = append(blsSigs, msg.Signature)
blsMessages = append(blsMessages, &msg.Message) blsMessages = append(blsMessages, &msg.Message)
@ -102,7 +103,7 @@ func MinerCreateBlock(ctx context.Context, sm *stmgr.StateManager, w *wallet.Wal
} }
next.BLSAggregate = aggSig next.BLSAggregate = aggSig
pweight, err := sm.ChainStore().Weight(ctx, parents) pweight, err := sm.ChainStore().Weight(ctx, pts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -618,7 +618,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
return xerrors.Errorf("miner created a block but was not a winner") return xerrors.Errorf("miner created a block but was not a winner")
} }
// TODO: validate winning post proof log.Warn("TODO: validate winning post proof") // TODO: validate winning post proof
return nil return nil
}) })
@ -634,7 +634,6 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
if err := beacon.ValidateBlockValues(syncer.beacon, h, *prevBeacon); err != nil { if err := beacon.ValidateBlockValues(syncer.beacon, h, *prevBeacon); err != nil {
return xerrors.Errorf("failed to validate blocks random beacon values: %w", err) return xerrors.Errorf("failed to validate blocks random beacon values: %w", err)
} }
// TODO: check if first value links to value from previous block/previous block containing a value
return nil return nil
}) })

View File

@ -70,12 +70,7 @@ create table if not exists blocks
miner text not null, miner text not null,
timestamp bigint not null, timestamp bigint not null,
vrfproof bytea, vrfproof bytea,
tickets bigint not null,
eprof bytea, eprof bytea,
prand bytea,
ep0partial bytea,
ep0sector numeric not null,
ep0challangei numeric not null
); );
create unique index if not exists block_cid_uindex create unique index if not exists block_cid_uindex

View File

@ -424,7 +424,16 @@ func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *type
nheight := base.ts.Height() + base.nullRounds + 1 nheight := base.ts.Height() + base.nullRounds + 1
// why even return this? that api call could just submit it for us // why even return this? that api call could just submit it for us
return m.api.MinerCreateBlock(context.TODO(), addr, base.ts.Key(), ticket, eproof, bvals, msgs, nheight, uts) return m.api.MinerCreateBlock(context.TODO(), &api.BlockTemplate{
Miner: addr,
Parents: base.ts.Key(),
Ticket: ticket,
Eproof: eproof,
BeaconValues: bvals,
Messages: msgs,
Epoch: nheight,
Timestamp: uts,
})
} }
type ActorLookup func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error) type ActorLookup func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error)

View File

@ -269,12 +269,8 @@ func (a *StateAPI) MinerGetBaseInfo(ctx context.Context, maddr address.Address,
return stmgr.MinerGetBaseInfo(ctx, a.StateManager, tsk, maddr) return stmgr.MinerGetBaseInfo(ctx, a.StateManager, tsk, maddr)
} }
func (a *StateAPI) MinerCreateBlock(ctx context.Context, addr address.Address, parentsTSK types.TipSetKey, ticket *types.Ticket, proof *types.ElectionProof, bvals []types.BeaconEntry, msgs []*types.SignedMessage, height abi.ChainEpoch, ts uint64) (*types.BlockMsg, error) { func (a *StateAPI) MinerCreateBlock(ctx context.Context, bt *api.BlockTemplate) (*types.BlockMsg, error) {
parents, err := a.Chain.GetTipSetFromKey(parentsTSK) fblk, err := gen.MinerCreateBlock(ctx, a.StateManager, a.Wallet, bt)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", parentsTSK, err)
}
fblk, err := gen.MinerCreateBlock(ctx, a.StateManager, a.Wallet, addr, parents, ticket, proof, bvals, msgs, height, ts)
if err != nil { if err != nil {
return nil, err return nil, err
} }