From 672807791407913adc8387eed54b71433ad9f811 Mon Sep 17 00:00:00 2001 From: Frank van de Pol Date: Tue, 7 Jun 2022 13:50:13 +0200 Subject: [PATCH] lnd: add advanced channel policy min/max_htlc_msat --- server/controllers/lnd/channels.ts | 3 +++ .../channel-lookup.component.html | 10 ++++++++++ .../channel-open-table.component.ts | 18 +++++++++++++++--- src/app/lnd/store/lnd.effects.ts | 7 ++++++- .../confirmation-message.component.html | 19 ++++++++++++------- .../confirmation-message.component.ts | 10 +++++++++- src/app/shared/models/alertData.ts | 2 ++ src/app/shared/models/lndModels.ts | 1 + 8 files changed, 58 insertions(+), 12 deletions(-) diff --git a/server/controllers/lnd/channels.ts b/server/controllers/lnd/channels.ts index de87887d..c8881f2c 100644 --- a/server/controllers/lnd/channels.ts +++ b/server/controllers/lnd/channels.ts @@ -224,6 +224,9 @@ export const postChanPolicy = (req, res, next) => { base_fee_msat: req.body.baseFeeMsat, fee_rate: parseFloat((req.body.feeRate / 1000000).toString()), time_lock_delta: parseInt(req.body.timeLockDelta), + max_htlc_msat: req.body.max_htlc_msat, + min_htlc_msat: req.body.min_htlc_msat, + min_htlc_msat_specified: true, chan_point: { funding_txid_str: txid_str, output_index: parseInt(output_idx) } }); } diff --git a/src/app/lnd/graph/lookups/channel-lookup/channel-lookup.component.html b/src/app/lnd/graph/lookups/channel-lookup/channel-lookup.component.html index 27b5a711..780f1936 100644 --- a/src/app/lnd/graph/lookups/channel-lookup/channel-lookup.component.html +++ b/src/app/lnd/graph/lookups/channel-lookup/channel-lookup.component.html @@ -44,6 +44,11 @@ {{lookupResult.node1_policy?.min_htlc}} +
+

Max HTLC

+ {{lookupResult.node1_policy?.max_htlc_msat}} +
+

Fee Base Msat

{{lookupResult.node1_policy?.fee_base_msat}} @@ -80,6 +85,11 @@ {{lookupResult.node2_policy?.min_htlc}}
+
+

Max HTLC

+ {{lookupResult.node2_policy?.max_htlc_msat}} +
+

Fee Base Msat

{{lookupResult.node2_policy?.fee_base_msat}} diff --git a/src/app/lnd/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts b/src/app/lnd/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts index 5caa22d3..4632d813 100644 --- a/src/app/lnd/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts +++ b/src/app/lnd/peers-channels/channels/channels-tables/channel-open-table/channel-open-table.component.ts @@ -199,7 +199,7 @@ export class ChannelOpenTableComponent implements OnInit, AfterViewInit, OnDestr } }); } else { - this.myChanPolicy = { fee_base_msat: 0, fee_rate_milli_msat: 0, time_lock_delta: 0 }; + this.myChanPolicy = { fee_base_msat: 0, fee_rate_milli_msat: 0, time_lock_delta: 0, min_htlc_msat: 0, max_htlc_msat: 0 }; this.store.dispatch(channelLookup({ payload: { uiMessage: UI_MESSAGES.GET_CHAN_POLICY, channelID: channelToUpdate.chan_id.toString() } })); this.lndEffects.setLookup.pipe(take(1)).subscribe((resLookup) => { if (resLookup.node1_pub === this.information.identity_pubkey) { @@ -223,10 +223,13 @@ export class ChannelOpenTableComponent implements OnInit, AfterViewInit, OnDestr yesBtnText: 'Update Channel', message: confirmationMsg, flgShowInput: true, + hasAdvanced: true, getInputs: [ { placeholder: 'Base Fee (mSat)', inputType: DataTypeEnum.NUMBER.toLowerCase(), inputValue: (this.myChanPolicy.fee_base_msat === '') ? 0 : this.myChanPolicy.fee_base_msat, width: 32 }, { placeholder: 'Fee Rate (mili mSat)', inputType: DataTypeEnum.NUMBER.toLowerCase(), inputValue: this.myChanPolicy.fee_rate_milli_msat, min: 1, width: 32, hintFunction: this.percentHintFunction }, - { placeholder: 'Time Lock Delta', inputType: DataTypeEnum.NUMBER.toLowerCase(), inputValue: this.myChanPolicy.time_lock_delta, width: 32 } + { placeholder: 'Time Lock Delta', inputType: DataTypeEnum.NUMBER.toLowerCase(), inputValue: this.myChanPolicy.time_lock_delta, width: 32 }, + { placeholder: 'Minimum HTLC (mSat)', inputType: DataTypeEnum.NUMBER.toLowerCase(), inputValue: (this.myChanPolicy.min_htlc === '') ? 0 : this.myChanPolicy.min_htlc, width: 32, advancedField: true }, + { placeholder: 'Maximum HTLC (mSat)', inputType: DataTypeEnum.NUMBER.toLowerCase(), inputValue: (this.myChanPolicy.max_htlc_msat === '') ? 0 : this.myChanPolicy.max_htlc_msat, width: 32, advancedField: true } ] } } @@ -240,7 +243,16 @@ export class ChannelOpenTableComponent implements OnInit, AfterViewInit, OnDestr const base_fee = confirmRes[0].inputValue; const fee_rate = confirmRes[1].inputValue; const time_lock_delta = confirmRes[2].inputValue; - this.store.dispatch(updateChannel({ payload: { baseFeeMsat: base_fee, feeRate: fee_rate, timeLockDelta: time_lock_delta, chanPoint: channelToUpdate.channel_point } })); + const min_htlc = confirmRes[3].inputValue; + const max_htlc_msat = confirmRes[4].inputValue; + this.store.dispatch(updateChannel({ payload: { + baseFeeMsat: base_fee, + feeRate: fee_rate, + timeLockDelta: time_lock_delta, + minHtlcMsat: min_htlc, + maxHtlcMsat: max_htlc_msat, + chanPoint: channelToUpdate.channel_point + } })); } }); } diff --git a/src/app/lnd/store/lnd.effects.ts b/src/app/lnd/store/lnd.effects.ts index f0203658..02e859b6 100644 --- a/src/app/lnd/store/lnd.effects.ts +++ b/src/app/lnd/store/lnd.effects.ts @@ -302,7 +302,12 @@ export class LNDEffects implements OnDestroy { mergeMap((action: { type: string, payload: any }) => { this.store.dispatch(openSpinner({ payload: UI_MESSAGES.UPDATE_CHAN_POLICY })); return this.httpClient.post(this.CHILD_API_URL + environment.CHANNELS_API + '/chanPolicy', - { baseFeeMsat: action.payload.baseFeeMsat, feeRate: action.payload.feeRate, timeLockDelta: action.payload.timeLockDelta, chanPoint: action.payload.chanPoint } + { baseFeeMsat: action.payload.baseFeeMsat, + feeRate: action.payload.feeRate, + timeLockDelta: action.payload.timeLockDelta, + max_htlc_msat: action.payload.maxHtlcMsat, + min_htlc_msat: action.payload.minHtlcMsat, + chanPoint: action.payload.chanPoint } ).pipe( map((postRes: any) => { this.logger.info(postRes); diff --git a/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.html b/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.html index 64a22e57..c62f239a 100644 --- a/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.html +++ b/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.html @@ -41,16 +41,21 @@

{{data.titleMessage}}

-
- - - - {{getInput.placeholder}} is required. - {{getInput.hintFunction ? getInput.hintFunction(getInput.inputValue) : getInput.hintText}} - +
+ + + + {{getInput.placeholder}} is required. + {{getInput.hintFunction ? getInput.hintFunction(getInput.inputValue) : getInput.hintText}} + +
+ diff --git a/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.ts b/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.ts index b01cec15..537a7add 100644 --- a/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.ts +++ b/src/app/shared/components/data-modal/confirmation-message/confirmation-message.component.ts @@ -25,9 +25,12 @@ export class ConfirmationMessageComponent implements OnInit { public yesBtnText = 'Yes'; public messageObjs = []; public flgShowInput = false; + public hasAdvanced = false; public alertTypeEnum = AlertTypeEnum; public dataTypeEnum = DataTypeEnum; - public getInputs: Array = [{ placeholder: '', inputType: 'text', inputValue: '', hintText: '', hintFunction: null }]; + public getInputs: Array = [{ placeholder: '', inputType: 'text', inputValue: '', hintText: '', hintFunction: null, advancedField: false }]; + + private showAdvanced = false; constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: ConfirmationData, private logger: LoggerService, @@ -41,6 +44,7 @@ export class ConfirmationMessageComponent implements OnInit { this.getInputs = this.data.getInputs; this.noBtnText = (this.data.noBtnText) ? this.data.noBtnText : 'No'; this.yesBtnText = (this.data.yesBtnText) ? this.data.yesBtnText : 'Yes'; + this.hasAdvanced = (this.data.hasAdvanced) ? this.data.hasAdvanced : false; this.messageObjs = this.data.message; if (this.data.type === AlertTypeEnum.ERROR) { if (!this.data.message && !this.data.titleMessage && this.messageObjs.length <= 0) { @@ -48,6 +52,10 @@ export class ConfirmationMessageComponent implements OnInit { } } } + + onShowAdvanced() { + this.showAdvanced = !this.showAdvanced; + } onClose(dialogRes: any): boolean | void { if (dialogRes && this.getInputs && this.getInputs.some((input) => typeof input.inputValue === 'undefined')) { diff --git a/src/app/shared/models/alertData.ts b/src/app/shared/models/alertData.ts index b4a30163..4273a4ae 100644 --- a/src/app/shared/models/alertData.ts +++ b/src/app/shared/models/alertData.ts @@ -30,6 +30,7 @@ export interface InputData { width?: number; hintText?: string; hintFunction?: Function; + advancedField?: boolean; } export interface OnChainLabelUTXO { @@ -197,6 +198,7 @@ export interface ConfirmationData { noBtnText?: string; yesBtnText?: string; flgShowInput?: boolean; + hasAdvanced?: boolean; getInputs?: Array; component?: any; } diff --git a/src/app/shared/models/lndModels.ts b/src/app/shared/models/lndModels.ts index 39d61516..bb5ab6c6 100644 --- a/src/app/shared/models/lndModels.ts +++ b/src/app/shared/models/lndModels.ts @@ -168,6 +168,7 @@ export interface LightningNode { export interface RoutingPolicy { time_lock_delta?: number; min_htlc?: string; + max_htlc_msat?: string; fee_base_msat?: string; fee_rate_milli_msat?: string; disabled?: boolean;