Update payment channel logic to exclude Proof from UpdateChannelStateParams
This commit is contained in:
parent
1cf51b956a
commit
9fcbaa72cc
@ -433,7 +433,7 @@ type FullNode interface {
|
|||||||
PaychVoucherCreate(context.Context, address.Address, types.BigInt, uint64) (*VoucherCreateResult, error)
|
PaychVoucherCreate(context.Context, address.Address, types.BigInt, uint64) (*VoucherCreateResult, error)
|
||||||
PaychVoucherAdd(context.Context, address.Address, *paych.SignedVoucher, []byte, types.BigInt) (types.BigInt, error)
|
PaychVoucherAdd(context.Context, address.Address, *paych.SignedVoucher, []byte, types.BigInt) (types.BigInt, error)
|
||||||
PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error)
|
PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error)
|
||||||
PaychVoucherSubmit(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (cid.Cid, error)
|
PaychVoucherSubmit(context.Context, address.Address, *paych.SignedVoucher, []byte) (cid.Cid, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileRef struct {
|
type FileRef struct {
|
||||||
|
@ -218,11 +218,11 @@ type FullNodeStruct struct {
|
|||||||
PaychNewPayment func(ctx context.Context, from, to address.Address, vouchers []api.VoucherSpec) (*api.PaymentInfo, error) `perm:"sign"`
|
PaychNewPayment func(ctx context.Context, from, to address.Address, vouchers []api.VoucherSpec) (*api.PaymentInfo, error) `perm:"sign"`
|
||||||
PaychVoucherCheck func(context.Context, *paych.SignedVoucher) error `perm:"read"`
|
PaychVoucherCheck func(context.Context, *paych.SignedVoucher) error `perm:"read"`
|
||||||
PaychVoucherCheckValid func(context.Context, address.Address, *paych.SignedVoucher) error `perm:"read"`
|
PaychVoucherCheckValid func(context.Context, address.Address, *paych.SignedVoucher) error `perm:"read"`
|
||||||
PaychVoucherCheckSpendable func(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error) `perm:"read"`
|
PaychVoucherCheckSpendable func(context.Context, address.Address, *paych.SignedVoucher, []byte) (bool, error) `perm:"read"`
|
||||||
PaychVoucherAdd func(context.Context, address.Address, *paych.SignedVoucher, []byte, types.BigInt) (types.BigInt, error) `perm:"write"`
|
PaychVoucherAdd func(context.Context, address.Address, *paych.SignedVoucher, []byte, types.BigInt) (types.BigInt, error) `perm:"write"`
|
||||||
PaychVoucherCreate func(context.Context, address.Address, big.Int, uint64) (*api.VoucherCreateResult, error) `perm:"sign"`
|
PaychVoucherCreate func(context.Context, address.Address, big.Int, uint64) (*api.VoucherCreateResult, error) `perm:"sign"`
|
||||||
PaychVoucherList func(context.Context, address.Address) ([]*paych.SignedVoucher, error) `perm:"write"`
|
PaychVoucherList func(context.Context, address.Address) ([]*paych.SignedVoucher, error) `perm:"write"`
|
||||||
PaychVoucherSubmit func(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (cid.Cid, error) `perm:"sign"`
|
PaychVoucherSubmit func(context.Context, address.Address, *paych.SignedVoucher, []byte) (cid.Cid, error) `perm:"sign"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -921,8 +921,8 @@ func (c *FullNodeStruct) PaychVoucherCheckValid(ctx context.Context, addr addres
|
|||||||
return c.Internal.PaychVoucherCheckValid(ctx, addr, sv)
|
return c.Internal.PaychVoucherCheckValid(ctx, addr, sv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) PaychVoucherCheckSpendable(ctx context.Context, addr address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) {
|
func (c *FullNodeStruct) PaychVoucherCheckSpendable(ctx context.Context, addr address.Address, sv *paych.SignedVoucher, secret []byte) (bool, error) {
|
||||||
return c.Internal.PaychVoucherCheckSpendable(ctx, addr, sv, secret, proof)
|
return c.Internal.PaychVoucherCheckSpendable(ctx, addr, sv, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) PaychVoucherAdd(ctx context.Context, addr address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {
|
func (c *FullNodeStruct) PaychVoucherAdd(ctx context.Context, addr address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {
|
||||||
@ -953,8 +953,8 @@ func (c *FullNodeStruct) PaychNewPayment(ctx context.Context, from, to address.A
|
|||||||
return c.Internal.PaychNewPayment(ctx, from, to, vouchers)
|
return c.Internal.PaychNewPayment(ctx, from, to, vouchers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
|
func (c *FullNodeStruct) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte) (cid.Cid, error) {
|
||||||
return c.Internal.PaychVoucherSubmit(ctx, ch, sv, secret, proof)
|
return c.Internal.PaychVoucherSubmit(ctx, ch, sv, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StorageMinerStruct
|
// StorageMinerStruct
|
||||||
|
@ -559,7 +559,7 @@ var paychVoucherSubmitCmd = &cli.Command{
|
|||||||
|
|
||||||
ctx := ReqContext(cctx)
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
mcid, err := api.PaychVoucherSubmit(ctx, ch, sv, nil, nil)
|
mcid, err := api.PaychVoucherSubmit(ctx, ch, sv, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -122,8 +122,8 @@ func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Addres
|
|||||||
return a.PaychMgr.CheckVoucherValid(ctx, ch, sv)
|
return a.PaychMgr.CheckVoucherValid(ctx, ch, sv)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) {
|
func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte) (bool, error) {
|
||||||
return a.PaychMgr.CheckVoucherSpendable(ctx, ch, sv, secret, proof)
|
return a.PaychMgr.CheckVoucherSpendable(ctx, ch, sv, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {
|
func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {
|
||||||
@ -155,6 +155,6 @@ func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
|
func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte) (cid.Cid, error) {
|
||||||
return a.PaychMgr.SubmitVoucher(ctx, ch, sv, secret, proof)
|
return a.PaychMgr.SubmitVoucher(ctx, ch, sv, secret)
|
||||||
}
|
}
|
||||||
|
@ -215,13 +215,13 @@ func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckVoucherSpendable checks if the given voucher is currently spendable
|
// CheckVoucherSpendable checks if the given voucher is currently spendable
|
||||||
func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) {
|
func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte) (bool, error) {
|
||||||
ca, err := pm.accessorByAddress(ch)
|
ca, err := pm.accessorByAddress(ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ca.checkVoucherSpendable(ctx, ch, sv, secret, proof)
|
return ca.checkVoucherSpendable(ctx, ch, sv, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddVoucherOutbound adds a voucher for an outbound channel.
|
// AddVoucherOutbound adds a voucher for an outbound channel.
|
||||||
@ -306,12 +306,12 @@ func (pm *Manager) trackInboundChannel(ctx context.Context, ch address.Address)
|
|||||||
return pm.store.TrackChannel(stateCi)
|
return pm.store.TrackChannel(stateCi)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
|
func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte) (cid.Cid, error) {
|
||||||
ca, err := pm.accessorByAddress(ch)
|
ca, err := pm.accessorByAddress(ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
return ca.submitVoucher(ctx, ch, sv, secret, proof)
|
return ca.submitVoucher(ctx, ch, sv, secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pm *Manager) AllocateLane(ch address.Address) (uint64, error) {
|
func (pm *Manager) AllocateLane(ch address.Address) (uint64, error) {
|
||||||
|
@ -235,7 +235,7 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add
|
|||||||
return laneStates, nil
|
return laneStates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) {
|
func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte) (bool, error) {
|
||||||
ca.lk.Lock()
|
ca.lk.Lock()
|
||||||
defer ca.lk.Unlock()
|
defer ca.lk.Unlock()
|
||||||
|
|
||||||
@ -258,26 +258,9 @@ func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If proof is needed and wasn't supplied as a parameter, get it from the
|
|
||||||
// datastore
|
|
||||||
if sv.Extra != nil && proof == nil {
|
|
||||||
vi, err := ci.infoForVoucher(sv)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if vi.Proof != nil {
|
|
||||||
log.Info("CheckVoucherSpendable: using stored proof")
|
|
||||||
proof = vi.Proof
|
|
||||||
} else {
|
|
||||||
log.Warn("CheckVoucherSpendable: nil proof for voucher with validation")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enc, err := actors.SerializeParams(&paych.UpdateChannelStateParams{
|
enc, err := actors.SerializeParams(&paych.UpdateChannelStateParams{
|
||||||
Sv: *sv,
|
Sv: *sv,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
Proof: proof,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -380,7 +363,7 @@ func (ca *channelAccessor) addVoucherUnlocked(ctx context.Context, ch address.Ad
|
|||||||
return delta, ca.store.putChannelInfo(ci)
|
return delta, ca.store.putChannelInfo(ci)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
|
func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte) (cid.Cid, error) {
|
||||||
ca.lk.Lock()
|
ca.lk.Lock()
|
||||||
defer ca.lk.Unlock()
|
defer ca.lk.Unlock()
|
||||||
|
|
||||||
@ -389,21 +372,6 @@ func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address
|
|||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If voucher needs proof, and none was supplied, check datastore for proof
|
|
||||||
if sv.Extra != nil && proof == nil {
|
|
||||||
vi, err := ci.infoForVoucher(sv)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if vi.Proof != nil {
|
|
||||||
log.Info("SubmitVoucher: using stored proof")
|
|
||||||
proof = vi.Proof
|
|
||||||
} else {
|
|
||||||
log.Warn("SubmitVoucher: nil proof for voucher with validation")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
has, err := ci.hasVoucher(sv)
|
has, err := ci.hasVoucher(sv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
@ -424,7 +392,6 @@ func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address
|
|||||||
enc, err := actors.SerializeParams(&paych.UpdateChannelStateParams{
|
enc, err := actors.SerializeParams(&paych.UpdateChannelStateParams{
|
||||||
Sv: *sv,
|
Sv: *sv,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
Proof: proof,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
@ -448,7 +415,6 @@ func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address
|
|||||||
// Add the voucher to the channel
|
// Add the voucher to the channel
|
||||||
ci.Vouchers = append(ci.Vouchers, &VoucherInfo{
|
ci.Vouchers = append(ci.Vouchers, &VoucherInfo{
|
||||||
Voucher: sv,
|
Voucher: sv,
|
||||||
Proof: proof,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ type API struct {
|
|||||||
type settlerAPI interface {
|
type settlerAPI interface {
|
||||||
PaychList(context.Context) ([]address.Address, error)
|
PaychList(context.Context) ([]address.Address, error)
|
||||||
PaychStatus(context.Context, address.Address) (*api.PaychStatus, error)
|
PaychStatus(context.Context, address.Address) (*api.PaychStatus, error)
|
||||||
PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error)
|
PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte) (bool, error)
|
||||||
PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error)
|
PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error)
|
||||||
PaychVoucherSubmit(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (cid.Cid, error)
|
PaychVoucherSubmit(context.Context, address.Address, *paych.SignedVoucher, []byte) (cid.Cid, error)
|
||||||
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error)
|
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ func (pcs *paymentChannelSettler) messageHandler(msg *types.Message, rec *types.
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(bestByLane))
|
wg.Add(len(bestByLane))
|
||||||
for _, voucher := range bestByLane {
|
for _, voucher := range bestByLane {
|
||||||
submitMessageCID, err := pcs.api.PaychVoucherSubmit(pcs.ctx, msg.To, voucher, nil, nil)
|
submitMessageCID, err := pcs.api.PaychVoucherSubmit(pcs.ctx, msg.To, voucher, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type BestSpendableAPI interface {
|
type BestSpendableAPI interface {
|
||||||
PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error)
|
PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error)
|
||||||
PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error)
|
PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BestSpendableByLane(ctx context.Context, api BestSpendableAPI, ch address.Address) (map[uint64]*paych.SignedVoucher, error) {
|
func BestSpendableByLane(ctx context.Context, api BestSpendableAPI, ch address.Address) (map[uint64]*paych.SignedVoucher, error) {
|
||||||
@ -20,7 +20,7 @@ func BestSpendableByLane(ctx context.Context, api BestSpendableAPI, ch address.A
|
|||||||
|
|
||||||
bestByLane := make(map[uint64]*paych.SignedVoucher)
|
bestByLane := make(map[uint64]*paych.SignedVoucher)
|
||||||
for _, voucher := range vouchers {
|
for _, voucher := range vouchers {
|
||||||
spendable, err := api.PaychVoucherCheckSpendable(ctx, ch, voucher, nil, nil)
|
spendable, err := api.PaychVoucherCheckSpendable(ctx, ch, voucher, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user