Skip to content

Commit 17b481e

Browse files
committed
Merge pull request ethereum#1581 from obscuren/olympic
cmd, core, eth: support for the olympic network
2 parents 97cdf84 + dcdb705 commit 17b481e

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

cmd/geth/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
280280
utils.BootnodesFlag,
281281
utils.DataDirFlag,
282282
utils.BlockchainVersionFlag,
283+
utils.OlympicFlag,
283284
utils.CacheFlag,
284285
utils.JSpathFlag,
285286
utils.ListenPortFlag,
@@ -346,6 +347,9 @@ func main() {
346347

347348
func run(ctx *cli.Context) {
348349
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
350+
if ctx.GlobalBool(utils.OlympicFlag.Name) {
351+
utils.InitOlympic()
352+
}
349353

350354
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
351355
ethereum, err := eth.New(cfg)

cmd/utils/cmd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"bufio"
2222
"fmt"
2323
"io"
24+
"math/big"
2425
"os"
2526
"os/signal"
2627
"regexp"
@@ -32,6 +33,7 @@ import (
3233
"github.com/ethereum/go-ethereum/eth"
3334
"github.com/ethereum/go-ethereum/logger"
3435
"github.com/ethereum/go-ethereum/logger/glog"
36+
"github.com/ethereum/go-ethereum/params"
3537
"github.com/ethereum/go-ethereum/rlp"
3638
"github.com/peterh/liner"
3739
)
@@ -143,6 +145,15 @@ func StartEthereum(ethereum *eth.Ethereum) {
143145
}()
144146
}
145147

148+
func InitOlympic() {
149+
params.DurationLimit = big.NewInt(8)
150+
params.GenesisGasLimit = big.NewInt(3141592)
151+
params.MinGasLimit = big.NewInt(125000)
152+
params.MaximumExtraDataSize = big.NewInt(1024)
153+
NetworkIdFlag.Value = 0
154+
core.BlockReward = big.NewInt(1.5e+18)
155+
}
156+
146157
func FormatTransactionData(data string) []byte {
147158
d := common.StringToByteFunc(data, func(s string) (ret []byte) {
148159
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
@@ -203,6 +214,11 @@ func ImportChain(chain *core.ChainManager, fn string) error {
203214
} else if err != nil {
204215
return fmt.Errorf("at block %d: %v", n, err)
205216
}
217+
// don't import first block
218+
if b.NumberU64() == 0 {
219+
i--
220+
continue
221+
}
206222
blocks[i] = &b
207223
n++
208224
}
@@ -218,6 +234,7 @@ func ImportChain(chain *core.ChainManager, fn string) error {
218234
batch, blocks[0].Hash().Bytes()[:4], blocks[i-1].Hash().Bytes()[:4])
219235
continue
220236
}
237+
221238
if _, err := chain.InsertChain(blocks[:i]); err != nil {
222239
return fmt.Errorf("invalid block %d: %v", n, err)
223240
}

cmd/utils/flags.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ var (
131131
Usage: "Megabytes of memory allocated to internal caching",
132132
Value: 0,
133133
}
134+
OlympicFlag = cli.BoolFlag{
135+
Name: "olympic",
136+
Usage: "Use olympic style protocol",
137+
}
134138

135139
// miner settings
136140
MinerThreadsFlag = cli.IntFlag{
@@ -402,6 +406,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
402406
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
403407
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
404408
Port: ctx.GlobalString(ListenPortFlag.Name),
409+
Olympic: ctx.GlobalBool(OlympicFlag.Name),
405410
NAT: MakeNAT(ctx),
406411
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
407412
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
@@ -444,6 +449,13 @@ func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, ex
444449
if extraDB, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "extra"), cache); err != nil {
445450
Fatalf("Could not open database: %v", err)
446451
}
452+
if ctx.GlobalBool(OlympicFlag.Name) {
453+
InitOlympic()
454+
_, err := core.WriteTestNetGenesisBlock(stateDB, blockDB, 42)
455+
if err != nil {
456+
glog.Fatalln(err)
457+
}
458+
}
447459

448460
eventMux := new(event.TypeMux)
449461
pow := ethash.New()

eth/backend.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type Config struct {
7878
GenesisNonce int
7979
GenesisFile string
8080
GenesisBlock *types.Block // used by block tests
81+
Olympic bool
8182

8283
BlockChainVersion int
8384
SkipBcVersionCheck bool // e.g. blockchain export
@@ -302,6 +303,14 @@ func New(config *Config) (*Ethereum, error) {
302303
glog.V(logger.Info).Infof("Successfully wrote genesis block. New genesis hash = %x\n", block.Hash())
303304
}
304305

306+
if config.Olympic {
307+
_, err := core.WriteTestNetGenesisBlock(stateDb, blockDb, 42)
308+
if err != nil {
309+
return nil, err
310+
}
311+
glog.V(logger.Error).Infoln("Starting Olympic network")
312+
}
313+
305314
// This is for testing only.
306315
if config.GenesisBlock != nil {
307316
core.WriteBlock(blockDb, config.GenesisBlock)

0 commit comments

Comments
 (0)