-
Notifications
You must be signed in to change notification settings - Fork 129
Ocean API: rocks db implementation for ocean API #2728
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b057f66
added ain-ocean
nagarajm22 f3c7679
added rpc server
nagarajm22 31d7ddd
added rpc server
nagarajm22 81f084c
fixed tokio crate
nagarajm22 2b50e51
added server
nagarajm22 0c130b7
added server
nagarajm22 bffd6f9
added rpc server and block modules
nagarajm22 6ff36de
added default value to config
nagarajm22 7b078c0
added default value to config
nagarajm22 6a5cf8f
added default value to config
nagarajm22 65cfb56
added default value to config and server stop
nagarajm22 4fc80fd
added rocks db with multiple table and column strucutre
nagarajm22 335e583
added rocks db with multiple table and column strucutre
nagarajm22 b71040a
added rocks db test cases
nagarajm22 2a853fc
added rocks db test cases
nagarajm22 68d912f
fixed rocks db test cases
nagarajm22 aa30821
added readme for ocean api
nagarajm22 9141d57
Ocean endpoints scaffold
Jouzo 1c28652
Start ocean server
Jouzo af87e90
added rocks database
nagarajm22 43914e8
added table and db methods
nagarajm22 f82ea41
added table and db methods
nagarajm22 d1f34d5
added table and db methods
nagarajm22 ded0f7e
fixed white space
nagarajm22 0bf59c0
added data_access with module
nagarajm22 b1d5d8e
update transactions data module
nagarajm22 8d9551a
updated oracle price
nagarajm22 271b65e
added crud opetration to oracle fixed the issue
nagarajm22 6c013af
added method for oracle,price,order_history
nagarajm22 69b09dc
added method for oracle,price,order_history
nagarajm22 6bd15ea
merged feature/ain-ocean
nagarajm22 7d6d53e
merged to feature/ain-ocean
nagarajm22 0df6dc3
update data_acess module
nagarajm22 f2d477b
added more functionality to module
nagarajm22 0e7efd8
fixed transaction module
nagarajm22 7aacc02
rebased ocean-archive
nagarajm22 a2e8868
rebased ocean-archive
nagarajm22 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -3,35 +3,30 @@ use std::{borrow::ToOwned, num::NonZeroUsize, sync::RwLock}; | |
| use ethereum::{BlockAny, TransactionV2}; | ||
| use ethereum_types::{H256, U256}; | ||
| use lru::LruCache; | ||
| use parking_lot::Mutex; | ||
|
|
||
| use super::traits::{BlockStorage, Rollback, TransactionStorage}; | ||
| use crate::Result; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct Cache { | ||
| transactions: Mutex<LruCache<H256, TransactionV2>>, | ||
|
Contributor
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. not sure will it cause backward-compatibility? |
||
| blocks: Mutex<LruCache<U256, BlockAny>>, | ||
| block_hashes: Mutex<LruCache<H256, U256>>, | ||
| transactions: RwLock<LruCache<H256, TransactionV2>>, | ||
| blocks: RwLock<LruCache<U256, BlockAny>>, | ||
| block_hashes: RwLock<LruCache<H256, U256>>, | ||
| latest_block: RwLock<Option<BlockAny>>, | ||
| contract_code: Mutex<LruCache<H256, Vec<u8>>>, | ||
|
Contributor
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. why is this removed?? |
||
| } | ||
|
|
||
| impl Cache { | ||
| const DEFAULT_CACHE_SIZE: usize = 1000; | ||
|
|
||
| pub fn new(cache_size: Option<usize>) -> Self { | ||
| Cache { | ||
| transactions: Mutex::new(LruCache::new( | ||
| transactions: RwLock::new(LruCache::new( | ||
| NonZeroUsize::new(cache_size.unwrap_or(Self::DEFAULT_CACHE_SIZE)).unwrap(), | ||
| )), | ||
| blocks: Mutex::new(LruCache::new( | ||
| blocks: RwLock::new(LruCache::new( | ||
| NonZeroUsize::new(cache_size.unwrap_or(Self::DEFAULT_CACHE_SIZE)).unwrap(), | ||
| )), | ||
| block_hashes: Mutex::new(LruCache::new( | ||
| NonZeroUsize::new(cache_size.unwrap_or(Self::DEFAULT_CACHE_SIZE)).unwrap(), | ||
| )), | ||
| contract_code: Mutex::new(LruCache::new( | ||
| block_hashes: RwLock::new(LruCache::new( | ||
| NonZeroUsize::new(cache_size.unwrap_or(Self::DEFAULT_CACHE_SIZE)).unwrap(), | ||
| )), | ||
| latest_block: RwLock::new(None), | ||
|
|
@@ -41,13 +36,19 @@ impl Cache { | |
|
|
||
| impl BlockStorage for Cache { | ||
| fn get_block_by_number(&self, number: &U256) -> Result<Option<BlockAny>> { | ||
| let block = self.blocks.lock().get(number).map(ToOwned::to_owned); | ||
| let block = self | ||
| .blocks | ||
| .write() | ||
| .unwrap() | ||
| .get(number) | ||
| .map(ToOwned::to_owned); | ||
| Ok(block) | ||
| } | ||
|
|
||
| fn get_block_by_hash(&self, block_hash: &H256) -> Result<Option<BlockAny>> { | ||
| self.block_hashes | ||
| .lock() | ||
| .write() | ||
| .unwrap() | ||
| .get(block_hash) | ||
| .map_or(Ok(None), |block_number| { | ||
| self.get_block_by_number(block_number) | ||
|
|
@@ -59,8 +60,11 @@ impl BlockStorage for Cache { | |
|
|
||
| let block_number = block.header.number; | ||
| let hash = block.header.hash(); | ||
| self.blocks.lock().put(block_number, block.clone()); | ||
| self.block_hashes.lock().put(hash, block_number); | ||
| self.blocks | ||
| .write() | ||
| .unwrap() | ||
| .put(block_number, block.clone()); | ||
| self.block_hashes.write().unwrap().put(hash, block_number); | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -83,7 +87,7 @@ impl BlockStorage for Cache { | |
|
|
||
| impl TransactionStorage for Cache { | ||
| fn extend_transactions_from_block(&self, block: &BlockAny) -> Result<()> { | ||
| let mut cache = self.transactions.lock(); | ||
| let mut cache = self.transactions.write().unwrap(); | ||
|
|
||
| for transaction in &block.transactions { | ||
| let hash = transaction.hash(); | ||
|
|
@@ -93,7 +97,12 @@ impl TransactionStorage for Cache { | |
| } | ||
|
|
||
| fn get_transaction_by_hash(&self, hash: &H256) -> Result<Option<TransactionV2>> { | ||
| let transaction = self.transactions.lock().get(hash).map(ToOwned::to_owned); | ||
| let transaction = self | ||
| .transactions | ||
| .write() | ||
| .unwrap() | ||
| .get(hash) | ||
| .map(ToOwned::to_owned); | ||
| Ok(transaction) | ||
| } | ||
|
|
||
|
|
@@ -103,7 +112,8 @@ impl TransactionStorage for Cache { | |
| index: usize, | ||
| ) -> Result<Option<TransactionV2>> { | ||
| self.block_hashes | ||
| .lock() | ||
| .write() | ||
| .unwrap() | ||
| .get(block_hash) | ||
| .map_or(Ok(None), |block_number| { | ||
| self.get_transaction_by_block_number_and_index(block_number, index) | ||
|
|
@@ -117,15 +127,17 @@ impl TransactionStorage for Cache { | |
| ) -> Result<Option<TransactionV2>> { | ||
| let transaction = self | ||
| .blocks | ||
| .lock() | ||
| .write() | ||
| .unwrap() | ||
| .get(block_number) | ||
| .and_then(|block| block.transactions.get(index).map(ToOwned::to_owned)); | ||
| Ok(transaction) | ||
| } | ||
|
|
||
| fn put_transaction(&self, transaction: &TransactionV2) -> Result<()> { | ||
| self.transactions | ||
| .lock() | ||
| .write() | ||
| .unwrap() | ||
| .put(transaction.hash(), transaction.clone()); | ||
| Ok(()) | ||
| } | ||
|
|
@@ -134,28 +146,17 @@ impl TransactionStorage for Cache { | |
| impl Rollback for Cache { | ||
| fn disconnect_latest_block(&self) -> Result<()> { | ||
| if let Some(block) = self.get_latest_block()? { | ||
| let mut transaction_cache = self.transactions.lock(); | ||
| let mut transaction_cache = self.transactions.write().unwrap(); | ||
| for tx in &block.transactions { | ||
| transaction_cache.pop(&tx.hash()); | ||
| } | ||
|
|
||
| self.block_hashes.lock().pop(&block.header.hash()); | ||
| self.blocks.lock().pop(&block.header.number); | ||
| self.block_hashes.write().unwrap().pop(&block.header.hash()); | ||
| self.blocks.write().unwrap().pop(&block.header.number); | ||
|
|
||
| let previous_block = self.get_block_by_hash(&block.header.parent_hash)?; | ||
| self.put_latest_block(previous_block.as_ref())?; | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl Cache { | ||
| pub fn get_code_by_hash(&self, hash: &H256) -> Result<Option<Vec<u8>>> { | ||
| Ok(self.contract_code.lock().get(hash).map(ToOwned::to_owned)) | ||
| } | ||
|
|
||
| pub fn put_code(&self, hash: H256, code: &[u8]) -> Result<()> { | ||
| self.contract_code.lock().put(hash, code.to_vec()); | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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.
hmm.. why remove this line?? we can do
#[allow(clippy::<lint>)]specifically...