Skip to content

Commit 488528e

Browse files
committed
Merge pull request bnb-chain#2497 from karalabe/version-contract-3
Geth release oracle
2 parents 1c20313 + 4536b99 commit 488528e

13 files changed

Lines changed: 1407 additions & 53 deletions

File tree

‎accounts/abi/bind/backend.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ type ContractCaller interface {
4747
// used when the user does not provide some needed values, but rather leaves it up
4848
// to the transactor to decide.
4949
type ContractTransactor interface {
50-
// Nonce retrieves the current pending nonce associated with an account.
50+
// PendingAccountNonce retrieves the current pending nonce associated with an
51+
// account.
5152
PendingAccountNonce(account common.Address) (uint64, error)
5253

5354
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
@@ -62,7 +63,7 @@ type ContractTransactor interface {
6263
EstimateGasLimit(sender common.Address, contract *common.Address, value *big.Int, data []byte) (*big.Int, error)
6364

6465
// SendTransaction injects the transaction into the pending pool for execution.
65-
SendTransaction(*types.Transaction) error
66+
SendTransaction(tx *types.Transaction) error
6667
}
6768

6869
// ContractBackend defines the methods needed to allow operating with contract

‎cmd/geth/main.go‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package main
1919

2020
import (
21+
"encoding/hex"
2122
"fmt"
2223
"io/ioutil"
2324
"os"
@@ -41,31 +42,48 @@ import (
4142
"github.com/ethereum/go-ethereum/metrics"
4243
"github.com/ethereum/go-ethereum/node"
4344
"github.com/ethereum/go-ethereum/params"
45+
"github.com/ethereum/go-ethereum/release"
4446
"github.com/ethereum/go-ethereum/rlp"
4547
)
4648

4749
const (
48-
ClientIdentifier = "Geth"
49-
Version = "1.5.0-unstable"
50-
VersionMajor = 1
51-
VersionMinor = 5
52-
VersionPatch = 0
50+
clientIdentifier = "Geth" // Client identifier to advertise over the network
51+
versionMajor = 1 // Major version component of the current release
52+
versionMinor = 5 // Minor version component of the current release
53+
versionPatch = 0 // Patch version component of the current release
54+
versionMeta = "unstable" // Version metadata to append to the version string
55+
56+
versionOracle = "0xfa7b9770ca4cb04296cac84f37736d4041251cdf" // Ethereum address of the Geth release oracle
5357
)
5458

5559
var (
56-
gitCommit string // set via linker flagg
57-
nodeNameVersion string
58-
app *cli.App
60+
gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
61+
verString string // Combined textual representation of all the version components
62+
relConfig release.Config // Structured version information and release oracle config
63+
app *cli.App
5964
)
6065

6166
func init() {
62-
if gitCommit == "" {
63-
nodeNameVersion = Version
64-
} else {
65-
nodeNameVersion = Version + "-" + gitCommit[:8]
67+
// Construct the textual version string from the individual components
68+
verString = fmt.Sprintf("%d.%d.%d", versionMajor, versionMinor, versionPatch)
69+
if versionMeta != "" {
70+
verString += "-" + versionMeta
71+
}
72+
if gitCommit != "" {
73+
verString += "-" + gitCommit[:8]
6674
}
75+
// Construct the version release oracle configuration
76+
relConfig.Oracle = common.HexToAddress(versionOracle)
6777

68-
app = utils.NewApp(Version, "the go-ethereum command line interface")
78+
relConfig.Major = uint32(versionMajor)
79+
relConfig.Minor = uint32(versionMinor)
80+
relConfig.Patch = uint32(versionPatch)
81+
82+
commit, _ := hex.DecodeString(gitCommit)
83+
copy(relConfig.Commit[:], commit)
84+
85+
// Initialize the CLI app and start Geth
86+
app = utils.NewApp(verString, "the go-ethereum command line interface")
6987
app.Action = geth
7088
app.HideVersion = true // we have a command to print the version
7189
app.Commands = []cli.Command{
@@ -257,7 +275,7 @@ func makeDefaultExtra() []byte {
257275
Name string
258276
GoVersion string
259277
Os string
260-
}{uint(VersionMajor<<16 | VersionMinor<<8 | VersionPatch), ClientIdentifier, runtime.Version(), runtime.GOOS}
278+
}{uint(versionMajor<<16 | versionMinor<<8 | versionPatch), clientIdentifier, runtime.Version(), runtime.GOOS}
261279
extra, err := rlp.EncodeToBytes(clientInfo)
262280
if err != nil {
263281
glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
@@ -275,7 +293,7 @@ func makeDefaultExtra() []byte {
275293
// It creates a default node based on the command line arguments and runs it in
276294
// blocking mode, waiting for it to be shut down.
277295
func geth(ctx *cli.Context) {
278-
node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx)
296+
node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
279297
startNode(ctx, node)
280298
node.Wait()
281299
}
@@ -339,7 +357,7 @@ func initGenesis(ctx *cli.Context) {
339357
// same time.
340358
func console(ctx *cli.Context) {
341359
// Create and start the node based on the CLI flags
342-
node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx)
360+
node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
343361
startNode(ctx, node)
344362

345363
// Attach to the newly started node, and either execute script or become interactive
@@ -372,7 +390,7 @@ func console(ctx *cli.Context) {
372390
// of the JavaScript files specified as command arguments.
373391
func execScripts(ctx *cli.Context) {
374392
// Create and start the node based on the CLI flags
375-
node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx)
393+
node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
376394
startNode(ctx, node)
377395
defer node.Stop()
378396

@@ -488,11 +506,8 @@ func gpubench(ctx *cli.Context) {
488506
}
489507

490508
func version(c *cli.Context) {
491-
fmt.Println(ClientIdentifier)
492-
fmt.Println("Version:", Version)
493-
if gitCommit != "" {
494-
fmt.Println("Git Commit:", gitCommit)
495-
}
509+
fmt.Println(clientIdentifier)
510+
fmt.Println("Version:", version)
496511
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
497512
fmt.Println("Network Id:", c.GlobalInt(utils.NetworkIdFlag.Name))
498513
fmt.Println("Go Version:", runtime.Version())

‎cmd/utils/flags.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
"github.com/ethereum/go-ethereum/p2p/nat"
4949
"github.com/ethereum/go-ethereum/params"
5050
"github.com/ethereum/go-ethereum/pow"
51+
"github.com/ethereum/go-ethereum/release"
5152
"github.com/ethereum/go-ethereum/rpc"
5253
"github.com/ethereum/go-ethereum/whisper"
5354
)
@@ -641,7 +642,7 @@ func MakePasswordList(ctx *cli.Context) []string {
641642

642643
// MakeSystemNode sets up a local node, configures the services to launch and
643644
// assembles the P2P protocol stack.
644-
func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.Node {
645+
func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node {
645646
// Avoid conflicting network flags
646647
networks, netFlags := 0, []cli.BoolFlag{DevModeFlag, TestNetFlag, OlympicFlag}
647648
for _, flag := range netFlags {
@@ -772,7 +773,11 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
772773
Fatalf("Failed to register the Whisper service: %v", err)
773774
}
774775
}
775-
776+
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
777+
return release.NewReleaseService(ctx, relconf)
778+
}); err != nil {
779+
Fatalf("Failed to register the Geth release oracle service: %v", err)
780+
}
776781
return stack
777782
}
778783

‎eth/api.go‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ import (
5252
"golang.org/x/net/context"
5353
)
5454

55-
// ErrNoCode is returned by call and transact operations for which the requested
55+
// errNoCode is returned by call and transact operations for which the requested
5656
// recipient contract to operate on does not exist in the state db or does not
5757
// have any code associated with it (i.e. suicided).
5858
//
5959
// Please note, this error string is part of the RPC API and is expected by the
6060
// native contract bindings to signal this particular error. Do not change this
6161
// as it will break all dependent code!
62-
var ErrNoCode = errors.New("no contract code at given address")
62+
var errNoCode = errors.New("no contract code at given address")
6363

6464
const defaultGas = uint64(90000)
6565

@@ -107,8 +107,11 @@ type PublicEthereumAPI struct {
107107
}
108108

109109
// NewPublicEthereumAPI creates a new Ethereum protocol API.
110-
func NewPublicEthereumAPI(e *Ethereum, gpo *GasPriceOracle) *PublicEthereumAPI {
111-
return &PublicEthereumAPI{e, gpo}
110+
func NewPublicEthereumAPI(e *Ethereum) *PublicEthereumAPI {
111+
return &PublicEthereumAPI{
112+
e: e,
113+
gpo: e.gpo,
114+
}
112115
}
113116

114117
// GasPrice returns a suggestion for a gas price.
@@ -717,7 +720,7 @@ func (s *PublicBlockChainAPI) doCall(args CallArgs, blockNr rpc.BlockNumber) (st
717720
// If there's no code to interact with, respond with an appropriate error
718721
if args.To != nil {
719722
if code := stateDb.GetCode(*args.To); len(code) == 0 {
720-
return "0x", nil, ErrNoCode
723+
return "0x", nil, errNoCode
721724
}
722725
}
723726
// Retrieve the account state object to interact with
@@ -914,18 +917,17 @@ type PublicTransactionPoolAPI struct {
914917
}
915918

916919
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
917-
func NewPublicTransactionPoolAPI(e *Ethereum, gpo *GasPriceOracle) *PublicTransactionPoolAPI {
920+
func NewPublicTransactionPoolAPI(e *Ethereum) *PublicTransactionPoolAPI {
918921
api := &PublicTransactionPoolAPI{
919-
eventMux: e.EventMux(),
920-
gpo: gpo,
921-
chainDb: e.ChainDb(),
922-
bc: e.BlockChain(),
923-
am: e.AccountManager(),
924-
txPool: e.TxPool(),
925-
miner: e.Miner(),
922+
eventMux: e.eventMux,
923+
gpo: e.gpo,
924+
chainDb: e.chainDb,
925+
bc: e.blockchain,
926+
am: e.accountManager,
927+
txPool: e.txPool,
928+
miner: e.miner,
926929
pendingTxSubs: make(map[string]rpc.Subscription),
927930
}
928-
929931
go api.subscriptionLoop()
930932

931933
return api

‎eth/backend.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type Ethereum struct {
119119
protocolManager *ProtocolManager
120120
SolcPath string
121121
solc *compiler.Solidity
122+
gpo *GasPriceOracle
122123

123124
GpoMinGasPrice *big.Int
124125
GpoMaxGasPrice *big.Int
@@ -260,6 +261,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
260261
}
261262
return nil, err
262263
}
264+
eth.gpo = NewGasPriceOracle(eth)
265+
263266
newPool := core.NewTxPool(eth.chainConfig, eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit)
264267
eth.txPool = newPool
265268

@@ -276,34 +279,31 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
276279
// APIs returns the collection of RPC services the ethereum package offers.
277280
// NOTE, some of these services probably need to be moved to somewhere else.
278281
func (s *Ethereum) APIs() []rpc.API {
279-
// share gas price oracle in API's
280-
gpo := NewGasPriceOracle(s)
281-
282282
return []rpc.API{
283283
{
284284
Namespace: "eth",
285285
Version: "1.0",
286-
Service: NewPublicEthereumAPI(s, gpo),
286+
Service: NewPublicEthereumAPI(s),
287287
Public: true,
288288
}, {
289289
Namespace: "eth",
290290
Version: "1.0",
291-
Service: NewPublicAccountAPI(s.AccountManager()),
291+
Service: NewPublicAccountAPI(s.accountManager),
292292
Public: true,
293293
}, {
294294
Namespace: "personal",
295295
Version: "1.0",
296-
Service: NewPrivateAccountAPI(s.AccountManager()),
296+
Service: NewPrivateAccountAPI(s.accountManager),
297297
Public: false,
298298
}, {
299299
Namespace: "eth",
300300
Version: "1.0",
301-
Service: NewPublicBlockChainAPI(s.chainConfig, s.BlockChain(), s.Miner(), s.ChainDb(), gpo, s.EventMux(), s.AccountManager()),
301+
Service: NewPublicBlockChainAPI(s.chainConfig, s.blockchain, s.miner, s.chainDb, s.gpo, s.eventMux, s.accountManager),
302302
Public: true,
303303
}, {
304304
Namespace: "eth",
305305
Version: "1.0",
306-
Service: NewPublicTransactionPoolAPI(s, gpo),
306+
Service: NewPublicTransactionPoolAPI(s),
307307
Public: true,
308308
}, {
309309
Namespace: "eth",
@@ -313,7 +313,7 @@ func (s *Ethereum) APIs() []rpc.API {
313313
}, {
314314
Namespace: "eth",
315315
Version: "1.0",
316-
Service: downloader.NewPublicDownloaderAPI(s.Downloader(), s.EventMux()),
316+
Service: downloader.NewPublicDownloaderAPI(s.protocolManager.downloader, s.eventMux),
317317
Public: true,
318318
}, {
319319
Namespace: "miner",
@@ -328,7 +328,7 @@ func (s *Ethereum) APIs() []rpc.API {
328328
}, {
329329
Namespace: "eth",
330330
Version: "1.0",
331-
Service: filters.NewPublicFilterAPI(s.ChainDb(), s.EventMux()),
331+
Service: filters.NewPublicFilterAPI(s.chainDb, s.eventMux),
332332
Public: true,
333333
}, {
334334
Namespace: "admin",
@@ -351,7 +351,7 @@ func (s *Ethereum) APIs() []rpc.API {
351351
}, {
352352
Namespace: "admin",
353353
Version: "1.0",
354-
Service: ethreg.NewPrivateRegistarAPI(s.chainConfig, s.BlockChain(), s.ChainDb(), s.TxPool(), s.AccountManager()),
354+
Service: ethreg.NewPrivateRegistarAPI(s.chainConfig, s.blockchain, s.chainDb, s.txPool, s.accountManager),
355355
},
356356
}
357357
}

0 commit comments

Comments
 (0)