Skip to content

Commit

Permalink
Add support for creating namespaced databases
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas committed Dec 2, 2024
1 parent 6170b9b commit 6383a48
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
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
2 changes: 1 addition & 1 deletion dev/contracts/deploy-ephemeral
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ source dev/contracts/.env

cd ./contracts

forge create --legacy --json --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "$1:$2"
forge create --legacy --json --broadcast --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "$1:$2"
4 changes: 3 additions & 1 deletion dev/contracts/deploy-local
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# Deploy the smart contracts to the local anvil node

set -euo pipefail

source dev/contracts/.env

# Make sure the build directory exists
Expand All @@ -10,7 +12,7 @@ cd ./contracts

# Deploy a contract and save the output (which includes the contract address) to a JSON file to be used in tests
function deploy_contract() {
forge create --legacy --json --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "$1:$2" > ../build/$2.json
forge create --legacy --json --broadcast --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "$1:$2" > ../build/$2.json
}

deploy_contract src/GroupMessages.sol GroupMessages
Expand Down
1 change: 1 addition & 0 deletions dev/contracts/deploy-testnet
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cd ./contracts
function deploy_contract() {
forge create \
--rpc-url $RPC_URL \
--broadcast \
--chain=241320161 \
--compiler-version=0.8.28 \
--verify \
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 6383a48

Please sign in to comment.