2019-10-22 22:43:41 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2024-02-14 21:46:47 -08:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db/kv"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/io/file"
|
2019-10-22 22:43:41 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// A basic tool to extract genesis.ssz from existing beaconchain.db.
|
|
|
|
// ex:
|
2022-11-18 14:12:19 -05:00
|
|
|
//
|
|
|
|
// bazel run //tools/interop/export-genesis:export-genesis -- /tmp/data/beaconchaindata /tmp/genesis.ssz
|
2019-10-22 22:43:41 -07:00
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 3 {
|
|
|
|
fmt.Println("Usage: ./main /path/to/datadir /path/to/output/genesis.ssz")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Reading db at %s and writing ssz output to %s.\n", os.Args[1], os.Args[2])
|
|
|
|
|
2023-12-06 14:20:34 -06:00
|
|
|
d, err := kv.NewKVStore(context.Background(), os.Args[1])
|
2019-10-22 22:43:41 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-04-12 21:11:09 -07:00
|
|
|
defer func() {
|
|
|
|
if err := d.Close(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
2019-10-22 22:43:41 -07:00
|
|
|
gs, err := d.GenesisState(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-05-24 12:55:42 +08:00
|
|
|
if gs == nil || gs.IsNil() {
|
2019-10-22 22:43:41 -07:00
|
|
|
panic("nil genesis state")
|
|
|
|
}
|
2021-03-15 17:43:27 -07:00
|
|
|
b, err := gs.MarshalSSZ()
|
2019-10-22 22:43:41 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-17 16:55:24 -05:00
|
|
|
if err := file.WriteFile(os.Args[2], b); err != nil {
|
2019-10-22 22:43:41 -07:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Println("done")
|
|
|
|
}
|