aboutsummaryrefslogtreecommitdiffstats
path: root/chain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-03 05:37:45 +0800
committerobscuren <geffobscura@gmail.com>2014-12-03 05:37:45 +0800
commitf7789220862f67c2aadaf7b6a44fcd54152dd234 (patch)
tree173339a8da9b45c3e03b4f5a36ca5622a42e48b0 /chain
parentedc52bdcbf65b396a838a347b370ea859ae58247 (diff)
downloadgo-tangerine-f7789220862f67c2aadaf7b6a44fcd54152dd234.tar
go-tangerine-f7789220862f67c2aadaf7b6a44fcd54152dd234.tar.gz
go-tangerine-f7789220862f67c2aadaf7b6a44fcd54152dd234.tar.bz2
go-tangerine-f7789220862f67c2aadaf7b6a44fcd54152dd234.tar.lz
go-tangerine-f7789220862f67c2aadaf7b6a44fcd54152dd234.tar.xz
go-tangerine-f7789220862f67c2aadaf7b6a44fcd54152dd234.tar.zst
go-tangerine-f7789220862f67c2aadaf7b6a44fcd54152dd234.zip
Set proper message value
Diffstat (limited to 'chain')
-rw-r--r--chain/block.go2
-rw-r--r--chain/block_manager.go56
-rw-r--r--chain/state_transition.go6
3 files changed, 31 insertions, 33 deletions
diff --git a/chain/block.go b/chain/block.go
index dccb7ca41..6b976cc14 100644
--- a/chain/block.go
+++ b/chain/block.go
@@ -97,6 +97,8 @@ type Block struct {
receipts Receipts
TxSha, ReceiptSha []byte
LogsBloom []byte
+
+ Reward *big.Int
}
func NewBlockFromBytes(raw []byte) *Block {
diff --git a/chain/block_manager.go b/chain/block_manager.go
index fe84a94ca..d89789255 100644
--- a/chain/block_manager.go
+++ b/chain/block_manager.go
@@ -117,6 +117,19 @@ func (sm *BlockManager) ChainManager() *ChainManager {
return sm.bc
}
+func (sm *BlockManager) TransitionState(statedb *state.State, parent, block *Block) (receipts Receipts, err error) {
+ coinbase := statedb.GetOrNewStateObject(block.Coinbase)
+ coinbase.SetGasPool(block.CalcGasLimit(parent))
+
+ // Process the transactions on to current block
+ receipts, _, _, _, err = sm.ProcessTransactions(coinbase, statedb, block, parent, block.Transactions())
+ if err != nil {
+ return nil, err
+ }
+
+ return receipts, nil
+}
+
func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, Transactions, error) {
var (
receipts Receipts
@@ -124,6 +137,7 @@ func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state
erroneous Transactions
totalUsedGas = big.NewInt(0)
err error
+ cumulativeSum = new(big.Int)
)
done:
@@ -155,6 +169,7 @@ done:
}
txGas.Sub(txGas, st.gas)
+ cumulativeSum.Add(cumulativeSum, new(big.Int).Mul(txGas, tx.GasPrice))
// Update the state with pending changes
state.Update(txGas)
@@ -174,6 +189,7 @@ done:
}
}
+ block.Reward = cumulativeSum
block.GasUsed = totalUsedGas
return receipts, handled, unhandled, erroneous, err
@@ -211,7 +227,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
fmt.Printf("## %x %x ##\n", block.Hash(), block.Number)
}
- _, err = sm.ApplyDiff(state, parent, block)
+ _, err = sm.TransitionState(state, parent, block)
if err != nil {
return
}
@@ -275,27 +291,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
}
}
-func (sm *BlockManager) ApplyDiff(statedb *state.State, parent, block *Block) (receipts Receipts, err error) {
- coinbase := statedb.GetOrNewStateObject(block.Coinbase)
- coinbase.SetGasPool(block.CalcGasLimit(parent))
-
- // Process the transactions on to current block
- receipts, _, _, _, err = sm.ProcessTransactions(coinbase, statedb, block, parent, block.Transactions())
- if err != nil {
- return nil, err
- }
-
- statedb.Manifest().AddMessage(&state.Message{
- To: block.Coinbase, From: block.Coinbase,
- Input: nil,
- Origin: nil,
- Block: block.Hash(), Timestamp: block.Time, Coinbase: block.Coinbase, Number: block.Number,
- Value: new(big.Int),
- })
-
- return receipts, nil
-}
-
func (sm *BlockManager) CalculateTD(block *Block) (*big.Int, bool) {
uncleDiff := new(big.Int)
for _, uncle := range block.Uncles {
@@ -345,7 +340,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *Block) error {
return nil
}
-func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Block) error {
+func (sm *BlockManager) AccumelateRewards(statedb *state.State, block, parent *Block) error {
reward := new(big.Int).Set(BlockReward)
knownUncles := ethutil.Set(parent.Uncles)
@@ -374,17 +369,25 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Blo
r := new(big.Int)
r.Mul(BlockReward, big.NewInt(15)).Div(r, big.NewInt(16))
- uncleAccount := state.GetAccount(uncle.Coinbase)
+ uncleAccount := statedb.GetAccount(uncle.Coinbase)
uncleAccount.AddAmount(r)
reward.Add(reward, new(big.Int).Div(BlockReward, big.NewInt(32)))
}
// Get the account associated with the coinbase
- account := state.GetAccount(block.Coinbase)
+ account := statedb.GetAccount(block.Coinbase)
// Reward amount of ether to the coinbase address
account.AddAmount(reward)
+ statedb.Manifest().AddMessage(&state.Message{
+ To: block.Coinbase, From: block.Coinbase,
+ Input: nil,
+ Origin: nil,
+ Block: block.Hash(), Timestamp: block.Time, Coinbase: block.Coinbase, Number: block.Number,
+ Value: new(big.Int).Add(reward, block.Reward),
+ })
+
return nil
}
@@ -402,8 +405,7 @@ func (sm *BlockManager) GetMessages(block *Block) (messages []*state.Message, er
defer state.Reset()
- sm.ApplyDiff(state, parent, block)
-
+ sm.TransitionState(state, parent, block)
sm.AccumelateRewards(state, block, parent)
return state.Manifest().Messages, nil
diff --git a/chain/state_transition.go b/chain/state_transition.go
index f9b82c58b..53c306903 100644
--- a/chain/state_transition.go
+++ b/chain/state_transition.go
@@ -168,12 +168,6 @@ func (self *StateTransition) TransitionState() (err error) {
return
}
- //dataPrice := big.NewInt(int64(len(self.data)))
- //dataPrice.Mul(dataPrice, vm.GasData)
- //if err = self.UseGas(dataPrice); err != nil {
- // return
- //}
-
if sender.Balance().Cmp(self.value) < 0 {
return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Balance)
}