-
Notifications
You must be signed in to change notification settings - Fork 618
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
feat: Implicit account creation #3251
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3251 +/- ##
==========================================
- Coverage 87.03% 86.96% -0.08%
==========================================
Files 216 216
Lines 42119 42317 +198
==========================================
+ Hits 36659 36800 +141
- Misses 5460 5517 +57
Continue to review full report at Codecov.
|
&& action_receipt.signer_id == receipt.receiver_id | ||
{ | ||
try_refund_allowance( | ||
if let Some(account) = account.as_mut() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Execution of transfer action
@@ -132,7 +152,18 @@ pub fn exec_fee(config: &RuntimeFeesConfig, action: &Action) -> Gas { | |||
cfg.function_call_cost.exec_fee() | |||
+ cfg.function_call_cost_per_byte.exec_fee() * num_bytes | |||
} | |||
Transfer(_) => cfg.transfer_cost.exec_fee(), | |||
Transfer(_) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated exec fees
@@ -88,7 +92,18 @@ pub fn total_send_fees( | |||
cfg.function_call_cost.send_fee(sender_is_receiver) | |||
+ cfg.function_call_cost_per_byte.send_fee(sender_is_receiver) * num_bytes | |||
} | |||
Transfer(_) => cfg.transfer_cost.send_fee(sender_is_receiver), | |||
Transfer(_) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated send fee
@@ -509,19 +552,47 @@ pub(crate) fn check_account_existence( | |||
action: &Action, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic for checking whether the current action is allowed.
@@ -343,6 +348,44 @@ pub(crate) fn action_create_account( | |||
}); | |||
} | |||
|
|||
pub(crate) fn action_implicit_account_creation_transfer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Execution of transfer action with implicit account creation
@@ -1358,6 +1389,25 @@ impl<'a> VMLogic<'a> { | |||
|
|||
let (receipt_idx, sir) = self.promise_idx_to_receipt_idx_with_sir(promise_idx)?; | |||
|
|||
if self.current_protocol_version >= IMPLICIT_ACCOUNT_CREATION_PROTOCOL_VERSION { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We charge more base fees for transfer on 64len hex account under new protocol
Please use my comments to navigate logical changes in the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a surjection between ed25519 keypairs and byte arrays of length 32?
use near_vm_logic::{ReturnData, VMConfig, VMContext, VMOutcome}; | ||
use near_vm_runner::{run, VMError}; | ||
|
||
const LATEST_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runner doesn't have primitives, so I can't use real protocol version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if Bowen asked why do you need to introduce this const. It seems ProtocolVersion::MAX
is quite descriptive to use it inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. @bowenwang1996 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering whether using max here can cause problems. For example if we have some function that requires doing arithmetic on protocol version it might easily overflow.
Aa part of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we run nightly tests on this PR?
use near_vm_logic::{ReturnData, VMConfig, VMContext, VMOutcome}; | ||
use near_vm_runner::{run, VMError}; | ||
|
||
const LATEST_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if Bowen asked why do you need to introduce this const. It seems ProtocolVersion::MAX
is quite descriptive to use it inline.
This PR implements near/NEPs#71 It contains a bunch of boilerplate code to pass the protocol version to VM and tests. Logical changes: - Bumps protocol version to 35 - Post protocol version, when a transfer action is executed on the 64-length hex like account ID as a single action in a transaction, it creates a new account if the account doesn't exist and add the ED25519 public key from the account ID hex representation. - If a CreateAccount action attempts to create 64-length hex like account, it fails. - Refunds don't automatically create accounts, because refunds are free and we don't want some type of abuse. NOTE: Account deletion with beneficiary creates a refund, so it'll not create a new account. - `TransferAction` fee cost on such 64-len hex accounts include `CreateAction` and `AddFullAccessKey` costs - The fee is also updated when calling a promise. - `VMLogic::new` change is backward compatible until we release a new `near-sdk` version. So it shouldn't break master after pushing it. - Bump `near-vm-*` versions to `2.2.0`. TODO: - [x] Add integration test for transfer from promise - [x] Add migration test for transfer to 64len - [x] Uncomment `VMLogic::new` for `near-sdk` `MockedBlockchain` ## Test plan: - CI - Added integration test and migration test
This PR implements near/NEPs#71 It contains a bunch of boilerplate code to pass the protocol version to VM and tests. Logical changes: - Bumps protocol version to 35 - Post protocol version, when a transfer action is executed on the 64-length hex like account ID as a single action in a transaction, it creates a new account if the account doesn't exist and add the ED25519 public key from the account ID hex representation. - If a CreateAccount action attempts to create 64-length hex like account, it fails. - Refunds don't automatically create accounts, because refunds are free and we don't want some type of abuse. NOTE: Account deletion with beneficiary creates a refund, so it'll not create a new account. - `TransferAction` fee cost on such 64-len hex accounts include `CreateAction` and `AddFullAccessKey` costs - The fee is also updated when calling a promise. - `VMLogic::new` change is backward compatible until we release a new `near-sdk` version. So it shouldn't break master after pushing it. - Bump `near-vm-*` versions to `2.2.0`. TODO: - [x] Add integration test for transfer from promise - [x] Add migration test for transfer to 64len - [x] Uncomment `VMLogic::new` for `near-sdk` `MockedBlockchain` ## Test plan: - CI - Added integration test and migration test
This PR implements near/NEPs#71
It contains a bunch of boilerplate code to pass the protocol version to VM and tests.
Logical changes:
TransferAction
fee cost on such 64-len hex accounts includeCreateAction
andAddFullAccessKey
costsVMLogic::new
change is backward compatible until we release a newnear-sdk
version. So it shouldn't break master after pushing it.near-vm-*
versions to2.2.0
.TODO:
VMLogic::new
fornear-sdk
MockedBlockchain
Test plan: