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

Recording partial trie for storage proofs #1177

Merged
merged 2 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 13 additions & 3 deletions chain/chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use near_primitives::transaction::{
};
use near_primitives::types::{AccountId, BlockIndex, MerkleHash, ShardId, ValidatorStake};
use near_store::test_utils::create_test_store;
use near_store::{Store, StoreUpdate, Trie, TrieChanges, WrappedTrieChanges};
use near_store::{PartialStorage, Store, StoreUpdate, Trie, TrieChanges, WrappedTrieChanges};

use crate::error::{Error, ErrorKind};
use crate::types::{BlockHeader, ReceiptResult, RuntimeAdapter, Weight};
Expand Down Expand Up @@ -152,7 +152,7 @@ impl RuntimeAdapter for KeyValueRuntime {
Ok((parent_hash, 0))
}

fn apply_transactions(
fn apply_transactions_with_optional_storage_proof(
&self,
_shard_id: ShardId,
state_root: &MerkleHash,
Expand All @@ -161,10 +161,19 @@ impl RuntimeAdapter for KeyValueRuntime {
_block_hash: &CryptoHash,
_receipts: &Vec<Vec<Receipt>>,
transactions: &Vec<SignedTransaction>,
generate_storage_proof: bool,
) -> Result<
(WrappedTrieChanges, MerkleHash, Vec<TransactionLog>, ReceiptResult, Vec<ValidatorStake>),
(
WrappedTrieChanges,
MerkleHash,
Vec<TransactionLog>,
ReceiptResult,
Vec<ValidatorStake>,
Option<PartialStorage>,
),
Box<dyn std::error::Error>,
> {
assert!(!generate_storage_proof);
let mut tx_results = vec![];
for tx in transactions {
tx_results.push(TransactionLog {
Expand All @@ -183,6 +192,7 @@ impl RuntimeAdapter for KeyValueRuntime {
tx_results,
HashMap::default(),
vec![],
None,
))
}

Expand Down
47 changes: 45 additions & 2 deletions chain/chain/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use near_primitives::receipt::Receipt;
use near_primitives::rpc::QueryResponse;
use near_primitives::transaction::{SignedTransaction, TransactionLog};
use near_primitives::types::{AccountId, BlockIndex, MerkleHash, ShardId, ValidatorStake};
use near_store::{StoreUpdate, WrappedTrieChanges};
use near_store::{PartialStorage, StoreUpdate, WrappedTrieChanges};

use crate::error::Error;

Expand Down Expand Up @@ -126,7 +126,7 @@ pub trait RuntimeAdapter: Send + Sync {
fn apply_transactions(
&self,
shard_id: ShardId,
merkle_hash: &MerkleHash,
state_root: &MerkleHash,
block_index: BlockIndex,
prev_block_hash: &CryptoHash,
block_hash: &CryptoHash,
Expand All @@ -135,6 +135,49 @@ pub trait RuntimeAdapter: Send + Sync {
) -> Result<
(WrappedTrieChanges, MerkleHash, Vec<TransactionLog>, ReceiptResult, Vec<ValidatorStake>),
Box<dyn std::error::Error>,
> {
self.apply_transactions_with_optional_storage_proof(
shard_id,
state_root,
block_index,
prev_block_hash,
block_hash,
receipts,
transactions,
false,
)
.map(
|(
trie_changes,
root,
tx_results,
receipt_result,
validator_proposals,
_partial_storage,
)| (trie_changes, root, tx_results, receipt_result, validator_proposals),
)
}

fn apply_transactions_with_optional_storage_proof(
&self,
shard_id: ShardId,
state_root: &MerkleHash,
block_index: BlockIndex,
prev_block_hash: &CryptoHash,
block_hash: &CryptoHash,
receipts: &Vec<Vec<Receipt>>,
transactions: &Vec<SignedTransaction>,
generate_storage_proof: bool,
) -> Result<
(
WrappedTrieChanges,
MerkleHash,
Vec<TransactionLog>,
ReceiptResult,
Vec<ValidatorStake>,
Option<PartialStorage>,
),
Box<dyn std::error::Error>,
>;

/// Query runtime with given `path` and `data`.
Expand Down
4 changes: 2 additions & 2 deletions core/store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use near_protos::access_key as access_key_proto;
use near_protos::account as account_proto;

pub use crate::trie::{
update::TrieUpdate, update::TrieUpdateIterator, Trie, TrieChanges, TrieIterator,
WrappedTrieChanges,
update::TrieUpdate, update::TrieUpdateIterator, PartialStorage, Trie, TrieChanges,
TrieIterator, WrappedTrieChanges,
};

pub mod test_utils;
Expand Down
Loading