Skip to content

Add additional checks to checkContractIsRegistered - #309

Merged
JonoPrest merged 2 commits into
mainfrom
jp/fix-is-registered-check
Oct 30, 2024
Merged

Add additional checks to checkContractIsRegistered#309
JonoPrest merged 2 commits into
mainfrom
jp/fix-is-registered-check

Conversation

@JonoPrest

Copy link
Copy Markdown
Collaborator

Two potential cases for double registration handled:

  1. The newly introduced "pendingDynamicContracts" contains the dynamic contract
  2. The same batch contains a double registration

@JonoPrest
JonoPrest force-pushed the jp/fix-is-registered-check branch from dd413c2 to eaf9e61 Compare October 30, 2024 15:09
@JonoPrest
JonoPrest requested a review from DZakh October 30, 2024 15:09
Comment on lines +142 to +148
!checkContractIsRegistered(~chain, ~contractAddress, ~contractName=contractType) &&
!checkContractIsInCurrentRegistrations(
~dynamicContractRegistrations,
~chain,
~contractAddress,
~contractType,
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously it would be possible for two events in a batch to register the same contract

Comment on lines +878 to +890
let rec checkBaseRegisterContainsRegisteredContract = (
register: register,
~contractName,
self: register,
~contractAddress,
) => {
let addresses =
self.contractAddressMapping
->ContractAddressingMap.getAddresses(contractName)
->Option.mapWithDefault(addresses, newAddresses => {
addresses->Set.String.union(newAddresses)
})

switch self.registerType {
| RootRegister(_) => addresses
| DynamicContractRegister({nextRegister}) =>
nextRegister->getAllAddressesForContract(~addresses, ~contractName)
switch register.contractAddressMapping->ContractAddressingMap.getAddresses(contractName) {
| Some(addresses) if addresses->Belt.Set.String.has(contractAddress->Address.toString) => true
| _ =>
switch register.registerType {
| RootRegister(_) => false
| DynamicContractRegister({nextRegister}) =>
nextRegister->checkBaseRegisterContainsRegisteredContract(~contractName, ~contractAddress)
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved this function to early return rather than always iterate over all registers

Comment on lines +899 to +904
self.baseRegister->checkBaseRegisterContainsRegisteredContract(~contractName, ~contractAddress) ||
self.pendingDynamicContracts->Array.some(({dynamicContracts}) =>
dynamicContracts->Array.some(dcr =>
dcr.contractAddress == contractAddress && (dcr.contractType :> string) == contractName
)
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the check for pending dynamic contracts as well over here

@JonoPrest
JonoPrest force-pushed the jp/fix-is-registered-check branch from eaf9e61 to 1212125 Compare October 30, 2024 15:15

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@JonoPrest
JonoPrest merged commit f2b7427 into main Oct 30, 2024
@JonoPrest
JonoPrest deleted the jp/fix-is-registered-check branch October 30, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants