aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-03-21 14:25:10 +0800
committerMission Liao <mission.liao@dexon.org>2019-03-21 14:25:10 +0800
commit89200f8e67d5ada9cd919fb62926f9264788e5ea (patch)
tree3ae9c74f5d77b7a7a43ba2c706f1564b98d2bdf4
parentfec2fb7d227d0fd2fc496d8cc3c5595a30590c04 (diff)
downloaddexon-consensus-89200f8e67d5ada9cd919fb62926f9264788e5ea.tar
dexon-consensus-89200f8e67d5ada9cd919fb62926f9264788e5ea.tar.gz
dexon-consensus-89200f8e67d5ada9cd919fb62926f9264788e5ea.tar.bz2
dexon-consensus-89200f8e67d5ada9cd919fb62926f9264788e5ea.tar.lz
dexon-consensus-89200f8e67d5ada9cd919fb62926f9264788e5ea.tar.xz
dexon-consensus-89200f8e67d5ada9cd919fb62926f9264788e5ea.tar.zst
dexon-consensus-89200f8e67d5ada9cd919fb62926f9264788e5ea.zip
Tmp
-rw-r--r--core/blockchain.go4
-rw-r--r--core/blockchain_test.go2
-rw-r--r--core/consensus.go33
-rw-r--r--core/dkg-tsig-protocol.go10
4 files changed, 31 insertions, 18 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index fbd1f72..0ecd083 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -123,6 +123,7 @@ func newBlockChainConfig(prev blockChainConfig, config *types.Config) (
type tsigVerifierGetter interface {
UpdateAndGet(uint64) (TSigVerifier, bool, error)
+ Purge(uint64)
}
type blockChain struct {
@@ -197,6 +198,9 @@ func (bc *blockChain) notifyRoundEvents(evts []utils.RoundEventParam) error {
}
bc.configs = append(bc.configs, c)
}
+ if e.Reset != 0 {
+ bc.vGetter.Purge(e.Round + 1)
+ }
return nil
}
for _, e := range evts {
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index ca42b09..6a615c1 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -43,6 +43,8 @@ func (t *testTSigVerifierGetter) UpdateAndGet(round uint64) (
return &testTSigVerifier{}, true, nil
}
+func (t *testTSigVerifierGetter) Purge(_ uint64) {}
+
type BlockChainTestSuite struct {
suite.Suite
diff --git a/core/consensus.go b/core/consensus.go
index 946a5d0..0b46ea8 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -639,22 +639,22 @@ func newConsensusForRound(
tsigVerifierCache, signer, logger)
// Construct Consensus instance.
con := &Consensus{
- ID: ID,
- app: appModule,
- debugApp: debugApp,
- gov: gov,
- db: db,
- network: network,
- baConfirmedBlock: make(map[common.Hash]chan<- *types.Block),
- dkgReady: sync.NewCond(&sync.Mutex{}),
- cfgModule: cfgModule,
- bcModule: bcModule,
- dMoment: dMoment,
- nodeSetCache: nodeSetCache,
- tsigVerifierCache: tsigVerifierCache,
- signer: signer,
- event: common.NewEvent(),
- logger: logger,
+ ID: ID,
+ app: appModule,
+ debugApp: debugApp,
+ gov: gov,
+ db: db,
+ network: network,
+ baConfirmedBlock: make(map[common.Hash]chan<- *types.Block),
+ dkgReady: sync.NewCond(&sync.Mutex{}),
+ cfgModule: cfgModule,
+ bcModule: bcModule,
+ dMoment: dMoment,
+ nodeSetCache: nodeSetCache,
+ tsigVerifierCache: tsigVerifierCache,
+ signer: signer,
+ event: common.NewEvent(),
+ logger: logger,
resetDeliveryGuardTicker: make(chan struct{}),
msgChan: make(chan interface{}, 1024),
processBlockChan: make(chan *types.Block, 1024),
@@ -720,6 +720,7 @@ func (con *Consensus) prepare(
continue
}
con.nodeSetCache.Purge(e.Round + 1)
+ con.tsigVerifierCache.Purge(e.Round + 1)
}
})
// Register round event handler to abort previous running DKG if any.
diff --git a/core/dkg-tsig-protocol.go b/core/dkg-tsig-protocol.go
index 50c3a0b..067bc13 100644
--- a/core/dkg-tsig-protocol.go
+++ b/core/dkg-tsig-protocol.go
@@ -157,8 +157,8 @@ func (d *dkgProtocol) toDKGProtocolInfo() db.DKGProtocolInfo {
PrvSharesReceived: d.prvSharesReceived,
NodeComplained: d.nodeComplained,
AntiComplaintReceived: d.antiComplaintReceived,
- Step: uint64(d.step),
- Reset: d.reset,
+ Step: uint64(d.step),
+ Reset: d.reset,
}
if d.masterPrivateShare != nil {
@@ -555,6 +555,12 @@ func (tc *TSigVerifierCache) UpdateAndGet(round uint64) (
return v, ok, nil
}
+func (tc *TSigVerifierCache) Purge(round uint64) {
+ tc.lock.Lock()
+ defer tc.lock.Unlock()
+ delete(tc.verifier, round)
+}
+
// Update the cache and returns if success.
func (tc *TSigVerifierCache) Update(round uint64) (bool, error) {
tc.lock.Lock()