Skip to content

Commit

Permalink
CN - Fix URSM / Entity Manager short circuit logic (#4005)
Browse files Browse the repository at this point in the history
  • Loading branch information
SidSethi committed Oct 7, 2022
1 parent dcd8b30 commit c6d058d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 58 deletions.
2 changes: 1 addition & 1 deletion creator-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions creator-node/src/config.js
Expand Up @@ -306,19 +306,6 @@ const config = convict({
env: 'delegatePrivateKey',
default: null
},
// wallet information
oldDelegateOwnerWallet: {
doc: 'wallet address',
format: String,
env: 'oldDelegateOwnerWallet',
default: ''
},
oldDelegatePrivateKey: {
doc: 'private key string',
format: String,
env: 'oldDelegatePrivateKey',
default: ''
},
solDelegatePrivateKeyBase64: {
doc: 'Base64-encoded Solana private key created using delegatePrivateKey as the seed (auto-generated -- any input here will be overwritten)',
format: String,
Expand Down
36 changes: 19 additions & 17 deletions creator-node/src/services/URSMRegistrationManager.js
Expand Up @@ -25,11 +25,11 @@ class URSMRegistrationManager {
this.nodeConfig = nodeConfig
this.audiusLibs = audiusLibs

this.delegateOwnerWallet = nodeConfig.get('delegateOwnerWallet')
this.delegateOwnerWallet = nodeConfig
.get('delegateOwnerWallet')
.toLowerCase()
this.delegatePrivateKey = nodeConfig.get('delegatePrivateKey')
this.spOwnerWallet = nodeConfig.get('spOwnerWallet')
this.oldDelegateOwnerWallet = this.nodeConfig.get('oldDelegateOwnerWallet')
this.oldDelegatePrivateKey = this.nodeConfig.get('oldDelegatePrivateKey')
this.entityManagerReplicaSetEnabled = this.nodeConfig.get(
'entityManagerReplicaSetEnabled'
)
Expand Down Expand Up @@ -69,6 +69,15 @@ class URSMRegistrationManager {
* 5. Submit registration transaction to URSM with signatures
*/
async run() {
if (this.entityManagerReplicaSetEnabled) {
// Update config
this.nodeConfig.set('isRegisteredOnURSM', true)

this.logInfo(`When EntityManager is enabled, URSM is not applicable`)

return
}

this.logInfo('Beginning URSM registration process')

/**
Expand Down Expand Up @@ -112,6 +121,12 @@ class URSMRegistrationManager {
throw new Error('Failed to find valid L1 record for node')
}

if (this.delegateOwnerWallet !== delegateOwnerWalletFromSPFactory) {
throw new Error(
`Local delegateOwnerWallet config (${this.delegateOwnerWallet}) doesn't match delegateOwnerWalletFromSPFactory (${delegateOwnerWalletFromSPFactory}) for spID ${spID}`
)
}

/**
* 2. Fetch node record from L2 UserReplicaSetManager for spID
*/
Expand All @@ -124,15 +139,7 @@ class URSMRegistrationManager {
/**
* 2-a. Short-circuit if L2 record for node already matches L1 record (i.e. delegateOwnerWallets match)
*/
const activeDelegateOwnerWallet =
this.oldDelegateOwnerWallet || this.delegateOwnerWallet
this.logError(
`activeDelegateOwnerWallet: ${activeDelegateOwnerWallet.toLowerCase()} // delegateOwnerWalletFromURSM: ${delegateOwnerWalletFromURSM}`
)
if (
!this.entityManagerReplicaSetEnabled &&
activeDelegateOwnerWallet.toLowerCase() === delegateOwnerWalletFromURSM
) {
if (this.delegateOwnerWallet === delegateOwnerWalletFromURSM) {
// Update config
this.nodeConfig.set('isRegisteredOnURSM', true)

Expand All @@ -142,11 +149,6 @@ class URSMRegistrationManager {
return
}

if (this.oldDelegateOwnerWallet) {
// New node registration is disabled if using oldDelegateOwnerWallet and above URSM check failed
throw new Error('Something went wrong if we got here')
}

/**
* 3. Fetch list of all nodes registered on URSM, in order to submit requests for proposal
* a. Randomize list to minimize bias
Expand Down
4 changes: 2 additions & 2 deletions creator-node/src/services/initAudiusLibs.js
Expand Up @@ -34,7 +34,7 @@ module.exports = async ({
const entityManagerAddress = config.get('entityManagerAddress')
const dataProviderUrl = config.get('dataProviderUrl')
const delegatePrivateKey = config.get('delegatePrivateKey')
const oldDelegatePrivateKey = config.get('oldDelegatePrivateKey')

const creatorNodeIsDebug = config.get('creatorNodeIsDebug')

const discoveryProviderWhitelist = discoveryProviderWhitelistConfig
Expand Down Expand Up @@ -74,7 +74,7 @@ module.exports = async ({
// pass as array
[dataProviderUrl],
// TODO - formatting this private key here is not ideal
(oldDelegatePrivateKey || delegatePrivateKey).replace('0x', ''),
delegatePrivateKey.replace('0x', ''),
entityManagerAddress
)
: null,
Expand Down
25 changes: 0 additions & 25 deletions mad-dog/src/tests/test_integration.js
Expand Up @@ -76,31 +76,6 @@ module.exports = coreIntegration = async ({
}) => {
// Begin: Test Setup

// If running with UserReplicaSetManager deployed, wait until all Content Nodes are registered on it
const URSMClient = await executeOne(0, libs => libs.libsInstance.contracts.UserReplicaSetManagerClient)
if (URSMClient) {
let retryCount = 0
const retryLimit = 10
const retryIntervalMs = 10000 // 10sec
while (true) {
console.log(`Ensuring correct URSM state with interval ${retryIntervalMs} || attempt #${retryCount} ...`)

const URSMContentNodes = await executeOne(0, libs => getURSMContentNodes(libs))

if (URSMContentNodes.length === numCreatorNodes) {
break
}

if (retryCount >= retryLimit) {
return { error: `URSM state not correctly initialized after ${retryIntervalMs * retryLimit}ms` }
}

retryCount++

await delay(retryIntervalMs)
}
}

// create tmp storage dir
await fs.ensureDir(TEMP_STORAGE_PATH)
await fs.ensureDir(TEMP_IMG_STORAGE_PATH)
Expand Down

0 comments on commit c6d058d

Please sign in to comment.