Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim account #1

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
00771aa
restructure account and account metadata objects
quocle108 Dec 31, 2023
70478b1
restructure resource object
quocle108 Jan 1, 2024
b8b7904
add slim account protocol feature
quocle108 Jan 2, 2024
778963d
test slim account
quocle108 Jan 4, 2024
b0295d0
slim account chain api
quocle108 Jan 5, 2024
0b85c3d
remove slim activatio
quocle108 Jan 5, 2024
2427a08
unused policy
quocle108 Jan 5, 2024
46c0d2f
fixed
quocle108 Jan 5, 2024
37fe103
add test set contract for slim accounts
quocle108 Jan 9, 2024
795571d
update account resource logs and history
quocle108 Jan 10, 2024
3b2a608
charge RAM for metadata object
quocle108 Jan 10, 2024
dc889d4
update history state acording change change from permission object
quocle108 Jan 11, 2024
79e3ef4
format
quocle108 Jan 12, 2024
26de6df
upodate ram bill for permissionion object
quocle108 Jan 13, 2024
ef0af5f
read objects from old snapshot
quocle108 Jan 15, 2024
e6f5553
add doc to create s slim account
quocle108 Jan 15, 2024
fd9e4e1
fixed creating slim account doc
quocle108 Jan 15, 2024
1c88575
typo
quocle108 Jan 15, 2024
ca546a6
fixed last_used time for permission 0
quocle108 Jan 16, 2024
552497b
fixed snapshot compatible test
quocle108 Jan 16, 2024
b691432
revert state history test
quocle108 Jan 16, 2024
b7de2f9
create slim account with owner key instead of active key
quocle108 Mar 7, 2024
73a4ee9
add more tests for slim accounts
quocle108 Mar 14, 2024
387205a
system accounts cannot create through newslimacc action
quocle108 Mar 15, 2024
46bbe46
update doc for slim accounts
quocle108 Mar 15, 2024
1f05d53
move abi field from account object to account metadata object
quocle108 Mar 16, 2024
ddfbec9
refactor implementation to load old snapshot for account object
quocle108 Mar 18, 2024
e29ccf2
refactor loading snapshot for account and permisison object
quocle108 Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/02_cleos/02_how-to-guides/how-to-create-a-slim-account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Overview

This how-to guide provides instructions on how to create a new slim Antelope blockchain account using the `cleos` CLI tool. You can use accounts to deploy smart contracts and perform other related blockchain operations. Create one or multiple accounts as part of your development environment setup.

The example in this how-to guide creates a new account named **ted**, authorized by the default system account **eosio**, using the `cleos` CLI tool.

## Before you Begin

Make sure you meet the following requirements:

* Install the currently supported version of `cleos`.
[[info | Note]]
| The cleos tool is bundled with the Antelope software. [Installing Antelope](../../00_install/index.md) will also install the cleos tool.
* Learn about [Antelope Accounts and Permissions](/protocol-guides/04_accounts_and_permissions.md)
* Learn about Asymmetric Cryptography - [public key](/glossary.md#public-key) and [private key](/glossary.md#private-key) pairs.
* Create public/private keypair for the `active` permissions of an account.

## Command Reference

See the following reference guide for `cleos` command line usage and related options:
* [`cleos create slimaccount`](../03_command-reference/create/slim_account.md) command and its parameters

## Procedure

The following step shows how to create a new account **ted** authorized by the default system account **eosio**.

1. Run the following command to create the new account **ted**:

```sh
cleos create slimaccount eosio ted EOS87TQktA5RVse2EguhztfQVEh6XXxBmgkU8b4Y5YnGvtYAoLGNN
```
**Where**:
* `eosio` = the system account that authorizes the creation of a new account
* `ted` = the name of the new account conforming to [account naming conventions](/protocol-guides/04_accounts_and_permissions.md#2-accounts)
* `EOS87TQ...AoLGNN` = the active public key or permission level for the new account (**required**)
[[info | Note]]
| To create a new account in the Antelope blockchain, an existing account, also referred to as a creator account, is required to authorize the creation of a new account. For a newly created Antelope blockchain, the default system account used to create a new account is **eosio**.

**Example Output**

```console
executed transaction: 80a54e6220ba90edfae2f35d1841f72660313337294685937ab4eedf422a26d8 152 bytes 139 us
# eosio <= eosio::newslimacc "0000000000ea305500000000000092ca01000000010003a887c1d7893cb40746c6f8fc6e0a964320d0316b85c6ebc8c905a...
warning: transaction executed locally, but may not be confirmed by the network yet ]
```

### Summary

By following these instructions, you are able to create a new slim Antelope account in your blockchain environment.
107 changes: 107 additions & 0 deletions docs/02_cleos/03_command-reference/create/slim_account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
## Description
Create a new slim account on the blockchain (assumes system contract does not restrict RAM usage)

## Usage

```console
Usage: cleos create slimaccount [OPTIONS] creator name ActiveKey

Positionals:
creator TEXT The name of the account creating the new account (required)
name TEXT The name of the new account (required)
ActiveKey TEXT The active public key or permission level for the new account

Options:
-h,--help Print this help message and exit
-x,--expiration set the time in seconds before a transaction expires, defaults to 30s
-f,--force-unique force the transaction to be unique. this will consume extra bandwidth and remove any protections against accidently issuing the same transaction multiple times
-s,--skip-sign Specify if unlocked wallet keys should be used to sign transaction
-j,--json print result as json
--json-file TEXT save result in json format into a file
-d,--dont-broadcast don't broadcast transaction to the network (just print to stdout)
--return-packed used in conjunction with --dont-broadcast to get the packed transaction
-r,--ref-block TEXT set the reference block num or block id used for TAPOS (Transaction as Proof-of-Stake)
--use-old-rpc use old RPC push_transaction, rather than new RPC send_transaction
-p,--permission TEXT ... An account and permission level to authorize, as in 'account@permission' (defaults to 'creator@active')
--max-cpu-usage-ms UINT set an upper limit on the milliseconds of cpu usage budget, for the execution of the transaction (defaults to 0 which means no limit)
--max-net-usage UINT set an upper limit on the net usage budget, in bytes, for the transaction (defaults to 0 which means no limit)
--delay-sec UINT set the delay_sec seconds, defaults to 0s
```

## Command
A set of Antelope keys is required to create an account. The Antelope keys can be generated by using `cleos create key`.

```sh
cleos create slimaccount eosio alice EOS4toFS3YXEQCkuuw1aqDLrtHim86Gz9u3hBdcBw5KNPZcursVHq
```

## Output

```json
{
"transaction_id": "089e813085a99d854a3e6425fddd63d9fb6cfa1b11ebf807f134d0be1046bc2b",
"processed": {
"id": "089e813085a99d854a3e6425fddd63d9fb6cfa1b11ebf807f134d0be1046bc2b",
"block_num": 222,
"block_time": "2024-01-15T15:54:26.500",
"producer_block_id": null,
"receipt": {
"status": "executed",
"cpu_usage_us": 138,
"net_usage_words": 19
},
"elapsed": 138,
"net_usage": 152,
"scheduled": false,
"action_traces": [{
"action_ordinal": 1,
"creator_action_ordinal": 0,
"closest_unnotified_ancestor_action_ordinal": 0,
"receipt": {
"receiver": "eosio",
"act_digest": "bfe408bd33f540cb6696d1a3a0a28ade8e72c5206b7de25f2b24589b41518725",
"global_sequence": 233,
"recv_sequence": 233,
"auth_sequence": [[
"eosio",
233
]
],
"code_sequence": 0,
"abi_sequence": 0
},
"receiver": "eosio",
"act": {
"account": "eosio",
"name": "newslimacc",
"authorization": [{
"actor": "eosio",
"permission": "active"
}
],
"data": "0000000000ea30550000000000855c340100000001000200b35ad060d629717bd3dbec82731094dae9cd7e9980c39625ad58fa7f9b654b01000000",
"hex_data": "0000000000ea30550000000000855c340100000001000200b35ad060d629717bd3dbec82731094dae9cd7e9980c39625ad58fa7f9b654b01000000"
},
"context_free": false,
"elapsed": 43,
"console": "",
"trx_id": "089e813085a99d854a3e6425fddd63d9fb6cfa1b11ebf807f134d0be1046bc2b",
"block_num": 222,
"block_time": "2024-01-15T15:54:26.500",
"producer_block_id": null,
"account_ram_deltas": [{
"account": "alice",
"delta": 2210
}
],
"except": null,
"error_code": null,
"return_value_hex_data": ""
}
],
"account_ram_delta": null,
"except": null,
"error_code": null
}
}
```
27 changes: 27 additions & 0 deletions docs/02_cleos/03_command-reference/system/system-newslimacc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Description

Create a slim account, buy ram, stake for bandwidth for the account

## Positional Arguments
- `creator` _TEXT_ - The name of the account creating the new account
- `name` _TEXT_ - The name of the new account
- `ActiveKey` _TEXT_ - The active public key for the new account
## Options
- `-h,--help` Print this help message and exit
- `--stake-net` _TEXT_ - The amount of EOS delegated for net bandwidth
- `--stake-cpu` _TEXT_ - The amount of EOS delegated for CPU bandwidth
- `--buy-ram-bytes` _UINT_ - The amount of RAM bytes to purchase for the new account in kilobytes KiB, default is 8 KiB
- `--buy-ram-EOS` _TEXT_ - The amount of RAM bytes to purchase for the new account in EOS
- `--transfer` - Transfer voting power and right to unstake EOS to receiver
- `-x,--expiration` _TEXT_ - set the time in seconds before a transaction expires, defaults to 30s
- `-f,--force-unique` - force the transaction to be unique. this will consume extra bandwidth and remove any protections against accidently issuing the same transaction multiple times
- `-s,--skip-sign` Specify if unlocked wallet keys should be used to sign transaction
- `-d,--dont-broadcast` - Don't broadcast transaction to the network (just print to stdout)
- `-r,--ref-block` _TEXT_ set the reference block num or block id used for TAPOS (Transaction as Proof-of-Stake)
- `-p,--permission` _TEXT_ - An account and permission level to authorize, as in 'account@permission' (defaults to 'account@active')
- `--max-cpu-usage-ms` _UINT_ - set an upper limit on the milliseconds of cpu usage budget, for the execution of the transaction (defaults to 0 which means no limit)
- `--max-net-usage` _UINT_ - set an upper limit on the net usage budget, in bytes, for the transaction (defaults to 0 which means no limit)
- `--delay-sec` _UINT_ set the delay_sec seconds, defaults to 0s
- `-j,--json` print result as json

## Examples
38 changes: 20 additions & 18 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ void apply_context::exec_one()

digest_type act_digest;

const account_metadata_object* receiver_account = nullptr;
const account_object* receiver_account = nullptr;
const account_metadata_object* receiver_account_metadata = nullptr;

auto handle_exception = [&](const auto& e)
{
Expand All @@ -80,9 +81,10 @@ void apply_context::exec_one()
try {
try {
action_return_value.clear();
receiver_account = &db.get<account_metadata_object,by_name>( receiver );
if( !(context_free && control.skip_trx_checks()) ) {
privileged = receiver_account->is_privileged();
receiver_account = &db.get<account_object,by_name>( receiver );
receiver_account_metadata = db.find<account_metadata_object,by_name>( receiver );
if( receiver_account_metadata != nullptr && !(context_free && control.skip_trx_checks()) ) {
privileged = receiver_account_metadata->is_privileged();
auto native = control.find_apply_handler( receiver, act->account, act->name );
if( native ) {
if( trx_context.enforce_whiteblacklist && control.is_speculative_block() ) {
Expand All @@ -92,7 +94,7 @@ void apply_context::exec_one()
(*native)( *this );
}

if( ( receiver_account->code_hash != digest_type() ) &&
if( ( receiver_account_metadata->code_hash != digest_type() ) &&
( !( act->account == config::system_account_name
&& act->name == "setcode"_n
&& receiver == config::system_account_name )
Expand All @@ -104,7 +106,7 @@ void apply_context::exec_one()
control.check_action_list( act->account, act->name );
}
try {
control.get_wasm_interface().apply( receiver_account->code_hash, receiver_account->vm_type, receiver_account->vm_version, *this );
control.get_wasm_interface().apply( receiver_account_metadata->code_hash, receiver_account_metadata->vm_type, receiver_account_metadata->vm_version, *this );
} catch( const wasm_exit& ) {}
}

Expand Down Expand Up @@ -155,10 +157,10 @@ void apply_context::exec_one()
handle_exception(wrapper);
}

// Note: It should not be possible for receiver_account to be invalidated because:
// Note: It should not be possible for receiver_account_metadata to be invalidated because:
// * a pointer to an object in a chainbase index is not invalidated if other objects in that index are modified, removed, or added;
// * a pointer to an object in a chainbase index is not invalidated if the fields of that object are modified;
// * and, the *receiver_account object itself cannot be removed because accounts cannot be deleted in EOSIO.
// * and, the *receiver_account_metadata object itself cannot be removed because accounts cannot be deleted in EOSIO.

action_trace& trace = trx_context.get_action_trace( action_ordinal );
trace.return_value = std::move(action_return_value);
Expand All @@ -170,15 +172,15 @@ void apply_context::exec_one()
r.global_sequence = next_global_sequence();
r.recv_sequence = next_recv_sequence( *receiver_account );

const account_metadata_object* first_receiver_account = nullptr;
const account_metadata_object* first_receiver_account_metadata = nullptr;
if( act->account == receiver ) {
first_receiver_account = receiver_account;
first_receiver_account_metadata = receiver_account_metadata;
} else {
first_receiver_account = &db.get<account_metadata_object, by_name>(act->account);
first_receiver_account_metadata = db.find<account_metadata_object, by_name>(act->account);
}

r.code_sequence = first_receiver_account->code_sequence; // could be modified by action execution above
r.abi_sequence = first_receiver_account->abi_sequence; // could be modified by action execution above
r.code_sequence = first_receiver_account_metadata != nullptr ? first_receiver_account_metadata->code_sequence : 0; // could be modified by action execution above
r.abi_sequence = first_receiver_account_metadata != nullptr ? first_receiver_account_metadata->abi_sequence: 0; // could be modified by action execution above

for( const auto& auth : act->authorization ) {
r.auth_sequence[auth.actor] = next_auth_sequence( auth.actor );
Expand Down Expand Up @@ -1053,7 +1055,7 @@ uint64_t apply_context::next_global_sequence() {
}
}

uint64_t apply_context::next_recv_sequence( const account_metadata_object& receiver_account ) {
uint64_t apply_context::next_recv_sequence( const account_object& receiver_account ) {
if ( trx_context.is_read_only() ) {
// To avoid confusion of duplicated receive sequence number, hard code to be 0.
return 0;
Expand All @@ -1065,11 +1067,11 @@ uint64_t apply_context::next_recv_sequence( const account_metadata_object& recei
}
}
uint64_t apply_context::next_auth_sequence( account_name actor ) {
const auto& amo = db.get<account_metadata_object,by_name>( actor );
db.modify( amo, [&](auto& am ){
++am.auth_sequence;
const auto& ao = db.get<account_object,by_name>( actor );
db.modify( ao, [&](auto& a ){
++a.auth_sequence;
});
return amo.auth_sequence;
return ao.auth_sequence;
}

void apply_context::add_ram_usage( account_name account, int64_t ram_delta ) {
Expand Down
Loading