- 
                Notifications
    
You must be signed in to change notification settings  - Fork 149
 
Add hook to force committing state to disk #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: snap_sync
Are you sure you want to change the base?
Changes from 13 commits
0722c8a
              f9f2a95
              d210557
              e47297e
              1ac9c79
              de45e56
              690ef23
              de611b4
              1180b65
              1c37534
              706b28e
              2f5bc99
              bfc07a2
              dcb5999
              077881d
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -245,8 +245,11 @@ type BlockChain struct { | |
| 
     | 
||
| numberOfBlocksToSkipStateSaving uint32 | ||
| amountOfGasInBlocksToSkipStateSaving uint64 | ||
| forceTriedbCommitHook ForceTriedbCommitHook | ||
| } | ||
| 
     | 
||
| type ForceTriedbCommitHook func(*types.Block) bool | ||
| 
     | 
||
| type trieGcEntry struct { | ||
| Root common.Hash | ||
| Timestamp uint64 | ||
| 
        
          
        
         | 
    @@ -255,7 +258,7 @@ type trieGcEntry struct { | |
| // NewBlockChain returns a fully initialised block chain using information | ||
| // available in the database. It initialises the default Ethereum Validator | ||
| // and Processor. | ||
| func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64) (*BlockChain, error) { | ||
| func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64, forceTriedbCommitHook ForceTriedbCommitHook) (*BlockChain, error) { | ||
| if cacheConfig == nil { | ||
| cacheConfig = defaultCacheConfig | ||
| } | ||
| 
          
            
          
           | 
    @@ -469,6 +472,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par | |
| bc.wg.Add(1) | ||
| go bc.maintainTxIndex() | ||
| } | ||
| bc.forceTriedbCommitHook = forceTriedbCommitHook | ||
| return bc, nil | ||
| } | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -1430,6 +1434,12 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. | |
| if err != nil { | ||
| return err | ||
| } | ||
| 
     | 
||
| if bc.forceTriedbCommitHook != nil && bc.forceTriedbCommitHook(block) { | ||
| bc.numberOfBlocksToSkipStateSaving = bc.cacheConfig.MaxNumberOfBlocksToSkipStateSaving | ||
| bc.amountOfGasInBlocksToSkipStateSaving = bc.cacheConfig.MaxAmountOfGasToSkipStateSaving | ||
| return bc.triedb.Commit(root, false) | ||
| } | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want the storing-from-force to happen together with storing here: So the hook should check gcproc, and if it returns yes gcproc should also be updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure it's the best solution, but my current thought is that if the hook is null we use a function that replicates the current behavior for hook (tests bc.gcproc > flushInterval)  | 
||
| // If we're running an archive node, flush | ||
| // If MaxNumberOfBlocksToSkipStateSaving or MaxAmountOfGasToSkipStateSaving is not zero, then flushing of some blocks will be skipped: | ||
| // * at most MaxNumberOfBlocksToSkipStateSaving block state commits will be skipped | ||
| 
          
            
          
           | 
    ||
Uh oh!
There was an error while loading. Please reload this page.