Skip to content

Commit

Permalink
Use namespace in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Nov 27, 2024
1 parent f1897ed commit 0a2d620
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/replication/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ func main() {
var wg sync.WaitGroup
doneC := make(chan bool, 1)
tracing.GoPanicWrap(ctx, &wg, "main", func(ctx context.Context) {
db, err := db.NewDB(
db, err := db.NewNamespacedDB(
ctx,
options.DB.WriterConnectionString,
utils.BuildNamespace(options),
options.DB.WaitForDB,
options.DB.ReadTimeout,
)
Expand Down
15 changes: 15 additions & 0 deletions pkg/utils/namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package utils

import (
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/xmtp/xmtpd/pkg/config"
)

func BuildNamespace(options config.ServerOptions) string {
hash := ethcrypto.Keccak256(
[]byte(options.Signer.PrivateKey),
[]byte(options.Contracts.NodesContractAddress),
)

return HexEncode(hash)[:12]
}

0 comments on commit 0a2d620

Please sign in to comment.