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
33a0dec8
Commit
33a0dec8
authored
Sep 15, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved catching up and refactored
parent
2f614900
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
125 additions
and
102 deletions
+125
-102
block_pool.go
block_pool.go
+17
-42
block.go
ethchain/block.go
+29
-4
block_chain.go
ethchain/block_chain.go
+12
-13
state_manager.go
ethchain/state_manager.go
+5
-3
dump.go
ethstate/dump.go
+1
-1
state.go
ethstate/state.go
+3
-2
state_object.go
ethstate/state_object.go
+10
-5
bytes.go
ethutil/bytes.go
+16
-0
rlp.go
ethutil/rlp.go
+2
-0
set.go
ethutil/set.go
+10
-6
peer.go
peer.go
+20
-26
No files found.
block_pool.go
View file @
33a0dec8
...
@@ -52,59 +52,34 @@ func (self *BlockPool) AddHash(hash []byte) {
...
@@ -52,59 +52,34 @@ func (self *BlockPool) AddHash(hash []byte) {
func
(
self
*
BlockPool
)
SetBlock
(
b
*
ethchain
.
Block
,
peer
*
Peer
)
{
func
(
self
*
BlockPool
)
SetBlock
(
b
*
ethchain
.
Block
,
peer
*
Peer
)
{
hash
:=
string
(
b
.
Hash
())
hash
:=
string
(
b
.
Hash
())
if
self
.
pool
[
hash
]
==
nil
{
if
self
.
pool
[
hash
]
==
nil
&&
!
self
.
eth
.
BlockChain
()
.
HasBlock
(
b
.
Hash
())
{
self
.
hashPool
=
append
(
self
.
hashPool
,
b
.
Hash
())
self
.
hashPool
=
append
(
self
.
hashPool
,
b
.
Hash
())
self
.
pool
[
hash
]
=
&
block
{
peer
,
nil
}
self
.
pool
[
hash
]
=
&
block
{
peer
,
b
}
}
}
else
if
self
.
pool
[
hash
]
!=
nil
{
self
.
pool
[
hash
]
.
block
=
b
self
.
pool
[
hash
]
.
block
=
b
}
}
}
func
(
self
*
BlockPool
)
CheckLinkAndProcess
(
f
func
(
block
*
ethchain
.
Block
))
bool
{
func
(
self
*
BlockPool
)
CheckLinkAndProcess
(
f
func
(
block
*
ethchain
.
Block
))
{
self
.
mut
.
Lock
()
defer
self
.
mut
.
Unlock
()
if
self
.
IsLinked
()
{
var
blocks
ethchain
.
Blocks
for
i
,
hash
:=
range
self
.
hashPool
{
for
_
,
item
:=
range
self
.
pool
{
if
self
.
pool
[
string
(
hash
)]
==
nil
{
if
item
.
block
!=
nil
{
continue
blocks
=
append
(
blocks
,
item
.
block
)
}
}
}
block
:=
self
.
pool
[
string
(
hash
)]
.
block
ethchain
.
BlockBy
(
ethchain
.
Number
)
.
Sort
(
blocks
)
if
block
!=
nil
{
for
_
,
block
:=
range
blocks
{
if
self
.
eth
.
BlockChain
()
.
HasBlock
(
block
.
PrevHash
)
{
f
(
block
)
f
(
block
)
hash
:=
block
.
Hash
()
self
.
hashPool
=
ethutil
.
DeleteFromByteSlice
(
self
.
hashPool
,
hash
)
delete
(
self
.
pool
,
string
(
hash
))
delete
(
self
.
pool
,
string
(
hash
))
}
else
{
self
.
hashPool
=
self
.
hashPool
[
i
:
]
return
false
}
}
}
return
true
}
}
return
false
}
func
(
self
*
BlockPool
)
IsLinked
()
bool
{
if
len
(
self
.
hashPool
)
==
0
{
return
false
}
for
i
:=
0
;
i
<
len
(
self
.
hashPool
);
i
++
{
item
:=
self
.
pool
[
string
(
self
.
hashPool
[
i
])]
if
item
!=
nil
&&
item
.
block
!=
nil
{
if
self
.
eth
.
BlockChain
()
.
HasBlock
(
item
.
block
.
PrevHash
)
{
self
.
hashPool
=
self
.
hashPool
[
i
:
]
return
true
}
}
}
return
false
}
}
func
(
self
*
BlockPool
)
Take
(
amount
int
,
peer
*
Peer
)
(
hashes
[][]
byte
)
{
func
(
self
*
BlockPool
)
Take
(
amount
int
,
peer
*
Peer
)
(
hashes
[][]
byte
)
{
...
...
ethchain/block.go
View file @
33a0dec8
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"bytes"
"bytes"
"fmt"
"fmt"
"math/big"
"math/big"
"sort"
_
"strconv"
_
"strconv"
"time"
"time"
...
@@ -42,9 +43,32 @@ func (self Blocks) AsSet() ethutil.UniqueSet {
...
@@ -42,9 +43,32 @@ func (self Blocks) AsSet() ethutil.UniqueSet {
return
set
return
set
}
}
type
BlockBy
func
(
b1
,
b2
*
Block
)
bool
func
(
self
BlockBy
)
Sort
(
blocks
Blocks
)
{
bs
:=
blockSorter
{
blocks
:
blocks
,
by
:
self
,
}
sort
.
Sort
(
bs
)
}
type
blockSorter
struct
{
blocks
Blocks
by
func
(
b1
,
b2
*
Block
)
bool
}
func
(
self
blockSorter
)
Len
()
int
{
return
len
(
self
.
blocks
)
}
func
(
self
blockSorter
)
Swap
(
i
,
j
int
)
{
self
.
blocks
[
i
],
self
.
blocks
[
j
]
=
self
.
blocks
[
j
],
self
.
blocks
[
i
]
}
func
(
self
blockSorter
)
Less
(
i
,
j
int
)
bool
{
return
self
.
by
(
self
.
blocks
[
i
],
self
.
blocks
[
j
])
}
func
Number
(
b1
,
b2
*
Block
)
bool
{
return
b1
.
Number
.
Cmp
(
b2
.
Number
)
<
0
}
type
Block
struct
{
type
Block
struct
{
// Hash to the previous block
// Hash to the previous block
PrevHash
[]
byte
PrevHash
ethutil
.
Bytes
// Uncles of this block
// Uncles of this block
Uncles
Blocks
Uncles
Blocks
UncleSha
[]
byte
UncleSha
[]
byte
...
@@ -68,7 +92,7 @@ type Block struct {
...
@@ -68,7 +92,7 @@ type Block struct {
// Extra data
// Extra data
Extra
string
Extra
string
// Block Nonce for verification
// Block Nonce for verification
Nonce
[]
byte
Nonce
ethutil
.
Bytes
// List of transactions and/or contracts
// List of transactions and/or contracts
transactions
[]
*
Transaction
transactions
[]
*
Transaction
receipts
[]
*
Receipt
receipts
[]
*
Receipt
...
@@ -117,8 +141,9 @@ func CreateBlock(root interface{},
...
@@ -117,8 +141,9 @@ func CreateBlock(root interface{},
}
}
// Returns a hash of the block
// Returns a hash of the block
func
(
block
*
Block
)
Hash
()
[]
byte
{
func
(
block
*
Block
)
Hash
()
ethutil
.
Bytes
{
return
ethcrypto
.
Sha3Bin
(
block
.
Value
()
.
Encode
())
return
ethcrypto
.
Sha3Bin
(
ethutil
.
NewValue
(
block
.
header
())
.
Encode
())
//return ethcrypto.Sha3Bin(block.Value().Encode())
}
}
func
(
block
*
Block
)
HashNoNonce
()
[]
byte
{
func
(
block
*
Block
)
HashNoNonce
()
[]
byte
{
...
...
ethchain/block_chain.go
View file @
33a0dec8
...
@@ -58,24 +58,20 @@ func (bc *BlockChain) NewBlock(coinbase []byte) *Block {
...
@@ -58,24 +58,20 @@ func (bc *BlockChain) NewBlock(coinbase []byte) *Block {
block
.
MinGasPrice
=
big
.
NewInt
(
10000000000000
)
block
.
MinGasPrice
=
big
.
NewInt
(
10000000000000
)
if
bc
.
CurrentBlock
!=
nil
{
parent
:=
bc
.
CurrentBlock
var
mul
*
big
.
Int
if
parent
!=
nil
{
if
block
.
Time
<
lastBlockTime
+
5
{
diff
:=
new
(
big
.
Int
)
mul
=
big
.
NewInt
(
1
)
adjust
:=
new
(
big
.
Int
)
.
Rsh
(
parent
.
Difficulty
,
10
)
if
block
.
Time
>=
lastBlockTime
+
5
{
diff
.
Sub
(
parent
.
Difficulty
,
adjust
)
}
else
{
}
else
{
mul
=
big
.
NewInt
(
-
1
)
diff
.
Add
(
parent
.
Difficulty
,
adjust
)
}
}
diff
:=
new
(
big
.
Int
)
diff
.
Add
(
diff
,
bc
.
CurrentBlock
.
Difficulty
)
diff
.
Div
(
diff
,
big
.
NewInt
(
1024
))
diff
.
Mul
(
diff
,
mul
)
diff
.
Add
(
diff
,
bc
.
CurrentBlock
.
Difficulty
)
block
.
Difficulty
=
diff
block
.
Difficulty
=
diff
block
.
Number
=
new
(
big
.
Int
)
.
Add
(
bc
.
CurrentBlock
.
Number
,
ethutil
.
Big1
)
block
.
Number
=
new
(
big
.
Int
)
.
Add
(
bc
.
CurrentBlock
.
Number
,
ethutil
.
Big1
)
block
.
GasLimit
=
block
.
CalcGasLimit
(
bc
.
CurrentBlock
)
block
.
GasLimit
=
block
.
CalcGasLimit
(
bc
.
CurrentBlock
)
}
}
return
block
return
block
...
@@ -159,6 +155,9 @@ func (bc *BlockChain) setLastBlock() {
...
@@ -159,6 +155,9 @@ func (bc *BlockChain) setLastBlock() {
bc
.
LastBlockHash
=
block
.
Hash
()
bc
.
LastBlockHash
=
block
.
Hash
()
bc
.
LastBlockNumber
=
block
.
Number
.
Uint64
()
bc
.
LastBlockNumber
=
block
.
Number
.
Uint64
()
if
bc
.
LastBlockNumber
==
0
{
bc
.
genesisBlock
=
block
}
}
else
{
}
else
{
AddTestNetFunds
(
bc
.
genesisBlock
)
AddTestNetFunds
(
bc
.
genesisBlock
)
...
...
ethchain/state_manager.go
View file @
33a0dec8
...
@@ -217,13 +217,13 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
...
@@ -217,13 +217,13 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
return
err
return
err
}
}
// I'm not sure, but I don't know if there should be thrown
// any errors at this time.
if
err
=
sm
.
AccumelateRewards
(
state
,
block
,
parent
);
err
!=
nil
{
if
err
=
sm
.
AccumelateRewards
(
state
,
block
,
parent
);
err
!=
nil
{
statelogger
.
Errorln
(
"Error accumulating reward"
,
err
)
statelogger
.
Errorln
(
"Error accumulating reward"
,
err
)
return
err
return
err
}
}
state
.
Update
()
if
!
block
.
State
()
.
Cmp
(
state
)
{
if
!
block
.
State
()
.
Cmp
(
state
)
{
err
=
fmt
.
Errorf
(
"Invalid merkle root.
\n
rec: %x
\n
is: %x"
,
block
.
State
()
.
Trie
.
Root
,
state
.
Trie
.
Root
)
err
=
fmt
.
Errorf
(
"Invalid merkle root.
\n
rec: %x
\n
is: %x"
,
block
.
State
()
.
Trie
.
Root
,
state
.
Trie
.
Root
)
return
return
...
@@ -335,7 +335,7 @@ func (sm *StateManager) ValidateBlock(block *Block) error {
...
@@ -335,7 +335,7 @@ func (sm *StateManager) ValidateBlock(block *Block) error {
}
}
func
(
sm
*
StateManager
)
AccumelateRewards
(
state
*
ethstate
.
State
,
block
,
parent
*
Block
)
error
{
func
(
sm
*
StateManager
)
AccumelateRewards
(
state
*
ethstate
.
State
,
block
,
parent
*
Block
)
error
{
reward
:=
new
(
big
.
Int
)
reward
:=
new
(
big
.
Int
)
.
Set
(
BlockReward
)
knownUncles
:=
ethutil
.
Set
(
parent
.
Uncles
)
knownUncles
:=
ethutil
.
Set
(
parent
.
Uncles
)
nonces
:=
ethutil
.
NewSet
(
block
.
Nonce
)
nonces
:=
ethutil
.
NewSet
(
block
.
Nonce
)
...
@@ -358,6 +358,8 @@ func (sm *StateManager) AccumelateRewards(state *ethstate.State, block, parent *
...
@@ -358,6 +358,8 @@ func (sm *StateManager) AccumelateRewards(state *ethstate.State, block, parent *
return
UncleError
(
"Uncle in chain"
)
return
UncleError
(
"Uncle in chain"
)
}
}
nonces
.
Insert
(
uncle
.
Nonce
)
r
:=
new
(
big
.
Int
)
r
:=
new
(
big
.
Int
)
r
.
Mul
(
BlockReward
,
big
.
NewInt
(
15
))
.
Div
(
r
,
big
.
NewInt
(
16
))
r
.
Mul
(
BlockReward
,
big
.
NewInt
(
15
))
.
Div
(
r
,
big
.
NewInt
(
16
))
...
...
ethstate/dump.go
View file @
33a0dec8
...
@@ -28,7 +28,7 @@ func (self *State) Dump() []byte {
...
@@ -28,7 +28,7 @@ func (self *State) Dump() []byte {
self
.
Trie
.
NewIterator
()
.
Each
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
self
.
Trie
.
NewIterator
()
.
Each
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
stateObject
:=
NewStateObjectFromBytes
([]
byte
(
key
),
value
.
Bytes
())
stateObject
:=
NewStateObjectFromBytes
([]
byte
(
key
),
value
.
Bytes
())
account
:=
Account
{
Balance
:
stateObject
.
Balance
.
String
(),
Nonce
:
stateObject
.
Nonce
,
CodeHash
:
ethutil
.
Bytes2Hex
(
stateObject
.
C
odeHash
)}
account
:=
Account
{
Balance
:
stateObject
.
Balance
.
String
(),
Nonce
:
stateObject
.
Nonce
,
CodeHash
:
ethutil
.
Bytes2Hex
(
stateObject
.
c
odeHash
)}
account
.
Storage
=
make
(
map
[
string
]
string
)
account
.
Storage
=
make
(
map
[
string
]
string
)
stateObject
.
EachStorage
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
stateObject
.
EachStorage
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
...
...
ethstate/state.go
View file @
33a0dec8
...
@@ -3,7 +3,6 @@ package ethstate
...
@@ -3,7 +3,6 @@ package ethstate
import
(
import
(
"math/big"
"math/big"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
...
@@ -66,7 +65,9 @@ func (self *State) GetCode(addr []byte) []byte {
...
@@ -66,7 +65,9 @@ func (self *State) GetCode(addr []byte) []byte {
func
(
self
*
State
)
UpdateStateObject
(
stateObject
*
StateObject
)
{
func
(
self
*
State
)
UpdateStateObject
(
stateObject
*
StateObject
)
{
addr
:=
stateObject
.
Address
()
addr
:=
stateObject
.
Address
()
ethutil
.
Config
.
Db
.
Put
(
ethcrypto
.
Sha3Bin
(
stateObject
.
Code
),
stateObject
.
Code
)
if
len
(
stateObject
.
CodeHash
())
>
0
{
ethutil
.
Config
.
Db
.
Put
(
stateObject
.
CodeHash
(),
stateObject
.
Code
)
}
self
.
Trie
.
Update
(
string
(
addr
),
string
(
stateObject
.
RlpEncode
()))
self
.
Trie
.
Update
(
string
(
addr
),
string
(
stateObject
.
RlpEncode
()))
}
}
...
...
ethstate/state_object.go
View file @
33a0dec8
...
@@ -32,7 +32,7 @@ type StateObject struct {
...
@@ -32,7 +32,7 @@ type StateObject struct {
address
[]
byte
address
[]
byte
// Shared attributes
// Shared attributes
Balance
*
big
.
Int
Balance
*
big
.
Int
C
odeHash
[]
byte
c
odeHash
[]
byte
Nonce
uint64
Nonce
uint64
// Contract related attributes
// Contract related attributes
State
*
State
State
*
State
...
@@ -236,7 +236,7 @@ func (self *StateObject) RefundGas(gas, price *big.Int) {
...
@@ -236,7 +236,7 @@ func (self *StateObject) RefundGas(gas, price *big.Int) {
func
(
self
*
StateObject
)
Copy
()
*
StateObject
{
func
(
self
*
StateObject
)
Copy
()
*
StateObject
{
stateObject
:=
NewStateObject
(
self
.
Address
())
stateObject
:=
NewStateObject
(
self
.
Address
())
stateObject
.
Balance
.
Set
(
self
.
Balance
)
stateObject
.
Balance
.
Set
(
self
.
Balance
)
stateObject
.
CodeHash
=
ethutil
.
CopyBytes
(
self
.
C
odeHash
)
stateObject
.
codeHash
=
ethutil
.
CopyBytes
(
self
.
c
odeHash
)
stateObject
.
Nonce
=
self
.
Nonce
stateObject
.
Nonce
=
self
.
Nonce
if
self
.
State
!=
nil
{
if
self
.
State
!=
nil
{
stateObject
.
State
=
self
.
State
.
Copy
()
stateObject
.
State
=
self
.
State
.
Copy
()
...
@@ -297,12 +297,17 @@ func (c *StateObject) RlpEncode() []byte {
...
@@ -297,12 +297,17 @@ func (c *StateObject) RlpEncode() []byte {
}
else
{
}
else
{
root
=
""
root
=
""
}
}
return
ethutil
.
Encode
([]
interface
{}{
c
.
Nonce
,
c
.
Balance
,
root
,
c
.
CodeHash
()})
}
func
(
c
*
StateObject
)
CodeHash
()
ethutil
.
Bytes
{
var
codeHash
[]
byte
var
codeHash
[]
byte
if
len
(
c
.
Code
)
>
0
{
if
len
(
c
.
Code
)
>
0
{
codeHash
=
ethcrypto
.
Sha3Bin
(
c
.
Code
)
codeHash
=
ethcrypto
.
Sha3Bin
(
c
.
Code
)
}
}
return
ethutil
.
Encode
([]
interface
{}{
c
.
Nonce
,
c
.
Balance
,
root
,
codeHash
})
return
codeHash
}
}
func
(
c
*
StateObject
)
RlpDecode
(
data
[]
byte
)
{
func
(
c
*
StateObject
)
RlpDecode
(
data
[]
byte
)
{
...
@@ -314,9 +319,9 @@ func (c *StateObject) RlpDecode(data []byte) {
...
@@ -314,9 +319,9 @@ func (c *StateObject) RlpDecode(data []byte) {
c
.
storage
=
make
(
map
[
string
]
*
ethutil
.
Value
)
c
.
storage
=
make
(
map
[
string
]
*
ethutil
.
Value
)
c
.
gasPool
=
new
(
big
.
Int
)
c
.
gasPool
=
new
(
big
.
Int
)
c
.
C
odeHash
=
decoder
.
Get
(
3
)
.
Bytes
()
c
.
c
odeHash
=
decoder
.
Get
(
3
)
.
Bytes
()
c
.
Code
,
_
=
ethutil
.
Config
.
Db
.
Get
(
c
.
C
odeHash
)
c
.
Code
,
_
=
ethutil
.
Config
.
Db
.
Get
(
c
.
c
odeHash
)
}
}
// Storage change object. Used by the manifest for notifying changes to
// Storage change object. Used by the manifest for notifying changes to
...
...
ethutil/bytes.go
View file @
33a0dec8
...
@@ -9,6 +9,22 @@ import (
...
@@ -9,6 +9,22 @@ import (
"strings"
"strings"
)
)
type
Bytes
[]
byte
func
(
self
Bytes
)
String
()
string
{
return
string
(
self
)
}
func
DeleteFromByteSlice
(
s
[][]
byte
,
hash
[]
byte
)
[][]
byte
{
for
i
,
h
:=
range
s
{
if
bytes
.
Compare
(
h
,
hash
)
==
0
{
return
append
(
s
[
:
i
],
s
[
i
+
1
:
]
...
)
}
}
return
s
}
// Number to bytes
// Number to bytes
//
//
// Returns the number in bytes with the specified base
// Returns the number in bytes with the specified base
...
...
ethutil/rlp.go
View file @
33a0dec8
...
@@ -124,6 +124,8 @@ func Encode(object interface{}) []byte {
...
@@ -124,6 +124,8 @@ func Encode(object interface{}) []byte {
}
else
{
}
else
{
buff
.
Write
(
Encode
(
t
.
Bytes
()))
buff
.
Write
(
Encode
(
t
.
Bytes
()))
}
}
case
Bytes
:
buff
.
Write
(
Encode
([]
byte
(
t
)))
case
[]
byte
:
case
[]
byte
:
if
len
(
t
)
==
1
&&
t
[
0
]
<=
0x7f
{
if
len
(
t
)
==
1
&&
t
[
0
]
<=
0x7f
{
buff
.
Write
(
t
)
buff
.
Write
(
t
)
...
...
ethutil/set.go
View file @
33a0dec8
...
@@ -4,9 +4,13 @@ type Settable interface {
...
@@ -4,9 +4,13 @@ type Settable interface {
AsSet
()
UniqueSet
AsSet
()
UniqueSet
}
}
type
UniqueSet
map
[
interface
{}]
struct
{}
type
Stringable
interface
{
String
()
string
}
type
UniqueSet
map
[
string
]
struct
{}
func
NewSet
(
v
...
interface
{}
)
UniqueSet
{
func
NewSet
(
v
...
Stringable
)
UniqueSet
{
set
:=
make
(
UniqueSet
)
set
:=
make
(
UniqueSet
)
for
_
,
val
:=
range
v
{
for
_
,
val
:=
range
v
{
set
.
Insert
(
val
)
set
.
Insert
(
val
)
...
@@ -15,14 +19,14 @@ func NewSet(v ...interface{}) UniqueSet {
...
@@ -15,14 +19,14 @@ func NewSet(v ...interface{}) UniqueSet {
return
set
return
set
}
}
func
(
self
UniqueSet
)
Insert
(
k
interface
{}
)
UniqueSet
{
func
(
self
UniqueSet
)
Insert
(
k
Stringable
)
UniqueSet
{
self
[
k
]
=
struct
{}{}
self
[
k
.
String
()
]
=
struct
{}{}
return
self
return
self
}
}
func
(
self
UniqueSet
)
Include
(
k
interface
{}
)
bool
{
func
(
self
UniqueSet
)
Include
(
k
Stringable
)
bool
{
_
,
ok
:=
self
[
k
]
_
,
ok
:=
self
[
k
.
String
()
]
return
ok
return
ok
}
}
...
...
peer.go
View file @
33a0dec8
...
@@ -24,7 +24,7 @@ const (
...
@@ -24,7 +24,7 @@ const (
// The size of the output buffer for writing messages
// The size of the output buffer for writing messages
outputBufferSize
=
50
outputBufferSize
=
50
// Current protocol version
// Current protocol version
ProtocolVersion
=
28
ProtocolVersion
=
32
// Current P2P version
// Current P2P version
P2PVersion
=
0
P2PVersion
=
0
// Interval for ping/pong message
// Interval for ping/pong message
...
@@ -276,6 +276,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
...
@@ -276,6 +276,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
return
return
}
}
}
else
{
}
else
{
/*
if !p.statusKnown {
if !p.statusKnown {
switch msg.Type {
switch msg.Type {
case ethwire.MsgStatusTy: // Ok
case ethwire.MsgStatusTy: // Ok
...
@@ -283,6 +284,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
...
@@ -283,6 +284,7 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
return
return
}
}
}
}
*/
}
}
peerlogger
.
DebugDetailf
(
"(%v) <= %v %v
\n
"
,
p
.
conn
.
RemoteAddr
(),
msg
.
Type
,
msg
.
Data
)
peerlogger
.
DebugDetailf
(
"(%v) <= %v %v
\n
"
,
p
.
conn
.
RemoteAddr
(),
msg
.
Type
,
msg
.
Data
)
...
@@ -488,19 +490,25 @@ func (p *Peer) HandleInbound() {
...
@@ -488,19 +490,25 @@ func (p *Peer) HandleInbound() {
it
:=
msg
.
Data
.
NewIterator
()
it
:=
msg
.
Data
.
NewIterator
()
for
it
.
Next
()
{
for
it
.
Next
()
{
block
:=
ethchain
.
NewBlockFromRlpValue
(
it
.
Value
())
block
:=
ethchain
.
NewBlockFromRlpValue
(
it
.
Value
())
//fmt.Printf("%v %x - %x\n", block.Number, block.Hash()[0:4], block.PrevHash[0:4])
blockPool
.
SetBlock
(
block
,
p
)
blockPool
.
SetBlock
(
block
,
p
)
p
.
lastBlockReceived
=
time
.
Now
()
p
.
lastBlockReceived
=
time
.
Now
()
}
}
linked
:=
blockPool
.
CheckLinkAndProcess
(
func
(
block
*
ethchain
.
Block
)
{
blockPool
.
CheckLinkAndProcess
(
func
(
block
*
ethchain
.
Block
)
{
p
.
ethereum
.
StateManager
()
.
Process
(
block
,
false
)
err
:=
p
.
ethereum
.
StateManager
()
.
Process
(
block
,
false
)
if
err
!=
nil
{
peerlogger
.
Infoln
(
err
)
}
})
})
/*
if !linked {
if !linked {
p.FetchBlocks()
p.FetchBlocks()
}
}
*/
}
}
}
}
}
}
...
@@ -596,20 +604,6 @@ func (p *Peer) Stop() {
...
@@ -596,20 +604,6 @@ func (p *Peer) Stop() {
p
.
ethereum
.
RemovePeer
(
p
)
p
.
ethereum
.
RemovePeer
(
p
)
}
}
/*
func (p *Peer) pushHandshake() error {
pubkey := p.ethereum.KeyManager().PublicKey()
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{
uint32(ProtocolVersion), uint32(0), []byte(p.version), byte(p.caps), p.port, pubkey[1:],
p.ethereum.BlockChain().TD.Uint64(), p.ethereum.BlockChain().CurrentBlock.Hash(),
})
p.QueueMessage(msg)
return nil
}
*/
func
(
p
*
Peer
)
peersMessage
()
*
ethwire
.
Msg
{
func
(
p
*
Peer
)
peersMessage
()
*
ethwire
.
Msg
{
outPeers
:=
make
([]
interface
{},
len
(
p
.
ethereum
.
InOutPeers
()))
outPeers
:=
make
([]
interface
{},
len
(
p
.
ethereum
.
InOutPeers
()))
// Serialise each peer
// Serialise each peer
...
...
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