(mostly) proper ticket generation
This commit is contained in:
parent
5a7f59498e
commit
f7dc253669
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user