Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSPS7: Channel lease extensions #2720

Merged
merged 27 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
591ab1b
Refactor LSPS1 code + wire up lsps7.get_extendable_channels call
kaloudis Jan 9, 2025
435e395
Channel: fix shortChannelId
kaloudis Jan 10, 2025
112ae4c
LSPS: custom message listener on start-up
kaloudis Jan 10, 2025
9d8b330
LSPS7: Single channel view
kaloudis Jan 10, 2025
11fa752
Views: move LSPS1 dir
kaloudis Jan 10, 2025
e0141e4
LSPS7: wire up Create Order view
kaloudis Jan 11, 2025
0f97ba5
LSPS7: Create Order: fix params
kaloudis Jan 13, 2025
05019a8
LSPS7: adds months to expiry display
kaloudis Jan 13, 2025
36cda04
LSPS7: Create Order + Get Order
kaloudis Jan 14, 2025
62da9e0
LSPS7: separate loading state from LSPS1
kaloudis Jan 14, 2025
c2a21c9
LSPS7: add expiration status to Channels list
kaloudis Jan 14, 2025
4ed6572
DateTimeUtils: blocksToMonthsAndDays tests
kaloudis Jan 14, 2025
fe3ba69
LSPS7: enable custom messages for remote LND nodes
kaloudis Jan 17, 2025
5d47848
Localize channel statuses
kaloudis Jan 17, 2025
1d84e82
LSPS7: Create order: add block heights
kaloudis Jan 17, 2025
540d1fe
Channel: SCID: handle undefined chanIds (Pending open chans)
kaloudis Jan 18, 2025
9bf80f7
Channel: fix display of SCID for CLN nodes
kaloudis Jan 21, 2025
193a6ad
LSPS7: upgrade to new Storage system
kaloudis Jan 25, 2025
daf4e1f
LSPS1: GetInfo: add loading to REST call
kaloudis Jan 29, 2025
68e56b4
LSPS7: only call get_extendable_channels if backend supports custom m…
kaloudis Jan 29, 2025
67738cf
supportsLSPS1customMessage -> supportsLSPScustomMessage
kaloudis Jan 29, 2025
a8ca8df
getLSPS1Host -> getLSPSHost
kaloudis Feb 1, 2025
5b3723b
LSPS7: update stored orders key
kaloudis Feb 1, 2025
44131fb
LSPS single Order views: refactor update and fallback flow
kaloudis Feb 1, 2025
741668a
Channel status: Good -> Online + add LSP discretion warning
kaloudis Feb 5, 2025
7b4a1c6
LSPS7: fix response component import name
kaloudis Feb 5, 2025
eb8fcb6
LSPS7: Order response: fix extension ID and expiration block display
kaloudis Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ import RestoreChannelBackups from './views/Settings/EmbeddedNode/RestoreChannelB
import LSPServicesList from './views/Settings/LSPServicesList';

// LSPS1
import LSPS1 from './views/Settings/LSPS1/index';
import LSPS1Settings from './views/Settings/LSPS1/Settings';
import OrdersPane from './views/Settings/LSPS1/OrdersPane';
import Orders from './views/Settings/LSPS1/Order';
import LSPS1 from './views/LSPS1/index';
import LSPS1Settings from './views/LSPS1/Settings';
import OrdersPane from './views/LSPS1/OrdersPane';
import LSPS1Order from './views/LSPS1/Order';
// LSPS7
import LSPS7 from './views/LSPS7/index';
import LSPS7Order from './views/LSPS7/Order';

import RawTxHex from './views/RawTxHex';

Expand Down Expand Up @@ -891,7 +894,15 @@ export default class App extends React.PureComponent {
/>
<Stack.Screen
name="LSPS1Order" // @ts-ignore:next-line
component={Orders}
component={LSPS1Order}
/>
<Stack.Screen
name="LSPS7" // @ts-ignore:next-line
component={LSPS7}
/>
<Stack.Screen
name="LSPS7Order" // @ts-ignore:next-line
component={LSPS7Order}
/>
<Stack.Screen
name="PendingHTLCs" // @ts-ignore:next-line
Expand Down
2 changes: 1 addition & 1 deletion backends/CLNRest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export default class CLNRest {
supportsOnchainBatching = () => false;
supportsChannelBatching = () => false;
supportsChannelFundMax = () => true;
supportsLSPS1customMessage = () => false;
supportsLSPScustomMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
Expand Down
2 changes: 1 addition & 1 deletion backends/CLightningREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default class CLightningREST extends LND {
supportsOnchainSendMax = () => true;
supportsOnchainBatching = () => false;
supportsChannelBatching = () => false;
supportsLSPS1customMessage = () => false;
supportsLSPScustomMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
Expand Down
1 change: 1 addition & 0 deletions backends/CoreLightningRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const listPeers = async (data: any) => {
remote_pubkey: peer.peer_id,
channel_point: peer.funding_txid,
chan_id: peer.channel_id,
short_channel_id: peer.short_channel_id,
capacity: Number(peer.total_msat / 1000).toString(),
local_balance: Number(peer.to_us_msat / 1000).toString(),
remote_balance: Number(
Expand Down
2 changes: 1 addition & 1 deletion backends/Eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export default class Eclair {
supportsOnchainSendMax = () => false;
supportsOnchainBatching = () => false;
supportsChannelBatching = () => false;
supportsLSPS1customMessage = () => false;
supportsLSPScustomMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
Expand Down
2 changes: 1 addition & 1 deletion backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export default class EmbeddedLND extends LND {
supportsOnchainBatching = () => true;
supportsChannelBatching = () => true;
supportsChannelFundMax = () => true;
supportsLSPS1customMessage = () => true;
supportsLSPScustomMessage = () => true;
supportsLSPS1rest = () => false;
supportsOffers = () => false;
supportsBolt11BlindedRoutes = () => this.supports('v0.18.3');
Expand Down
2 changes: 1 addition & 1 deletion backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ export default class LND {
supportsOnchainBatching = () => true;
supportsChannelBatching = () => true;
supportsChannelFundMax = () => true;
supportsLSPS1customMessage = () => false;
supportsLSPScustomMessage = () => true;
supportsLSPS1rest = () => true;
supportsOffers = (): Promise<boolean> | boolean => false;
supportsBolt11BlindedRoutes = () => this.supports('v0.18.3');
Expand Down
2 changes: 1 addition & 1 deletion backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ export default class LightningNodeConnect {
supportsOnchainBatching = () => true;
supportsChannelBatching = () => true;
supportsChannelFundMax = () => true;
supportsLSPS1customMessage = () => false;
supportsLSPScustomMessage = () => true;
supportsLSPS1rest = () => true;
supportsOffers = () => false;
supportsBolt11BlindedRoutes = () => this.supports('v0.18.3');
Expand Down
2 changes: 1 addition & 1 deletion backends/LndHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default class LndHub extends LND {
supportsOnchainSendMax = () => false;
supportsOnchainBatching = () => false;
supportsChannelBatching = () => true;
supportsLSPS1customMessage = () => false;
supportsLSPScustomMessage = () => false;
supportsLSPS1rest = () => false;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
Expand Down
2 changes: 1 addition & 1 deletion backends/Spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export default class Spark {
supportsOnchainSendMax = () => false;
supportsOnchainBatching = () => false;
supportsChannelBatching = () => true;
supportsLSPS1customMessage = () => false;
supportsLSPScustomMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
Expand Down
5 changes: 4 additions & 1 deletion components/Channels/ChannelItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { View } from 'react-native';
import { Body } from '../../components/text/Body';
import { BalanceBar } from '../../components/Channels/BalanceBar';
import { Row } from '../../components/layout/Row';
import { Status } from '../../views/Channels/ChannelsPane';
import { Status, ExpirationStatus } from '../../views/Channels/ChannelsPane';
import Amount from '../Amount';
import { Tag } from './Tag';

Expand All @@ -28,6 +28,7 @@ export function ChannelItem({
outboundReserve = 0,
largestTotal,
status,
expirationStatus,
pendingHTLCs,
pendingTimelock,
noBorder,
Expand All @@ -46,6 +47,7 @@ export function ChannelItem({
outboundReserve?: string | number;
largestTotal?: number;
status?: Status;
expirationStatus?: ExpirationStatus;
pendingHTLCs?: boolean;
pendingTimelock?: string;
noBorder?: boolean;
Expand Down Expand Up @@ -133,6 +135,7 @@ export function ChannelItem({
<Body small={true}>{pendingTimelock}</Body>
</View>
) : null}
{expirationStatus && <Tag status={expirationStatus} />}
{status && <Tag status={status} />}
</Row>
{localBalance &&
Expand Down
43 changes: 27 additions & 16 deletions components/Channels/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { View } from 'react-native';
import { Body } from '../../components/text/Body';
import { Row } from '../../components/layout/Row';
import { Spacer } from '../../components/layout/Spacer';
import { Status } from '../../views/Channels/ChannelsPane';
import { ExpirationStatus, Status } from '../../views/Channels/ChannelsPane';
import { themeColor } from '../../utils/ThemeUtils';

export function Tag({ status }: { status: Status }) {
// Garish colors to let you know you fucked up
const colors = { background: 'pink', dot: 'blue' };
export function Tag({ status }: { status: Status | ExpirationStatus }) {
const colors = { background: '', dot: '' };

// TODO: should all these colors be in the theme?
switch (status) {
case Status.Good:
case Status.Online:
colors.background = '#2C553D';
colors.dot = '#46E80E';
break;
Expand All @@ -30,6 +30,15 @@ export function Tag({ status }: { status: Status }) {
colors.background = '#A7A9AC';
colors.dot = '#E5E5E5';
break;
case ExpirationStatus.Expiring:
colors.background = themeColor('warning');
break;
case ExpirationStatus.Expired:
colors.background = themeColor('error');
break;
case ExpirationStatus.LSPDiscretion:
colors.background = themeColor('warning');
break;
}

return (
Expand All @@ -40,20 +49,22 @@ export function Tag({ status }: { status: Status }) {
paddingTop: 3,
paddingBottom: 3,
backgroundColor: colors.background,
borderRadius: 4
borderRadius: 4,
marginLeft: 8
}}
>
<Row>
<View
style={{
width: 6,
height: 6,
borderRadius: 6,
backgroundColor: colors.dot
}}
/>
<Spacer width={6} />
{/* TODO: localize */}
{colors.dot && (
<View
style={{
width: 6,
height: 6,
borderRadius: 6,
backgroundColor: colors.dot
}}
/>
)}
{colors.dot && <Spacer width={6} />}
<Body colorOverride="white" small>
{status}
</Body>
Expand Down
32 changes: 32 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@
"general.defaultNodeNickname": "My Lightning Node",
"general.active": "Active",
"general.unknown": "Unknown",
"general.retry": "Retry",
"channel.status.good": "Good",
"channel.status.stable": "Stable",
"channel.status.unstable": "Unstable",
"channel.status.offline": "Offline",
"channel.status.opening": "Opening",
"channel.status.closing": "Closing",
"channel.expirationStatus.expiring": "Expiring soon",
"channel.expirationStatus.expired": "Expired",
"restart.title": "Restart required",
"restart.msg": "ZEUS has to be restarted before the new configuration is applied.",
"restart.msg1": "Would you like to restart now?",
Expand Down Expand Up @@ -453,6 +462,13 @@
"views.Channel.Total.offline": "Total offline",
"views.Channel.zeroConf": "Zero conf",
"views.Channel.commitmentType": "Commitment Type",
"views.Channel.lease.expiresIn": "Expires in",
"views.Channel.lease.outboundChannel": "Outbound channel",
"views.Channel.lease.lspDiscretion": "May be closed at LSP's discretion",
"views.Channel.lease.lspDiscretion.explainer1": "The Lightning Service Provider (LSP) reserves the right to close your channel at any time. Channels with large balances pushed to the LSP's side, are more likely to be closed.",
"views.Channel.lease.lspDiscretion.explainer2": "If you would like to ensure your channel remains open, consider purchasing a channel lease.",
"views.Channel.lease.purchaseLease": "Purchase channel lease",
"views.Channel.lease.extendLease": "Extend channel lease",
"views.UTXOs.CoinControl.noUTXOs": "No UTXOs available",
"views.EditFee.mainText": "Edit network fee",
"views.EditFee.fastestFee": "Fastest fee",
Expand Down Expand Up @@ -1027,6 +1043,7 @@
"views.Sync.currentBlockHeight": "Current block height",
"views.Sync.tip": "Tip",
"views.Sync.numBlocksUntilSynced": "Number of blocks until synced",
"views.LSPS1.type": "In advance channel purchase",
"views.LSPS1.pubkeyAndHostNotFound": "Node pubkey and host are not set",
"views.SyncRecovery.title": "Recovering wallet",
"views.LSPS1.timeoutError": "Did not receive response from server",
Expand Down Expand Up @@ -1062,6 +1079,7 @@
"views.LSPS1.fundingOutpoint": "Funding outpoint",
"views.LSPS1.purchaseInbound": "Purchase inbound channel",
"views.LSPS1.lsps1Spec": "LSPS1 API and spec",
"views.LSPS1.lspOrders": "LSP Orders",
"views.LSPS1.lsps1Orders": "LSPS1 Orders",
"views.LSPS1.noOrdersError": "No orders are saved yet!",
"views.LSPS1.showingPreviousState": "showing previous state!",
Expand All @@ -1073,6 +1091,16 @@
"views.LSPS1.serviceInfoText2": "If you don't want to wait for on-chain confirmation, you can use our just-in-time channel service. The JIT service will create a 0-conf channel of the amount you specify plus 100k sats of inbound (receiving capacity).",
"views.LSPS1.useJit": "Use just-in-time service",
"views.LSPS1.spec": "Spec",
"views.LSPS7.type": "Channel lease extension",
"views.LSPS7.channelExtensionBlocks": "Number of blocks to extend channel lease by",
"views.LSPS7.extensionExpiryBlocks": "Extension expiry blocks",
"views.LSPS7.maxChannelExtensionExpiryBlocks": "Max channel extension expiry blocks",
"views.LSPS7.expirationBlock": "Current expiration block",
"views.LSPS7.proposedExpirationBlock": "Proposed expiration block",
"views.LSPS7.originalOrderId": "Original order ID",
"views.LSPS7.originalService": "Original service",
"views.LSPS7.extensionOrderIds": "Extension Order IDs",
"views.LSPS7.serviceInfoText1": "This service allows you to extend the duration of a purchased channel lease, or purchase a channel lease for a channel you have opened to the LSP.",
"components.UTXOPicker.modal.title": "Select UTXOs to use",
"components.UTXOPicker.modal.description": "Select the UTXOs to be used in this operation. You may want to only use specific UTXOs to preserve your privacy.",
"components.UTXOPicker.modal.set": "Set UTXOs",
Expand Down Expand Up @@ -1280,7 +1308,10 @@
"time.minutes": "Minutes",
"time.hours": "Hours",
"time.days": "Days",
"time.day": "Day",
"time.weeks": "Weeks",
"time.months": "Months",
"time.month": "Month",
"time.10min": "10 min",
"time.1H": "1H",
"time.1D": "1D",
Expand All @@ -1289,6 +1320,7 @@
"time.3mo": "3 mo",
"time.6mo": "6 mo",
"time.12mo": "12 mo",
"time.max": "Max",
"components.AlertModal.zeusDetected": "ZEUS has detected the following issues:",
"components.AlertModal.highZombieCount": "High zombie channel count",
"components.AlertModal.zombieExplainer": "Zombie channels indicate stale data on your downloaded network graph.",
Expand Down
25 changes: 7 additions & 18 deletions models/Channel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js';
import { observable, computed } from 'mobx';
import BigInt from 'big-integer';
const { chanFormat } = require('bolt07');

import BaseModel from './BaseModel';
import { lnrpc } from '../proto/lightning';
Expand Down Expand Up @@ -61,6 +61,7 @@ export default class Channel extends BaseModel {
// CLN v23.05 msat new
total: string;
to_us: string;
short_channel_id: string; // CLN

channel_id?: string;
alias?: string;
Expand Down Expand Up @@ -187,23 +188,11 @@ export default class Channel extends BaseModel {

@computed
public get shortChannelId(): string | undefined {
// make sure channelId is a number, or don't both w/ SCID calculation
if (Number.isNaN(Number(this.channelId))) return;

const chanId = BigInt(Number(this.channelId) || 0); // Use BigInt for large numbers

// Extract the components
// @ts-ignore:next-line
const blockHeight = chanId >> BigInt(40); // Shift right by 40 bits
// @ts-ignore:next-line
const txIndex = (chanId >> BigInt(16)) & BigInt(0xffffff); // Shift right by 16 bits and mask 24 bits
// @ts-ignore:next-line
const outputIndex = chanId & BigInt(0xffff); // Mask the lower 16 bits

// Combine components into the short channel ID
const scid = `${blockHeight}x${txIndex}x${outputIndex}`;

return scid !== '0x0x0' ? scid : '';
return this.short_channel_id
? this.short_channel_id
: this.channelId
? chanFormat({ number: this.channelId }).channel
: undefined;
}

@computed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"aez": "1.0.1",
"assert": "1.5.0",
"bech32": "2.0.0",
"big-integer": "1.6.52",
"bignumber.js": "9.0.2",
"bip32": "3.0.1",
"bip39": "3.1.0",
"bitcoinjs-lib": "6.1.5",
"bolt07": "1.9.4",
"bolt11": "1.4.1",
"browserify-zlib": "0.1.4",
"bs58check": "2.1.2",
Expand Down
Loading