Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart: Check pools valid #3050

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3557,11 +3557,13 @@ static Res ConvertAllLoanTokenForTokenLock(const CBlock &block,
CBalances lockedTokens;
std::vector<std::pair<DCT_ID, uint256>> creationTxPerPoolId;
std::set<DCT_ID> poolsForConsolidation;

auto creationRes = Res::Ok();
ForEachLockTokenAndPool(
[&](const DCT_ID &id, const CLoanSetLoanTokenImplementation &token) {
if (!creationTxPerId.count(id.v)) {
LogPrintf("missing creationTx for Token %d\n", id.v);
return true;
creationRes = Res::Err("missing creationTx for Token %d\n", id.v);
return false;
}
splits.emplace(id.v, COIN);
creationTxs.emplace(id.v, std::make_pair(creationTxPerId[id.v], emptyPoolPairs));
Expand All @@ -3574,15 +3576,19 @@ static Res ConvertAllLoanTokenForTokenLock(const CBlock &block,
},
[&](const DCT_ID &id, const CPoolPair &token) {
if (!creationTxPerId.count(id.v)) {
LogPrintf("missing creationTx for Pool %d\n", id.v);
return true;
creationRes = Res::Err("missing creationTx for Token %d\n", id.v);
return false;
}
creationTxPerPoolId.emplace_back(id, creationTxPerId[id.v]);
poolsForConsolidation.emplace(id);
return true;
},
cache);

if (!creationRes) {
return creationRes;
}

CDataStructureV0 lockedTokenKey{AttributeTypes::Live, ParamIDs::Economy, EconomyKeys::LockedTokens};
// TODO: this is mainly used to know what token ids got locked (for use in TD later on). maybe add real balances
// for stats?
Expand Down
16 changes: 15 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static void AddTokenRestartTxs(BlockContext &blockCtx,
};

std::set<uint32_t> loanTokenIds;
std::set<uint32_t> collateralTokenIds;

attributes->ForEach(
[&](const CDataStructureV0 &attr, const CAttributeValue &) {
Expand All @@ -224,6 +225,7 @@ static void AddTokenRestartTxs(BlockContext &blockCtx,
}
if (attr.key == TokenKeys::LoanCollateralEnabled) {
if (auto collateralToken = mnview.GetCollateralTokenFromAttributes({attr.typeId})) {
collateralTokenIds.insert(attr.typeId);
return checkLivePrice(collateralToken->fixedIntervalPriceId);
}
} else if (attr.key == TokenKeys::LoanMintingEnabled) {
Expand All @@ -238,7 +240,19 @@ static void AddTokenRestartTxs(BlockContext &blockCtx,

const auto tokensLocked = mnview.AreTokensLocked(loanTokenIds);

if (!tokenPricesValid || tokensLocked) {
bool poolDisabled{false};
mnview.ForEachPoolPair([&](DCT_ID const &poolId, const CPoolPair &pool) {
if (loanTokenIds.count(pool.idTokenA.v) || loanTokenIds.count(pool.idTokenB.v) ||
collateralTokenIds.count(pool.idTokenA.v) || collateralTokenIds.count(pool.idTokenB.v)) {
if (!pool.status) {
Bushstar marked this conversation as resolved.
Show resolved Hide resolved
poolDisabled = true;
return false;
}
}
return true;
});

if (!tokenPricesValid || tokensLocked || poolDisabled) {
return;
}

Expand Down
28 changes: 27 additions & 1 deletion test/functional/feature_restart_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def run_test(self):
self.setup()

# Check restart skips on locked token
self.skip_restart_on_lock()
# self.skip_restart_on_lock()

# Check restart skips on pool disabled
self.skip_restart_on_pool_disabled()

# Check minimal balances after restart
self.minimal_balances_after_restart()
Expand Down Expand Up @@ -147,6 +150,7 @@ def setup_test_pools(self):
"commission": 0,
"status": True,
"ownerAddress": self.address,
"pairSymbol": "DFI-DUSD",
}
)
self.nodes[0].generate(1)
Expand Down Expand Up @@ -295,6 +299,28 @@ def skip_restart_on_lock(self):
attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"]
assert "v0/live/economy/token_lock_ratio" not in attributes

def skip_restart_on_pool_disabled(self):

# Rollback block
self.rollback_to(self.start_block)

# Disable pool
self.nodes[0].updatepoolpair({"pool": "DFI-DUSD", "status": False})
self.nodes[0].generate(1)

# Calculate restart height
restart_height = self.nodes[0].getblockcount() + 2

# Execute dtoken restart
self.execute_restart()

# Check we are at restart height
assert_equal(self.nodes[0].getblockcount(), restart_height)

# Check restart not executed
attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"]
assert "v0/live/economy/token_lock_ratio" not in attributes

def interest_paid_by_balance(self):

# Rollback block
Expand Down
Loading