diff --git a/cmd/hack/hack.go b/cmd/hack/hack.go index 5de39accc..5d24f1a45 100644 --- a/cmd/hack/hack.go +++ b/cmd/hack/hack.go @@ -2093,6 +2093,42 @@ func indexKeySizes(chaindata string) error { return nil } +func extractBodies(chaindata string, block uint64) error { + db := ethdb.MustOpen(chaindata) + defer db.Close() + tx, err := db.Begin(context.Background(), ethdb.RO) + if err != nil { + return err + } + defer tx.Rollback() + c := tx.(ethdb.HasTx).Tx().Cursor(dbutils.BlockBodyPrefix) + defer c.Close() + blockEncoded := dbutils.EncodeBlockNumber(block) + for k, _, err := c.Seek(blockEncoded); k != nil; k, _, err = c.Next() { + if err != nil { + return err + } + blockNumber := binary.BigEndian.Uint64(k[:8]) + blockHash := common.BytesToHash(k[8:]) + body := rawdb.ReadBody(db, blockHash, blockNumber) + b, err := rlp.EncodeToBytes(body) + if err != nil { + return err + } + fmt.Printf("Body %d %x: %x\n", blockNumber, blockHash, b) + header := rawdb.ReadHeader(db, blockHash, blockNumber) + b, err = rlp.EncodeToBytes(header) + if err != nil { + return err + } + fmt.Printf("Header %d %x: %x\n", blockNumber, blockHash, b) + if blockNumber > block+5 { + break + } + } + return nil +} + func main() { flag.Parse() @@ -2277,4 +2313,9 @@ func main() { fmt.Printf("Error: %v\n", err) } } + if *action == "extractBodies" { + if err := extractBodies(*chaindata, uint64(*block)); err != nil { + fmt.Printf("Error:%v\n", err) + } + } }