2020-01-29 22:39:48 +00:00
|
|
|
// +build debug
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-23 18:29:58 +00:00
|
|
|
"encoding/binary"
|
|
|
|
"time"
|
|
|
|
|
2020-01-29 22:39:48 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
2020-04-09 17:34:54 +00:00
|
|
|
lapi "github.com/filecoin-project/lotus/api"
|
2020-01-29 22:39:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/gen"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-01-29 22:39:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
AdvanceBlockCmd = &cli.Command{
|
|
|
|
Name: "advance-block",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
api, closer, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
head, err := api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
2020-01-30 01:35:32 +00:00
|
|
|
return err
|
2020-01-29 22:39:48 +00:00
|
|
|
}
|
2020-08-11 11:05:04 +00:00
|
|
|
msgs, err := api.MpoolSelect(ctx, head.Key(), 1)
|
2020-01-29 22:39:48 +00:00
|
|
|
if err != nil {
|
2020-01-30 01:35:32 +00:00
|
|
|
return err
|
2020-01-29 22:39:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 13:10:46 +00:00
|
|
|
addr, _ := address.NewIDAddress(1000)
|
2020-01-29 22:39:48 +00:00
|
|
|
var ticket *types.Ticket
|
|
|
|
{
|
2020-04-17 15:58:20 +00:00
|
|
|
mi, err := api.StateMinerInfo(ctx, addr, head.Key())
|
2020-01-29 22:39:48 +00:00
|
|
|
if err != nil {
|
2020-02-21 19:31:45 +00:00
|
|
|
return xerrors.Errorf("StateMinerWorker: %w", err)
|
2020-01-29 22:39:48 +00:00
|
|
|
}
|
2020-02-23 21:30:36 +00:00
|
|
|
|
2020-09-02 17:44:17 +00:00
|
|
|
// XXX: This can't be right
|
2020-08-11 23:58:35 +00:00
|
|
|
rand, err := api.ChainGetRandomnessFromTickets(ctx, head.Key(), crypto.DomainSeparationTag_TicketProduction, head.Height(), addr.Bytes())
|
2020-02-23 21:30:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to get randomness: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:58:20 +00:00
|
|
|
t, err := gen.ComputeVRF(ctx, api.WalletSign, mi.Worker, rand)
|
2020-01-29 22:39:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("compute vrf failed: %w", err)
|
|
|
|
}
|
|
|
|
ticket = &types.Ticket{
|
|
|
|
VRFProof: t,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-28 01:38:51 +00:00
|
|
|
|
|
|
|
mbi, err := api.MinerGetBaseInfo(ctx, addr, head.Height()+1, head.Key())
|
2020-09-02 06:41:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting base info: %w", err)
|
|
|
|
}
|
2020-08-28 01:38:51 +00:00
|
|
|
|
2020-06-23 18:29:58 +00:00
|
|
|
ep := &types.ElectionProof{}
|
|
|
|
ep.WinCount = ep.ComputeWinCount(types.NewInt(1), types.NewInt(1))
|
|
|
|
for ep.WinCount == 0 {
|
|
|
|
fakeVrf := make([]byte, 8)
|
|
|
|
unixNow := uint64(time.Now().UnixNano())
|
|
|
|
binary.LittleEndian.PutUint64(fakeVrf, unixNow)
|
|
|
|
|
|
|
|
ep.VRFProof = fakeVrf
|
|
|
|
ep.WinCount = ep.ComputeWinCount(types.NewInt(1), types.NewInt(1))
|
|
|
|
}
|
2020-01-29 22:39:48 +00:00
|
|
|
|
2020-06-30 13:22:48 +00:00
|
|
|
uts := head.MinTimestamp() + uint64(build.BlockDelaySecs)
|
2020-01-29 22:39:48 +00:00
|
|
|
nheight := head.Height() + 1
|
2020-04-09 17:34:54 +00:00
|
|
|
blk, err := api.MinerCreateBlock(ctx, &lapi.BlockTemplate{
|
2020-08-28 01:38:51 +00:00
|
|
|
addr, head.Key(), ticket, ep, mbi.BeaconEntries, msgs, nheight, uts, gen.ValidWpostForTesting,
|
2020-04-09 17:34:54 +00:00
|
|
|
})
|
2020-01-29 22:39:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("creating block: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return api.SyncSubmitBlock(ctx, blk)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|