Skip to content

Commit 26f01fc

Browse files
committed
Merge branch 'eager_electron_5.0RC' into testnet
2 parents 23331a2 + fb7778b commit 26f01fc

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

core/lightning.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ void Channel::Update()
518518
if (!m_State.m_Terminate)
519519
{
520520
const HeightRange* pHR = pPath->get_HR();
521-
if (pHR && ((hTip + m_Params.m_hPostLockReserve + (m_iRole ? kPostLockReserveLag : 0)) > pHR->m_Max))
521+
if (pHR && (hTip + (m_iRole ? kPostLockReserveLag : 0)) > (pHR->m_Max - m_Params.m_hPostLockReserve))
522522
{
523523
m_State.m_Terminate = true;
524524
m_pNegCtx.reset();

wallet/laser/mediator.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,23 @@ bool Mediator::Serve(const std::string& channelID)
288288
{
289289
m_actionsQueue.emplace_back([this, p_channelID] () {
290290
auto& channel = m_channels[p_channelID];
291+
292+
if (!channel)
293+
{
294+
LOG_ERROR() << "Unknown channel ID: " << to_hex(p_channelID->m_pData, p_channelID->nBytes);
295+
return;
296+
}
297+
298+
if (IsChannelExpired(channel))
299+
{
300+
LOG_ERROR() << "Channel ID: "
301+
<< to_hex(p_channelID->m_pData, p_channelID->nBytes) << " lock height expired";
302+
return;
303+
}
304+
291305
if (channel)
292306
channel->Subscribe();
293-
else
294-
LOG_ERROR() << "Unknown channel ID: " << to_hex(p_channelID->m_pData, p_channelID->nBytes);
307+
295308
});
296309
return true;
297310
}
@@ -367,6 +380,13 @@ bool Mediator::Close(const std::string& channelID)
367380
return false;
368381
}
369382

383+
if (IsChannelExpired(channel))
384+
{
385+
LOG_ERROR() << "Channel ID: "
386+
<< to_hex(p_channelID->m_pData, p_channelID->nBytes) << " lock height expired";
387+
return false;
388+
}
389+
370390
m_actionsQueue.emplace_back([this, p_channelID] () {
371391
CloseInternal(p_channelID);
372392
});
@@ -398,6 +418,13 @@ bool Mediator::GracefulClose(const std::string& channelID)
398418
return false;
399419
}
400420

421+
if (IsChannelExpired(channel))
422+
{
423+
LOG_ERROR() << "Channel ID: "
424+
<< to_hex(p_channelID->m_pData, p_channelID->nBytes) << " lock height expired";
425+
return false;
426+
}
427+
401428
if (!IsInSync())
402429
{
403430
m_actionsQueue.emplace_back([this, &channel] () {
@@ -825,7 +852,8 @@ void Mediator::UpdateChannels()
825852

826853
if (state != Lightning::Channel::State::None &&
827854
state != Lightning::Channel::State::Closed &&
828-
state != Lightning::Channel::State::OpenFailed)
855+
state != Lightning::Channel::State::OpenFailed &&
856+
!IsChannelExpired(channel))
829857
{
830858
channel->Update();
831859
}
@@ -941,4 +969,11 @@ bool Mediator::IsInSync()
941969
return IsValidTimeStamp(tip.m_TimeStamp, kDefaultLaserTolerance);
942970
}
943971

972+
bool Mediator::IsChannelExpired(const std::unique_ptr<Channel>& channel)
973+
{
974+
Block::SystemState::Full tip;
975+
get_History().get_Tip(tip);
976+
return tip.m_Height >= channel->get_LockHeight() + channel->m_Params.m_hLockTime + channel->m_Params.m_hPostLockReserve;
977+
}
978+
944979
} // namespace beam::wallet::laser

wallet/laser/mediator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class Mediator : public IChannelHolder, public proto::FlyClient
108108
void Subscribe();
109109
void Unsubscribe();
110110
bool IsInSync();
111+
bool IsChannelExpired(const std::unique_ptr<Channel>& channel);
111112

112113
IWalletDB::Ptr m_pWalletDB;
113114
proto::FlyClient::INetwork::Ptr m_pConnection;

0 commit comments

Comments
 (0)