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

cmd/geth: add db cmd to show metadata #23900

Merged
merged 3 commits into from Jan 18, 2022
Merged

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Nov 12, 2021

[user@work go-ethereum]$ ./build/bin/geth --sepolia db metadata
INFO [11-12|14:02:05.331] Maximum peer count                       ETH=50 LES=0 total=50
INFO [11-12|14:02:05.331] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [11-12|14:02:05.332] Set global gas cap                       cap=50,000,000
INFO [11-12|14:02:05.332] Allocated cache and file handles         database=/home/user/.ethereum/sepolia/geth/chaindata cache=512.00MiB handles=262,144 readonly=true
INFO [11-12|14:02:05.536] Opened ancient database                  database=/home/user/.ethereum/sepolia/geth/chaindata/ancient readonly=true
+------------------------+--------------------------------------------------------------------+
|         FIELD          |                               VALUE                                |
+------------------------+--------------------------------------------------------------------+
| databaseVersion        | 8 (0x8)                                                            |
| headBlockHash          | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headFastBlockHash      | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headHeaderHash         | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headBlock.Hash         | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headBlock.Root         | 0x4eaa376b7e4634c1c2258a40206221ff20e126fe529a160cc9eec7fd9286c4cb |
| headBlock.Number       | 96236 (0x177ec)                                                    |
| headHeader.Hash        | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headHeader.Root        | 0x4eaa376b7e4634c1c2258a40206221ff20e126fe529a160cc9eec7fd9286c4cb |
| headHeader.Number      | 96236 (0x177ec)                                                    |
| frozen                 |                                                               6237 |
| lastPivotNumber        | 96168 (0x177a8)                                                    |
| snapshotSyncStatus     | 299 bytes                                                          |
| snapshotGenerator      | c6800180808080                                                     |
| snapshotDisabled       | false                                                              |
| snapshotJournal        | 5882 bytes                                                         |
| snapshotRecoveryNumber | <nil>                                                              |
| snapshotRoot           | 0xcf36401ce2143625f9823620740e59efa93445451acc7cc1e8b621bbc6dab95b |
+------------------------+--------------------------------------------------------------------+

Example with a quirky (broken) datadir, where some things don't match up -- both header hashes/number as well as the frozen-count, which is off.

+------------------------+--------------------------------------------------------------------+
|         FIELD          |                               VALUE                                |
+------------------------+--------------------------------------------------------------------+
| databaseVersion        | 8 (0x8)                                                            |
| headBlockHash          | 0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3 |
| headFastBlockHash      | 0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3 |
| headHeaderHash         | 0x723899e82d352c6eabd21e34942f868687203ca14b3d5a23aeb47c555c123390 |
| headBlock.Hash         | 0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3 |
| headBlock.Root         | 0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544 |
| headBlock.Number       | 0 (0x0)                                                            |
| headHeader.Hash        | 0x723899e82d352c6eabd21e34942f868687203ca14b3d5a23aeb47c555c123390 |
| headHeader.Root        | 0x90a744bf211c10d2ef5a745a09b6813563e6d14453042a916771237aa5ec3f3b |
| headHeader.Number      | 192 (0xc0)                                                         |
| frozen                 |                                                                  2 |
| lastPivotNumber        | 13597267 (0xcf7a53)                                                |
| snapshotSyncStatus     | 227 bytes                                                          |
| snapshotGenerator      |                                                                    |
| snapshotDisabled       | true                                                               |
| snapshotJournal        | 0 bytes                                                            |
| snapshotRecoveryNumber | <nil>                                                              |
| snapshotRoot           | 0x0000000000000000000000000000000000000000000000000000000000000000 |
+------------------------+--------------------------------------------------------------------+

data = append(data, [][]string{{"frozen", fmt.Sprintf("%v", ancients)},
{"lastPivotNumber", pp(rawdb.ReadLastPivotNumber(db))},
{"snapshotSyncStatus", fmt.Sprintf("%d bytes", len(rawdb.ReadSnapshotSyncStatus(db)))},
{"snapshotGenerator", fmt.Sprintf("%x", rawdb.ReadSnapshotGenerator(db))},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to show the byte format generator. Maybe we can decode the content and show the real info? We can define a public function to decode the generator in the snapshot package I think.

@holiman
Copy link
Contributor Author

holiman commented Nov 16, 2021

@rjl493456442 something like this?

+------------------------+--------------------------------------------------------------------+
|         FIELD          |                               VALUE                                |
+------------------------+--------------------------------------------------------------------+
| databaseVersion        | 8 (0x8)                                                            |
| headBlockHash          | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headFastBlockHash      | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headHeaderHash         | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headBlock.Hash         | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headBlock.Root         | 0x4eaa376b7e4634c1c2258a40206221ff20e126fe529a160cc9eec7fd9286c4cb |
| headBlock.Number       | 96236 (0x177ec)                                                    |
| headHeader.Hash        | 0x58552a4eec5f77b1145256e58ea0576ad6e11127bdf2329b947b0e94bc1986fb |
| headHeader.Root        | 0x4eaa376b7e4634c1c2258a40206221ff20e126fe529a160cc9eec7fd9286c4cb |
| headHeader.Number      | 96236 (0x177ec)                                                    |
| frozen                 |                                                               6237 |
| lastPivotNumber        | 96168 (0x177a8)                                                    |
| snapshotSyncStatus     | 299 bytes                                                          |
| snapshotGenerator      | Wiping: false, Done: true,                                         |
|                        | Accounts: 0, Slots: 0,                                             |
|                        | Storage: 0, Marker:                                                |
| snapshotDisabled       | false                                                              |
| snapshotJournal        | 5882 bytes                                                         |
| snapshotRecoveryNumber | <nil>                                                              |
| snapshotRoot           | 0xcf36401ce2143625f9823620740e59efa93445451acc7cc1e8b621bbc6dab95b |
| txIndexTail            | 0 (0x0)                                                            |
| fastTxLookupLimit      | 2350000 (0x23dbb0)                                                 |
+------------------------+--------------------------------------------------------------------+

Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicks, otherwise lgtm

@@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/core/state/snapshot"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the imports

log.Warn("failed to decode snapshot generator", "err", err)
return ""
}
return fmt.Sprintf(`Wiping: %v, Done: %v, Accounts: %d, Slots: %d, Storage: %d, Marker: %x`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

  • we don't have the wiping notion anymore. Wiping will never happen again. I would prefer to not show this info.
  • generation marker can indicate to a storage position, which is 2 * 32 bytes length. I would prefer to interpret it a bit further, e.g.
// Figure out whether we're after or within an account
	switch len(marker) {
	case common.HashLength:
		ctx = append(ctx, []interface{}{"at", common.BytesToHash(marker)}...)
	case 2 * common.HashLength:
		ctx = append(ctx, []interface{}{
			"in", common.BytesToHash(marker[:common.HashLength]),
			"at", common.BytesToHash(marker[common.HashLength:]),
		}...)
	}

cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Copy link
Contributor

@s1na s1na left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@karalabe karalabe added this to the 1.10.16 milestone Jan 18, 2022
@karalabe karalabe merged commit 51eb5f8 into ethereum:master Jan 18, 2022
sidhujag pushed a commit to syscoin/go-ethereum that referenced this pull request Jan 18, 2022
* cmd/geth: add db cmd to show metadata

* cmd/geth: better output generator status

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>

* cmd: minor

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
ValentinTrinque pushed a commit to vegaprotocol/go-ethereum that referenced this pull request Jan 25, 2022
* cmd/geth: add db cmd to show metadata

* cmd/geth: better output generator status

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>

* cmd: minor

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
MariusVanDerWijden pushed a commit to MariusVanDerWijden/go-ethereum that referenced this pull request Jan 27, 2022
* cmd/geth: add db cmd to show metadata

* cmd/geth: better output generator status

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>

* cmd: minor

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
JacekGlen pushed a commit to JacekGlen/go-ethereum that referenced this pull request May 26, 2022
* cmd/geth: add db cmd to show metadata

* cmd/geth: better output generator status

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>

* cmd: minor

Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants