paych: Lanes are back to u64

This commit is contained in:
Łukasz Magiera 2020-02-21 18:26:44 +01:00
parent c744dc06c6
commit 104871d6c9
10 changed files with 27 additions and 24 deletions

View File

@ -140,7 +140,7 @@ type FullNode interface {
PaychList(context.Context) ([]address.Address, error) PaychList(context.Context) ([]address.Address, error)
PaychStatus(context.Context, address.Address) (*PaychStatus, error) PaychStatus(context.Context, address.Address) (*PaychStatus, error)
PaychClose(context.Context, address.Address) (cid.Cid, error) PaychClose(context.Context, address.Address) (cid.Cid, error)
PaychAllocateLane(ctx context.Context, ch address.Address) (int64, error) PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error)
PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []VoucherSpec) (*PaymentInfo, error) PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []VoucherSpec) (*PaymentInfo, error)
PaychVoucherCheckValid(context.Context, address.Address, *types.SignedVoucher) error PaychVoucherCheckValid(context.Context, address.Address, *types.SignedVoucher) error
PaychVoucherCheckSpendable(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error) PaychVoucherCheckSpendable(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error)

View File

@ -132,7 +132,7 @@ type FullNodeStruct struct {
PaychList func(context.Context) ([]address.Address, error) `perm:"read"` PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
PaychStatus func(context.Context, address.Address) (*api.PaychStatus, error) `perm:"read"` PaychStatus func(context.Context, address.Address) (*api.PaychStatus, error) `perm:"read"`
PaychClose func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"` PaychClose func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"`
PaychAllocateLane func(context.Context, address.Address) (int64, error) `perm:"sign"` PaychAllocateLane func(context.Context, address.Address) (uint64, error) `perm:"sign"`
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, *types.SignedVoucher) error `perm:"read"` PaychVoucherCheck func(context.Context, *types.SignedVoucher) error `perm:"read"`
PaychVoucherCheckValid func(context.Context, address.Address, *types.SignedVoucher) error `perm:"read"` PaychVoucherCheckValid func(context.Context, address.Address, *types.SignedVoucher) error `perm:"read"`
@ -537,7 +537,7 @@ func (c *FullNodeStruct) PaychClose(ctx context.Context, a address.Address) (cid
return c.Internal.PaychClose(ctx, a) return c.Internal.PaychClose(ctx, a)
} }
func (c *FullNodeStruct) PaychAllocateLane(ctx context.Context, ch address.Address) (int64, error) { func (c *FullNodeStruct) PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error) {
return c.Internal.PaychAllocateLane(ctx, ch) return c.Internal.PaychAllocateLane(ctx, ch)
} }

2
go.mod
View File

@ -19,7 +19,7 @@ require (
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
github.com/filecoin-project/go-fil-markets v0.0.0-20200212222958-2202549b86ee github.com/filecoin-project/go-fil-markets v0.0.0-20200220181918-bfd030852a59
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6
github.com/filecoin-project/go-paramfetch v0.0.1 github.com/filecoin-project/go-paramfetch v0.0.1
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b

3
go.sum
View File

@ -117,6 +117,8 @@ github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5/go.mod h1:JbkIgFF/Z9BDlvrJO1FuKkaWsH673/UdFaiVS6uIHlA= github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5/go.mod h1:JbkIgFF/Z9BDlvrJO1FuKkaWsH673/UdFaiVS6uIHlA=
github.com/filecoin-project/go-fil-markets v0.0.0-20200212222958-2202549b86ee h1:DAV4RFTUBM1120KSI++jySWKDWpZ0njO57byuKFksuc= github.com/filecoin-project/go-fil-markets v0.0.0-20200212222958-2202549b86ee h1:DAV4RFTUBM1120KSI++jySWKDWpZ0njO57byuKFksuc=
github.com/filecoin-project/go-fil-markets v0.0.0-20200212222958-2202549b86ee/go.mod h1:CUIM9THHU1A4tz5SIuVfqz+GPgWwUNVGa5ub7HaMC2o= github.com/filecoin-project/go-fil-markets v0.0.0-20200212222958-2202549b86ee/go.mod h1:CUIM9THHU1A4tz5SIuVfqz+GPgWwUNVGa5ub7HaMC2o=
github.com/filecoin-project/go-fil-markets v0.0.0-20200220181918-bfd030852a59 h1:AULXvl86fSjh1gS3V/xo2YEWntAOSe3HGAHO0+S2h8k=
github.com/filecoin-project/go-fil-markets v0.0.0-20200220181918-bfd030852a59/go.mod h1:ftsiBbjLjNLAZ52FVDigkdCp73ltdcvAzAXav6drSLA=
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 h1:92PET+sx1Hb4W/8CgFwGuxaKbttwY+UNspYZTvXY0vs= github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 h1:92PET+sx1Hb4W/8CgFwGuxaKbttwY+UNspYZTvXY0vs=
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE= github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE=
github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU= github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go.mod h1:40kI2Gv16mwcRsHptI3OAV4nlOEU7wVDc4RgMylNFjU=
@ -132,6 +134,7 @@ github.com/filecoin-project/specs-actors v0.0.0-20200218211922-372fea3f131f h1:x
github.com/filecoin-project/specs-actors v0.0.0-20200218211922-372fea3f131f/go.mod h1:Ecx+3v6Bn4exCS0NbPu7VjrDCu2J+t1PdEpYin1/qOU= github.com/filecoin-project/specs-actors v0.0.0-20200218211922-372fea3f131f/go.mod h1:Ecx+3v6Bn4exCS0NbPu7VjrDCu2J+t1PdEpYin1/qOU=
github.com/filecoin-project/specs-actors v0.0.0-20200219191759-7e15e5c89659 h1:qHn5166bAy0dVEZr1Z4TPoveZNEEcFVz+RumCSM6QqA= github.com/filecoin-project/specs-actors v0.0.0-20200219191759-7e15e5c89659 h1:qHn5166bAy0dVEZr1Z4TPoveZNEEcFVz+RumCSM6QqA=
github.com/filecoin-project/specs-actors v0.0.0-20200219191759-7e15e5c89659/go.mod h1:Ecx+3v6Bn4exCS0NbPu7VjrDCu2J+t1PdEpYin1/qOU= github.com/filecoin-project/specs-actors v0.0.0-20200219191759-7e15e5c89659/go.mod h1:Ecx+3v6Bn4exCS0NbPu7VjrDCu2J+t1PdEpYin1/qOU=
github.com/filecoin-project/specs-actors v0.0.0-20200220011005-b2a2fbf40362/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA=
github.com/filecoin-project/specs-actors v0.0.0-20200221134721-ef38bdd3e05f h1:XplJWD0+rmozthAz4idL2wGyScmw9XlEZDaNmUKoY00= github.com/filecoin-project/specs-actors v0.0.0-20200221134721-ef38bdd3e05f h1:XplJWD0+rmozthAz4idL2wGyScmw9XlEZDaNmUKoY00=
github.com/filecoin-project/specs-actors v0.0.0-20200221134721-ef38bdd3e05f/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU= github.com/filecoin-project/specs-actors v0.0.0-20200221134721-ef38bdd3e05f/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
github.com/filecoin-project/specs-actors v0.0.0-20200221155838-19bb26c4b9d7 h1:iBqYva5s34J0LVBe7Fqrv/ToNVUFyKwpaXLk47wjq3A= github.com/filecoin-project/specs-actors v0.0.0-20200221155838-19bb26c4b9d7 h1:iBqYva5s34J0LVBe7Fqrv/ToNVUFyKwpaXLk47wjq3A=

View File

@ -32,7 +32,7 @@ func (rcn *retrievalClientNode) GetOrCreatePaymentChannel(ctx context.Context, c
// Allocate late creates a lane within a payment channel so that calls to // Allocate late creates a lane within a payment channel so that calls to
// CreatePaymentVoucher will automatically make vouchers only for the difference // CreatePaymentVoucher will automatically make vouchers only for the difference
// in total // in total
func (rcn *retrievalClientNode) AllocateLane(paymentChannel address.Address) (int64, error) { func (rcn *retrievalClientNode) AllocateLane(paymentChannel address.Address) (uint64, error) {
return rcn.pmgr.AllocateLane(paymentChannel) return rcn.pmgr.AllocateLane(paymentChannel)
} }
@ -44,5 +44,5 @@ func (rcn *retrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymen
if err != nil { if err != nil {
return nil, err return nil, err
} }
return voucher return voucher, nil
} }

View File

@ -6,11 +6,11 @@ import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/go-sectorbuilder" "github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/paychmgr"
"github.com/filecoin-project/lotus/storage" "github.com/filecoin-project/lotus/storage"
) )
@ -26,15 +26,15 @@ func NewRetrievalProviderNode(miner *storage.Miner, sb sectorbuilder.Interface,
return &retrievalProviderNode{miner, sb, full} return &retrievalProviderNode{miner, sb, full}
} }
func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID abi.SectorNumber, offset uint64, length uint64) (io.ReadCloser, error) { func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID uint64, offset uint64, length uint64) (io.ReadCloser, error) {
si, err := rpn.miner.GetSectorInfo(sectorID) si, err := rpn.miner.GetSectorInfo(abi.SectorNumber(sectorID))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return rpn.sb.ReadPieceFromSealedSector(ctx, sectorID, sectorbuilder.UnpaddedByteIndex(offset), abi.UnpaddedPieceSize(length), si.Ticket.TicketBytes, si.CommD) return rpn.sb.ReadPieceFromSealedSector(ctx, abi.SectorNumber(sectorID), sectorbuilder.UnpaddedByteIndex(offset), abi.UnpaddedPieceSize(length), si.Ticket.TicketBytes, si.CommD)
} }
func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paychmgr.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount) (abi.TokenAmount, error) { func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount) (abi.TokenAmount, error) {
added, err := rpn.full.PaychVoucherAdd(ctx, paymentChannel, voucher, proof, expectedAmount) added, err := rpn.full.PaychVoucherAdd(ctx, paymentChannel, voucher, proof, expectedAmount)
return added, err return added, err
} }

View File

@ -40,7 +40,7 @@ func (a *PaychAPI) PaychGet(ctx context.Context, from, to address.Address, ensur
}, nil }, nil
} }
func (a *PaychAPI) PaychAllocateLane(ctx context.Context, ch address.Address) (int64, error) { func (a *PaychAPI) PaychAllocateLane(ctx context.Context, ch address.Address) (uint64, error) {
return a.PaychMgr.AllocateLane(ch) return a.PaychMgr.AllocateLane(ch)
} }

View File

@ -366,7 +366,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error {
if maj != cbg.MajUnsignedInt { if maj != cbg.MajUnsignedInt {
return fmt.Errorf("wrong type for uint64 field") return fmt.Errorf("wrong type for uint64 field")
} }
t.NextLane = int64(extra) t.NextLane = uint64(extra)
default: default:
return fmt.Errorf("unknown struct field %d: '%s'", i, name) return fmt.Errorf("unknown struct field %d: '%s'", i, name)

View File

@ -53,11 +53,11 @@ func NewManager(sm *stmgr.StateManager, pchstore *Store, api ManagerApi) *Manage
} }
} }
func maxLaneFromState(st *actors.PaymentChannelActorState) (int64, error) { func maxLaneFromState(st *actors.PaymentChannelActorState) (uint64, error) {
maxLane := int64(math.MaxInt64) maxLane := uint64(math.MaxInt64)
for _, state := range st.LaneStates { for _, state := range st.LaneStates {
if int64(state.ID)+1 > maxLane+1 { if (state.ID)+1 > maxLane+1 {
maxLane = int64(state.ID) maxLane = state.ID
} }
} }
return maxLane, nil return maxLane, nil
@ -293,14 +293,14 @@ func (pm *Manager) AddVoucher(ctx context.Context, ch address.Address, sv *types
Proof: proof, Proof: proof,
}) })
if ci.NextLane <= int64(sv.Lane) { if ci.NextLane <= (sv.Lane) {
ci.NextLane = int64(sv.Lane + 1) ci.NextLane = sv.Lane + 1
} }
return delta, pm.store.putChannelInfo(ci) return delta, pm.store.putChannelInfo(ci)
} }
func (pm *Manager) AllocateLane(ch address.Address) (int64, error) { func (pm *Manager) AllocateLane(ch address.Address) (uint64, error) {
return pm.store.AllocateLane(ch) return pm.store.AllocateLane(ch)
} }

View File

@ -51,7 +51,7 @@ type ChannelInfo struct {
Direction uint64 Direction uint64
Vouchers []*VoucherInfo Vouchers []*VoucherInfo
NextLane int64 NextLane uint64
} }
func dskeyForChannel(addr address.Address) datastore.Key { func dskeyForChannel(addr address.Address) datastore.Key {
@ -177,7 +177,7 @@ func (ps *Store) findChan(filter func(*ChannelInfo) bool) (address.Address, erro
return address.Undef, nil return address.Undef, nil
} }
func (ps *Store) AllocateLane(ch address.Address) (int64, error) { func (ps *Store) AllocateLane(ch address.Address) (uint64, error) {
ps.lk.Lock() ps.lk.Lock()
defer ps.lk.Unlock() defer ps.lk.Unlock()