Skip to content

Commit

Permalink
Revert pool find rewards changes (#1064)
Browse files Browse the repository at this point in the history
* Revert "Update value on pool pair suitable finding"

This reverts commit ec12c8f.

* Revert "Adjust pool reward height to Fort Canning Hill"

This reverts commit 11ce566.

* Revert "Fix pool rewards starting after actual share"

This reverts commit 784fc6b.
  • Loading branch information
Bushstar authored Jan 26, 2022
1 parent a6537c0 commit 532fca7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
31 changes: 5 additions & 26 deletions src/masternodes/poolpairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,6 @@ void ReadValueMoveToNext(TIterator & it, DCT_ID poolId, ValueType & value, uint3
}
}

template<typename TIterator, typename ValueType>
void FindSuitablePoolRewards(TIterator & it, PoolHeightKey poolKey, uint32_t endHeight, ValueType & value, uint32_t & height) {

static const auto poolStartHeight = uint32_t(Params().GetConsensus().FortCanningHillHeight);
poolKey.height = std::max(poolKey.height, poolStartHeight);

while (!it.Valid() && poolKey.height < endHeight) {
poolKey.height++;
it.Seek(poolKey);
}

if (it.Valid() && it.Key().poolID == poolKey.poolID) {
value = it.Value();
height = it.Key().height;
} else {
height = UINT_MAX;
}
}

void CPoolPairView::CalculatePoolRewards(DCT_ID const & poolId, std::function<CAmount()> onLiquidity, uint32_t begin, uint32_t end, std::function<void(RewardType, CTokenAmount, uint32_t)> onReward) {
if (begin >= end) {
return;
Expand All @@ -250,14 +231,11 @@ void CPoolPairView::CalculatePoolRewards(DCT_ID const & poolId, std::function<CA
PoolHeightKey poolKey = {poolId, begin};

CAmount poolReward = 0;
auto nextPoolReward = begin;
auto itPoolReward = LowerBound<ByPoolReward>(poolKey);
FindSuitablePoolRewards(itPoolReward, poolKey, end, poolReward, nextPoolReward);

CAmount poolLoanReward = 0;
auto nextPoolReward = begin;
auto nextPoolLoanReward = begin;
auto itPoolReward = LowerBound<ByPoolReward>(poolKey);
auto itPoolLoanReward = LowerBound<ByPoolLoanReward>(poolKey);
FindSuitablePoolRewards(itPoolLoanReward, poolKey, end, poolLoanReward, nextPoolLoanReward);

CAmount totalLiquidity = 0;
auto nextTotalLiquidity = begin;
Expand All @@ -266,13 +244,14 @@ void CPoolPairView::CalculatePoolRewards(DCT_ID const & poolId, std::function<CA
CBalances customRewards;
auto nextCustomRewards = begin;
auto itCustomRewards = LowerBound<ByCustomReward>(poolKey);
FindSuitablePoolRewards(itCustomRewards, poolKey, end, customRewards, nextCustomRewards);

PoolSwapValue poolSwap;
auto nextPoolSwap = UINT_MAX;
auto poolSwapHeight = UINT_MAX;
auto itPoolSwap = LowerBound<ByPoolSwap>(poolKey);
FindSuitablePoolRewards(itPoolSwap, poolKey, end, poolSwap, nextPoolSwap);
if (itPoolSwap.Valid() && itPoolSwap.Key().poolID == poolId) {
nextPoolSwap = itPoolSwap.Key().height;
}

for (auto height = begin; height < end;) {
// find suitable pool liquidity
Expand Down
16 changes: 0 additions & 16 deletions src/test/storage_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,22 +463,6 @@ BOOST_AUTO_TEST_CASE(LowerBoundTest)
BOOST_CHECK(it.Valid());
BOOST_CHECK(it.Value().as<int>() == 2);
}

{
CCustomCSView view(*pcustomcsview);
view.WriteBy<TestBackward>(TestBackward{5}, 1);
view.WriteBy<TestBackward>(TestBackward{6}, 2);

auto start = TestBackward{0};
auto it = view.LowerBound<TestBackward>(start);
while (!it.Valid()) {
start.n++;
it.Seek(start);
}
BOOST_REQUIRE(it.Valid());
BOOST_CHECK_EQUAL(start.n, 5);
BOOST_CHECK_EQUAL(it.Key().n, 5);
}
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 532fca7

Please sign in to comment.