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
68028f49
Commit
68028f49
authored
Feb 18, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed block handling
parent
8629d9a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
20 deletions
+29
-20
block_chain.go
ethchain/block_chain.go
+3
-4
block_manager.go
ethchain/block_manager.go
+26
-16
No files found.
ethchain/block_chain.go
View file @
68028f49
...
...
@@ -104,7 +104,6 @@ func (bc *BlockChain) GetChainFromHash(hash []byte, max uint64) []interface{} {
currentHash
=
block
.
PrevHash
chain
=
append
(
chain
,
block
.
Value
()
.
Val
)
//chain = append([]interface{}{block.RlpValue().Value}, chain...)
num
--
}
...
...
@@ -141,7 +140,9 @@ func (bc *BlockChain) Add(block *Block) {
bc
.
CurrentBlock
=
block
bc
.
LastBlockHash
=
block
.
Hash
()
ethutil
.
Config
.
Db
.
Put
(
block
.
Hash
(),
block
.
RlpEncode
())
encodedBlock
:=
block
.
RlpEncode
()
ethutil
.
Config
.
Db
.
Put
(
block
.
Hash
(),
encodedBlock
)
ethutil
.
Config
.
Db
.
Put
([]
byte
(
"LastBlock"
),
encodedBlock
)
}
func
(
bc
*
BlockChain
)
GetBlock
(
hash
[]
byte
)
*
Block
{
...
...
@@ -177,8 +178,6 @@ func (bc *BlockChain) writeBlockInfo(block *Block) {
func
(
bc
*
BlockChain
)
Stop
()
{
if
bc
.
CurrentBlock
!=
nil
{
ethutil
.
Config
.
Db
.
Put
([]
byte
(
"LastBlock"
),
bc
.
CurrentBlock
.
RlpEncode
())
log
.
Println
(
"[CHAIN] Stopped"
)
}
}
ethchain/block_manager.go
View file @
68028f49
...
...
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/obscuren/secp256k1-go"
"log"
"math"
...
...
@@ -18,10 +19,6 @@ type BlockProcessor interface {
ProcessBlock
(
block
*
Block
)
}
func
CalculateBlockReward
(
block
*
Block
,
uncleLength
int
)
*
big
.
Int
{
return
BlockReward
}
type
BlockManager
struct
{
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex
sync
.
Mutex
...
...
@@ -48,7 +45,7 @@ func AddTestNetFunds(block *Block) {
"8a40bfaa73256b60764c1bf40675a99083efb075"
,
// Gavin
"93658b04240e4bd4046fd2d6d417d20f146f4b43"
,
// Jeffrey
"1e12515ce3e0f817a4ddef9ca55788a1d66bd2df"
,
// Vit
"
80c01a26338f0d905e295fccb71fa9ea849ffa12
"
,
// Alex
"
1a26338f0d905e295fccb71fa9ea849ffa12aaf4
"
,
// Alex
}
{
//log.Println("2^200 Wei to", addr)
codedAddr
,
_
:=
hex
.
DecodeString
(
addr
)
...
...
@@ -70,14 +67,17 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager {
if
bm
.
bc
.
CurrentBlock
==
nil
{
AddTestNetFunds
(
bm
.
bc
.
genesisBlock
)
bm
.
bc
.
genesisBlock
.
State
()
.
Sync
()
// Prepare the genesis block
bm
.
bc
.
Add
(
bm
.
bc
.
genesisBlock
)
log
.
Printf
(
"Genesis: %x
\n
"
,
bm
.
bc
.
genesisBlock
.
Hash
())
//log.Printf("root %x\n", bm.bc.genesisBlock.State().Root)
//bm.bc.genesisBlock.PrintHash()
}
log
.
Printf
(
"Last block: %x
\n
"
,
bm
.
bc
.
CurrentBlock
.
Hash
())
return
bm
}
...
...
@@ -115,12 +115,6 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
return
nil
}
/*
if ethutil.Config.Debug {
log.Printf("[BMGR] Processing block(%x)\n", hash)
}
*/
// 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
!
bm
.
bc
.
HasBlock
(
block
.
PrevHash
)
&&
bm
.
bc
.
CurrentBlock
!=
nil
{
...
...
@@ -142,13 +136,12 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
}
if
!
block
.
State
()
.
Cmp
(
bm
.
bc
.
CurrentBlock
.
State
())
{
//if block.State().Root != state.Root {
return
fmt
.
Errorf
(
"Invalid merkle root. Expected %x, got %x"
,
block
.
State
()
.
Root
,
bm
.
bc
.
CurrentBlock
.
State
()
.
Root
)
}
// Calculate the new total difficulty and sync back to the db
if
bm
.
CalculateTD
(
block
)
{
// Sync the current block's state to the database
// Sync the current block's state to the database
and cancelling out the deferred Undo
bm
.
bc
.
CurrentBlock
.
State
()
.
Sync
()
// Add the block to the chain
bm
.
bc
.
Add
(
block
)
...
...
@@ -172,7 +165,7 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
*/
// Broadcast the valid block back to the wire
//bm.Speaker.Broadcast(ethwire.MsgBlockTy, []interface{}{block.RlpValue().Value
})
bm
.
Speaker
.
Broadcast
(
ethwire
.
MsgBlockTy
,
[]
interface
{}{
block
.
Value
()
.
Val
})
// If there's a block processor present, pass in the block for further
// processing
...
...
@@ -251,6 +244,18 @@ func (bm *BlockManager) ValidateBlock(block *Block) error {
return
nil
}
func
CalculateBlockReward
(
block
*
Block
,
uncleLength
int
)
*
big
.
Int
{
base
:=
new
(
big
.
Int
)
for
i
:=
0
;
i
<
uncleLength
;
i
++
{
base
.
Add
(
base
,
UncleInclusionReward
)
}
return
base
.
Add
(
base
,
BlockReward
)
}
func
CalculateUncleReward
(
block
*
Block
)
*
big
.
Int
{
return
UncleReward
}
func
(
bm
*
BlockManager
)
AccumelateRewards
(
processor
*
Block
,
block
*
Block
)
error
{
// Get the coinbase rlp data
addr
:=
processor
.
GetAddr
(
block
.
Coinbase
)
...
...
@@ -259,7 +264,12 @@ func (bm *BlockManager) AccumelateRewards(processor *Block, block *Block) error
processor
.
UpdateAddr
(
block
.
Coinbase
,
addr
)
// TODO Reward each uncle
for
_
,
uncle
:=
range
block
.
Uncles
{
uncleAddr
:=
processor
.
GetAddr
(
uncle
.
Coinbase
)
uncleAddr
.
AddFee
(
CalculateUncleReward
(
uncle
))
processor
.
UpdateAddr
(
uncle
.
Coinbase
,
uncleAddr
)
}
return
nil
}
...
...
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