aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/consensus.go15
-rw-r--r--simulation/network.go46
2 files changed, 41 insertions, 20 deletions
diff --git a/core/consensus.go b/core/consensus.go
index bf3650f..f9b8b37 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -783,20 +783,15 @@ func (con *Consensus) ProcessBlockRandomnessResult(
if !con.ccModule.blockRegistered(rand.BlockHash) {
return nil
}
- // TODO(jimmy-dexon): reuse the GPK.
round := rand.Position.Round
- con.logger.Debug("Calling Governance.DKGMasterPublicKeys",
- "round", con.round)
- con.logger.Debug("Calling Governance.DKGComplaints", "round", con.round)
- con.logger.Debug("Calling Governance.Configuration", "round", con.round)
- gpk, err := NewDKGGroupPublicKey(round,
- con.gov.DKGMasterPublicKeys(round),
- con.gov.DKGComplaints(round),
- int(con.gov.Configuration(round).DKGSetSize/3)+1)
+ v, ok, err := con.ccModule.tsigVerifier.UpdateAndGet(round)
if err != nil {
return err
}
- if !gpk.VerifySignature(
+ if !ok {
+ return nil
+ }
+ if !v.VerifySignature(
rand.BlockHash, crypto.Signature{Signature: rand.Randomness}) {
return ErrIncorrectBlockRandomnessResult
}
diff --git a/simulation/network.go b/simulation/network.go
index 89b81ce..985fad7 100644
--- a/simulation/network.go
+++ b/simulation/network.go
@@ -78,13 +78,15 @@ type infoMessage struct {
// network implements core.Network interface and other methods for simulation
// based on test.TransportClient.
type network struct {
- cfg config.Networking
- ctx context.Context
- ctxCancel context.CancelFunc
- trans test.TransportClient
- fromTransport <-chan *test.TransportEnvelope
- toConsensus chan interface{}
- toNode chan interface{}
+ cfg config.Networking
+ ctx context.Context
+ ctxCancel context.CancelFunc
+ trans test.TransportClient
+ fromTransport <-chan *test.TransportEnvelope
+ toConsensus chan interface{}
+ toNode chan interface{}
+ sentRandomness map[common.Hash]struct{}
+ sentAgreement map[common.Hash]struct{}
}
// newNetwork setup network stuffs for nodes, which provides an
@@ -97,9 +99,11 @@ func newNetwork(pubKey crypto.PublicKey, cfg config.Networking) (n *network) {
}
// Construct basic network instance.
n = &network{
- cfg: cfg,
- toNode: make(chan interface{}, 1000),
- toConsensus: make(chan interface{}, 1000),
+ cfg: cfg,
+ toNode: make(chan interface{}, 1000),
+ toConsensus: make(chan interface{}, 1000),
+ sentRandomness: make(map[common.Hash]struct{}),
+ sentAgreement: make(map[common.Hash]struct{}),
}
n.ctx, n.ctxCancel = context.WithCancel(context.Background())
// Construct transport layer.
@@ -135,6 +139,17 @@ func (n *network) BroadcastBlock(block *types.Block) {
// BroadcastAgreementResult implements core.Network interface.
func (n *network) BroadcastAgreementResult(
randRequest *types.AgreementResult) {
+ if _, exist := n.sentAgreement[randRequest.BlockHash]; exist {
+ return
+ }
+ if len(n.sentAgreement) > 1000 {
+ // Randomly drop one entry.
+ for k := range n.sentAgreement {
+ delete(n.sentAgreement, k)
+ break
+ }
+ }
+ n.sentAgreement[randRequest.BlockHash] = struct{}{}
if err := n.trans.Broadcast(randRequest); err != nil {
panic(err)
}
@@ -143,6 +158,17 @@ func (n *network) BroadcastAgreementResult(
// BroadcastRandomnessResult implements core.Network interface.
func (n *network) BroadcastRandomnessResult(
randResult *types.BlockRandomnessResult) {
+ if _, exist := n.sentRandomness[randResult.BlockHash]; exist {
+ return
+ }
+ if len(n.sentRandomness) > 1000 {
+ // Randomly drop one entry.
+ for k := range n.sentRandomness {
+ delete(n.sentRandomness, k)
+ break
+ }
+ }
+ n.sentRandomness[randResult.BlockHash] = struct{}{}
if err := n.trans.Broadcast(randResult); err != nil {
panic(err)
}