Skip to content

Commit 4044a8c

Browse files
committed
Merge pull request ethereum#2258 from obscuren/release/1.3.4
Homestead Release Candidate
2 parents c541b38 + 61be63b commit 4044a8c

File tree

863 files changed

+196405
-10368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

863 files changed

+196405
-10368
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ env:
2020
global:
2121
- secure: "U2U1AmkU4NJBgKR/uUAebQY87cNL0+1JHjnLOmmXwxYYyj5ralWb1aSuSH3qSXiT93qLBmtaUkuv9fberHVqrbAeVlztVdUsKAq7JMQH+M99iFkC9UiRMqHmtjWJ0ok4COD1sRYixxi21wb/JrMe3M1iL4QJVS61iltjHhVdM64="
2222
sudo: false
23-
addons:
24-
apt:
25-
packages:
26-
- libgmp3-dev
2723
notifications:
2824
webhooks:
2925
urls:

Makefile

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
GOBIN = build/bin
1212

13-
CROSSDEPS = https://gmplib.org/download/gmp/gmp-6.0.0a.tar.bz2
13+
MODE ?= default
1414
GO ?= latest
1515

1616
geth:
@@ -26,32 +26,51 @@ geth-linux: xgo geth-linux-arm geth-linux-386 geth-linux-amd64
2626
@echo "Linux cross compilation done:"
2727
@ls -l $(GOBIN)/geth-linux-*
2828

29-
geth-linux-arm: xgo
30-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=linux/arm -v $(shell build/flags.sh) ./cmd/geth
31-
@echo "Linux ARM cross compilation done:"
32-
@ls -l $(GOBIN)/geth-linux-* | grep arm
33-
3429
geth-linux-386: xgo
35-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=linux/386 -v $(shell build/flags.sh) ./cmd/geth
30+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=linux/386 -v $(shell build/flags.sh) ./cmd/geth
3631
@echo "Linux 386 cross compilation done:"
3732
@ls -l $(GOBIN)/geth-linux-* | grep 386
3833

3934
geth-linux-amd64: xgo
40-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=linux/amd64 -v $(shell build/flags.sh) ./cmd/geth
35+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=linux/amd64 -v $(shell build/flags.sh) ./cmd/geth
4136
@echo "Linux amd64 cross compilation done:"
4237
@ls -l $(GOBIN)/geth-linux-* | grep amd64
4338

44-
geth-darwin: xgo geth-darwin-386 geth-darwin-amd64
39+
geth-linux-arm: geth-linux-arm-5 geth-linux-arm-6 geth-linux-arm-7 geth-linux-arm64
40+
@echo "Linux ARM cross compilation done:"
41+
@ls -l $(GOBIN)/geth-linux-* | grep arm
42+
43+
geth-linux-arm-5: xgo
44+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=linux/arm-5 -v $(shell build/flags.sh) ./cmd/geth
45+
@echo "Linux ARMv5 cross compilation done:"
46+
@ls -l $(GOBIN)/geth-linux-* | grep arm-5
47+
48+
geth-linux-arm-6: xgo
49+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=linux/arm-6 -v $(shell build/flags.sh) ./cmd/geth
50+
@echo "Linux ARMv6 cross compilation done:"
51+
@ls -l $(GOBIN)/geth-linux-* | grep arm-6
52+
53+
geth-linux-arm-7: xgo
54+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=linux/arm-7 -v $(shell build/flags.sh) ./cmd/geth
55+
@echo "Linux ARMv7 cross compilation done:"
56+
@ls -l $(GOBIN)/geth-linux-* | grep arm-7
57+
58+
geth-linux-arm64: xgo
59+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=linux/arm64 -v $(shell build/flags.sh) ./cmd/geth
60+
@echo "Linux ARM64 cross compilation done:"
61+
@ls -l $(GOBIN)/geth-linux-* | grep arm64
62+
63+
geth-darwin: geth-darwin-386 geth-darwin-amd64
4564
@echo "Darwin cross compilation done:"
4665
@ls -l $(GOBIN)/geth-darwin-*
4766

4867
geth-darwin-386: xgo
49-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=darwin/386 -v $(shell build/flags.sh) ./cmd/geth
68+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=darwin/386 -v $(shell build/flags.sh) ./cmd/geth
5069
@echo "Darwin 386 cross compilation done:"
5170
@ls -l $(GOBIN)/geth-darwin-* | grep 386
5271

5372
geth-darwin-amd64: xgo
54-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=darwin/amd64 -v $(shell build/flags.sh) ./cmd/geth
73+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=darwin/amd64 -v $(shell build/flags.sh) ./cmd/geth
5574
@echo "Darwin amd64 cross compilation done:"
5675
@ls -l $(GOBIN)/geth-darwin-* | grep amd64
5776

@@ -60,28 +79,33 @@ geth-windows: xgo geth-windows-386 geth-windows-amd64
6079
@ls -l $(GOBIN)/geth-windows-*
6180

6281
geth-windows-386: xgo
63-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=windows/386 -v $(shell build/flags.sh) ./cmd/geth
82+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=windows/386 -v $(shell build/flags.sh) ./cmd/geth
6483
@echo "Windows 386 cross compilation done:"
6584
@ls -l $(GOBIN)/geth-windows-* | grep 386
6685

6786
geth-windows-amd64: xgo
68-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=windows/amd64 -v $(shell build/flags.sh) ./cmd/geth
87+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=windows/amd64 -v $(shell build/flags.sh) ./cmd/geth
6988
@echo "Windows amd64 cross compilation done:"
7089
@ls -l $(GOBIN)/geth-windows-* | grep amd64
7190

72-
geth-android: xgo geth-android-16 geth-android-21
91+
geth-android: xgo
92+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=android/* -v $(shell build/flags.sh) ./cmd/geth
7393
@echo "Android cross compilation done:"
7494
@ls -l $(GOBIN)/geth-android-*
7595

76-
geth-android-16: xgo
77-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=android-16/* -v $(shell build/flags.sh) ./cmd/geth
78-
@echo "Android 16 cross compilation done:"
79-
@ls -l $(GOBIN)/geth-android-16-*
96+
geth-ios: geth-ios-arm-7 geth-ios-arm64
97+
@echo "iOS cross compilation done:"
98+
@ls -l $(GOBIN)/geth-ios-*
99+
100+
geth-ios-arm-7: xgo
101+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=ios/arm-7 -v $(shell build/flags.sh) ./cmd/geth
102+
@echo "iOS ARMv7 cross compilation done:"
103+
@ls -l $(GOBIN)/geth-ios-* | grep arm-7
80104

81-
geth-android-21: xgo
82-
build/env.sh $(GOBIN)/xgo --go=$(GO) --dest=$(GOBIN) --deps=$(CROSSDEPS) --targets=android-21/* -v $(shell build/flags.sh) ./cmd/geth
83-
@echo "Android 21 cross compilation done:"
84-
@ls -l $(GOBIN)/geth-android-21-*
105+
geth-ios-arm64: xgo
106+
build/env.sh $(GOBIN)/xgo --go=$(GO) --buildmode=$(MODE) --dest=$(GOBIN) --targets=ios-7.0/arm64 -v $(shell build/flags.sh) ./cmd/geth
107+
@echo "iOS ARM64 cross compilation done:"
108+
@ls -l $(GOBIN)/geth-ios-* | grep arm64
85109

86110
evm:
87111
build/env.sh $(GOROOT)/bin/go install -v $(shell build/flags.sh) ./cmd/evm

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ For prerequisites and detailed build instructions please read the
3030
[Installation Instructions](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum)
3131
on the wiki.
3232

33-
Building geth requires two external dependencies, Go and GMP.
33+
Building geth requires both a Go and a C compiler.
3434
You can install them using your favourite package manager.
3535
Once the dependencies are installed, run
3636

cmd/evm/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,15 @@ func (self *VMEnv) Call(caller vm.ContractRef, addr common.Address, data []byte,
225225
self.Gas = gas
226226
return core.Call(self, caller, addr, data, gas, price, value)
227227
}
228+
228229
func (self *VMEnv) CallCode(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {
229230
return core.CallCode(self, caller, addr, data, gas, price, value)
230231
}
231232

233+
func (self *VMEnv) DelegateCall(caller vm.ContractRef, addr common.Address, data []byte, gas, price *big.Int) ([]byte, error) {
234+
return core.DelegateCall(self, caller, addr, data, gas, price)
235+
}
236+
232237
func (self *VMEnv) Create(caller vm.ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) {
233238
return core.Create(self, caller, data, gas, price, value)
234239
}

cmd/geth/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ import (
4848

4949
const (
5050
ClientIdentifier = "Geth"
51-
Version = "1.3.3"
51+
Version = "1.3.4"
5252
VersionMajor = 1
5353
VersionMinor = 3
54-
VersionPatch = 3
54+
VersionPatch = 4
5555
)
5656

5757
var (

cmd/utils/flags.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ var (
183183
GasPriceFlag = cli.StringFlag{
184184
Name: "gasprice",
185185
Usage: "Minimal gas price to accept for mining a transactions",
186-
Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(),
186+
Value: new(big.Int).Mul(big.NewInt(20), common.Shannon).String(),
187187
}
188188
ExtraDataFlag = cli.StringFlag{
189189
Name: "extradata",
@@ -356,7 +356,7 @@ var (
356356
GpoMinGasPriceFlag = cli.StringFlag{
357357
Name: "gpomin",
358358
Usage: "Minimum suggested gas price",
359-
Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(),
359+
Value: new(big.Int).Mul(big.NewInt(20), common.Shannon).String(),
360360
}
361361
GpoMaxGasPriceFlag = cli.StringFlag{
362362
Name: "gpomax",
@@ -472,6 +472,8 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
472472
cfg.DataDir += "/testnet"
473473
cfg.NetworkId = 2
474474
cfg.TestNet = true
475+
// overwrite homestead block
476+
params.HomesteadBlock = params.TestNetHomesteadBlock
475477
}
476478

477479
if ctx.GlobalBool(VMEnableJitFlag.Name) {

core/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
8282
return func(i int, gen *BlockGen) {
8383
toaddr := common.Address{}
8484
data := make([]byte, nbytes)
85-
gas := IntrinsicGas(data)
85+
gas := IntrinsicGas(data, false, false)
8686
tx, _ := types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data).SignECDSA(benchRootKey)
8787
gen.AddTx(tx)
8888
}

core/block_validator.go

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import (
3030
"gopkg.in/fatih/set.v0"
3131
)
3232

33+
var (
34+
ExpDiffPeriod = big.NewInt(100000)
35+
big10 = big.NewInt(10)
36+
bigMinus99 = big.NewInt(-99)
37+
)
38+
3339
// BlockValidator is responsible for validating block headers, uncles and
3440
// processed state.
3541
//
@@ -111,7 +117,7 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
111117
// For valid blocks this should always validate to true.
112118
rbloom := types.CreateBloom(receipts)
113119
if rbloom != header.Bloom {
114-
return fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
120+
return fmt.Errorf("unable to replicate block's bloom=%x vs calculated bloom=%x", header.Bloom, rbloom)
115121
}
116122
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]]))
117123
receiptSha := types.DeriveSha(receipts)
@@ -241,3 +247,127 @@ func ValidateHeader(pow pow.PoW, header *types.Header, parent *types.Header, che
241247
}
242248
return nil
243249
}
250+
251+
// CalcDifficulty is the difficulty adjustment algorithm. It returns
252+
// the difficulty that a new block should have when created at time
253+
// given the parent block's time and difficulty.
254+
func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
255+
if params.IsHomestead(new(big.Int).Add(parentNumber, common.Big1)) {
256+
return calcDifficultyHomestead(time, parentTime, parentNumber, parentDiff)
257+
} else {
258+
return calcDifficultyFrontier(time, parentTime, parentNumber, parentDiff)
259+
}
260+
}
261+
262+
func calcDifficultyHomestead(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
263+
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.mediawiki
264+
// algorithm:
265+
// diff = (parent_diff +
266+
// (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
267+
// ) + 2^(periodCount - 2)
268+
269+
bigTime := new(big.Int).SetUint64(time)
270+
bigParentTime := new(big.Int).SetUint64(parentTime)
271+
272+
// holds intermediate values to make the algo easier to read & audit
273+
x := new(big.Int)
274+
y := new(big.Int)
275+
276+
// 1 - (block_timestamp -parent_timestamp) // 10
277+
x.Sub(bigTime, bigParentTime)
278+
x.Div(x, big10)
279+
x.Sub(common.Big1, x)
280+
281+
// max(1 - (block_timestamp - parent_timestamp) // 10, -99)))
282+
if x.Cmp(bigMinus99) < 0 {
283+
x.Set(bigMinus99)
284+
}
285+
286+
// (parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
287+
y.Div(parentDiff, params.DifficultyBoundDivisor)
288+
x.Mul(y, x)
289+
x.Add(parentDiff, x)
290+
291+
// minimum difficulty can ever be (before exponential factor)
292+
if x.Cmp(params.MinimumDifficulty) < 0 {
293+
x = params.MinimumDifficulty
294+
}
295+
296+
// for the exponential factor
297+
periodCount := new(big.Int).Add(parentNumber, common.Big1)
298+
periodCount.Div(periodCount, ExpDiffPeriod)
299+
300+
// the exponential factor, commonly refered to as "the bomb"
301+
// diff = diff + 2^(periodCount - 2)
302+
if periodCount.Cmp(common.Big1) > 0 {
303+
y.Sub(periodCount, common.Big2)
304+
y.Exp(common.Big2, y, nil)
305+
x.Add(x, y)
306+
}
307+
308+
return x
309+
}
310+
311+
func calcDifficultyFrontier(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
312+
diff := new(big.Int)
313+
adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor)
314+
bigTime := new(big.Int)
315+
bigParentTime := new(big.Int)
316+
317+
bigTime.SetUint64(time)
318+
bigParentTime.SetUint64(parentTime)
319+
320+
if bigTime.Sub(bigTime, bigParentTime).Cmp(params.DurationLimit) < 0 {
321+
diff.Add(parentDiff, adjust)
322+
} else {
323+
diff.Sub(parentDiff, adjust)
324+
}
325+
if diff.Cmp(params.MinimumDifficulty) < 0 {
326+
diff = params.MinimumDifficulty
327+
}
328+
329+
periodCount := new(big.Int).Add(parentNumber, common.Big1)
330+
periodCount.Div(periodCount, ExpDiffPeriod)
331+
if periodCount.Cmp(common.Big1) > 0 {
332+
// diff = diff + 2^(periodCount - 2)
333+
expDiff := periodCount.Sub(periodCount, common.Big2)
334+
expDiff.Exp(common.Big2, expDiff, nil)
335+
diff.Add(diff, expDiff)
336+
diff = common.BigMax(diff, params.MinimumDifficulty)
337+
}
338+
339+
return diff
340+
}
341+
342+
// CalcGasLimit computes the gas limit of the next block after parent.
343+
// The result may be modified by the caller.
344+
// This is miner strategy, not consensus protocol.
345+
func CalcGasLimit(parent *types.Block) *big.Int {
346+
// contrib = (parentGasUsed * 3 / 2) / 1024
347+
contrib := new(big.Int).Mul(parent.GasUsed(), big.NewInt(3))
348+
contrib = contrib.Div(contrib, big.NewInt(2))
349+
contrib = contrib.Div(contrib, params.GasLimitBoundDivisor)
350+
351+
// decay = parentGasLimit / 1024 -1
352+
decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
353+
decay.Sub(decay, big.NewInt(1))
354+
355+
/*
356+
strategy: gasLimit of block-to-mine is set based on parent's
357+
gasUsed value. if parentGasUsed > parentGasLimit * (2/3) then we
358+
increase it, otherwise lower it (or leave it unchanged if it's right
359+
at that usage) the amount increased/decreased depends on how far away
360+
from parentGasLimit * (2/3) parentGasUsed is.
361+
*/
362+
gl := new(big.Int).Sub(parent.GasLimit(), decay)
363+
gl = gl.Add(gl, contrib)
364+
gl.Set(common.BigMax(gl, params.MinGasLimit))
365+
366+
// however, if we're now below the target (GenesisGasLimit) we increase the
367+
// limit as much as we can (parentGasLimit / 1024 -1)
368+
if gl.Cmp(params.GenesisGasLimit) < 0 {
369+
gl.Add(parent.GasLimit(), decay)
370+
gl.Set(common.BigMin(gl, params.GenesisGasLimit))
371+
}
372+
return gl
373+
}

0 commit comments

Comments
 (0)