paych: Fix createPaych

This commit is contained in:
Łukasz Magiera 2019-09-16 19:23:48 +02:00
parent 55014becc8
commit b88d23fd8b
5 changed files with 27 additions and 8 deletions

View File

@ -95,6 +95,7 @@ func (a *API) ClientStartDeal(ctx context.Context, data cid.Cid, miner address.A
} }
head := a.Chain.GetHeaviestTipSet() head := a.Chain.GetHeaviestTipSet()
payment, err := a.PaychNewPayment(ctx, self, miner, total, extra, head.Height()+blocksDuration, head.Height()+blocksDuration) payment, err := a.PaychNewPayment(ctx, self, miner, total, extra, head.Height()+blocksDuration, head.Height()+blocksDuration)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -43,8 +43,8 @@ func (a *PaychAPI) PaychAllocateLane(ctx context.Context, ch address.Address) (u
} }
func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address, amount types.BigInt, extra *types.ModVerifyParams, tl uint64, minClose uint64) (*api.PaymentInfo, error) { func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address, amount types.BigInt, extra *types.ModVerifyParams, tl uint64, minClose uint64) (*api.PaymentInfo, error) {
// TODO: Fix free fund tracking in PaychGet, pass amount // TODO: Fix free fund tracking in PaychGet
ch, err := a.PaychGet(ctx, from, to, types.NewInt(0)) ch, err := a.PaychGet(ctx, from, to, amount)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -81,25 +81,34 @@ func (pm *Manager) TrackInboundChannel(ctx context.Context, ch address.Address)
}) })
} }
func (pm *Manager) TrackOutboundChannel(ctx context.Context, ch address.Address) error { func (pm *Manager) loadOutboundChannelInfo(ctx context.Context, ch address.Address) (*ChannelInfo, error) {
_, st, err := pm.loadPaychState(ctx, ch) _, st, err := pm.loadPaychState(ctx, ch)
if err != nil { if err != nil {
return err return nil, err
} }
maxLane, err := maxLaneFromState(st) maxLane, err := maxLaneFromState(st)
if err != nil { if err != nil {
return err return nil, err
} }
return pm.store.TrackChannel(&ChannelInfo{ return &ChannelInfo{
Channel: ch, Channel: ch,
Control: st.From, Control: st.From,
Target: st.To, Target: st.To,
Direction: DirOutbound, Direction: DirOutbound,
NextLane: maxLane + 1, NextLane: maxLane + 1,
}) }, nil
}
func (pm *Manager) TrackOutboundChannel(ctx context.Context, ch address.Address) error {
ci, err := pm.loadOutboundChannelInfo(ctx, ch)
if err != nil {
return err
}
return pm.store.TrackChannel(ci)
} }
func (pm *Manager) ListChannels() ([]address.Address, error) { func (pm *Manager) ListChannels() ([]address.Address, error) {

View File

@ -65,7 +65,12 @@ func (pm *Manager) createPaych(ctx context.Context, from, to address.Address, am
return address.Undef, cid.Undef, err return address.Undef, cid.Undef, err
} }
if err := pm.TrackOutboundChannel(ctx, paychaddr); err != nil { ci, err := pm.loadOutboundChannelInfo(ctx, paychaddr)
if err != nil {
return address.Undef, cid.Undef, err
}
if err := pm.store.trackChannel(ci); err != nil {
return address.Undef, cid.Undef, err return address.Undef, cid.Undef, err
} }

View File

@ -96,6 +96,10 @@ func (ps *Store) TrackChannel(ch *ChannelInfo) error {
ps.lk.Lock() ps.lk.Lock()
defer ps.lk.Unlock() defer ps.lk.Unlock()
return ps.trackChannel(ch)
}
func (ps *Store) trackChannel(ch *ChannelInfo) error {
_, err := ps.getChannelInfo(ch.Channel) _, err := ps.getChannelInfo(ch.Channel)
switch err { switch err {
default: default: