beignet 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createAcceptorChannel = exports.createOpenerChannel = exports.Channel = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const types_1 = require("../message/types");
|
|
9
|
+
const anchor_1 = require("../script/anchor");
|
|
9
10
|
const channel_open_1 = require("../message/channel-open");
|
|
10
11
|
const channel_funding_1 = require("../message/channel-funding");
|
|
11
12
|
const channel_update_1 = require("../message/channel-update");
|
|
@@ -923,8 +924,12 @@ class Channel {
|
|
|
923
924
|
const remoteReserveMsat = this._state.localConfig.channelReserveSatoshis * 1000n;
|
|
924
925
|
let remoteRequiredMsat = remoteReserveMsat;
|
|
925
926
|
if (this._state.role === types_2.ChannelRole.ACCEPTOR) {
|
|
926
|
-
const
|
|
927
|
+
const anchor = (0, types_3.isAnchorChannel)(this._state.channelType);
|
|
928
|
+
const feeMsat = BigInt((0, commitment_builder_1.calculateCommitmentFee)(Math.max((0, commitment_builder_1.getLocalCommitmentFeeRate)(this._state), (0, commitment_builder_1.getRemoteCommitmentFeeRate)(this._state)), this._countActiveHtlcs() + 1, anchor)) * 1000n;
|
|
927
929
|
remoteRequiredMsat += feeMsat;
|
|
930
|
+
if (anchor) {
|
|
931
|
+
remoteRequiredMsat += anchor_1.ANCHOR_TOTAL_COST * 1000n;
|
|
932
|
+
}
|
|
928
933
|
}
|
|
929
934
|
if (this._state.remoteBalanceMsat - msg.amountMsat < remoteRequiredMsat) {
|
|
930
935
|
return [
|
|
@@ -1687,7 +1692,8 @@ class Channel {
|
|
|
1687
1692
|
}
|
|
1688
1693
|
const activeHtlcCount = this._countActiveHtlcs();
|
|
1689
1694
|
const anchor = (0, types_3.isAnchorChannel)(this._state.channelType);
|
|
1690
|
-
const newFee = (0, commitment_builder_1.calculateCommitmentFee)(feeratePerKw, activeHtlcCount, anchor)
|
|
1695
|
+
const newFee = (0, commitment_builder_1.calculateCommitmentFee)(feeratePerKw, activeHtlcCount, anchor) +
|
|
1696
|
+
(anchor ? anchor_1.ANCHOR_TOTAL_COST : 0n);
|
|
1691
1697
|
const reserveMsat = this._state.remoteConfig.channelReserveSatoshis * 1000n;
|
|
1692
1698
|
if (newFee * 1000n > this._state.localBalanceMsat - reserveMsat) {
|
|
1693
1699
|
return [
|
|
@@ -1770,7 +1776,8 @@ class Channel {
|
|
|
1770
1776
|
}
|
|
1771
1777
|
const activeHtlcCount = this._countActiveHtlcs();
|
|
1772
1778
|
const anchor = (0, types_3.isAnchorChannel)(this._state.channelType);
|
|
1773
|
-
const newFee = (0, commitment_builder_1.calculateCommitmentFee)(msg.feeratePerKw, activeHtlcCount, anchor)
|
|
1779
|
+
const newFee = (0, commitment_builder_1.calculateCommitmentFee)(msg.feeratePerKw, activeHtlcCount, anchor) +
|
|
1780
|
+
(anchor ? anchor_1.ANCHOR_TOTAL_COST : 0n);
|
|
1774
1781
|
const reserveMsat = this._state.localConfig.channelReserveSatoshis * 1000n;
|
|
1775
1782
|
if (newFee * 1000n > this._state.remoteBalanceMsat - reserveMsat) {
|
|
1776
1783
|
return [
|
|
@@ -3918,8 +3925,12 @@ class Channel {
|
|
|
3918
3925
|
let requiredMsat = reserveMsat;
|
|
3919
3926
|
if (this._state.role === types_2.ChannelRole.OPENER) {
|
|
3920
3927
|
const feeratePerKw = Math.max((0, commitment_builder_1.getLocalCommitmentFeeRate)(this._state), (0, commitment_builder_1.getRemoteCommitmentFeeRate)(this._state));
|
|
3928
|
+
const anchor = (0, types_3.isAnchorChannel)(this._state.channelType);
|
|
3921
3929
|
requiredMsat +=
|
|
3922
|
-
BigInt((0, commitment_builder_1.calculateCommitmentFee)(feeratePerKw, this._countActiveHtlcs() +
|
|
3930
|
+
BigInt((0, commitment_builder_1.calculateCommitmentFee)(feeratePerKw * 2, this._countActiveHtlcs() + 2, anchor)) * 1000n;
|
|
3931
|
+
if (anchor) {
|
|
3932
|
+
requiredMsat += anchor_1.ANCHOR_TOTAL_COST * 1000n;
|
|
3933
|
+
}
|
|
3923
3934
|
}
|
|
3924
3935
|
const spendable = localMsat - requiredMsat;
|
|
3925
3936
|
return spendable > 0n ? spendable : 0n;
|