2019-10-23 05:43:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db"
|
2021-02-15 20:29:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
2021-09-17 21:55:24 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/io/file"
|
2019-10-23 05:43:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// A basic tool to extract genesis.ssz from existing beaconchain.db.
|
|
|
|
// ex:
|
|
|
|
// bazel run //tools/interop/export-genesis:export-genesis -- /tmp/data/beaconchaindata /tmp/genesis.ssz
|
|
|
|
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])
|
|
|
|
|
2021-02-15 20:29:47 +00:00
|
|
|
d, err := db.NewDB(context.Background(), os.Args[1], &kv.Config{})
|
2019-10-23 05:43:41 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-04-13 04:11:09 +00:00
|
|
|
defer func() {
|
|
|
|
if err := d.Close(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
2019-10-23 05:43:41 +00:00
|
|
|
gs, err := d.GenesisState(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-05-24 04:55:42 +00:00
|
|
|
if gs == nil || gs.IsNil() {
|
2019-10-23 05:43:41 +00:00
|
|
|
panic("nil genesis state")
|
|
|
|
}
|
2021-03-16 00:43:27 +00:00
|
|
|
b, err := gs.MarshalSSZ()
|
2019-10-23 05:43:41 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-09-17 21:55:24 +00:00
|
|
|
if err := file.WriteFile(os.Args[2], b); err != nil {
|
2019-10-23 05:43:41 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Println("done")
|
|
|
|
}
|