diff options
author | Wei-Ning Huang <w@cobinhood.com> | 2018-10-12 13:54:32 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:23:38 +0800 |
commit | 4a131ffec89a8229d2b661eb8e6ebd4ec292baf2 (patch) | |
tree | a29a9cdd25e3e133f30d2f58014ff5cd4840a94d /dex | |
parent | 25124281519a0ec7d163bb38c64b6b5c9c122df6 (diff) | |
download | go-tangerine-4a131ffec89a8229d2b661eb8e6ebd4ec292baf2.tar go-tangerine-4a131ffec89a8229d2b661eb8e6ebd4ec292baf2.tar.gz go-tangerine-4a131ffec89a8229d2b661eb8e6ebd4ec292baf2.tar.bz2 go-tangerine-4a131ffec89a8229d2b661eb8e6ebd4ec292baf2.tar.lz go-tangerine-4a131ffec89a8229d2b661eb8e6ebd4ec292baf2.tar.xz go-tangerine-4a131ffec89a8229d2b661eb8e6ebd4ec292baf2.tar.zst go-tangerine-4a131ffec89a8229d2b661eb8e6ebd4ec292baf2.zip |
dex: governance: implement governance interface
Diffstat (limited to 'dex')
-rw-r--r-- | dex/api_backend.go | 7 | ||||
-rw-r--r-- | dex/backend.go | 32 | ||||
-rw-r--r-- | dex/governance.go | 15 |
3 files changed, 38 insertions, 16 deletions
diff --git a/dex/api_backend.go b/dex/api_backend.go index 151a5d7da..791d3ab8f 100644 --- a/dex/api_backend.go +++ b/dex/api_backend.go @@ -29,6 +29,7 @@ import ( "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" "github.com/dexon-foundation/dexon/core/vm" + "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/eth/gasprice" "github.com/dexon-foundation/dexon/ethdb" @@ -181,9 +182,9 @@ func (b *DexAPIBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.S return b.dex.TxPool().SubscribeNewTxsEvent(ch) } -//func (b *DexAPIBackend) Downloader() *downloader.Downloader { -// return b.dex.Downloader() -//} +func (b *DexAPIBackend) Downloader() *downloader.Downloader { + return b.dex.Downloader() +} func (b *DexAPIBackend) ProtocolVersion() int { return b.dex.DexVersion() diff --git a/dex/backend.go b/dex/backend.go index 3b7fde400..8213f582e 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -31,6 +31,8 @@ import ( "github.com/dexon-foundation/dexon/core/bloombits" "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/vm" + "github.com/dexon-foundation/dexon/dex/gasprice" + "github.com/dexon-foundation/dexon/eth/downloader" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" "github.com/dexon-foundation/dexon/internal/ethapi" @@ -64,6 +66,8 @@ type Dexon struct { bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports + APIBackend *DexAPIBackend + // Dexon consensus. app *DexconApp governance *DexconGovernance @@ -81,7 +85,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { if err != nil { panic(err) } - gov := NewDexconGovernance() network := NewDexconNetwork() // TODO(w): replace this with node key. @@ -116,7 +119,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { shutdownChan: make(chan bool), networkID: config.NetworkId, bloomRequests: make(chan chan *bloombits.Retrieval), - governance: gov, network: network, blockdb: db, engine: dexcon.New(¶ms.DexconConfig{}), @@ -145,9 +147,16 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { } dex.txPool = core.NewTxPool(config.TxPool, dex.chainConfig, dex.blockchain) - dex.app = NewDexconApp(dex.txPool, dex.blockchain, gov, chainDb, config, vmConfig) + dex.APIBackend = &DexAPIBackend{dexon, nil} + gpoParams := config.GPO + //if gpoParams.Default == nil { + // gpoParams.Default = config.MinerGasPrice + //} + dex.APIBackend.gpo = gasprice.NewOracle(dex.APIBackend, gpoParams) - dex.consensus = dexCore.NewConsensus(dex.app, gov, db, network, privKey) + dex.governance = NewDexconGovernance(dex.APIBackend) + dex.app = NewDexconApp(dex.txPool, dex.blockchain, dex.governance, chainDb, config, vmConfig) + dex.consensus = dexCore.NewConsensus(dex.app, dex.governance, db, network, privKey) return dex, nil } @@ -180,10 +189,11 @@ func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Data return db, nil } -func (d *Dexon) AccountManager() *accounts.Manager { return d.accountManager } -func (d *Dexon) BlockChain() *core.BlockChain { return d.blockchain } -func (d *Dexon) TxPool() *core.TxPool { return d.txPool } -func (d *Dexon) DexVersion() int { return int(d.protocolManager.SubProtocols[0].Version) } -func (d *Dexon) EventMux() *event.TypeMux { return d.eventMux } -func (d *Dexon) Engine() consensus.Engine { return d.engine } -func (d *Dexon) ChainDb() ethdb.Database { return d.chainDb } +func (d *Dexon) AccountManager() *accounts.Manager { return d.accountManager } +func (d *Dexon) BlockChain() *core.BlockChain { return d.blockchain } +func (d *Dexon) TxPool() *core.TxPool { return d.txPool } +func (d *Dexon) DexVersion() int { return int(d.protocolManager.SubProtocols[0].Version) } +func (d *Dexon) EventMux() *event.TypeMux { return d.eventMux } +func (d *Dexon) Engine() consensus.Engine { return d.engine } +func (d *Dexon) ChainDb() ethdb.Database { return d.chainDb } +func (d *Dexon) Downloader() *downloader.Downloader { return d.protocolManager.downloader } diff --git a/dex/governance.go b/dex/governance.go index e990f32f3..f49355816 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -4,19 +4,30 @@ import ( coreCommon "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + "github.com/dexon-foundation/dexon/core/vm" ) type DexconGovernance struct { + b *DexAPIBackend } // NewDexconGovernance retruns a governance implementation of the DEXON // consensus governance interface. -func NewDexconGovernance() *DexconGovernance { - return &DexconGovernance{} +func NewDexconGovernance(backend *DexAPIBackend) *DexconGovernance { + return &DexconGovernance{ + b: backend, + } } // Configuration return the total ordering K constant. func (d *DexconGovernance) Configuration(round uint64) *types.Config { + state, _, err := d.b.StateAndHeaderByNumber(ctx, blockNr) + if state == nil || err != nil { + return nil, err + } + + s := vm.GovernanceStateHelper{state} + return &types.Config{} } |