chore: omit `CommunityDescription` queuing if owner is already verified

This commit is contained in:
Patryk Osmaczko 2023-10-19 18:52:57 +02:00 committed by osmaczko
parent 42527723f2
commit 05db628406
2 changed files with 23 additions and 20 deletions

View File

@ -1308,6 +1308,9 @@ func (o *Community) setPrivateKey(pk *ecdsa.PrivateKey) {
} }
func (o *Community) ControlNode() *ecdsa.PublicKey { func (o *Community) ControlNode() *ecdsa.PublicKey {
if o.config.ControlNode == nil {
return o.config.ID
}
return o.config.ControlNode return o.config.ControlNode
} }

View File

@ -1545,36 +1545,36 @@ func (m *Manager) HandleCommunityDescriptionMessage(signer *ecdsa.PublicKey, des
} }
// A new community, we need to check if we need to validate async. // A new community, we need to check if we need to validate async.
// That would be the case if it has a contract. We queue everything and process separately // That would be the case if it has a contract. We queue everything and process separately.
if shouldQueue { if shouldQueue {
return nil, m.Queue(signer, community, description.Clock, payload) return nil, m.Queue(signer, community, description.Clock, payload)
} }
} else { } else {
// we only queue if the clock is greater // only queue if already known control node is different than the signer
if shouldQueue && community.config.CommunityDescription.Clock < description.Clock { // and if the clock is greater
shouldQueue = shouldQueue && !common.IsPubKeyEqual(community.ControlNode(), signer) &&
community.config.CommunityDescription.Clock < description.Clock
if shouldQueue {
return nil, m.Queue(signer, community, description.Clock, payload) return nil, m.Queue(signer, community, description.Clock, payload)
} }
} }
// Override verified owner if hasTokenOwnership {
if verifiedOwner != nil { // Override verified owner
m.logger.Info("updating verified owner", zap.String("communityID", community.IDString()), zap.String("owner", common.PubkeyToHex(verifiedOwner))) if verifiedOwner != nil {
m.logger.Info("updating verified owner", zap.String("communityID", community.IDString()), zap.String("owner", common.PubkeyToHex(verifiedOwner)))
// If we are not the verified owner anymore, drop the private key // If we are not the verified owner anymore, drop the private key
if !common.IsPubKeyEqual(verifiedOwner, &m.identity.PublicKey) { if !common.IsPubKeyEqual(verifiedOwner, &m.identity.PublicKey) {
community.config.PrivateKey = nil community.config.PrivateKey = nil
}
community.setControlNode(verifiedOwner)
} }
if !common.IsPubKeyEqual(community.ControlNode(), signer) {
community.setControlNode(verifiedOwner) return nil, ErrNotAuthorized
} }
} else if !common.IsPubKeyEqual(community.PublicKey(), signer) {
// If it has token ownership, we check the control node
// otherwise we check the public key
if hasTokenOwnership && !common.IsPubKeyEqual(community.ControlNode(), signer) {
return nil, ErrNotAuthorized
} else if !hasTokenOwnership && !common.IsPubKeyEqual(community.PublicKey(), signer) {
return nil, ErrNotAuthorized return nil, ErrNotAuthorized
} }