aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/oracle_contracts.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-04-03 22:47:05 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-15 22:09:55 +0800
commit83967112258e35425dae4aa943404ee76a36f591 (patch)
tree8e32a727fa1ac39cb4f8884d6334c2fa52b11a8e /core/vm/oracle_contracts.go
parent89aed9c306ea8b1b712bf8e84c1f79b328e19052 (diff)
downloadgo-tangerine-83967112258e35425dae4aa943404ee76a36f591.tar
go-tangerine-83967112258e35425dae4aa943404ee76a36f591.tar.gz
go-tangerine-83967112258e35425dae4aa943404ee76a36f591.tar.bz2
go-tangerine-83967112258e35425dae4aa943404ee76a36f591.tar.lz
go-tangerine-83967112258e35425dae4aa943404ee76a36f591.tar.xz
go-tangerine-83967112258e35425dae4aa943404ee76a36f591.tar.zst
go-tangerine-83967112258e35425dae4aa943404ee76a36f591.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/oracle_contracts.go')
-rw-r--r--core/vm/oracle_contracts.go41
1 files changed, 21 insertions, 20 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index b794ac8e5..10459a870 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 {
@@ -1244,19 +1254,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 {