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

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

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

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

@ -157,12 +157,24 @@ func (self *StateTransition) TransitionState() (err error) {
} }
// Pay data gas // Pay data gas
dataPrice := big.NewInt(int64(len(self.data))) var dgas int64
dataPrice.Mul(dataPrice, vm.GasData) for _, byt := range self.data {
if err = self.UseGas(dataPrice); err != nil { 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 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 { if sender.Balance().Cmp(self.value) < 0 {
return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Balance) return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Balance)
} }

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

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

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

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

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

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

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