-
Notifications
You must be signed in to change notification settings - Fork 48
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
Implemented writing on-chain accounts details on block applying #294
Conversation
# Conflicts: # .gitignore # Cargo.toml
06d453a
to
63be641
Compare
1d6d3a4
to
c0110c7
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.
partial review, since this is built in another pr.
.map(|(account_id, account_states)| (*account_id, account_states.final_state)) | ||
pub fn updated_accounts( | ||
&self | ||
) -> impl Iterator<Item = (AccountId, Option<AccountDetails>, Digest)> + '_ { |
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 you add a struct type for the return tuple? It should make the code a bit easier to read.
block.updated_accounts.iter().map(|(account_id, _, _)| *account_id).collect(); | ||
let produced_nullifiers = block.produced_nullifiers.clone(); | ||
|
||
self.store.apply_block(block).await?; |
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 assume that store.apply_block
encodes the Block
into a protobuf message. Meaning it doesn't need ownership of Block
. If that is the case, I think we should change it to receive a reference, and then here we don't need the copies.
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.
@hackaugusto we can't do it simple way because the block needs be disassembled inside apply_block
:
miden-node/block-producer/src/store/mod.rs
Lines 137 to 140 in 8f0935a
block: Some(block.header.into()), | |
accounts: convert(block.updated_accounts), | |
nullifiers: convert(block.produced_nullifiers), | |
notes: convert(block.created_notes), |
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.
The linked code is creating new objects. At first sight it seems none of them require ownership.
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.
Done, thanks for noticing!
store/src/db/sql.rs
Outdated
if let Some(details) = details { | ||
match details { | ||
AccountDetails::Full(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.
nit: this could be just:
match details {
Some(AccountDetails::Full(account)) => { ... },
Some(AccountDetails::Delta(delta)) => { ... },
None => (),
}
Not a huge improvement, but this makes the indentation shallower which IMO is a bit easier to read.
store/src/server/api.rs
Outdated
@@ -190,11 +221,15 @@ impl api_server::Api for StoreApi { | |||
.accounts | |||
.into_iter() | |||
.map(|account_update| { | |||
let account_details: Option<AccountDetails> = | |||
<Option<AccountDetails>>::read_from_bytes(&account_update.details) | |||
.map_err(|err| Status::invalid_argument(err.to_string()))?; |
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 should have validation:
- if the account is on-chain, there must be details
- if the account is off-chain, there must NOT be any details
aa86a10
to
324bca3
Compare
# Conflicts: # Cargo.lock # block-producer/src/block_builder/prover/tests.rs # block-producer/src/block_builder/tests.rs # block-producer/src/test_utils/account.rs # store/src/db/tests.rs
324bca3
to
d338bda
Compare
d338bda
to
7f09974
Compare
chore: update `miden-base` dependency to fixed version refactor: extract `apply_delta` function fix: separate error invariant for missed details in store fix: make account details optional refactor: introduce `UpdatedAccount` struct fix: avoid cloning of block data feat: simple details validation in store feat: rewrite `sql::upsert_accounts` to simplified work with details and update test fix: compilation errors feat: use serialized account details feat: writing account details on block applying
# Conflicts: # Cargo.lock # proto/src/domain/accounts.rs # store/src/db/mod.rs # store/src/db/sql.rs # store/src/db/tests.rs # store/src/errors.rs # store/src/server/api.rs # store/src/state.rs
7f09974
to
328042b
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! I left some comments inline.
The main open question is how to verify that the account details included with a public account are valid. The most problematic part of this is to verify account delta for existing accounts. Ideally, this should be happening in the RPC so that a proven transaction with malformed account delta would not make it into the block producer. But I'm not seeing an efficient way of doing this. So, the current approach is fine, but let's create an issue to figure out how to validate account delta more holistically.
# Conflicts: # rpc/README.md # store/README.md # store/src/db/mod.rs # store/src/db/sql.rs # store/src/db/tests.rs # store/src/server/api.rs # store/src/state.rs
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.
Looks good! Thank you! I left a couple of very small nits inline. After these, we can merge.
rpc/README.md
Outdated
@@ -111,7 +110,7 @@ contains excessive notes and nullifiers, client can make additional filtering of | |||
- `chain_tip`: `uint32` – number of the latest block in the chain. | |||
- `block_header`: `BlockHeader` – block header of the block with the first note matching the specified criteria. | |||
- `mmr_delta`: `MmrDelta` – data needed to update the partial MMR from `block_num + 1` to `block_header.block_num`. | |||
- `accounts`: `[AccountHashUpdate]` – a list of account hashes updated after `block_num + 1` but not after `block_header.block_num`. | |||
- `accounts`: `[AccountSummary]` – a list of account hashes updated after `block_num + 1` but not after `block_header.block_num`. |
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.
nit: I would probably change the description to something like: "account summaries for accounts updated after ...".
store/README.md
Outdated
@@ -157,7 +156,7 @@ contains excessive notes and nullifiers, client can make additional filtering of | |||
- `chain_tip`: `uint32` – number of the latest block in the chain. | |||
- `block_header`: `BlockHeader` – block header of the block with the first note matching the specified criteria. | |||
- `mmr_delta`: `MmrDelta` – data needed to update the partial MMR from `block_num + 1` to `block_header.block_num`. | |||
- `accounts`: `[AccountHashUpdate]` – a list of account hashes updated after `block_num + 1` but not after `block_header.block_num`. | |||
- `accounts`: `[AccountSummary]` – a list of account hashes updated after `block_num + 1` but not after `block_header.block_num`. |
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.
Same nit as above.
* feat: add `account_details` table to the DB * refactor: rename `block_number` column in nullifiers table to `block_num` * refactor: use `BETWEEN` in interval comparison checks * feat: implement account details protobuf messages, domain objects and conversions * feat: (WIP) implement account details support * feat: (WIP) implement account details support * feat: (WIP) implement account details support * feat: (WIP) implement account details support * fix: db creation * docs: remove TODO * refactor: apply formatting * feat: implement endpoint for getting public account details * tests: add test for storage * feat: add rpc endpoint for getting account details * refactor: keep only domain object changes * fix: compilation errors * fix: use note tag conversion from `u64` * refactor: remove account details protobuf messages * fix: remove unused error invariants * refactor: introduce `UpdatedAccount` struct * fix: rollback details conversion * fix: compilation error * feat: account details in store * refactor: add constraint name for foreign key * refactor: small code improvement Co-authored-by: Augusto Hack <[email protected]> * feat: account id validation * refactor: rename `get_account_details` to `select_*` * feat: return serialized account details * feat: add requirement of account id to be public in RPC * fix: remove error message used in different PR * fix: union account details with account and process them together * docs: remove `GetAccountDetails` from README.md * fix: remove unused error invariants * fix: use `Account` instead of `AccountDetails` in store * wip * feat: implement `GetAccountDetails` endpoint * docs: document `GetAccountDetails` endpoint * refactor: simplify code, make account details optional * fix: clippy warning * fix: address review comments * fix: update code to the latest miden-base * refactor: little code improvement * fix: remove error message used in different PR * fix: compilation errors chore: update `miden-base` dependency to fixed version refactor: extract `apply_delta` function fix: separate error invariant for missed details in store fix: make account details optional refactor: introduce `UpdatedAccount` struct fix: avoid cloning of block data feat: simple details validation in store feat: rewrite `sql::upsert_accounts` to simplified work with details and update test fix: compilation errors feat: use serialized account details feat: writing account details on block applying * fix: compilation errors, update test * refactor: rename protobuf messages * docs: update endpoint in README.md * tests: get rid of miden-mock dependency * tests: get rid of winter-rand-utils dependency * refactor: rename `AccountDetailsUpdate` to `AccountUpdateDetails` * feat: check for account hash for new on-chain accounts * formatting: run rustfmt * docs: address review comments --------- Co-authored-by: Augusto Hack <[email protected]>
This is the last PR of this series. Here is details of on-chain accounts is written to database.