executor

package
v0.0.158 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2023 License: MIT Imports: 34 Imported by: 0

README

Executor

The Executor is an agent responsible for executing messages on the Destination.sol contract. It verifies that the message has been accepted by verifying a merkle proof, as well as the message's optimistic period.

Components

The Executor operates with four main components:

Run

streamLogs is the data-getter for the Executor. It works by instantiating a gRPC connection to Scribe, and puts logs in a channel for the origin and destination contracts on each chain in the config. From here, it verifies the logs' order since the order of logs are very important for merkle tree construction.
Additionally, if the Executor unexpectedly stops in the middle of streaming logs, it will use the current database state to reconstruct the tree up to where the last log was, then continue to use gRPC.

receiveLogs is the data-processor for the Executor. It works by taking the logs streamed from streamLogs and parsing the logs into either a Message on the Origin.sol contract, or a Attestation on the Destination.sol contract. It then stores the data into the Executor's database and builds the tree accordingly.

setMinimumTime sets the minimum unix time for a message before it has passed the optimistic period and can be executed. It works by going through all messages in the database that haven't been set, and checks for attestations to set each message's time.

executeExecutable is the function that executes messages. It looks through all messages that have a time set from setMinimumTime and executes them if the minimum time is past the current time.

Execute

Execute works in 3 parts.

  1. Verify that the optimistic period for the message has passed. This is done by checking the timestamp that the attestation was accepted on the Destination, then checking the timestamp of the last block.
  2. Verify that the message is in the merkle tree.
  3. Call the Execute function on the Destination.sol contract.

Usage

Navigate to sanguine/agents/agents/executor/main and run the following command to start the Executor:

$ go run main.go

Then the Executor command line will be exposed. The Executor requires a gRPC connection to a Scribe instance to stream logs. This can be done with either a remote Scribe or an embedded Scribe.

From the CLI, you specify whether you want to use a remote or embedded scribe via the --scribe-type flag. If using remote, you need to use the --scribe-port, --scribe-grpc-port and --scribe-url flags. If using embedded, you need to use the --scribe-db and --scribe-path flags.

Remote Scribe

Run the following command to start the Executor with a remote Scribe:

# Start the Executor
$ run --config </Users/synapsecns/config.yaml> --db <sqlite> or <mysql>\
 --path <path/to/database> or <database url> --scribe-type remote\
 --scribe-port <port> --scribe-grpc-port <port> --scribe-url <url>
Embedded Scribe

When using an embedded Scribe, a Scribe config must be included in the Executor config.

Run the following command to start the Executor with an embedded Scribe:

# Start the Executor and an embedded Scribe
$ run --config </Users/synapsecns/config.yaml> --db <sqlite> or <mysql>\
 --path <path/to/database> or <database url> --scribe-type embedded\
 --scribe-db <sqlite> or <mysql> --scribe-path <path/to/database> or <database url>

Directory Structure

Executor
├── cmd: CLI commands
├── config: Configuration files
├── db: Database interface
│   └── sql: Database writer, reader, and migrations
├── main: CLI entrypoint
└── types: Executor types

Documentation

Overview

Package executor is the executor agent responsible for proving and executing cross-chain messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTreeFromDB added in v0.0.81

func NewTreeFromDB(ctx context.Context, chainID uint32, executorDB db.ExecutorDB) (*merkle.HistoricalTree, error)

NewTreeFromDB builds a merkle tree from the db.

Types

type Backend added in v0.0.63

type Backend interface {
	// HeaderByNumber returns the block header with the given block number.
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

Backend is the backend for the executor.

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor is the executor agent.

func NewExecutor

func NewExecutor(ctx context.Context, config config.Config, executorDB db.ExecutorDB, scribeClient client.ScribeClient, clients map[uint32]Backend, handler metrics.Handler) (*Executor, error)

NewExecutor creates a new executor agent.

func NewExecutorInjectedBackend added in v0.0.81

func NewExecutorInjectedBackend(ctx context.Context, config config.Config, executorDB db.ExecutorDB, scribeClient client.ScribeClient, clients map[uint32]Backend, urls map[uint32]string, handler metrics.Handler) (*Executor, error)

NewExecutorInjectedBackend creates a new Executor suitable for testing since it does not need a valid omnirpcURL.

func (Executor) Execute added in v0.0.69

func (e Executor) Execute(parentCtx context.Context, message types.Message) (_ bool, err error)

Execute calls execute on `Destination.sol` on the destination chain, after verifying the message. TODO: Use multi-call to batch execute.

func (Executor) ExecuteExecutable added in v0.0.86

func (e Executor) ExecuteExecutable(ctx context.Context) error

ExecuteExecutable executes executable messages in the database.

func (Executor) GetExecuted added in v0.0.109

func (e Executor) GetExecuted(chainID uint32) map[[32]byte]bool

GetExecuted gets the executed mapping.

func (Executor) GetLogChan added in v0.0.81

func (e Executor) GetLogChan(chainID uint32) chan *ethTypes.Log

GetLogChan gets a log channel.

func (Executor) GetMerkleTree added in v0.0.81

func (e Executor) GetMerkleTree(chainID uint32) *merkle.HistoricalTree

GetMerkleTree gets a merkle tree.

func (Executor) OverrideMerkleTree added in v0.0.81

func (e Executor) OverrideMerkleTree(chainID uint32, tree *merkle.HistoricalTree)

OverrideMerkleTree overrides the merkle tree for the chainID and domain.

func (Executor) Run added in v0.0.78

func (e Executor) Run(ctx context.Context) error

Run starts the executor agent. It calls `Start` and `Listen`.

func (Executor) SetMinimumTime added in v0.0.86

func (e Executor) SetMinimumTime(ctx context.Context) error

SetMinimumTime sets the minimum times.

func (Executor) StartAndListenOrigin added in v0.0.130

func (e Executor) StartAndListenOrigin(ctx context.Context, chainID uint32, address string) error

StartAndListenOrigin starts and listens to a chain.

func (Executor) Stop

func (e Executor) Stop(chainID uint32)

Stop stops the executor agent.

func (Executor) VerifyMessageMerkleProof added in v0.0.69

func (e Executor) VerifyMessageMerkleProof(message types.Message) (bool, error)

VerifyMessageMerkleProof verifies message merkle proof.

func (Executor) VerifyMessageOptimisticPeriod added in v0.0.69

func (e Executor) VerifyMessageOptimisticPeriod(ctx context.Context, message types.Message) (*uint32, error)

VerifyMessageOptimisticPeriod verifies message optimistic period.

func (Executor) VerifyStateMerkleProof added in v0.0.130

func (e Executor) VerifyStateMerkleProof(ctx context.Context, state types.State) (bool, error)

VerifyStateMerkleProof verifies state merkle proof.

Directories

Path Synopsis
Package api contains the API for the executor.
Package api contains the API for the executor.
Package cmd provides the command line interface for the executor.
Package cmd provides the command line interface for the executor.
Package config defines the config for the Executor.
Package config defines the config for the Executor.
db
Package db provides a database interface for the executor.
Package db provides a database interface for the executor.
datastore/sql
Package sql provides a datastore implementation for the executor.
Package sql provides a datastore implementation for the executor.
datastore/sql/base
Package base contains the base sql implementation
Package base contains the base sql implementation
datastore/sql/mysql
Package mysql implements the mysql package
Package mysql implements the mysql package
datastore/sql/sqlite
Package sqlite implements the sqlite package
Package sqlite implements the sqlite package
Package main provides the main entry point for the executor.
Package main provides the main entry point for the executor.
Package metadata provides metadata for Executor.
Package metadata provides metadata for Executor.
Package types contains the database types for the Executor.
Package types contains the database types for the Executor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL