executor

package
v1.0.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

KV Executor

This is a simple key-value store executor implementation for testing Evolve nodes.

Server Lifecycle

The HTTP server starts when the Evolve node starts and is automatically shut down when the node stops (including when receiving CTRL+C or other termination signals). The server is context-aware, meaning:

  1. It gracefully handles in-progress requests during shutdown
  2. It automatically shuts down when the node's context is cancelled
  3. There's a 5-second timeout for shutdown to complete
API Endpoints

The HTTP server provides the following endpoints:

  • POST /tx: Submit a transaction to the KV executor.

    • Request body should contain the transaction data.
    • For consistency with the KV executor's transaction format, it's recommended to use transactions in the format key=value.
    • Returns HTTP 202 (Accepted) if the transaction is accepted.
  • GET /kv?key=<key>: Get the value for a specific key.

    • Returns the value as plain text if the key exists.
    • Returns HTTP 404 if the key doesn't exist.
  • POST /kv: Set a key-value pair directly.

    • Request body should be a JSON object with key and value fields.
    • Example: {"key": "mykey", "value": "myvalue"}
  • GET /store: Get all key-value pairs in the store.

    • Returns a JSON object with all key-value pairs.

CLI Client

A simple CLI client is provided to interact with the KV executor HTTP server. To build the client:

cd test/executors/kv/cmd/txclient
go build -o txclient
Usage

Submit a transaction with key and value:

./txclient -key mykey -value myvalue

Submit a raw transaction:

./txclient -raw "mykey=myvalue"

List all key-value pairs in the store:

./txclient -list

Specify a different server address:

./txclient -addr http://localhost:40042 -key mykey -value myvalue

Transaction Format

The KV executor expects transactions in the format key=value. For example:

  • mykey=myvalue
  • foo=bar

When a transaction is executed, the key-value pair is added to the store.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPServer

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

HTTPServer wraps a KVExecutor and provides an HTTP interface for it

func NewHTTPServer

func NewHTTPServer(executor *KVExecutor, listenAddr string) *HTTPServer

NewHTTPServer creates a new HTTP server for the KVExecutor

func (*HTTPServer) Start

func (hs *HTTPServer) Start(ctx context.Context) error

Start begins listening for HTTP requests

func (*HTTPServer) Stop

func (hs *HTTPServer) Stop() error

Stop shuts down the HTTP server

type KVExecutor

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

KVExecutor is a simple key-value store backed by go-datastore that implements the Executor interface for testing purposes. It uses a buffered channel as a mempool for transactions. It also includes fields to track genesis initialization persisted in the datastore.

func NewKVExecutor

func NewKVExecutor(rootdir, dbpath string) (*KVExecutor, error)

NewKVExecutor creates a new instance of KVExecutor with initialized store and mempool channel.

func (*KVExecutor) ExecuteTxs

func (k *KVExecutor) ExecuteTxs(ctx context.Context, txs [][]byte, blockHeight uint64, timestamp time.Time, prevStateRoot []byte) ([]byte, error)

ExecuteTxs processes each transaction assumed to be in the format "key=value". It updates the database accordingly using a batch and removes the executed transactions from the mempool. Invalid transactions are filtered out and logged, but execution continues.

func (*KVExecutor) FilterTxs

func (k *KVExecutor) FilterTxs(ctx context.Context, txs [][]byte, maxBytes, maxGas uint64, hasForceIncludedTransaction bool) ([]execution.FilterStatus, error)

FilterTxs validates force-included transactions and applies size filtering. For KVExecutor, validates key=value format when force-included txs are present. KVExecutor doesn't track gas, so maxGas is ignored.

func (*KVExecutor) GetExecutionInfo

func (k *KVExecutor) GetExecutionInfo(ctx context.Context) (execution.ExecutionInfo, error)

GetExecutionInfo returns execution layer parameters. For KVExecutor, returns MaxGas=0 indicating no gas-based filtering.

func (*KVExecutor) GetStoreValue

func (k *KVExecutor) GetStoreValue(ctx context.Context, key string) (string, bool)

GetStoreValue is a helper for the HTTP interface to retrieve the value for a key from the database. It searches across all block heights to find the latest value for the given key.

func (*KVExecutor) GetTxs

func (k *KVExecutor) GetTxs(ctx context.Context) ([][]byte, error)

GetTxs retrieves available transactions from the mempool channel. It drains the channel in a non-blocking way.

func (*KVExecutor) InitChain

func (k *KVExecutor) InitChain(ctx context.Context, genesisTime time.Time, initialHeight uint64, chainID string) ([]byte, error)

InitChain initializes the chain state with genesis parameters. It checks the database to see if genesis was already performed. If not, it computes the state root from the current DB state and persists genesis info.

func (*KVExecutor) InjectTx

func (k *KVExecutor) InjectTx(tx []byte)

InjectTx adds a transaction to the mempool channel. Uses a non-blocking send to avoid blocking the caller if the channel is full.

func (*KVExecutor) Rollback

func (k *KVExecutor) Rollback(ctx context.Context, height uint64) error

Rollback reverts the state to the previous block height.

func (*KVExecutor) SetFinal

func (k *KVExecutor) SetFinal(ctx context.Context, blockHeight uint64) error

SetFinal marks a block as finalized at the specified height.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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