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
f6bd9a0e
Commit
f6bd9a0e
authored
Sep 23, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved unhash to the oracle
parent
ff183c82
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
31 deletions
+36
-31
database.go
minigeth/core/state/database.go
+7
-24
main.go
minigeth/main.go
+2
-2
proved.go
minigeth/oracle/proved.go
+13
-2
database.go
minigeth/trie/database.go
+7
-1
trie.go
minigeth/trie/trie.go
+7
-2
No files found.
minigeth/core/state/database.go
View file @
f6bd9a0e
...
...
@@ -6,7 +6,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"
"github.com/ethereum/go-ethereum/trie"
)
...
...
@@ -21,20 +20,13 @@ type Database struct {
}
func
NewDatabase
(
header
types
.
Header
)
Database
{
triedb
:=
trie
.
Database
{
BlockNumber
:
header
.
Number
}
triedb
:=
trie
.
Database
{
BlockNumber
:
header
.
Number
,
Root
:
header
.
Root
}
return
Database
{
db
:
&
triedb
,
BlockNumber
:
header
.
Number
,
StateRoot
:
header
.
Root
}
}
var
unhashMap
=
make
(
map
[
common
.
Hash
]
common
.
Address
)
func
unhash
(
addrHash
common
.
Hash
)
common
.
Address
{
return
unhashMap
[
addrHash
]
}
// ContractCode retrieves a particular contract's code.
func
(
db
*
Database
)
ContractCode
(
addrHash
common
.
Hash
,
codeHash
common
.
Hash
)
([]
byte
,
error
)
{
addr
:=
unhash
(
addrHash
)
code
:=
oracle
.
GetProvedCodeBytes
(
db
.
BlockNumber
,
addr
,
codeHash
)
code
:=
oracle
.
GetProvedCodeBytes
(
db
.
BlockNumber
,
addrHash
,
codeHash
)
return
code
,
nil
}
...
...
@@ -45,8 +37,7 @@ func (db *Database) CopyTrie(trie Trie) Trie {
// ContractCodeSize retrieves a particular contracts code's size.
func
(
db
*
Database
)
ContractCodeSize
(
addrHash
common
.
Hash
,
codeHash
common
.
Hash
)
(
int
,
error
)
{
addr
:=
unhash
(
addrHash
)
code
:=
oracle
.
GetProvedCodeBytes
(
db
.
BlockNumber
,
addr
,
codeHash
)
code
:=
oracle
.
GetProvedCodeBytes
(
db
.
BlockNumber
,
addrHash
,
codeHash
)
return
len
(
code
),
nil
}
...
...
@@ -58,7 +49,7 @@ func (db *Database) OpenTrie(root common.Hash) (Trie, error) {
// OpenStorageTrie opens the storage trie of an account.
func
(
db
*
Database
)
OpenStorageTrie
(
addrHash
,
root
common
.
Hash
)
(
Trie
,
error
)
{
return
SimpleTrie
{
db
.
BlockNumber
,
root
,
true
,
unhash
(
addrHash
)
},
nil
return
SimpleTrie
{
db
.
BlockNumber
,
root
,
true
,
addrHash
},
nil
}
type
Trie
interface
{
...
...
@@ -90,7 +81,7 @@ type SimpleTrie struct {
BlockNumber
*
big
.
Int
Root
common
.
Hash
Storage
bool
Address
common
.
Address
Address
Hash
common
.
Hash
}
func
(
trie
SimpleTrie
)
Commit
(
onleaf
trie
.
LeafCallback
)
(
common
.
Hash
,
error
)
{
...
...
@@ -114,16 +105,8 @@ func (trie SimpleTrie) TryDelete(key []byte) error {
}
func
(
trie
SimpleTrie
)
TryGet
(
key
[]
byte
)
([]
byte
,
error
)
{
if
trie
.
Storage
{
enc
:=
oracle
.
GetProvedStorage
(
trie
.
BlockNumber
,
trie
.
Address
,
trie
.
Root
,
common
.
BytesToHash
(
key
))
return
enc
.
Bytes
(),
nil
}
else
{
address
:=
common
.
BytesToAddress
(
key
)
addrHash
:=
crypto
.
Keccak256Hash
(
address
[
:
])
unhashMap
[
addrHash
]
=
address
enc
:=
oracle
.
GetProvedAccountBytes
(
trie
.
BlockNumber
,
trie
.
Root
,
address
)
return
enc
,
nil
}
enc
:=
oracle
.
GetProvedStorage
(
trie
.
BlockNumber
,
trie
.
AddressHash
,
trie
.
Root
,
common
.
BytesToHash
(
key
))
return
enc
.
Bytes
(),
nil
}
// stubbed: we don't prefetch
...
...
minigeth/main.go
View file @
f6bd9a0e
...
...
@@ -52,8 +52,8 @@ func main() {
_
,
_
,
_
,
err
:=
processor
.
Process
(
block
,
statedb
,
vmconfig
)
fmt
.
Println
(
err
)
outHash
,
err
:=
statedb
.
Commit
(
false
)
/*
outHash, err := statedb.Commit(false)
fmt.Println(err)
fmt
.
Println
(
"process done with hash"
,
outHash
,
header
.
Root
)
fmt.Println("process done with hash", outHash, header.Root)
*/
}
minigeth/oracle/proved.go
View file @
f6bd9a0e
...
...
@@ -85,10 +85,19 @@ func cacheWrite(key string, value []byte) {
os
.
WriteFile
(
toFilename
(
key
),
value
,
0644
)
}
var
unhashMap
=
make
(
map
[
common
.
Hash
]
common
.
Address
)
func
unhash
(
addrHash
common
.
Hash
)
common
.
Address
{
return
unhashMap
[
addrHash
]
}
func
GetProvedAccountBytes
(
blockNumber
*
big
.
Int
,
stateRoot
common
.
Hash
,
addr
common
.
Address
)
[]
byte
{
fmt
.
Println
(
"ORACLE GetProvedAccountBytes:"
,
blockNumber
,
stateRoot
,
addr
)
key
:=
fmt
.
Sprintf
(
"accounts_%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
)
...
...
@@ -120,7 +129,8 @@ func GetProvedAccountBytes(blockNumber *big.Int, stateRoot common.Hash, addr com
return
cacheRead
(
key
)
}
func
GetProvedCodeBytes
(
blockNumber
*
big
.
Int
,
addr
common
.
Address
,
codehash
common
.
Hash
)
[]
byte
{
func
GetProvedCodeBytes
(
blockNumber
*
big
.
Int
,
addrHash
common
.
Hash
,
codehash
common
.
Hash
)
[]
byte
{
addr
:=
unhash
(
addrHash
)
fmt
.
Println
(
"ORACLE GetProvedCodeBytes:"
,
blockNumber
,
addr
,
codehash
)
key
:=
fmt
.
Sprintf
(
"code_%s"
,
codehash
)
if
!
cacheExists
(
key
)
{
...
...
@@ -155,7 +165,8 @@ func GetProvedCodeBytes(blockNumber *big.Int, addr common.Address, codehash comm
return
cacheRead
(
key
)
}
func
GetProvedStorage
(
blockNumber
*
big
.
Int
,
addr
common
.
Address
,
root
common
.
Hash
,
skey
common
.
Hash
)
common
.
Hash
{
func
GetProvedStorage
(
blockNumber
*
big
.
Int
,
addrHash
common
.
Hash
,
root
common
.
Hash
,
skey
common
.
Hash
)
common
.
Hash
{
addr
:=
unhash
(
addrHash
)
key
:=
fmt
.
Sprintf
(
"storage_%d_%s_%s_%s"
,
blockNumber
,
addr
,
root
,
skey
)
if
!
cacheExists
(
key
)
{
...
...
minigeth/trie/database.go
View file @
f6bd9a0e
...
...
@@ -24,6 +24,7 @@ func (n rawNode) EncodeRLP(w io.Writer) error {
type
Database
struct
{
BlockNumber
*
big
.
Int
Root
common
.
Hash
lock
sync
.
RWMutex
}
...
...
@@ -38,8 +39,13 @@ func (db *Database) Node(hash common.Hash) ([]byte, error) {
// found in the memory cache.
func
(
db
*
Database
)
node
(
hash
common
.
Hash
)
node
{
fmt
.
Println
(
"trie node"
,
hash
)
emptyHash
:=
common
.
Hash
{}
if
hash
==
emptyHash
{
return
nilValueNode
}
//return hashNode(hash.Bytes())
return
nilValueNode
return
hashNode
(
nil
)
//return nilValueNode
}
// insert inserts a collapsed trie node into the memory database.
...
...
minigeth/trie/trie.go
View file @
f6bd9a0e
...
...
@@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/oracle"
)
var
(
...
...
@@ -114,11 +115,15 @@ func (t *Trie) 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
*
Trie
)
TryGet
(
key
[]
byte
)
([]
byte
,
error
)
{
value
,
newroot
,
didResolve
,
err
:=
t
.
tryGet
(
t
.
root
,
keybytesToHex
(
key
),
0
)
fmt
.
Println
(
"TryGet"
,
key
)
/*value, newroot, didResolve, err := t.tryGet(t.root, keybytesToHex(key), 0)
if err == nil && didResolve {
t.root = newroot
}
return
value
,
err
return value, err*/
address
:=
common
.
BytesToAddress
(
key
)
enc
:=
oracle
.
GetProvedAccountBytes
(
t
.
db
.
BlockNumber
,
t
.
db
.
Root
,
address
)
return
enc
,
nil
}
func
(
t
*
Trie
)
tryGet
(
origNode
node
,
key
[]
byte
,
pos
int
)
(
value
[]
byte
,
newnode
node
,
didResolve
bool
,
err
error
)
{
...
...
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