Skip to content

Commit

Permalink
fixup! fixup! [libra-framework] Refactor writeset prologue and epilogue
Browse files Browse the repository at this point in the history
  • Loading branch information
Runtian Zhou committed Sep 16, 2020
1 parent aefa093 commit 74ffffd
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
Binary file modified language/stdlib/compiled/stdlib/036_LibraAccount.mv
Binary file not shown.
Binary file modified language/stdlib/compiled/stdlib/037_Genesis.mv
Binary file not shown.
1 change: 1 addition & 0 deletions language/stdlib/modules/Genesis.move
Expand Up @@ -89,6 +89,7 @@ module Genesis {
lr_account,
);
LibraBlock::initialize_block_metadata(lr_account);
LibraAccount::initialize_writeset_manager(lr_account);

let lr_rotate_key_cap = LibraAccount::extract_key_rotation_capability(lr_account);
LibraAccount::rotate_authentication_key(&lr_rotate_key_cap, lr_auth_key);
Expand Down
8 changes: 8 additions & 0 deletions language/stdlib/modules/LibraAccount.move
Expand Up @@ -197,6 +197,14 @@ module LibraAccount {
limits_cap: AccountLimits::grant_mutation_capability(lr_account),
}
);
}

public fun initialize_writeset_manager(
lr_account: &signer,
) {
LibraTimestamp::assert_genesis();
// Operational constraint, not a privilege constraint.
CoreAddresses::assert_libra_root(lr_account);

assert(
!exists<LibraWriteSetManager>(CoreAddresses::LIBRA_ROOT_ADDRESS()),
Expand Down
1 change: 1 addition & 0 deletions language/stdlib/modules/doc/Genesis.md
Expand Up @@ -89,6 +89,7 @@
lr_account,
);
<a href="LibraBlock.md#0x1_LibraBlock_initialize_block_metadata">LibraBlock::initialize_block_metadata</a>(lr_account);
<a href="LibraAccount.md#0x1_LibraAccount_initialize_writeset_manager">LibraAccount::initialize_writeset_manager</a>(lr_account);

<b>let</b> lr_rotate_key_cap = <a href="LibraAccount.md#0x1_LibraAccount_extract_key_rotation_capability">LibraAccount::extract_key_rotation_capability</a>(lr_account);
<a href="LibraAccount.md#0x1_LibraAccount_rotate_authentication_key">LibraAccount::rotate_authentication_key</a>(&lr_rotate_key_cap, lr_auth_key);
Expand Down
61 changes: 45 additions & 16 deletions language/stdlib/modules/doc/LibraAccount.md
Expand Up @@ -45,6 +45,7 @@
- [Const `PROLOGUE_EMODULE_NOT_ALLOWED`](#0x1_LibraAccount_PROLOGUE_EMODULE_NOT_ALLOWED)
- [Const `PROLOGUE_INVALID_WRITESET_SENDER`](#0x1_LibraAccount_PROLOGUE_INVALID_WRITESET_SENDER)
- [Function `initialize`](#0x1_LibraAccount_initialize)
- [Function `initialize_writeset_manager`](#0x1_LibraAccount_initialize_writeset_manager)
- [Function `has_published_account_limits`](#0x1_LibraAccount_has_published_account_limits)
- [Function `should_track_limits_for_account`](#0x1_LibraAccount_should_track_limits_for_account)
- [Function `staple_lbr`](#0x1_LibraAccount_staple_lbr)
Expand Down Expand Up @@ -858,6 +859,34 @@ Initialize this module. This is only callable from genesis.
limits_cap: <a href="AccountLimits.md#0x1_AccountLimits_grant_mutation_capability">AccountLimits::grant_mutation_capability</a>(lr_account),
}
);
}
</code></pre>



</details>

<a name="0x1_LibraAccount_initialize_writeset_manager"></a>

## Function `initialize_writeset_manager`



<pre><code><b>public</b> <b>fun</b> <a href="#0x1_LibraAccount_initialize_writeset_manager">initialize_writeset_manager</a>(lr_account: &signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="#0x1_LibraAccount_initialize_writeset_manager">initialize_writeset_manager</a>(
lr_account: &signer,
) {
<a href="LibraTimestamp.md#0x1_LibraTimestamp_assert_genesis">LibraTimestamp::assert_genesis</a>();
// Operational constraint, not a privilege constraint.
<a href="CoreAddresses.md#0x1_CoreAddresses_assert_libra_root">CoreAddresses::assert_libra_root</a>(lr_account);

<b>assert</b>(
!exists&lt;<a href="#0x1_LibraAccount_LibraWriteSetManager">LibraWriteSetManager</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_LIBRA_ROOT_ADDRESS">CoreAddresses::LIBRA_ROOT_ADDRESS</a>()),
Expand Down Expand Up @@ -2733,11 +2762,11 @@ pragma verify_duration_estimate = 100;
<pre><code><b>schema</b> <a href="#0x1_LibraAccount_StapleLBRAbortsIf">StapleLBRAbortsIf</a> {
cap: <a href="#0x1_LibraAccount_WithdrawCapability">WithdrawCapability</a>;
amount_lbr: u64;
<a name="0x1_LibraAccount_reserve$58"></a>
<a name="0x1_LibraAccount_reserve$59"></a>
<b>let</b> reserve = <b>global</b>&lt;<a href="LBR.md#0x1_LBR_Reserve">LBR::Reserve</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_LIBRA_ROOT_ADDRESS">CoreAddresses::LIBRA_ROOT_ADDRESS</a>());
<a name="0x1_LibraAccount_amount_coin1$59"></a>
<a name="0x1_LibraAccount_amount_coin1$60"></a>
<b>let</b> amount_coin1 = <a href="FixedPoint32.md#0x1_FixedPoint32_spec_multiply_u64">FixedPoint32::spec_multiply_u64</a>(amount_lbr, reserve.coin1.ratio) + 1;
<a name="0x1_LibraAccount_amount_coin2$60"></a>
<a name="0x1_LibraAccount_amount_coin2$61"></a>
<b>let</b> amount_coin2 = <a href="FixedPoint32.md#0x1_FixedPoint32_spec_multiply_u64">FixedPoint32::spec_multiply_u64</a>(amount_lbr, reserve.coin2.ratio) + 1;
<b>aborts_if</b> amount_lbr == 0 with Errors::INVALID_ARGUMENT;
<b>aborts_if</b> reserve.coin1.backing.value + amount_coin1 &gt; MAX_U64 with Errors::LIMIT_EXCEEDED;
Expand Down Expand Up @@ -2768,17 +2797,17 @@ pragma verify_duration_estimate = 100;
<pre><code><b>schema</b> <a href="#0x1_LibraAccount_StapleLBREnsures">StapleLBREnsures</a> {
cap: <a href="#0x1_LibraAccount_WithdrawCapability">WithdrawCapability</a>;
amount_lbr: u64;
<a name="0x1_LibraAccount_reserve$61"></a>
<a name="0x1_LibraAccount_reserve$62"></a>
<b>let</b> reserve = <b>global</b>&lt;<a href="LBR.md#0x1_LBR_Reserve">LBR::Reserve</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_LIBRA_ROOT_ADDRESS">CoreAddresses::LIBRA_ROOT_ADDRESS</a>());
<a name="0x1_LibraAccount_amount_coin1$62"></a>
<a name="0x1_LibraAccount_amount_coin1$63"></a>
<b>let</b> amount_coin1 = <a href="FixedPoint32.md#0x1_FixedPoint32_spec_multiply_u64">FixedPoint32::spec_multiply_u64</a>(amount_lbr, reserve.coin1.ratio) + 1;
<a name="0x1_LibraAccount_amount_coin2$63"></a>
<a name="0x1_LibraAccount_amount_coin2$64"></a>
<b>let</b> amount_coin2 = <a href="FixedPoint32.md#0x1_FixedPoint32_spec_multiply_u64">FixedPoint32::spec_multiply_u64</a>(amount_lbr, reserve.coin2.ratio) + 1;
<a name="0x1_LibraAccount_total_value_coin1$64"></a>
<a name="0x1_LibraAccount_total_value_coin1$65"></a>
<b>let</b> total_value_coin1 = <b>global</b>&lt;<a href="Libra.md#0x1_Libra_CurrencyInfo">Libra::CurrencyInfo</a>&lt;<a href="Coin1.md#0x1_Coin1">Coin1</a>&gt;&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_CURRENCY_INFO_ADDRESS">CoreAddresses::CURRENCY_INFO_ADDRESS</a>()).total_value;
<a name="0x1_LibraAccount_total_value_coin2$65"></a>
<a name="0x1_LibraAccount_total_value_coin2$66"></a>
<b>let</b> total_value_coin2 = <b>global</b>&lt;<a href="Libra.md#0x1_Libra_CurrencyInfo">Libra::CurrencyInfo</a>&lt;<a href="Coin2.md#0x1_Coin2">Coin2</a>&gt;&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_CURRENCY_INFO_ADDRESS">CoreAddresses::CURRENCY_INFO_ADDRESS</a>()).total_value;
<a name="0x1_LibraAccount_total_value_lbr$66"></a>
<a name="0x1_LibraAccount_total_value_lbr$67"></a>
<b>let</b> total_value_lbr = <b>global</b>&lt;<a href="Libra.md#0x1_Libra_CurrencyInfo">Libra::CurrencyInfo</a>&lt;<a href="LBR.md#0x1_LBR">LBR</a>&gt;&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_CURRENCY_INFO_ADDRESS">CoreAddresses::CURRENCY_INFO_ADDRESS</a>()).total_value;
<b>ensures</b> <b>global</b>&lt;<a href="#0x1_LibraAccount_Balance">Balance</a>&lt;<a href="Coin1.md#0x1_Coin1">Coin1</a>&gt;&gt;(cap.account_address).coin.value
== <b>old</b>(<b>global</b>&lt;<a href="#0x1_LibraAccount_Balance">Balance</a>&lt;<a href="Coin1.md#0x1_Coin1">Coin1</a>&gt;&gt;(cap.account_address).coin.value) - amount_coin1;
Expand Down Expand Up @@ -2969,7 +2998,7 @@ Can only withdraw from the balances of cap.account_address [B27].


<pre><code>pragma opaque;
<a name="0x1_LibraAccount_payer$69"></a>
<a name="0x1_LibraAccount_payer$70"></a>
<b>let</b> payer = cap.account_address;
<b>modifies</b> <b>global</b>&lt;<a href="#0x1_LibraAccount_Balance">Balance</a>&lt;Token&gt;&gt;(payer);
<b>modifies</b> <b>global</b>&lt;<a href="#0x1_LibraAccount">LibraAccount</a>&gt;(payer);
Expand All @@ -2991,7 +3020,7 @@ Can only withdraw from the balances of cap.account_address [B27].
cap: <a href="#0x1_LibraAccount_WithdrawCapability">WithdrawCapability</a>;
payee: address;
amount: u64;
<a name="0x1_LibraAccount_payer$57"></a>
<a name="0x1_LibraAccount_payer$58"></a>
<b>let</b> payer = cap.account_address;
<b>include</b> <a href="LibraTimestamp.md#0x1_LibraTimestamp_AbortsIfNotOperating">LibraTimestamp::AbortsIfNotOperating</a>;
<b>include</b> <a href="Libra.md#0x1_Libra_AbortsIfNoCurrency">Libra::AbortsIfNoCurrency</a>&lt;Token&gt;;
Expand All @@ -3015,7 +3044,7 @@ Can only withdraw from the balances of cap.account_address [B27].


<pre><code>pragma opaque;
<a name="0x1_LibraAccount_sender_addr$70"></a>
<a name="0x1_LibraAccount_sender_addr$71"></a>
<b>let</b> sender_addr = <a href="Signer.md#0x1_Signer_spec_address_of">Signer::spec_address_of</a>(sender);
<b>modifies</b> <b>global</b>&lt;<a href="#0x1_LibraAccount">LibraAccount</a>&gt;(sender_addr);
<b>ensures</b> exists&lt;<a href="#0x1_LibraAccount">LibraAccount</a>&gt;(sender_addr);
Expand Down Expand Up @@ -3053,7 +3082,7 @@ Can only withdraw from the balances of cap.account_address [B27].


<pre><code>pragma opaque;
<a name="0x1_LibraAccount_cap_addr$71"></a>
<a name="0x1_LibraAccount_cap_addr$72"></a>
<b>let</b> cap_addr = cap.account_address;
<b>modifies</b> <b>global</b>&lt;<a href="#0x1_LibraAccount">LibraAccount</a>&gt;(cap_addr);
<b>aborts_if</b> !<a href="#0x1_LibraAccount_exists_at">exists_at</a>(cap_addr) with Errors::NOT_PUBLISHED;
Expand Down Expand Up @@ -3124,7 +3153,7 @@ Can only rotate the authentication_key of cap.account_address [B26].



<a name="0x1_LibraAccount_account_addr$72"></a>
<a name="0x1_LibraAccount_account_addr$73"></a>


<pre><code><b>let</b> account_addr = <a href="Signer.md#0x1_Signer_spec_address_of">Signer::spec_address_of</a>(account);
Expand Down Expand Up @@ -3294,7 +3323,7 @@ Returns true if the LibraAccount at

<pre><code><b>schema</b> <a href="#0x1_LibraAccount_EnsuresHasKeyRotationCap">EnsuresHasKeyRotationCap</a> {
account: signer;
<a name="0x1_LibraAccount_addr$67"></a>
<a name="0x1_LibraAccount_addr$68"></a>
<b>let</b> addr = <a href="Signer.md#0x1_Signer_spec_address_of">Signer::spec_address_of</a>(account);
<b>ensures</b> <a href="#0x1_LibraAccount_spec_has_key_rotation_cap">spec_has_key_rotation_cap</a>(addr);
<b>ensures</b> <a href="Option.md#0x1_Option_spec_get">Option::spec_get</a>(<a href="#0x1_LibraAccount_spec_get_key_rotation_cap">spec_get_key_rotation_cap</a>(addr)).account_address == addr;
Expand Down Expand Up @@ -3353,7 +3382,7 @@ or the key rotation capability for addr itself [B26].

<pre><code><b>schema</b> <a href="#0x1_LibraAccount_EnsuresWithdrawalCap">EnsuresWithdrawalCap</a> {
account: signer;
<a name="0x1_LibraAccount_addr$68"></a>
<a name="0x1_LibraAccount_addr$69"></a>
<b>let</b> addr = <a href="Signer.md#0x1_Signer_spec_address_of">Signer::spec_address_of</a>(account);
<b>ensures</b> <a href="#0x1_LibraAccount_spec_has_withdraw_cap">spec_has_withdraw_cap</a>(addr);
<b>ensures</b> <a href="Option.md#0x1_Option_spec_get">Option::spec_get</a>(<a href="#0x1_LibraAccount_spec_get_withdraw_cap">spec_get_withdraw_cap</a>(addr)).account_address == addr;
Expand Down
2 changes: 1 addition & 1 deletion types/src/block_metadata.rs
Expand Up @@ -69,7 +69,7 @@ impl BlockMetadata {
}

pub fn new_block_event_key() -> EventKey {
EventKey::new_from_address(&libra_root_address(), 21)
EventKey::new_from_address(&libra_root_address(), 20)
}

/// The path to the new block event handle under a LibraBlock::BlockMetadata resource.
Expand Down

0 comments on commit 74ffffd

Please sign in to comment.