Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
a24394dc
Commit
a24394dc
authored
Sep 23, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor prefetch a bit, still bad
parent
dc6a9291
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
53 deletions
+40
-53
prefetch.go
minigeth/oracle/prefetch.go
+40
-53
No files found.
minigeth/oracle/prefetch.go
View file @
a24394dc
...
@@ -5,11 +5,11 @@ import (
...
@@ -5,11 +5,11 @@ import (
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io"
"io/ioutil"
"io/ioutil"
"math/big"
"math/big"
"net/http"
"net/http"
"os"
"os"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/hexutil"
...
@@ -85,6 +85,18 @@ func cacheWrite(key string, value []byte) {
...
@@ -85,6 +85,18 @@ func cacheWrite(key string, value []byte) {
os
.
WriteFile
(
toFilename
(
key
),
value
,
0644
)
os
.
WriteFile
(
toFilename
(
key
),
value
,
0644
)
}
}
func
getAPI
(
jsonData
[]
byte
)
io
.
Reader
{
key
:=
hexutil
.
Encode
(
crypto
.
Keccak256
(
jsonData
))
if
cacheExists
(
key
)
{
return
bytes
.
NewReader
(
cacheRead
(
key
))
}
resp
,
_
:=
http
.
Post
(
nodeUrl
,
"application/json"
,
bytes
.
NewBuffer
(
jsonData
))
defer
resp
.
Body
.
Close
()
ret
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
cacheWrite
(
key
,
ret
)
return
bytes
.
NewReader
(
ret
)
}
var
unhashMap
=
make
(
map
[
common
.
Hash
]
common
.
Address
)
var
unhashMap
=
make
(
map
[
common
.
Hash
]
common
.
Address
)
func
unhash
(
addrHash
common
.
Hash
)
common
.
Address
{
func
unhash
(
addrHash
common
.
Hash
)
common
.
Address
{
...
@@ -136,70 +148,45 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {
...
@@ -136,70 +148,45 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {
preimages
[
hash
]
=
ret
preimages
[
hash
]
=
ret
}
}
func
getProofAccount
(
blockNumber
*
big
.
Int
,
addr
common
.
Address
,
skey
common
.
Hash
,
storage
bool
)
[]
string
{
func
PrefetchBlock
(
blockNumber
*
big
.
Int
)
{
var
key
string
}
if
storage
{
key
=
fmt
.
Sprintf
(
"proof_%d_%s_%s"
,
blockNumber
,
addr
,
skey
)
}
else
{
key
=
fmt
.
Sprintf
(
"proof_%d_%s"
,
blockNumber
,
addr
)
}
func
getProofAccount
(
blockNumber
*
big
.
Int
,
addr
common
.
Address
,
skey
common
.
Hash
,
storage
bool
)
[]
string
{
addrHash
:=
crypto
.
Keccak256Hash
(
addr
[
:
])
addrHash
:=
crypto
.
Keccak256Hash
(
addr
[
:
])
unhashMap
[
addrHash
]
=
addr
unhashMap
[
addrHash
]
=
addr
if
!
cacheExists
(
key
)
{
r
:=
jsonreq
{
Jsonrpc
:
"2.0"
,
Method
:
"eth_getProof"
,
Id
:
1
}
r
:=
jsonreq
{
Jsonrpc
:
"2.0"
,
Method
:
"eth_getProof"
,
Id
:
1
}
r
.
Params
=
make
([]
interface
{},
3
)
r
.
Params
=
make
([]
interface
{},
3
)
r
.
Params
[
0
]
=
addr
r
.
Params
[
0
]
=
addr
r
.
Params
[
1
]
=
[
1
]
common
.
Hash
{
skey
}
r
.
Params
[
1
]
=
[
1
]
common
.
Hash
{
skey
}
r
.
Params
[
2
]
=
fmt
.
Sprintf
(
"0x%x"
,
blockNumber
.
Int64
())
r
.
Params
[
2
]
=
fmt
.
Sprintf
(
"0x%x"
,
blockNumber
.
Int64
())
jsonData
,
_
:=
json
.
Marshal
(
r
)
jsonData
,
_
:=
json
.
Marshal
(
r
)
jr
:=
jsonresp
{}
resp
,
_
:=
http
.
Post
(
nodeUrl
,
"application/json"
,
bytes
.
NewBuffer
(
jsonData
))
json
.
NewDecoder
(
getAPI
(
jsonData
))
.
Decode
(
&
jr
)
defer
resp
.
Body
.
Close
()
jr
:=
jsonresp
{}
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
jr
)
if
storage
{
arr
:=
jr
.
Result
.
StorageProof
[
0
]
.
Proof
cacheWrite
(
key
,
[]
byte
(
strings
.
Join
(
arr
,
"
\n
"
)))
}
else
{
arr
:=
jr
.
Result
.
AccountProof
cacheWrite
(
key
,
[]
byte
(
strings
.
Join
(
arr
,
"
\n
"
)))
}
if
storage
{
return
jr
.
Result
.
StorageProof
[
0
]
.
Proof
}
else
{
return
jr
.
Result
.
AccountProof
}
}
return
strings
.
Split
(
string
(
cacheRead
(
key
)),
"
\n
"
)
}
}
func
getProvedCodeBytes
(
blockNumber
*
big
.
Int
,
addrHash
common
.
Hash
)
[]
byte
{
func
getProvedCodeBytes
(
blockNumber
*
big
.
Int
,
addrHash
common
.
Hash
)
[]
byte
{
addr
:=
unhash
(
addrHash
)
addr
:=
unhash
(
addrHash
)
//fmt.Println("ORACLE GetProvedCodeBytes:", blockNumber, addr, codehash)
key
:=
fmt
.
Sprintf
(
"code_%d_%s"
,
blockNumber
,
addr
)
if
!
cacheExists
(
key
)
{
r
:=
jsonreq
{
Jsonrpc
:
"2.0"
,
Method
:
"eth_getCode"
,
Id
:
1
}
r
.
Params
=
make
([]
interface
{},
2
)
r
.
Params
[
0
]
=
addr
r
.
Params
[
1
]
=
fmt
.
Sprintf
(
"0x%x"
,
blockNumber
.
Int64
())
jsonData
,
_
:=
json
.
Marshal
(
r
)
//fmt.Println(string(jsonData))
resp
,
_
:=
http
.
Post
(
nodeUrl
,
"application/json"
,
bytes
.
NewBuffer
(
jsonData
))
defer
resp
.
Body
.
Close
()
/*tmp, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(tmp))*/
jr
:=
jsonresps
{}
r
:=
jsonreq
{
Jsonrpc
:
"2.0"
,
Method
:
"eth_getCode"
,
Id
:
1
}
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
jr
)
r
.
Params
=
make
([]
interface
{},
2
)
r
.
Params
[
0
]
=
addr
r
.
Params
[
1
]
=
fmt
.
Sprintf
(
"0x%x"
,
blockNumber
.
Int64
())
jsonData
,
_
:=
json
.
Marshal
(
r
)
jr
:=
jsonresps
{}
json
.
NewDecoder
(
getAPI
(
jsonData
))
.
Decode
(
&
jr
)
//fmt.Println(jr.Result)
//fmt.Println(jr.Result)
// curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x2"],"id":1}'
// curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x2"],"id":1}'
ret
,
_
:=
hex
.
DecodeString
(
jr
.
Result
[
2
:
])
//fmt.Println(ret)
cacheWrite
(
key
,
ret
)
}
return
cacheRead
(
key
)
ret
,
_
:=
hex
.
DecodeString
(
jr
.
Result
[
2
:
])
//fmt.Println(ret)
return
ret
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment