11use graph:: {
22 anyhow:: Error ,
33 blockchain:: BlockchainKind ,
4- components:: network_provider:: { AmpChainNames , ChainName } ,
4+ components:: {
5+ network_provider:: { AmpChainNames , ChainName } ,
6+ store:: BLOCK_CACHE_SIZE ,
7+ } ,
58 env:: ENV_VARS ,
69 firehose:: { SubgraphLimit , SUBGRAPHS_PER_CONN } ,
710 itertools:: Itertools ,
@@ -462,8 +465,17 @@ impl ChainSection {
462465 fn validate ( & mut self ) -> Result < ( ) > {
463466 NodeId :: new ( & self . ingestor )
464467 . map_err ( |node| anyhow ! ( "invalid node id for ingestor {}" , node) ) ?;
465- for ( _, chain) in self . chains . iter_mut ( ) {
466- chain. validate ( ) ?
468+ let reorg_threshold = ENV_VARS . reorg_threshold ( ) ;
469+ for ( name, chain) in self . chains . iter_mut ( ) {
470+ chain. validate ( ) ?;
471+ if chain. cache_size <= reorg_threshold {
472+ return Err ( anyhow ! (
473+ "chain '{}': cache_size ({}) must be greater than reorg_threshold ({})" ,
474+ name,
475+ chain. cache_size,
476+ reorg_threshold
477+ ) ) ;
478+ }
467479 }
468480
469481 // Validate that effective AMP names are unique and don't collide
@@ -587,6 +599,7 @@ impl ChainSection {
587599 polling_interval : default_polling_interval ( ) ,
588600 providers : vec ! [ ] ,
589601 amp : None ,
602+ cache_size : default_cache_size ( ) ,
590603 } ) ;
591604 entry. providers . push ( provider) ;
592605 }
@@ -611,6 +624,15 @@ pub struct Chain {
611624 /// resolve to this chain. Defaults to the chain name.
612625 #[ serde( default ) ]
613626 pub amp : Option < String > ,
627+ /// Number of blocks from chain head for which to keep block data
628+ /// cached. When `GRAPH_STORE_IGNORE_BLOCK_CACHE` is set, blocks
629+ /// older than this are treated as if they have no data.
630+ #[ serde( default = "default_cache_size" ) ]
631+ pub cache_size : i32 ,
632+ }
633+
634+ fn default_cache_size ( ) -> i32 {
635+ BLOCK_CACHE_SIZE
614636}
615637
616638fn default_blockchain_kind ( ) -> BlockchainKind {
@@ -1297,7 +1319,7 @@ where
12971319#[ cfg( test) ]
12981320mod tests {
12991321
1300- use crate :: config:: { default_polling_interval, ChainSection , Web3Rule } ;
1322+ use crate :: config:: { default_cache_size , default_polling_interval, ChainSection , Web3Rule } ;
13011323
13021324 use super :: {
13031325 Chain , Config , FirehoseProvider , Provider , ProviderDetails , Shard , Transport , Web3Provider ,
@@ -1345,6 +1367,7 @@ mod tests {
13451367 polling_interval: default_polling_interval( ) ,
13461368 providers: vec![ ] ,
13471369 amp: None ,
1370+ cache_size: default_cache_size( ) ,
13481371 } ,
13491372 actual
13501373 ) ;
@@ -1368,6 +1391,7 @@ mod tests {
13681391 polling_interval: default_polling_interval( ) ,
13691392 providers: vec![ ] ,
13701393 amp: None ,
1394+ cache_size: default_cache_size( ) ,
13711395 } ,
13721396 actual
13731397 ) ;
0 commit comments