uncle validation

This commit is contained in:
obscuren
2015-03-04 10:49:56 +01:00
parent d4d505c868
commit 84a4f761f3
4 changed files with 46 additions and 30 deletions

View File

@ -28,16 +28,16 @@ type StateQuery interface {
GetAccount(addr []byte) *state.StateObject
}
func CalcDifficulty(block, parent *types.Block) *big.Int {
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))
if (block.Time() - parent.Time()) < 8 {
diff.Add(parent.Difficulty(), adjust)
adjust := new(big.Int).Div(parent.Difficulty, big.NewInt(2048))
if (block.Time - parent.Time) < 8 {
diff.Add(parent.Difficulty, adjust)
} else {
diff.Sub(parent.Difficulty(), adjust)
diff.Sub(parent.Difficulty, adjust)
}
return diff
@ -206,7 +206,7 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
parent := bc.currentBlock
if parent != nil {
header := block.Header()
header.Difficulty = CalcDifficulty(block, parent)
header.Difficulty = CalcDifficulty(block.Header(), parent.Header())
header.Number = new(big.Int).Add(parent.Header().Number, ethutil.Big1)
header.GasLimit = CalcGasLimit(parent, block)