LightManager

Git Source

Inherits: AgentManager, InterfaceLightManager

LightManager keeps track of all agents on chains other than Synapse Chain. Is uses the Agent Merkle Roots from the Notary-signed attestations to stay in sync with the BondingManager. LightManager is responsible for the following:

  • Accepting the Agent Merkle Roots (passing the optimistic period check) from the Destination contract.
  • Using these roots to enable agents to register themselves by proving their status.
  • Accepting Manager Message from BondingManager on Synapse Chain to withdraw tips.
  • Sending Manager Messages to BondingManager on Synapse Chain to slash agents, when their fraud is proven.

State Variables

agentRoot

Returns the latest known root of the Agent Merkle Tree.

bytes32 public agentRoot;

_proposedAgentRoot

Pending Agent Merkle Root that was proposed by the contract owner.

bytes32 internal _proposedAgentRoot;

_agentRootProposedAt

Timestamp when the Agent Merkle Root was proposed by the contract owner.

uint256 internal _agentRootProposedAt;

_agentMap

mapping(bytes32 => mapping(address => AgentStatus)) private _agentMap;

_agents

mapping(uint256 => address) private _agents;

_agentIndexes

mapping(address => uint256) private _agentIndexes;

Functions

constructor

constructor(uint32 synapseDomain_) MessagingBase("0.0.3", synapseDomain_);

initialize

function initialize(address origin_, address destination_, address inbox_) external initializer;

proposeAgentRootWhenStuck

Allows contract owner to set the agent root to resolve the "stuck" chain by proposing the new agent root. The contract owner will be able to resolve the proposed agent root after a certain period of time. Note: this function could be called multiple times, each time the timer will be reset. This could only be called if no fresh data has been submitted by the Notaries to the Inbox, indicating that the chain is stuck for one of the reasons:

  • All active Notaries are in Dispute.
  • No active Notaries exist under the current agent root.

*Will revert if any of the following conditions is met:

  • Caller is not the contract owner.
  • Agent root is empty.
  • The chain is not in a stuck state (has recently received a fresh data from the Notaries).*
function proposeAgentRootWhenStuck(bytes32 agentRoot_) external onlyOwner onlyWhenStuck;

Parameters

NameTypeDescription
agentRoot_bytes32New Agent Merkle Root that is proposed to be set

cancelProposedAgentRoot

Allows contract owner to cancel the previously proposed agent root.

*Will revert if any of the following conditions is met:

  • Caller is not the contract owner.
  • No agent root was proposed.*
function cancelProposedAgentRoot() external onlyOwner;

resolveProposedAgentRoot

Allows contract owner to resolve the previously proposed agent root. This will update the agent root, allowing the agents to update their status, effectively resolving the "stuck" chain.

Should proceed with the proposed root, even if new Notary data is available. This is done to prevent rogue Notaries from going offline and then indefinitely blocking the agent root resolution, thus onlyWhenStuck modifier is not used here.

function resolveProposedAgentRoot() external onlyOwner;

updateAgentStatus

Updates agent status, using a proof against the latest known Agent Merkle Root.

Will revert if the provided proof doesn't match the latest merkle root.

function updateAgentStatus(address agent, AgentStatus memory status, bytes32[] memory proof) external;

Parameters

NameTypeDescription
agentaddressAgent address
statusAgentStatusStructure specifying agent status: (flag, domain, index)
proofbytes32[]Merkle proof of Active status for the agent

setAgentRoot

Updates the root of Agent Merkle Tree that the Light Manager is tracking. Could be only called by a local Destination contract, which is supposed to verify the attested Agent Merkle Roots.

function setAgentRoot(bytes32 agentRoot_) external;

Parameters

NameTypeDescription
agentRoot_bytes32New Agent Merkle Root

remoteWithdrawTips

Withdraws locked base message tips from local Origin to the recipient.

Could only be remote-called by BondingManager contract on Synapse Chain. Note: as an extra security check this function returns its own selector, so that Destination could verify that a "remote" function was called when executing a manager message.

function remoteWithdrawTips(uint32 msgOrigin, uint256 proofMaturity, address recipient, uint256 amount)
    external
    returns (bytes4 magicValue);

Parameters

NameTypeDescription
msgOriginuint32
proofMaturityuint256
recipientaddressAddress to withdraw tips to
amountuint256Tips value to withdraw

proposedAgentRootData

Returns the latest proposed agent root and the timestamp when it was proposed.

Will return zero values if no agent root was proposed, or if the proposed agent root was already resolved.

function proposedAgentRootData() external view returns (bytes32 agentRoot_, uint256 proposedAt_);

_afterAgentSlashed

function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual override;

_notifyDisputeOpened

Notify local AgentSecured contracts about the opened dispute.

function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal override;

_notifyDisputeResolved

Notify local AgentSecured contracts about the resolved dispute.

function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal override;

_setAgentRoot

Updates the Agent Merkle Root that Light Manager is tracking.

function _setAgentRoot(bytes32 _agentRoot) internal;

_storedAgentStatus

Returns the stored status for the agent: whether or not they have been added using latest Agent merkle Root.

function _storedAgentStatus(address agent) internal view override returns (AgentStatus memory);

_getAgent

Returns agent address for the given index. Returns zero for non existing indexes, or for indexes of the agents that have not been added to Light Manager yet.

function _getAgent(uint256 index) internal view override returns (address agent);

_getIndex

Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents, or for agents that have not been added to Light Manager yet.

function _getIndex(address agent) internal view override returns (uint256 index);