Skip to content

Commit 4e971d5

Browse files
harshadptlweikengchen
authored and
shaorongqiang
committedNov 1, 2023
Fix failure for DefineAsset and IssueAsset operation sent in same txn (#1022)
* Fix failure for DefineAsset and IssueAsset operation sent in same txn The DefineAsset Operation has the raw asset code whereas IssueAsset Operation has the derived asset code. Currently if both the operations are sent in the same txn for a new asset it fails because the Asset code don't match. This is fixed by comparing the derived asset code from newly defined assets in the txn. * lint * fix docker image build * fix lint * lint * lint * Remove fix for testing * trigger build * trigger github actions * Revert "Remove fix for testing" This reverts commit df1f070. * fix typo in yaml of CLI * Update mod.rs --------- Co-authored-by: Weikeng Chen <w.k@berkeley.edu>
1 parent b8b7b2e commit 4e971d5

File tree

6 files changed

+43
-24
lines changed

6 files changed

+43
-24
lines changed
 

‎src/components/abciapp/src/abci/server/callback/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ pub fn deliver_tx(
532532
}
533533

534534
/// putting block in the ledgerState
535+
#[allow(noop_method_call)]
535536
pub fn end_block(
536537
s: &mut ABCISubmissionServer,
537538
req: &RequestEndBlock,

‎src/components/abciapp/src/abci/staking/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub fn get_validators(
233233
/// - pay delegation rewards
234234
/// - pay proposer rewards(traditional block rewards)
235235
/// - do governance operations
236+
#[allow(noop_method_call)]
236237
pub fn system_ops(
237238
la: &mut LedgerState,
238239
header: &Header,

‎src/components/finutils/src/bins/fn.yml

+18-18
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ subcommands:
158158
- use-default-eth-address:
159159
help: use a private key of the eth address if `staker-priv-key` is not provided
160160
long: use-default-eth-address
161-
conflicts-with:
161+
conflicts_with:
162162
- staker-priv-key
163163
- claim:
164164
about: Claim accumulated FRA rewards
@@ -183,7 +183,7 @@ subcommands:
183183
- use-default-eth-address:
184184
help: use a private key of the eth address if `seckey` is not provided
185185
long: use-default-eth-address
186-
conflicts-with:
186+
conflicts_with:
187187
- seckey
188188
- delegate:
189189
about: Delegating operations
@@ -213,7 +213,7 @@ subcommands:
213213
- use-default-eth-address:
214214
help: use a private key of the eth address if `seckey` is not provided
215215
long: use-default-eth-address
216-
conflicts-with:
216+
conflicts_with:
217217
- seckey
218218
- undelegate:
219219
about: Undelegating operations
@@ -237,7 +237,7 @@ subcommands:
237237
- use-default-eth-address:
238238
help: use a private key of the eth address if `seckey` is not provided
239239
long: use-default-eth-address
240-
conflicts-with:
240+
conflicts_with:
241241
- seckey
242242
- transfer:
243243
about: Transfer tokens from one address to another
@@ -285,7 +285,7 @@ subcommands:
285285
- use-default-eth-address:
286286
help: use a private key of the eth address if `from-seckey` is not provided
287287
long: use-default-eth-address
288-
conflicts-with:
288+
conflicts_with:
289289
- from-seckey
290290
- transfer-batch:
291291
about: Transfer tokens from one address to many others
@@ -324,7 +324,7 @@ subcommands:
324324
- use-default-eth-address:
325325
help: use a private key of the eth address if `from-seckey` is not provided
326326
long: use-default-eth-address
327-
conflicts-with:
327+
conflicts_with:
328328
- from-seckey
329329
- wallet:
330330
about: manipulates a findora wallet
@@ -355,14 +355,14 @@ subcommands:
355355
- gen-eth-address:
356356
help: generate the keypair of an eth address
357357
long: gen-eth-address
358-
conflicts-with:
358+
conflicts_with:
359359
- show
360360
- seckey
361361
- asset
362362
- use-default-eth-address:
363363
help: use a private key of the eth address if `seckey` is not provided
364364
long: use-default-eth-address
365-
conflicts-with:
365+
conflicts_with:
366366
- seckey
367367
- create
368368
- asset:
@@ -466,7 +466,7 @@ subcommands:
466466
- use-default-eth-address:
467467
help: use a private key of the eth address if `seckey` is not provided
468468
long: use-default-eth-address
469-
conflicts-with:
469+
conflicts_with:
470470
- seckey
471471
- account:
472472
about: Return user contract account information or the balance if secret key is provided
@@ -492,7 +492,7 @@ subcommands:
492492
- use-default-eth-address:
493493
help: use a private key of the eth address if `sec-key` is not provided
494494
long: use-default-eth-address
495-
conflicts-with:
495+
conflicts_with:
496496
- sec-key
497497
- contract-deposit:
498498
about: Transfer an asset from the UTXO chain to the EVM chain
@@ -582,7 +582,7 @@ subcommands:
582582
- use-default-eth-address:
583583
help: use a private key of the eth address if `from-seckey` is not provided
584584
long: use-default-eth-address
585-
conflicts-with:
585+
conflicts_with:
586586
- from-seckey
587587
- anon-balance:
588588
about: List Anon balance and spending status for a public key and a list of commitments
@@ -611,7 +611,7 @@ subcommands:
611611
- use-default-eth-address:
612612
help: use a private key of the eth address if `from-seckey` is not provided
613613
long: use-default-eth-address
614-
conflicts-with:
614+
conflicts_with:
615615
- from-seckey
616616
- owned-open-abars:
617617
about: Get Open Anon UTXOs for a keypair using commitment
@@ -634,7 +634,7 @@ subcommands:
634634
- use-default-eth-address:
635635
help: use a private key of the eth address if `from-seckey` is not provided
636636
long: use-default-eth-address
637-
conflicts-with:
637+
conflicts_with:
638638
- from-seckey
639639
- owned-utxos:
640640
about: List owned UTXOs for a public key
@@ -674,7 +674,7 @@ subcommands:
674674
- use-default-eth-address:
675675
help: use a private key of the eth address if `from-seckey` is not provided
676676
long: use-default-eth-address
677-
conflicts-with:
677+
conflicts_with:
678678
- from-seckey
679679
- convert-abar-to-bar:
680680
about: Convert an ABAR to BAR
@@ -717,7 +717,7 @@ subcommands:
717717
- use-default-eth-address:
718718
help: use a private key of the eth address if `from-seckey` is not provided
719719
long: use-default-eth-address
720-
conflicts-with:
720+
conflicts_with:
721721
- from-seckey
722722
- anon-transfer:
723723
about: Perform an anonymous transfer
@@ -759,7 +759,7 @@ subcommands:
759759
- use-default-eth-address:
760760
help: use a private key of the eth address if `from-seckey` is not provided
761761
long: use-default-eth-address
762-
conflicts-with:
762+
conflicts_with:
763763
- from-seckey
764764
- anon-transfer-batch:
765765
about: Anonymous Transfer of tokens from multiple inputs to multiple outputs
@@ -801,7 +801,7 @@ subcommands:
801801
- use-default-eth-address:
802802
help: use a private key of the eth address if `from-seckey` is not provided
803803
long: use-default-eth-address
804-
conflicts-with:
804+
conflicts_with:
805805
- from-seckey
806806
- anon-fetch-merkle-proof:
807807
about: Query Merkle tree leaf info
@@ -834,7 +834,7 @@ subcommands:
834834
- use-default-eth-address:
835835
help: use a private key of the eth address if `from-seckey` is not provided
836836
long: use-default-eth-address
837-
conflicts-with:
837+
conflicts_with:
838838
- from-seckey
839839
- replace_staker:
840840
about: Replace the staker of the validator with target address

‎src/ledger/src/data_model/effects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl TxnEffect {
287287

288288
// (1), within this transaction
289289
//let v = vec![];
290-
let iss_nums = self.new_issuance_nums.entry(code).or_insert_with(Vec::new);
290+
let iss_nums = self.new_issuance_nums.entry(code).or_default();
291291

292292
if let Some(last_num) = iss_nums.last() {
293293
if seq_num <= *last_num {

‎src/ledger/src/staking/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ impl Staking {
809809
self.delegation_info
810810
.end_height_map
811811
.entry(end_height)
812-
.or_insert_with(BTreeSet::new)
812+
.or_default()
813813
.insert(owner);
814814

815815
// There should be no failure here !!
@@ -903,7 +903,7 @@ impl Staking {
903903
self.delegation_info
904904
.end_height_map
905905
.entry(h + CFG.checkpoint.unbond_block_cnt)
906-
.or_insert_with(BTreeSet::new)
906+
.or_default()
907907
.insert(*addr);
908908
}
909909

@@ -995,7 +995,7 @@ impl Staking {
995995
self.delegation_info
996996
.end_height_map
997997
.entry(h + CFG.checkpoint.unbond_block_cnt)
998-
.or_insert_with(BTreeSet::new)
998+
.or_default()
999999
.insert(pu.new_delegator_id);
10001000

10011001
// update delegator entries for pu target_validator
@@ -1078,7 +1078,7 @@ impl Staking {
10781078
self.delegation_info
10791079
.end_height_map
10801080
.entry(end_height)
1081-
.or_insert_with(BTreeSet::new)
1081+
.or_default()
10821082
.insert(addr.to_owned());
10831083
Ok(())
10841084
} else {

‎src/ledger/src/store/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,22 @@ impl LedgerStatus {
15471547
// Asset issuance should match the currently registered key
15481548
}
15491549

1550+
let get_effect_asset =
1551+
|derived_asset_code: &AssetTypeCode| -> Option<AssetType> {
1552+
for (code, asset) in &txn_effect.new_asset_codes {
1553+
let dc = AssetTypeCode::from_prefix_and_raw_asset_type_code(
1554+
AssetTypePrefix::UserDefined,
1555+
&code,
1556+
&CFG.checkpoint,
1557+
self.td_commit_height,
1558+
);
1559+
if dc == *derived_asset_code {
1560+
return Some(asset.clone());
1561+
}
1562+
}
1563+
None
1564+
};
1565+
15501566
// New issuance numbers
15511567
// (1) Must refer to a created asset type
15521568
// - NOTE: if the asset type is created in this transaction, this
@@ -1560,7 +1576,7 @@ impl LedgerStatus {
15601576
let asset_type = self
15611577
.asset_types
15621578
.get(&code)
1563-
.or_else(|| txn_effect.new_asset_codes.get(&code).cloned())
1579+
.or_else(|| get_effect_asset(&code))
15641580
.c(d!())?;
15651581
let proper_key = asset_type.properties.issuer;
15661582
if *iss_key != proper_key {
@@ -1715,6 +1731,7 @@ impl LedgerStatus {
17151731
//
17161732
// This drains every field of `block` except `txns` and `temp_sids`.
17171733
#[allow(unused_mut)]
1734+
#[allow(clippy::unwrap_or_default)]
17181735
fn apply_block_effects(&mut self, block: &mut BlockEffect) -> (TmpSidMap, u64, u64) {
17191736
let base_sid = self.next_txo.0;
17201737
let handle_asset_type_code = |code: AssetTypeCode| {

0 commit comments

Comments
 (0)
Please sign in to comment.