Commit 4da9923c authored by George Hotz's avatar George Hotz

oracle cache

parent 8c5d5b43
...@@ -91,6 +91,7 @@ func unhash(addrHash common.Hash) common.Address { ...@@ -91,6 +91,7 @@ func unhash(addrHash common.Hash) common.Address {
return unhashMap[addrHash] return unhashMap[addrHash]
} }
var cached = make(map[string]bool)
var preimages = make(map[common.Hash][]byte) var preimages = make(map[common.Hash][]byte)
func Preimage(hash common.Hash) []byte { func Preimage(hash common.Hash) []byte {
...@@ -102,6 +103,13 @@ func Preimage(hash common.Hash) []byte { ...@@ -102,6 +103,13 @@ func Preimage(hash common.Hash) []byte {
} }
func PrefetchAddress(blockNumber *big.Int, addr common.Address, skey common.Hash) { func PrefetchAddress(blockNumber *big.Int, addr common.Address, skey common.Hash) {
key := fmt.Sprintf("proof_%d_%s_%s", blockNumber, addr, skey)
if cached[key] {
//fmt.Println("hit", key)
return
}
cached[key] = true
ap := GetProofAccount(blockNumber, addr, skey) ap := GetProofAccount(blockNumber, addr, skey)
for _, s := range ap { for _, s := range ap {
ret, _ := hex.DecodeString(s[2:]) ret, _ := hex.DecodeString(s[2:])
...@@ -138,7 +146,7 @@ func GetProofAccount(blockNumber *big.Int, addr common.Address, skey common.Hash ...@@ -138,7 +146,7 @@ func GetProofAccount(blockNumber *big.Int, addr common.Address, skey common.Hash
func GetProvedCodeBytes(blockNumber *big.Int, addrHash common.Hash, codehash common.Hash) []byte { func GetProvedCodeBytes(blockNumber *big.Int, addrHash common.Hash, codehash common.Hash) []byte {
addr := unhash(addrHash) addr := unhash(addrHash)
fmt.Println("ORACLE GetProvedCodeBytes:", blockNumber, addr, codehash) //fmt.Println("ORACLE GetProvedCodeBytes:", blockNumber, addr, codehash)
key := fmt.Sprintf("code_%s", codehash) key := fmt.Sprintf("code_%s", codehash)
if !cacheExists(key) { if !cacheExists(key) {
r := jsonreq{Jsonrpc: "2.0", Method: "eth_getCode", Id: 1} r := jsonreq{Jsonrpc: "2.0", Method: "eth_getCode", Id: 1}
......
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