{
    "Function": "_recordUpdateAndAddToMiddlewareTimes",
    "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"
    ],
    "Internal Calls": [
        "_uintToAddress",
        "_addressToUint",
        "require(bool,string)",
        "_addressToUint"
    ],
    "Library Calls": [
        "getNextNode",
        "getHead"
    ],
    "Low-Level Calls": [],
    "Code": "function _recordUpdateAndAddToMiddlewareTimes(address operator, uint32 updateBlock, uint32 serveUntilBlock) internal {\n        // reject any stale update, i.e. one from before that of the most recent recorded update for the currently updating middleware\n        require(_whitelistedContractDetails[operator][msg.sender].latestUpdateBlock <= updateBlock, \n                \"Slasher._recordUpdateAndAddToMiddlewareTimes: can't push a previous update\");\n        _whitelistedContractDetails[operator][msg.sender].latestUpdateBlock = updateBlock;\n        // get the latest recorded MiddlewareTimes, if the operator's list of MiddlwareTimes is non empty\n        MiddlewareTimes memory curr;\n        uint256 _operatorToMiddlewareTimesLength = _operatorToMiddlewareTimes[operator].length;\n        if (_operatorToMiddlewareTimesLength != 0) {\n            curr = _operatorToMiddlewareTimes[operator][_operatorToMiddlewareTimesLength - 1];\n        }\n        MiddlewareTimes memory next = curr;\n        bool pushToMiddlewareTimes;\n        // if the serve until is later than the latest recorded one, update it\n        if (serveUntilBlock > curr.latestServeUntilBlock) {\n            next.latestServeUntilBlock = serveUntilBlock;\n            // mark that we need push next to middleware times array because it contains new information\n            pushToMiddlewareTimes = true;\n        } \n        \n        // If this is the very first middleware added to the operator's list of middleware, then we add an entry to _operatorToMiddlewareTimes\n        if (_operatorToWhitelistedContractsByUpdate[operator].size == 0) {\n            next.stalestUpdateBlock = updateBlock;\n            pushToMiddlewareTimes = true;\n        }\n        // If the middleware is the first in the list, we will update the `stalestUpdateBlock` field in MiddlewareTimes\n        else if (_operatorToWhitelistedContractsByUpdate[operator].getHead() == _addressToUint(msg.sender)) {\n            // if the updated middleware was the earliest update, set it to the 2nd earliest update's update time\n            (bool hasNext, uint256 nextNode) = _operatorToWhitelistedContractsByUpdate[operator].getNextNode(_addressToUint(msg.sender));\n\n            if (hasNext) {\n                // get the next middleware's latest update block\n                uint32 nextMiddlewaresLeastRecentUpdateBlock = _whitelistedContractDetails[operator][_uintToAddress(nextNode)].latestUpdateBlock;\n                if (nextMiddlewaresLeastRecentUpdateBlock < updateBlock) {\n                    // if there is a next node, then set the stalestUpdateBlock to its recorded value\n                    next.stalestUpdateBlock = nextMiddlewaresLeastRecentUpdateBlock;\n                } else {\n                    //otherwise updateBlock is the least recent update as well\n                    next.stalestUpdateBlock = updateBlock;\n                }\n            } else {\n                // otherwise this is the only middleware so right now is the stalestUpdateBlock\n                next.stalestUpdateBlock = updateBlock;\n            }\n            // mark that we need to push `next` to middleware times array because it contains new information\n            pushToMiddlewareTimes = true;\n        }\n        \n        // if `next` has new information, then push it\n        if (pushToMiddlewareTimes) {\n            _operatorToMiddlewareTimes[operator].push(next);\n            emit MiddlewareTimesAdded(operator, _operatorToMiddlewareTimes[operator].length - 1, next.stalestUpdateBlock, next.latestServeUntilBlock);\n        }\n    }"
}