From 778241a3d29de78d58e1b44b51248c3ba03e83ab Mon Sep 17 00:00:00 2001 From: Nicholas Molnar <65710+neekolas@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:37:23 -0700 Subject: [PATCH] Add own node to fixed registry (#130) ## tl;dr We can't run the server with the current configuration because your own node isn't in the registry. This fixes that by hacking your public key in to the `FixedNodeRegistry` --- cmd/replication/main.go | 20 +++++++++++++++++++- pkg/registrant/registrant.go | 3 +-- pkg/utils/keys.go | 12 ++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 pkg/utils/keys.go diff --git a/cmd/replication/main.go b/cmd/replication/main.go index 467f97d4..22f483cb 100644 --- a/cmd/replication/main.go +++ b/cmd/replication/main.go @@ -14,6 +14,7 @@ import ( "github.com/xmtp/xmtpd/pkg/registry" "github.com/xmtp/xmtpd/pkg/server" "github.com/xmtp/xmtpd/pkg/tracing" + "github.com/xmtp/xmtpd/pkg/utils" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -46,15 +47,32 @@ func main() { options.DB.WaitForDB, options.DB.ReadTimeout, ) + if err != nil { log.Fatal("initializing database", zap.Error(err)) } + privateKey, err := utils.ParseEcdsaPrivateKey(options.SignerPrivateKey) + if err != nil { + log.Fatal("parsing private key", zap.Error(err)) + } + s, err := server.NewReplicationServer( ctx, log, options, - registry.NewFixedNodeRegistry([]registry.Node{}), + // TODO:nm replace with real node registry + registry.NewFixedNodeRegistry( + []registry.Node{ + { + NodeID: 0, + SigningKey: &privateKey.PublicKey, + IsHealthy: true, + HttpAddress: "http://example.com", + IsValidConfig: true, + }, + }, + ), db, ) if err != nil { diff --git a/pkg/registrant/registrant.go b/pkg/registrant/registrant.go index 38fdb458..9cfcd682 100644 --- a/pkg/registrant/registrant.go +++ b/pkg/registrant/registrant.go @@ -6,7 +6,6 @@ import ( "crypto/ecdsa" "fmt" "slices" - "strings" "github.com/ethereum/go-ethereum/crypto" "github.com/xmtp/xmtpd/pkg/db/queries" @@ -28,7 +27,7 @@ func NewRegistrant( nodeRegistry registry.NodeRegistry, privateKeyString string, ) (*Registrant, error) { - privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(privateKeyString, "0x")) + privateKey, err := utils.ParseEcdsaPrivateKey(privateKeyString) if err != nil { return nil, fmt.Errorf("unable to parse private key: %v", err) } diff --git a/pkg/utils/keys.go b/pkg/utils/keys.go new file mode 100644 index 00000000..c29a83b0 --- /dev/null +++ b/pkg/utils/keys.go @@ -0,0 +1,12 @@ +package utils + +import ( + "crypto/ecdsa" + "strings" + + "github.com/ethereum/go-ethereum/crypto" +) + +func ParseEcdsaPrivateKey(key string) (*ecdsa.PrivateKey, error) { + return crypto.HexToECDSA(strings.TrimPrefix(key, "0x")) +}