Adam Fuller
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # On-chain epoch oracle > This is a placeholder detailed specification for the **Protocol Chain Epoch Oracle proposal**. We will introduce an Epoch Block Oracle contract which will track the "Epoch Block" for all networks supported for indexing rewards. Indexers will use block hashes specified by this oracle to close their allocations. ## On-chain Epoch Block Oracle Create a simple contract which tracks the block number to close allocations for the latest epoch. A sketch of what this might look like in Solidity: ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract EpochOracle is Ownable { event networkAdded(string _network); event networkRemoved(string _network); event newEpochBlock(uint256 _epoch, uint256 _networkId, string _blockHash); error NetworkExists(); constructor(address _owner) { transferOwnership(address _owner); } // count of supported networks uint256 public networkCounter; // mapping of supported networks to IDs to reduce cost of ongoing updates mapping(string => uint256) public networkIds; mapping(uint256 => string) public names; // mapping from internal ID to the latest block hash mapping(uint => string) public epochBlockLookup; // current epoch uint256 public epoch; // Add support for a new network function addNetwork(string calldata newNetwork) onlyOwner { if(networkIds[newNetwork] > 0) revert NetworkExists(); networkCounter++; networkIds[newNetwork] = networkCounter; names[networkCounter] = newNetwork; } // Remove support for a network (does not decrement counter) function removeNetwork(string calldata removedNetwork) onlyOwner { delete epochBlockLookup[networkIds[removedNetwork]]; delete names[networkCounter]; } // helper to get the latest epochBlock function getEpochBlock(string calldata _network) view returns(string memory) { uint256 networkId = networkIds[_network]; return epochBlockLookup[networkId]; } struct epochBlockUpdate { uint256 networkId; string blockHash; } // set multiple epoch blocks function setEpochBlocks(uint256 _epoch, epochBlockUpdate[] calldata _updates) public onlyOwner { // this could be set automatically using the EpochManager // but that makes some assumptions about the process epoch = _epoch; for (uint256 i = 0; i < _updates.length; i++) { uint256 networkId = _updates[i].networkId; // only allow updates for active networks if(networkId <= networkCounter && !names[networkId]) { epochBlock[networkId] = _updates[i].blockHash; emit newEpochBlock(_epoch, networkId, _updates[i].blockHash); } } } }; ``` The Owner would be responsible for fetching the blocks from the different chains, and deciding which ones should be used to close the current Epoch. The Owner therefore has some operational requirements: - Connecting to all of the networks supported for indexing on The Graph Network - Identifying the epoch block across those chains - The rule for Mainnet Ethereum will be unchanged - The Owner will need a mechanism to match that block to the simultaneous block those chains > Precision here is less important than having a block that is on the main chain in an appropriate time-frame - Calling `setEpochBlock` to update the Epoch Block Oracle - This will be required once per epoch (~24 hours) - The oracle will need to wait some time between the start of the Epoch & calling this function to allow for re-orgs - Monitoring the stability & performance of the Oracle to ensure that Epochs are being updated Initially the Owner will be managed by members of The Graph Protocol's core development teams, in line with other trusted network components (the gateway, the subgraph oracle). > This proposal assumes that the Oracle is deployed on Ethereum Mainnet, however it could be deployed elsewhere. That could reduce gas costs for management, but it would reduce security and composability, and increase the operational burden for indexers. ### Update the EpochManager The Epoch manager will need to be updated to support this new system. > Notable is the fact that this propsal uses `blockHash`, rather than `blockNumber`, for cross-chain determinism. ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IEpochOracle.sol" contract EpochManager { /... .../ IEpochOracle public epochOracle; function setEpochOracle(address newEpochOracle) onlyOwner { epochOracle = IEPochOracle(newEpochOracle); } function currentEpochBlock(string network) view returns(string memory) { return epochOracle.getEpochBlock(network) } }; ``` The `currentEpochBlock()` function can remain the same (returning a blockNumber), for backwards compabitility. Indexers could then query `currentEpochBlock("polygon")` to get the block to use in order to close allocations. > An alternative implementation could deploy the Oracle on a chain other than Ethereum Mainnet, in which case the above change would not be required, but instead the Indexer Agent would need to fetch the information from wherever the Oracle is deployed. ### Update the Indexer Agent The Indexer Agent currently fetches the `currentEpochBlock` from the `EpochManager` ([link](https://github.com/graphprotocol/indexer/blob/main/packages/indexer-agent/src/agent.ts#L179)), and finds the blockHash by fetching the block from an Ethereum client. This will need to be updated to fetch the Epoch Block for the relevant network from the proposed `currentEpochBlock(string network)` function, which will depend on which network a subgraph is indexing. > An alternative implementation could deploy the Oracle on a chain other than Ethereum Mainnet, in which case the Indexer Agent would need to fetch the information from wherever the Oracle is deployed. ### Track the block for allocation closure Track the block hash for an allocation closure. > This is optional: it would improve legibility for other ecosystem participants, and simplify arbitration, but it would also increase the cost of closing an allocation, which is currently a signficant pain point for indexers. There is an open [Pull Request](https://github.com/graphprotocol/contracts/pull/506) which implements this, and also looks to introduce [recency checking for mainnet subgraphs](https://forum.thegraph.com/t/require-that-more-recent-pois-are-submitted-in-order-to-collect-indexing-rewards-multi-blockhain-pois/2500) - the latter functionality is not feasible for non-mainnet subgraphs. ### Update the Arbitration Charter The Arbitration Charter will need to reflect the change in requirements for allocation closure - in order to be eligible for Indexing Rewards, an allocation must be closed with a POI for the block specified by the Epoch Block Oracle, for the relevant epoch:network. To allow for cases where allocations are being closed when the epoch is being updated, the existing N-1 policy should remain in place. ### Update the Subgraph Oracle The Subgraph Oracle will need to check with the Epoch Block Oracle if there is an Epoch Block available for the network a subgraph is indexing. If there is, then the subgraph will be eligible for indexing rewards.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully