aboutsummaryrefslogtreecommitdiffstats
path: root/dex
diff options
context:
space:
mode:
authorWei-Ning Huang <w@cobinhood.com>2018-09-21 15:06:38 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:21:31 +0800
commit20d12131b5b411a35558fa13a8bc86ec66d7923a (patch)
tree1d0a89371d9b87c592f86685e04d38e6b70814e3 /dex
parent8e483e2f87cdccd924ce2261ac3a5ec8b58aaf05 (diff)
downloadgo-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar.gz
go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.tar.zst
go-tangerine-20d12131b5b411a35558fa13a8bc86ec66d7923a.zip
dex: make geth buildable and update interface skeleton
Diffstat (limited to 'dex')
-rw-r--r--dex/app.go26
-rw-r--r--dex/backend.go107
-rw-r--r--dex/governance.go14
-rw-r--r--dex/network.go35
4 files changed, 177 insertions, 5 deletions
diff --git a/dex/app.go b/dex/app.go
index 5aa1f6e35..f87f669fb 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -22,18 +22,32 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
+
+ "github.com/ethereum/go-ethereum/core"
)
// DexconApp implementes the DEXON consensus core application interface.
type DexconApp struct {
+ txPool *core.TxPool
+
+ witnessResultChan chan types.WitnessResult
+}
+
+func NewDexconApp(txPool *core.TxPool) *DexconApp {
+ return &DexconApp{
+ txPool: txPool,
+ witnessResultChan: make(chan types.WitnessResult),
+ }
}
// PreparePayload is called when consensus core is preparing a block.
-func (d *DexconApp) PreparePayloads(position types.Position) []byte {
+func (d *DexconApp) PreparePayload(position types.Position) []byte {
+ return nil
}
// VerifyPayloads verifies if the payloads are valid.
func (d *DexconApp) VerifyPayloads(payloads []byte) bool {
+ return true
}
// BlockConfirmed is called when a block is confirmed and added to lattice.
@@ -53,6 +67,12 @@ func (d *DexconApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool)
func (d *DexconApp) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
}
-// NotaryAckDeliver is called when a notary ack is created.
-func (d *DexconApp) NotaryAckDeliver(notaryAck *types.NotaryAck) {
+// BlockProcessedChan returns a channel to receive the block hashes that have
+// finished processing by the application.
+func (d *DexconApp) BlockProcessedChan() <-chan types.WitnessResult {
+ return d.witnessResultChan
+}
+
+// WitnessAckDeliver is called when a notary ack is created.
+func (d *DexconApp) WitnessAckDeliver(notaryAck *types.WitnessAck) {
}
diff --git a/dex/backend.go b/dex/backend.go
index 73a84c139..e374bb70f 100644
--- a/dex/backend.go
+++ b/dex/backend.go
@@ -17,6 +17,113 @@
package dex
+import (
+ "math/big"
+ "sync"
+
+ dexCore "github.com/dexon-foundation/dexon-consensus-core/core"
+ "github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ ethCrypto "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
+
+ "github.com/ethereum/go-ethereum/accounts"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/consensus"
+ "github.com/ethereum/go-ethereum/core"
+ "github.com/ethereum/go-ethereum/core/bloombits"
+ "github.com/ethereum/go-ethereum/eth"
+ "github.com/ethereum/go-ethereum/ethdb"
+ "github.com/ethereum/go-ethereum/event"
+ "github.com/ethereum/go-ethereum/internal/ethapi"
+ "github.com/ethereum/go-ethereum/node"
+ "github.com/ethereum/go-ethereum/p2p"
+ "github.com/ethereum/go-ethereum/params"
+ "github.com/ethereum/go-ethereum/rpc"
+)
+
// Dexon implementes the DEXON fullnode service.
type Dexon struct {
+ config *eth.Config
+ chainConfig *params.ChainConfig
+
+ // Channel for shutting down the service
+ shutdownChan chan bool // Channel for shutting down the Ethereum
+ txPool *core.TxPool
+ blockchain *core.BlockChain
+
+ // DB interfaces
+ chainDb ethdb.Database // Block chain database
+
+ eventMux *event.TypeMux
+ engine consensus.Engine
+ accountManager *accounts.Manager
+
+ bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
+ bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
+
+ gasPrice *big.Int
+ etherbase common.Address
+
+ // Dexon consensus.
+ app *DexconApp
+ governance *DexconGovernance
+ network *DexconNetwork
+ blockdb blockdb.BlockDatabase
+ consensus *dexCore.Consensus
+
+ networkID uint64
+ netRPCService *ethapi.PublicNetAPI
+
+ lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
+}
+
+func New(ctx *node.ServiceContext, config *eth.Config) (*Dexon, error) {
+ // Consensus.
+ db, err := blockdb.NewLevelDBBackedBlockDB("main.blockdb")
+ if err != nil {
+ panic(err)
+ }
+ app := NewDexconApp(nil)
+ gov := NewDexconGovernance()
+ network := NewDexconNetwork()
+
+ // TODO(w): replace this with node key.
+ privKey, err := ethCrypto.NewPrivateKey()
+ if err != nil {
+ panic(err)
+ }
+ consensus := dexCore.NewConsensus(
+ app, gov, db, network, privKey, ethCrypto.SigToPub)
+
+ dex := &Dexon{
+ config: config,
+ eventMux: ctx.EventMux,
+ accountManager: ctx.AccountManager,
+ shutdownChan: make(chan bool),
+ networkID: config.NetworkId,
+ gasPrice: config.MinerGasPrice,
+ etherbase: config.Etherbase,
+ bloomRequests: make(chan chan *bloombits.Retrieval),
+ app: app,
+ governance: gov,
+ network: network,
+ blockdb: db,
+ consensus: consensus,
+ }
+ return dex, nil
+}
+
+func (s *Dexon) Protocols() []p2p.Protocol {
+ return nil
+}
+
+func (s *Dexon) APIs() []rpc.API {
+ return nil
+}
+
+func (s *Dexon) Start(server *p2p.Server) error {
+ return nil
+}
+
+func (s *Dexon) Stop() error {
+ return nil
}
diff --git a/dex/governance.go b/dex/governance.go
index cb696e42c..0ef0b56db 100644
--- a/dex/governance.go
+++ b/dex/governance.go
@@ -7,12 +7,20 @@ import (
type DexconGovernance struct {
}
+// NewDexconGovernance retruns a governance implementation of the DEXON
+// consensus governance interface.
+func NewDexconGovernance() *DexconGovernance {
+ return &DexconGovernance{}
+}
+
// GetValidatorSet returns the current notary set.
-func (d *DexconGovernance) GetNotarySet() map[types.ValidatorID]struct{} {
+func (d *DexconGovernance) GetNotarySet() map[types.NodeID]struct{} {
+ return make(map[types.NodeID]struct{})
}
// GetTotalOrderingK return the total ordering K constant.
-func (d *DexconGovernance) GetCCP() types.CCP {
+func (d *DexconGovernance) GetConfiguration(blockHeight uint64) *types.Config {
+ return &types.Config{}
}
// AddDKGComplaint adds a DKGComplaint.
@@ -21,6 +29,7 @@ func (d *DexconGovernance) AddDKGComplaint(complaint *types.DKGComplaint) {
// GetDKGComplaints gets all the DKGComplaints of round.
func (d *DexconGovernance) DKGComplaints(round uint64) []*types.DKGComplaint {
+ return nil
}
// AddDKGMasterPublicKey adds a DKGMasterPublicKey.
@@ -29,4 +38,5 @@ func (d *DexconGovernance) AddDKGMasterPublicKey(masterPublicKey *types.DKGMaste
// DKGMasterPublicKeys gets all the DKGMasterPublicKey of round.
func (d *DexconGovernance) DKGMasterPublicKeys(round uint64) []*types.DKGMasterPublicKey {
+ return nil
}
diff --git a/dex/network.go b/dex/network.go
new file mode 100644
index 000000000..d0b8b5d77
--- /dev/null
+++ b/dex/network.go
@@ -0,0 +1,35 @@
+package dex
+
+import "github.com/dexon-foundation/dexon-consensus-core/core/types"
+
+type DexconNetwork struct {
+ receiveChan chan interface{}
+}
+
+func NewDexconNetwork() *DexconNetwork {
+ return &DexconNetwork{
+ receiveChan: make(chan interface{}),
+ }
+}
+
+// BroadcastVote broadcasts vote to all nodes in DEXON network.
+func (n *DexconNetwork) BroadcastVote(vote *types.Vote) {
+}
+
+// BroadcastBlock broadcasts block to all nodes in DEXON network.
+func (n *DexconNetwork) BroadcastBlock(block *types.Block) {
+}
+
+// BroadcastWitnessAck broadcasts witnessAck to all nodes in DEXON network.
+func (n *DexconNetwork) BroadcastWitnessAck(witnessAck *types.WitnessAck) {
+}
+
+// SendDKGPrivateShare sends PrivateShare to a DKG participant.
+func (n *DexconNetwork) SendDKGPrivateShare(
+ recv types.NodeID, prvShare *types.DKGPrivateShare) {
+}
+
+// ReceiveChan returns a channel to receive messages from DEXON network.
+func (n *DexconNetwork) ReceiveChan() <-chan interface{} {
+ return n.receiveChan
+}