Implement initialization of dispute manager in node

This commit is contained in:
ChronosX88 2021-03-17 17:31:27 +03:00
parent 480f85fc7b
commit 4006a2effa
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A

View File

@ -12,6 +12,7 @@ import (
pex "github.com/Secured-Finance/go-libp2p-pex" pex "github.com/Secured-Finance/go-libp2p-pex"
"github.com/Secured-Finance/dione/cache" "github.com/Secured-Finance/dione/cache"
"github.com/Secured-Finance/dione/consensus"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
@ -38,7 +39,6 @@ import (
"github.com/Secured-Finance/dione/beacon" "github.com/Secured-Finance/dione/beacon"
"github.com/Secured-Finance/dione/config" "github.com/Secured-Finance/dione/config"
"github.com/Secured-Finance/dione/consensus"
"github.com/Secured-Finance/dione/ethclient" "github.com/Secured-Finance/dione/ethclient"
pubsub2 "github.com/Secured-Finance/dione/pubsub" pubsub2 "github.com/Secured-Finance/dione/pubsub"
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
@ -65,6 +65,7 @@ type Node struct {
Beacon beacon.BeaconNetworks Beacon beacon.BeaconNetworks
Wallet *wallet.LocalWallet Wallet *wallet.LocalWallet
EventCache cache.EventCache EventCache cache.EventCache
DisputeManager *consensus.DisputeManager
} }
func NewNode(config *config.Config, prvKey crypto.PrivKey, pexDiscoveryUpdateTime time.Duration) (*Node, error) { func NewNode(config *config.Config, prvKey crypto.PrivKey, pexDiscoveryUpdateTime time.Duration) (*Node, error) {
@ -121,8 +122,6 @@ func NewNode(config *config.Config, prvKey crypto.PrivKey, pexDiscoveryUpdateTim
n.Miner = miner n.Miner = miner
// initialize event log cache subsystem // initialize event log cache subsystem
//eventLogCache := provideEventLogCache()
//n.EventLogCache = eventLogCache
eventCache := provideEventCache(config) eventCache := provideEventCache(config)
n.EventCache = eventCache n.EventCache = eventCache
@ -130,6 +129,13 @@ func NewNode(config *config.Config, prvKey crypto.PrivKey, pexDiscoveryUpdateTim
cManager := provideConsensusManager(psb, miner, ethClient, rawPrivKey, n.Config.ConsensusMinApprovals, eventCache) cManager := provideConsensusManager(psb, miner, ethClient, rawPrivKey, n.Config.ConsensusMinApprovals, eventCache)
n.ConsensusManager = cManager n.ConsensusManager = cManager
// initialize dispute subsystem
disputeManager, err := provideDisputeManager(context.TODO(), ethClient, cManager)
if err != nil {
logrus.Fatal(err)
}
n.DisputeManager = disputeManager
// initialize internal eth wallet // initialize internal eth wallet
wallet, err := provideWallet(n.Host.ID(), rawPrivKey) wallet, err := provideWallet(n.Host.ID(), rawPrivKey)
if err != nil { if err != nil {
@ -256,6 +262,10 @@ func provideEventCache(config *config.Config) cache.EventCache {
return backend return backend
} }
func provideDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient, pcm *consensus.PBFTConsensusManager) (*consensus.DisputeManager, error) {
return consensus.NewDisputeManager(ctx, ethClient, pcm)
}
func provideMiner(peerID peer.ID, ethAddress common.Address, beacon beacon.BeaconNetworks, ethClient *ethclient.EthereumClient, privateKey []byte) *consensus.Miner { func provideMiner(peerID peer.ID, ethAddress common.Address, beacon beacon.BeaconNetworks, ethClient *ethclient.EthereumClient, privateKey []byte) *consensus.Miner {
return consensus.NewMiner(peerID, ethAddress, beacon, ethClient, privateKey) return consensus.NewMiner(peerID, ethAddress, beacon, ethClient, privateKey)
} }