aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-05 16:14:58 +0800
committerobscuren <geffobscura@gmail.com>2015-03-05 16:14:58 +0800
commitc47866d25174bd783ee6bcd5b400d81d7bf598bb (patch)
tree01c71c40981f4f75e1721011006d2da96dfc3c2d /core
parent15f491e5007d1507f20d0edce36cc9c0bd5cbd37 (diff)
downloadgo-tangerine-c47866d25174bd783ee6bcd5b400d81d7bf598bb.tar
go-tangerine-c47866d25174bd783ee6bcd5b400d81d7bf598bb.tar.gz
go-tangerine-c47866d25174bd783ee6bcd5b400d81d7bf598bb.tar.bz2
go-tangerine-c47866d25174bd783ee6bcd5b400d81d7bf598bb.tar.lz
go-tangerine-c47866d25174bd783ee6bcd5b400d81d7bf598bb.tar.xz
go-tangerine-c47866d25174bd783ee6bcd5b400d81d7bf598bb.tar.zst
go-tangerine-c47866d25174bd783ee6bcd5b400d81d7bf598bb.zip
Miner fixes and updates (including miner)
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go7
-rw-r--r--core/chain_manager.go28
-rw-r--r--core/genesis.go5
-rw-r--r--core/types/block.go14
4 files changed, 32 insertions, 22 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index c2799dc48..34c12729c 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -253,9 +253,6 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd)
}
- //expl := CalcGasLimit(parent, block)
- //if expl.Cmp(block.Header().GasLimit) != 0 {
-
// block.gasLimit - parent.gasLimit <= parent.gasLimit / 1024
a := new(big.Int).Sub(block.GasLimit, parent.GasLimit)
b := new(big.Int).Div(parent.GasLimit, big.NewInt(1024))
@@ -263,8 +260,8 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
return fmt.Errorf("GasLimit check failed for block %v (%v > %v)", block.GasLimit, a, b)
}
- if block.Time < parent.Time {
- return ValidationError("Block timestamp not after prev block (%v - %v)", block.Time, parent.Time)
+ if block.Time <= parent.Time {
+ return ValidationError("Block timestamp not after or equal to prev block (%v - %v)", block.Time, parent.Time)
}
if int64(block.Time) > time.Now().Unix() {
diff --git a/core/chain_manager.go b/core/chain_manager.go
index f2382cf8d..d2a6560c1 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -31,15 +31,18 @@ type StateQuery interface {
func CalcDifficulty(block, parent *types.Header) *big.Int {
diff := new(big.Int)
- //adjust := new(big.Int).Rsh(parent.Difficulty(), 10)
- //if block.Time() >= parent.Time()+8 {
- adjust := new(big.Int).Div(parent.Difficulty, big.NewInt(2048))
+ min := big.NewInt(2048)
+ adjust := new(big.Int).Div(parent.Difficulty, min)
if (block.Time - parent.Time) < 8 {
diff.Add(parent.Difficulty, adjust)
} else {
diff.Sub(parent.Difficulty, adjust)
}
+ if diff.Cmp(GenesisDiff) < 0 {
+ return GenesisDiff
+ }
+
return diff
}
@@ -378,9 +381,12 @@ func (bc *ChainManager) Stop() {
}
func (self *ChainManager) InsertChain(chain types.Blocks) error {
+ println("insert chain start")
self.tsmu.Lock()
defer self.tsmu.Unlock()
+ defer println("insert chain end")
+
for _, block := range chain {
// Call in to the block processor and check for errors. It's likely that if one block fails
// all others will fail too (unless a known block is returned).
@@ -422,14 +428,18 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
self.mu.Unlock()
if canonical {
- jsonlogger.LogJson(&logger.EthChainNewHead{
- BlockHash: ethutil.Bytes2Hex(block.Hash()),
- BlockNumber: block.Number(),
- ChainHeadHash: ethutil.Bytes2Hex(cblock.Hash()),
- BlockPrevHash: ethutil.Bytes2Hex(block.ParentHash()),
- })
+ /*
+ jsonlogger.LogJson(&logger.EthChainNewHead{
+ BlockHash: ethutil.Bytes2Hex(block.Hash()),
+ BlockNumber: block.Number(),
+ ChainHeadHash: ethutil.Bytes2Hex(cblock.Hash()),
+ BlockPrevHash: ethutil.Bytes2Hex(block.ParentHash()),
+ })
+ */
self.setTransState(state.New(block.Root(), self.db))
self.eventMux.Post(ChainEvent{block, td})
+ } else {
+ //self.eventMux.
}
if split {
diff --git a/core/genesis.go b/core/genesis.go
index f675be53f..a3f5dfb38 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -22,8 +22,10 @@ var ZeroHash512 = make([]byte, 64)
var EmptyShaList = crypto.Sha3(ethutil.Encode([]interface{}{}))
var EmptyListRoot = crypto.Sha3(ethutil.Encode(""))
+var GenesisDiff = big.NewInt(131072)
+
func GenesisBlock(db ethutil.Database) *types.Block {
- genesis := types.NewBlock(ZeroHash256, ZeroHash160, nil, big.NewInt(2048), 42, "")
+ genesis := types.NewBlock(ZeroHash256, ZeroHash160, nil, GenesisDiff, 42, "")
genesis.Header().Number = ethutil.Big0
genesis.Header().GasLimit = big.NewInt(1000000)
genesis.Header().GasUsed = ethutil.Big0
@@ -53,7 +55,6 @@ func GenesisBlock(db ethutil.Database) *types.Block {
}
statedb.Sync()
genesis.Header().Root = statedb.Root()
- fmt.Println(genesis)
return genesis
}
diff --git a/core/types/block.go b/core/types/block.go
index 18a21e8c6..31c7c2b87 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -40,12 +40,12 @@ type Header struct {
Time uint64
// Extra data
Extra string
- // Nonce
- Nonce []byte
- // Mix digest for quick checking to prevent DOS
- MixDigest ethutil.Bytes
// SeedHash used for light client verification
SeedHash ethutil.Bytes
+ // Mix digest for quick checking to prevent DOS
+ MixDigest ethutil.Bytes
+ // Nonce
+ Nonce []byte
}
func (self *Header) rlpData(withNonce bool) []interface{} {
@@ -62,9 +62,11 @@ func (self *Header) rlpData(withNonce bool) []interface{} {
self.GasLimit,
self.GasUsed,
self.Time,
- self.Extra}
+ self.Extra,
+ self.SeedHash,
+ }
if withNonce {
- fields = append(fields, self.SeedHash, self.MixDigest, self.Nonce)
+ fields = append(fields, self.MixDigest, self.Nonce)
}
return fields