Fixed merge

This commit is contained in:
obscuren 2014-11-28 21:44:34 +01:00
commit 1bce02eff7
11 changed files with 77 additions and 70 deletions

View File

@ -155,10 +155,11 @@ done:
}
}
// Update the state with pending changes
state.Update()
txGas.Sub(txGas, st.gas)
// Update the state with pending changes
state.Update(txGas)
cumulative := new(big.Int).Set(totalUsedGas.Add(totalUsedGas, txGas))
receipt := types.NewReceipt(state.Root(), cumulative)
receipt.SetLogs(state.Logs())
@ -247,7 +248,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return
}
state.Update()
state.Update(nil)
if !block.State().Cmp(state) {
err = fmt.Errorf("invalid merkle root. received=%x got=%x", block.Root(), state.Root())

View File

@ -112,8 +112,6 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
nil,
"")
block.MinGasPrice = big.NewInt(10000000000000)
parent := bc.CurrentBlock
if parent != nil {
block.Difficulty = CalcDifficulty(block, parent)

View File

@ -37,8 +37,6 @@ var GenesisHeader = []interface{}{
big.NewInt(131072),
// Number
ethutil.Big0,
// Block minimum gas price
ethutil.Big0,
// Block upper gas bound
big.NewInt(1000000),
// Block gas used

View File

@ -157,12 +157,24 @@ func (self *StateTransition) TransitionState() (err error) {
}
// Pay data gas
dataPrice := big.NewInt(int64(len(self.data)))
dataPrice.Mul(dataPrice, vm.GasData)
if err = self.UseGas(dataPrice); err != nil {
var dgas int64
for _, byt := range self.data {
if byt != 0 {
dgas += vm.GasData.Int64()
} else {
dgas += 1 // This is 1/5. If GasData changes this fails
}
}
if err = self.UseGas(big.NewInt(dgas)); err != nil {
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)
}

View File

@ -84,8 +84,6 @@ type Block struct {
Time int64
// The block number
Number *big.Int
// Minimum Gas Price
MinGasPrice *big.Int
// Gas limit
GasLimit *big.Int
// Gas used
@ -132,7 +130,6 @@ func CreateBlock(root interface{},
Extra: extra,
UncleSha: nil,
GasUsed: new(big.Int),
MinGasPrice: new(big.Int),
GasLimit: new(big.Int),
}
block.SetUncles([]*Block{})
@ -300,12 +297,11 @@ func (self *Block) setHeader(header *ethutil.Value) {
self.LogsBloom = header.Get(6).Bytes()
self.Difficulty = header.Get(7).BigInt()
self.Number = header.Get(8).BigInt()
self.MinGasPrice = header.Get(9).BigInt()
self.GasLimit = header.Get(10).BigInt()
self.GasUsed = header.Get(11).BigInt()
self.Time = int64(header.Get(12).BigInt().Uint64())
self.Extra = header.Get(13).Str()
self.Nonce = header.Get(14).Bytes()
self.GasLimit = header.Get(9).BigInt()
self.GasUsed = header.Get(10).BigInt()
self.Time = int64(header.Get(11).BigInt().Uint64())
self.Extra = header.Get(12).Str()
self.Nonce = header.Get(13).Bytes()
}
func NewUncleBlockFromValue(header *ethutil.Value) *Block {
@ -351,8 +347,6 @@ func (block *Block) miningHeader() []interface{} {
block.Difficulty,
// The block number
block.Number,
// Block minimum gas price
block.MinGasPrice,
// Block upper gas bound
block.GasLimit,
// Block gas used
@ -380,7 +374,6 @@ func (block *Block) String() string {
Bloom: %x
Difficulty: %v
Number: %v
MinGas: %v
MaxLimit: %v
GasUsed: %v
Time: %v
@ -399,7 +392,6 @@ func (block *Block) String() string {
block.LogsBloom,
block.Difficulty,
block.Number,
block.MinGasPrice,
block.GasLimit,
block.GasUsed,
block.Time,

View File

@ -21,6 +21,7 @@ import (
"fmt"
"os"
"runtime"
"github.com/ethereum/go-ethereum/chain/types"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/ethutil"
@ -29,7 +30,7 @@ import (
const (
ClientIdentifier = "Ethereum(G)"
Version = "0.7.5"
Version = "0.7.6"
)
var clilogger = logger.NewLogger("CLI")

View File

@ -31,7 +31,7 @@ import (
const (
ClientIdentifier = "Mist"
Version = "0.7.5"
Version = "0.7.6"
)
var ethereum *eth.Ethereum

View File

@ -1,15 +1,20 @@
#!/bin/sh
if [ "$1" == "" ]; then
echo "Usage $0 executable branch ethereum develop"
echo "executable ethereum or mist"
echo "branch develop or master"
echo "Usage $0 executable branch"
echo "executable ethereum | mist"
echo "branch develop | master"
exit
fi
exe=$1
path=$exe
branch=$2
if [ "$branch" == "develop" ]; then
path="cmd/$exe"
fi
# Test if go is installed
command -v go >/dev/null 2>&1 || { echo >&2 "Unable to find 'go'. This script requires go."; exit 1; }
@ -19,20 +24,23 @@ if [ "$GOPATH" == "" ]; then
exit
fi
echo "go get -u -d github.com/ethereum/go-ethereum/$exe"
go get -v -u -d github.com/ethereum/go-ethereum/$exe
if [ $? != 0 ]; then
echo "go get failed"
exit
fi
echo "eth-go"
echo "changing branch to $branch"
cd $GOPATH/src/github.com/ethereum/go-ethereum
git checkout $branch
echo "go-ethereum"
cd $GOPATH/src/github.com/ethereum/go-ethereum/$exe
git checkout $branch
# installing package dependencies doesn't work for develop
# branch as go get always pulls from master head
# so build will continue to fail, but this installs locally
# for people who git clone since go install will manage deps
#echo "go get -u -d github.com/ethereum/go-ethereum/$path"
#go get -v -u -d github.com/ethereum/go-ethereum/$path
#if [ $? != 0 ]; then
# echo "go get failed"
# exit
#fi
cd $GOPATH/src/github.com/ethereum/go-ethereum/$path
if [ "$exe" == "mist" ]; then
echo "Building Mist GUI. Assuming Qt is installed. If this step"
@ -42,9 +50,4 @@ else
fi
go install
if [ $? == 0 ]; then
echo "go install failed"
exit
fi
echo "done. Please run $exe :-)"

View File

@ -179,7 +179,6 @@ func (self *Miner) mine() {
chainMan = self.eth.ChainManager()
block = chainMan.NewBlock(self.Coinbase)
)
block.MinGasPrice = self.MinAcceptedGasPrice
// Apply uncles
if len(self.uncles) > 0 {
@ -206,7 +205,7 @@ func (self *Miner) mine() {
// Accumulate the rewards included for this block
blockManager.AccumelateRewards(block.State(), block, parent)
block.State().Update()
block.State().Update(nil)
minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions))

View File

@ -24,7 +24,7 @@ const (
// The size of the output buffer for writing messages
outputBufferSize = 50
// Current protocol version
ProtocolVersion = 43
ProtocolVersion = 45
// Current P2P version
P2PVersion = 2
// Ethereum network version

View File

@ -23,14 +23,14 @@ type State struct {
manifest *Manifest
refund map[string]*big.Int
refund map[string][]refund
logs Logs
}
// Create a new state from a given trie
func New(trie *trie.Trie) *State {
return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string]*big.Int)}
return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest(), refund: make(map[string][]refund)}
}
func (self *State) EmptyLogs() {
@ -55,14 +55,12 @@ func (self *State) GetBalance(addr []byte) *big.Int {
return ethutil.Big0
}
func (self *State) Refund(addr []byte, gas, price *big.Int) {
amount := new(big.Int).Mul(gas, price)
if self.refund[string(addr)] == nil {
self.refund[string(addr)] = new(big.Int)
type refund struct {
gas, price *big.Int
}
self.refund[string(addr)].Add(self.refund[string(addr)], amount)
func (self *State) Refund(addr []byte, gas, price *big.Int) {
self.refund[string(addr)] = append(self.refund[string(addr)], refund{gas, price})
}
func (self *State) AddBalance(addr []byte, amount *big.Int) {
@ -276,15 +274,20 @@ func (s *State) Sync() {
func (self *State) Empty() {
self.stateObjects = make(map[string]*StateObject)
self.refund = make(map[string]*big.Int)
self.refund = make(map[string][]refund)
}
func (self *State) Update() {
func (self *State) Update(gasUsed *big.Int) {
var deleted bool
// Refund any gas that's left
for addr, amount := range self.refund {
self.GetStateObject([]byte(addr)).AddBalance(amount)
uhalf := new(big.Int).Div(gasUsed, ethutil.Big2)
for addr, refs := range self.refund {
for _, ref := range refs {
refund := ethutil.BigMin(uhalf, ref.gas)
self.GetStateObject([]byte(addr)).AddBalance(refund.Mul(refund, ref.price))
}
}
for _, stateObject := range self.stateObjects {