Skip to content
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

State expiry mvp0.1: testnet bugs fixed; #124

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
Flags: flags.Merge([]cli.Flag{
utils.CachePreimagesFlag,
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.DatabasePathFlags),
Description: `
The init command initializes a new genesis block and definition for the network.
Expand Down Expand Up @@ -86,7 +87,8 @@ It expects the genesis file as argument.`,
Name: "dumpgenesis",
Usage: "Dumps genesis block JSON configuration to stdout",
ArgsUsage: "",
Flags: append([]cli.Flag{utils.DataDirFlag}, utils.NetworkFlags...),
Flags: append([]cli.Flag{utils.DataDirFlag,
utils.StateExpiryEnableFlag}, utils.NetworkFlags...),
Description: `
The dumpgenesis command prints the genesis configuration of the network preset
if one is set. Otherwise it prints the genesis from the datadir.`,
Expand Down Expand Up @@ -121,6 +123,7 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
utils.TransactionHistoryFlag,
utils.StateSchemeFlag,
utils.StateHistoryFlag,
utils.StateExpiryEnableFlag,
}, utils.DatabasePathFlags),
Description: `
The import command imports blocks from an RLP-encoded form. The form can be one file
Expand All @@ -138,6 +141,7 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
utils.CacheFlag,
utils.SyncModeFlag,
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.DatabasePathFlags),
Description: `
Requires a first argument of the file to write to.
Expand All @@ -154,6 +158,7 @@ be gzipped.`,
Flags: flags.Merge([]cli.Flag{
utils.CacheFlag,
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.DatabasePathFlags),
Description: `
The import-preimages command imports hash preimages from an RLP encoded stream.
Expand All @@ -168,6 +173,7 @@ It's deprecated, please use "geth db import" instead.
Flags: flags.Merge([]cli.Flag{
utils.CacheFlag,
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.DatabasePathFlags),
Description: `
The export-preimages command exports hash preimages to an RLP encoded stream.
Expand All @@ -188,6 +194,7 @@ It's deprecated, please use "geth db export" instead.
utils.StartKeyFlag,
utils.DumpLimitFlag,
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.DatabasePathFlags),
Description: `
This command dumps out the state for a given block (or latest, if none provided).
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
Name: "dumpconfig",
Usage: "Export configuration values in a TOML format",
ArgsUsage: "<dumpfile (optional)>",
Flags: flags.Merge(nodeFlags, rpcFlags),
Flags: flags.Merge(nodeFlags, rpcFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Description: `Export configuration values in TOML format (to stdout by default).`,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/consolecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
Action: localConsole,
Name: "console",
Usage: "Start an interactive JavaScript environment",
Flags: flags.Merge(nodeFlags, rpcFlags, consoleFlags),
Flags: flags.Merge(nodeFlags, rpcFlags, consoleFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Description: `
The Geth console is an interactive shell for the JavaScript runtime environment
which exposes a node admin interface as well as the Ðapp JavaScript API.
Expand Down
17 changes: 15 additions & 2 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
Name: "removedb",
Usage: "Remove blockchain and state databases",
ArgsUsage: "",
Flags: utils.DatabasePathFlags,
Flags: flags.Merge(utils.DatabasePathFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Description: `
Remove blockchain and state databases`,
}
Expand Down Expand Up @@ -83,6 +83,7 @@ Remove blockchain and state databases`,
ArgsUsage: "<prefix> <start>",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Usage: "Inspect the storage size for each type of data in the database",
Description: `This commands iterates the entire database. If the optional 'prefix' and 'start' arguments are provided, then the iteration is limited to the given subset of data.`,
Expand All @@ -93,6 +94,7 @@ Remove blockchain and state databases`,
ArgsUsage: "<blocknum> <jobnum>",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.DatabasePathFlags),
Usage: "Inspect the MPT tree of the account and contract.",
Description: `This commands iterates the entrie WorldState.`,
Expand All @@ -101,7 +103,7 @@ Remove blockchain and state databases`,
Action: checkStateContent,
Name: "check-state-content",
ArgsUsage: "<start (optional)>",
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Usage: "Verify that state data is cryptographically correct",
Description: `This command iterates the entire database for 32-byte keys, looking for rlp-encoded trie nodes.
For each trie node encountered, it checks that the key corresponds to the keccak256(value). If this is not true, this indicates
Expand All @@ -113,6 +115,7 @@ a data corruption.`,
Usage: "Print leveldb statistics",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
}
dbCompactCmd = &cli.Command{
Expand All @@ -123,6 +126,7 @@ a data corruption.`,
utils.SyncModeFlag,
utils.CacheFlag,
utils.CacheDatabaseFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: `This command performs a database compaction.
WARNING: This operation may take a very long time to finish, and may cause database
Expand All @@ -135,6 +139,7 @@ corruption if it is aborted during execution'!`,
ArgsUsage: "<hex-encoded key>",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: "This command looks up the specified database key from the database.",
}
Expand All @@ -145,6 +150,7 @@ corruption if it is aborted during execution'!`,
ArgsUsage: "<hex-encoded key>",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: `This command deletes the specified database key from the database.
WARNING: This is a low-level operation which may cause database corruption!`,
Expand All @@ -156,6 +162,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<hex-encoded key> <hex-encoded value>",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: `This command sets a given database key to the given value.
WARNING: This is a low-level operation which may cause database corruption!`,
Expand All @@ -168,6 +175,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: "This command looks up the specified database key from the database.",
}
Expand All @@ -178,6 +186,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<freezer-type> <table-type> <start (int)> <end (int)>",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: "This command displays information about the freezer index.",
}
Expand All @@ -188,6 +197,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<dumpfile> <start (optional)",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: "The import command imports the specific chain data from an RLP encoded stream.",
}
Expand All @@ -198,6 +208,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
ArgsUsage: "<type> <dumpfile>",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: "Exports the specified chain data to an RLP encoded stream, optionally gzip-compressed.",
}
Expand All @@ -207,6 +218,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Usage: "Shows metadata about the chain status.",
Flags: flags.Merge([]cli.Flag{
utils.SyncModeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: "Shows metadata about the chain status.",
}
Expand All @@ -215,6 +227,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Name: "inspect-reserved-oldest-blocks",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.StateExpiryEnableFlag,
},
Usage: "Inspect the ancientStore information",
Description: `This commands will read current offset from kvdb, which is the current offset and starting BlockNumber
Expand Down
10 changes: 8 additions & 2 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ WARNING: it's only supported in hash mode(--state.scheme=hash)".
utils.BlockAmountReserved,
utils.TriesInMemoryFlag,
utils.CheckSnapshotWithMPT,
utils.StateExpiryEnableFlag,
},
Description: `
geth offline prune-block for block data in ancientdb.
Expand All @@ -107,6 +108,7 @@ so it's very necessary to do block data prune, this feature will handle it.
Action: verifyState,
Flags: flags.Merge([]cli.Flag{
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: `
geth snapshot verify-state <state-root>
Expand All @@ -125,6 +127,7 @@ In other words, this command does the snapshot to trie conversion.
Flags: []cli.Flag{
utils.DataDirFlag,
utils.AncientFlag,
utils.StateExpiryEnableFlag,
},
Description: `
will prune all historical trie state data except genesis block.
Expand All @@ -143,7 +146,7 @@ the trie clean cache with default directory will be deleted.
Usage: "Check that there is no 'dangling' snap storage",
ArgsUsage: "<root>",
Action: checkDanglingStorage,
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Description: `
geth snapshot check-dangling-storage <state-root> traverses the snap storage
data, and verifies that all snapshot storage data has a corresponding account.
Expand All @@ -154,7 +157,7 @@ data, and verifies that all snapshot storage data has a corresponding account.
Usage: "Check all snapshot layers for the a specific account",
ArgsUsage: "<address | hash>",
Action: checkAccount,
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Description: `
geth snapshot inspect-account <address | hash> checks all snapshot layers and prints out
information about the specified address.
Expand All @@ -167,6 +170,7 @@ information about the specified address.
Action: traverseState,
Flags: flags.Merge([]cli.Flag{
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: `
geth snapshot traverse-state <state-root>
Expand All @@ -184,6 +188,7 @@ It's also usable without snapshot enabled.
Action: traverseRawState,
Flags: flags.Merge([]cli.Flag{
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: `
geth snapshot traverse-rawstate <state-root>
Expand All @@ -207,6 +212,7 @@ It's also usable without snapshot enabled.
utils.DumpLimitFlag,
utils.TriesInMemoryFlag,
utils.StateSchemeFlag,
utils.StateExpiryEnableFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
Description: `
This command is semantically equivalent to 'geth dump', but uses the snapshots
Expand Down
4 changes: 2 additions & 2 deletions cmd/geth/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
Usage: "verify the conversion of a MPT into a verkle tree",
ArgsUsage: "<root>",
Action: verifyVerkle,
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Description: `
geth verkle verify <state-root>
This command takes a root commitment and attempts to rebuild the tree.
Expand All @@ -56,7 +56,7 @@ This command takes a root commitment and attempts to rebuild the tree.
Usage: "Dump a verkle tree to a DOT file",
ArgsUsage: "<root> <key1> [<key 2> ...]",
Action: expandVerkle,
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags, []cli.Flag{utils.StateExpiryEnableFlag}),
Description: `
geth verkle dump <state-root> <key 1> [<key 2> ...]
This command will produce a dot file representing the tree, rooted at <root>.
Expand Down
16 changes: 13 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,9 @@ func (bc *BlockChain) Stop() {
}
}

epochMetaSnapTree := bc.triedb.EpochMetaSnapTree()
if epochMetaSnapTree != nil {
if err := epochMetaSnapTree.Journal(); err != nil {
epochMetaSnap := bc.triedb.EpochMetaSnapTree()
if epochMetaSnap != nil {
if err := epochMetaSnap.Journal(); err != nil {
log.Error("Failed to journal epochMetaSnapTree", "err", err)
}
}
Expand Down Expand Up @@ -1654,6 +1654,10 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// If node is running in path mode, skip explicit gc operation
// which is unnecessary in this mode.
if bc.triedb.Scheme() == rawdb.PathScheme {
err := bc.triedb.CommitEpochMeta(block.Root())
if err != nil {
return err
}
return nil
}

Expand All @@ -1668,6 +1672,12 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// Full but not archive node, do proper garbage collection
triedb.Reference(block.Root(), common.Hash{}) // metadata reference to keep trie alive
bc.triegc.Push(block.Root(), -int64(block.NumberU64()))
// TODO(0xbundler): when opt commit later, remove it.
go triedb.CommitEpochMeta(block.Root())
//err := triedb.CommitEpochMeta(block.Root())
//if err != nil {
// return err
//}

if current := block.NumberU64(); current > bc.triesInMemory {
// If we exceeded our memory allowance, flush matured singleton nodes to disk
Expand Down
Loading