From 89200f8e67d5ada9cd919fb62926f9264788e5ea Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Thu, 21 Mar 2019 14:25:10 +0800 Subject: Tmp --- core/blockchain.go | 4 ++++ core/blockchain_test.go | 2 ++ core/consensus.go | 33 +++++++++++++++++---------------- core/dkg-tsig-protocol.go | 10 ++++++++-- 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() -- cgit v1.2.3