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
2e5242f9
Commit
2e5242f9
authored
Jul 01, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1355 from Gustav-Simonsson/block_header_ts_uint64
Use uint64 for block header timestamp
parents
cb2c10d8
4c490db6
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
24 additions
and
25 deletions
+24
-25
main.go
cmd/evm/main.go
+3
-3
block_processor.go
core/block_processor.go
+7
-8
chain_makers.go
core/chain_makers.go
+1
-1
chain_manager.go
core/chain_manager.go
+1
-1
block.go
core/types/block.go
+1
-1
block_test.go
core/types/block_test.go
+1
-1
environment.go
core/vm/environment.go
+1
-1
vm.go
core/vm/vm.go
+1
-1
vm_env.go
core/vm_env.go
+1
-1
worker.go
miner/worker.go
+3
-3
util.go
tests/util.go
+3
-3
types.go
xeth/types.go
+1
-1
No files found.
cmd/evm/main.go
View file @
2e5242f9
...
...
@@ -106,7 +106,7 @@ type VMEnv struct {
depth
int
Gas
*
big
.
Int
time
int64
time
u
int64
logs
[]
vm
.
StructLog
}
...
...
@@ -115,7 +115,7 @@ func NewEnv(state *state.StateDB, transactor common.Address, value *big.Int) *VM
state
:
state
,
transactor
:
&
transactor
,
value
:
value
,
time
:
time
.
Now
()
.
Unix
(
),
time
:
uint64
(
time
.
Now
()
.
Unix
()
),
}
}
...
...
@@ -123,7 +123,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
func
(
self
*
VMEnv
)
Origin
()
common
.
Address
{
return
*
self
.
transactor
}
func
(
self
*
VMEnv
)
BlockNumber
()
*
big
.
Int
{
return
common
.
Big0
}
func
(
self
*
VMEnv
)
Coinbase
()
common
.
Address
{
return
*
self
.
transactor
}
func
(
self
*
VMEnv
)
Time
()
int64
{
return
self
.
time
}
func
(
self
*
VMEnv
)
Time
()
uint64
{
return
self
.
time
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
common
.
Big1
}
func
(
self
*
VMEnv
)
BlockHash
()
[]
byte
{
return
make
([]
byte
,
32
)
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
value
}
...
...
core/block_processor.go
View file @
2e5242f9
...
...
@@ -362,6 +362,13 @@ func ValidateHeader(pow pow.PoW, block *types.Header, parent *types.Block, check
return
fmt
.
Errorf
(
"Block extra data too long (%d)"
,
len
(
block
.
Extra
))
}
if
block
.
Time
>
uint64
(
time
.
Now
()
.
Unix
())
{
return
BlockFutureErr
}
if
block
.
Time
<=
parent
.
Time
()
{
return
BlockEqualTSErr
}
expd
:=
CalcDifficulty
(
int64
(
block
.
Time
),
int64
(
parent
.
Time
()),
parent
.
Difficulty
())
if
expd
.
Cmp
(
block
.
Difficulty
)
!=
0
{
return
fmt
.
Errorf
(
"Difficulty check failed for block %v, %v"
,
block
.
Difficulty
,
expd
)
...
...
@@ -377,20 +384,12 @@ func ValidateHeader(pow pow.PoW, block *types.Header, parent *types.Block, check
return
fmt
.
Errorf
(
"GasLimit check failed for block %v (%v > %v)"
,
block
.
GasLimit
,
a
,
b
)
}
if
int64
(
block
.
Time
)
>
time
.
Now
()
.
Unix
()
{
return
BlockFutureErr
}
num
:=
parent
.
Number
()
num
.
Sub
(
block
.
Number
,
num
)
if
num
.
Cmp
(
big
.
NewInt
(
1
))
!=
0
{
return
BlockNumberErr
}
if
block
.
Time
<=
uint64
(
parent
.
Time
())
{
return
BlockEqualTSErr
//ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time)
}
if
checkPow
{
// Verify the nonce of the block. Return an error if it's not valid
if
!
pow
.
Verify
(
types
.
NewBlockWithHeader
(
block
))
{
...
...
core/chain_makers.go
View file @
2e5242f9
...
...
@@ -155,7 +155,7 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header {
Root
:
state
.
Root
(),
ParentHash
:
parent
.
Hash
(),
Coinbase
:
parent
.
Coinbase
(),
Difficulty
:
CalcDifficulty
(
time
,
parent
.
Time
(
),
parent
.
Difficulty
()),
Difficulty
:
CalcDifficulty
(
int64
(
time
),
int64
(
parent
.
Time
()
),
parent
.
Difficulty
()),
GasLimit
:
CalcGasLimit
(
parent
),
GasUsed
:
new
(
big
.
Int
),
Number
:
new
(
big
.
Int
)
.
Add
(
parent
.
Number
(),
common
.
Big1
),
...
...
core/chain_manager.go
View file @
2e5242f9
...
...
@@ -658,7 +658,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
// Allow up to MaxFuture second in the future blocks. If this limit
// is exceeded the chain is discarded and processed at a later time
// if given.
if
max
:=
time
.
Now
()
.
Unix
()
+
maxTimeFutureBlocks
;
block
.
Time
(
)
>
max
{
if
max
:=
time
.
Now
()
.
Unix
()
+
maxTimeFutureBlocks
;
int64
(
block
.
Time
()
)
>
max
{
return
i
,
fmt
.
Errorf
(
"%v: BlockFutureErr, %v > %v"
,
BlockFutureErr
,
block
.
Time
(),
max
)
}
...
...
core/types/block.go
View file @
2e5242f9
...
...
@@ -290,7 +290,7 @@ 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
)
Bloom
()
Bloom
{
return
b
.
header
.
Bloom
}
func
(
b
*
Block
)
Coinbase
()
common
.
Address
{
return
b
.
header
.
Coinbase
}
func
(
b
*
Block
)
Time
()
int64
{
return
int64
(
b
.
header
.
Time
)
}
func
(
b
*
Block
)
Time
()
uint64
{
return
b
.
header
.
Time
}
func
(
b
*
Block
)
Root
()
common
.
Hash
{
return
b
.
header
.
Root
}
func
(
b
*
Block
)
ParentHash
()
common
.
Hash
{
return
b
.
header
.
ParentHash
}
func
(
b
*
Block
)
TxHash
()
common
.
Hash
{
return
b
.
header
.
TxHash
}
...
...
core/types/block_test.go
View file @
2e5242f9
...
...
@@ -31,7 +31,7 @@ func TestBlockEncoding(t *testing.T) {
check
(
"Root"
,
block
.
Root
(),
common
.
HexToHash
(
"ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"
))
check
(
"Hash"
,
block
.
Hash
(),
common
.
HexToHash
(
"0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"
))
check
(
"Nonce"
,
block
.
Nonce
(),
uint64
(
0xa13a5a8c8f2bb1c4
))
check
(
"Time"
,
block
.
Time
(),
int64
(
1426516743
))
check
(
"Time"
,
block
.
Time
(),
u
int64
(
1426516743
))
check
(
"Size"
,
block
.
Size
(),
common
.
StorageSize
(
len
(
blockEnc
)))
tx1
:=
NewTransaction
(
0
,
common
.
HexToAddress
(
"095e7baea6a6c7c4c2dfeb977efac326af552d87"
),
big
.
NewInt
(
10
),
big
.
NewInt
(
50000
),
big
.
NewInt
(
10
),
nil
)
...
...
core/vm/environment.go
View file @
2e5242f9
...
...
@@ -17,7 +17,7 @@ type Environment interface {
BlockNumber
()
*
big
.
Int
GetHash
(
n
uint64
)
common
.
Hash
Coinbase
()
common
.
Address
Time
()
int64
Time
()
u
int64
Difficulty
()
*
big
.
Int
GasLimit
()
*
big
.
Int
Transfer
(
from
,
to
Account
,
amount
*
big
.
Int
)
error
...
...
core/vm/vm.go
View file @
2e5242f9
...
...
@@ -444,7 +444,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
case
TIMESTAMP
:
time
:=
self
.
env
.
Time
()
stack
.
push
(
big
.
NewInt
(
time
))
stack
.
push
(
new
(
big
.
Int
)
.
SetUint64
(
time
))
case
NUMBER
:
number
:=
self
.
env
.
BlockNumber
()
...
...
core/vm_env.go
View file @
2e5242f9
...
...
@@ -33,7 +33,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
)
BlockNumber
()
*
big
.
Int
{
return
self
.
header
.
Number
}
func
(
self
*
VMEnv
)
Coinbase
()
common
.
Address
{
return
self
.
header
.
Coinbase
}
func
(
self
*
VMEnv
)
Time
()
int64
{
return
int64
(
self
.
header
.
Time
)
}
func
(
self
*
VMEnv
)
Time
()
uint64
{
return
self
.
header
.
Time
}
func
(
self
*
VMEnv
)
Difficulty
()
*
big
.
Int
{
return
self
.
header
.
Difficulty
}
func
(
self
*
VMEnv
)
GasLimit
()
*
big
.
Int
{
return
self
.
header
.
GasLimit
}
func
(
self
*
VMEnv
)
Value
()
*
big
.
Int
{
return
self
.
msg
.
Value
()
}
...
...
miner/worker.go
View file @
2e5242f9
...
...
@@ -368,8 +368,8 @@ func (self *worker) commitNewWork() {
tstart
:=
time
.
Now
()
parent
:=
self
.
chain
.
CurrentBlock
()
tstamp
:=
tstart
.
Unix
()
if
tstamp
<=
parent
.
Time
(
)
{
tstamp
=
parent
.
Time
(
)
+
1
if
tstamp
<=
int64
(
parent
.
Time
()
)
{
tstamp
=
int64
(
parent
.
Time
()
)
+
1
}
// this will ensure we're not going off too far in the future
if
now
:=
time
.
Now
()
.
Unix
();
tstamp
>
now
+
4
{
...
...
@@ -382,7 +382,7 @@ func (self *worker) commitNewWork() {
header
:=
&
types
.
Header
{
ParentHash
:
parent
.
Hash
(),
Number
:
num
.
Add
(
num
,
common
.
Big1
),
Difficulty
:
core
.
CalcDifficulty
(
tstamp
,
parent
.
Time
(
),
parent
.
Difficulty
()),
Difficulty
:
core
.
CalcDifficulty
(
int64
(
tstamp
),
int64
(
parent
.
Time
()
),
parent
.
Difficulty
()),
GasLimit
:
core
.
CalcGasLimit
(
parent
),
GasUsed
:
new
(
big
.
Int
),
Coinbase
:
self
.
coinbase
,
...
...
tests/util.go
View file @
2e5242f9
...
...
@@ -120,7 +120,7 @@ type Env struct {
coinbase
common
.
Address
number
*
big
.
Int
time
int64
time
u
int64
difficulty
*
big
.
Int
gasLimit
*
big
.
Int
...
...
@@ -150,7 +150,7 @@ func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues
//env.parent = common.Hex2Bytes(envValues["previousHash"])
env
.
coinbase
=
common
.
HexToAddress
(
envValues
[
"currentCoinbase"
])
env
.
number
=
common
.
Big
(
envValues
[
"currentNumber"
])
env
.
time
=
common
.
Big
(
envValues
[
"currentTimestamp"
])
.
I
nt64
()
env
.
time
=
common
.
Big
(
envValues
[
"currentTimestamp"
])
.
Ui
nt64
()
env
.
difficulty
=
common
.
Big
(
envValues
[
"currentDifficulty"
])
env
.
gasLimit
=
common
.
Big
(
envValues
[
"currentGasLimit"
])
env
.
Gas
=
new
(
big
.
Int
)
...
...
@@ -163,7 +163,7 @@ func (self *Env) BlockNumber() *big.Int { return self.number }
//func (self *Env) PrevHash() []byte { return self.parent }
func
(
self
*
Env
)
Coinbase
()
common
.
Address
{
return
self
.
coinbase
}
func
(
self
*
Env
)
Time
()
int64
{
return
self
.
time
}
func
(
self
*
Env
)
Time
()
uint64
{
return
self
.
time
}
func
(
self
*
Env
)
Difficulty
()
*
big
.
Int
{
return
self
.
difficulty
}
func
(
self
*
Env
)
State
()
*
state
.
StateDB
{
return
self
.
state
}
func
(
self
*
Env
)
GasLimit
()
*
big
.
Int
{
return
self
.
gasLimit
}
...
...
xeth/types.go
View file @
2e5242f9
...
...
@@ -60,7 +60,7 @@ type Block struct {
Hash
string
`json:"hash"`
Transactions
*
common
.
List
`json:"transactions"`
Uncles
*
common
.
List
`json:"uncles"`
Time
int64
`json:"time"`
Time
uint64
`json:"time"`
Coinbase
string
`json:"coinbase"`
Name
string
`json:"name"`
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