Skip to content

Commit

Permalink
Restart: Check pools valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Sep 16, 2024
1 parent a0ac5bc commit 89eaabb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/dfi/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1626,9 +1626,12 @@ static Res PoolSplits(CCustomCSView &view,
pindex->nHeight,
poolCreationTxs.size());

if (poolCreationTxs.empty()) {
return Res::Err("No pool creation transactions found");
}

try {
const std::string oldPoolSuffix = "/v";
assert(poolCreationTxs.size());
for (const auto &[oldPoolId, creationTx] : poolCreationTxs) {
auto loopTime = GetTimeMillis();
auto oldPoolToken = view.GetToken(oldPoolId);
Expand Down
13 changes: 12 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,18 @@ 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)) {
if (!pool.status) {
poolDisabled = true;
return false;
}
}
return true;
});

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

Expand Down
30 changes: 29 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,30 @@ 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

assert False

def interest_paid_by_balance(self):

# Rollback block
Expand Down

0 comments on commit 89eaabb

Please sign in to comment.