2019-07-25 22:15:33 +00:00
|
|
|
package gen
|
|
|
|
|
|
|
|
import (
|
2019-07-30 11:45:48 +00:00
|
|
|
"bytes"
|
2019-07-25 22:15:33 +00:00
|
|
|
"context"
|
2019-09-06 06:26:02 +00:00
|
|
|
"fmt"
|
2020-11-01 13:03:21 +00:00
|
|
|
"io"
|
2019-11-29 03:38:18 +00:00
|
|
|
"io/ioutil"
|
2019-07-30 13:20:40 +00:00
|
|
|
"sync/atomic"
|
2020-03-25 23:16:17 +00:00
|
|
|
"time"
|
2019-07-25 22:15:33 +00:00
|
|
|
|
2020-10-08 21:57:03 +00:00
|
|
|
"github.com/google/uuid"
|
2019-07-30 11:45:48 +00:00
|
|
|
"github.com/ipfs/go-blockservice"
|
2020-01-30 23:48:25 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2019-07-30 11:45:48 +00:00
|
|
|
offline "github.com/ipfs/go-ipfs-exchange-offline"
|
2020-02-23 20:00:47 +00:00
|
|
|
format "github.com/ipfs/go-ipld-format"
|
2020-01-30 23:48:25 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2019-07-30 11:45:48 +00:00
|
|
|
"github.com/ipfs/go-merkledag"
|
2020-05-05 01:31:56 +00:00
|
|
|
"github.com/ipld/go-car"
|
2020-03-26 19:34:38 +00:00
|
|
|
"golang.org/x/xerrors"
|
2019-07-30 11:45:48 +00:00
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
|
|
|
proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-01-29 20:01:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2020-09-23 19:24:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/policy"
|
2020-03-25 23:16:17 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/beacon"
|
2021-09-02 16:07:23 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
2020-02-11 20:48:03 +00:00
|
|
|
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/rand"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-01-30 23:48:25 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/vm"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/wallet"
|
2019-11-29 03:38:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
|
|
|
|
"github.com/filecoin-project/lotus/genesis"
|
2020-10-09 19:52:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/journal"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper"
|
2022-06-17 11:52:19 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2019-07-25 22:15:33 +00:00
|
|
|
)
|
|
|
|
|
2019-10-08 00:28:13 +00:00
|
|
|
const msgsPerBlock = 20
|
2019-07-30 13:20:40 +00:00
|
|
|
|
2020-08-20 04:49:10 +00:00
|
|
|
//nolint:deadcode,varcheck
|
|
|
|
var log = logging.Logger("gen")
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
var ValidWpostForTesting = []proof7.PoStProof{{
|
2020-06-16 01:02:53 +00:00
|
|
|
ProofBytes: []byte("valid proof"),
|
|
|
|
}}
|
|
|
|
|
2019-07-25 22:15:33 +00:00
|
|
|
type ChainGen struct {
|
|
|
|
msgsPerBlock int
|
|
|
|
|
|
|
|
bs blockstore.Blockstore
|
|
|
|
|
|
|
|
cs *store.ChainStore
|
|
|
|
|
2020-09-08 20:28:06 +00:00
|
|
|
beacon beacon.Schedule
|
2020-03-25 23:16:17 +00:00
|
|
|
|
2019-09-06 06:26:02 +00:00
|
|
|
sm *stmgr.StateManager
|
|
|
|
|
|
|
|
genesis *types.BlockHeader
|
2019-10-05 23:18:39 +00:00
|
|
|
CurTipset *store.FullTipSet
|
2019-07-25 22:15:33 +00:00
|
|
|
|
2020-02-08 02:18:32 +00:00
|
|
|
Timestamper func(*types.TipSet, abi.ChainEpoch) uint64
|
2019-10-10 03:04:10 +00:00
|
|
|
|
2020-01-31 23:51:15 +00:00
|
|
|
GetMessages func(*ChainGen) ([]*types.SignedMessage, error)
|
|
|
|
|
2020-09-04 20:17:28 +00:00
|
|
|
w *wallet.LocalWallet
|
2019-07-30 13:20:40 +00:00
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
eppProvs map[address.Address]WinningPoStProver
|
|
|
|
Miners []address.Address
|
|
|
|
receivers []address.Address
|
|
|
|
// a SecP address
|
2019-07-30 13:20:40 +00:00
|
|
|
banker address.Address
|
|
|
|
bankerNonce uint64
|
2019-07-29 19:34:09 +00:00
|
|
|
|
2019-07-30 11:45:48 +00:00
|
|
|
r repo.Repo
|
2019-07-29 19:34:09 +00:00
|
|
|
lr repo.LockedRepo
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 09:22:50 +00:00
|
|
|
var rootkeyMultisig = genesis.MultisigMeta{
|
2020-08-19 20:32:53 +00:00
|
|
|
Signers: []address.Address{remAccTestKey},
|
2020-07-24 09:22:50 +00:00
|
|
|
Threshold: 1,
|
|
|
|
VestingDuration: 0,
|
|
|
|
VestingStart: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
var DefaultVerifregRootkeyActor = genesis.Actor{
|
|
|
|
Type: genesis.TMultisig,
|
|
|
|
Balance: big.NewInt(0),
|
|
|
|
Meta: rootkeyMultisig.ActorMeta(),
|
|
|
|
}
|
|
|
|
|
2020-08-18 21:30:49 +00:00
|
|
|
var remAccTestKey, _ = address.NewFromString("t1ceb34gnsc6qk5dt6n7xg6ycwzasjhbxm3iylkiy")
|
2020-08-19 20:32:53 +00:00
|
|
|
var remAccMeta = genesis.MultisigMeta{
|
|
|
|
Signers: []address.Address{remAccTestKey},
|
|
|
|
Threshold: 1,
|
2020-08-18 21:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var DefaultRemainderAccountActor = genesis.Actor{
|
2020-08-19 20:32:53 +00:00
|
|
|
Type: genesis.TMultisig,
|
2020-08-18 21:30:49 +00:00
|
|
|
Balance: big.NewInt(0),
|
|
|
|
Meta: remAccMeta.ActorMeta(),
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeSchedule) (*ChainGen, error) {
|
2020-10-09 19:52:04 +00:00
|
|
|
j := journal.NilJournal()
|
2020-09-23 19:24:51 +00:00
|
|
|
// TODO: we really shouldn't modify a global variable here.
|
|
|
|
policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1)
|
2020-05-12 16:58:43 +00:00
|
|
|
|
2019-07-25 22:15:33 +00:00
|
|
|
mr := repo.NewMemory(nil)
|
2019-11-12 17:59:38 +00:00
|
|
|
lr, err := mr.Lock(repo.StorageMiner)
|
2019-07-25 22:15:33 +00:00
|
|
|
if err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("taking mem-repo lock failed: %w", err)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 10:25:34 +00:00
|
|
|
ds, err := lr.Datastore(context.TODO(), "/metadata")
|
2019-07-29 19:34:09 +00:00
|
|
|
if err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("failed to get metadata datastore: %w", err)
|
2019-07-29 19:34:09 +00:00
|
|
|
}
|
|
|
|
|
2021-02-28 22:48:36 +00:00
|
|
|
bs, err := lr.Blockstore(context.TODO(), repo.UniversalBlockstore)
|
2019-07-25 22:15:33 +00:00
|
|
|
if err != nil {
|
2020-11-01 13:03:21 +00:00
|
|
|
return nil, err
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
2019-07-29 19:34:09 +00:00
|
|
|
|
2020-11-01 13:03:21 +00:00
|
|
|
defer func() {
|
|
|
|
if c, ok := bs.(io.Closer); ok {
|
|
|
|
if err := c.Close(); err != nil {
|
|
|
|
log.Warnf("failed to close blockstore: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2019-07-25 22:15:33 +00:00
|
|
|
ks, err := lr.KeyStore()
|
|
|
|
if err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("getting repo keystore failed: %w", err)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w, err := wallet.NewWallet(ks)
|
|
|
|
if err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("creating memrepo wallet failed: %w", err)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-11 18:12:01 +00:00
|
|
|
banker, err := w.WalletNew(context.Background(), types.KTSecp256k1)
|
2019-07-25 22:15:33 +00:00
|
|
|
if err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("failed to generate banker key: %w", err)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 13:20:40 +00:00
|
|
|
receievers := make([]address.Address, msgsPerBlock)
|
|
|
|
for r := range receievers {
|
2020-10-11 18:12:01 +00:00
|
|
|
receievers[r], err = w.WalletNew(context.Background(), types.KTBLS)
|
2019-07-30 13:20:40 +00:00
|
|
|
if err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("failed to generate receiver key: %w", err)
|
2019-07-30 13:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
maddr1 := genesis2.MinerAddress(0)
|
2019-11-29 03:38:18 +00:00
|
|
|
|
|
|
|
m1temp, err := ioutil.TempDir("", "preseal")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-07-03 01:29:06 +00:00
|
|
|
genm1, k1, err := seed.PreSeal(maddr1, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, numSectors, m1temp, []byte("some randomness"), nil, true)
|
2019-11-29 03:38:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
maddr2 := genesis2.MinerAddress(1)
|
2019-11-29 04:04:46 +00:00
|
|
|
|
|
|
|
m2temp, err := ioutil.TempDir("", "preseal")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-07-03 01:29:06 +00:00
|
|
|
genm2, k2, err := seed.PreSeal(maddr2, abi.RegisteredSealProof_StackedDrg2KiBV1, 0, numSectors, m2temp, []byte("some randomness"), nil, true)
|
2019-11-29 04:04:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-09-04 20:17:28 +00:00
|
|
|
mk1, err := w.WalletImport(context.Background(), k1)
|
2019-11-29 04:41:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-04 20:17:28 +00:00
|
|
|
mk2, err := w.WalletImport(context.Background(), k2)
|
2019-11-29 04:41:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-02-18 07:15:30 +00:00
|
|
|
sys := vm.Syscalls(&genFakeVerifier{})
|
2020-02-12 21:41:59 +00:00
|
|
|
|
|
|
|
tpl := genesis.Template{
|
2021-05-15 01:11:23 +00:00
|
|
|
NetworkVersion: network.Version0,
|
2020-02-13 00:15:33 +00:00
|
|
|
Accounts: []genesis.Actor{
|
2020-02-12 21:41:59 +00:00
|
|
|
{
|
|
|
|
Type: genesis.TAccount,
|
2020-07-17 21:34:18 +00:00
|
|
|
Balance: types.FromFil(20_000_000),
|
2020-02-12 21:41:59 +00:00
|
|
|
Meta: (&genesis.AccountMeta{Owner: mk1}).ActorMeta(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: genesis.TAccount,
|
2020-07-17 21:34:18 +00:00
|
|
|
Balance: types.FromFil(20_000_000),
|
2020-02-12 21:41:59 +00:00
|
|
|
Meta: (&genesis.AccountMeta{Owner: mk2}).ActorMeta(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: genesis.TAccount,
|
|
|
|
Balance: types.FromFil(50000),
|
|
|
|
Meta: (&genesis.AccountMeta{Owner: banker}).ActorMeta(),
|
|
|
|
},
|
|
|
|
},
|
2020-02-13 00:15:33 +00:00
|
|
|
Miners: []genesis.Miner{
|
2020-02-12 21:41:59 +00:00
|
|
|
*genm1,
|
|
|
|
*genm2,
|
2019-11-29 03:38:18 +00:00
|
|
|
},
|
2020-08-18 21:30:49 +00:00
|
|
|
VerifregRootKey: DefaultVerifregRootkeyActor,
|
|
|
|
RemainderAccount: DefaultRemainderAccountActor,
|
2020-10-08 21:57:03 +00:00
|
|
|
NetworkName: uuid.New().String(),
|
2020-08-18 21:30:49 +00:00
|
|
|
Timestamp: uint64(build.Clock.Now().Add(-500 * time.Duration(build.BlockDelaySecs) * time.Second).Unix()),
|
2019-09-06 20:03:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 19:52:04 +00:00
|
|
|
genb, err := genesis2.MakeGenesisBlock(context.TODO(), j, bs, sys, tpl)
|
2019-07-25 22:15:33 +00:00
|
|
|
if err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("make genesis block failed: %w", err)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
cs := store.NewChainStore(bs, bs, ds, filcns.Weight, j)
|
2019-07-25 22:15:33 +00:00
|
|
|
|
|
|
|
genfb := &types.FullBlock{Header: genb.Genesis}
|
2019-09-06 06:26:02 +00:00
|
|
|
gents := store.NewFullTipSet([]*types.FullBlock{genfb})
|
2019-07-25 22:15:33 +00:00
|
|
|
|
2021-12-11 21:03:00 +00:00
|
|
|
if err := cs.SetGenesis(context.TODO(), genb.Genesis); err != nil {
|
2019-08-15 18:45:32 +00:00
|
|
|
return nil, xerrors.Errorf("set genesis failed: %w", err)
|
2019-07-26 12:19:27 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:07:18 +00:00
|
|
|
mgen := make(map[address.Address]WinningPoStProver)
|
2020-02-12 21:41:59 +00:00
|
|
|
for i := range tpl.Miners {
|
2020-04-10 21:07:18 +00:00
|
|
|
mgen[genesis2.MinerAddress(uint64(i))] = &wppProvider{}
|
2019-11-21 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 21:41:59 +00:00
|
|
|
miners := []address.Address{maddr1, maddr2}
|
|
|
|
|
2020-09-08 20:28:06 +00:00
|
|
|
beac := beacon.Schedule{{Start: 0, Beacon: beacon.NewMockBeacon(time.Second)}}
|
2020-06-30 13:22:48 +00:00
|
|
|
//beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelaySecs)
|
2020-05-22 14:07:38 +00:00
|
|
|
//if err != nil {
|
|
|
|
//return nil, xerrors.Errorf("creating drand beacon: %w", err)
|
|
|
|
//}
|
2020-03-25 23:16:17 +00:00
|
|
|
|
2021-09-18 17:57:04 +00:00
|
|
|
sm, err := stmgr.NewStateManager(cs, filcns.NewTipSetExecutor(), sys, us, beac)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("initing stmgr: %w", err)
|
|
|
|
}
|
|
|
|
|
2019-07-25 22:15:33 +00:00
|
|
|
gen := &ChainGen{
|
|
|
|
bs: bs,
|
|
|
|
cs: cs,
|
2019-09-06 06:26:02 +00:00
|
|
|
sm: sm,
|
2019-07-25 22:15:33 +00:00
|
|
|
msgsPerBlock: msgsPerBlock,
|
|
|
|
genesis: genb.Genesis,
|
2020-03-25 23:16:17 +00:00
|
|
|
beacon: beac,
|
2019-07-30 13:20:40 +00:00
|
|
|
w: w,
|
|
|
|
|
2020-01-31 23:51:15 +00:00
|
|
|
GetMessages: getRandomMessages,
|
2020-02-12 21:41:59 +00:00
|
|
|
Miners: miners,
|
2020-01-31 23:51:15 +00:00
|
|
|
eppProvs: mgen,
|
|
|
|
banker: banker,
|
|
|
|
receivers: receievers,
|
2019-07-30 13:20:40 +00:00
|
|
|
|
2019-10-05 23:18:39 +00:00
|
|
|
CurTipset: gents,
|
2019-07-29 19:34:09 +00:00
|
|
|
|
2019-07-30 11:45:48 +00:00
|
|
|
r: mr,
|
2019-07-29 19:34:09 +00:00
|
|
|
lr: lr,
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gen, nil
|
|
|
|
}
|
|
|
|
|
2020-05-01 00:54:41 +00:00
|
|
|
func NewGenerator() (*ChainGen, error) {
|
|
|
|
return NewGeneratorWithSectors(1)
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
|
2021-09-02 16:07:23 +00:00
|
|
|
return NewGeneratorWithSectorsAndUpgradeSchedule(numSectors, filcns.DefaultUpgradeSchedule())
|
2021-05-26 23:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewGeneratorWithUpgradeSchedule(us stmgr.UpgradeSchedule) (*ChainGen, error) {
|
|
|
|
return NewGeneratorWithSectorsAndUpgradeSchedule(1, us)
|
|
|
|
}
|
|
|
|
|
2021-10-06 03:34:33 +00:00
|
|
|
func (cg *ChainGen) Blockstore() blockstore.Blockstore {
|
|
|
|
return cg.bs
|
|
|
|
}
|
|
|
|
|
2020-08-09 00:20:37 +00:00
|
|
|
func (cg *ChainGen) StateManager() *stmgr.StateManager {
|
|
|
|
return cg.sm
|
|
|
|
}
|
|
|
|
|
2020-01-31 23:51:15 +00:00
|
|
|
func (cg *ChainGen) SetStateManager(sm *stmgr.StateManager) {
|
|
|
|
cg.sm = sm
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cg *ChainGen) ChainStore() *store.ChainStore {
|
|
|
|
return cg.cs
|
|
|
|
}
|
|
|
|
|
2021-09-18 17:57:04 +00:00
|
|
|
func (cg *ChainGen) BeaconSchedule() beacon.Schedule {
|
|
|
|
return cg.beacon
|
|
|
|
}
|
|
|
|
|
2019-07-25 22:15:33 +00:00
|
|
|
func (cg *ChainGen) Genesis() *types.BlockHeader {
|
|
|
|
return cg.genesis
|
|
|
|
}
|
|
|
|
|
2019-07-30 11:45:48 +00:00
|
|
|
func (cg *ChainGen) GenesisCar() ([]byte, error) {
|
|
|
|
offl := offline.Exchange(cg.bs)
|
|
|
|
blkserv := blockservice.New(cg.bs, offl)
|
|
|
|
dserv := merkledag.NewDAGService(blkserv)
|
|
|
|
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
|
2020-02-21 19:27:29 +00:00
|
|
|
if err := car.WriteCarWithWalker(context.TODO(), dserv, []cid.Cid{cg.Genesis().Cid()}, out, CarWalkFunc); err != nil {
|
2019-11-21 22:21:45 +00:00
|
|
|
return nil, xerrors.Errorf("genesis car write car failed: %w", err)
|
2019-07-30 11:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return out.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
2020-02-21 19:27:29 +00:00
|
|
|
func CarWalkFunc(nd format.Node) (out []*format.Link, err error) {
|
|
|
|
for _, link := range nd.Links() {
|
2020-08-18 01:54:49 +00:00
|
|
|
pref := link.Cid.Prefix()
|
|
|
|
if pref.Codec == cid.FilCommitmentSealed || pref.Codec == cid.FilCommitmentUnsealed {
|
2020-02-21 19:27:29 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
out = append(out, link)
|
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:06:41 +00:00
|
|
|
func (cg *ChainGen) nextBlockProof(ctx context.Context, pts *types.TipSet, m address.Address, round abi.ChainEpoch) ([]types.BeaconEntry, *types.ElectionProof, *types.Ticket, error) {
|
2020-04-30 22:11:14 +00:00
|
|
|
mc := &mca{w: cg.w, sm: cg.sm, pv: ffiwrapper.ProofVerifier, bcn: cg.beacon}
|
2020-04-09 17:13:09 +00:00
|
|
|
|
2020-04-17 23:36:54 +00:00
|
|
|
mbi, err := mc.MinerGetBaseInfo(ctx, m, round, pts.Key())
|
2020-04-08 16:31:16 +00:00
|
|
|
if err != nil {
|
2020-04-09 17:13:09 +00:00
|
|
|
return nil, nil, nil, xerrors.Errorf("get miner base info: %w", err)
|
2020-04-08 16:31:16 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 12:05:01 +00:00
|
|
|
entries := mbi.BeaconEntries
|
|
|
|
rbase := mbi.PrevBeaconEntry
|
2020-04-08 16:31:16 +00:00
|
|
|
if len(entries) > 0 {
|
|
|
|
rbase = entries[len(entries)-1]
|
|
|
|
}
|
|
|
|
|
2020-04-09 17:13:09 +00:00
|
|
|
eproof, err := IsRoundWinner(ctx, pts, round, m, rbase, mbi, mc)
|
2020-04-08 19:06:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, xerrors.Errorf("checking round winner failed: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-03-19 02:42:24 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
if err := m.MarshalCBOR(buf); err != nil {
|
2020-04-08 19:06:41 +00:00
|
|
|
return nil, nil, nil, xerrors.Errorf("failed to cbor marshal address: %w", err)
|
2020-03-19 02:42:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 03:06:23 +00:00
|
|
|
if round > build.UpgradeSmokeHeight {
|
|
|
|
buf.Write(pts.MinTicket().VRFProof)
|
|
|
|
}
|
2020-04-29 22:25:48 +00:00
|
|
|
|
2021-09-18 17:57:04 +00:00
|
|
|
ticketRand, err := rand.DrawRandomness(rbase.Data, crypto.DomainSeparationTag_TicketProduction, round-build.TicketRandomnessLookback, buf.Bytes())
|
2020-02-23 20:00:47 +00:00
|
|
|
if err != nil {
|
2020-04-08 19:06:41 +00:00
|
|
|
return nil, nil, nil, err
|
2020-02-23 20:00:47 +00:00
|
|
|
}
|
2019-09-06 06:26:02 +00:00
|
|
|
|
2019-10-06 03:32:56 +00:00
|
|
|
st := pts.ParentState()
|
2019-08-16 00:17:09 +00:00
|
|
|
|
2019-10-23 17:39:14 +00:00
|
|
|
worker, err := stmgr.GetMinerWorkerRaw(ctx, cg.sm, st, m)
|
2019-09-06 06:26:02 +00:00
|
|
|
if err != nil {
|
2020-04-08 19:06:41 +00:00
|
|
|
return nil, nil, nil, xerrors.Errorf("get miner worker: %w", err)
|
2019-09-06 06:26:02 +00:00
|
|
|
}
|
2019-08-16 04:40:59 +00:00
|
|
|
|
2020-10-08 23:27:38 +00:00
|
|
|
sf := func(ctx context.Context, a address.Address, i []byte) (*crypto.Signature, error) {
|
|
|
|
return cg.w.WalletSign(ctx, a, i, api.MsgMeta{
|
2020-10-08 23:27:49 +00:00
|
|
|
Type: api.MTUnknown,
|
2020-10-08 23:27:38 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
vrfout, err := ComputeVRF(ctx, sf, worker, ticketRand)
|
2019-08-16 00:17:09 +00:00
|
|
|
if err != nil {
|
2020-04-08 19:06:41 +00:00
|
|
|
return nil, nil, nil, xerrors.Errorf("compute VRF: %w", err)
|
2019-08-15 02:30:21 +00:00
|
|
|
}
|
2019-08-16 00:17:09 +00:00
|
|
|
|
2020-04-08 19:06:41 +00:00
|
|
|
return entries, eproof, &types.Ticket{VRFProof: vrfout}, nil
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 04:36:07 +00:00
|
|
|
type MinedTipSet struct {
|
|
|
|
TipSet *store.FullTipSet
|
|
|
|
Messages []*types.SignedMessage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cg *ChainGen) NextTipSet() (*MinedTipSet, error) {
|
2021-09-18 17:57:04 +00:00
|
|
|
return cg.NextTipSetWithNulls(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cg *ChainGen) NextTipSetWithNulls(nulls abi.ChainEpoch) (*MinedTipSet, error) {
|
|
|
|
mts, err := cg.NextTipSetFromMiners(cg.CurTipset.TipSet(), cg.Miners, nulls)
|
2019-10-05 16:04:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return mts, nil
|
|
|
|
}
|
|
|
|
|
2020-07-22 19:12:41 +00:00
|
|
|
func (cg *ChainGen) SetWinningPoStProver(m address.Address, wpp WinningPoStProver) {
|
|
|
|
cg.eppProvs[m] = wpp
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
func (cg *ChainGen) NextTipSetFromMiners(base *types.TipSet, miners []address.Address, nulls abi.ChainEpoch) (*MinedTipSet, error) {
|
2020-08-09 00:20:37 +00:00
|
|
|
ms, err := cg.GetMessages(cg)
|
2019-07-25 22:15:33 +00:00
|
|
|
if err != nil {
|
2019-10-16 07:07:16 +00:00
|
|
|
return nil, xerrors.Errorf("get random messages: %w", err)
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-09 00:20:37 +00:00
|
|
|
msgs := make([][]*types.SignedMessage, len(miners))
|
|
|
|
for i := range msgs {
|
|
|
|
msgs[i] = ms
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
fts, err := cg.NextTipSetFromMinersWithMessagesAndNulls(base, miners, msgs, nulls)
|
2020-08-09 00:20:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
cg.CurTipset = fts
|
|
|
|
|
2020-08-09 00:20:37 +00:00
|
|
|
return &MinedTipSet{
|
|
|
|
TipSet: fts,
|
|
|
|
Messages: ms,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
func (cg *ChainGen) NextTipSetFromMinersWithMessagesAndNulls(base *types.TipSet, miners []address.Address, msgs [][]*types.SignedMessage, nulls abi.ChainEpoch) (*store.FullTipSet, error) {
|
2020-08-09 00:20:37 +00:00
|
|
|
var blks []*types.FullBlock
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
for round := base.Height() + nulls + 1; len(blks) == 0; round++ {
|
2020-08-09 00:20:37 +00:00
|
|
|
for mi, m := range miners {
|
2020-04-08 19:06:41 +00:00
|
|
|
bvals, et, ticket, err := cg.nextBlockProof(context.TODO(), base, m, round)
|
2019-09-06 06:26:02 +00:00
|
|
|
if err != nil {
|
2019-10-02 20:27:41 +00:00
|
|
|
return nil, xerrors.Errorf("next block proof: %w", err)
|
2019-09-06 06:26:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 19:06:41 +00:00
|
|
|
if et != nil {
|
2020-04-17 20:44:13 +00:00
|
|
|
// TODO: maybe think about passing in more real parameters to this?
|
2021-12-08 17:11:19 +00:00
|
|
|
wpost, err := cg.eppProvs[m].ComputeProof(context.TODO(), nil, nil, round, network.Version0)
|
2020-04-17 20:44:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-08-09 00:20:37 +00:00
|
|
|
fblk, err := cg.makeBlock(base, m, ticket, et, bvals, round, wpost, msgs[mi])
|
2019-09-06 06:26:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("making a block for next tipset failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
blks = append(blks, fblk)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 02:45:02 +00:00
|
|
|
fts := store.NewFullTipSet(blks)
|
|
|
|
if err := cg.cs.PutTipSet(context.TODO(), fts.TipSet()); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:03:46 +00:00
|
|
|
cg.CurTipset = fts
|
|
|
|
|
2021-01-27 02:45:02 +00:00
|
|
|
return fts, nil
|
2019-09-06 06:26:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 19:06:41 +00:00
|
|
|
func (cg *ChainGen) makeBlock(parents *types.TipSet, m address.Address, vrfticket *types.Ticket,
|
|
|
|
eticket *types.ElectionProof, bvals []types.BeaconEntry, height abi.ChainEpoch,
|
2022-04-20 21:34:28 +00:00
|
|
|
wpost []proof7.PoStProof, msgs []*types.SignedMessage) (*types.FullBlock, error) {
|
2019-09-06 06:26:02 +00:00
|
|
|
|
2019-10-10 03:04:10 +00:00
|
|
|
var ts uint64
|
|
|
|
if cg.Timestamper != nil {
|
2019-11-19 15:53:00 +00:00
|
|
|
ts = cg.Timestamper(parents, height-parents.Height())
|
2019-10-10 03:04:10 +00:00
|
|
|
} else {
|
2020-06-30 21:56:13 +00:00
|
|
|
ts = parents.MinTimestamp() + uint64(height-parents.Height())*build.BlockDelaySecs
|
2019-10-10 03:04:10 +00:00
|
|
|
}
|
2019-09-06 06:26:02 +00:00
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
fblk, err := filcns.NewFilecoinExpectedConsensus(cg.sm, nil, nil, nil).CreateBlock(context.TODO(), cg.w, &api.BlockTemplate{
|
2020-04-17 20:44:13 +00:00
|
|
|
Miner: m,
|
|
|
|
Parents: parents.Key(),
|
|
|
|
Ticket: vrfticket,
|
|
|
|
Eproof: eticket,
|
|
|
|
BeaconValues: bvals,
|
|
|
|
Messages: msgs,
|
|
|
|
Epoch: height,
|
|
|
|
Timestamp: ts,
|
|
|
|
WinningPoStProof: wpost,
|
2020-04-09 00:24:10 +00:00
|
|
|
})
|
2019-09-06 06:26:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return fblk, err
|
|
|
|
}
|
|
|
|
|
2020-06-02 14:29:39 +00:00
|
|
|
// ResyncBankerNonce is used for dealing with messages made when
|
2019-10-06 00:51:48 +00:00
|
|
|
// simulating forks
|
|
|
|
func (cg *ChainGen) ResyncBankerNonce(ts *types.TipSet) error {
|
2020-09-17 07:32:10 +00:00
|
|
|
st, err := cg.sm.ParentState(ts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
act, err := st.GetActor(cg.banker)
|
2019-10-06 00:51:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
cg.bankerNonce = act.Nonce
|
2020-09-17 07:32:10 +00:00
|
|
|
|
2019-10-06 00:51:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-31 23:51:15 +00:00
|
|
|
func (cg *ChainGen) Banker() address.Address {
|
|
|
|
return cg.banker
|
|
|
|
}
|
|
|
|
|
2020-09-04 20:17:28 +00:00
|
|
|
func (cg *ChainGen) Wallet() *wallet.LocalWallet {
|
2020-01-31 23:51:15 +00:00
|
|
|
return cg.w
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRandomMessages(cg *ChainGen) ([]*types.SignedMessage, error) {
|
2019-07-30 13:20:40 +00:00
|
|
|
msgs := make([]*types.SignedMessage, cg.msgsPerBlock)
|
|
|
|
for m := range msgs {
|
|
|
|
msg := types.Message{
|
2019-08-30 07:05:21 +00:00
|
|
|
To: cg.receivers[m%len(cg.receivers)],
|
2019-07-30 13:20:40 +00:00
|
|
|
From: cg.banker,
|
|
|
|
|
|
|
|
Nonce: atomic.AddUint64(&cg.bankerNonce, 1) - 1,
|
|
|
|
|
|
|
|
Value: types.NewInt(uint64(m + 1)),
|
|
|
|
|
|
|
|
Method: 0,
|
|
|
|
|
2020-08-06 21:08:42 +00:00
|
|
|
GasLimit: 100_000_000,
|
|
|
|
GasFeeCap: types.NewInt(0),
|
|
|
|
GasPremium: types.NewInt(0),
|
2019-07-30 13:20:40 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 23:27:38 +00:00
|
|
|
sig, err := cg.w.WalletSign(context.TODO(), cg.banker, msg.Cid().Bytes(), api.MsgMeta{
|
2020-10-08 23:27:49 +00:00
|
|
|
Type: api.MTUnknown, // testing
|
2020-10-08 23:27:38 +00:00
|
|
|
})
|
2019-07-30 13:20:40 +00:00
|
|
|
if err != nil {
|
2019-09-03 04:36:07 +00:00
|
|
|
return nil, err
|
2019-07-30 13:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msgs[m] = &types.SignedMessage{
|
|
|
|
Message: msg,
|
|
|
|
Signature: *sig,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 06:26:02 +00:00
|
|
|
return msgs, nil
|
2019-07-25 22:15:33 +00:00
|
|
|
}
|
2019-07-29 19:34:09 +00:00
|
|
|
|
|
|
|
func (cg *ChainGen) YieldRepo() (repo.Repo, error) {
|
|
|
|
if err := cg.lr.Close(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return cg.r, nil
|
|
|
|
}
|
2019-09-03 04:36:07 +00:00
|
|
|
|
|
|
|
type MiningCheckAPI interface {
|
2021-09-12 02:24:53 +00:00
|
|
|
StateGetRandomnessFromBeacon(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error)
|
|
|
|
StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error)
|
2019-09-03 04:36:07 +00:00
|
|
|
|
2020-04-17 23:36:54 +00:00
|
|
|
MinerGetBaseInfo(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*api.MiningBaseInfo, error)
|
2019-11-25 04:45:13 +00:00
|
|
|
|
2020-02-12 23:52:36 +00:00
|
|
|
WalletSign(context.Context, address.Address, []byte) (*crypto.Signature, error)
|
2019-09-03 04:36:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 06:26:02 +00:00
|
|
|
type mca struct {
|
2020-09-04 20:17:28 +00:00
|
|
|
w *wallet.LocalWallet
|
2020-04-30 22:11:14 +00:00
|
|
|
sm *stmgr.StateManager
|
2022-06-17 11:52:19 +00:00
|
|
|
pv storiface.Verifier
|
2020-09-08 20:28:06 +00:00
|
|
|
bcn beacon.Schedule
|
2019-09-06 06:26:02 +00:00
|
|
|
}
|
|
|
|
|
2021-09-12 02:24:53 +00:00
|
|
|
func (mca mca) StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) {
|
2021-09-18 17:57:04 +00:00
|
|
|
return mca.sm.GetRandomnessFromTickets(ctx, personalization, randEpoch, entropy, tsk)
|
2019-09-06 06:26:02 +00:00
|
|
|
}
|
|
|
|
|
2021-09-12 02:24:53 +00:00
|
|
|
func (mca mca) StateGetRandomnessFromBeacon(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) {
|
2021-09-18 17:57:04 +00:00
|
|
|
return mca.sm.GetRandomnessFromBeacon(ctx, personalization, randEpoch, entropy, tsk)
|
2020-08-11 23:58:35 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 23:36:54 +00:00
|
|
|
func (mca mca) MinerGetBaseInfo(ctx context.Context, maddr address.Address, epoch abi.ChainEpoch, tsk types.TipSetKey) (*api.MiningBaseInfo, error) {
|
2020-04-30 22:11:14 +00:00
|
|
|
return stmgr.MinerGetBaseInfo(ctx, mca.sm, mca.bcn, tsk, epoch, maddr, mca.pv)
|
2019-11-25 04:45:13 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 23:52:36 +00:00
|
|
|
func (mca mca) WalletSign(ctx context.Context, a address.Address, v []byte) (*crypto.Signature, error) {
|
2020-10-08 23:27:38 +00:00
|
|
|
return mca.w.WalletSign(ctx, a, v, api.MsgMeta{
|
2020-10-08 23:27:49 +00:00
|
|
|
Type: api.MTUnknown,
|
2020-10-08 23:27:38 +00:00
|
|
|
})
|
2019-09-06 06:26:02 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:07:18 +00:00
|
|
|
type WinningPoStProver interface {
|
|
|
|
GenerateCandidates(context.Context, abi.PoStRandomness, uint64) ([]uint64, error)
|
2022-04-20 21:34:28 +00:00
|
|
|
ComputeProof(context.Context, []proof7.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]proof7.PoStProof, error)
|
2019-11-21 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:07:18 +00:00
|
|
|
type wppProvider struct{}
|
2019-11-21 22:21:45 +00:00
|
|
|
|
2020-04-10 21:07:18 +00:00
|
|
|
func (wpp *wppProvider) GenerateCandidates(ctx context.Context, _ abi.PoStRandomness, _ uint64) ([]uint64, error) {
|
|
|
|
return []uint64{0}, nil
|
2019-11-21 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (wpp *wppProvider) ComputeProof(context.Context, []proof7.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]proof7.PoStProof, error) {
|
2020-06-16 01:02:53 +00:00
|
|
|
return ValidWpostForTesting, nil
|
2019-11-21 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 15:11:42 +00:00
|
|
|
func IsRoundWinner(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch,
|
2020-04-09 17:13:09 +00:00
|
|
|
miner address.Address, brand types.BeaconEntry, mbi *api.MiningBaseInfo, a MiningCheckAPI) (*types.ElectionProof, error) {
|
2020-04-07 18:23:16 +00:00
|
|
|
|
2020-04-08 15:11:42 +00:00
|
|
|
buf := new(bytes.Buffer)
|
2020-03-19 02:42:24 +00:00
|
|
|
if err := miner.MarshalCBOR(buf); err != nil {
|
2020-08-20 04:49:10 +00:00
|
|
|
return nil, xerrors.Errorf("failed to cbor marshal address: %w", err)
|
2020-03-19 02:42:24 +00:00
|
|
|
}
|
2020-04-07 18:23:16 +00:00
|
|
|
|
2021-09-18 17:57:04 +00:00
|
|
|
electionRand, err := rand.DrawRandomness(brand.Data, crypto.DomainSeparationTag_ElectionProofProduction, round, buf.Bytes())
|
2019-09-03 04:36:07 +00:00
|
|
|
if err != nil {
|
2020-04-08 19:06:41 +00:00
|
|
|
return nil, xerrors.Errorf("failed to draw randomness: %w", err)
|
2019-09-03 04:36:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 17:17:56 +00:00
|
|
|
vrfout, err := ComputeVRF(ctx, a.WalletSign, mbi.WorkerKey, electionRand)
|
2019-09-03 04:36:07 +00:00
|
|
|
if err != nil {
|
2020-04-08 19:06:41 +00:00
|
|
|
return nil, xerrors.Errorf("failed to compute VRF: %w", err)
|
2019-09-03 04:36:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 14:59:44 +00:00
|
|
|
ep := &types.ElectionProof{VRFProof: vrfout}
|
|
|
|
j := ep.ComputeWinCount(mbi.MinerPower, mbi.NetworkPower)
|
|
|
|
ep.WinCount = j
|
|
|
|
if j < 1 {
|
2020-04-08 19:06:41 +00:00
|
|
|
return nil, nil
|
2020-04-08 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 14:59:44 +00:00
|
|
|
return ep, nil
|
2019-12-03 18:25:56 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 23:52:36 +00:00
|
|
|
type SignFunc func(context.Context, address.Address, []byte) (*crypto.Signature, error)
|
2019-09-03 04:36:07 +00:00
|
|
|
|
2020-02-23 20:00:47 +00:00
|
|
|
func ComputeVRF(ctx context.Context, sign SignFunc, worker address.Address, sigInput []byte) ([]byte, error) {
|
2019-11-21 22:21:45 +00:00
|
|
|
sig, err := sign(ctx, worker, sigInput)
|
2019-09-06 06:26:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-03 04:36:07 +00:00
|
|
|
|
2020-02-12 23:52:36 +00:00
|
|
|
if sig.Type != crypto.SigTypeBLS {
|
2019-09-06 06:26:02 +00:00
|
|
|
return nil, fmt.Errorf("miner worker address was not a BLS key")
|
|
|
|
}
|
2019-09-03 04:36:07 +00:00
|
|
|
|
2019-09-06 06:26:02 +00:00
|
|
|
return sig.Data, nil
|
2019-09-03 04:36:07 +00:00
|
|
|
}
|
2020-02-18 07:15:30 +00:00
|
|
|
|
|
|
|
type genFakeVerifier struct{}
|
|
|
|
|
2022-06-17 11:52:19 +00:00
|
|
|
var _ storiface.Verifier = (*genFakeVerifier)(nil)
|
2020-02-18 07:15:30 +00:00
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (m genFakeVerifier) VerifySeal(svi proof7.SealVerifyInfo) (bool, error) {
|
2020-02-18 07:15:30 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (m genFakeVerifier) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) (bool, error) {
|
2020-04-17 14:47:19 +00:00
|
|
|
panic("not supported")
|
2020-04-10 21:07:18 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 15:59:29 +00:00
|
|
|
func (m genFakeVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) {
|
|
|
|
panic("not supported")
|
|
|
|
}
|
|
|
|
|
2022-01-11 16:53:14 +00:00
|
|
|
func (m genFakeVerifier) VerifyWinningPoSt(ctx context.Context, info proof7.WinningPoStVerifyInfo) (bool, error) {
|
2021-03-10 15:16:44 +00:00
|
|
|
panic("not supported")
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
func (m genFakeVerifier) VerifyWindowPoSt(ctx context.Context, info proof7.WindowPoStVerifyInfo) (bool, error) {
|
2020-04-17 14:47:19 +00:00
|
|
|
panic("not supported")
|
|
|
|
}
|
|
|
|
|
2020-06-15 16:30:49 +00:00
|
|
|
func (m genFakeVerifier) GenerateWinningPoStSectorChallenge(ctx context.Context, proof abi.RegisteredPoStProof, id abi.ActorID, randomness abi.PoStRandomness, u uint64) ([]uint64, error) {
|
2020-04-17 14:47:19 +00:00
|
|
|
panic("not supported")
|
2020-02-18 07:15:30 +00:00
|
|
|
}
|