Skip to content

Commit 93bd0c7

Browse files
authored
refactor: rename assetLockedAmount in CbTx to creditPoolBalance (#5526)
## Issue being fixed or feature implemented Bad naming is noticed in #5026 by thephez ## What was done? Renamed `assetLockedAmount` in CbTx to `creditPoolBalance` Renamed also some local variables and functions to make it matched also. ## How Has This Been Tested? Run functional/unit tests - succeed Called python's rpc binding `node.getblock(block_hash)['cbTx']`: Got this result: ``` {'version': 3, 'height': 1556, 'merkleRootMNList': '978b2b4d1b884de62799b9eaee75c7812fea59f98f80d5ff9c963b0f0f195e14', 'merkleRootQuorums': 'bc7a34eb114f4e4bf38a11080b5d8ac41bdb36dd41e17467bae23c94ba06b013', 'bestCLHeightDiff': 0, 'bestCLSignature': '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 'creditPoolBalance': Decimal('7.00141421')} ``` ## Breaking Changes Renamed `assetLockedAmount` in CbTx to `creditPoolBalance`. @shumkov be informed ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
1 parent a679f8b commit 93bd0c7

File tree

7 files changed

+52
-52
lines changed

7 files changed

+52
-52
lines changed

src/evo/cbtx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ bool CalcCbTxBestChainlock(const llmq::CChainLocksHandler& chainlock_handler, co
432432

433433
std::string CCbTx::ToString() const
434434
{
435-
return strprintf("CCbTx(nVersion=%d, nHeight=%d, merkleRootMNList=%s, merkleRootQuorums=%s, bestCLHeightDiff=%d, bestCLSig=%s, assetLockedAmount=%d.%08d)",
435+
return strprintf("CCbTx(nVersion=%d, nHeight=%d, merkleRootMNList=%s, merkleRootQuorums=%s, bestCLHeightDiff=%d, bestCLSig=%s, creditPoolBalance=%d.%08d)",
436436
nVersion, nHeight, merkleRootMNList.ToString(), merkleRootQuorums.ToString(), bestCLHeightDiff, bestCLSignature.ToString(),
437-
assetLockedAmount / COIN, assetLockedAmount % COIN);
437+
creditPoolBalance / COIN, creditPoolBalance % COIN);
438438
}
439439

440440
std::optional<CCbTx> GetCoinbaseTx(const CBlockIndex* pindex)

src/evo/cbtx.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CCbTx
3737
uint256 merkleRootQuorums;
3838
uint32_t bestCLHeightDiff;
3939
CBLSSignature bestCLSignature;
40-
CAmount assetLockedAmount{0};
40+
CAmount creditPoolBalance{0};
4141

4242
SERIALIZE_METHODS(CCbTx, obj)
4343
{
@@ -48,7 +48,7 @@ class CCbTx
4848
if (obj.nVersion >= CB_V20_VERSION) {
4949
READWRITE(COMPACTSIZE(obj.bestCLHeightDiff));
5050
READWRITE(obj.bestCLSignature);
51-
READWRITE(obj.assetLockedAmount);
51+
READWRITE(obj.creditPoolBalance);
5252
}
5353
}
5454

@@ -68,7 +68,7 @@ class CCbTx
6868
if (nVersion >= CB_V20_VERSION) {
6969
obj.pushKV("bestCLHeightDiff", static_cast<int>(bestCLHeightDiff));
7070
obj.pushKV("bestCLSignature", bestCLSignature.ToString());
71-
obj.pushKV("assetLockedAmount", ValueFromAmount(assetLockedAmount));
71+
obj.pushKV("creditPoolBalance", ValueFromAmount(creditPoolBalance));
7272
}
7373
}
7474
}

src/evo/creditpool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo
142142
if (!GetTxPayload(block->vtx[0]->vExtraPayload, cbTx)) {
143143
throw std::runtime_error(strprintf("%s: failed-getcreditpool-cbtx-payload", __func__));
144144
}
145-
locked = cbTx.assetLockedAmount;
145+
locked = cbTx.creditPoolBalance;
146146
}
147147

148148
// We use here sliding window with LimitBlocksToTrace to determine
@@ -226,7 +226,7 @@ bool CCreditPoolDiff::SetTarget(const CTransaction& tx, TxValidationState& state
226226
}
227227

228228
if (cbTx.nVersion == 3) {
229-
targetLocked = cbTx.assetLockedAmount;
229+
targetBalance = cbTx.creditPoolBalance;
230230
}
231231
return true;
232232
}

src/evo/creditpool.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CCreditPoolDiff {
6969
CAmount sessionUnlocked{0};
7070

7171
// target value is used to validate CbTx. If values mismatched, block is invalid
72-
std::optional<CAmount> targetLocked;
72+
std::optional<CAmount> targetBalance;
7373

7474
const CBlockIndex *pindex{nullptr};
7575
public:
@@ -86,12 +86,12 @@ class CCreditPoolDiff {
8686
return pool.locked + sessionLocked - sessionUnlocked;
8787
}
8888

89-
const std::optional<CAmount>& GetTargetLocked() const {
90-
return targetLocked;
89+
const std::optional<CAmount>& GetTargetBalance() const {
90+
return targetBalance;
9191
}
9292

9393
std::string ToString() const {
94-
return strprintf("CCreditPoolDiff(target=%lld, sessionLocked=%lld, sessionUnlocked=%lld, newIndexes=%lld, pool=%s)", GetTargetLocked() ? *GetTargetLocked() : -1, sessionLocked, sessionUnlocked, newIndexes.size(), pool.ToString());
94+
return strprintf("CCreditPoolDiff(target=%lld, sessionLocked=%lld, sessionUnlocked=%lld, newIndexes=%lld, pool=%s)", GetTargetBalance() ? *GetTargetBalance() : -1, sessionLocked, sessionUnlocked, newIndexes.size(), pool.ToString());
9595
}
9696

9797
private:

src/evo/specialtxman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, ll
160160
}
161161
if (creditPoolDiff != std::nullopt) {
162162
CAmount locked_proposed{0};
163-
if(creditPoolDiff->GetTargetLocked()) locked_proposed = *creditPoolDiff->GetTargetLocked();
163+
if(creditPoolDiff->GetTargetBalance()) locked_proposed = *creditPoolDiff->GetTargetBalance();
164164

165165
CAmount locked_calculated = creditPoolDiff->GetTotalLocked();
166166
if (locked_proposed != locked_calculated) {

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
231231
LogPrintf("CreateNewBlock() h[%d] CbTx failed to find best CL. Inserting null CL\n", nHeight);
232232
}
233233
assert(creditPoolDiff != std::nullopt);
234-
cbTx.assetLockedAmount = creditPoolDiff->GetTotalLocked();
234+
cbTx.creditPoolBalance = creditPoolDiff->GetTotalLocked();
235235
}
236236
}
237237

test/functional/feature_asset_locks.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,18 @@ def create_assetunlock(self, index, withdrawal, pubkey=None, fee=tiny_amount):
117117
unlock_tx.vExtraPayload = unlockTx_payload.serialize()
118118
return unlock_tx
119119

120-
def get_credit_pool_amount(self, node = None, block_hash = None):
120+
def get_credit_pool_balance(self, node = None, block_hash = None):
121121
if node is None:
122122
node = self.nodes[0]
123123

124124
if block_hash is None:
125125
block_hash = node.getbestblockhash()
126126
block = node.getblock(block_hash)
127-
return int(COIN * block['cbTx']['assetLockedAmount'])
127+
return int(COIN * block['cbTx']['creditPoolBalance'])
128128

129-
def validate_credit_pool_amount(self, expected = None, block_hash = None):
129+
def validate_credit_pool_balance(self, expected = None, block_hash = None):
130130
for node in self.nodes:
131-
locked = self.get_credit_pool_amount(node=node, block_hash=block_hash)
131+
locked = self.get_credit_pool_balance(node=node, block_hash=block_hash)
132132
if expected is None:
133133
expected = locked
134134
else:
@@ -241,38 +241,38 @@ def run_test(self):
241241
asset_lock_tx = self.create_assetlock(coin, locked_1, pubkey)
242242

243243
self.check_mempool_result(tx=asset_lock_tx, result_expected={'allowed': True})
244-
self.validate_credit_pool_amount(0)
244+
self.validate_credit_pool_balance(0)
245245
txid_in_block = self.send_tx(asset_lock_tx)
246-
self.validate_credit_pool_amount(0)
246+
self.validate_credit_pool_balance(0)
247247
node.generate(1)
248-
assert_equal(self.get_credit_pool_amount(node=node_wallet), 0)
249-
assert_equal(self.get_credit_pool_amount(node=node), locked_1)
248+
assert_equal(self.get_credit_pool_balance(node=node_wallet), 0)
249+
assert_equal(self.get_credit_pool_balance(node=node), locked_1)
250250
self.log.info("Generate a number of blocks to ensure this is the longest chain for later in the test when we reconsiderblock")
251251
node.generate(12)
252252
self.sync_all()
253253

254-
self.validate_credit_pool_amount(locked_1)
254+
self.validate_credit_pool_balance(locked_1)
255255

256256
# tx is mined, let's get blockhash
257257
self.log.info("Invalidate block with asset lock tx...")
258258
block_hash_1 = node_wallet.gettransaction(txid_in_block)['blockhash']
259259
for inode in self.nodes:
260260
inode.invalidateblock(block_hash_1)
261-
assert_equal(self.get_credit_pool_amount(node=inode), 0)
261+
assert_equal(self.get_credit_pool_balance(node=inode), 0)
262262
node.generate(3)
263263
self.sync_all()
264-
self.validate_credit_pool_amount(0)
264+
self.validate_credit_pool_balance(0)
265265
self.log.info("Resubmit asset lock tx to new chain...")
266266
# NEW tx appears
267267
asset_lock_tx_2 = self.create_assetlock(coin, locked_2, pubkey)
268268
txid_in_block = self.send_tx(asset_lock_tx_2)
269269
node.generate(1)
270270
self.sync_all()
271-
self.validate_credit_pool_amount(locked_2)
271+
self.validate_credit_pool_balance(locked_2)
272272
self.log.info("Reconsider old blocks...")
273273
for inode in self.nodes:
274274
inode.reconsiderblock(block_hash_1)
275-
self.validate_credit_pool_amount(locked_1)
275+
self.validate_credit_pool_balance(locked_1)
276276
self.sync_all()
277277

278278
self.log.info('Mine block with incorrect credit-pool value...')
@@ -281,7 +281,7 @@ def run_test(self):
281281

282282
self.log.info("Mine a quorum...")
283283
self.mine_quorum()
284-
self.validate_credit_pool_amount(locked_1)
284+
self.validate_credit_pool_balance(locked_1)
285285

286286
self.log.info("Testing asset unlock...")
287287
asset_unlock_tx_index_too_far = self.create_assetunlock(10001, COIN, pubkey)
@@ -294,7 +294,7 @@ def run_test(self):
294294
self.ensure_tx_is_not_mined(tx_too_far_index)
295295

296296
self.log.info("Generating several txes by same quorum....")
297-
self.validate_credit_pool_amount(locked_1)
297+
self.validate_credit_pool_balance(locked_1)
298298
asset_unlock_tx = self.create_assetunlock(101, COIN, pubkey)
299299
asset_unlock_tx_late = self.create_assetunlock(102, COIN, pubkey)
300300
asset_unlock_tx_too_late = self.create_assetunlock(103, COIN, pubkey)
@@ -322,11 +322,11 @@ def run_test(self):
322322
self.send_tx(asset_unlock_tx)
323323
self.mempool_size += 1
324324
self.check_mempool_size()
325-
self.validate_credit_pool_amount(locked_1)
325+
self.validate_credit_pool_balance(locked_1)
326326
self.log.info("Mining one block - index '10001' can't be included in this block")
327327
node.generate(1)
328328
self.sync_all()
329-
self.validate_credit_pool_amount(locked_1 - COIN)
329+
self.validate_credit_pool_balance(locked_1 - COIN)
330330
self.mempool_size -= 1
331331
self.check_mempool_size()
332332
self.log.info("Tx should not be mined yet... mine one more block")
@@ -347,20 +347,20 @@ def run_test(self):
347347
reason = "double index")
348348

349349
self.log.info("Checking tx with too far index is mined too - it is not too far anymore...")
350-
self.validate_credit_pool_amount(locked_1 - 2 * COIN)
350+
self.validate_credit_pool_balance(locked_1 - 2 * COIN)
351351
self.nodes[0].getrawtransaction(tx_too_far_index, 1)['blockhash']
352352

353353
self.log.info("Mining next quorum to check tx 'asset_unlock_tx_late' is still valid...")
354354
self.mine_quorum()
355355
self.log.info("Checking credit pool amount is same...")
356-
self.validate_credit_pool_amount(locked_1 - 2 * COIN)
356+
self.validate_credit_pool_balance(locked_1 - 2 * COIN)
357357
self.check_mempool_result(tx=asset_unlock_tx_late, result_expected={'allowed': True})
358358
self.log.info("Checking credit pool amount still is same...")
359-
self.validate_credit_pool_amount(locked_1 - 2 * COIN)
359+
self.validate_credit_pool_balance(locked_1 - 2 * COIN)
360360
self.send_tx(asset_unlock_tx_late)
361361
node.generate(1)
362362
self.sync_all()
363-
self.validate_credit_pool_amount(locked_1 - 3 * COIN)
363+
self.validate_credit_pool_balance(locked_1 - 3 * COIN)
364364

365365
self.log.info("Generating many blocks to make quorum far behind (even still active)...")
366366
self.slowly_generate_batch(too_late_height - node.getblock(node.getbestblockhash())["height"] - 1)
@@ -380,24 +380,24 @@ def run_test(self):
380380
self.log.info("Test block invalidation with asset unlock tx...")
381381
for inode in self.nodes:
382382
inode.invalidateblock(block_asset_unlock)
383-
self.validate_credit_pool_amount(locked_1)
383+
self.validate_credit_pool_balance(locked_1)
384384
self.slowly_generate_batch(50)
385-
self.validate_credit_pool_amount(locked_1)
385+
self.validate_credit_pool_balance(locked_1)
386386
for inode in self.nodes:
387387
inode.reconsiderblock(block_to_reconsider)
388-
self.validate_credit_pool_amount(locked_1 - 3 * COIN)
388+
self.validate_credit_pool_balance(locked_1 - 3 * COIN)
389389

390390
self.log.info("Forcibly mining asset_unlock_tx_too_late and ensure block is invalid...")
391391
self.create_and_check_block([asset_unlock_tx_too_late], expected_error = "bad-assetunlock-not-active-quorum")
392392

393393
node.generate(1)
394394
self.sync_all()
395395

396-
self.validate_credit_pool_amount(locked_1 - 3 * COIN)
397-
self.validate_credit_pool_amount(block_hash=block_hash_1, expected=locked_1)
396+
self.validate_credit_pool_balance(locked_1 - 3 * COIN)
397+
self.validate_credit_pool_balance(block_hash=block_hash_1, expected=locked_1)
398398

399399
self.log.info("Checking too big withdrawal... expected to not be mined")
400-
asset_unlock_tx_full = self.create_assetunlock(201, 1 + self.get_credit_pool_amount(), pubkey)
400+
asset_unlock_tx_full = self.create_assetunlock(201, 1 + self.get_credit_pool_balance(), pubkey)
401401

402402
self.log.info("Checking that transaction with exceeding amount accepted by mempool...")
403403
# Mempool doesn't know about the size of the credit pool
@@ -413,7 +413,7 @@ def run_test(self):
413413
self.create_and_check_block([asset_unlock_tx_full], expected_error = "failed-creditpool-unlock-too-much")
414414

415415
self.mempool_size += 1
416-
asset_unlock_tx_full = self.create_assetunlock(301, self.get_credit_pool_amount(), pubkey)
416+
asset_unlock_tx_full = self.create_assetunlock(301, self.get_credit_pool_balance(), pubkey)
417417
self.check_mempool_result(tx=asset_unlock_tx_full, result_expected={'allowed': True })
418418

419419
txid_in_block = self.send_tx(asset_unlock_tx_full)
@@ -422,7 +422,7 @@ def run_test(self):
422422
self.log.info("Check txid_in_block was mined...")
423423
block = node.getblock(node.getbestblockhash())
424424
assert txid_in_block in block['tx']
425-
self.validate_credit_pool_amount(0)
425+
self.validate_credit_pool_balance(0)
426426

427427
self.log.info("After many blocks duplicated tx still should not be mined")
428428
self.send_tx(asset_unlock_tx_duplicate_index,
@@ -436,7 +436,7 @@ def run_test(self):
436436
self.slowly_generate_batch(blocks_in_one_day + 1)
437437
self.mine_quorum()
438438

439-
total = self.get_credit_pool_amount()
439+
total = self.get_credit_pool_balance()
440440
while total <= 10_900 * COIN:
441441
self.log.info(f"Collecting coins in pool... Collected {total}/{10_900 * COIN}")
442442
coin = coins.pop()
@@ -449,8 +449,8 @@ def run_test(self):
449449
self.sync_mempools()
450450
node.generate(1)
451451
self.sync_all()
452-
credit_pool_amount_1 = self.get_credit_pool_amount()
453-
assert_greater_than(credit_pool_amount_1, 10_900 * COIN)
452+
credit_pool_balance_1 = self.get_credit_pool_balance()
453+
assert_greater_than(credit_pool_balance_1, 10_900 * COIN)
454454
limit_amount_1 = 1000 * COIN
455455
# take most of limit by one big tx for faster testing and
456456
# create several tiny withdrawal with exactly 1 *invalid* / causes spend above limit tx
@@ -469,7 +469,7 @@ def run_test(self):
469469
node.generate(1)
470470
self.sync_all()
471471

472-
new_total = self.get_credit_pool_amount()
472+
new_total = self.get_credit_pool_balance()
473473
amount_actually_withdrawn = total - new_total
474474
block = node.getblock(node.getbestblockhash())
475475
self.log.info("Testing that we tried to withdraw more than we could...")
@@ -485,26 +485,26 @@ def run_test(self):
485485
self.mempool_size = 1
486486
self.check_mempool_size()
487487

488-
assert_equal(new_total, self.get_credit_pool_amount())
488+
assert_equal(new_total, self.get_credit_pool_balance())
489489
self.log.info("Fast forward to next day again...")
490490
self.slowly_generate_batch(blocks_in_one_day - 2)
491491
self.log.info("Checking mempool is empty now...")
492492
self.mempool_size = 0
493493
self.check_mempool_size()
494494

495495
self.log.info("Creating new asset-unlock tx. It should be mined exactly 1 block after")
496-
credit_pool_amount_2 = self.get_credit_pool_amount()
497-
limit_amount_2 = credit_pool_amount_2 // 10
496+
credit_pool_balance_2 = self.get_credit_pool_balance()
497+
limit_amount_2 = credit_pool_balance_2 // 10
498498
index += 1
499499
asset_unlock_tx = self.create_assetunlock(index, limit_amount_2, pubkey)
500500
self.send_tx(asset_unlock_tx)
501501
node.generate(1)
502502
self.sync_all()
503-
assert_equal(new_total, self.get_credit_pool_amount())
503+
assert_equal(new_total, self.get_credit_pool_balance())
504504
node.generate(1)
505505
self.sync_all()
506506
new_total -= limit_amount_2
507-
assert_equal(new_total, self.get_credit_pool_amount())
507+
assert_equal(new_total, self.get_credit_pool_balance())
508508
self.log.info("Trying to withdraw more... expecting to fail")
509509
index += 1
510510
asset_unlock_tx = self.create_assetunlock(index, COIN * 100, pubkey)
@@ -515,7 +515,7 @@ def run_test(self):
515515
self.log.info("generate many blocks to be sure that mempool is empty afterwards...")
516516
self.slowly_generate_batch(60)
517517
self.log.info("Checking that credit pool is not changed...")
518-
assert_equal(new_total, self.get_credit_pool_amount())
518+
assert_equal(new_total, self.get_credit_pool_balance())
519519
self.check_mempool_size()
520520

521521
if __name__ == '__main__':

0 commit comments

Comments
 (0)