Skip to content

Commit

Permalink
[move] set slow wallet entry function (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Jan 15, 2024
1 parent 61f594d commit 7009361
Show file tree
Hide file tree
Showing 22 changed files with 10,492 additions and 10,418 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- synchronize
branches:
- "release**"
- "main"
- "main**"
env:
DIEM_FORGE_NODE_BIN_PATH: ${{github.workspace}}/diem-node
LIBRA_CI: 1
Expand Down Expand Up @@ -166,4 +166,4 @@ jobs:
- name: rescue
if: always()
working-directory: ./tools/rescue
run: RUST_MIN_STACK=104857600 cargo test --no-fail-fast -- --test-threads=1
run: RUST_MIN_STACK=104857600 cargo test --no-fail-fast -- --test-threads=1
2 changes: 1 addition & 1 deletion .github/workflows/cleanliness.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- synchronize
branches:
- 'release**'
- 'main'
- 'main**'
env:
DIEM_FORGE_NODE_BIN_PATH: ${{github.workspace}}/diem-node
LIBRA_CI: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/formal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- synchronize
branches:
- 'release**'
- 'main'
- 'main**'
env:
DOTNET_ROOT: "/home/runner/.dotnet"
Z3_EXE: "/home/runner/bin/z3"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/move.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- synchronize
branches:
- 'release**'
- 'main'
- 'main**'

jobs:
functional-tests:
Expand Down
36 changes: 36 additions & 0 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ pub enum EntryFunctionCall {
transferred: u64,
},

/// Users can change their account to slow, by calling the entry function
/// Warning: this is permanent for the account. There's no way to
/// reverse a "slow wallet".
SlowWalletUserSetSlow {},

/// Initialize the validator account and give ownership to the signing account
/// except it leaves the ValidatorConfig to be set by another entity.
/// Note: this triggers setting the operator and owner, set it to the account's address
Expand Down Expand Up @@ -811,6 +816,7 @@ impl EntryFunctionCall {
unlocked,
transferred,
} => slow_wallet_smoke_test_vm_unlock(user_addr, unlocked, transferred),
SlowWalletUserSetSlow {} => slow_wallet_user_set_slow(),
StakeInitializeStakeOwner {
initial_stake_amount,
operator,
Expand Down Expand Up @@ -2128,6 +2134,24 @@ pub fn slow_wallet_smoke_test_vm_unlock(
))
}

/// Users can change their account to slow, by calling the entry function
/// Warning: this is permanent for the account. There's no way to
/// reverse a "slow wallet".
pub fn slow_wallet_user_set_slow() -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("slow_wallet").to_owned(),
),
ident_str!("user_set_slow").to_owned(),
vec![],
vec![],
))
}

/// Initialize the validator account and give ownership to the signing account
/// except it leaves the ValidatorConfig to be set by another entity.
/// Note: this triggers setting the operator and owner, set it to the account's address
Expand Down Expand Up @@ -3078,6 +3102,14 @@ mod decoder {
}
}

pub fn slow_wallet_user_set_slow(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(_script) = payload {
Some(EntryFunctionCall::SlowWalletUserSetSlow {})
} else {
None
}
}

pub fn stake_initialize_stake_owner(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::StakeInitializeStakeOwner {
Expand Down Expand Up @@ -3450,6 +3482,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"slow_wallet_smoke_test_vm_unlock".to_string(),
Box::new(decoder::slow_wallet_smoke_test_vm_unlock),
);
map.insert(
"slow_wallet_user_set_slow".to_string(),
Box::new(decoder::slow_wallet_user_set_slow),
);
map.insert(
"stake_initialize_stake_owner".to_string(),
Box::new(decoder::stake_initialize_stake_owner),
Expand Down
13 changes: 5 additions & 8 deletions framework/libra-framework/sources/ol_sources/ol_account.move
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ module ol_framework::ol_account {
assert!(amount < limit, error::invalid_state(EINSUFFICIENT_BALANCE));

let coin = coin::withdraw_with_capability(cap, amount);
slow_wallet::maybe_track_unlocked_withdraw(payer, amount);

// the outgoing coins should trigger an update on this account
// order matters here
maybe_update_burn_tracker_impl(payer);
Expand All @@ -202,16 +204,15 @@ module ol_framework::ol_account {
assume !system_addresses::signer_is_ol_root(sender);
assume chain_status::is_operating();
};
// never abort when its a system address
// if (system_addresses::signer_is_ol_root(sender)) return
// coin::zero<LibraCoin>(); // and VM needs to figure this out.

let addr = signer::address_of(sender);
assert!(amount > 0, error::invalid_argument(EZERO_TRANSFER));

let limit = slow_wallet::unlocked_amount(addr);
assert!(amount <= limit, error::invalid_state(EINSUFFICIENT_BALANCE));
let coin = coin::withdraw<LibraCoin>(sender, amount);
slow_wallet::maybe_track_unlocked_withdraw(addr, amount);

// the outgoing coins should trigger an update on this account
// order matters here
maybe_update_burn_tracker_impl(addr);
Expand All @@ -235,7 +236,7 @@ module ol_framework::ol_account {
assert!(coin::is_account_registered<LibraCoin>(recipient), error::invalid_argument(EACCOUNT_NOT_REGISTERED_FOR_GAS));

// must track the slow wallet on both sides of the transfer
slow_wallet::maybe_track_slow_transfer(payer, recipient, amount);
// slow_wallet::maybe_track_slow_transfer(payer, recipient, amount);

// maybe track cumulative deposits if this is a donor directed wallet
// or other wallet which tracks cumulative payments.
Expand Down Expand Up @@ -324,10 +325,6 @@ module ol_framework::ol_account {

}

// public fun withdraw_with_capability(cap: &WithdrawCapability, amount: u64): Coin<LibraCoin> {
// coin::withdraw_with_capability(cap, amount)
// }

//////// 0L ////////

#[view]
Expand Down
8 changes: 8 additions & 0 deletions framework/libra-framework/sources/ol_sources/slow_wallet.move
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ module ol_framework::slow_wallet {
}
}

/// Users can change their account to slow, by calling the entry function
/// Warning: this is permanent for the account. There's no way to
/// reverse a "slow wallet".
public entry fun user_set_slow(sig: &signer) acquires SlowWalletList {
set_slow(sig);
}

/// implementation of setting slow wallet, allows contracts to call.
public fun set_slow(sig: &signer) acquires SlowWalletList {
assert!(exists<SlowWalletList>(@ol_framework), error::invalid_argument(EGENESIS_ERROR));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module ol_framework::test_slow_wallet {
use ol_framework::rewards;
use std::vector;

// use diem_std::debug::print;
use diem_std::debug::print;

#[test(root = @ol_framework)]
// we are testing that genesis creates the needed struct
Expand Down Expand Up @@ -118,6 +118,10 @@ module ol_framework::test_slow_wallet {
// slow transfer
let b_balance = coin::balance<LibraCoin>(@0x456);
assert!(b_balance == transfer_amount, 735704);
print(&alice_init_balance);
print(&transfer_amount);
print(&slow_wallet::unlocked_amount(@0x123));

assert!(slow_wallet::unlocked_amount(@0x123) == (alice_init_balance - transfer_amount), 735705);
assert!(slow_wallet::unlocked_amount(@0x456) == transfer_amount, 735706);

Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6fcc2d535e4013d722923951822480f53d21b5896d85dc86b29214b6a0b9e982
ab5790de50c45fc51e4c2a3ef39607cef4eebbb02c8580364a1380482b61bcd7
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Upgrade proposal for package `MoveStdlib`

// Framework commit hash: 73ffbfdea37815d75885ce45a6c9716331562742
// Framework commit hash: 9670b386edf4841282907daaac7d0d2d2e4d3f2b
// Builder commit hash: db1137ba1f8e7301e325021f71f740063daaf76e

// Next step script hash: 561ff5339c760f4e8070da4dc20824773842299c372b17a412cdbf00517f6e69
// Next step script hash: 5af922a1bf1e481ec45aa29eb747d9badb16b486cdfac6c147d2ebe886349fbb

// source digest: B7AED5C969B8CA9DF201BC95AB87937D7A060ECFDC7E715CE3A0F6450AB8AD71
script {
Expand All @@ -17,7 +17,7 @@ script {
let framework_signer = diem_governance::resolve_multi_step_proposal(
proposal_id,
@0000000000000000000000000000000000000000000000000000000000000001,
vector[86u8,31u8,245u8,51u8,156u8,118u8,15u8,78u8,128u8,112u8,218u8,77u8,194u8,8u8,36u8,119u8,56u8,66u8,41u8,156u8,55u8,43u8,23u8,164u8,18u8,205u8,191u8,0u8,81u8,127u8,110u8,105u8,],
vector[90u8,249u8,34u8,161u8,191u8,30u8,72u8,30u8,196u8,90u8,162u8,158u8,183u8,71u8,217u8,186u8,219u8,22u8,180u8,134u8,205u8,250u8,198u8,193u8,71u8,210u8,235u8,232u8,134u8,52u8,159u8,187u8,],
);
let code = vector::empty();
let code_chunk0 =
Expand Down Expand Up @@ -1533,6 +1533,6 @@ script {
78u8,55u8,95u8,1u8,176u8,130u8,161u8,216u8,26u8,13u8,0u8,0u8,0u8,0u8,0u8,0u8,
];
code::publish_package_txn(&framework_signer, metadata_chunk1, code);
version::upgrade_set_git(&framework_signer, x"73ffbfdea37815d75885ce45a6c9716331562742")
version::upgrade_set_git(&framework_signer, x"9670b386edf4841282907daaac7d0d2d2e4d3f2b")
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
561ff5339c760f4e8070da4dc20824773842299c372b17a412cdbf00517f6e69
5af922a1bf1e481ec45aa29eb747d9badb16b486cdfac6c147d2ebe886349fbb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Upgrade proposal for package `VendorStdlib`

// Framework commit hash: 73ffbfdea37815d75885ce45a6c9716331562742
// Framework commit hash: 9670b386edf4841282907daaac7d0d2d2e4d3f2b
// Builder commit hash: db1137ba1f8e7301e325021f71f740063daaf76e

// Next step script hash: 36e7243637efc43ad18daf9177da55ea527d615dc489961aa023549a81b152e8
// Next step script hash: ecb7454f451694c1c742ac71d78fbed31f4fbb1d6ecc26b01869bc7f68598080

// source digest: 5E12DDD8987B153D75378183FB77218A1FAB6038899EB9121ECD4BE94EC1D598
script {
Expand All @@ -17,7 +17,7 @@ script {
let framework_signer = diem_governance::resolve_multi_step_proposal(
proposal_id,
@0000000000000000000000000000000000000000000000000000000000000001,
vector[54u8,231u8,36u8,54u8,55u8,239u8,196u8,58u8,209u8,141u8,175u8,145u8,119u8,218u8,85u8,234u8,82u8,125u8,97u8,93u8,196u8,137u8,150u8,26u8,160u8,35u8,84u8,154u8,129u8,177u8,82u8,232u8,],
vector[236u8,183u8,69u8,79u8,69u8,22u8,148u8,193u8,199u8,66u8,172u8,113u8,215u8,143u8,190u8,211u8,31u8,79u8,187u8,29u8,110u8,204u8,38u8,176u8,24u8,105u8,188u8,127u8,104u8,89u8,128u8,128u8,],
);
let code = vector::empty();
let code_chunk0 =
Expand Down Expand Up @@ -7332,6 +7332,6 @@ script {
vector::append(&mut metadata_chunk1, metadata_chunk2);
vector::append(&mut metadata_chunk1, metadata_chunk3);
code::publish_package_txn(&framework_signer, metadata_chunk1, code);
version::upgrade_set_git(&framework_signer, x"73ffbfdea37815d75885ce45a6c9716331562742")
version::upgrade_set_git(&framework_signer, x"9670b386edf4841282907daaac7d0d2d2e4d3f2b")
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
36e7243637efc43ad18daf9177da55ea527d615dc489961aa023549a81b152e8
ecb7454f451694c1c742ac71d78fbed31f4fbb1d6ecc26b01869bc7f68598080
Loading

0 comments on commit 7009361

Please sign in to comment.