{
    "Function": "_updateMiddlewareList",
    "File": "src/contracts/core/Slasher.sol",
    "Parent Contracts": [
        "src/contracts/permissions/Pausable.sol",
        "src/contracts/interfaces/IPausable.sol",
        "src/contracts/interfaces/ISlasher.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol",
        "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"
    ],
    "High-Level Calls": [
        "StructuredLinkedList",
        "StructuredLinkedList",
        "StructuredLinkedList",
        "StructuredLinkedList",
        "StructuredLinkedList"
    ],
    "Internal Calls": [
        "_addressToUint",
        "_uintToAddress",
        "_updateMiddlewareList",
        "getCorrectValueForInsertAfter",
        "_uintToAddress",
        "_addressToUint",
        "require(bool,string)",
        "_updateMiddlewareList",
        "_uintToAddress",
        "require(bool,string)",
        "getCorrectValueForInsertAfter"
    ],
    "Library Calls": [
        "insertAfter",
        "pushFront",
        "getHead",
        "nodeExists",
        "getNextNode"
    ],
    "Low-Level Calls": [],
    "Code": "function _updateMiddlewareList(address operator, uint32 updateBlock, uint256 insertAfter) internal {\n        /**\n         * boolean used to track if the `insertAfter input to this function is incorrect. If it is, then `runFallbackRoutine` will\n         * be flipped to 'true', and we will use `getCorrectValueForInsertAfter` to find the correct input. This routine helps solve\n         * a race condition where the proper value of `insertAfter` changes while a transaction is pending.\n         */\n       \n        bool runFallbackRoutine = false;\n        // If this condition is met, then the `updateBlock` input should be after `insertAfter`'s latest updateBlock\n        if (insertAfter != HEAD) {\n            // Check that `insertAfter` exists. If not, we will use the fallback routine to find the correct value for `insertAfter`.\n            if (!_operatorToWhitelistedContractsByUpdate[operator].nodeExists(insertAfter)) {\n                runFallbackRoutine = true;\n            }\n\n            /**\n             * Make sure `insertAfter` specifies a node for which the most recent updateBlock was *at or before* updateBlock.\n             * Again, if not,  we will use the fallback routine to find the correct value for `insertAfter`.\n             */\n            if ((!runFallbackRoutine) && (_whitelistedContractDetails[operator][_uintToAddress(insertAfter)].latestUpdateBlock > updateBlock)) {\n                runFallbackRoutine = true;\n            }\n\n            // if we have not marked `runFallbackRoutine` as 'true' yet, then that means the `insertAfter` input was correct so far\n            if (!runFallbackRoutine) {\n                // Get `insertAfter`'s successor. `hasNext` will be false if `insertAfter` is the last node in the list\n                (bool hasNext, uint256 nextNode) = _operatorToWhitelistedContractsByUpdate[operator].getNextNode(insertAfter);\n                if (hasNext) {\n                    /**\n                     * Make sure the element after `insertAfter`'s most recent updateBlock was *strictly after* `updateBlock`.\n                     * Again, if not,  we will use the fallback routine to find the correct value for `insertAfter`.\n                     */\n                    if (_whitelistedContractDetails[operator][_uintToAddress(nextNode)].latestUpdateBlock <= updateBlock) {\n                        runFallbackRoutine = true;\n                    }\n                }\n            }\n\n            // if we have not marked `runFallbackRoutine` as 'true' yet, then that means the `insertAfter` input was correct on all counts\n            if (!runFallbackRoutine) {\n                /** \n                 * Insert the caller (middleware) after `insertAfter`.\n                 * This will fail if `msg.sender` is already in the list, which they shouldn't be because they were removed from the list above.\n                 */\n                require(_operatorToWhitelistedContractsByUpdate[operator].insertAfter(insertAfter, _addressToUint(msg.sender)),\n                    \"Slasher.recordStakeUpdate: Inserting middleware unsuccessful\");\n            // in this case (runFallbackRoutine == true), we run a search routine to find the correct input value of `insertAfter` and then rerun this function\n            } else {\n                insertAfter = getCorrectValueForInsertAfter(operator, updateBlock);\n                _updateMiddlewareList(operator, updateBlock, insertAfter);\n            }\n        // In this case (insertAfter == HEAD), the `updateBlock` input should be before every other middleware's latest updateBlock.\n        } else {\n            /**\n             * Check that `updateBlock` is before any other middleware's latest updateBlock.\n             * If not, use the fallback routine to find the correct value for `insertAfter`.\n             */\n            if (_whitelistedContractDetails[operator][\n                _uintToAddress(_operatorToWhitelistedContractsByUpdate[operator].getHead()) ].latestUpdateBlock <= updateBlock)\n            {\n                runFallbackRoutine = true;\n            }\n            // if we have not marked `runFallbackRoutine` as 'true' yet, then that means the `insertAfter` input was correct on all counts\n            if (!runFallbackRoutine) {\n                /**\n                 * Insert the middleware at the start (i.e. HEAD) of the list.\n                 * This will fail if `msg.sender` is already in the list, which they shouldn't be because they were removed from the list above.\n                 */\n                require(_operatorToWhitelistedContractsByUpdate[operator].pushFront(_addressToUint(msg.sender)), \n                    \"Slasher.recordStakeUpdate: Preppending middleware unsuccessful\");\n            // in this case (runFallbackRoutine == true), we run a search routine to find the correct input value of `insertAfter` and then rerun this function\n            } else {\n                insertAfter = getCorrectValueForInsertAfter(operator, updateBlock);\n                _updateMiddlewareList(operator, updateBlock, insertAfter);\n            }\n        }\n    }"
}