diff --git a/chain/actors/actor_paych_test.go b/chain/actors/actor_paych_test.go index 960bc3064..ccb14c7de 100644 --- a/chain/actors/actor_paych_test.go +++ b/chain/actors/actor_paych_test.go @@ -1,6 +1,7 @@ package actors_test import ( + "context" "testing" "github.com/filecoin-project/go-lotus/chain/actors" @@ -30,7 +31,7 @@ func signVoucher(t *testing.T, w *wallet.Wallet, addr address.Address, sv *types t.Fatal(err) } - sig, err := w.Sign(addr, vb) + sig, err := w.Sign(context.TODO(), addr, vb) if err != nil { t.Fatal(err) } diff --git a/chain/deals/client.go b/chain/deals/client.go index 5659ec755..1789d04c4 100644 --- a/chain/deals/client.go +++ b/chain/deals/client.go @@ -2,9 +2,10 @@ package deals import ( "context" - "github.com/filecoin-project/go-lotus/chain/actors" "math" + "github.com/filecoin-project/go-lotus/chain/actors" + sectorbuilder "github.com/filecoin-project/go-sectorbuilder" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" @@ -139,7 +140,7 @@ func (c *Client) sendProposal(s inet.Stream, proposal StorageDealProposal, from if err != nil { return err } - sig, err := c.w.Sign(from, msg) + sig, err := c.w.Sign(context.TODO(), from, msg) if err != nil { return err } diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 3a6c937d6..af3125ab8 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -178,16 +178,23 @@ func (cg *ChainGen) GenesisCar() ([]byte, error) { return out.Bytes(), nil } -func (cg *ChainGen) nextBlockProof() (address.Address, types.ElectionProof, []*types.Ticket, error) { - vrf := []byte("veee arrr efff") +func (cg *ChainGen) nextBlockProof(ctx context.Context) (address.Address, types.ElectionProof, []*types.Ticket, error) { - out, proof, err := vdf.Run(vrf) + ticks := cg.curBlock.Header.Tickets + lastTicket := ticks[len(ticks)-1] + + vrfout, err := ComputeVRF(ctx, cg.w.Sign, cg.mworker, lastTicket.VDFResult) + if err != nil { + return address.Undef, nil, nil, err + } + + out, proof, err := vdf.Run(vrfout) if err != nil { return address.Undef, nil, nil, err } tick := &types.Ticket{ - VRFProof: vrf, + VRFProof: vrfout, VDFProof: proof, VDFResult: out, } @@ -196,7 +203,7 @@ func (cg *ChainGen) nextBlockProof() (address.Address, types.ElectionProof, []*t } func (cg *ChainGen) NextBlock() (*types.FullBlock, []*types.SignedMessage, error) { - miner, proof, tickets, err := cg.nextBlockProof() + miner, proof, tickets, err := cg.nextBlockProof(context.TODO()) if err != nil { return nil, nil, err } @@ -224,7 +231,7 @@ func (cg *ChainGen) NextBlock() (*types.FullBlock, []*types.SignedMessage, error return nil, nil, err } - sig, err := cg.w.Sign(cg.banker, unsigned) + sig, err := cg.w.Sign(context.TODO(), cg.banker, unsigned) if err != nil { return nil, nil, err } diff --git a/chain/gen/utils.go b/chain/gen/utils.go index 3ca5b1521..e912d35a5 100644 --- a/chain/gen/utils.go +++ b/chain/gen/utils.go @@ -310,3 +310,19 @@ func MakeGenesisBlock(bs bstore.Blockstore, balances map[address.Address]types.B Genesis: b, }, nil } + +type SignFunc func(context.Context, address.Address, []byte) (*types.Signature, error) + +func ComputeVRF(ctx context.Context, sign SignFunc, w address.Address, input []byte) ([]byte, error) { + + sig, err := sign(ctx, w, input) + if err != nil { + return nil, err + } + + if sig.Type != types.KTBLS { + return nil, fmt.Errorf("miner worker address was not a BLS key") + } + + return sig.Data, nil +} diff --git a/chain/wallet/wallet.go b/chain/wallet/wallet.go index d012b1d14..1ef13845f 100644 --- a/chain/wallet/wallet.go +++ b/chain/wallet/wallet.go @@ -1,6 +1,7 @@ package wallet import ( + "context" "sort" "strings" @@ -33,7 +34,7 @@ func NewWallet(keystore types.KeyStore) (*Wallet, error) { return w, nil } -func (w *Wallet) Sign(addr address.Address, msg []byte) (*types.Signature, error) { +func (w *Wallet) Sign(ctx context.Context, addr address.Address, msg []byte) (*types.Signature, error) { ki, err := w.findKey(addr) if err != nil { return nil, err diff --git a/miner/miner.go b/miner/miner.go index 20d217f6a..92b666e17 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -3,7 +3,6 @@ package miner import ( "context" "crypto/sha256" - "fmt" "math/big" "time" @@ -15,6 +14,7 @@ import ( chain "github.com/filecoin-project/go-lotus/chain" "github.com/filecoin-project/go-lotus/chain/actors" "github.com/filecoin-project/go-lotus/chain/address" + "github.com/filecoin-project/go-lotus/chain/gen" "github.com/filecoin-project/go-lotus/chain/types" "github.com/filecoin-project/go-lotus/lib/vdf" ) @@ -154,16 +154,7 @@ func (m *Miner) computeVRF(ctx context.Context, input []byte) ([]byte, error) { return nil, err } - sig, err := m.api.WalletSign(ctx, w, input) - if err != nil { - return nil, err - } - - if sig.Type != types.KTBLS { - return nil, fmt.Errorf("miner worker address was not a BLS key") - } - - return sig.Data, nil + return gen.ComputeVRF(ctx, m.api.WalletSign, w, input) } func (m *Miner) getMinerWorker(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) { diff --git a/node/impl/full.go b/node/impl/full.go index 5fbd452c6..77c22a7c4 100644 --- a/node/impl/full.go +++ b/node/impl/full.go @@ -326,7 +326,7 @@ func (a *FullNodeAPI) WalletBalance(ctx context.Context, addr address.Address) ( } func (a *FullNodeAPI) WalletSign(ctx context.Context, k address.Address, msg []byte) (*types.Signature, error) { - return a.Wallet.Sign(k, msg) + return a.Wallet.Sign(ctx, k, msg) } func (a *FullNodeAPI) WalletSignMessage(ctx context.Context, k address.Address, msg *types.Message) (*types.SignedMessage, error) {