-
Notifications
You must be signed in to change notification settings - Fork 1
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
Rewind fix #6
Rewind fix #6
Changes from 10 commits
7a987d9
4337df2
9647ed5
7ab7aef
e6470d0
5f07d0f
69d844a
185355d
f69c24a
7db6543
6cca4df
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 | ||||
---|---|---|---|---|---|---|
|
@@ -137,18 +137,22 @@ type CacheConfig struct { | |||||
SnapshotLimit int // Memory allowance (MB) to use for caching snapshot entries in memory | ||||||
Preimages bool // Whether to store preimage of trie key to the disk | ||||||
|
||||||
SnapshotNoBuild bool // Whether the background generation is allowed | ||||||
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it | ||||||
AllowForceUpdate bool // Enable to force snapshots based on commit counts | ||||||
CommitThreshold int // Number of commits to force a root snapshot | ||||||
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.
Suggested change
|
||||||
SnapshotNoBuild bool // Whether the background generation is allowed | ||||||
SnapshotWait bool // Wait for snapshot construction on startup. TODO(karalabe): This is a dirty hack for testing, nuke it | ||||||
} | ||||||
|
||||||
// defaultCacheConfig are the default caching values if none are specified by the | ||||||
// user (also used during testing). | ||||||
var defaultCacheConfig = &CacheConfig{ | ||||||
TrieCleanLimit: 256, | ||||||
TrieDirtyLimit: 256, | ||||||
TrieTimeLimit: 5 * time.Minute, | ||||||
SnapshotLimit: 256, | ||||||
SnapshotWait: true, | ||||||
TrieCleanLimit: 256, | ||||||
TrieDirtyLimit: 256, | ||||||
TrieTimeLimit: 5 * time.Minute, | ||||||
SnapshotLimit: 256, | ||||||
SnapshotWait: true, | ||||||
AllowForceUpdate: false, | ||||||
CommitThreshold: 128, | ||||||
} | ||||||
|
||||||
// BlockChain represents the canonical chain given a database with a genesis | ||||||
|
@@ -397,10 +401,12 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis | |||||
recover = true | ||||||
} | ||||||
snapconfig := snapshot.Config{ | ||||||
CacheSize: bc.cacheConfig.SnapshotLimit, | ||||||
Recovery: recover, | ||||||
NoBuild: bc.cacheConfig.SnapshotNoBuild, | ||||||
AsyncBuild: !bc.cacheConfig.SnapshotWait, | ||||||
CacheSize: bc.cacheConfig.SnapshotLimit, | ||||||
Recovery: recover, | ||||||
NoBuild: bc.cacheConfig.SnapshotNoBuild, | ||||||
AsyncBuild: !bc.cacheConfig.SnapshotWait, | ||||||
AllowForceUpdate: bc.cacheConfig.AllowForceUpdate, | ||||||
CommitThreshold: bc.cacheConfig.CommitThreshold, | ||||||
} | ||||||
bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root) | ||||||
} | ||||||
|
@@ -623,7 +629,6 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha | |||||
// current freezer limit to start nuking id underflown | ||||||
pivot := rawdb.ReadLastPivotNumber(bc.db) | ||||||
frozen, _ := bc.db.Ancients() | ||||||
|
||||||
updateFn := func(db ethdb.KeyValueWriter, header *types.Header) (*types.Header, bool) { | ||||||
// Rewind the blockchain, ensuring we don't end up with a stateless head | ||||||
// block. Note, depth equality is permitted to allow using SetHead as a | ||||||
|
@@ -1358,6 +1363,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. | |||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
log.Debug("Committed State", "root", root) | ||||||
// If we're running an archive node, always flush | ||||||
if bc.cacheConfig.TrieDirtyDisabled { | ||||||
return bc.triedb.Commit(root, false) | ||||||
|
@@ -1368,6 +1374,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. | |||||
|
||||||
current := block.NumberU64() | ||||||
// Flush limits are not considered for the first TriesInMemory blocks. | ||||||
log.Debug("Trie in memory", "current", current, "inMemory", TriesInMemory) | ||||||
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. would this be a large struct to print? if so maybe change to Trace level |
||||||
if current <= TriesInMemory { | ||||||
return nil | ||||||
} | ||||||
|
@@ -1376,12 +1383,14 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. | |||||
nodes, imgs = bc.triedb.Size() | ||||||
limit = common.StorageSize(bc.cacheConfig.TrieDirtyLimit) * 1024 * 1024 | ||||||
) | ||||||
|
||||||
if nodes > limit || imgs > 4*1024*1024 { | ||||||
bc.triedb.Cap(limit - ethdb.IdealBatchSize) | ||||||
} | ||||||
// Find the next state trie we need to commit | ||||||
chosen := current - TriesInMemory | ||||||
flushInterval := time.Duration(bc.flushInterval.Load()) | ||||||
log.Debug("Flush Interval", "proc", bc.gcproc, "interval", flushInterval, "block", chosen, "flushing", (bc.gcproc > flushInterval)) | ||||||
// If we exceeded time allowance, flush an entire trie to disk | ||||||
if bc.gcproc > flushInterval { | ||||||
// If the header is missing (canonical chain behind), we're reorging a low | ||||||
|
@@ -1401,6 +1410,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. | |||||
bc.gcproc = 0 | ||||||
} | ||||||
} | ||||||
|
||||||
// Garbage collect anything below our required write retention | ||||||
for !bc.triegc.Empty() { | ||||||
root, number := bc.triegc.Pop() | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -75,6 +75,9 @@ var ( | |||||
bloomDestructHasherOffset = 0 | ||||||
bloomAccountHasherOffset = 0 | ||||||
bloomStorageHasherOffset = 0 | ||||||
|
||||||
// Count for number of commits before fore disk root update | ||||||
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.
Suggested change
|
||||||
defaultCommitThreshold = 128 | ||||||
) | ||||||
|
||||||
func init() { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.