diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-04-03 22:47:05 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:59 +0800 |
commit | b8eb11fc1ecba52c05ea150cf77217e61bb16c55 (patch) | |
tree | 46d5203f72303d45194a13a375364c3a7972be40 /core/vm | |
parent | c32e7ba03af9360a7797acdcb5fed2691ef75f9c (diff) | |
download | dexon-b8eb11fc1ecba52c05ea150cf77217e61bb16c55.tar dexon-b8eb11fc1ecba52c05ea150cf77217e61bb16c55.tar.gz dexon-b8eb11fc1ecba52c05ea150cf77217e61bb16c55.tar.bz2 dexon-b8eb11fc1ecba52c05ea150cf77217e61bb16c55.tar.lz dexon-b8eb11fc1ecba52c05ea150cf77217e61bb16c55.tar.xz dexon-b8eb11fc1ecba52c05ea150cf77217e61bb16c55.tar.zst dexon-b8eb11fc1ecba52c05ea150cf77217e61bb16c55.zip |
core: add cache for DKG MPK and complaint (#334)
Since deserializing DKG related items are extremely slow (takes about 3
seconds for 100 items), we cache it in the governance interface.
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/oracle_contracts.go | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index 9f994c6fd..a698b87f1 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -599,27 +599,23 @@ func (s *GovernanceState) IncDKGResetCount(round *big.Int) { } // bytes[] public dkgMasterPublicKeys; +func (s *GovernanceState) LenDKGMasterPublicKeys() *big.Int { + return s.getStateBigInt(big.NewInt(dkgMasterPublicKeysLoc)) +} func (s *GovernanceState) DKGMasterPublicKeys() [][]byte { return s.read1DByteArray(big.NewInt(dkgMasterPublicKeysLoc)) } func (s *GovernanceState) PushDKGMasterPublicKey(mpk []byte) { s.appendTo1DByteArray(big.NewInt(dkgMasterPublicKeysLoc), mpk) } -func (s *GovernanceState) UniqueDKGMasterPublicKeys() []*dkgTypes.MasterPublicKey { +func (s *GovernanceState) DKGMasterPublicKeyItems() []*dkgTypes.MasterPublicKey { // Prepare DKGMasterPublicKeys. var dkgMasterPKs []*dkgTypes.MasterPublicKey - existence := make(map[coreTypes.NodeID]struct{}) for _, mpk := range s.DKGMasterPublicKeys() { x := new(dkgTypes.MasterPublicKey) if err := rlp.DecodeBytes(mpk, x); err != nil { panic(err) } - - // Only the first DKG MPK submission is valid. - if _, exists := existence[x.ProposerID]; exists { - continue - } - existence[x.ProposerID] = struct{}{} dkgMasterPKs = append(dkgMasterPKs, x) } return dkgMasterPKs @@ -666,6 +662,9 @@ func (s *GovernanceState) ClearDKGMasterPublicKeyProposed() { } // bytes[] public dkgComplaints; +func (s *GovernanceState) LenDKGComplaints() *big.Int { + return s.getStateBigInt(big.NewInt(dkgComplaintsLoc)) +} func (s *GovernanceState) DKGComplaints() [][]byte { return s.read1DByteArray(big.NewInt(dkgComplaintsLoc)) } @@ -675,6 +674,17 @@ func (s *GovernanceState) PushDKGComplaint(complaint []byte) { func (s *GovernanceState) ClearDKGComplaints() { s.erase1DByteArray(big.NewInt(dkgComplaintsLoc)) } +func (s *GovernanceState) DKGComplaintItems() []*dkgTypes.Complaint { + var dkgComplaints []*dkgTypes.Complaint + for _, pk := range s.DKGComplaints() { + x := new(dkgTypes.Complaint) + if err := rlp.DecodeBytes(pk, x); err != nil { + panic(err) + } + dkgComplaints = append(dkgComplaints, x) + } + return dkgComplaints +} // mapping(bytes32 => bool) public dkgComplaintsProposed; func (s *GovernanceState) DKGComplaintProposed(id Bytes32) bool { @@ -1246,19 +1256,10 @@ func (c *defaultCoreDKGUtils) NewGroupPublicKey( state *GovernanceState, round *big.Int, threshold int) (tsigVerifierIntf, error) { // Prepare DKGMasterPublicKeys. - mpks := state.UniqueDKGMasterPublicKeys() - - // Prepare DKGComplaints. - var complaints []*dkgTypes.Complaint - for _, comp := range state.DKGComplaints() { - x := new(dkgTypes.Complaint) - if err := rlp.DecodeBytes(comp, x); err != nil { - panic(err) - } - complaints = append(complaints, x) - } + mpks := state.DKGMasterPublicKeyItems() + comps := state.DKGComplaintItems() - return dkgTypes.NewGroupPublicKey(round.Uint64(), mpks, complaints, threshold) + return dkgTypes.NewGroupPublicKey(round.Uint64(), mpks, comps, threshold) } func (g *GovernanceContract) Address() common.Address { |