simulator

package
v1.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 64 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpRecording added in v1.2.0

func DumpRecording(rd ioutil.SectionReader) error

func EmptySnapshots added in v1.1.0

func EmptySnapshots(partition string, _ *accumulated.NetworkInit, _ log.Logger) (ioutil2.SectionReader, error)

func LocalNetwork added in v1.1.0

func LocalNetwork(name string, bvnCount, nodeCount int, baseIP net.IP, basePort uint64) *accumulated.NetworkInit

LocalNetwork returns a SimpleNetwork with sequential IPs starting from the base IP with the given base port.

func MemoryDatabase

func MemoryDatabase(string, int, log.Logger) keyvalue.Beginner

func SimpleNetwork

func SimpleNetwork(name string, bvnCount, nodeCount int) *accumulated.NetworkInit

SimpleNetwork creates a basic network with the given name, number of BVNs, and number of nodes per BVN.

Types

type BlockHookFunc added in v1.1.0

type BlockHookFunc = func(execute.BlockParams, []*messaging.Envelope) (_ []*messaging.Envelope, keepHook bool)

type CommitConsensusError added in v1.1.1

type CommitConsensusError [][]byte

func (CommitConsensusError) Error added in v1.1.1

func (CommitConsensusError) Error() string

type CommitHookFunc added in v1.1.0

type CommitHookFunc = func(*protocol.PartitionInfo, execute.BlockState)

type ListenOptions added in v1.1.0

type ListenOptions struct {
	// ListenHTTPv2 enables API v2 over HTTP.
	ListenHTTPv2 bool

	// ListenHTTPv3 enables API v3 over HTTP.
	ListenHTTPv3 bool

	// ListenWSv3 enables API v3 over WebSockets.
	ListenWSv3 bool

	// ListenP2Pv3 enables API v3 over libp2p.
	ListenP2Pv3 bool

	// HookHTTP hooks into HTTP calls.
	HookHTTP func(http.Handler, http.ResponseWriter, *http.Request)

	// ServeError handles errors produced by http.Server.Serve. If Error is nil,
	// ListenAndServe will panic if http.Server.Serve returns an error.
	ServeError func(error)
}

ListenOptions are options for Simulator.ListenAndServe.

type Node

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

func (*Node) Begin

func (n *Node) Begin(writable bool) *database.Batch

func (*Node) SetObserver added in v1.1.0

func (n *Node) SetObserver(observer database.Observer)

func (*Node) Update

func (n *Node) Update(fn func(*database.Batch) error) error

func (*Node) View

func (n *Node) View(fn func(*database.Batch) error) error

type NodeBlockHookFunc added in v1.1.1

type NodeBlockHookFunc = func(int, execute.BlockParams, []*messaging.Envelope) (_ []*messaging.Envelope, keepHook bool)

type OpenDatabaseFunc

type OpenDatabaseFunc func(partition string, node int, logger log.Logger) keyvalue.Beginner

func BadgerDatabaseFromDirectory

func BadgerDatabaseFromDirectory(dir string, onErr func(error)) OpenDatabaseFunc

type Partition

type Partition struct {
	protocol.PartitionInfo
	// contains filtered or unexported fields
}

func (*Partition) Begin added in v1.1.0

func (p *Partition) Begin(writable bool) *database.Batch

Begin will panic if called to create a writable batch if the partition has more than one node.

func (*Partition) SetBlockHook added in v1.1.0

func (p *Partition) SetBlockHook(fn BlockHookFunc)

func (*Partition) SetCommitHook added in v1.1.0

func (p *Partition) SetCommitHook(fn CommitHookFunc)

func (*Partition) SetNodeBlockHook added in v1.1.1

func (p *Partition) SetNodeBlockHook(fn NodeBlockHookFunc)

func (*Partition) SetObserver added in v1.1.0

func (p *Partition) SetObserver(observer database.Observer)

func (*Partition) SetSubmitHook

func (p *Partition) SetSubmitHook(fn SubmitHookFunc)

func (*Partition) Submit

func (p *Partition) Submit(envelope *messaging.Envelope, pretend bool) ([]*protocol.TransactionStatus, error)

func (*Partition) Update

func (p *Partition) Update(fn func(*database.Batch) error) error

func (*Partition) View

func (p *Partition) View(fn func(*database.Batch) error) error

type RecordingFunc added in v1.2.0

type RecordingFunc func(partition string, node int) (io.WriteSeeker, error)

type ResponseSubmit added in v1.1.1

type ResponseSubmit struct {
	Code         uint32
	Data         []byte
	Log          string
	Info         string
	Codespace    string
	MempoolError string
}

ResponseSubmit is the response from a call to Submit.

type Router

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

func (*Router) RequestAPIv2

func (r *Router) RequestAPIv2(ctx context.Context, partition, method string, params, result interface{}) error

func (*Router) Route

func (r *Router) Route(envs ...*messaging.Envelope) (string, error)

func (*Router) RouteAccount

func (r *Router) RouteAccount(account *url.URL) (string, error)

func (*Router) SetRoute

func (r *Router) SetRoute(account *url.URL, partition string)

func (*Router) Submit

func (r *Router) Submit(ctx context.Context, partition string, envelope *messaging.Envelope, pretend, async bool) (*ResponseSubmit, error)

type Simulator

type Simulator struct {

	// Deterministic attempts to run the simulator in a fully deterministic,
	// repeatable way.
	Deterministic bool

	// DropDispatchedMessages drops all internally dispatched messages.
	DropDispatchedMessages bool

	// IgnoreDeliverResults ignores inconsistencies in the result of DeliverTx
	// (the results of transactions and signatures).
	IgnoreDeliverResults bool

	// IgnoreCommitResults ignores inconsistencies in the result of Commit (the
	// root hash of the BPT).
	IgnoreCommitResults bool

	// Recordings is a function that returns files to write node recordings to.
	// TODO Make this an option once #3314 is merged.
	Recordings RecordingFunc
	// contains filtered or unexported fields
}

func New

func New(logger log.Logger, database OpenDatabaseFunc, network *accumulated.NetworkInit, snapshot SnapshotFunc) (*Simulator, error)

func New2 added in v1.2.0

func New2(logger log.Logger, database OpenDatabaseFunc, network *accumulated.NetworkInit, snapshot SnapshotFunc, recordings RecordingFunc) (*Simulator, error)

New2 is a hack to avoid changing everything - this needs to be handled with options.

func (*Simulator) BlockIndex added in v1.1.0

func (s *Simulator) BlockIndex(partition string) uint64

func (*Simulator) BlockIndexFor added in v1.1.0

func (s *Simulator) BlockIndexFor(account *url.URL) uint64

func (*Simulator) ClientV2 added in v1.1.0

func (s *Simulator) ClientV2(part string) *client.Client

ClientV2 returns an API V2 client for the given partition.

func (*Simulator) Collect added in v1.1.1

func (s *Simulator) Collect(partition string, file io.WriteSeeker, opts *database.CollectOptions) error

func (*Simulator) Database

func (s *Simulator) Database(partition string) database.Beginner

func (*Simulator) DatabaseFor

func (s *Simulator) DatabaseFor(account *url.URL) database.Updater

func (*Simulator) EventBus added in v1.1.0

func (s *Simulator) EventBus(partition string) *events.Bus

func (*Simulator) ListenAndServe

func (s *Simulator) ListenAndServe(ctx context.Context, opts ListenOptions) (err error)

ListenAndServe serves the Accumulate API. The simulator must have been initialized with a network configuration that includes addresses. At least one of the Listen options of opts must be true.

func (*Simulator) NewDirectClientWithHook added in v1.1.0

func (s *Simulator) NewDirectClientWithHook(hook func(http.Handler) http.Handler) *client.Client

NewDirectClientWithHook creates a direct HTTP client and applies the given hook.

func (*Simulator) Partition added in v1.1.1

func (s *Simulator) Partition(partition string) *Partition

func (*Simulator) Partitions

func (s *Simulator) Partitions() []*protocol.PartitionInfo

func (*Simulator) Router

func (s *Simulator) Router() *Router

func (*Simulator) Services added in v1.1.0

func (s *Simulator) Services() *simService

Services returns the simulator's API v3 implementation.

func (*Simulator) SetBlockHook added in v1.1.0

func (s *Simulator) SetBlockHook(partition string, fn BlockHookFunc)

func (*Simulator) SetBlockHookFor added in v1.1.0

func (s *Simulator) SetBlockHookFor(account *url.URL, fn BlockHookFunc)

func (*Simulator) SetCommitHook added in v1.1.0

func (s *Simulator) SetCommitHook(partition string, fn CommitHookFunc)

func (*Simulator) SetCommitHookFor added in v1.1.0

func (s *Simulator) SetCommitHookFor(account *url.URL, fn CommitHookFunc)

func (*Simulator) SetNodeBlockHook added in v1.1.1

func (s *Simulator) SetNodeBlockHook(partition string, fn NodeBlockHookFunc)

func (*Simulator) SetNodeBlockHookFor added in v1.1.1

func (s *Simulator) SetNodeBlockHookFor(account *url.URL, fn NodeBlockHookFunc)

func (*Simulator) SetRoute

func (s *Simulator) SetRoute(account *url.URL, partition string)

func (*Simulator) SetSubmitHook

func (s *Simulator) SetSubmitHook(partition string, fn SubmitHookFunc)

func (*Simulator) SetSubmitHookFor added in v1.1.0

func (s *Simulator) SetSubmitHookFor(account *url.URL, fn SubmitHookFunc)

func (*Simulator) SignWithNode

func (s *Simulator) SignWithNode(partition string, i int) nodeSigner

func (*Simulator) Step

func (s *Simulator) Step() error

Step executes a single simulator step

func (*Simulator) Submit

func (s *Simulator) Submit(envelope *messaging.Envelope) ([]*protocol.TransactionStatus, error)

func (*Simulator) SubmitTo added in v1.1.0

func (s *Simulator) SubmitTo(partition string, envelope *messaging.Envelope) ([]*protocol.TransactionStatus, error)

func (*Simulator) ViewAll

func (s *Simulator) ViewAll(fn func(batch *database.Batch) error) error

type SnapshotFunc

type SnapshotFunc func(partition string, network *accumulated.NetworkInit, logger log.Logger) (ioutil2.SectionReader, error)

func Genesis

func Genesis(time time.Time) SnapshotFunc

func GenesisWith

func GenesisWith(time time.Time, values *core.GlobalValues) SnapshotFunc

func GenesisWithVersion added in v1.1.0

func GenesisWithVersion(time time.Time, version protocol.ExecutorVersion) SnapshotFunc

func SnapshotFromDirectory

func SnapshotFromDirectory(dir string) SnapshotFunc

func SnapshotMap added in v1.1.0

func SnapshotMap(snapshots map[string][]byte) SnapshotFunc

type SubmitHookFunc

type SubmitHookFunc = func([]messaging.Message) (drop, keepHook bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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