-
Notifications
You must be signed in to change notification settings - Fork 60
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
Simplified account details for on-chain accounts (only delta remains) #530
Conversation
As I mentioned in #524, I think we should probably put this on hold for now. But as far as this PR goes, we'd also need to update deserialization code for |
beea8af
to
dc072b2
Compare
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.
Thank you! Looks good. Not a full review yet - but I left some comments inline.
CHANGELOG.md
Outdated
@@ -2,6 +2,8 @@ | |||
|
|||
## 0.3.0 (TBD) | |||
|
|||
* [BREAKING] Simplified account details for on-chain accounts, now only delta provided |
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.
minor nit: let's add a PR number to this line (similar to how we do it for other changes below).
pub struct AccountDelta { | ||
storage: AccountStorageDelta, | ||
vault: AccountVaultDelta, | ||
code: Option<AccountCode>, | ||
nonce: Option<Felt>, | ||
} |
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 should also update comments for this struct.
@@ -31,7 +31,11 @@ impl AccountStorageDelta { | |||
/// - The number of cleared or updated items is greater than 255. | |||
/// - Any of cleared or updated items are at slot 255 (i.e., immutable slot). | |||
/// - Any of the cleared or updated items is referenced more than once (e.g., updated twice). | |||
pub fn validate(&self) -> Result<(), AccountDeltaError> { | |||
pub fn validate(&self, is_new_account: bool) -> Result<(), AccountDeltaError> { |
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.
Let's update the comments above to include this new error condition.
if nonce != Some(ZERO) { | ||
return Err(AccountDeltaError::IncorrectNonceForNewAccount(nonce)); | ||
} |
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'm not sure this is correct: nonce for a new account would start out as zero, but after the update it would not be zero. So, the nonce in the delta would not be zero. We could potentially force the nonce for the first update to be one - but I'm not sure that's a good idea.
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.
Let's make sure deserialization code here works correctly. I think this will currently fail for new accounts as for new accounts we need to set storage layout in MAX_MUTABLE_STORAGE_SLOT_IDX
but deserialization code would not allow this.
@@ -28,7 +28,11 @@ impl AccountVaultDelta { | |||
/// - The number of removed assets is greater than [u16::MAX]. | |||
/// - The same asset was added more than once, removed more than once, or both added and | |||
/// removed. | |||
pub fn validate(&self) -> Result<(), AccountDeltaError> { | |||
pub fn validate(&self, is_new_account: bool) -> Result<(), AccountDeltaError> { |
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.
Let's update the comments above describing the new failure condition.
/// Creates and returns a new account constructed from the specified ID and delta. | ||
pub fn from_delta(id: AccountId, delta: &AccountDelta) -> Result<Self, AccountError> { |
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 should probably return an error from here if the delta is not for new account.
let storage = AccountStorage::new( | ||
delta | ||
.storage() | ||
.updated_items | ||
.iter() | ||
.map(|&(index, value)| SlotItem { | ||
index, | ||
slot: StorageSlot::new_value(value), | ||
}) | ||
.collect(), | ||
)?; |
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.
This may be fine for now - but we'll also need to handle other storage slot types (e.g., storage map which are implemented in #521). So, I wonder if it would be better to encapsulate this in the AccountStorageDelta
- e.g., by implementing TryFrom<AccountStorageDelta> for <AccountStorage>
.
@bobbinth thank you! |
# Conflicts: # CHANGELOG.md # objects/src/transaction/proven_tx.rs
Yeah - I was wondering the same thing. It seems like we are introducing a lot of code to handle the special case of If we do keep the things the way they are now, we should probably rename pub enum AccountUpdateDetails {
None,
NewAccount(Account),
Delta(AccountDelta),
} Another potential thing we might want to do is to define a new struct for pub struct AccountUpdate {
init_hash: Diget,
final_hash: Digest,
details: AccountUpdateDetails,
} And then pub struct ProvenTransaction {
id: TransactionId,
account_id: AccountId,
account_update: AccountUpdate,
input_notes: InputNotes<Nullifier>,
output_notes: OutputNotes,
block_ref: Digest,
proof: ExecutionProof,
} |
@bobbinth thank you! |
I don't really understand why the special cases are needed. But if you and @bobbinth think the change is worse, totally fine with me to not do it. |
There are a couple of reasons. First is validation of the delta. For example, for new accounts, the vault delta should not have any If we forego special cases during validation, that would probably simplify things enough to make it worth it. But I'm not sure if that's a good idea. |
Closed in favour of #618 |
Related to issue: #524
We decided to use just
AccountDelta
for on-chain accounts, even for new ones. In this case, all values must be provided.Limitations:
updated_values
). Maps and arrays are not supported.I think, we also should discuss these limitations. Do we really want to move in that direction? It seems, we would need to add more and more special cases for delta processing for new/existing accounts so this will lead to even worse code than it was before simplification.