|
|
@ -219,7 +219,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) { |
|
|
|
|
|
|
|
|
|
|
|
// I'm not sure, but I don't know if there should be thrown
|
|
|
|
// I'm not sure, but I don't know if there should be thrown
|
|
|
|
// any errors at this time.
|
|
|
|
// any errors at this time.
|
|
|
|
if err = sm.AccumelateRewards(state, block); err != nil { |
|
|
|
if err = sm.AccumelateRewards(state, block, parent); err != nil { |
|
|
|
statelogger.Errorln("Error accumulating reward", err) |
|
|
|
statelogger.Errorln("Error accumulating reward", err) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -334,36 +334,44 @@ func (sm *StateManager) ValidateBlock(block *Block) error { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func CalculateBlockReward(block *Block, uncleLength int) *big.Int { |
|
|
|
func (sm *StateManager) AccumelateRewards(state *ethstate.State, block, parent *Block) error { |
|
|
|
base := new(big.Int) |
|
|
|
reward := new(big.Int) |
|
|
|
for i := 0; i < uncleLength; i++ { |
|
|
|
|
|
|
|
base.Add(base, UncleInclusionReward) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return base.Add(base, BlockReward) |
|
|
|
knownUncles := ethutil.Set(parent.Uncles) |
|
|
|
} |
|
|
|
nonces := ethutil.NewSet(block.Nonce) |
|
|
|
|
|
|
|
for _, uncle := range block.Uncles { |
|
|
|
|
|
|
|
if nonces.Include(uncle.Nonce) { |
|
|
|
|
|
|
|
// Error not unique
|
|
|
|
|
|
|
|
return UncleError("Uncle not unique") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func CalculateUncleReward(block *Block) *big.Int { |
|
|
|
uncleParent := sm.bc.GetBlock(uncle.PrevHash) |
|
|
|
return UncleReward |
|
|
|
if uncleParent == nil { |
|
|
|
} |
|
|
|
return UncleError("Uncle's parent unknown") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (sm *StateManager) AccumelateRewards(state *ethstate.State, block *Block) error { |
|
|
|
if uncleParent.Number.Cmp(new(big.Int).Sub(parent.Number, big.NewInt(6))) < 0 { |
|
|
|
// Get the account associated with the coinbase
|
|
|
|
return UncleError("Uncle too old") |
|
|
|
account := state.GetAccount(block.Coinbase) |
|
|
|
} |
|
|
|
// Reward amount of ether to the coinbase address
|
|
|
|
|
|
|
|
account.AddAmount(CalculateBlockReward(block, len(block.Uncles))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addr := make([]byte, len(block.Coinbase)) |
|
|
|
if knownUncles.Include(uncle.Hash()) { |
|
|
|
copy(addr, block.Coinbase) |
|
|
|
return UncleError("Uncle in chain") |
|
|
|
state.UpdateStateObject(account) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
r := new(big.Int) |
|
|
|
|
|
|
|
r.Mul(BlockReward, big.NewInt(15)).Div(r, big.NewInt(16)) |
|
|
|
|
|
|
|
|
|
|
|
for _, uncle := range block.Uncles { |
|
|
|
|
|
|
|
uncleAccount := state.GetAccount(uncle.Coinbase) |
|
|
|
uncleAccount := state.GetAccount(uncle.Coinbase) |
|
|
|
uncleAccount.AddAmount(CalculateUncleReward(uncle)) |
|
|
|
uncleAccount.AddAmount(r) |
|
|
|
|
|
|
|
|
|
|
|
state.UpdateStateObject(uncleAccount) |
|
|
|
reward.Add(reward, new(big.Int).Div(BlockReward, big.NewInt(32))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the account associated with the coinbase
|
|
|
|
|
|
|
|
account := state.GetAccount(block.Coinbase) |
|
|
|
|
|
|
|
// Reward amount of ether to the coinbase address
|
|
|
|
|
|
|
|
account.AddAmount(reward) |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -375,14 +383,6 @@ func (sm *StateManager) Stop() { |
|
|
|
func (sm *StateManager) createBloomFilter(state *ethstate.State) *BloomFilter { |
|
|
|
func (sm *StateManager) createBloomFilter(state *ethstate.State) *BloomFilter { |
|
|
|
bloomf := NewBloomFilter(nil) |
|
|
|
bloomf := NewBloomFilter(nil) |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
for addr, stateObject := range state.Manifest().ObjectChanges { |
|
|
|
|
|
|
|
// Set the bloom filter's bin
|
|
|
|
|
|
|
|
bloomf.Set([]byte(addr)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sm.Ethereum.Reactor().Post("object:"+addr, stateObject) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
for _, msg := range state.Manifest().Messages { |
|
|
|
for _, msg := range state.Manifest().Messages { |
|
|
|
bloomf.Set(msg.To) |
|
|
|
bloomf.Set(msg.To) |
|
|
|
bloomf.Set(msg.From) |
|
|
|
bloomf.Set(msg.From) |
|
|
@ -390,17 +390,6 @@ func (sm *StateManager) createBloomFilter(state *ethstate.State) *BloomFilter { |
|
|
|
|
|
|
|
|
|
|
|
sm.Ethereum.Reactor().Post("messages", state.Manifest().Messages) |
|
|
|
sm.Ethereum.Reactor().Post("messages", state.Manifest().Messages) |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
for stateObjectAddr, mappedObjects := range state.Manifest().StorageChanges { |
|
|
|
|
|
|
|
for addr, value := range mappedObjects { |
|
|
|
|
|
|
|
// Set the bloom filter's bin
|
|
|
|
|
|
|
|
bloomf.Set(ethcrypto.Sha3Bin([]byte(stateObjectAddr + addr))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sm.Ethereum.Reactor().Post("storage:"+stateObjectAddr+":"+addr, ðstate.StorageState{[]byte(stateObjectAddr), []byte(addr), value}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bloomf |
|
|
|
return bloomf |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -420,7 +409,7 @@ func (sm *StateManager) GetMessages(block *Block) (messages []*ethstate.Message, |
|
|
|
|
|
|
|
|
|
|
|
sm.ApplyDiff(state, parent, block) |
|
|
|
sm.ApplyDiff(state, parent, block) |
|
|
|
|
|
|
|
|
|
|
|
sm.AccumelateRewards(state, block) |
|
|
|
sm.AccumelateRewards(state, block, parent) |
|
|
|
|
|
|
|
|
|
|
|
return state.Manifest().Messages, nil |
|
|
|
return state.Manifest().Messages, nil |
|
|
|
} |
|
|
|
} |
|
|
|