Skip to content

Commit

Permalink
Add own node to fixed registry (#130)
Browse files Browse the repository at this point in the history
## 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`
neekolas authored Aug 30, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e7fe0ab commit 778241a
Showing 3 changed files with 32 additions and 3 deletions.
20 changes: 19 additions & 1 deletion cmd/replication/main.go
Original file line number Diff line number Diff line change
@@ -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 {
3 changes: 1 addition & 2 deletions pkg/registrant/registrant.go
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 12 additions & 0 deletions pkg/utils/keys.go
Original file line number Diff line number Diff line change
@@ -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"))
}

0 comments on commit 778241a

Please sign in to comment.