Commit 0ea43a93 authored by George Hotz's avatar George Hotz

write directories

parent ba611478
......@@ -43,6 +43,7 @@ func main() {
pkwtrie := trie.NewStackTrie(pkw)
blockNumber, _ := strconv.Atoi(os.Args[1])
oracle.SetRoot(fmt.Sprintf("/tmp/eth/%d", blockNumber))
oracle.PrefetchBlock(big.NewInt(int64(blockNumber)), true, nil)
oracle.PrefetchBlock(big.NewInt(int64(blockNumber)+1), false, pkwtrie)
hash, err := pkwtrie.Commit()
......
......@@ -83,7 +83,7 @@ type Account struct {
var nodeUrl = "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
func toFilename(key string) string {
return fmt.Sprintf("/tmp/eth/json_%s", key)
return fmt.Sprintf("%s/json_%s", root, key)
}
func cacheRead(key string) []byte {
......@@ -196,6 +196,7 @@ func Input(index int) common.Hash {
func Output(output common.Hash, receipts common.Hash) {
if receipts != inputs[7] {
fmt.Println("WARNING, receipts don't match", receipts, "!=", inputs[7])
panic("BAD receipts")
}
if output == inputs[6] {
fmt.Println("good transition")
......@@ -299,7 +300,7 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
for i := 0; i < len(inputs); i++ {
saveinput = append(saveinput, inputs[i].Bytes()[:]...)
}
key := fmt.Sprintf("/tmp/eth/%d", blockNumber.Uint64()-1)
key := fmt.Sprintf("%s/input", root)
ioutil.WriteFile(key, saveinput, 0644)
// save the txs
......
......@@ -6,16 +6,27 @@ package oracle
import (
"fmt"
"io/ioutil"
"log"
"os"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
var preimages = make(map[common.Hash][]byte)
var root = "/tmp/eth"
func SetRoot(newRoot string) {
root = newRoot
err := os.MkdirAll(root, os.ModePerm)
if err != nil {
log.Fatal(err)
}
}
func Preimage(hash common.Hash) []byte {
val, ok := preimages[hash]
key := fmt.Sprintf("/tmp/eth/%s", hash)
key := fmt.Sprintf("%s/%s", root, hash)
ioutil.WriteFile(key, val, 0644)
if !ok {
fmt.Println("can't find preimage", hash)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment