Skip to content

Commit

Permalink
Revert "[AUD-726] Support create sender public in discovery" (#2083)
Browse files Browse the repository at this point in the history
* Revert "[AUD-726] Support create sender public in discovery (#1808)"

This reverts commit 6492534.

* Revert "Fix discovery test broken in 6492534 (#2082)"

This reverts commit 0820e93.
  • Loading branch information
rickyrombo committed Nov 20, 2021
1 parent ff46b65 commit e6f8fac
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 68 deletions.
3 changes: 1 addition & 2 deletions discovery-provider/.test.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# TODO: dummy ganache keys for local setup; should wire with dynamically generated keys
audius_delegate_owner_wallet=0x1D9c77BcfBfa66D37390BF2335f0140979a6122B
audius_delegate_private_key=0x3873ed01bfb13621f9301487cc61326580614a5b99f3c33cf39c6f9da3a19cad
audius_solana_rewards_manager_account=8MzNUaBHskteN7poTrZG5wgSNSbXQwieMDB4wk9fgB7f
audius_delegate_private_key=0x3873ed01bfb13621f9301487cc61326580614a5b99f3c33cf39c6f9da3a19cad
17 changes: 3 additions & 14 deletions discovery-provider/src/queries/get_attestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from hexbytes import HexBytes
from sqlalchemy.orm.session import Session
from sqlalchemy.sql.elements import and_
from solana.publickey import PublicKey
from src.models.models import (
Challenge,
ChallengeDisbursement,
Expand All @@ -21,9 +20,7 @@
get_oracle_addresses_from_chain,
)

REWARDS_MANAGER_PROGRAM_ACCOUNT = PublicKey(
shared_config["solana"]["rewards_manager_account"]
)
REWARDS_MANAGER_PROGRAM = shared_config["solana"]["rewards_manager_program_address"]
ATTESTATION_DECIMALS = 9


Expand Down Expand Up @@ -114,8 +111,7 @@ def get_attestation(
"""
Returns a owner_wallet, signed_attestation tuple,
or throws an error explaining why the attestation was
not able to be created.
"""
not able to be created."""
if not user_id or not challenge_id or not oracle_address:
raise AttestationError(INVALID_INPUT)

Expand Down Expand Up @@ -193,20 +189,13 @@ def verify_discovery_node_exists_on_chain(new_sender_address: str) -> bool:


def get_create_sender_attestation(new_sender_address: str) -> Tuple[str, str]:
"""
Returns a owner_wallet, signed_attestation tuple,
or throws an error explaining why the sender attestation was
not able to be created.
"""
is_valid = verify_discovery_node_exists_on_chain(new_sender_address)
if not is_valid:
raise Exception(f"Expected {new_sender_address} to be registered on chain")

items = [
to_bytes(text=ADD_SENDER_MESSAGE_PREFIX),
# Solana PubicKey should be coerced to bytes using the pythonic bytes method
# See https://michaelhly.github.io/solana-py/solana.html#solana.publickey.PublicKey
bytes(REWARDS_MANAGER_PROGRAM_ACCOUNT),
to_bytes(hexstr=REWARDS_MANAGER_PROGRAM),
to_bytes(hexstr=new_sender_address),
]
attestation_bytes = to_bytes(text="").join(items)
Expand Down
1 change: 1 addition & 0 deletions discovery-provider/src/utils/get_all_other_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
SP_FACTORY_REGISTRY_KEY = bytes("ServiceProviderFactory", "utf-8")
DISCOVERY_NODE_SERVICE_TYPE = bytes("discovery-node", "utf-8")


# Perform eth web3 call to fetch endpoint info
def fetch_discovery_node_info(sp_id, sp_factory_instance):
return sp_factory_instance.functions.getServiceEndpointInfo(
Expand Down
42 changes: 5 additions & 37 deletions discovery-provider/tests/test_get_attestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from hexbytes import HexBytes

from src.queries.get_attestation import (
ADD_SENDER_MESSAGE_PREFIX,
REWARDS_MANAGER_PROGRAM_ACCOUNT,
Attestation,
AttestationError,
get_attestation,
Expand Down Expand Up @@ -138,40 +136,10 @@ def test_get_create_sender_attestation(app, patch_get_all_other_nodes):
new_sender_address = "0x94e140D27F3d5EE9EcA0109A71CcBa0109964DCa"
owner_wallet, sender_attestation = get_create_sender_attestation(new_sender_address)

# confirm the attestation is what we think it should be
config_owner_wallet = shared_config["delegate"]["owner_wallet"]
config_private_key = shared_config["delegate"]["private_key"]

# Ensure we returned the correct owner wallet
assert owner_wallet == config_owner_wallet

# Ensure we can derive the owner wallet from the signed stringified attestation
items = [
to_bytes(text=ADD_SENDER_MESSAGE_PREFIX),
bytes(REWARDS_MANAGER_PROGRAM_ACCOUNT),
to_bytes(hexstr=new_sender_address),
]
attestation_bytes = to_bytes(text="").join(items)
to_sign_hash = Web3.keccak(attestation_bytes)
private_key = keys.PrivateKey(HexBytes(config_private_key))
public_key = keys.PublicKey.from_private(private_key)
signture_bytes = to_bytes(hexstr=sender_attestation)
msg_signature = keys.Signature(signature_bytes=signture_bytes, vrs=None)

recovered_pubkey = public_key.recover_from_msg_hash(
message_hash=to_sign_hash, signature=msg_signature
)

assert owner_wallet == "0x1D9c77BcfBfa66D37390BF2335f0140979a6122B"
assert (
Web3.toChecksumAddress(recovered_pubkey.to_address())
== config_owner_wallet
sender_attestation
== "0xdea0857f45136b5b986b45303d00051bb4c96313"
+ "3c0e75945534a3bca1e6702d10106357a1d72e68c90f"
+ "7d46f69f4023518ccc211a7994b41d359c9ea5d65f9700"
)


def test_get_create_sender_attestation_not_registered(app, patch_get_all_other_nodes):
new_sender_address = "0x04e140D27F3d5EE9EcA0109A71CcBa0109964DCa"
with pytest.raises(
Exception,
match=r"Expected 0x04e140D27F3d5EE9EcA0109A71CcBa0109964DCa to be registered on chain"
):
get_create_sender_attestation(new_sender_address)
3 changes: 1 addition & 2 deletions discovery-provider/tests/test_index_rewards_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from tests.utils import populate_mock_db

REWARDS_MANAGER_PROGRAM = shared_config["solana"]["rewards_manager_program_address"]
REWARDS_MANAGER_ACCOUNT = shared_config["solana"]["rewards_manager_account"]


def test_decode_reward_manager_transfer_instruction():
Expand Down Expand Up @@ -177,7 +176,7 @@ def test_parse_transfer_instruction_id():
"transaction": {
"message": {
"accountKeys": [
REWARDS_MANAGER_ACCOUNT,
"2HYDf9XvHRKhquxK1z4ETJ8ywueZcqEazyFZdRfLqGcT",
"54u7LVJhhbWaENGLzzgvTX72k9XSHSF3EhCcuvD9xMfk",
"3zKGHtF9aNjevZ2DETXzTDWiN65Fkwv9oeiScAfSVh3H",
"9ShGNjEm5repSKTkZMUXMj8cx31HAo363ovdm1AoLA8d",
Expand Down
4 changes: 2 additions & 2 deletions libs/initScripts/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ const run = async () => {
break
}

case 'register-discovery-node':
case 'register-discprov':
const serviceCount = args[3]
if (serviceCount === undefined) throw new Error('register-discovery-node requires a service # as the second arg')
if (serviceCount === undefined) throw new Error('register-discprov requires a service # as the second arg')
await _registerDiscProv(ethAccounts, parseInt(serviceCount))
break

Expand Down
18 changes: 9 additions & 9 deletions service-commands/scripts/rewardManagerLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,29 +223,29 @@ const createSenderLocal = async ethAddress => {
}
}

const findEthAddressForDiscoveryNodeAndRegister = async serviceNumber => {
const findEthAddressForDiscProvAndRegister = async serviceNumber => {
const ethWeb3 = new Web3(
new Web3.providers.HttpProvider('http://localhost:8546')
)
const ethAccounts = await ethWeb3.eth.getAccounts()
console.log(`Finding address for discovery node #${serviceNumber}`)
console.log(`Finding address for disc prov #${serviceNumber}`)
const accountIndex = 8 + parseInt(serviceNumber)
console.log(`Account index = ${accountIndex}`)
const discoveryNodeAccount = ethAccounts[accountIndex]
console.log(`Eth address for discovery node #${serviceNumber}=${discoveryNodeAccount}`)
await createSenderLocal(discoveryNodeAccount)
const discProvAccount = ethAccounts[accountIndex]
console.log(`Eth address for disc prov #${serviceNumber}=${discProvAccount}`)
await createSenderLocal(discProvAccount)
}

const args = process.argv
const run = async () => {
try {
switch (args[2]) {
case 'register-discovery-node':
case 'register-discprov':
const serviceCount = args[3]
console.log(`RewardManager | Registering discovery node ${serviceCount}`)
await findEthAddressForDiscoveryNodeAndRegister(serviceCount)
console.log(`RewardManager | Registering disc prov ${serviceCount}`)
await findEthAddressForDiscProvAndRegister(serviceCount)
console.log(
`RewardManager | Finished registering discovery node ${serviceCount}`
`RewardManager | Finished registering disc prov ${serviceCount}`
)
break
case 'register-eth-address':
Expand Down
4 changes: 2 additions & 2 deletions service-commands/src/commands/service-commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
"cd discovery-provider; . compose/env/unsetShellEnv.sh"
],
"register": [
"cd libs/; node initScripts/local.js register-discovery-node #",
"cd service-commands/; node scripts/rewardManagerLocal.js register-discovery-node #"
"cd libs/; node initScripts/local.js register-discprov #",
"cd service-commands/; node scripts/rewardManagerLocal.js register-discprov #"
],
"restart": [
"cd discovery-provider; . compose/env/unsetShellEnv.sh",
Expand Down

0 comments on commit e6f8fac

Please sign in to comment.