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
ff183c82
Commit
ff183c82
authored
Sep 23, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie progress
parent
be29bfd9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
15 deletions
+46
-15
database.go
minigeth/core/state/database.go
+16
-4
statedb.go
minigeth/core/state/statedb.go
+21
-9
main.go
minigeth/main.go
+2
-1
database.go
minigeth/trie/database.go
+7
-1
No files found.
minigeth/core/state/database.go
View file @
ff183c82
...
@@ -5,18 +5,26 @@ import (
...
@@ -5,18 +5,26 @@ import (
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/oracle"
"github.com/ethereum/go-ethereum/oracle"
"github.com/ethereum/go-ethereum/trie"
)
)
// TODO: add oracle calls here
// TODO: add oracle calls here
// wrapper for the oracle
// wrapper for the oracle
type
Database
struct
{
type
Database
struct
{
db
*
trie
.
Database
BlockNumber
*
big
.
Int
BlockNumber
*
big
.
Int
StateRoot
common
.
Hash
StateRoot
common
.
Hash
}
}
func
NewDatabase
(
header
types
.
Header
)
Database
{
triedb
:=
trie
.
Database
{
BlockNumber
:
header
.
Number
}
return
Database
{
db
:
&
triedb
,
BlockNumber
:
header
.
Number
,
StateRoot
:
header
.
Root
}
}
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
{
...
@@ -42,13 +50,17 @@ func (db *Database) ContractCodeSize(addrHash common.Hash, codeHash common.Hash)
...
@@ -42,13 +50,17 @@ func (db *Database) ContractCodeSize(addrHash common.Hash, codeHash common.Hash)
return
len
(
code
),
nil
return
len
(
code
),
nil
}
}
// OpenTrie opens the main account trie at a specific root hash.
func
(
db
*
Database
)
OpenTrie
(
root
common
.
Hash
)
(
Trie
,
error
)
{
//tr, err := trie.NewSecure(root, db.db)
return
trie
.
New
(
root
,
db
.
db
)
}
// OpenStorageTrie opens the storage trie of an account.
// OpenStorageTrie opens the storage trie of an account.
func
(
db
*
Database
)
OpenStorageTrie
(
addrHash
,
root
common
.
Hash
)
(
Trie
,
error
)
{
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
,
unhash
(
addrHash
)},
nil
}
}
type
LeafCallback
func
(
paths
[][]
byte
,
hexpath
[]
byte
,
leaf
[]
byte
,
parent
common
.
Hash
)
error
type
Trie
interface
{
type
Trie
interface
{
// TryGet returns the value for key stored in the trie. The value bytes must
// TryGet returns the value for key stored in the trie. The value bytes must
// not be modified by the caller. If a node was not found in the database, a
// not be modified by the caller. If a node was not found in the database, a
...
@@ -71,7 +83,7 @@ type Trie interface {
...
@@ -71,7 +83,7 @@ type Trie interface {
// Commit writes all nodes to the trie's memory database, tracking the internal
// Commit writes all nodes to the trie's memory database, tracking the internal
// and external (for account tries) references.
// and external (for account tries) references.
Commit
(
onleaf
LeafCallback
)
(
common
.
Hash
,
error
)
Commit
(
onleaf
trie
.
LeafCallback
)
(
common
.
Hash
,
error
)
}
}
type
SimpleTrie
struct
{
type
SimpleTrie
struct
{
...
@@ -81,7 +93,7 @@ type SimpleTrie struct {
...
@@ -81,7 +93,7 @@ type SimpleTrie struct {
Address
common
.
Address
Address
common
.
Address
}
}
func
(
trie
SimpleTrie
)
Commit
(
onleaf
LeafCallback
)
(
common
.
Hash
,
error
)
{
func
(
trie
SimpleTrie
)
Commit
(
onleaf
trie
.
LeafCallback
)
(
common
.
Hash
,
error
)
{
fmt
.
Println
(
"trie.Commit"
)
fmt
.
Println
(
"trie.Commit"
)
return
trie
.
Root
,
nil
return
trie
.
Root
,
nil
}
}
...
...
minigeth/core/state/statedb.go
View file @
ff183c82
...
@@ -117,23 +117,35 @@ type StateDB struct {
...
@@ -117,23 +117,35 @@ type StateDB struct {
SnapshotAccountReads
time
.
Duration
SnapshotAccountReads
time
.
Duration
SnapshotStorageReads
time
.
Duration
SnapshotStorageReads
time
.
Duration
SnapshotCommits
time
.
Duration
SnapshotCommits
time
.
Duration
blockNumber
*
big
.
Int
}
}
func
NewStateDB
(
header
types
.
Header
)
*
StateDB
{
func
New
(
root
common
.
Hash
,
db
Database
,
snaps
*
snapshot
.
Tree
)
(
*
StateDB
,
error
)
{
return
&
StateDB
{
tr
,
err
:=
db
.
OpenTrie
(
root
)
blockNumber
:
header
.
Number
,
if
err
!=
nil
{
return
nil
,
err
}
sdb
:=
&
StateDB
{
db
:
db
,
trie
:
tr
,
originalRoot
:
root
,
snaps
:
snaps
,
stateObjects
:
make
(
map
[
common
.
Address
]
*
stateObject
),
stateObjects
:
make
(
map
[
common
.
Address
]
*
stateObject
),
stateObjectsPending
:
make
(
map
[
common
.
Address
]
struct
{}),
stateObjectsPending
:
make
(
map
[
common
.
Address
]
struct
{}),
stateObjectsDirty
:
make
(
map
[
common
.
Address
]
struct
{}),
stateObjectsDirty
:
make
(
map
[
common
.
Address
]
struct
{}),
originalRoot
:
header
.
Root
,
logs
:
make
(
map
[
common
.
Hash
][]
*
types
.
Log
),
db
:
Database
{
BlockNumber
:
header
.
Number
,
StateRoot
:
header
.
Root
},
preimages
:
make
(
map
[
common
.
Hash
][]
byte
),
trie
:
SimpleTrie
{
BlockNumber
:
header
.
Number
,
Root
:
header
.
Root
,
Storage
:
false
},
journal
:
newJournal
(),
journal
:
newJournal
(),
accessList
:
newAccessList
(),
accessList
:
newAccessList
(),
logs
:
make
(
map
[
common
.
Hash
][]
*
types
.
Log
),
hasher
:
crypto
.
NewKeccakState
(
),
}
}
/*if sdb.snaps != nil {
if sdb.snap = sdb.snaps.Snapshot(root); sdb.snap != nil {
sdb.snapDestructs = make(map[common.Hash]struct{})
sdb.snapAccounts = make(map[common.Hash][]byte)
sdb.snapStorage = make(map[common.Hash]map[common.Hash][]byte)
}
}*/
return
sdb
,
nil
}
}
// setError remembers the first non-nil error it is called with.
// setError remembers the first non-nil error it is called with.
...
...
minigeth/main.go
View file @
ff183c82
...
@@ -24,7 +24,8 @@ func main() {
...
@@ -24,7 +24,8 @@ func main() {
}
}
bc
:=
core
.
NewBlockChain
()
bc
:=
core
.
NewBlockChain
()
statedb
:=
state
.
NewStateDB
(
header
)
database
:=
state
.
NewDatabase
(
header
)
statedb
,
_
:=
state
.
New
(
header
.
Root
,
database
,
nil
)
vmconfig
:=
vm
.
Config
{}
vmconfig
:=
vm
.
Config
{}
processor
:=
core
.
NewStateProcessor
(
params
.
MainnetChainConfig
,
bc
,
bc
.
Engine
())
processor
:=
core
.
NewStateProcessor
(
params
.
MainnetChainConfig
,
bc
,
bc
.
Engine
())
fmt
.
Println
(
"made state processor"
)
fmt
.
Println
(
"made state processor"
)
...
...
minigeth/trie/
extras
.go
→
minigeth/trie/
database
.go
View file @
ff183c82
package
trie
package
trie
import
(
import
(
"fmt"
"io"
"io"
"math/big"
"sync"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -21,18 +23,22 @@ func (n rawNode) EncodeRLP(w io.Writer) error {
...
@@ -21,18 +23,22 @@ func (n rawNode) EncodeRLP(w io.Writer) error {
}
}
type
Database
struct
{
type
Database
struct
{
lock
sync
.
RWMutex
BlockNumber
*
big
.
Int
lock
sync
.
RWMutex
}
}
// Node retrieves an encoded cached trie node from memory. If it cannot be found
// Node retrieves an encoded cached trie node from memory. If it cannot be found
// cached, the method queries the persistent database for the content.
// cached, the method queries the persistent database for the content.
func
(
db
*
Database
)
Node
(
hash
common
.
Hash
)
([]
byte
,
error
)
{
func
(
db
*
Database
)
Node
(
hash
common
.
Hash
)
([]
byte
,
error
)
{
fmt
.
Println
(
"trie Node"
,
hash
)
return
[]
byte
{},
nil
return
[]
byte
{},
nil
}
}
// node retrieves a cached trie node from memory, or returns nil if none can be
// node retrieves a cached trie node from memory, or returns nil if none can be
// found in the memory cache.
// found in the memory cache.
func
(
db
*
Database
)
node
(
hash
common
.
Hash
)
node
{
func
(
db
*
Database
)
node
(
hash
common
.
Hash
)
node
{
fmt
.
Println
(
"trie node"
,
hash
)
//return hashNode(hash.Bytes())
return
nilValueNode
return
nilValueNode
}
}
...
...
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