Skip to content

Commit

Permalink
new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Nov 4, 2024
1 parent 9b03ad5 commit 84b67ea
Show file tree
Hide file tree
Showing 30 changed files with 1,354 additions and 761 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion aptos-move/aptos-aggregator/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ pub trait TAggregatorV1View {
PartialVMError::new(StatusCode::SPECULATIVE_EXECUTION_ABORT_ERROR)
.with_message("Cannot convert delta for deleted aggregator".to_string())
})?;

delta_op
.apply_to(base)
.map_err(|e| match &e {
Expand Down
8 changes: 4 additions & 4 deletions aptos-move/e2e-tests/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use aptos_keygen::KeyGen;
use aptos_types::{
account_config::{
new_block_event_key, AccountResource, CoinInfoResource, CoinStoreResource,
ConcurrentSupply, NewBlockEvent, ObjectGroupResource, CORE_CODE_ADDRESS,
ConcurrentSupplyResource, NewBlockEvent, ObjectGroupResource, CORE_CODE_ADDRESS,
},
block_executor::config::{
BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig,
Expand Down Expand Up @@ -438,10 +438,10 @@ impl FakeExecutor {
let mut fa_resource_group = self
.read_resource_group::<ObjectGroupResource>(&AccountAddress::TEN)
.expect("resource group must exist in data store");
let mut supply = bcs::from_bytes::<ConcurrentSupply>(
let mut supply = bcs::from_bytes::<ConcurrentSupplyResource>(
fa_resource_group
.group
.get(&ConcurrentSupply::struct_tag())
.get(&ConcurrentSupplyResource::struct_tag())
.unwrap(),
)
.unwrap();
Expand All @@ -451,7 +451,7 @@ impl FakeExecutor {
fa_resource_group
.group
.insert(
ConcurrentSupply::struct_tag(),
ConcurrentSupplyResource::struct_tag(),
bcs::to_bytes(&supply).unwrap(),
)
.unwrap();
Expand Down
34 changes: 16 additions & 18 deletions aptos-move/framework/aptos-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -3468,25 +3468,23 @@ Decrease the supply of a fungible asset by burning.
};
<b>let</b> metadata_address = <a href="object.md#0x1_object_object_address">object::object_address</a>(metadata);

<b>if</b> (amount == 0) {
<b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address)) {
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address);
<b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address)) {
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentSupply">ConcurrentSupply</a>&gt;(metadata_address);

<b>assert</b>!(
<a href="aggregator_v2.md#0x1_aggregator_v2_try_sub">aggregator_v2::try_sub</a>(&<b>mut</b> supply.current, (amount <b>as</b> u128)),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
} <b>else</b> <b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address)) {
<b>assert</b>!(<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address);
<b>assert</b>!(
supply.current &gt;= (amount <b>as</b> u128),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_state">error::invalid_state</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
supply.current = supply.current - (amount <b>as</b> u128);
} <b>else</b> {
<b>assert</b>!(<b>false</b>, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
}
<b>assert</b>!(
<a href="aggregator_v2.md#0x1_aggregator_v2_try_sub">aggregator_v2::try_sub</a>(&<b>mut</b> supply.current, (amount <b>as</b> u128)),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_out_of_range">error::out_of_range</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
} <b>else</b> <b>if</b> (<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address)) {
<b>assert</b>!(<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
<b>let</b> supply = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_Supply">Supply</a>&gt;(metadata_address);
<b>assert</b>!(
supply.current &gt;= (amount <b>as</b> u128),
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_state">error::invalid_state</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_UNDERFLOW">ESUPPLY_UNDERFLOW</a>)
);
supply.current = supply.current - (amount <b>as</b> u128);
} <b>else</b> {
<b>assert</b>!(<b>false</b>, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_ESUPPLY_NOT_FOUND">ESUPPLY_NOT_FOUND</a>));
}
}
</code></pre>
Expand Down
34 changes: 16 additions & 18 deletions aptos-move/framework/aptos-framework/sources/fungible_asset.move
Original file line number Diff line number Diff line change
Expand Up @@ -1098,25 +1098,23 @@ module aptos_framework::fungible_asset {
};
let metadata_address = object::object_address(metadata);

if (amount == 0) {
if (exists<ConcurrentSupply>(metadata_address)) {
let supply = borrow_global_mut<ConcurrentSupply>(metadata_address);
if (exists<ConcurrentSupply>(metadata_address)) {
let supply = borrow_global_mut<ConcurrentSupply>(metadata_address);

assert!(
aggregator_v2::try_sub(&mut supply.current, (amount as u128)),
error::out_of_range(ESUPPLY_UNDERFLOW)
);
} else if (exists<Supply>(metadata_address)) {
assert!(exists<Supply>(metadata_address), error::not_found(ESUPPLY_NOT_FOUND));
let supply = borrow_global_mut<Supply>(metadata_address);
assert!(
supply.current >= (amount as u128),
error::invalid_state(ESUPPLY_UNDERFLOW)
);
supply.current = supply.current - (amount as u128);
} else {
assert!(false, error::not_found(ESUPPLY_NOT_FOUND));
}
assert!(
aggregator_v2::try_sub(&mut supply.current, (amount as u128)),
error::out_of_range(ESUPPLY_UNDERFLOW)
);
} else if (exists<Supply>(metadata_address)) {
assert!(exists<Supply>(metadata_address), error::not_found(ESUPPLY_NOT_FOUND));
let supply = borrow_global_mut<Supply>(metadata_address);
assert!(
supply.current >= (amount as u128),
error::invalid_state(ESUPPLY_UNDERFLOW)
);
supply.current = supply.current - (amount as u128);
} else {
assert!(false, error::not_found(ESUPPLY_NOT_FOUND));
}
}

Expand Down
2 changes: 2 additions & 0 deletions execution/executor-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version = { workspace = true }

[dependencies]
anyhow = { workspace = true }
aptos-aggregator = { workspace = true }
aptos-block-executor = { workspace = true }
aptos-block-partitioner = { workspace = true }
aptos-config = { workspace = true }
Expand Down Expand Up @@ -49,6 +50,7 @@ derivative = { workspace = true }
indicatif = { workspace = true }
itertools = { workspace = true }
move-core-types = { workspace = true }
move-vm-types = { workspace = true }
num_cpus = { workspace = true }
once_cell = { workspace = true }
rand = { workspace = true }
Expand Down
23 changes: 21 additions & 2 deletions execution/executor-benchmark/src/db_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use anyhow::Result;
use aptos_types::{
account_address::AccountAddress,
account_config::{
AccountResource, CoinStoreResource, FungibleStoreResource, ObjectGroupResource,
AccountResource, CoinInfoResource, CoinStoreResource, ConcurrentSupplyResource,
FungibleStoreResource, ObjectCoreResource, ObjectGroupResource,
},
event::{EventHandle, EventKey},
state_store::{state_key::StateKey, StateView},
write_set::TOTAL_SUPPLY_STATE_KEY,
AptosCoinType,
AptosCoinType, CoinType,
};
use move_core_types::{
identifier::Identifier,
Expand All @@ -24,7 +25,13 @@ pub struct CommonStructTags {
pub account: StructTag,
pub apt_coin_store: StructTag,
pub object_group: StructTag,
pub object_core: StructTag,
pub fungible_store: StructTag,
pub concurrent_supply: StructTag,

pub apt_coin_type_name: String,

pub apt_coin_info_resource: StateKey,
}

impl CommonStructTags {
Expand All @@ -33,7 +40,15 @@ impl CommonStructTags {
account: AccountResource::struct_tag(),
apt_coin_store: CoinStoreResource::<AptosCoinType>::struct_tag(),
object_group: ObjectGroupResource::struct_tag(),
object_core: ObjectCoreResource::struct_tag(),
fungible_store: FungibleStoreResource::struct_tag(),
concurrent_supply: ConcurrentSupplyResource::struct_tag(),

apt_coin_type_name: "0x1::aptos_coin::AptosCoin".to_string(),
apt_coin_info_resource: StateKey::resource_typed::<CoinInfoResource<AptosCoinType>>(
&AptosCoinType::coin_info_address(),
)
.unwrap(),
}
}
}
Expand Down Expand Up @@ -149,4 +164,8 @@ impl DbAccessUtil {
EventHandle::new(EventKey::new(2, address), 0),
)
}

pub fn new_object_core(address: AccountAddress, owner: AccountAddress) -> ObjectCoreResource {
ObjectCoreResource::new(owner, false, EventHandle::new(EventKey::new(1, address), 0))
}
}
Loading

0 comments on commit 84b67ea

Please sign in to comment.