GithubHelp home page GithubHelp logo

nomad-xyz / rust Goto Github PK

View Code? Open in Web Editor NEW
54.0 54.0 16.0 2.59 MB

Rust work for nomad actors

License: Apache License 2.0

Dockerfile 0.06% Rust 97.78% Shell 0.60% Python 1.02% TypeScript 0.53%

rust's People

Contributors

anna-carroll avatar arnaud036 avatar erinhales avatar imti avatar kekonen avatar lattejed avatar luketchang avatar mattsse avatar prestwich avatar psushi avatar yourbuddyconner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust's Issues

Document steps for running relayer

  • Describe what the agent does, namely forward signed updates from the home to configured replicas
  • Describe how configuration maps to relayer behavior (forwards updates for channels home to X replicas)
  • Describe behavior during failure modes for clarity

Allow external config files

Current agent configuration scheme is rigid and breaks when trying to supply external config file. Want to allow any arbitrary party to provide a unified config file and set of env vars to run agent against arbitrary networks.

  • Fix base config validation to allow for config files
  • Compare secrets against supplied config (whether builtin or from file)

document process to deploy contracts

copied from a Discord message which should be transcribed:

the code for deploying the contracts is here: https://github.com/nomad-xyz/monorepo/tree/main/packages/new-deploy

this script is an example of invoking the deploy script: https://github.com/nomad-xyz/monorepo/blob/5b603ee6f58c27d9d5dda6b2a1fa9435a9fc9b97/packages/new-deploy/package.json#L31
the arguments are

  1. the local path to the config file
  2. the local path to the overrides for submitting transactions (if desired)

in my case, i opted to store the configs in a local file in the same package, here: https://github.com/nomad-xyz/monorepo/tree/main/packages/new-deploy/config/development

the layout of the config file should look like this: https://github.com/nomad-xyz/rust/blob/main/configuration/configs/development.json

steps to make your own deploy are:

  1. configure the chains you wan to deploy in the protocol section
  2. delete the core and bridge components so that they are empty objects {} (TODO: make an example pre-deploy configuration)
  3. plop that file into the local path, like above, and invoke the deploy script - just like in npm run deploy

Document general steps for running a Nomad agent

Document steps for running a Nomad agent in general. This would include some of the following:

  • Where/how to get/setup image for agent (cc @yourbuddyconner)
  • Supplying configuration file or specifying run env
  • Supplying env vars for RPC endpoints, transaction signers, and optional attestation signer

Additional Relevant Deploy Info:

  • We release images via Github actions to our GCR Image Repository which get tagged with the git sha/branch they were built with
  • You can see the build process here if you'd like to build from source -- here is the Dockerfile.
  • We've got a helm repository here, with a nomad-agent helm chart.

feature/refactor: allow agents to optionally read with timelag

  • Some reads want timelag (updater produce_update), some don't (processor message_status)
  • Having all or nothing leads to unexpected behavior with agents reading old state
  • Want granular control over when timelag is used per contract call at call time
  • Want something like home.produce_update(TimeLag::On)

bug(merklesync-updater): tries to poll new_root before it has finished syncing all messages

TL;DR the bug in the updater that failed all dev homes is as follows:

  • Updater tries produce new_roots from a local merkle tree which is built from all the emitted messages for that home (same process as the processor)
  • The updater has until now never synced/indexed messages
  • The updater started syncing messages but before that has finished, it picks the current root of the local tree and uses that as its new_root
  • This update of last_committed-->new_root is invalid (the new_root is actually a really old root)
  • The improper update is submitted and the home is failed (for each updater)

Solution:

  • Have the syncing merkle tree keep track of the current committed_root corresponding to its current root
  • I.e. Each time the syncing tree stores a new leaf, it will get the Dispatch.committed_root field and update its current committed_root field
  • The updater will only use tree.root() if tree.current_committed() == old_root

Support new NomadConfig from nomad-xyz/configuration

High Level Agent Startup Flow

  1. Retrieve NomadConfig for the intended environment (dev, staging, prod)
  2. Use NomadConfig to build union of nomad_base::Settings and agent-specific settings
  3. Instantiate agent from settings (e.g. Updater::from_settings(settings).await? in agents/updater/main.rs) and run agent (implementation already there)

Implementation Details (modify decl_settings! macro)

  • Implement nomad_base::Settings::from_nomad_config(config: NomadConfig, home_name: &str) to map NomadConfig to agent-specific settings (used in next step)
  • fn new() -> Result<Self> must:
    • Fetch NomadConfig based on the RUN_ENV env variable by calling config::get_builtins(<environment name>)
    • Get separation of home vs. replicas based on the AGENT_HOME env variable
    • Return result of Settings::from_nomad_config(config, home_name)
  • Agent takes result of Settings::new()? and uses to run agent (rest of agent/main.rs)

Loading secrets (signers & RPC)?

  • Looks like new config crate is not meant to support secrets since all NomadConfig values will come directly from public crate imported as dependency (using something like config::get_builtins(...))
  • Possible solution:
    • Create new AgentSecrets struct (below) that can be deserialized from JSON (shown below)
    • In agent-specific Settings::new() function, expect/load a secrets.json file (below) that deserializes into AgentSecrets (inject secrets into json file as we already do)
    • Implement some kind of Settings::from_configuration(config: NomadConfig, secrets: AgentSecrets, home_name: &str) where all public values come from NomadConfig while all private values come from AgentSecrets
    • Implement checks if we are missing values in AgentSecrets when comparing to NomadConfig (e.g. we accidentally left out rpc for one network)
=== Rust - AgentSecrets ===
struct AgentSecrets {
   rpcs: HashMap<String, ChainConf>,
   transaction_signers: HashMap<String, SignerConf>,
   attestation_signer: SignerConf,
}

=== JSON - secrets.json ===
{
   "rpcs": {
       "ethereum": {
           "type": "http",
           "url": ""
       },
       "moonbeam": {
           "type": "http",
           "url": ""
       },
       "milkomedaC1": {
           "type": "http",
           "url": ""
       },
   },
   "transactionSigners": {
      "ethereum": {
          "key": "",
          "type": "hexKey"
      },
      "moonbeam": {
          "key": "",
          "type": "hexKey"
      },
      "milkomedaC1": {
          "key": "",
          "type": "hexKey"
      },
   },
   "attestationSigner": {
       "key": "",
       "type": "hexKey"
   }
}

feature: preflight reverts in fixed-gas actions

currently reverts in certain actions are not caught in pre-flight because we no longer estimate gas. We should run an eth_call to see if they would cause a revert and take appropriate action

example action:
update on a failed home

refactor: deprecate base `Settings` and move info to config crate

Should have something like BaseAgentSettings in configuration and then all the types with lots of functionality (e.g. CachingHome) implement From<BaseAgentSettings>. Overall, we should move from implementing <config struct>::into_<some struct with functionality> to implementing <struct with functionality>::from_<some config struct>

refactor: have ContractSync catch missed updates when syncing at tip

  • backtracking algorithm for catching updates only works if we assume there will be more updates to reveal a discontinuity in RPC
  • relayer and watcher (which sync at tip) are then vulnerable to missing updates completely for hours until next update shows up (if it ever does)
  • we want to index at the tip and also reindex ranges finality_blocks behind the tip to catch any missed updates

Allow env overriding agent config values

Want to allow agent-specific values to be overridden through environment variables.

  • implement EnvOverridable for each agent config in configuration/src/agent
  • agent_settings.load_env_overrides() in nomad-base/src/settings/macro.rs before adding to overarching agent settings

feature: Secrets Reconciliation Script

See comment here for details on executing the secrets_template script.

We need to write an automation tool that wraps the secrets_template script, and diffs the output of it with a secret that exists in Google Secrets Manager and outputs a patch to the existing secret.

This tool can then be used as a pre-deploy hook to error if the secrets are malformed or missing entries.

Document steps for running processor

  • Describe the functionality of the processor, namely that it tracks messages on the home and proves/processes them on any configured replicas
  • Describe how configuration maps to processor behavior (proves/processes messages for channels home to X replicas
  • Describe the functionality of the allowlist, denylist, index_only, and s3 options and how they can be used for custom clients/use cases
  • Describe behavior during failure modes for extra clarity

fix: remove updater `blocktime x finality` latency between updates

Problem

  • Currently, updater must wait till its last update becomes final to move onto producing a new one (does so by re-reading its own update on a timelag)
  • This incurs a blocktime x finality latency for between each update
  • If you dispatch a message that reaches finality just after the last update was submitted, you have a potentially 2 x (blocktime x finality) latency

Solution

  • We know that the all updates produced in db will be valid chain, thus the new_root of the prev produced update will always be the old_root of the next produced update
  • UpdateProducer should immediately retrieve next root to build off of from produced updates db

Document steps for running watcher

  • Describe key provision process and watcher enrollment on xapp connection managers
  • Describe what watcher configuration with given homes and replicas means (watchers over channel from home to X replicas)
  • Suggest running watcher with multiple RPC endpoints for safety
  • Describe behavior during failure modes

feature: agent expect JSON config and secrets files by default

Need some way to override agent config values at agent run time.

Nomad Team:

  1. Run pre-agent script, which takes in a RUN_ENV environment variable. This script will output a template secrets.json and the a config.json from the Nomad configuration crate for that RUN_ENV (config will be development or production json files in crate).
  2. Override any necessary values in secrets.json or config.json.
  3. Run agent with RUN_ENV and AGENT_HOME. All agent expects is secrets.json and config.json in cwd.

External Party (no usage of Nomad configuration crate)

  1. Create custom config.json and secrets.json in cwd (might not include all our networks).
  2. Run agent.

feature: add logging/metrics to watcher

Just watcher:

  • Gauge: number of updates sent through UpdateHandler (number of updates checked)
  • Gauge: 0 or 1 binary for double update detected
  • Histogram: latency between Update event emitted and update sent through UpdateHandler (see ContractSync for example)

All agents that check home failure:

  • Gauge: 0 or 1 for improper update observed (failed home; can be for all agents)
  • Gauge: number of home failed checks (can be for all agents)

observability: add grafana graphs/alerts for failure checks and watcher

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.