From 35c928806a99afda747db009d3189aa8c951e091 Mon Sep 17 00:00:00 2001 From: obdCoder Date: Wed, 16 Feb 2022 12:47:47 +0800 Subject: [PATCH] Accepting HTLC when the balance is insufficient --- lightclient/wsclient_user.go | 3 ++- service/htlc_tx_forward.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lightclient/wsclient_user.go b/lightclient/wsclient_user.go index b3a2f8822..059e4b3c4 100644 --- a/lightclient/wsclient_user.go +++ b/lightclient/wsclient_user.go @@ -38,7 +38,7 @@ func (client *Client) UserModule(msg bean.RequestMessage) (enum.SendTargetType, isAdmin := false //TODO 管理员验证 - if client.IsGRpcRequest || true { + if client.IsGRpcRequest { loginToken := gjson.Get(msg.Data, "login_token").Str isAdmin = service.CheckIsAdmin(loginToken) } @@ -47,6 +47,7 @@ func (client *Client) UserModule(msg bean.RequestMessage) (enum.SendTargetType, peerId = tool.GetUserPeerId(mnemonic) } else { peerId = tool.GetUserPeerId(walletId) + //peerId = tool.GetUserPeerId(mnemonic) } if GlobalWsClientManager.OnlineClientMap[peerId] != nil { if GlobalWsClientManager.OnlineClientMap[peerId].User.IsAdmin { diff --git a/service/htlc_tx_forward.go b/service/htlc_tx_forward.go index 8bb483880..d49506995 100644 --- a/service/htlc_tx_forward.go +++ b/service/htlc_tx_forward.go @@ -497,6 +497,11 @@ func (service *htlcForwardTxManager) AliceAddHtlcAtAliceSide(msg bean.RequestMes } latestCommitmentTx, _ = getLatestCommitmentTxUseDbTx(tx, channelInfo.ChannelId, user.PeerId) + // Accepting HTLC when the balance is insufficient + if latestCommitmentTx.AmountToRSMC < requestData.AmountToPayee { + return nil, false, errors.New(fmt.Sprintf("The amountToPayee in transaction must be more than %.8f", latestCommitmentTx.AmountToRSMC)) + } + if latestCommitmentTx.Id > 0 { if latestCommitmentTx.CurrState == dao.TxInfoState_CreateAndSign { _, err = omnicore.GetPubKeyFromWifAndCheck(requestData.LastTempAddressPrivateKey, latestCommitmentTx.RSMCTempAddressPubKey)