@@ -4,6 +4,7 @@ use futures::executor::block_on;
44use near_primitives:: epoch_manager:: { AllEpochConfig , EpochConfig } ;
55
66use crate :: modules:: blocks:: { BlocksInfoByFinality , CacheBlock } ;
7+ use crate :: utils;
78
89static NEARD_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
910static NEARD_BUILD : & str = env ! ( "BUILD_VERSION" ) ;
@@ -20,8 +21,7 @@ pub struct GenesisInfo {
2021impl GenesisInfo {
2122 pub async fn get (
2223 near_rpc_client : & crate :: utils:: JsonRpcClient ,
23- s3_client : & near_lake_framework:: LakeS3Client ,
24- s3_bucket_name : & str ,
24+ fastnear_client : & near_lake_framework:: FastNearClient ,
2525 ) -> Self {
2626 tracing:: info!( "Get genesis config..." ) ;
2727 let genesis_config = near_rpc_client
@@ -32,25 +32,20 @@ impl GenesisInfo {
3232 . await
3333 . expect ( "Error to get genesis config" ) ;
3434
35- let genesis_block = near_lake_framework:: s3:: fetchers:: fetch_block (
36- s3_client,
37- s3_bucket_name,
38- genesis_config. genesis_height ,
39- )
40- . await
41- . expect ( "Error to get genesis block" ) ;
35+ let genesis_block =
36+ near_lake_framework:: fastnear:: fetchers:: fetch_first_block ( fastnear_client) . await ;
4237
4338 Self {
4439 genesis_config,
45- genesis_block_cache : CacheBlock :: from ( & genesis_block) ,
40+ genesis_block_cache : CacheBlock :: from ( & genesis_block. block ) ,
4641 }
4742 }
4843}
4944
5045#[ derive( Clone ) ]
5146pub struct ServerContext {
52- /// Lake s3 client
53- pub s3_client : near_lake_framework:: LakeS3Client ,
47+ /// Fastnear client
48+ pub fastnear_client : near_lake_framework:: FastNearClient ,
5449 /// Database manager
5550 pub db_manager : std:: sync:: Arc < Box < dyn database:: ReaderDbManager + Sync + Send + ' static > > ,
5651 /// TransactionDetails storage
@@ -61,8 +56,6 @@ pub struct ServerContext {
6156 pub genesis_info : GenesisInfo ,
6257 /// Near rpc client
6358 pub near_rpc_client : crate :: utils:: JsonRpcClient ,
64- /// AWS s3 lake bucket name
65- pub s3_bucket_name : String ,
6659 /// Blocks cache
6760 pub blocks_cache : std:: sync:: Arc < crate :: cache:: RwLockLruMemoryCache < u64 , CacheBlock > > ,
6861 /// Final block info include final_block_cache and current_validators_info
@@ -89,27 +82,36 @@ pub struct ServerContext {
8982}
9083
9184impl ServerContext {
92- pub async fn init (
93- rpc_server_config : configuration:: RpcServerConfig ,
94- near_rpc_client : crate :: utils:: JsonRpcClient ,
95- ) -> anyhow:: Result < Self > {
85+ pub async fn init ( rpc_server_config : configuration:: RpcServerConfig ) -> anyhow:: Result < Self > {
9686 let contract_code_cache_size_in_bytes =
97- crate :: utils:: gigabytes_to_bytes ( rpc_server_config. general . contract_code_cache_size )
98- . await ;
87+ utils:: gigabytes_to_bytes ( rpc_server_config. general . contract_code_cache_size ) . await ;
9988 let contract_code_cache = std:: sync:: Arc :: new ( crate :: cache:: RwLockLruMemoryCache :: new (
10089 contract_code_cache_size_in_bytes,
10190 ) ) ;
10291
10392 let block_cache_size_in_bytes =
104- crate :: utils:: gigabytes_to_bytes ( rpc_server_config. general . block_cache_size ) . await ;
93+ utils:: gigabytes_to_bytes ( rpc_server_config. general . block_cache_size ) . await ;
10594 let blocks_cache = std:: sync:: Arc :: new ( crate :: cache:: RwLockLruMemoryCache :: new (
10695 block_cache_size_in_bytes,
10796 ) ) ;
108-
109- let blocks_info_by_finality =
110- std:: sync:: Arc :: new ( BlocksInfoByFinality :: new ( & near_rpc_client, & blocks_cache) . await ) ;
111-
112- let s3_client = rpc_server_config. lake_config . lake_s3_client ( ) . await ;
97+ let near_rpc_client = utils:: JsonRpcClient :: new (
98+ rpc_server_config. general . near_rpc_url . clone ( ) ,
99+ rpc_server_config. general . near_archival_rpc_url . clone ( ) ,
100+ ) ;
101+ // We want to set a custom referer to let NEAR JSON RPC nodes know that we are a read-rpc instance
102+ let near_rpc_client = near_rpc_client. header (
103+ "Referer" . to_string ( ) ,
104+ rpc_server_config. general . referer_header_value . clone ( ) ,
105+ ) ?;
106+
107+ let fastnear_client = rpc_server_config
108+ . lake_config
109+ . lake_client ( rpc_server_config. general . chain_id )
110+ . await ?;
111+
112+ let blocks_info_by_finality = std:: sync:: Arc :: new (
113+ BlocksInfoByFinality :: new ( & near_rpc_client, & fastnear_client) . await ,
114+ ) ;
113115
114116 let tx_details_storage = tx_details_storage:: TxDetailsStorage :: new (
115117 rpc_server_config. tx_details_storage . storage_client ( ) . await ,
@@ -124,12 +126,7 @@ impl ServerContext {
124126 } )
125127 . ok ( ) ;
126128
127- let genesis_info = GenesisInfo :: get (
128- & near_rpc_client,
129- & s3_client,
130- & rpc_server_config. lake_config . aws_bucket_name ,
131- )
132- . await ;
129+ let genesis_info = GenesisInfo :: get ( & near_rpc_client, & fastnear_client) . await ;
133130
134131 let default_epoch_config = EpochConfig :: from ( & genesis_info. genesis_config ) ;
135132 let all_epoch_config = AllEpochConfig :: new (
@@ -159,13 +156,12 @@ impl ServerContext {
159156 . inc ( ) ;
160157
161158 Ok ( Self {
162- s3_client ,
159+ fastnear_client ,
163160 db_manager : std:: sync:: Arc :: new ( Box :: new ( db_manager) ) ,
164161 tx_details_storage : std:: sync:: Arc :: new ( tx_details_storage) ,
165162 tx_cache_storage,
166163 genesis_info,
167164 near_rpc_client,
168- s3_bucket_name : rpc_server_config. lake_config . aws_bucket_name . clone ( ) ,
169165 blocks_cache,
170166 blocks_info_by_finality,
171167 compiled_contract_code_cache,
0 commit comments