Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
张蕾
Geth-Modification
Commits
38d6b67b
Commit
38d6b67b
authored
11 years ago
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed state problem
parent
5516efdf
master
v1.10.12
v1.10.12-modified
No related merge requests found
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
20 deletions
+48
-20
block.go
ethchain/block.go
+1
-4
block_chain.go
ethchain/block_chain.go
+2
-1
state_manager.go
ethchain/state_manager.go
+7
-6
miner.go
ethminer/miner.go
+7
-5
bytes.go
ethutil/bytes.go
+10
-0
trie.go
ethutil/trie.go
+17
-2
peer.go
peer.go
+4
-2
No files found.
ethchain/block.go
View file @
38d6b67b
...
...
@@ -80,9 +80,6 @@ func CreateBlock(root interface{},
extra
string
,
txes
[]
*
Transaction
)
*
Block
{
// Copy over the bytes
copiedRoot
:=
ethutil
.
NewValue
(
root
)
.
Bytes
()
block
:=
&
Block
{
// Slice of transactions to include in this block
transactions
:
txes
,
...
...
@@ -98,7 +95,7 @@ func CreateBlock(root interface{},
block
.
SetTransactions
(
txes
)
block
.
SetUncles
([]
*
Block
{})
block
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
copiedR
oot
))
block
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
r
oot
))
for
_
,
tx
:=
range
txes
{
block
.
MakeContract
(
tx
)
...
...
This diff is collapsed.
Click to expand it.
ethchain/block_chain.go
View file @
38d6b67b
...
...
@@ -179,7 +179,8 @@ func (bc *BlockChain) ResetTillBlockHash(hash []byte) error {
bc
.
LastBlockNumber
=
info
.
Number
}
bc
.
Ethereum
.
StateManager
()
.
PrepareDefault
(
returnTo
)
// XXX Why are we resetting? This is the block chain, it has nothing to do with states
//bc.Ethereum.StateManager().PrepareDefault(returnTo)
err
:=
ethutil
.
Config
.
Db
.
Delete
(
lastBlock
.
Hash
())
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
ethchain/state_manager.go
View file @
38d6b67b
...
...
@@ -158,18 +158,19 @@ func (sm *StateManager) ProcessBlock(block *Block, dontReact bool) error {
// Processing a blocks may never happen simultaneously
sm
.
mutex
.
Lock
()
defer
sm
.
mutex
.
Unlock
()
// Defer the Undo on the Trie. If the block processing happened
// we don't want to undo but since undo only happens on dirty
// nodes this won't happen because Commit would have been called
// before that.
defer
sm
.
bc
.
CurrentBlock
.
Undo
()
hash
:=
block
.
Hash
()
if
sm
.
bc
.
HasBlock
(
hash
)
{
fmt
.
Println
(
"[S
M
] We already have this block, ignoring"
)
fmt
.
Println
(
"[S
TATE
] We already have this block, ignoring"
)
return
nil
}
// Defer the Undo on the Trie. If the block processing happened
// we don't want to undo but since undo only happens on dirty
// nodes this won't happen because Commit would have been called
// before that.
defer
sm
.
bc
.
CurrentBlock
.
Undo
()
// Check if we have the parent hash, if it isn't known we discard it
// Reasons might be catching up or simply an invalid block
if
!
sm
.
bc
.
HasBlock
(
block
.
PrevHash
)
&&
sm
.
bc
.
CurrentBlock
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
ethminer/miner.go
View file @
38d6b67b
...
...
@@ -2,6 +2,7 @@ package ethminer
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
...
...
@@ -61,10 +62,10 @@ func (miner *Miner) listener() {
select
{
case
chanMessage
:=
<-
miner
.
reactChan
:
if
block
,
ok
:=
chanMessage
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
//
log.Println("[MINER] Got new block via Reactor")
log
.
Println
(
"[MINER] Got new block via Reactor"
)
if
bytes
.
Compare
(
miner
.
ethereum
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
block
.
Hash
())
==
0
{
// TODO: Perhaps continue mining to get some uncle rewards
//
log.Println("[MINER] New top block found resetting state")
log
.
Println
(
"[MINER] New top block found resetting state"
)
// Filter out which Transactions we have that were not in this block
var
newtxs
[]
*
ethchain
.
Transaction
...
...
@@ -86,7 +87,7 @@ func (miner *Miner) listener() {
}
else
{
if
bytes
.
Compare
(
block
.
PrevHash
,
miner
.
ethereum
.
BlockChain
()
.
CurrentBlock
.
PrevHash
)
==
0
{
//
log.Println("[MINER] Adding uncle block")
log
.
Println
(
"[MINER] Adding uncle block"
)
miner
.
uncles
=
append
(
miner
.
uncles
,
block
)
miner
.
ethereum
.
StateManager
()
.
Prepare
(
miner
.
block
.
State
(),
miner
.
block
.
State
())
}
...
...
@@ -133,8 +134,9 @@ func (miner *Miner) listener() {
miner
.
ethereum
.
StateManager
()
.
PrepareDefault
(
miner
.
block
)
err
:=
miner
.
ethereum
.
StateManager
()
.
ProcessBlock
(
miner
.
block
,
true
)
if
err
!=
nil
{
log
.
Println
(
"Error result from process block:"
,
err
)
miner
.
block
.
State
()
.
Reset
()
log
.
Println
(
err
)
miner
.
txs
=
[]
*
ethchain
.
Transaction
{}
// Move this somewhere neat
miner
.
block
=
miner
.
ethereum
.
BlockChain
()
.
NewBlock
(
miner
.
coinbase
,
miner
.
txs
)
}
else
{
/*
...
...
This diff is collapsed.
Click to expand it.
ethutil/bytes.go
View file @
38d6b67b
...
...
@@ -73,3 +73,13 @@ func BinaryLength(num int) int {
return
1
+
BinaryLength
(
num
>>
8
)
}
// Copy bytes
//
// Returns an exact copy of the provided bytes
func
CopyBytes
(
b
[]
byte
)
(
copiedBytes
[]
byte
)
{
copiedBytes
=
make
([]
byte
,
len
(
b
))
copy
(
copiedBytes
,
b
)
return
}
This diff is collapsed.
Click to expand it.
ethutil/trie.go
View file @
38d6b67b
...
...
@@ -119,14 +119,29 @@ type Trie struct {
cache
*
Cache
}
func
copyRoot
(
root
interface
{})
interface
{}
{
var
prevRootCopy
interface
{}
if
b
,
ok
:=
root
.
([]
byte
);
ok
{
prevRootCopy
=
CopyBytes
(
b
)
}
else
{
prevRootCopy
=
root
}
return
prevRootCopy
}
func
NewTrie
(
db
Database
,
Root
interface
{})
*
Trie
{
return
&
Trie
{
cache
:
NewCache
(
db
),
Root
:
Root
,
prevRoot
:
Root
}
// Make absolute sure the root is copied
r
:=
copyRoot
(
Root
)
p
:=
copyRoot
(
Root
)
return
&
Trie
{
cache
:
NewCache
(
db
),
Root
:
r
,
prevRoot
:
p
}
}
// Save the cached value to the database.
func
(
t
*
Trie
)
Sync
()
{
t
.
cache
.
Commit
()
t
.
prevRoot
=
t
.
Root
t
.
prevRoot
=
copyRoot
(
t
.
Root
)
}
func
(
t
*
Trie
)
Undo
()
{
...
...
This diff is collapsed.
Click to expand it.
peer.go
View file @
38d6b67b
...
...
@@ -449,8 +449,10 @@ func (p *Peer) HandleInbound() {
if
parent
!=
nil
{
ethutil
.
Config
.
Log
.
Infof
(
"[PEER] Found conical block, returning chain from: %x "
,
parent
.
Hash
())
chain
:=
p
.
ethereum
.
BlockChain
()
.
GetChainFromHash
(
parent
.
Hash
(),
amountOfBlocks
)
ethutil
.
Config
.
Log
.
Infof
(
"[PEER] Returning %d blocks: %x "
,
len
(
chain
),
parent
.
Hash
())
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgBlockTy
,
chain
))
if
len
(
chain
)
>
0
{
ethutil
.
Config
.
Log
.
Infof
(
"[PEER] Returning %d blocks: %x "
,
len
(
chain
),
parent
.
Hash
())
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgBlockTy
,
chain
))
}
}
else
{
ethutil
.
Config
.
Log
.
Infof
(
"[PEER] Could not find a similar block"
)
// If no blocks are found we send back a reply with msg not in chain
...
...
This diff is collapsed.
Click to expand it.
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