-
-
Save manav2401/157a102434eaa5b28983a9a477caa78d to your computer and use it in GitHub Desktop.
Find offset value for ancient pruner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module go-test | |
go 1.22.4 | |
require github.com/ethereum/go-ethereum v1.14.5 | |
require ( | |
github.com/DataDog/zstd v1.4.5 // indirect | |
github.com/StackExchange/wmi v1.2.1 // indirect | |
github.com/beorn7/perks v1.0.1 // indirect | |
github.com/bits-and-blooms/bitset v1.10.0 // indirect | |
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect | |
github.com/cespare/xxhash/v2 v2.3.0 // indirect | |
github.com/cockroachdb/errors v1.11.1 // indirect | |
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect | |
github.com/cockroachdb/pebble v1.1.0 // indirect | |
github.com/cockroachdb/redact v1.1.5 // indirect | |
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect | |
github.com/consensys/bavard v0.1.13 // indirect | |
github.com/consensys/gnark-crypto v0.12.1 // indirect | |
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect | |
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect | |
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect | |
github.com/getsentry/sentry-go v0.18.0 // indirect | |
github.com/go-ole/go-ole v1.3.0 // indirect | |
github.com/gofrs/flock v0.8.1 // indirect | |
github.com/gogo/protobuf v1.3.2 // indirect | |
github.com/golang/protobuf v1.5.4 // indirect | |
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect | |
github.com/holiman/uint256 v1.2.4 // indirect | |
github.com/klauspost/compress v1.15.15 // indirect | |
github.com/kr/pretty v0.3.1 // indirect | |
github.com/kr/text v0.2.0 // indirect | |
github.com/mattn/go-runewidth v0.0.13 // indirect | |
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect | |
github.com/mmcloughlin/addchain v0.4.0 // indirect | |
github.com/olekukonko/tablewriter v0.0.5 // indirect | |
github.com/pkg/errors v0.9.1 // indirect | |
github.com/prometheus/client_golang v1.12.0 // indirect | |
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect | |
github.com/prometheus/common v0.32.1 // indirect | |
github.com/prometheus/procfs v0.7.3 // indirect | |
github.com/rivo/uniseg v0.2.0 // indirect | |
github.com/rogpeppe/go-internal v1.9.0 // indirect | |
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect | |
github.com/supranational/blst v0.3.11 // indirect | |
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect | |
github.com/tklauser/go-sysconf v0.3.12 // indirect | |
github.com/tklauser/numcpus v0.6.1 // indirect | |
golang.org/x/crypto v0.22.0 // indirect | |
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect | |
golang.org/x/sync v0.7.0 // indirect | |
golang.org/x/sys v0.20.0 // indirect | |
golang.org/x/text v0.14.0 // indirect | |
google.golang.org/protobuf v1.33.0 // indirect | |
rsc.io/tmplfunc v0.0.3 // indirect | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"math/big" | |
"github.com/ethereum/go-ethereum/core/rawdb" | |
"github.com/ethereum/go-ethereum/ethdb" | |
) | |
var ( | |
// offset of the new updated ancientDB. | |
offsetOfCurrentAncientFreezer = []byte("offsetOfCurrentAncientFreezer") | |
// offset of the ancientDB before updated version. | |
offsetOfLastAncientFreezer = []byte("offsetOfLastAncientFreezer") | |
) | |
func main() { | |
path := "/opt/data" | |
fmt.Println("Finding offset in leveldb, path:", path) | |
db, err := rawdb.NewLevelDBDatabase(path, 1024, 2000, "", true) | |
if err != nil { | |
log.Fatalf("Error opening db: %v", err) | |
} | |
defer db.Close() | |
fmt.Println("offsetOfCurrentAncientFreezer:", ReadOffsetOfCurrentAncientFreezer(db)) | |
fmt.Println("offsetOfLastAncientFreezer:", ReadOffsetOfLastAncientFreezer(db)) | |
} | |
// ReadOffsetOfCurrentAncientFreezer reads the offset of current ancient freezer | |
func ReadOffsetOfCurrentAncientFreezer(db ethdb.Database) uint64 { | |
offset, err := db.Get(offsetOfCurrentAncientFreezer) | |
if err != nil { | |
log.Println("Error reading offsetOfCurrentAncientFreezer:", err) | |
} | |
if offset == nil { | |
return 0 | |
} | |
return new(big.Int).SetBytes(offset).Uint64() | |
} | |
// ReadOffsetOfLastAncientFreezer reads the offset of last pruned ancient freezer | |
func ReadOffsetOfLastAncientFreezer(db ethdb.Database) uint64 { | |
offset, err := db.Get(offsetOfLastAncientFreezer) | |
if err != nil { | |
log.Println("Error reading offsetOfCurrentAncientFreezer:", err) | |
} | |
if offset == nil { | |
return 0 | |
} | |
return new(big.Int).SetBytes(offset).Uint64() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment