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 18a80b4 commit 984bbcb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Binary file modified language/stdlib/compiled/stdlib/036_LibraAccount.mv
Binary file not shown.
12 changes: 8 additions & 4 deletions language/stdlib/modules/LibraAccount.move
Expand Up @@ -80,7 +80,7 @@ module LibraAccount {
limits_cap: AccountLimitMutationCapability,
}

/// A resource for the number of WriteSets that has been committed on chain.
/// A resource that holds the event handle for all the past WriteSet transactions that have been committed on chain.
resource struct LibraWriteSetManager {
upgrade_events: Event::EventHandle<Self::UpgradeEvent>,
}
Expand Down Expand Up @@ -1154,6 +1154,10 @@ module LibraAccount {
txn_expiration_time: u64,
chain_id: u8,
) acquires LibraAccount, Balance {
assert(
Signer::address_of(sender) == CoreAddresses::LIBRA_ROOT_ADDRESS(),
Errors::invalid_argument(PROLOGUE_INVALID_WRITESET_SENDER)
);
assert(Roles::has_libra_root_role(sender), Errors::invalid_argument(PROLOGUE_INVALID_WRITESET_SENDER));

// Currency code don't matter here as it won't be charged anyway. Gas constants are ommitted.
Expand Down Expand Up @@ -1303,10 +1307,10 @@ module LibraAccount {
writeset_payload: vector<u8>,
txn_sequence_number: u64
) acquires LibraWriteSetManager, LibraAccount, Balance {
let t_ref = borrow_global_mut<LibraWriteSetManager>(CoreAddresses::LIBRA_ROOT_ADDRESS());
let writeset_events_ref = borrow_global_mut<LibraWriteSetManager>(CoreAddresses::LIBRA_ROOT_ADDRESS());

Event::emit_event<Self::UpgradeEvent>(
&mut t_ref.upgrade_events,
Event::emit_event<UpgradeEvent>(
&mut writeset_events_ref.upgrade_events,
UpgradeEvent { writeset_payload },
);
// Currency code don't matter here as it won't be charged anyway.
Expand Down
12 changes: 8 additions & 4 deletions language/stdlib/modules/doc/LibraAccount.md
Expand Up @@ -315,7 +315,7 @@ and to record freeze/unfreeze events.

## Resource `LibraWriteSetManager`

A resource for the number of WriteSets that has been committed on chain.
A resource that holds the event handle for all the past WriteSet transactions that have been committed on chain.


<pre><code><b>resource</b> <b>struct</b> <a href="#0x1_LibraAccount_LibraWriteSetManager">LibraWriteSetManager</a>
Expand Down Expand Up @@ -2368,6 +2368,10 @@ The prologue for WriteSet transaction
txn_expiration_time: u64,
chain_id: u8,
) <b>acquires</b> <a href="#0x1_LibraAccount">LibraAccount</a>, <a href="#0x1_LibraAccount_Balance">Balance</a> {
<b>assert</b>(
<a href="Signer.md#0x1_Signer_address_of">Signer::address_of</a>(sender) == <a href="CoreAddresses.md#0x1_CoreAddresses_LIBRA_ROOT_ADDRESS">CoreAddresses::LIBRA_ROOT_ADDRESS</a>(),
<a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(PROLOGUE_INVALID_WRITESET_SENDER)
);
<b>assert</b>(<a href="Roles.md#0x1_Roles_has_libra_root_role">Roles::has_libra_root_role</a>(sender), <a href="Errors.md#0x1_Errors_invalid_argument">Errors::invalid_argument</a>(PROLOGUE_INVALID_WRITESET_SENDER));

// Currency code don't matter here <b>as</b> it won't be charged anyway. Gas constants are ommitted.
Expand Down Expand Up @@ -2567,10 +2571,10 @@ Epilogue for WriteSet trasnaction
writeset_payload: vector&lt;u8&gt;,
txn_sequence_number: u64
) <b>acquires</b> <a href="#0x1_LibraAccount_LibraWriteSetManager">LibraWriteSetManager</a>, <a href="#0x1_LibraAccount">LibraAccount</a>, <a href="#0x1_LibraAccount_Balance">Balance</a> {
<b>let</b> t_ref = borrow_global_mut&lt;<a href="#0x1_LibraAccount_LibraWriteSetManager">LibraWriteSetManager</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_LIBRA_ROOT_ADDRESS">CoreAddresses::LIBRA_ROOT_ADDRESS</a>());
<b>let</b> writeset_events_ref = borrow_global_mut&lt;<a href="#0x1_LibraAccount_LibraWriteSetManager">LibraWriteSetManager</a>&gt;(<a href="CoreAddresses.md#0x1_CoreAddresses_LIBRA_ROOT_ADDRESS">CoreAddresses::LIBRA_ROOT_ADDRESS</a>());

<a href="Event.md#0x1_Event_emit_event">Event::emit_event</a>&lt;<a href="#0x1_LibraAccount_UpgradeEvent">Self::UpgradeEvent</a>&gt;(
&<b>mut</b> t_ref.upgrade_events,
<a href="Event.md#0x1_Event_emit_event">Event::emit_event</a>&lt;<a href="#0x1_LibraAccount_UpgradeEvent">UpgradeEvent</a>&gt;(
&<b>mut</b> writeset_events_ref.upgrade_events,
<a href="#0x1_LibraAccount_UpgradeEvent">UpgradeEvent</a> { writeset_payload },
);
// Currency code don't matter here <b>as</b> it won't be charged anyway.
Expand Down

0 comments on commit 984bbcb

Please sign in to comment.