Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b057f66
added ain-ocean
nagarajm22 Nov 22, 2023
f3c7679
added rpc server
nagarajm22 Nov 22, 2023
31d7ddd
added rpc server
nagarajm22 Nov 22, 2023
81f084c
fixed tokio crate
nagarajm22 Nov 22, 2023
2b50e51
added server
nagarajm22 Nov 22, 2023
0c130b7
added server
nagarajm22 Nov 22, 2023
bffd6f9
added rpc server and block modules
nagarajm22 Nov 26, 2023
6ff36de
added default value to config
nagarajm22 Nov 26, 2023
7b078c0
added default value to config
nagarajm22 Nov 26, 2023
6a5cf8f
added default value to config
nagarajm22 Nov 26, 2023
65cfb56
added default value to config and server stop
nagarajm22 Nov 26, 2023
4fc80fd
added rocks db with multiple table and column strucutre
nagarajm22 Nov 27, 2023
335e583
added rocks db with multiple table and column strucutre
nagarajm22 Nov 27, 2023
b71040a
added rocks db test cases
nagarajm22 Nov 27, 2023
2a853fc
added rocks db test cases
nagarajm22 Nov 27, 2023
68d912f
fixed rocks db test cases
nagarajm22 Nov 27, 2023
aa30821
added readme for ocean api
nagarajm22 Nov 27, 2023
9141d57
Ocean endpoints scaffold
Jouzo Nov 23, 2023
1c28652
Start ocean server
Jouzo Nov 27, 2023
af87e90
added rocks database
nagarajm22 Nov 28, 2023
43914e8
added table and db methods
nagarajm22 Nov 28, 2023
f82ea41
added table and db methods
nagarajm22 Nov 28, 2023
d1f34d5
added table and db methods
nagarajm22 Nov 28, 2023
ded0f7e
fixed white space
nagarajm22 Nov 28, 2023
0bf59c0
added data_access with module
nagarajm22 Nov 28, 2023
b1d5d8e
update transactions data module
nagarajm22 Nov 29, 2023
8d9551a
updated oracle price
nagarajm22 Nov 30, 2023
271b65e
added crud opetration to oracle fixed the issue
nagarajm22 Dec 1, 2023
6c013af
added method for oracle,price,order_history
nagarajm22 Dec 4, 2023
69b09dc
added method for oracle,price,order_history
nagarajm22 Dec 4, 2023
6bd15ea
merged feature/ain-ocean
nagarajm22 Dec 5, 2023
7d6d53e
merged to feature/ain-ocean
nagarajm22 Dec 5, 2023
0df6dc3
update data_acess module
nagarajm22 Dec 5, 2023
f2d477b
added more functionality to module
nagarajm22 Dec 6, 2023
0e7efd8
fixed transaction module
nagarajm22 Dec 8, 2023
7aacc02
rebased ocean-archive
nagarajm22 Dec 8, 2023
a2e8868
rebased ocean-archive
nagarajm22 Dec 8, 2023
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
331 changes: 324 additions & 7 deletions lib/Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ jsonrpsee-server = "0.16"
jsonrpsee-types = "0.16"

axum = { version = "0.7.1", features = ["macros"] }

tempdir = "0.3"

rocksdb = { version = "0.21", default-features = false }
Expand Down
4 changes: 0 additions & 4 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ check:
test:
$(CARGO) test $(CARGO_MANIFEST_ARG) $(CARGO_EXTRA_ARGS)

.PHONY: clippy
clippy:
$(CARGO) clippy $(CARGO_MANIFEST_ARG) $(CARGO_EXTRA_ARGS) -- -Dwarnings

Copy link
Copy Markdown
Contributor

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...


.PHONY: doc
doc:
$(CARGO) doc $(CARGO_MANIFEST_ARG)
Expand Down
69 changes: 35 additions & 34 deletions lib/ain-evm/src/storage/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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>>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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),
Expand All @@ -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)
Expand All @@ -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(())
}

Expand All @@ -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();
Expand All @@ -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)
}

Expand All @@ -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)
Expand All @@ -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(())
}
Expand All @@ -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(())
}
}
12 changes: 1 addition & 11 deletions lib/ain-evm/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,7 @@ impl FlushableStorage for Storage {

impl Storage {
pub fn get_code_by_hash(&self, address: H160, hash: H256) -> Result<Option<Vec<u8>>> {
match self.cache.get_code_by_hash(&hash) {
Ok(Some(code)) => Ok(Some(code)),
Ok(None) => {
let code = self.blockstore.get_code_by_hash(address, &hash);
if let Ok(Some(ref code)) = code {
self.cache.put_code(hash, code)?;
}
code
}
Err(e) => Err(e),
}
self.blockstore.get_code_by_hash(address, &hash)
}

pub fn put_code(
Expand Down
14 changes: 14 additions & 0 deletions lib/ain-ocean/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,17 @@ thiserror.workspace = true
hex.workspace = true
dftx-rs.workspace = true
bitcoin.workspace = true
tarpc = { version = "0.33", features = ["tokio1", "serde1", "serde-transport","tcp"] }
tokio = { version = "1", features = ["full"] }
serde_json = "1.0"
json = "0.12.4"
tokio-serde = {version="0.8.0"}
futures = "0.3.29"
jsonrpsee = { version = "0.20.3", features = ["server", "macros", "http-client", "jsonrpsee-server"] }
rocksdb = "0.21.0"
ctrlc = "3.1.9"
tempdir = "0.3.7"
bitcoin_hashes = "0.12.0"
structopt = { version = "0.3", default-features = false }
tempfile = "3.8.1"
anyhow.workspace = true
Empty file added lib/ain-ocean/README.md
Empty file.
31 changes: 16 additions & 15 deletions lib/ain-ocean/src/api/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use axum::{debug_handler, extract::{Path, Query}, Json, routing::get, Router};
use axum::{
debug_handler,
extract::{Path, Query},
routing::get,
Json, Router,
};
use serde::{Deserialize, Serialize};

use crate::api_paged_response::ApiPagedResponse;
Expand All @@ -16,7 +21,7 @@ struct BlockHash {
#[derive(Deserialize)]
pub struct ListBlocksQuery {
pub size: usize,
pub next: Option<String>
pub next: Option<String>,
}

#[debug_handler]
Expand All @@ -28,14 +33,10 @@ async fn list_blocks(Query(query): Query<ListBlocksQuery>) -> Json<ApiPagedRespo
Block { id: "1".into() },
Block { id: "2".into() },
];

Json(ApiPagedResponse
::of(
blocks,
query.size,
|block| block.clone().id
)
)

Json(ApiPagedResponse::of(blocks, query.size, |block| {
block.clone().id
}))
}

async fn get_block(Path(BlockId { id }): Path<BlockId>) -> String {
Expand All @@ -60,24 +61,24 @@ pub struct Block {
// TODO(): type mapping
// hash: H256,
// previous_hash: H256,

// height: u64,
// version: u64,
// time: u64, // ---------------| block time in seconds since epoch
// median_time: u64, // --------| meidan time of the past 11 block timestamps

// transaction_count: u64,

// difficulty: u64,

// masternode: H256,
// minter: H256,
// minter_block_count: u64,
// reward: f64

// state_modifier: H256,
// merkle_root: H256,

// size: u64,
// size_stripped: u64,
// weight: u64,
Expand Down
Loading