aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-06-30 15:13:16 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-06-30 16:52:11 +0800
commit4c490db6afeb5a48d3e8d1d65ea8ddc9811d0a6d (patch)
tree4bb5055690cae276a5480572b463cd06fa219f23 /core
parentbe935bff84d54cd7a7f4074e2326d62f664ba4e3 (diff)
downloadgo-tangerine-4c490db6afeb5a48d3e8d1d65ea8ddc9811d0a6d.tar.gz
go-tangerine-4c490db6afeb5a48d3e8d1d65ea8ddc9811d0a6d.tar.zst
go-tangerine-4c490db6afeb5a48d3e8d1d65ea8ddc9811d0a6d.zip
Use uint64 for block header timestamp
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go15
-rw-r--r--core/chain_makers.go2
-rw-r--r--core/chain_manager.go2
-rw-r--r--core/types/block.go2
-rw-r--r--core/types/block_test.go2
-rw-r--r--core/vm/environment.go2
-rw-r--r--core/vm/vm.go2
-rw-r--r--core/vm_env.go2
8 files changed, 14 insertions, 15 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 22d4c7c27..9b77d10eb 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -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)) {
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 72ae7970e..013251d74 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -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),
diff --git a/core/chain_manager.go b/core/chain_manager.go
index c89aae3f0..cdbdeb5ae 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -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)
}
diff --git a/core/types/block.go b/core/types/block.go
index b7eb700ca..e8919e9a0 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -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 }
diff --git a/core/types/block_test.go b/core/types/block_test.go
index 03e6881be..e0b98cd26 100644
--- a/core/types/block_test.go
+++ b/core/types/block_test.go
@@ -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(), uint64(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)
diff --git a/core/vm/environment.go b/core/vm/environment.go
index c103049a2..0a5891f5c 100644
--- a/core/vm/environment.go
+++ b/core/vm/environment.go
@@ -17,7 +17,7 @@ type Environment interface {
BlockNumber() *big.Int
GetHash(n uint64) common.Hash
Coinbase() common.Address
- Time() int64
+ Time() uint64
Difficulty() *big.Int
GasLimit() *big.Int
Transfer(from, to Account, amount *big.Int) error
diff --git a/core/vm/vm.go b/core/vm/vm.go
index 9e092300d..ba803683b 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -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()
diff --git a/core/vm_env.go b/core/vm_env.go
index 6dd83acde..24a29545f 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -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() }