This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Storage chain: Runtime module #8624
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
bfdfce6
Transaction storage runtime module
arkpar 1784935
WIP: Tests
arkpar dd79ea5
Tests, benchmarks and docs
arkpar 57e1d93
Made check_proof mandatory
arkpar d0af6a0
Typo
arkpar 419bc5d
Renamed a crate
arkpar d9203f3
Apply suggestions from code review
arkpar 448f024
Added weight for on_finalize
arkpar ae7ee0f
Fixed counter mutations
arkpar 2f616eb
Reorganized tests
arkpar 5cdaf89
Fixed build
arkpar b65ca31
Update for the new inherent API
arkpar 6a2aa62
Reworked for the new inherents API
arkpar 65723de
Apply suggestions from code review
arkpar 9ac001b
Store transactions in a Vec
arkpar 4a94450
Added FeeDestination
arkpar c8c0c84
Get rid of constants
arkpar 0c059ee
Fixed node runtime build
arkpar b18d855
Fixed benches
arkpar bca7a81
Update frame/transaction-storage/src/lib.rs
arkpar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ use codec::{Decode, Encode}; | |
use hash_db::Prefix; | ||
use sp_trie::{MemoryDB, PrefixedMemoryDB, prefixed_key}; | ||
use sp_database::Transaction; | ||
use sp_core::{Hasher, ChangesTrieConfiguration}; | ||
use sp_core::ChangesTrieConfiguration; | ||
use sp_core::offchain::OffchainOverlayedChange; | ||
use sp_core::storage::{well_known_keys, ChildInfo}; | ||
use sp_arithmetic::traits::Saturating; | ||
|
@@ -591,6 +591,37 @@ impl<Block: BlockT> sc_client_api::blockchain::Backend<Block> for BlockchainDb<B | |
fn has_indexed_transaction(&self, hash: &Block::Hash) -> ClientResult<bool> { | ||
Ok(self.db.contains(columns::TRANSACTION, hash.as_ref())) | ||
} | ||
|
||
fn block_indexed_body(&self, id: BlockId<Block>) -> ClientResult<Option<Vec<Vec<u8>>>> { | ||
match self.transaction_storage { | ||
TransactionStorageMode::BlockBody => Ok(None), | ||
TransactionStorageMode::StorageChain => { | ||
let body = match read_db(&*self.db, columns::KEY_LOOKUP, columns::BODY, id)? { | ||
Some(body) => body, | ||
None => return Ok(None), | ||
}; | ||
match Vec::<ExtrinsicHeader>::decode(&mut &body[..]) { | ||
Ok(index) => { | ||
let mut transactions = Vec::new(); | ||
for ExtrinsicHeader { indexed_hash, .. } in index.into_iter() { | ||
if indexed_hash != Default::default() { | ||
match self.db.get(columns::TRANSACTION, indexed_hash.as_ref()) { | ||
Some(t) => transactions.push(t), | ||
None => return Err(sp_blockchain::Error::Backend( | ||
format!("Missing indexed transaction {:?}", indexed_hash)) | ||
) | ||
} | ||
} | ||
} | ||
Ok(Some(transactions)) | ||
} | ||
Err(err) => return Err(sp_blockchain::Error::Backend( | ||
format!("Error decoding body list: {}", err) | ||
)), | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<Block: BlockT> sc_client_api::blockchain::ProvideCache<Block> for BlockchainDb<Block> { | ||
|
@@ -1624,10 +1655,10 @@ fn apply_index_ops<Block: BlockT>( | |
let mut renewed_map = HashMap::new(); | ||
for op in ops { | ||
match op { | ||
IndexOperation::Insert { extrinsic, offset } => { | ||
index_map.insert(extrinsic, offset); | ||
IndexOperation::Insert { extrinsic, hash, size } => { | ||
index_map.insert(extrinsic, (hash, size)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for 'size' instead of 'offset' |
||
} | ||
IndexOperation::Renew { extrinsic, hash, .. } => { | ||
IndexOperation::Renew { extrinsic, hash } => { | ||
renewed_map.insert(extrinsic, DbHash::from_slice(hash.as_ref())); | ||
} | ||
} | ||
|
@@ -1643,9 +1674,8 @@ fn apply_index_ops<Block: BlockT>( | |
} | ||
} else { | ||
match index_map.get(&(index as u32)) { | ||
Some(offset) if *offset as usize <= extrinsic.len() => { | ||
let offset = *offset as usize; | ||
let hash = HashFor::<Block>::hash(&extrinsic[offset..]); | ||
Some((hash, size)) if *size as usize <= extrinsic.len() => { | ||
let offset = extrinsic.len() - *size as usize; | ||
transaction.store( | ||
columns::TRANSACTION, | ||
DbHash::from_slice(hash.as_ref()), | ||
|
@@ -3024,13 +3054,16 @@ pub(crate) mod tests { | |
for i in 0 .. 10 { | ||
let mut index = Vec::new(); | ||
if i == 0 { | ||
index.push(IndexOperation::Insert { extrinsic: 0, offset: 1 }); | ||
index.push(IndexOperation::Insert { | ||
extrinsic: 0, | ||
hash: x1_hash.as_ref().to_vec(), | ||
size: (x1.len() - 1) as u32, | ||
}); | ||
} else if i < 5 { | ||
// keep renewing 1st | ||
index.push(IndexOperation::Renew { | ||
extrinsic: 0, | ||
hash: x1_hash.as_ref().to_vec(), | ||
size: (x1.len() - 1) as u32, | ||
}); | ||
} // else stop renewing | ||
let hash = insert_block( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should it be 'Ok(Some(default()))' ? so None indicate missing block like for 'body' function.
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.
There's no default notion for indexed data.
BlockBody
means that no indexed data is stored, soNone
looks appropriate. Also it would be incorrect to returnSome
for blocks that are truly unknown.