@@ -462,8 +462,17 @@ impl ChainSection {
462462 fn validate ( & mut self ) -> Result < ( ) > {
463463 NodeId :: new ( & self . ingestor )
464464 . map_err ( |node| anyhow ! ( "invalid node id for ingestor {}" , node) ) ?;
465- for ( _, chain) in self . chains . iter_mut ( ) {
466- chain. validate ( ) ?
465+ let reorg_threshold = ENV_VARS . reorg_threshold ( ) ;
466+ for ( name, chain) in self . chains . iter_mut ( ) {
467+ chain. validate ( ) ?;
468+ if chain. cache_size <= reorg_threshold {
469+ return Err ( anyhow ! (
470+ "chain '{}': cache_size ({}) must be greater than reorg_threshold ({})" ,
471+ name,
472+ chain. cache_size,
473+ reorg_threshold
474+ ) ) ;
475+ }
467476 }
468477
469478 // Validate that effective AMP names are unique and don't collide
@@ -587,6 +596,7 @@ impl ChainSection {
587596 polling_interval : default_polling_interval ( ) ,
588597 providers : vec ! [ ] ,
589598 amp : None ,
599+ cache_size : default_cache_size ( ) ,
590600 } ) ;
591601 entry. providers . push ( provider) ;
592602 }
@@ -611,6 +621,15 @@ pub struct Chain {
611621 /// resolve to this chain. Defaults to the chain name.
612622 #[ serde( default ) ]
613623 pub amp : Option < String > ,
624+ /// Number of blocks from chain head for which to keep block data
625+ /// cached. When `GRAPH_STORE_IGNORE_BLOCK_CACHE` is set, blocks
626+ /// older than this are treated as if they have no data.
627+ #[ serde( default = "default_cache_size" ) ]
628+ pub cache_size : i32 ,
629+ }
630+
631+ fn default_cache_size ( ) -> i32 {
632+ 500
614633}
615634
616635fn default_blockchain_kind ( ) -> BlockchainKind {
@@ -1297,7 +1316,7 @@ where
12971316#[ cfg( test) ]
12981317mod tests {
12991318
1300- use crate :: config:: { default_polling_interval, ChainSection , Web3Rule } ;
1319+ use crate :: config:: { default_cache_size , default_polling_interval, ChainSection , Web3Rule } ;
13011320
13021321 use super :: {
13031322 Chain , Config , FirehoseProvider , Provider , ProviderDetails , Shard , Transport , Web3Provider ,
@@ -1345,6 +1364,7 @@ mod tests {
13451364 polling_interval: default_polling_interval( ) ,
13461365 providers: vec![ ] ,
13471366 amp: None ,
1367+ cache_size: default_cache_size( ) ,
13481368 } ,
13491369 actual
13501370 ) ;
@@ -1368,6 +1388,7 @@ mod tests {
13681388 polling_interval: default_polling_interval( ) ,
13691389 providers: vec![ ] ,
13701390 amp: None ,
1391+ cache_size: default_cache_size( ) ,
13711392 } ,
13721393 actual
13731394 ) ;
0 commit comments