diff --git a/cmd/replication/main.go b/cmd/replication/main.go index fb40b661..40de3557 100644 --- a/cmd/replication/main.go +++ b/cmd/replication/main.go @@ -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, ) diff --git a/pkg/utils/namespace.go b/pkg/utils/namespace.go new file mode 100644 index 00000000..67276c16 --- /dev/null +++ b/pkg/utils/namespace.go @@ -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] +}