From b1cfc81cf7018bf23e1b897c0531cb389e9e1038 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Wed, 21 Apr 2021 00:38:54 +0300 Subject: [PATCH] Implement customizing dispute vote window time in dione config --- config/config.go | 1 + consensus/dispute_manager.go | 6 ++++-- node/node.go | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index e17906d..2c25fa9 100644 --- a/config/config.go +++ b/config/config.go @@ -30,6 +30,7 @@ type EthereumConfig struct { DioneOracleContractAddress string `mapstructure:"oracle_contract_address"` DioneStakingContractAddress string `mapstructure:"staking_contract_address"` DisputeContractAddress string `mapstructure:"dispute_contract_address"` + DisputeVoteWindow int `mapstructure:"dispute_vote_window"` // in secs } type FilecoinConfig struct { diff --git a/consensus/dispute_manager.go b/consensus/dispute_manager.go index 7152aa0..1c143e2 100644 --- a/consensus/dispute_manager.go +++ b/consensus/dispute_manager.go @@ -21,9 +21,10 @@ type DisputeManager struct { pcm *PBFTConsensusManager submissionMap map[string]*dioneOracle.DioneOracleSubmittedOracleRequest disputeMap map[string]*dioneDispute.DioneDisputeNewDispute + voteWindow time.Duration } -func NewDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient, pcm *PBFTConsensusManager) (*DisputeManager, error) { +func NewDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient, pcm *PBFTConsensusManager, voteWindow int) (*DisputeManager, error) { newSubmittionsChan, submSubscription, err := ethClient.SubscribeOnNewSubmittions(ctx) if err != nil { return nil, err @@ -40,6 +41,7 @@ func NewDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient, ctx: ctx, submissionMap: map[string]*dioneOracle.DioneOracleSubmittedOracleRequest{}, disputeMap: map[string]*dioneDispute.DioneDisputeNewDispute{}, + voteWindow: time.Duration(voteWindow) * time.Second, } go func() { @@ -92,7 +94,7 @@ func (dm *DisputeManager) onNewSubmission(submittion *dioneOracle.DioneOracleSub logrus.Errorf(err.Error()) return } - disputeFinishTimer := time.NewTimer(time.Minute * 5) + disputeFinishTimer := time.NewTimer(dm.voteWindow) go func() { for { select { diff --git a/node/node.go b/node/node.go index a2d9fc8..1b1e103 100644 --- a/node/node.go +++ b/node/node.go @@ -139,7 +139,7 @@ func NewNode(config *config.Config, prvKey crypto.PrivKey, pexDiscoveryUpdateTim logrus.Info("Consensus subsystem has initialized!") // initialize dispute subsystem - disputeManager, err := provideDisputeManager(context.TODO(), ethClient, cManager) + disputeManager, err := provideDisputeManager(context.TODO(), ethClient, cManager, config) if err != nil { logrus.Fatal(err) } @@ -268,8 +268,8 @@ func provideEventCache(config *config.Config) cache.EventCache { return backend } -func provideDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient, pcm *consensus.PBFTConsensusManager) (*consensus.DisputeManager, error) { - return consensus.NewDisputeManager(ctx, ethClient, pcm) +func provideDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient, pcm *consensus.PBFTConsensusManager, cfg *config.Config) (*consensus.DisputeManager, error) { + return consensus.NewDisputeManager(ctx, ethClient, pcm, cfg.Ethereum.DisputeVoteWindow) } func provideMiner(peerID peer.ID, ethAddress common.Address, beacon beacon.BeaconNetworks, ethClient *ethclient.EthereumClient, privateKey []byte) *consensus.Miner {