Skip to content

Commit

Permalink
Merge pull request #1585 from radixdlt/feature/lock-resource-owner-ba…
Browse files Browse the repository at this point in the history
…dge-tags

Improve genesis resource creation
  • Loading branch information
iamyulong authored Sep 21, 2023
2 parents 7b454db + ea9bdb9 commit d846ed4
Show file tree
Hide file tree
Showing 43 changed files with 136 additions and 114 deletions.
38 changes: 21 additions & 17 deletions assets/blueprints/genesis_helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ mod genesis_helper {
fn create_resource(resource: GenesisResource) -> () {
let metadata: BTreeMap<String, MetadataValue> = resource.metadata.into_iter().collect();

let owner_badge_address = if let Some(mut owner) = resource.owner {
// TODO: Should we use securify style non fungible resource for the owner badge?
if let Some(mut owner) = resource.owner {
// create owner badge
let owner_badge = ResourceBuilder::new_fungible(OwnerRole::None)
.divisibility(DIVISIBILITY_NONE)
.metadata(metadata! {
Expand All @@ -210,28 +210,18 @@ mod genesis_helper {
String::from_metadata_value(metadata.get("symbol").unwrap().clone())
.unwrap()
), locked;
"tags" => vec!["badge".to_string()], locked;
}
})
.mint_initial_supply(1);

let owner_badge_address = owner_badge.resource_address();

let resource_mgr = owner_badge.resource_manager();
resource_mgr.set_metadata("tags", vec!["badge".to_string()]);

owner.deposit(owner_badge.into());

Some(owner_badge_address)
} else {
None
};

let owner_role = match owner_badge_address {
None => OwnerRole::None,
Some(owner_badge_address) => OwnerRole::Fixed(rule!(require(owner_badge_address))),
};

ResourceBuilder::new_fungible(owner_role)
// create resource
ResourceBuilder::new_fungible(OwnerRole::Fixed(rule!(require(
owner_badge_address
))))
.mint_roles(mint_roles! {
minter => OWNER;
minter_updater => OWNER;
Expand All @@ -246,6 +236,20 @@ mod genesis_helper {
})
.with_address(resource.address_reservation)
.create_with_no_initial_supply();
} else {
// create resource
ResourceBuilder::new_fungible(OwnerRole::None)
.mint_roles(mint_roles! {
minter => rule!(deny_all);
minter_updater => rule!(deny_all);
})
.metadata(ModuleConfig {
init: metadata.into(),
roles: RoleAssignmentInit::default(),
})
.with_address(resource.address_reservation)
.create_with_no_initial_supply();
};
}

fn allocate_resources(
Expand Down
Binary file modified assets/faucet.wasm
Binary file not shown.
Binary file modified assets/flash_loan.wasm
Binary file not shown.
Binary file modified assets/genesis_helper.wasm
Binary file not shown.
Binary file modified assets/global_n_owned.wasm
Binary file not shown.
Binary file modified assets/kv_store.wasm
Binary file not shown.
Binary file modified assets/max_transaction.wasm
Binary file not shown.
Binary file modified assets/metadata.wasm
Binary file not shown.
Binary file modified assets/radiswap.wasm
Binary file not shown.
Binary file modified assets/test_environment.wasm
Binary file not shown.
16 changes: 8 additions & 8 deletions radix-engine-tests/assets/cost_flash_loan.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Total Cost (XRD) , 0.62812212592, 100.0%
- Execution Cost (XRD) , 0.4676909, 74.5%
Total Cost (XRD) , 0.62851402592, 100.0%
- Execution Cost (XRD) , 0.4680828, 74.5%
- Finalization Cost (XRD) , 0.0322574, 5.1%
- Tipping Cost (XRD) , 0, 0.0%
- Storage Cost (XRD) , 0.12817382592, 20.4%
- Tipping Cost (XRD) , 0, 0.0%
- Royalty Cost (XRD) , 0, 0.0%
Execution Cost Breakdown , 9353818, 100.0%
Execution Cost Breakdown , 9361656, 100.0%
- AfterInvoke , 1884, 0.0%
- AllocateNodeId , 5141, 0.1%
- BeforeInvoke , 7694, 0.1%
Expand All @@ -20,13 +20,13 @@ Execution Cost Breakdown ,
- OpenSubstate::GlobalFungibleResourceManager , 259797, 2.8%
- OpenSubstate::GlobalGenericComponent , 47692, 0.5%
- OpenSubstate::GlobalNonFungibleResourceManager , 632452, 6.8%
- OpenSubstate::GlobalPackage , 3398653, 36.3%
- OpenSubstate::GlobalPackage , 3400691, 36.3%
- OpenSubstate::InternalFungibleVault , 290575, 3.1%
- OpenSubstate::InternalGenericComponent , 211658, 2.3%
- PinNode , 636, 0.0%
- PrepareWasmCode , 965508, 10.3%
- PrepareWasmCode , 967496, 10.3%
- QueryActor , 10500, 0.1%
- ReadSubstate , 1323109, 14.1%
- ReadSubstate , 1325097, 14.2%
- RunNativeCode::AuthZone_pop , 33696, 0.4%
- RunNativeCode::AuthZone_push , 47700, 0.5%
- RunNativeCode::Worktop_drain , 11224, 0.1%
Expand Down Expand Up @@ -54,8 +54,8 @@ Execution Cost Breakdown ,
- RunNativeCode::try_deposit_batch_or_abort , 121257, 1.3%
- RunNativeCode::unlock_amount_FungibleVault , 46544, 0.5%
- RunNativeCode::withdraw , 57851, 0.6%
- RunWasmCode::BasicFlashLoan_repay_loan , 74637, 0.8%
- RunWasmCode::BasicFlashLoan_take_loan , 68688, 0.7%
- RunWasmCode::BasicFlashLoan_repay_loan , 75809, 0.8%
- RunWasmCode::BasicFlashLoan_take_loan , 69340, 0.7%
- ValidateTxPayload , 18800, 0.2%
- VerifyTxSignatures , 14000, 0.1%
- WriteSubstate , 33968, 0.4%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Total Cost (XRD) , 207.47905608518, 100.0%
- Execution Cost (XRD) , 2.58930865, 1.2%
Total Cost (XRD) , 207.47923633518, 100.0%
- Execution Cost (XRD) , 2.5894889, 1.2%
- Finalization Cost (XRD) , 2.47943445, 1.2%
- Tipping Cost (XRD) , 0, 0.0%
- Storage Cost (XRD) , 202.41031298518, 97.6%
- Tipping Cost (XRD) , 0, 0.0%
- Royalty Cost (XRD) , 0, 0.0%
Execution Cost Breakdown , 51786173, 100.0%
Execution Cost Breakdown , 51789778, 100.0%
- AfterInvoke , 4752, 0.0%
- AllocateNodeId , 2231, 0.0%
- BeforeInvoke , 2093962, 4.0%
Expand All @@ -20,15 +20,15 @@ Execution Cost Breakdown ,
- OpenSubstate::GlobalFungibleResourceManager , 121872, 0.2%
- OpenSubstate::GlobalGenericComponent , 43690, 0.1%
- OpenSubstate::GlobalNonFungibleResourceManager , 14330, 0.0%
- OpenSubstate::GlobalPackage , 2965764, 5.7%
- OpenSubstate::GlobalPackage , 2966854, 5.7%
- OpenSubstate::InternalFungibleVault , 90202, 0.2%
- OpenSubstate::InternalGenericComponent , 59014, 0.1%
- OpenSubstate::InternalKeyValueStore , 40536, 0.1%
- OpenSubstate::InternalNonFungibleVault , 133804, 0.3%
- PinNode , 240, 0.0%
- PrepareWasmCode , 352162, 0.7%
- PrepareWasmCode , 353200, 0.7%
- QueryActor , 2000, 0.0%
- ReadSubstate , 631490, 1.2%
- ReadSubstate , 632528, 1.2%
- RunNativeCode::Worktop_drain , 11224, 0.0%
- RunNativeCode::Worktop_drop , 17918, 0.0%
- RunNativeCode::Worktop_put , 29033, 0.1%
Expand All @@ -42,7 +42,7 @@ Execution Cost Breakdown ,
- RunNativeCode::lock_fee , 45243, 0.1%
- RunNativeCode::put_NonFungibleVault , 35354, 0.1%
- RunNativeCode::try_deposit_batch_or_abort , 121257, 0.2%
- RunWasmCode::Faucet_lock_fee , 24140, 0.0%
- RunWasmCode::Faucet_lock_fee , 24579, 0.0%
- SetSubstate , 35917, 0.1%
- ValidateTxPayload , 41840720, 80.8%
- VerifyTxSignatures , 7000, 0.0%
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Total Cost (XRD) , 6.54708345536, 100.0%
- Execution Cost (XRD) , 0.29777005, 4.5%
Total Cost (XRD) , 6.54726370536, 100.0%
- Execution Cost (XRD) , 0.2979503, 4.6%
- Finalization Cost (XRD) , 2.4964143, 38.1%
- Tipping Cost (XRD) , 0, 0.0%
- Storage Cost (XRD) , 3.75289910536, 57.3%
- Tipping Cost (XRD) , 0, 0.0%
- Royalty Cost (XRD) , 0, 0.0%
Execution Cost Breakdown , 5955401, 100.0%
Execution Cost Breakdown , 5959006, 100.0%
- AfterInvoke , 4806, 0.1%
- AllocateNodeId , 2231, 0.0%
- BeforeInvoke , 10522, 0.2%
Expand All @@ -20,15 +20,15 @@ Execution Cost Breakdown ,
- OpenSubstate::GlobalFungibleResourceManager , 121872, 2.0%
- OpenSubstate::GlobalGenericComponent , 43690, 0.7%
- OpenSubstate::GlobalNonFungibleResourceManager , 14330, 0.2%
- OpenSubstate::GlobalPackage , 2965764, 49.8%
- OpenSubstate::GlobalPackage , 2966854, 49.8%
- OpenSubstate::InternalFungibleVault , 90202, 1.5%
- OpenSubstate::InternalGenericComponent , 59122, 1.0%
- OpenSubstate::InternalKeyValueStore , 40536, 0.7%
- OpenSubstate::InternalNonFungibleVault , 135427, 2.3%
- PinNode , 240, 0.0%
- PrepareWasmCode , 352162, 5.9%
- PrepareWasmCode , 353200, 5.9%
- QueryActor , 2000, 0.0%
- ReadSubstate , 632651, 10.6%
- ReadSubstate , 633689, 10.6%
- RunNativeCode::Worktop_drain , 11224, 0.2%
- RunNativeCode::Worktop_drop , 17918, 0.3%
- RunNativeCode::Worktop_put , 29033, 0.5%
Expand All @@ -42,7 +42,7 @@ Execution Cost Breakdown ,
- RunNativeCode::lock_fee , 45243, 0.8%
- RunNativeCode::put_NonFungibleVault , 35354, 0.6%
- RunNativeCode::try_deposit_batch_or_abort , 121257, 2.0%
- RunWasmCode::Faucet_lock_fee , 24140, 0.4%
- RunWasmCode::Faucet_lock_fee , 24579, 0.4%
- SetSubstate , 36370, 0.6%
- ValidateTxPayload , 171920, 2.9%
- VerifyTxSignatures , 7000, 0.1%
Expand Down
Loading

0 comments on commit d846ed4

Please sign in to comment.