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
[breaking][libra framework] add event on account creation #6156
Conversation
c25e3f1
to
dda7b3e
Compare
|
||
assert( | ||
!exists<AccountOperationsCapability>(CoreAddresses::LIBRA_ROOT_ADDRESS()), | ||
Errors::already_published(EACCOUNT_OPERATIONS_CAPABILITY) | ||
); | ||
move_to( | ||
lr_account, | ||
AccountOperationsCapability { | ||
limits_cap: AccountLimits::grant_mutation_capability(lr_account), | ||
} | ||
); | ||
|
||
assert( | ||
!exists<LibraWriteSetManager>(CoreAddresses::LIBRA_ROOT_ADDRESS()), | ||
Errors::already_published(EWRITESET_MANAGER) | ||
); | ||
move_to( | ||
lr_account, | ||
LibraWriteSetManager { | ||
upgrade_events: Event::new_event_handle<Self::UpgradeEvent>(lr_account), | ||
} | ||
); |
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 feels odd for this to be in the in the create_libra_root_account
function. What would you think of doing something like:
create_libra_root_account(...); // As before
emit_event<CreateAccountEvent>(....); // <- emit create account event for LR root account.
<THIS CODE>
create_treasury_compliance_account(...);
here?
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.
Unfortunately, this won't wok because emitting the event (which happens in create_libra_root_account
) requires <THIS_CODE>
to be run first, specifically, the AccountOperationsCapability
part.
I actually felt good about moving this code into create_libra_root_account
because the pattern we use elsewhere is to publish X role-specific resources in create_X_account
. But certainly open to alternatives!
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.
ahhh I see! For some reason I didn't see that the event emission is happening in make_account
.
I'm fine with this as-is since I can't think of any other alternatives that wouldn't make the code more complicated.
/// Message for creation of a new account | ||
struct CreateAccountEvent { | ||
/// Address of the account that was created | ||
created: address, |
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.
What would you think of also including the role id for the account created in this event?
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 love it except that role id's will no longer be opaque. But I'm ok with that because they can already be read off-chain...
language/tools/vm-genesis/src/lib.rs
Outdated
.iter() | ||
.find(|e| e.key() == &NewEpochEvent::event_key()) | ||
.expect("Couldn't find NewEpochEvent"); | ||
assert_eq!(*new_epoch_event.key(), NewEpochEvent::event_key()); |
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.
What would you think of adding an additional check that there's only one new epoch event?
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.
Very good idea, would not want to make that mistake (and it'd be easy to make!).
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.
LGTM!
dda7b3e
to
8877d8b
Compare
2b860d2
to
24cb838
Compare
/canary |
- New CreateAccountEvent struct that records the created address - Had to refactor LibraAccount::initialize() a bit to ensure that we can emit an event for the creation of LibraRoot - Had to refactor the event verification part of VM genesis since the number of events now depends on the # of created accounts - Added tests for each of the create_*_account functions - Added Rust wrapper for CreateAccountEvent Previously, users saw only TYPE_MISMATCH, NUMBER_OF_TYPE_ARGUMENTS_MISMATCH, or LINKER_ERROR, which are not very descriptive Closes: #6118 Closes: #6156
Cluster Test Result
❗ Cluster Test failed - non-zero exit code for Repro cmd:
|
💔 Test Failed - Build images and run cluster test |
/canary |
- New CreateAccountEvent struct that records the created address - Had to refactor LibraAccount::initialize() a bit to ensure that we can emit an event for the creation of LibraRoot - Had to refactor the event verification part of VM genesis since the number of events now depends on the # of created accounts - Added tests for each of the create_*_account functions - Added Rust wrapper for CreateAccountEvent Previously, users saw only TYPE_MISMATCH, NUMBER_OF_TYPE_ARGUMENTS_MISMATCH, or LINKER_ERROR, which are not very descriptive Closes: #6118 Closes: #6156
Cluster Test Result
❗ Cluster Test failed - non-zero exit code for Repro cmd:
|
💔 Test Failed - Build images and run cluster test |
24cb838
to
119cfba
Compare
/canary |
- New CreateAccountEvent struct that records the created address - Had to refactor LibraAccount::initialize() a bit to ensure that we can emit an event for the creation of LibraRoot - Had to refactor the event verification part of VM genesis since the number of events now depends on the # of created accounts - Added tests for each of the create_*_account functions - Added Rust wrapper for CreateAccountEvent Previously, users saw only TYPE_MISMATCH, NUMBER_OF_TYPE_ARGUMENTS_MISMATCH, or LINKER_ERROR, which are not very descriptive Closes: #6118 Closes: #6156
Ahh I forgot about that. Thanks! |
/canary |
- New CreateAccountEvent struct that records the created address - Had to refactor LibraAccount::initialize() a bit to ensure that we can emit an event for the creation of LibraRoot - Had to refactor the event verification part of VM genesis since the number of events now depends on the # of created accounts - Added tests for each of the create_*_account functions - Added Rust wrapper for CreateAccountEvent Previously, users saw only TYPE_MISMATCH, NUMBER_OF_TYPE_ARGUMENTS_MISMATCH, or LINKER_ERROR, which are not very descriptive Closes: #6118 Closes: #6156
Cluster Test Result
Repro cmd:
🎉 Land-blocking cluster test passed! 👌 |
☀️ Canary successful |
/land |
🔒 Merge Conflict |
71b0e07
to
d2c6376
Compare
/land |
/cancel |
437f9d7
to
b49195c
Compare
/land |
- New CreateAccountEvent struct that records the created address - Had to refactor LibraAccount::initialize() a bit to ensure that we can emit an event for the creation of LibraRoot - Had to refactor the event verification part of VM genesis since the number of events now depends on the # of created accounts - Added tests for each of the create_*_account functions - Added Rust wrapper for CreateAccountEvent Previously, users saw only TYPE_MISMATCH, NUMBER_OF_TYPE_ARGUMENTS_MISMATCH, or LINKER_ERROR, which are not very descriptive Closes: diem#6118 Closes: diem#6156
Cluster Test Result
Repro cmd:
🎉 Land-blocking cluster test passed! 👌 |
b49195c
to
6726e57
Compare
CreateAccountEvent
struct that records the created address