diff options
author | Wei-Ning Huang <w@cobinhood.com> | 2018-10-13 13:53:42 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:49 +0800 |
commit | fb8fb70b0c63e400a3779d36c4986e0d4520c141 (patch) | |
tree | ade151c07084a1237f30bc374bb21d1c3918bbd2 | |
parent | 83286d09174c739dcd94709377b3adb6ad55d80b (diff) | |
download | go-tangerine-fb8fb70b0c63e400a3779d36c4986e0d4520c141.tar go-tangerine-fb8fb70b0c63e400a3779d36c4986e0d4520c141.tar.gz go-tangerine-fb8fb70b0c63e400a3779d36c4986e0d4520c141.tar.bz2 go-tangerine-fb8fb70b0c63e400a3779d36c4986e0d4520c141.tar.lz go-tangerine-fb8fb70b0c63e400a3779d36c4986e0d4520c141.tar.xz go-tangerine-fb8fb70b0c63e400a3779d36c4986e0d4520c141.tar.zst go-tangerine-fb8fb70b0c63e400a3779d36c4986e0d4520c141.zip |
dex: pass p2p nodeKey to Dexon instance
-rw-r--r-- | cmd/utils/flags.go | 1 | ||||
-rw-r--r-- | dex/backend.go | 12 | ||||
-rw-r--r-- | dex/config.go | 4 | ||||
-rw-r--r-- | dex/governance.go | 17 | ||||
-rw-r--r-- | node/node.go | 1 | ||||
-rw-r--r-- | node/service.go | 5 |
6 files changed, 25 insertions, 15 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 0bb0cfe57..2c3b21755 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1295,6 +1295,7 @@ func RegisterDexService(stack *node.Node, cfg *dex.Config) { //}) } else { err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { + cfg.PrivateKey = ctx.ServerConfig.PrivateKey fullNode, err := dex.New(ctx, cfg) //if fullNode != nil && cfg.LightServ > 0 { // ls, _ := les.NewLesServer(fullNode, cfg) diff --git a/dex/backend.go b/dex/backend.go index b6a7bdc4d..2396f0f71 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -22,7 +22,7 @@ import ( dexCore "github.com/dexon-foundation/dexon-consensus-core/core" "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" + coreEcdsa "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon/accounts" "github.com/dexon-foundation/dexon/consensus" @@ -87,12 +87,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { } network := NewDexconNetwork() - // TODO(w): replace this with node key. - privKey, err := ecdsa.NewPrivateKey() - if err != nil { - panic(err) - } - chainDb, err := CreateDB(ctx, config, "chaindata") if err != nil { return nil, err @@ -154,8 +148,10 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { //} dex.APIBackend.gpo = gasprice.NewOracle(dex.APIBackend, gpoParams) - dex.governance = NewDexconGovernance(dex.APIBackend) + dex.governance = NewDexconGovernance(dex.APIBackend, config.PrivateKey) dex.app = NewDexconApp(dex.txPool, dex.blockchain, dex.governance, chainDb, config, vmConfig) + + privKey := coreEcdsa.NewPrivateKeyFromECDSA(config.PrivateKey) dex.consensus = dexCore.NewConsensus(dex.app, dex.governance, db, network, privKey) return dex, nil diff --git a/dex/config.go b/dex/config.go index df5babc73..7e33ae05f 100644 --- a/dex/config.go +++ b/dex/config.go @@ -17,6 +17,7 @@ package dex import ( + "crypto/ecdsa" "math/big" "os" "os/user" @@ -73,6 +74,9 @@ type Config struct { // If nil, the Ethereum main net block is used. Genesis *core.Genesis `toml:",omitempty"` + // PrivateKey, also represents the node identity. + PrivateKey *ecdsa.PrivateKey `toml:",omitempty"` + // Protocol options NetworkId uint64 // Network ID to use for selecting peers to connect to SyncMode downloader.SyncMode diff --git a/dex/governance.go b/dex/governance.go index d2cfe05c6..8993152df 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -2,12 +2,13 @@ package dex import ( "context" + "crypto/ecdsa" "math/big" "time" coreCommon "github.com/dexon-foundation/dexon-consensus-core/common" coreCrypto "github.com/dexon-foundation/dexon-consensus-core/core/crypto" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" + coreEcdsa "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" coreTypes "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon/core/vm" "github.com/dexon-foundation/dexon/rlp" @@ -15,14 +16,16 @@ import ( ) type DexconGovernance struct { - b *DexAPIBackend + b *DexAPIBackend + privateKey *ecdsa.PrivateKey } // NewDexconGovernance retruns a governance implementation of the DEXON // consensus governance interface. -func NewDexconGovernance(backend *DexAPIBackend) *DexconGovernance { +func NewDexconGovernance(backend *DexAPIBackend, privKey *ecdsa.PrivateKey) *DexconGovernance { return &DexconGovernance{ - b: backend, + b: backend, + privateKey: privKey, } } @@ -95,11 +98,15 @@ func (d *DexconGovernance) NodeSet(round uint64) []coreCrypto.PublicKey { var pks []coreCrypto.PublicKey for _, n := range s.Nodes() { - pks = append(pks, ecdsa.NewPublicKeyFromByteSlice(n.PublicKey)) + pks = append(pks, coreEcdsa.NewPublicKeyFromByteSlice(n.PublicKey)) } return pks } +// NotifyRoundHeight register the mapping between round and height. +func (d *DexconGovernance) NotifyRoundHeight(targetRound, consensusHeight uint64) { +} + // AddDKGComplaint adds a DKGComplaint. func (d *DexconGovernance) AddDKGComplaint(round uint64, complaint *coreTypes.DKGComplaint) { } diff --git a/node/node.go b/node/node.go index 43dba3e51..ffa9fa1b0 100644 --- a/node/node.go +++ b/node/node.go @@ -172,6 +172,7 @@ func (n *Node) Start() error { ctx := &ServiceContext{ config: n.config, services: make(map[reflect.Type]Service), + ServerConfig: &n.serverConfig, EventMux: n.eventmux, AccountManager: n.accman, } diff --git a/node/service.go b/node/service.go index 806d73b63..7f9683362 100644 --- a/node/service.go +++ b/node/service.go @@ -32,8 +32,9 @@ import ( type ServiceContext struct { config *Config services map[reflect.Type]Service // Index of the already constructed services - EventMux *event.TypeMux // Event multiplexer used for decoupled notifications - AccountManager *accounts.Manager // Account manager created by the node. + ServerConfig *p2p.Config + EventMux *event.TypeMux // Event multiplexer used for decoupled notifications + AccountManager *accounts.Manager // Account manager created by the node. } // OpenDatabase opens an existing database with the given name (or creates one |