Skip to content

Commit

Permalink
Fix failure for DefineAsset and IssueAsset operation sent in same txn (
Browse files Browse the repository at this point in the history
…#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 <[email protected]>
  • Loading branch information
harshadptl and weikengchen authored Oct 18, 2023
1 parent 7b043ec commit feb40e8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ pub fn deliver_tx(
}

/// putting block in the ledgerState
#[allow(noop_method_call)]
pub fn end_block(
s: &mut ABCISubmissionServer,
req: &RequestEndBlock,
Expand Down
1 change: 1 addition & 0 deletions src/components/abciapp/src/abci/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ pub fn get_validators(
/// - pay delegation rewards
/// - pay proposer rewards(traditional block rewards)
/// - do governance operations
#[allow(noop_method_call)]
pub fn system_ops(
la: &mut LedgerState,
header: &Header,
Expand Down
36 changes: 18 additions & 18 deletions src/components/finutils/src/bins/fn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `staker-priv-key` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- staker-priv-key
- claim:
about: Claim accumulated FRA rewards
Expand All @@ -183,7 +183,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- seckey
- delegate:
about: Delegating operations
Expand Down Expand Up @@ -213,7 +213,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- seckey
- undelegate:
about: Undelegating operations
Expand All @@ -237,7 +237,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- seckey
- transfer:
about: Transfer tokens from one address to another
Expand Down Expand Up @@ -285,7 +285,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- transfer-batch:
about: Transfer tokens from one address to many others
Expand Down Expand Up @@ -324,7 +324,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- wallet:
about: manipulates a findora wallet
Expand Down Expand Up @@ -355,14 +355,14 @@ subcommands:
- gen-eth-address:
help: generate the keypair of an eth address
long: gen-eth-address
conflicts-with:
conflicts_with:
- show
- seckey
- asset
- use-default-eth-address:
help: use a private key of the eth address if `seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- seckey
- create
- asset:
Expand Down Expand Up @@ -466,7 +466,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- seckey
- account:
about: Return user contract account information or the balance if secret key is provided
Expand All @@ -492,7 +492,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `sec-key` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- sec-key
- contract-deposit:
about: Transfer an asset from the UTXO chain to the EVM chain
Expand Down Expand Up @@ -582,7 +582,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- anon-balance:
about: List Anon balance and spending status for a public key and a list of commitments
Expand Down Expand Up @@ -611,7 +611,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- owned-open-abars:
about: Get Open Anon UTXOs for a keypair using commitment
Expand All @@ -634,7 +634,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- owned-utxos:
about: List owned UTXOs for a public key
Expand Down Expand Up @@ -674,7 +674,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- convert-abar-to-bar:
about: Convert an ABAR to BAR
Expand Down Expand Up @@ -717,7 +717,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- anon-transfer:
about: Perform an anonymous transfer
Expand Down Expand Up @@ -759,7 +759,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- anon-transfer-batch:
about: Anonymous Transfer of tokens from multiple inputs to multiple outputs
Expand Down Expand Up @@ -801,7 +801,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- anon-fetch-merkle-proof:
about: Query Merkle tree leaf info
Expand Down Expand Up @@ -834,7 +834,7 @@ subcommands:
- use-default-eth-address:
help: use a private key of the eth address if `from-seckey` is not provided
long: use-default-eth-address
conflicts-with:
conflicts_with:
- from-seckey
- replace_staker:
about: Replace the staker of the validator with target address
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/src/data_model/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl TxnEffect {

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

if let Some(last_num) = iss_nums.last() {
if seq_num <= *last_num {
Expand Down
8 changes: 4 additions & 4 deletions src/ledger/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ impl Staking {
self.delegation_info
.end_height_map
.entry(end_height)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(owner);

// There should be no failure here !!
Expand Down Expand Up @@ -903,7 +903,7 @@ impl Staking {
self.delegation_info
.end_height_map
.entry(h + CFG.checkpoint.unbond_block_cnt)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(*addr);
}

Expand Down Expand Up @@ -995,7 +995,7 @@ impl Staking {
self.delegation_info
.end_height_map
.entry(h + CFG.checkpoint.unbond_block_cnt)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(pu.new_delegator_id);

// update delegator entries for pu target_validator
Expand Down Expand Up @@ -1078,7 +1078,7 @@ impl Staking {
self.delegation_info
.end_height_map
.entry(end_height)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(addr.to_owned());
Ok(())
} else {
Expand Down
19 changes: 18 additions & 1 deletion src/ledger/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,22 @@ impl LedgerStatus {
// Asset issuance should match the currently registered key
}

let get_effect_asset =
|derived_asset_code: &AssetTypeCode| -> Option<AssetType> {
for (code, asset) in &txn_effect.new_asset_codes {
let dc = AssetTypeCode::from_prefix_and_raw_asset_type_code(
AssetTypePrefix::UserDefined,
&code,
&CFG.checkpoint,
self.td_commit_height,
);
if dc == *derived_asset_code {
return Some(asset.clone());
}
}
None
};

// New issuance numbers
// (1) Must refer to a created asset type
// - NOTE: if the asset type is created in this transaction, this
Expand All @@ -1560,7 +1576,7 @@ impl LedgerStatus {
let asset_type = self
.asset_types
.get(&code)
.or_else(|| txn_effect.new_asset_codes.get(&code).cloned())
.or_else(|| get_effect_asset(&code))
.c(d!())?;
let proper_key = asset_type.properties.issuer;
if *iss_key != proper_key {
Expand Down Expand Up @@ -1715,6 +1731,7 @@ impl LedgerStatus {
//
// This drains every field of `block` except `txns` and `temp_sids`.
#[allow(unused_mut)]
#[allow(clippy::unwrap_or_default)]
fn apply_block_effects(&mut self, block: &mut BlockEffect) -> (TmpSidMap, u64, u64) {
let base_sid = self.next_txo.0;
let handle_asset_type_code = |code: AssetTypeCode| {
Expand Down

0 comments on commit feb40e8

Please sign in to comment.