aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-01-27 10:10:11 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:21 +0800
commit44b3b292321b69f5f3d4f1a888e84327c978cd08 (patch)
tree83c8352e5540d2d0a169a3c7bb02322d42608585 /vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
parent24819d5eb4c2f58a8b63fccfc0d32044f5676e14 (diff)
downloadgo-tangerine-44b3b292321b69f5f3d4f1a888e84327c978cd08.tar
go-tangerine-44b3b292321b69f5f3d4f1a888e84327c978cd08.tar.gz
go-tangerine-44b3b292321b69f5f3d4f1a888e84327c978cd08.tar.bz2
go-tangerine-44b3b292321b69f5f3d4f1a888e84327c978cd08.tar.lz
go-tangerine-44b3b292321b69f5f3d4f1a888e84327c978cd08.tar.xz
go-tangerine-44b3b292321b69f5f3d4f1a888e84327c978cd08.tar.zst
go-tangerine-44b3b292321b69f5f3d4f1a888e84327c978cd08.zip
params: update testnet config (#177)
* vendor:sync to latest core * params: Update config for testnet
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go89
1 files changed, 58 insertions, 31 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
index a8fab7c69..bcf10139c 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
@@ -35,6 +35,8 @@ var (
ErrPreviousRoundIsNotFinished = errors.New("previous round is not finished")
)
+const maxResultCache = 100
+
// genValidLeader generate a validLeader function for agreement modules.
func genValidLeader(
mgr *agreementMgr) func(*types.Block) (bool, error) {
@@ -80,25 +82,26 @@ type baRoundSetting struct {
type agreementMgr struct {
// TODO(mission): unbound Consensus instance from this module.
- con *Consensus
- ID types.NodeID
- app Application
- gov Governance
- network Network
- logger common.Logger
- cache *utils.NodeSetCache
- signer *utils.Signer
- lattice *Lattice
- ctx context.Context
- lastEndTime time.Time
- initRound uint64
- configs []*agreementMgrConfig
- baModules []*agreement
- voteFilters []*utils.VoteFilter
- waitGroup sync.WaitGroup
- pendingVotes map[uint64][]*types.Vote
- pendingBlocks map[uint64][]*types.Block
- isRunning bool
+ con *Consensus
+ ID types.NodeID
+ app Application
+ gov Governance
+ network Network
+ logger common.Logger
+ cache *utils.NodeSetCache
+ signer *utils.Signer
+ lattice *Lattice
+ ctx context.Context
+ lastEndTime time.Time
+ initRound uint64
+ configs []*agreementMgrConfig
+ baModules []*agreement
+ processedBAResult map[types.Position]struct{}
+ voteFilters []*utils.VoteFilter
+ waitGroup sync.WaitGroup
+ pendingVotes map[uint64][]*types.Vote
+ pendingBlocks map[uint64][]*types.Block
+ isRunning bool
// This lock should be used when attempting to:
// - add a new baModule.
@@ -114,18 +117,19 @@ type agreementMgr struct {
func newAgreementMgr(con *Consensus, initRound uint64,
initRoundBeginTime time.Time) *agreementMgr {
return &agreementMgr{
- con: con,
- ID: con.ID,
- app: con.app,
- gov: con.gov,
- network: con.network,
- logger: con.logger,
- cache: con.nodeSetCache,
- signer: con.signer,
- lattice: con.lattice,
- ctx: con.ctx,
- initRound: initRound,
- lastEndTime: initRoundBeginTime,
+ con: con,
+ ID: con.ID,
+ app: con.app,
+ gov: con.gov,
+ network: con.network,
+ logger: con.logger,
+ cache: con.nodeSetCache,
+ signer: con.signer,
+ lattice: con.lattice,
+ ctx: con.ctx,
+ initRound: initRound,
+ lastEndTime: initRoundBeginTime,
+ processedBAResult: make(map[types.Position]struct{}, maxResultCache),
}
}
@@ -251,6 +255,29 @@ func (mgr *agreementMgr) processBlock(b *types.Block) error {
return mgr.baModules[b.Position.ChainID].processBlock(b)
}
+func (mgr *agreementMgr) touchAgreementResult(
+ result *types.AgreementResult) (first bool) {
+ // DO NOT LOCK THIS FUNCTION!!!!!!!! YOU WILL REGRET IT!!!!!
+ if _, exist := mgr.processedBAResult[result.Position]; !exist {
+ first = true
+ if len(mgr.processedBAResult) > maxResultCache {
+ for k := range mgr.processedBAResult {
+ // Randomly drop one element.
+ delete(mgr.processedBAResult, k)
+ break
+ }
+ }
+ mgr.processedBAResult[result.Position] = struct{}{}
+ }
+ return
+}
+
+func (mgr *agreementMgr) untouchAgreementResult(
+ result *types.AgreementResult) {
+ // DO NOT LOCK THIS FUNCTION!!!!!!!! YOU WILL REGRET IT!!!!!
+ delete(mgr.processedBAResult, result.Position)
+}
+
func (mgr *agreementMgr) processAgreementResult(
result *types.AgreementResult) error {
mgr.lock.RLock()