From 104871d6c94a8745a03862e01983797daf693d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 21 Feb 2020 18:26:44 +0100 Subject: [PATCH] paych: Lanes are back to u64 --- api/api_full.go | 2 +- api/apistruct/struct.go | 4 ++-- go.mod | 2 +- go.sum | 3 +++ markets/retrievaladapter/client.go | 4 ++-- markets/retrievaladapter/provider.go | 14 +++++++------- node/impl/paych/paych.go | 2 +- paychmgr/cbor_gen.go | 2 +- paychmgr/paych.go | 14 +++++++------- paychmgr/store.go | 4 ++-- 10 files changed, 27 insertions(+), 24 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 509758627..cb337d332 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -140,7 +140,7 @@ type FullNode interface { PaychList(context.Context) ([]address.Address, error) PaychStatus(context.Context, address.Address) (*PaychStatus, 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) PaychVoucherCheckValid(context.Context, address.Address, *types.SignedVoucher) error PaychVoucherCheckSpendable(context.Context, address.Address, *types.SignedVoucher, []byte, []byte) (bool, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index ea9b84a6c..d63a8a6a1 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -132,7 +132,7 @@ type FullNodeStruct struct { PaychList func(context.Context) ([]address.Address, 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"` - 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"` PaychVoucherCheck func(context.Context, *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) } -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) } diff --git a/go.mod b/go.mod index 576ccf6ed..5b3dfd50c 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( 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-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-paramfetch v0.0.1 github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b diff --git a/go.sum b/go.sum index c3dabd026..9d2dd0fa9 100644 --- a/go.sum +++ b/go.sum @@ -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-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-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/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE= 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-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-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/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU= github.com/filecoin-project/specs-actors v0.0.0-20200221155838-19bb26c4b9d7 h1:iBqYva5s34J0LVBe7Fqrv/ToNVUFyKwpaXLk47wjq3A= diff --git a/markets/retrievaladapter/client.go b/markets/retrievaladapter/client.go index a6c4cface..461fadd81 100644 --- a/markets/retrievaladapter/client.go +++ b/markets/retrievaladapter/client.go @@ -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 // CreatePaymentVoucher will automatically make vouchers only for the difference // 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) } @@ -44,5 +44,5 @@ func (rcn *retrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymen if err != nil { return nil, err } - return voucher + return voucher, nil } diff --git a/markets/retrievaladapter/provider.go b/markets/retrievaladapter/provider.go index ce423dd04..fef25c2a0 100644 --- a/markets/retrievaladapter/provider.go +++ b/markets/retrievaladapter/provider.go @@ -6,11 +6,11 @@ import ( "github.com/filecoin-project/go-address" "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/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin/paych" + "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/paychmgr" "github.com/filecoin-project/lotus/storage" ) @@ -26,15 +26,15 @@ func NewRetrievalProviderNode(miner *storage.Miner, sb sectorbuilder.Interface, return &retrievalProviderNode{miner, sb, full} } -func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID abi.SectorNumber, offset uint64, length uint64) (io.ReadCloser, error) { - si, err := rpn.miner.GetSectorInfo(sectorID) +func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID uint64, offset uint64, length uint64) (io.ReadCloser, error) { + si, err := rpn.miner.GetSectorInfo(abi.SectorNumber(sectorID)) if err != nil { 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) return added, err } diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index 2ea6d92c9..e165a6d17 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -40,7 +40,7 @@ func (a *PaychAPI) PaychGet(ctx context.Context, from, to address.Address, ensur }, 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) } diff --git a/paychmgr/cbor_gen.go b/paychmgr/cbor_gen.go index b89a4f24a..002ee2f08 100644 --- a/paychmgr/cbor_gen.go +++ b/paychmgr/cbor_gen.go @@ -366,7 +366,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { if maj != cbg.MajUnsignedInt { return fmt.Errorf("wrong type for uint64 field") } - t.NextLane = int64(extra) + t.NextLane = uint64(extra) default: return fmt.Errorf("unknown struct field %d: '%s'", i, name) diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 8bf607aa0..8cd625647 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -53,11 +53,11 @@ func NewManager(sm *stmgr.StateManager, pchstore *Store, api ManagerApi) *Manage } } -func maxLaneFromState(st *actors.PaymentChannelActorState) (int64, error) { - maxLane := int64(math.MaxInt64) +func maxLaneFromState(st *actors.PaymentChannelActorState) (uint64, error) { + maxLane := uint64(math.MaxInt64) for _, state := range st.LaneStates { - if int64(state.ID)+1 > maxLane+1 { - maxLane = int64(state.ID) + if (state.ID)+1 > maxLane+1 { + maxLane = state.ID } } return maxLane, nil @@ -293,14 +293,14 @@ func (pm *Manager) AddVoucher(ctx context.Context, ch address.Address, sv *types Proof: proof, }) - if ci.NextLane <= int64(sv.Lane) { - ci.NextLane = int64(sv.Lane + 1) + if ci.NextLane <= (sv.Lane) { + ci.NextLane = sv.Lane + 1 } 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) } diff --git a/paychmgr/store.go b/paychmgr/store.go index 02dc82d89..3a425c4fc 100644 --- a/paychmgr/store.go +++ b/paychmgr/store.go @@ -51,7 +51,7 @@ type ChannelInfo struct { Direction uint64 Vouchers []*VoucherInfo - NextLane int64 + NextLane uint64 } 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 } -func (ps *Store) AllocateLane(ch address.Address) (int64, error) { +func (ps *Store) AllocateLane(ch address.Address) (uint64, error) { ps.lk.Lock() defer ps.lk.Unlock()