mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-18 14:24:21 +01:00
insert htlc used for channel open
This commit is contained in:
@@ -26,6 +26,16 @@ type Forward struct {
|
|||||||
ResolvedTime time.Time
|
ResolvedTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OpenChannelHtlc struct {
|
||||||
|
NodeId []byte
|
||||||
|
PeerId []byte
|
||||||
|
ChannelPoint *wire.OutPoint
|
||||||
|
OriginalAmountMsat uint64
|
||||||
|
ForwardAmountMsat uint64
|
||||||
|
IncomingAmountMsat uint64
|
||||||
|
ForwardTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type Store interface {
|
type Store interface {
|
||||||
UpdateChannels(ctx context.Context, updates []*ChannelUpdate) error
|
UpdateChannels(ctx context.Context, updates []*ChannelUpdate) error
|
||||||
InsertForwards(ctx context.Context, forwards []*Forward, nodeId []byte) error
|
InsertForwards(ctx context.Context, forwards []*Forward, nodeId []byte) error
|
||||||
@@ -33,4 +43,5 @@ type Store interface {
|
|||||||
FetchClnForwardOffsets(ctx context.Context, nodeId []byte) (uint64, uint64, error)
|
FetchClnForwardOffsets(ctx context.Context, nodeId []byte) (uint64, uint64, error)
|
||||||
SetClnForwardOffsets(ctx context.Context, nodeId []byte, created uint64, updated uint64) error
|
SetClnForwardOffsets(ctx context.Context, nodeId []byte, created uint64, updated uint64) error
|
||||||
FetchLndForwardOffset(ctx context.Context, nodeId []byte) (*time.Time, error)
|
FetchLndForwardOffset(ctx context.Context, nodeId []byte) (*time.Time, error)
|
||||||
|
AddOpenChannelHtlc(ctx context.Context, htlc *OpenChannelHtlc) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,7 +255,28 @@ func (i *Interceptor) Intercept(req common.InterceptRequest) common.InterceptRes
|
|||||||
}})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't break here, this is not critical.
|
// Don't break here, this is not critical.
|
||||||
log.Printf("paymentHash: %s, failed to insert newly opened channel in history store. %v", reqPaymentHashStr, channelPoint.String())
|
log.Printf("paymentHash: %s, failed to insert newly opened channel in history store. %v: %v", reqPaymentHashStr, channelPoint.String(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = i.historyStore.AddOpenChannelHtlc(context.TODO(), &history.OpenChannelHtlc{
|
||||||
|
NodeId: i.nodeid,
|
||||||
|
PeerId: destination,
|
||||||
|
ChannelPoint: channelPoint,
|
||||||
|
OriginalAmountMsat: req.OutgoingAmountMsat,
|
||||||
|
ForwardAmountMsat: uint64(amt),
|
||||||
|
IncomingAmountMsat: req.IncomingAmountMsat,
|
||||||
|
ForwardTime: time.Now(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
// Don't break here, this is not critical.
|
||||||
|
log.Printf(
|
||||||
|
"paymentHash: %s, failed to insert htlc used for channel open in history store: channel: %v,"+
|
||||||
|
" original amount: %v, forward amount: %v",
|
||||||
|
reqPaymentHashStr,
|
||||||
|
channelPoint.String(),
|
||||||
|
req.OutgoingAmountMsat,
|
||||||
|
amt,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
useLegacyOnionBlob := slices.Contains(i.config.LegacyOnionTokens, token)
|
useLegacyOnionBlob := slices.Contains(i.config.LegacyOnionTokens, token)
|
||||||
|
|||||||
@@ -625,8 +625,22 @@ func (i *Interceptor) handlePaymentChanOpened(event *paymentChanOpenedEvent) {
|
|||||||
resolution.part.resolution <- resolution.resolution
|
resolution.part.resolution <- resolution.resolution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
payment.registration.IsComplete = true
|
payment.registration.IsComplete = true
|
||||||
go i.store.SetCompleted(context.TODO(), payment.registration.Id)
|
go func() {
|
||||||
|
i.store.SetCompleted(context.TODO(), payment.registration.Id)
|
||||||
|
for _, resolution := range resolutions {
|
||||||
|
i.historyStore.AddOpenChannelHtlc(context.TODO(), &history.OpenChannelHtlc{
|
||||||
|
NodeId: i.config.NodeId,
|
||||||
|
PeerId: destination,
|
||||||
|
ChannelPoint: event.channelPoint,
|
||||||
|
OriginalAmountMsat: resolution.part.req.OutgoingAmountMsat,
|
||||||
|
ForwardAmountMsat: resolution.resolution.AmountMsat,
|
||||||
|
IncomingAmountMsat: resolution.part.req.IncomingAmountMsat,
|
||||||
|
ForwardTime: now,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}()
|
||||||
delete(i.inflightPayments, event.paymentId)
|
delete(i.inflightPayments, event.paymentId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ func (s *mockHistoryStore) SetClnForwardOffsets(ctx context.Context, nodeId []by
|
|||||||
func (s *mockHistoryStore) FetchLndForwardOffset(ctx context.Context, nodeId []byte) (*time.Time, error) {
|
func (s *mockHistoryStore) FetchLndForwardOffset(ctx context.Context, nodeId []byte) (*time.Time, error) {
|
||||||
return nil, ErrNotImplemented
|
return nil, ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
func (s *mockHistoryStore) AddOpenChannelHtlc(ctx context.Context, htlc *history.OpenChannelHtlc) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type mockLightningClient struct {
|
type mockLightningClient struct {
|
||||||
openResponses []*wire.OutPoint
|
openResponses []*wire.OutPoint
|
||||||
|
|||||||
@@ -345,3 +345,29 @@ func (s *HistoryStore) SetClnForwardOffsets(
|
|||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *HistoryStore) AddOpenChannelHtlc(ctx context.Context, htlc *history.OpenChannelHtlc) error {
|
||||||
|
// TODO: Find an identifier equal to the forwarding_history identifier.
|
||||||
|
_, err := s.pool.Exec(ctx, `
|
||||||
|
INSERT INTO open_channel_htlcs (
|
||||||
|
nodeid
|
||||||
|
, peerid
|
||||||
|
, funding_tx_id
|
||||||
|
, funding_tx_outnum
|
||||||
|
, forward_amt_msat
|
||||||
|
, original_amt_msat
|
||||||
|
, incoming_amt_msat
|
||||||
|
, forward_time
|
||||||
|
) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
|
`,
|
||||||
|
htlc.NodeId,
|
||||||
|
htlc.PeerId,
|
||||||
|
htlc.ChannelPoint.Hash[:],
|
||||||
|
htlc.ChannelPoint.Index,
|
||||||
|
int64(htlc.ForwardAmountMsat),
|
||||||
|
int64(htlc.OriginalAmountMsat),
|
||||||
|
int64(htlc.IncomingAmountMsat),
|
||||||
|
htlc.ForwardTime.UnixNano(),
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
1
postgresql/migrations/000016_open_channel_htlc.down.sql
Normal file
1
postgresql/migrations/000016_open_channel_htlc.down.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE public.open_channel_htlcs;
|
||||||
9
postgresql/migrations/000016_open_channel_htlc.up.sql
Normal file
9
postgresql/migrations/000016_open_channel_htlc.up.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE public.open_channel_htlcs (
|
||||||
|
nodeid bytea NOT NULL,
|
||||||
|
peerid bytea NOT NULL,
|
||||||
|
funding_tx_id bytea NOT NULL,
|
||||||
|
funding_tx_outnum bigint NOT NULL,
|
||||||
|
forward_amt_msat bigint NOT NULL,
|
||||||
|
original_amt_msat bigint NOT NULL,
|
||||||
|
forward_time bigint NOT NULL
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user