@@ -54,9 +54,8 @@ pub mod primary {
5454 use std:: convert:: TryFrom ;
5555
5656 use diesel:: {
57- delete, insert_into,
58- r2d2:: { ConnectionManager , PooledConnection } ,
59- update, ExpressionMethods , OptionalExtension , PgConnection , QueryDsl , RunQueryDsl ,
57+ delete, insert_into, update, ExpressionMethods , OptionalExtension , PgConnection , QueryDsl ,
58+ RunQueryDsl ,
6059 } ;
6160 use graph:: {
6261 blockchain:: { BlockHash , ChainIdentifier } ,
@@ -109,18 +108,21 @@ pub mod primary {
109108 }
110109 }
111110
112- pub fn load_chains ( conn : & mut PgConnection ) -> Result < Vec < Chain > , StoreError > {
111+ pub async fn load_chains ( conn : & mut PgConnection ) -> Result < Vec < Chain > , StoreError > {
113112 Ok ( chains:: table. load ( conn) ?)
114113 }
115114
116- pub fn find_chain ( conn : & mut PgConnection , name : & str ) -> Result < Option < Chain > , StoreError > {
115+ pub async fn find_chain (
116+ conn : & mut PgConnection ,
117+ name : & str ,
118+ ) -> Result < Option < Chain > , StoreError > {
117119 Ok ( chains:: table
118120 . filter ( chains:: name. eq ( name) )
119121 . first ( conn)
120122 . optional ( ) ?)
121123 }
122124
123- pub fn add_chain (
125+ pub async fn add_chain (
124126 conn : & mut PgConnection ,
125127 name : & str ,
126128 shard : & Shard ,
@@ -165,7 +167,7 @@ pub mod primary {
165167 }
166168
167169 // update chain name where chain name is 'name'
168- pub fn update_chain_name (
170+ pub async fn update_chain_name (
169171 conn : & mut PgConnection ,
170172 name : & str ,
171173 new_name : & str ,
@@ -175,17 +177,6 @@ pub mod primary {
175177 . execute ( conn) ?;
176178 Ok ( ( ) )
177179 }
178-
179- pub fn update_chain_genesis_hash (
180- conn : & mut PooledConnection < ConnectionManager < PgConnection > > ,
181- name : & str ,
182- hash : BlockHash ,
183- ) -> Result < ( ) , StoreError > {
184- update ( chains:: table. filter ( chains:: name. eq ( name) ) )
185- . set ( chains:: genesis_block_hash. eq ( hash. hash_hex ( ) ) )
186- . execute ( conn) ?;
187- Ok ( ( ) )
188- }
189180}
190181
191182/// The store that chains use to maintain their state and cache often used
@@ -265,7 +256,7 @@ impl BlockStore {
265256
266257 let mirror = PrimaryMirror :: new ( & pools) ;
267258 let existing_chains = mirror
268- . read_async ( |conn| async { primary:: load_chains ( conn) } . scope_boxed ( ) )
259+ . read_async ( |conn| primary:: load_chains ( conn) . scope_boxed ( ) )
269260 . await ?;
270261 let chain_head_cache = TimedCache :: new ( CHAIN_HEAD_CACHE_TTL ) ;
271262 let chains = shards. clone ( ) ;
@@ -345,7 +336,7 @@ impl BlockStore {
345336 self . mirror . primary ( ) . query_permit ( ) . await
346337 }
347338
348- pub fn allocate_chain (
339+ pub async fn allocate_chain (
349340 conn : & mut PgConnection ,
350341 name : & String ,
351342 shard : & Shard ,
@@ -463,7 +454,7 @@ impl BlockStore {
463454 self . mirror
464455 . read_async ( |conn| {
465456 async {
466- match primary:: find_chain ( conn, & chain) ? {
457+ match primary:: find_chain ( conn, & chain) . await ? {
467458 Some ( chain) => {
468459 let chain_store = this
469460 . add_chain_store ( & chain, ChainStatus :: ReadOnly , false )
@@ -617,7 +608,7 @@ impl BlockStore {
617608 }
618609 } )
619610 . ok_or_else ( || anyhow ! ( "unable to find shard for network {}" , network) ) ?;
620- let chain = primary:: add_chain ( & mut conn, & network, & shard, ident) ?;
611+ let chain = primary:: add_chain ( & mut conn, & network, & shard, ident) . await ?;
621612 self . add_chain_store ( & chain, ChainStatus :: Ingestible , true )
622613 . await
623614 . map_err ( anyhow:: Error :: from)
0 commit comments