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
b7e2e8b6
Commit
b7e2e8b6
authored
Sep 23, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move prefetch into oracle
parent
20c6eba6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
49 deletions
+47
-49
proved.go
minigeth/oracle/proved.go
+38
-12
database.go
minigeth/trie/database.go
+6
-35
secure_trie.go
minigeth/trie/secure_trie.go
+3
-2
No files found.
minigeth/oracle/proved.go
View file @
b7e2e8b6
...
...
@@ -9,6 +9,7 @@ import (
"math/big"
"net/http"
"os"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
...
...
@@ -91,10 +92,32 @@ func unhash(addrHash common.Hash) common.Address {
return
unhashMap
[
addrHash
]
}
func
GetProofAccount
(
blockNumber
*
big
.
Int
,
stateRoot
common
.
Hash
,
addr
common
.
Address
)
[]
string
{
var
preimages
=
make
(
map
[
common
.
Hash
][]
byte
)
func
Preimage
(
hash
common
.
Hash
)
[]
byte
{
val
,
ok
:=
preimages
[
hash
]
if
!
ok
{
panic
(
"preimage missing"
)
}
return
val
}
func
PrefetchAddress
(
blockNumber
*
big
.
Int
,
addr
common
.
Address
)
{
ap
:=
GetProofAccount
(
blockNumber
,
addr
)
for
_
,
s
:=
range
ap
{
ret
,
_
:=
hex
.
DecodeString
(
s
[
2
:
])
hash
:=
crypto
.
Keccak256Hash
(
ret
)
preimages
[
hash
]
=
ret
}
}
func
GetProofAccount
(
blockNumber
*
big
.
Int
,
addr
common
.
Address
)
[]
string
{
key
:=
fmt
.
Sprintf
(
"proof_%d_%s"
,
blockNumber
,
addr
)
addrHash
:=
crypto
.
Keccak256Hash
(
addr
[
:
])
unhashMap
[
addrHash
]
=
addr
if
!
cacheExists
(
key
)
{
r
:=
jsonreq
{
Jsonrpc
:
"2.0"
,
Method
:
"eth_getProof"
,
Id
:
1
}
r
.
Params
=
make
([]
interface
{},
3
)
r
.
Params
[
0
]
=
addr
...
...
@@ -105,7 +128,10 @@ func GetProofAccount(blockNumber *big.Int, stateRoot common.Hash, addr common.Ad
defer
resp
.
Body
.
Close
()
jr
:=
jsonresp
{}
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
jr
)
return
jr
.
Result
.
AccountProof
cacheWrite
(
key
,
[]
byte
(
strings
.
Join
(
jr
.
Result
.
AccountProof
,
"
\n
"
)))
}
return
strings
.
Split
(
string
(
cacheRead
(
key
)),
"
\n
"
)
}
func
GetProvedAccountBytes
(
blockNumber
*
big
.
Int
,
stateRoot
common
.
Hash
,
addr
common
.
Address
)
[]
byte
{
...
...
minigeth/trie/database.go
View file @
b7e2e8b6
package
trie
import
(
"encoding/hex"
"fmt"
"io"
"math/big"
...
...
@@ -9,7 +8,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/oracle"
)
...
...
@@ -30,7 +28,6 @@ type Database struct {
BlockNumber
*
big
.
Int
Root
common
.
Hash
lock
sync
.
RWMutex
lookup
map
[
common
.
Hash
][]
byte
preimages
map
[
common
.
Hash
][]
byte
// Preimages of nodes from the secure trie
preimagesSize
common
.
StorageSize
// Storage size of the preimages cache
...
...
@@ -64,25 +61,11 @@ func (db *Database) preimage(hash common.Hash) []byte {
return
db
.
preimages
[
hash
]
}
func
(
db
*
Database
)
Fetch
(
addr
common
.
Address
)
{
fmt
.
Println
(
"prefetch"
,
addr
)
ap
:=
oracle
.
GetProofAccount
(
db
.
BlockNumber
,
db
.
Root
,
addr
)
for
i
,
s
:=
range
ap
{
ret
,
_
:=
hex
.
DecodeString
(
s
[
2
:
])
hash
:=
crypto
.
Keccak256Hash
(
ret
)
db
.
lookup
[
hash
]
=
ret
fmt
.
Println
(
i
,
hash
)
}
}
func
NewDatabase
(
header
types
.
Header
)
Database
{
triedb
:=
Database
{
BlockNumber
:
header
.
Number
,
Root
:
header
.
Root
}
triedb
.
lookup
=
make
(
map
[
common
.
Hash
][]
byte
)
triedb
.
preimages
=
make
(
map
[
common
.
Hash
][]
byte
)
fmt
.
Println
(
"init database"
)
// fetch the root node
triedb
.
Fetch
(
common
.
Address
{})
oracle
.
PrefetchAddress
(
header
.
Number
,
common
.
Address
{})
//panic("preseed")
return
triedb
...
...
@@ -91,27 +74,15 @@ func NewDatabase(header types.Header) Database {
// Node retrieves an encoded cached trie node from memory. If it cannot be found
// cached, the method queries the persistent database for the content.
func
(
db
*
Database
)
Node
(
hash
common
.
Hash
)
([]
byte
,
error
)
{
fmt
.
Println
(
"trie Node"
,
hash
)
return
[]
byte
{},
nil
/*fmt.Println("trie Node", hash)
return []byte{}, nil*/
panic
(
"no Node"
)
}
// node retrieves a cached trie node from memory, or returns nil if none can be
// found in the memory cache.
func
(
db
*
Database
)
node
(
hash
common
.
Hash
)
node
{
fmt
.
Println
(
"trie node"
,
hash
)
emptyHash
:=
common
.
Hash
{}
if
hash
==
emptyHash
{
panic
(
"empty"
)
}
/*emptyHash := common.Hash{}
if hash == emptyHash {
return nilValueNode
}
//return hashNode(hash.Bytes())*/
enc
:=
db
.
lookup
[
hash
]
return
mustDecodeNode
(
hash
[
:
],
enc
)
//return nilValueNode
return
mustDecodeNode
(
hash
[
:
],
oracle
.
Preimage
(
hash
))
}
// insert inserts a collapsed trie node into the memory database.
...
...
minigeth/trie/secure_trie.go
View file @
b7e2e8b6
...
...
@@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/oracle"
)
// SecureTrie wraps a trie with key hashing. In a secure trie, all
...
...
@@ -76,9 +77,9 @@ func (t *SecureTrie) Get(key []byte) []byte {
// The value bytes must not be modified by the caller.
// If a node was not found in the database, a MissingNodeError is returned.
func
(
t
*
SecureTrie
)
TryGet
(
key
[]
byte
)
([]
byte
,
error
)
{
fmt
.
Println
(
"TryGet"
,
key
)
t
.
trie
.
db
.
Fetch
(
common
.
BytesToAddress
(
key
))
oracle
.
PrefetchAddress
(
t
.
trie
.
db
.
BlockNumber
,
common
.
BytesToAddress
(
key
))
//t.trie.db.Fetch(common.BytesToAddress(key))
return
t
.
trie
.
TryGet
(
t
.
hashKey
(
key
))
}
...
...
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