Skip to content

Commit

Permalink
Run comms locally via audius-compose (#7028)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyrombo authored Dec 27, 2023
1 parent 14385bf commit dea3dfb
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 27 deletions.
2 changes: 1 addition & 1 deletion comms/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ COPY --from=builder /app/comms /bin/comms

EXPOSE 4222
VOLUME ["/tmp"]
ENTRYPOINT ["comms"]
CMD ["comms"]
7 changes: 7 additions & 0 deletions comms/discovery/pubkeystore/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func Dial(discoveryConfig *config.DiscoveryConfig) error {
finalPoaBlock = 30000000
}

if discoveryConfig.IsDev {
acdcEndpoint = "http://audius-protocol-poa-ganache-1"
poaEndpoint = "http://audius-protocol-poa-ganache-1" // won't ever be used
verifyingContract = "0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B"
finalPoaBlock = -1
}

poaClient, err = ethclient.Dial(poaEndpoint)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/EntityManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract EntityManager is SigningLogicInitializable {

function initialize(
address _verifierAddress,
uint _networkId
uint _chainId
) public initializer
{
require(
Expand All @@ -41,7 +41,7 @@ contract EntityManager is SigningLogicInitializable {
SigningLogicInitializable.initialize(
"Entity Manager",
"1",
_networkId
_chainId
);
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/migrations/2_entity_manager_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ module.exports = (deployer, network, accounts) => {
const config = contractConfig[network]
const proxyAdminAddress =
config.blacklisterAddress || accounts[accounts.length - 1]
const networkId = await web3.eth.net.getId()
console.log(`Deploying EntityManager to ${networkId}`)
const chainId = await web3.eth.getChainId()
console.log(`Deploying EntityManager to ${chainId}`)
const deployLogicTx = await deployer.deploy(EntityManager)
const logicContractAddress = deployLogicTx.address
console.log(logicContractAddress)
const verifierAddress = config.verifierAddress || accounts[0]
const initializeData = encodeCall(
'initialize',
['address', 'uint'],
[verifierAddress, networkId]
[verifierAddress, chainId]
)
// Deploy proxy contract with encoded initialize function
let deployedProxyTx = await deployer.deploy(
Expand Down
10 changes: 7 additions & 3 deletions dev-tools/compose/docker-compose.discovery.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ services:
build:
context: ${PROJECT_ROOT}/comms
dockerfile: Dockerfile
command: discovery
command: sh -c ". /tmp/dev-tools/startup/startup.sh && comms discovery"
restart: unless-stopped
env_file: .env # used by the startup script
environment:
comms_dev_mode: true
audius_delegate_private_key: 'c82ad757622db5a148089e0a8fc1741cefa8677ab56a2ac9e38dac905c5ad7c7'
audius_db_url: 'postgresql://postgres:postgres@db:5432/discovery_provider_1'
depends_on:
db:
condition: service_healthy
deploy:
mode: replicated
replicas: '${DISCOVERY_PROVIDER_REPLICAS}'
volumes:
- ${PROJECT_ROOT}/dev-tools:/tmp/dev-tools

trpc:
build:
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/compose/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ services:
build:
context: ${PROJECT_ROOT}/comms
dockerfile: Dockerfile
command: discovery-migrations
command: comms discovery-migrations
environment:
audius_db_url: 'postgres://postgres:postgres@discovery-provider-db:5432/discovery_provider?sslmode=disable'
depends_on:
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ x-common: &common
driver: json-file
extra_hosts:
# Allows the containers can talk to each other via their hostnames routed through nginx
- 'audius-protocol-comms-discovery-1:host-gateway'
- 'audius-protocol-comms-discovery-2:host-gateway'
- 'audius-protocol-comms-discovery-3:host-gateway'
- 'audius-protocol-comms-1:host-gateway'
- 'audius-protocol-comms-2:host-gateway'
- 'audius-protocol-comms-3:host-gateway'
- 'audius-protocol-creator-node-1:host-gateway'
- 'audius-protocol-creator-node-2:host-gateway'
- 'audius-protocol-creator-node-3:host-gateway'
Expand Down
42 changes: 39 additions & 3 deletions dev-tools/compose/nginx_ingress.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
# COMMS. Routes to containers for: audius-protocol-storage-1 audius-protocol-storage-2 audius-protocol-storage-3 audius-protocol-storage-4 audius-protocol-discovery-1 audius-protocol-discovery-2 audius-protocol-discovery-3
# Comes from comms/nginx/ingress.conf
#
include comms_ingress.conf;
# include comms_ingress.conf;

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

#
# DISCOVERY PROVIDER. Uses port 5000 to forward to the same nginx that stage and prod use (i.e., discovery-provider/nginx_conf/nginx.conf)
Expand Down Expand Up @@ -37,6 +42,17 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~ ^/comms(/.*)?$ {
resolver 127.0.0.11 valid=30s;
proxy_pass http://audius-protocol-comms-1:8925/comms$1$is_args$args;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# for websockets:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

location ^~ /healthz {
resolver 127.0.0.11 valid=30s;
proxy_pass http://healthz;
Expand All @@ -51,7 +67,6 @@ server {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}


Expand Down Expand Up @@ -81,6 +96,17 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~ ^/comms(/.*)?$ {
resolver 127.0.0.11 valid=30s;
proxy_pass http://audius-protocol-comms-2:8925/comms$1$is_args$args;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# for websockets:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

location ^~ /healthz {
resolver 127.0.0.11 valid=30s;
proxy_pass http://healthz;
Expand Down Expand Up @@ -123,6 +149,17 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~ ^/comms(/.*)?$ {
resolver 127.0.0.11 valid=30s;
proxy_pass http://audius-protocol-comms-1:8925/comms$1$is_args$args;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# for websockets:
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

location ^~ /healthz {
resolver 127.0.0.11 valid=30s;
proxy_pass http://healthz;
Expand All @@ -137,7 +174,6 @@ server {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}

#
Expand Down
16 changes: 16 additions & 0 deletions dev-tools/startup/comms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh
if [[ "$audius_db_url" == "" ]]; then
export audius_db_url="postgresql://postgres:postgres@audius-protocol-db-1:5432/discovery_provider_${replica}"
export audius_db_url_read_replica="postgresql://postgres:postgres@audius-protocol-db-1:5432/discovery_provider_${replica}"
fi

if [[ "$audius_redis_url" == "" ]]; then
export audius_redis_url="redis://audius-protocol-discovery-provider-redis-${replica}:6379/00"
fi

export audius_enable_rsyslog=false

export audius_discprov_url="http://audius-protocol-discovery-provider-${replica}"

export audius_delegate_owner_wallet=$(printenv "DP${replica}_DELEGATE_OWNER_ADDRESS")
export audius_delegate_private_key=$(printenv "DP${replica}_DELEGATE_OWNER_PRIVATE_KEY")
2 changes: 1 addition & 1 deletion dev-tools/startup/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# NOTE: This script is meant to be used from within docker containers

name=$(nslookup $(hostname -i) | grep -o "\(discovery-provider\|identity-service\)-[0-9]\+")
name=$(nslookup $(hostname -i) | grep -o "\(discovery-provider\|identity-service\|comms\)-[0-9]\+")
replica=$(echo $name | grep -o "[0-9]\+")

if [[ -f "/tmp/dev-tools/startup/$name.env" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ jest.mock('../../utils/web3', () => {
return jest.fn().mockImplementation(() => {
return {
eth: {
net: {
getId: () => ''
},
getChainId: () => '',
Contract: jest.fn().mockImplementation(() => ({
methods: {
manageEntity: () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class EntityManager implements EntityManagerService {
Pick<TransactionReceipt, 'blockHash' | 'blockNumber'>
> {
const nonce = await signatureSchemas.getNonce()
const chainId = Number(await this.web3.eth.net.getId())
const chainId = Number(await this.web3.eth.getChainId())
const signatureData = signatureSchemas.generators.getManageEntityData(
chainId,
this.config.contractAddress,
Expand Down
7 changes: 3 additions & 4 deletions packages/libs/src/services/contracts/ContractClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,10 @@ export class ContractClient {
return method
}

async getEthNetId() {
async getEthChainId() {
await this.init()
const netId = await this.web3Manager.getWeb3().eth.net.getId()

return netId
const chainId = await this.web3Manager.getWeb3().eth.getChainId()
return chainId
}

async getContract() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class EntityManagerClient extends ContractClient {
privateKey?: string
): Promise<[string, string]> {
const nonce = await signatureSchemas.getNonce()
const chainId = await this.getEthNetId()
const chainId = await this.getEthChainId()
const contractAddress = await this.getAddress()
const signatureData = signatureSchemas.generators.getManageEntityData(
chainId,
Expand Down Expand Up @@ -107,7 +107,7 @@ export class EntityManagerClient extends ContractClient {
privateKey?: string
): Promise<{ txReceipt: TransactionReceipt }> {
const nonce = await signatureSchemas.getNonce()
const chainId = await this.getEthNetId()
const chainId = await this.getEthChainId()
const contractAddress = await this.getAddress()
const nethermindContractAddress = await this.getNethermindAddress()
const signatureData = signatureSchemas.generators.getManageEntityData(
Expand Down

0 comments on commit dea3dfb

Please sign in to comment.