-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable custom community storenodes (#4532)
* enable custom community store nodes * fix * fix * fix * fix * cleanup * fix * migration * fix * cleanup * fix * cleanup * fix * fix * cleanup * message to update the community storenodes * rename * fix test * wait for availability only if global storenode * fix test * fix typo * sync community storenodes * remove unused * add tests * fix imports * fix todo * unused * pr comments * pr feedback * revert merge deleted * fix lint * fix db and perform ms request * typo * fix log * fix go imports * refactor handle message * cleanup public message * add tests * fix test * cleanup test * fix test * avoid making one file to big to keep codeclimate from complaining * fix lint * revert * Update protocol/storenodes/database.go Co-authored-by: richΛrd <info@richardramos.me> * Update protocol/messenger_mailserver_cycle.go Co-authored-by: richΛrd <info@richardramos.me> * PR comment * fix tx * proto files * pr comment --------- Co-authored-by: richΛrd <info@richardramos.me>
- Loading branch information
1 parent
515dbdf
commit 3f19972
Showing
29 changed files
with
1,862 additions
and
316 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
appdatabase/migrations/sql/1706955596_community_storenodes.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE IF NOT EXISTS community_storenodes ( | ||
community_id BLOB NOT NULL, | ||
storenode_id VARCHAR NOT NULL, | ||
name VARCHAR NOT NULL, | ||
address VARCHAR NOT NULL, | ||
fleet VARCHAR NOT NULL, | ||
version INT NOT NULL, | ||
clock INT NOT NULL DEFAULT 0, | ||
removed BOOLEAN NOT NULL DEFAULT FALSE, | ||
deleted_at INT NOT NULL DEFAULT 0, | ||
PRIMARY KEY (community_id, storenode_id) -- One to many relationship between communities and storenodes: one community might have multiple storenodes | ||
) WITHOUT ROWID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package protocol | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/golang/protobuf/proto" | ||
"go.uber.org/zap" | ||
|
||
"github.com/status-im/status-go/eth-node/crypto" | ||
"github.com/status-im/status-go/eth-node/types" | ||
"github.com/status-im/status-go/protocol/common" | ||
"github.com/status-im/status-go/protocol/communities" | ||
"github.com/status-im/status-go/protocol/protobuf" | ||
"github.com/status-im/status-go/protocol/storenodes" | ||
v1protocol "github.com/status-im/status-go/protocol/v1" | ||
) | ||
|
||
func (m *Messenger) sendCommunityPublicStorenodesInfo(community *communities.Community, snodes storenodes.Storenodes) error { | ||
if !community.IsControlNode() { | ||
return communities.ErrNotControlNode | ||
} | ||
|
||
clock, _ := m.getLastClockWithRelatedChat() | ||
pb := &protobuf.CommunityStorenodes{ | ||
Clock: clock, | ||
CommunityId: community.ID(), | ||
Storenodes: snodes.ToProtobuf(), | ||
ChainId: communities.CommunityDescriptionTokenOwnerChainID(community.Description()), | ||
} | ||
snPayload, err := proto.Marshal(pb) | ||
if err != nil { | ||
return err | ||
} | ||
signature, err := crypto.Sign(crypto.Keccak256(snPayload), community.PrivateKey()) | ||
if err != nil { | ||
return err | ||
} | ||
signedStorenodesInfo := &protobuf.CommunityPublicStorenodesInfo{ | ||
Signature: signature, | ||
Payload: snPayload, | ||
} | ||
signedPayload, err := proto.Marshal(signedStorenodesInfo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rawMessage := common.RawMessage{ | ||
Payload: signedPayload, | ||
Sender: community.PrivateKey(), | ||
SkipEncryptionLayer: true, | ||
MessageType: protobuf.ApplicationMetadataMessage_COMMUNITY_PUBLIC_STORENODES_INFO, | ||
PubsubTopic: community.PubsubTopic(), | ||
} | ||
|
||
_, err = m.sender.SendPublic(context.Background(), community.IDString(), rawMessage) | ||
return err | ||
} | ||
|
||
// HandleCommunityPublicStorenodesInfo will process the control message sent by the community owner on updating the community storenodes for his community (sendCommunityPublicStorenodesInfo). | ||
// The message will be received by many peers that are not interested on that community, so if we don't have this community in our DB we just ignore this message. | ||
func (m *Messenger) HandleCommunityPublicStorenodesInfo(state *ReceivedMessageState, a *protobuf.CommunityPublicStorenodesInfo, statusMessage *v1protocol.StatusMessage) error { | ||
sn := &protobuf.CommunityStorenodes{} | ||
err := proto.Unmarshal(a.Payload, sn) | ||
if err != nil { | ||
return err | ||
} | ||
logger := m.logger.Named("HandleCommunityPublicStorenodesInfo").With(zap.String("communityID", types.EncodeHex(sn.CommunityId))) | ||
|
||
err = m.verifyCommunitySignature(a.Payload, a.Signature, sn.CommunityId, sn.ChainId) | ||
if err != nil { | ||
logger.Error("failed to verify community signature", zap.Error(err)) | ||
return err | ||
} | ||
|
||
// verify if we are interested in this control message | ||
_, err = m.communitiesManager.GetByID(sn.CommunityId) | ||
if err != nil { | ||
if errors.Is(err, communities.ErrOrgNotFound) { | ||
logger.Debug("ignoring control message, community not found") | ||
return nil | ||
} | ||
logger.Error("failed get community by id", zap.Error(err)) | ||
return err | ||
} | ||
|
||
if err := m.communityStorenodes.UpdateStorenodesInDB(sn.CommunityId, storenodes.FromProtobuf(sn.Storenodes, sn.Clock), sn.Clock); err != nil { | ||
logger.Error("failed to update storenodes for community", zap.Error(err)) | ||
return err | ||
} | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.