diff options
author | obscuren <geffobscura@gmail.com> | 2014-11-29 04:44:34 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-11-29 04:44:34 +0800 |
commit | 1bce02eff70db43b98d68fcd094fd2e15745b021 (patch) | |
tree | a69acb327b4f71d59b297ca778450c128dce85f8 | |
parent | 8cf9ed0ea588e97f2baf0f834248727e8fbca18f (diff) | |
parent | a3559c5e1b469890bb8d71e9992175febaae31c7 (diff) | |
download | go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar.gz go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.tar.zst go-tangerine-1bce02eff70db43b98d68fcd094fd2e15745b021.zip |
Fixed merge
-rw-r--r-- | chain/block_manager.go | 7 | ||||
-rw-r--r-- | chain/chain_manager.go | 2 | ||||
-rw-r--r-- | chain/genesis.go | 2 | ||||
-rw-r--r-- | chain/state_transition.go | 18 | ||||
-rw-r--r-- | chain/types/block.go | 36 | ||||
-rw-r--r-- | cmd/ethereum/main.go | 3 | ||||
-rw-r--r-- | cmd/mist/main.go | 2 | ||||
-rwxr-xr-x | install.sh | 41 | ||||
-rw-r--r-- | miner/miner.go | 3 | ||||
-rw-r--r-- | peer.go | 2 | ||||
-rw-r--r-- | state/state.go | 29 |
11 files changed, 76 insertions, 69 deletions
diff --git a/chain/block_manager.go b/chain/block_manager.go index e652ad10e..4cc43840c 100644 --- a/chain/block_manager.go +++ b/chain/block_manager.go @@ -155,10 +155,11 @@ done: } } + txGas.Sub(txGas, st.gas) + // Update the state with pending changes - state.Update() + state.Update(txGas) - txGas.Sub(txGas, st.gas) 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()) diff --git a/chain/chain_manager.go b/chain/chain_manager.go index 11e16fa7d..115acb1c8 100644 --- a/chain/chain_manager.go +++ b/chain/chain_manager.go @@ -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) diff --git a/chain/genesis.go b/chain/genesis.go index 14117a82c..85e85d1ed 100644 --- a/chain/genesis.go +++ b/chain/genesis.go @@ -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 diff --git a/chain/state_transition.go b/chain/state_transition.go index 789698675..53b1f6e2d 100644 --- a/chain/state_transition.go +++ b/chain/state_transition.go @@ -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) } diff --git a/chain/types/block.go b/chain/types/block.go index b311433e3..5c8bb5f6c 100644 --- a/chain/types/block.go +++ b/chain/types/block.go @@ -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 @@ -124,16 +122,15 @@ func CreateBlock(root interface{}, extra string) *Block { block := &Block{ - PrevHash: prevHash, - Coinbase: base, - Difficulty: Difficulty, - Nonce: Nonce, - Time: time.Now().Unix(), - Extra: extra, - UncleSha: nil, - GasUsed: new(big.Int), - MinGasPrice: new(big.Int), - GasLimit: new(big.Int), + PrevHash: prevHash, + Coinbase: base, + Difficulty: Difficulty, + Nonce: Nonce, + Time: time.Now().Unix(), + Extra: extra, + UncleSha: nil, + GasUsed: 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, diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index aa933c4e7..c351167f2 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -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") diff --git a/cmd/mist/main.go b/cmd/mist/main.go index bc05d4f3d..39beeafdb 100644 --- a/cmd/mist/main.go +++ b/cmd/mist/main.go @@ -31,7 +31,7 @@ import ( const ( ClientIdentifier = "Mist" - Version = "0.7.5" + Version = "0.7.6" ) var ethereum *eth.Ethereum diff --git a/install.sh b/install.sh index f6232af83..30a3802e4 100755 --- a/install.sh +++ b/install.sh @@ -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 :-)" diff --git a/miner/miner.go b/miner/miner.go index 795385424..c5bff5690 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -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)) @@ -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 diff --git a/state/state.go b/state/state.go index 3abf1545b..0a7f717fe 100644 --- a/state/state.go +++ b/state/state.go @@ -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 { |