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
7324176f
Commit
7324176f
authored
Aug 24, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for uncle timestamps and refactor timestamp type
parent
d51d0022
Changes
21
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
380 additions
and
43 deletions
+380
-43
main.go
cmd/evm/main.go
+3
-3
block_processor.go
core/block_processor.go
+13
-7
block_processor_test.go
core/block_processor_test.go
+2
-2
chain_makers.go
core/chain_makers.go
+8
-3
chain_manager.go
core/chain_manager.go
+2
-1
error.go
core/error.go
+4
-3
genesis.go
core/genesis.go
+1
-1
block.go
core/types/block.go
+6
-3
block_test.go
core/types/block_test.go
+1
-1
environment.go
core/vm/environment.go
+1
-1
instructions.go
core/vm/instructions.go
+1
-1
jit_test.go
core/vm/jit_test.go
+1
-1
vm.go
core/vm/vm.go
+1
-1
vm_env.go
core/vm_env.go
+1
-1
handler.go
eth/handler.go
+1
-1
worker.go
miner/worker.go
+5
-5
block_test.go
tests/block_test.go
+7
-0
block_test_util.go
tests/block_test_util.go
+3
-3
bcUncleTest.json
tests/files/BlockchainTests/bcUncleTest.json
+314
-1
util.go
tests/util.go
+3
-3
types.go
xeth/types.go
+2
-1
No files found.
cmd/evm/main.go
View file @
7324176f
...
@@ -166,7 +166,7 @@ type VMEnv struct {
...
@@ -166,7 +166,7 @@ type VMEnv struct {
depth
int
depth
int
Gas
*
big
.
Int
Gas
*
big
.
Int
time
uint64
time
*
big
.
Int
logs
[]
vm
.
StructLog
logs
[]
vm
.
StructLog
}
}
...
@@ -175,7 +175,7 @@ func NewEnv(state *state.StateDB, transactor common.Address, value *big.Int) *VM
...
@@ -175,7 +175,7 @@ func NewEnv(state *state.StateDB, transactor common.Address, value *big.Int) *VM
state
:
state
,
state
:
state
,
transactor
:
&
transactor
,
transactor
:
&
transactor
,
value
:
value
,
value
:
value
,
time
:
uint64
(
time
.
Now
()
.
Unix
()),
time
:
big
.
NewInt
(
time
.
Now
()
.
Unix
()),
}
}
}
}
...
@@ -183,7 +183,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
...
@@ -183,7 +183,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
func
(
self
*
VMEnv
)
Origin
()
common
.
Address
{
return
*
self
.
transactor
}
func
(
self
*
VMEnv
)
Origin
()
common
.
Address
{
return
*
self
.
transactor
}
func
(
self
*
VMEnv
)
BlockNumber
()
*
big
.
Int
{
return
common
.
Big0
}
func
(
self
*
VMEnv
)
BlockNumber
()
*
big
.
Int
{
return
common
.
Big0
}
func
(
self
*
VMEnv
)
Coinbase
()
common
.
Address
{
return
*
self
.
transactor
}
func
(
self
*
VMEnv
)
Coinbase
()
common
.
Address
{
return
*
self
.
transactor
}
func
(
self
*
VMEnv
)
Time
()
uint64
{
return
self
.
time
}
func
(
self
*
VMEnv
)
Time
()
*
big
.
Int
{
return
self
.
time
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
common
.
Big1
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
common
.
Big1
}
func
(
self
*
VMEnv
)
BlockHash
()
[]
byte
{
return
make
([]
byte
,
32
)
}
func
(
self
*
VMEnv
)
BlockHash
()
[]
byte
{
return
make
([]
byte
,
32
)
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
value
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
value
}
...
...
core/block_processor.go
View file @
7324176f
...
@@ -203,7 +203,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
...
@@ -203,7 +203,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
txs
:=
block
.
Transactions
()
txs
:=
block
.
Transactions
()
// Block validation
// Block validation
if
err
=
ValidateHeader
(
sm
.
Pow
,
header
,
parent
,
false
);
err
!=
nil
{
if
err
=
ValidateHeader
(
sm
.
Pow
,
header
,
parent
,
false
,
false
);
err
!=
nil
{
return
return
}
}
...
@@ -327,7 +327,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
...
@@ -327,7 +327,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
return
UncleError
(
"uncle[%d](%x)'s parent is not ancestor (%x)"
,
i
,
hash
[
:
4
],
uncle
.
ParentHash
[
0
:
4
])
return
UncleError
(
"uncle[%d](%x)'s parent is not ancestor (%x)"
,
i
,
hash
[
:
4
],
uncle
.
ParentHash
[
0
:
4
])
}
}
if
err
:=
ValidateHeader
(
sm
.
Pow
,
uncle
,
ancestors
[
uncle
.
ParentHash
],
true
);
err
!=
nil
{
if
err
:=
ValidateHeader
(
sm
.
Pow
,
uncle
,
ancestors
[
uncle
.
ParentHash
],
true
,
true
);
err
!=
nil
{
return
ValidationError
(
fmt
.
Sprintf
(
"uncle[%d](%x) header invalid: %v"
,
i
,
hash
[
:
4
],
err
))
return
ValidationError
(
fmt
.
Sprintf
(
"uncle[%d](%x) header invalid: %v"
,
i
,
hash
[
:
4
],
err
))
}
}
}
}
...
@@ -358,19 +358,25 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
...
@@ -358,19 +358,25 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
// See YP section 4.3.4. "Block Header Validity"
// See YP section 4.3.4. "Block Header Validity"
// Validates a block. Returns an error if the block is invalid.
// Validates a block. Returns an error if the block is invalid.
func
ValidateHeader
(
pow
pow
.
PoW
,
block
*
types
.
Header
,
parent
*
types
.
Block
,
checkPow
bool
)
error
{
func
ValidateHeader
(
pow
pow
.
PoW
,
block
*
types
.
Header
,
parent
*
types
.
Block
,
checkPow
,
uncle
bool
)
error
{
if
big
.
NewInt
(
int64
(
len
(
block
.
Extra
)))
.
Cmp
(
params
.
MaximumExtraDataSize
)
==
1
{
if
big
.
NewInt
(
int64
(
len
(
block
.
Extra
)))
.
Cmp
(
params
.
MaximumExtraDataSize
)
==
1
{
return
fmt
.
Errorf
(
"Block extra data too long (%d)"
,
len
(
block
.
Extra
))
return
fmt
.
Errorf
(
"Block extra data too long (%d)"
,
len
(
block
.
Extra
))
}
}
if
block
.
Time
>
uint64
(
time
.
Now
()
.
Unix
())
{
if
uncle
{
return
BlockFutureErr
if
block
.
Time
.
Cmp
(
common
.
MaxBig
)
==
1
{
return
BlockTSTooBigErr
}
}
else
{
if
block
.
Time
.
Cmp
(
big
.
NewInt
(
time
.
Now
()
.
Unix
()))
==
1
{
return
BlockFutureErr
}
}
}
if
block
.
Time
<=
parent
.
Time
()
{
if
block
.
Time
.
Cmp
(
parent
.
Time
())
!=
1
{
return
BlockEqualTSErr
return
BlockEqualTSErr
}
}
expd
:=
CalcDifficulty
(
block
.
Time
,
parent
.
Time
(),
parent
.
Number
(),
parent
.
Difficulty
())
expd
:=
CalcDifficulty
(
block
.
Time
.
Uint64
(),
parent
.
Time
()
.
Uint64
(),
parent
.
Number
(),
parent
.
Difficulty
())
if
expd
.
Cmp
(
block
.
Difficulty
)
!=
0
{
if
expd
.
Cmp
(
block
.
Difficulty
)
!=
0
{
return
fmt
.
Errorf
(
"Difficulty check failed for block %v, %v"
,
block
.
Difficulty
,
expd
)
return
fmt
.
Errorf
(
"Difficulty check failed for block %v, %v"
,
block
.
Difficulty
,
expd
)
}
}
...
...
core/block_processor_test.go
View file @
7324176f
...
@@ -48,13 +48,13 @@ func TestNumber(t *testing.T) {
...
@@ -48,13 +48,13 @@ func TestNumber(t *testing.T) {
statedb
:=
state
.
New
(
chain
.
Genesis
()
.
Root
(),
chain
.
chainDb
)
statedb
:=
state
.
New
(
chain
.
Genesis
()
.
Root
(),
chain
.
chainDb
)
header
:=
makeHeader
(
chain
.
Genesis
(),
statedb
)
header
:=
makeHeader
(
chain
.
Genesis
(),
statedb
)
header
.
Number
=
big
.
NewInt
(
3
)
header
.
Number
=
big
.
NewInt
(
3
)
err
:=
ValidateHeader
(
pow
,
header
,
chain
.
Genesis
(),
false
)
err
:=
ValidateHeader
(
pow
,
header
,
chain
.
Genesis
(),
false
,
false
)
if
err
!=
BlockNumberErr
{
if
err
!=
BlockNumberErr
{
t
.
Errorf
(
"expected block number error, got %q"
,
err
)
t
.
Errorf
(
"expected block number error, got %q"
,
err
)
}
}
header
=
makeHeader
(
chain
.
Genesis
(),
statedb
)
header
=
makeHeader
(
chain
.
Genesis
(),
statedb
)
err
=
ValidateHeader
(
pow
,
header
,
chain
.
Genesis
(),
false
)
err
=
ValidateHeader
(
pow
,
header
,
chain
.
Genesis
(),
false
,
false
)
if
err
==
BlockNumberErr
{
if
err
==
BlockNumberErr
{
t
.
Errorf
(
"didn't expect block number error"
)
t
.
Errorf
(
"didn't expect block number error"
)
}
}
...
...
core/chain_makers.go
View file @
7324176f
...
@@ -166,16 +166,21 @@ func GenerateChain(parent *types.Block, db common.Database, n int, gen func(int,
...
@@ -166,16 +166,21 @@ func GenerateChain(parent *types.Block, db common.Database, n int, gen func(int,
}
}
func
makeHeader
(
parent
*
types
.
Block
,
state
*
state
.
StateDB
)
*
types
.
Header
{
func
makeHeader
(
parent
*
types
.
Block
,
state
*
state
.
StateDB
)
*
types
.
Header
{
time
:=
parent
.
Time
()
+
10
// block time is fixed at 10 seconds
var
time
*
big
.
Int
if
parent
.
Time
()
==
nil
{
time
=
big
.
NewInt
(
10
)
}
else
{
time
=
new
(
big
.
Int
)
.
Add
(
parent
.
Time
(),
big
.
NewInt
(
10
))
// block time is fixed at 10 seconds
}
return
&
types
.
Header
{
return
&
types
.
Header
{
Root
:
state
.
Root
(),
Root
:
state
.
Root
(),
ParentHash
:
parent
.
Hash
(),
ParentHash
:
parent
.
Hash
(),
Coinbase
:
parent
.
Coinbase
(),
Coinbase
:
parent
.
Coinbase
(),
Difficulty
:
CalcDifficulty
(
time
,
parent
.
Time
(),
parent
.
Number
(),
parent
.
Difficulty
()),
Difficulty
:
CalcDifficulty
(
time
.
Uint64
(),
new
(
big
.
Int
)
.
Sub
(
time
,
big
.
NewInt
(
10
))
.
Uint64
(),
parent
.
Number
(),
parent
.
Difficulty
()),
GasLimit
:
CalcGasLimit
(
parent
),
GasLimit
:
CalcGasLimit
(
parent
),
GasUsed
:
new
(
big
.
Int
),
GasUsed
:
new
(
big
.
Int
),
Number
:
new
(
big
.
Int
)
.
Add
(
parent
.
Number
(),
common
.
Big1
),
Number
:
new
(
big
.
Int
)
.
Add
(
parent
.
Number
(),
common
.
Big1
),
Time
:
uint64
(
time
)
,
Time
:
time
,
}
}
}
}
...
...
core/chain_manager.go
View file @
7324176f
...
@@ -596,7 +596,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
...
@@ -596,7 +596,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
// Allow up to MaxFuture second in the future blocks. If this limit
// Allow up to MaxFuture second in the future blocks. If this limit
// is exceeded the chain is discarded and processed at a later time
// is exceeded the chain is discarded and processed at a later time
// if given.
// if given.
if
max
:=
uint64
(
time
.
Now
()
.
Unix
())
+
maxTimeFutureBlocks
;
block
.
Time
()
>
max
{
max
:=
big
.
NewInt
(
time
.
Now
()
.
Unix
()
+
maxTimeFutureBlocks
)
if
block
.
Time
()
.
Cmp
(
max
)
==
1
{
return
i
,
fmt
.
Errorf
(
"%v: BlockFutureErr, %v > %v"
,
BlockFutureErr
,
block
.
Time
(),
max
)
return
i
,
fmt
.
Errorf
(
"%v: BlockFutureErr, %v > %v"
,
BlockFutureErr
,
block
.
Time
(),
max
)
}
}
...
...
core/error.go
View file @
7324176f
...
@@ -25,9 +25,10 @@ import (
...
@@ -25,9 +25,10 @@ import (
)
)
var
(
var
(
BlockNumberErr
=
errors
.
New
(
"block number invalid"
)
BlockNumberErr
=
errors
.
New
(
"block number invalid"
)
BlockFutureErr
=
errors
.
New
(
"block time is in the future"
)
BlockFutureErr
=
errors
.
New
(
"block time is in the future"
)
BlockEqualTSErr
=
errors
.
New
(
"block time stamp equal to previous"
)
BlockTSTooBigErr
=
errors
.
New
(
"block time too big"
)
BlockEqualTSErr
=
errors
.
New
(
"block time stamp equal to previous"
)
)
)
// Parent error. In case a parent is unknown this error will be thrown
// Parent error. In case a parent is unknown this error will be thrown
...
...
core/genesis.go
View file @
7324176f
...
@@ -73,7 +73,7 @@ func WriteGenesisBlock(chainDb common.Database, reader io.Reader) (*types.Block,
...
@@ -73,7 +73,7 @@ func WriteGenesisBlock(chainDb common.Database, reader io.Reader) (*types.Block,
difficulty
:=
common
.
String2Big
(
genesis
.
Difficulty
)
difficulty
:=
common
.
String2Big
(
genesis
.
Difficulty
)
block
:=
types
.
NewBlock
(
&
types
.
Header
{
block
:=
types
.
NewBlock
(
&
types
.
Header
{
Nonce
:
types
.
EncodeNonce
(
common
.
String2Big
(
genesis
.
Nonce
)
.
Uint64
()),
Nonce
:
types
.
EncodeNonce
(
common
.
String2Big
(
genesis
.
Nonce
)
.
Uint64
()),
Time
:
common
.
String2Big
(
genesis
.
Timestamp
)
.
Uint64
()
,
Time
:
common
.
String2Big
(
genesis
.
Timestamp
),
ParentHash
:
common
.
HexToHash
(
genesis
.
ParentHash
),
ParentHash
:
common
.
HexToHash
(
genesis
.
ParentHash
),
Extra
:
common
.
FromHex
(
genesis
.
ExtraData
),
Extra
:
common
.
FromHex
(
genesis
.
ExtraData
),
GasLimit
:
common
.
String2Big
(
genesis
.
GasLimit
),
GasLimit
:
common
.
String2Big
(
genesis
.
GasLimit
),
...
...
core/types/block.go
View file @
7324176f
...
@@ -60,7 +60,7 @@ type Header struct {
...
@@ -60,7 +60,7 @@ type Header struct {
Number
*
big
.
Int
// The block number
Number
*
big
.
Int
// The block number
GasLimit
*
big
.
Int
// Gas limit
GasLimit
*
big
.
Int
// Gas limit
GasUsed
*
big
.
Int
// Gas used
GasUsed
*
big
.
Int
// Gas used
Time
uint64
// Creation time
Time
*
big
.
Int
// Creation time
Extra
[]
byte
// Extra data
Extra
[]
byte
// Extra data
MixDigest
common
.
Hash
// for quick difficulty verification
MixDigest
common
.
Hash
// for quick difficulty verification
Nonce
BlockNonce
Nonce
BlockNonce
...
@@ -94,7 +94,7 @@ func (h *Header) UnmarshalJSON(data []byte) error {
...
@@ -94,7 +94,7 @@ func (h *Header) UnmarshalJSON(data []byte) error {
Coinbase
string
Coinbase
string
Difficulty
string
Difficulty
string
GasLimit
string
GasLimit
string
Time
uint64
Time
*
big
.
Int
Extra
string
Extra
string
}
}
dec
:=
json
.
NewDecoder
(
bytes
.
NewReader
(
data
))
dec
:=
json
.
NewDecoder
(
bytes
.
NewReader
(
data
))
...
@@ -210,6 +210,9 @@ func NewBlockWithHeader(header *Header) *Block {
...
@@ -210,6 +210,9 @@ func NewBlockWithHeader(header *Header) *Block {
func
copyHeader
(
h
*
Header
)
*
Header
{
func
copyHeader
(
h
*
Header
)
*
Header
{
cpy
:=
*
h
cpy
:=
*
h
if
cpy
.
Time
=
new
(
big
.
Int
);
h
.
Time
!=
nil
{
cpy
.
Time
.
Set
(
h
.
Time
)
}
if
cpy
.
Difficulty
=
new
(
big
.
Int
);
h
.
Difficulty
!=
nil
{
if
cpy
.
Difficulty
=
new
(
big
.
Int
);
h
.
Difficulty
!=
nil
{
cpy
.
Difficulty
.
Set
(
h
.
Difficulty
)
cpy
.
Difficulty
.
Set
(
h
.
Difficulty
)
}
}
...
@@ -301,13 +304,13 @@ func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number)
...
@@ -301,13 +304,13 @@ func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number)
func
(
b
*
Block
)
GasLimit
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
GasLimit
)
}
func
(
b
*
Block
)
GasLimit
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
GasLimit
)
}
func
(
b
*
Block
)
GasUsed
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
GasUsed
)
}
func
(
b
*
Block
)
GasUsed
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
GasUsed
)
}
func
(
b
*
Block
)
Difficulty
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
Difficulty
)
}
func
(
b
*
Block
)
Difficulty
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
Difficulty
)
}
func
(
b
*
Block
)
Time
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
Set
(
b
.
header
.
Time
)
}
func
(
b
*
Block
)
NumberU64
()
uint64
{
return
b
.
header
.
Number
.
Uint64
()
}
func
(
b
*
Block
)
NumberU64
()
uint64
{
return
b
.
header
.
Number
.
Uint64
()
}
func
(
b
*
Block
)
MixDigest
()
common
.
Hash
{
return
b
.
header
.
MixDigest
}
func
(
b
*
Block
)
MixDigest
()
common
.
Hash
{
return
b
.
header
.
MixDigest
}
func
(
b
*
Block
)
Nonce
()
uint64
{
return
binary
.
BigEndian
.
Uint64
(
b
.
header
.
Nonce
[
:
])
}
func
(
b
*
Block
)
Nonce
()
uint64
{
return
binary
.
BigEndian
.
Uint64
(
b
.
header
.
Nonce
[
:
])
}
func
(
b
*
Block
)
Bloom
()
Bloom
{
return
b
.
header
.
Bloom
}
func
(
b
*
Block
)
Bloom
()
Bloom
{
return
b
.
header
.
Bloom
}
func
(
b
*
Block
)
Coinbase
()
common
.
Address
{
return
b
.
header
.
Coinbase
}
func
(
b
*
Block
)
Coinbase
()
common
.
Address
{
return
b
.
header
.
Coinbase
}
func
(
b
*
Block
)
Time
()
uint64
{
return
b
.
header
.
Time
}
func
(
b
*
Block
)
Root
()
common
.
Hash
{
return
b
.
header
.
Root
}
func
(
b
*
Block
)
Root
()
common
.
Hash
{
return
b
.
header
.
Root
}
func
(
b
*
Block
)
ParentHash
()
common
.
Hash
{
return
b
.
header
.
ParentHash
}
func
(
b
*
Block
)
ParentHash
()
common
.
Hash
{
return
b
.
header
.
ParentHash
}
func
(
b
*
Block
)
TxHash
()
common
.
Hash
{
return
b
.
header
.
TxHash
}
func
(
b
*
Block
)
TxHash
()
common
.
Hash
{
return
b
.
header
.
TxHash
}
...
...
core/types/block_test.go
View file @
7324176f
...
@@ -47,7 +47,7 @@ func TestBlockEncoding(t *testing.T) {
...
@@ -47,7 +47,7 @@ func TestBlockEncoding(t *testing.T) {
check
(
"Root"
,
block
.
Root
(),
common
.
HexToHash
(
"ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"
))
check
(
"Root"
,
block
.
Root
(),
common
.
HexToHash
(
"ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"
))
check
(
"Hash"
,
block
.
Hash
(),
common
.
HexToHash
(
"0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"
))
check
(
"Hash"
,
block
.
Hash
(),
common
.
HexToHash
(
"0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"
))
check
(
"Nonce"
,
block
.
Nonce
(),
uint64
(
0xa13a5a8c8f2bb1c4
))
check
(
"Nonce"
,
block
.
Nonce
(),
uint64
(
0xa13a5a8c8f2bb1c4
))
check
(
"Time"
,
block
.
Time
(),
uint64
(
1426516743
))
check
(
"Time"
,
block
.
Time
(),
big
.
NewInt
(
1426516743
))
check
(
"Size"
,
block
.
Size
(),
common
.
StorageSize
(
len
(
blockEnc
)))
check
(
"Size"
,
block
.
Size
(),
common
.
StorageSize
(
len
(
blockEnc
)))
tx1
:=
NewTransaction
(
0
,
common
.
HexToAddress
(
"095e7baea6a6c7c4c2dfeb977efac326af552d87"
),
big
.
NewInt
(
10
),
big
.
NewInt
(
50000
),
big
.
NewInt
(
10
),
nil
)
tx1
:=
NewTransaction
(
0
,
common
.
HexToAddress
(
"095e7baea6a6c7c4c2dfeb977efac326af552d87"
),
big
.
NewInt
(
10
),
big
.
NewInt
(
50000
),
big
.
NewInt
(
10
),
nil
)
...
...
core/vm/environment.go
View file @
7324176f
...
@@ -33,7 +33,7 @@ type Environment interface {
...
@@ -33,7 +33,7 @@ type Environment interface {
BlockNumber
()
*
big
.
Int
BlockNumber
()
*
big
.
Int
GetHash
(
n
uint64
)
common
.
Hash
GetHash
(
n
uint64
)
common
.
Hash
Coinbase
()
common
.
Address
Coinbase
()
common
.
Address
Time
()
uint64
Time
()
*
big
.
Int
Difficulty
()
*
big
.
Int
Difficulty
()
*
big
.
Int
GasLimit
()
*
big
.
Int
GasLimit
()
*
big
.
Int
CanTransfer
(
from
Account
,
balance
*
big
.
Int
)
bool
CanTransfer
(
from
Account
,
balance
*
big
.
Int
)
bool
...
...
core/vm/instructions.go
View file @
7324176f
...
@@ -341,7 +341,7 @@ func opCoinbase(instr instruction, env Environment, context *Context, memory *Me
...
@@ -341,7 +341,7 @@ func opCoinbase(instr instruction, env Environment, context *Context, memory *Me
}
}
func
opTimestamp
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opTimestamp
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
stack
.
push
(
U256
(
new
(
big
.
Int
)
.
Set
Uint64
(
env
.
Time
())))
stack
.
push
(
U256
(
new
(
big
.
Int
)
.
Set
(
env
.
Time
())))
}
}
func
opNumber
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opNumber
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
...
...
core/vm/jit_test.go
View file @
7324176f
...
@@ -93,7 +93,7 @@ func (self *Env) StructLogs() []StructLog {
...
@@ -93,7 +93,7 @@ func (self *Env) StructLogs() []StructLog {
//func (self *Env) PrevHash() []byte { return self.parent }
//func (self *Env) PrevHash() []byte { return self.parent }
func
(
self
*
Env
)
Coinbase
()
common
.
Address
{
return
common
.
Address
{}
}
func
(
self
*
Env
)
Coinbase
()
common
.
Address
{
return
common
.
Address
{}
}
func
(
self
*
Env
)
Time
()
uint64
{
return
uint64
(
time
.
Now
()
.
Unix
())
}
func
(
self
*
Env
)
Time
()
*
big
.
Int
{
return
big
.
NewInt
(
time
.
Now
()
.
Unix
())
}
func
(
self
*
Env
)
Difficulty
()
*
big
.
Int
{
return
big
.
NewInt
(
0
)
}
func
(
self
*
Env
)
Difficulty
()
*
big
.
Int
{
return
big
.
NewInt
(
0
)
}
func
(
self
*
Env
)
State
()
*
state
.
StateDB
{
return
nil
}
func
(
self
*
Env
)
State
()
*
state
.
StateDB
{
return
nil
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
...
...
core/vm/vm.go
View file @
7324176f
...
@@ -491,7 +491,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
...
@@ -491,7 +491,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
case
TIMESTAMP
:
case
TIMESTAMP
:
time
:=
self
.
env
.
Time
()
time
:=
self
.
env
.
Time
()
stack
.
push
(
new
(
big
.
Int
)
.
Set
Uint64
(
time
))
stack
.
push
(
new
(
big
.
Int
)
.
Set
(
time
))
case
NUMBER
:
case
NUMBER
:
number
:=
self
.
env
.
BlockNumber
()
number
:=
self
.
env
.
BlockNumber
()
...
...
core/vm_env.go
View file @
7324176f
...
@@ -49,7 +49,7 @@ func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, header *type
...
@@ -49,7 +49,7 @@ func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, header *type
func
(
self
*
VMEnv
)
Origin
()
common
.
Address
{
f
,
_
:=
self
.
msg
.
From
();
return
f
}
func
(
self
*
VMEnv
)
Origin
()
common
.
Address
{
f
,
_
:=
self
.
msg
.
From
();
return
f
}
func
(
self
*
VMEnv
)
BlockNumber
()
*
big
.
Int
{
return
self
.
header
.
Number
}
func
(
self
*
VMEnv
)
BlockNumber
()
*
big
.
Int
{
return
self
.
header
.
Number
}
func
(
self
*
VMEnv
)
Coinbase
()
common
.
Address
{
return
self
.
header
.
Coinbase
}
func
(
self
*
VMEnv
)
Coinbase
()
common
.
Address
{
return
self
.
header
.
Coinbase
}
func
(
self
*
VMEnv
)
Time
()
uint64
{
return
self
.
header
.
Time
}
func
(
self
*
VMEnv
)
Time
()
*
big
.
Int
{
return
self
.
header
.
Time
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
self
.
header
.
Difficulty
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
self
.
header
.
Difficulty
}
func
(
self
*
VMEnv
)
GasLimit
()
*
big
.
Int
{
return
self
.
header
.
GasLimit
}
func
(
self
*
VMEnv
)
GasLimit
()
*
big
.
Int
{
return
self
.
header
.
GasLimit
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
msg
.
Value
()
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
msg
.
Value
()
}
...
...
eth/handler.go
View file @
7324176f
...
@@ -117,7 +117,7 @@ func NewProtocolManager(networkId int, mux *event.TypeMux, txpool txPool, pow po
...
@@ -117,7 +117,7 @@ func NewProtocolManager(networkId int, mux *event.TypeMux, txpool txPool, pow po
manager
.
downloader
=
downloader
.
New
(
manager
.
eventMux
,
manager
.
chainman
.
HasBlock
,
manager
.
chainman
.
GetBlock
,
manager
.
chainman
.
CurrentBlock
,
manager
.
chainman
.
InsertChain
,
manager
.
removePeer
)
manager
.
downloader
=
downloader
.
New
(
manager
.
eventMux
,
manager
.
chainman
.
HasBlock
,
manager
.
chainman
.
GetBlock
,
manager
.
chainman
.
CurrentBlock
,
manager
.
chainman
.
InsertChain
,
manager
.
removePeer
)
validator
:=
func
(
block
*
types
.
Block
,
parent
*
types
.
Block
)
error
{
validator
:=
func
(
block
*
types
.
Block
,
parent
*
types
.
Block
)
error
{
return
core
.
ValidateHeader
(
pow
,
block
.
Header
(),
parent
,
true
)
return
core
.
ValidateHeader
(
pow
,
block
.
Header
(),
parent
,
true
,
false
)
}
}
heighter
:=
func
()
uint64
{
heighter
:=
func
()
uint64
{
return
manager
.
chainman
.
CurrentBlock
()
.
NumberU64
()
return
manager
.
chainman
.
CurrentBlock
()
.
NumberU64
()
...
...
miner/worker.go
View file @
7324176f
...
@@ -278,7 +278,7 @@ func (self *worker) wait() {
...
@@ -278,7 +278,7 @@ func (self *worker) wait() {
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"Invalid block found during mining"
)
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"Invalid block found during mining"
)
continue
continue
}
}
if
err
:=
core
.
ValidateHeader
(
self
.
eth
.
BlockProcessor
()
.
Pow
,
block
.
Header
(),
parent
,
true
);
err
!=
nil
&&
err
!=
core
.
BlockFutureErr
{
if
err
:=
core
.
ValidateHeader
(
self
.
eth
.
BlockProcessor
()
.
Pow
,
block
.
Header
(),
parent
,
true
,
false
);
err
!=
nil
&&
err
!=
core
.
BlockFutureErr
{
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"Invalid header on mined block:"
,
err
)
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"Invalid header on mined block:"
,
err
)
continue
continue
}
}
...
@@ -434,8 +434,8 @@ func (self *worker) commitNewWork() {
...
@@ -434,8 +434,8 @@ func (self *worker) commitNewWork() {
tstart
:=
time
.
Now
()
tstart
:=
time
.
Now
()
parent
:=
self
.
chain
.
CurrentBlock
()
parent
:=
self
.
chain
.
CurrentBlock
()
tstamp
:=
tstart
.
Unix
()
tstamp
:=
tstart
.
Unix
()
if
tstamp
<=
int64
(
parent
.
Time
())
{
if
parent
.
Time
()
.
Cmp
(
new
(
big
.
Int
)
.
SetInt64
(
tstamp
))
!=
1
{
tstamp
=
int64
(
parent
.
Time
()
)
+
1
tstamp
=
parent
.
Time
()
.
Int64
(
)
+
1
}
}
// this will ensure we're not going off too far in the future
// this will ensure we're not going off too far in the future
if
now
:=
time
.
Now
()
.
Unix
();
tstamp
>
now
+
4
{
if
now
:=
time
.
Now
()
.
Unix
();
tstamp
>
now
+
4
{
...
@@ -448,12 +448,12 @@ func (self *worker) commitNewWork() {
...
@@ -448,12 +448,12 @@ func (self *worker) commitNewWork() {
header
:=
&
types
.
Header
{
header
:=
&
types
.
Header
{
ParentHash
:
parent
.
Hash
(),
ParentHash
:
parent
.
Hash
(),
Number
:
num
.
Add
(
num
,
common
.
Big1
),
Number
:
num
.
Add
(
num
,
common
.
Big1
),
Difficulty
:
core
.
CalcDifficulty
(
uint64
(
tstamp
),
parent
.
Time
(),
parent
.
Number
(),
parent
.
Difficulty
()),
Difficulty
:
core
.
CalcDifficulty
(
uint64
(
tstamp
),
parent
.
Time
()
.
Uint64
()
,
parent
.
Number
(),
parent
.
Difficulty
()),
GasLimit
:
core
.
CalcGasLimit
(
parent
),
GasLimit
:
core
.
CalcGasLimit
(
parent
),
GasUsed
:
new
(
big
.
Int
),
GasUsed
:
new
(
big
.
Int
),
Coinbase
:
self
.
coinbase
,
Coinbase
:
self
.
coinbase
,
Extra
:
self
.
extra
,
Extra
:
self
.
extra
,
Time
:
uint64
(
tstamp
),
Time
:
big
.
NewInt
(
tstamp
),
}
}
previous
:=
self
.
current
previous
:=
self
.
current
...
...
tests/block_test.go
View file @
7324176f
...
@@ -35,6 +35,13 @@ func TestBcUncleHeaderValidityTests(t *testing.T) {
...
@@ -35,6 +35,13 @@ func TestBcUncleHeaderValidityTests(t *testing.T) {
}
}
}
}
func
TestBcUncleTests
(
t
*
testing
.
T
)
{
err
:=
RunBlockTest
(
filepath
.
Join
(
blockTestDir
,
"bcUncleTest.json"
),
BlockSkipTests
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
TestBcInvalidHeaderTests
(
t
*
testing
.
T
)
{
func
TestBcInvalidHeaderTests
(
t
*
testing
.
T
)
{
err
:=
RunBlockTest
(
filepath
.
Join
(
blockTestDir
,
"bcInvalidHeaderTest.json"
),
BlockSkipTests
)
err
:=
RunBlockTest
(
filepath
.
Join
(
blockTestDir
,
"bcInvalidHeaderTest.json"
),
BlockSkipTests
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
tests/block_test_util.go
View file @
7324176f
...
@@ -365,8 +365,8 @@ func (s *BlockTest) validateBlockHeader(h *btHeader, h2 *types.Header) error {
...
@@ -365,8 +365,8 @@ func (s *BlockTest) validateBlockHeader(h *btHeader, h2 *types.Header) error {
return
fmt
.
Errorf
(
"GasUsed: expected: %v, decoded: %v"
,
expectedGasUsed
,
h2
.
GasUsed
)
return
fmt
.
Errorf
(
"GasUsed: expected: %v, decoded: %v"
,
expectedGasUsed
,
h2
.
GasUsed
)
}
}
expectedTimestamp
:=
mustConvert
Ui
nt
(
h
.
Timestamp
,
16
)
expectedTimestamp
:=
mustConvert
BigI
nt
(
h
.
Timestamp
,
16
)
if
expectedTimestamp
!=
h2
.
Time
{
if
expectedTimestamp
.
Cmp
(
h2
.
Time
)
!=
0
{
return
fmt
.
Errorf
(
"Timestamp: expected: %v, decoded: %v"
,
expectedTimestamp
,
h2
.
Time
)
return
fmt
.
Errorf
(
"Timestamp: expected: %v, decoded: %v"
,
expectedTimestamp
,
h2
.
Time
)
}
}
...
@@ -461,7 +461,7 @@ func mustConvertHeader(in btHeader) *types.Header {
...
@@ -461,7 +461,7 @@ func mustConvertHeader(in btHeader) *types.Header {
GasUsed
:
mustConvertBigInt
(
in
.
GasUsed
,
16
),
GasUsed
:
mustConvertBigInt
(
in
.
GasUsed
,
16
),
GasLimit
:
mustConvertBigInt
(
in
.
GasLimit
,
16
),
GasLimit
:
mustConvertBigInt
(
in
.
GasLimit
,
16
),
Difficulty
:
mustConvertBigInt
(
in
.
Difficulty
,
16
),
Difficulty
:
mustConvertBigInt
(
in
.
Difficulty
,
16
),
Time
:
mustConvert
Ui
nt
(
in
.
Timestamp
,
16
),
Time
:
mustConvert
BigI
nt
(
in
.
Timestamp
,
16
),
Nonce
:
types
.
EncodeNonce
(
mustConvertUint
(
in
.
Nonce
,
16
)),
Nonce
:
types
.
EncodeNonce
(
mustConvertUint
(
in
.
Nonce
,
16
)),
}
}
return
header
return
header
...
...
tests/files/BlockchainTests/bcUncleTest.json
View file @
7324176f
This diff is collapsed.
Click to expand it.
tests/util.go
View file @
7324176f
...
@@ -135,7 +135,7 @@ type Env struct {
...
@@ -135,7 +135,7 @@ type Env struct {
coinbase
common
.
Address
coinbase
common
.
Address
number
*
big
.
Int
number
*
big
.
Int
time
uint64
time
*
big
.
Int
difficulty
*
big
.
Int
difficulty
*
big
.
Int
gasLimit
*
big
.
Int
gasLimit
*
big
.
Int
...
@@ -165,7 +165,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
...
@@ -165,7 +165,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
//env.parent = common.Hex2Bytes(envValues["previousHash"])
//env.parent = common.Hex2Bytes(envValues["previousHash"])
env
.
coinbase
=
common
.
HexToAddress
(
envValues
[
"currentCoinbase"
])
env
.
coinbase
=
common
.
HexToAddress
(
envValues
[
"currentCoinbase"
])
env
.
number
=
common
.
Big
(
envValues
[
"currentNumber"
])
env
.
number
=
common
.
Big
(
envValues
[
"currentNumber"
])
env
.
time
=
common
.
Big
(
envValues
[
"currentTimestamp"
])
.
Uint64
()
env
.
time
=
common
.
Big
(
envValues
[
"currentTimestamp"
])
env
.
difficulty
=
common
.
Big
(
envValues
[
"currentDifficulty"
])
env
.
difficulty
=
common
.
Big
(
envValues
[
"currentDifficulty"
])
env
.
gasLimit
=
common
.
Big
(
envValues
[
"currentGasLimit"
])
env
.
gasLimit
=
common
.
Big
(
envValues
[
"currentGasLimit"
])
env
.
Gas
=
new
(
big
.
Int
)
env
.
Gas
=
new
(
big
.
Int
)
...
@@ -178,7 +178,7 @@ func (self *Env) BlockNumber() *big.Int { return self.number }
...
@@ -178,7 +178,7 @@ func (self *Env) BlockNumber() *big.Int { return self.number }
//func (self *Env) PrevHash() []byte { return self.parent }
//func (self *Env) PrevHash() []byte { return self.parent }
func
(
self
*
Env
)
Coinbase
()
common
.
Address
{
return
self
.
coinbase
}
func
(
self
*
Env
)
Coinbase
()
common
.
Address
{
return
self
.
coinbase
}
func
(
self
*
Env
)
Time
()
uint64
{
return
self
.
time
}
func
(
self
*
Env
)
Time
()
*
big
.
Int
{
return
self
.
time
}
func
(
self
*
Env
)
Difficulty
()
*
big
.
Int
{
return
self
.
difficulty
}
func
(
self
*
Env
)
Difficulty
()
*
big
.
Int
{
return
self
.
difficulty
}
func
(
self
*
Env
)
State
()
*
state
.
StateDB
{
return
self
.
state
}
func
(
self
*
Env
)
State
()
*
state
.
StateDB
{
return
self
.
state
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
...
...
xeth/types.go
View file @
7324176f
...
@@ -19,6 +19,7 @@ package xeth
...
@@ -19,6 +19,7 @@ package xeth
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"math/big"
"strings"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -76,7 +77,7 @@ type Block struct {
...
@@ -76,7 +77,7 @@ type Block struct {
Hash
string
`json:"hash"`
Hash
string
`json:"hash"`
Transactions
*
common
.
List
`json:"transactions"`
Transactions
*
common
.
List
`json:"transactions"`
Uncles
*
common
.
List
`json:"uncles"`
Uncles
*
common
.
List
`json:"uncles"`
Time
uint64
`json:"time"`
Time
*
big
.
Int
`json:"time"`
Coinbase
string
`json:"coinbase"`
Coinbase
string
`json:"coinbase"`
Name
string
`json:"name"`
Name
string
`json:"name"`
GasLimit
string
`json:"gasLimit"`
GasLimit
string
`json:"gasLimit"`
...
...
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