network

package
v0.0.0-...-455d6f4 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: LGPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package network is a generated GoMock package.

Package network is a generated GoMock package.

Package network is a generated GoMock package.

Index

Constants

View Source
const DefaultRetryAttempts = 180

Variables

View Source
var ErrPermanent = errors.New("permanent")

ErrPermanent is a sentinel error to be wrapped with fmt.Errorf when a function passed to Retry or RetryReturn should not be retried. Example: return fmt.Errorf("container exited: %w", network.ErrPermanent)

Functions

func AdvanceEpoch

func AdvanceEpoch(ctx context.Context, client rpc.Client, epochIncrement int) error

AdvanceEpoch triggers the sealing of an epoch advancing it by the given number. The function blocks until the final epoch has been reached.

func ApplyNetworkRules

func ApplyNetworkRules(ctx context.Context, backend ContractBackend, rules genesis.NetworkRulesPatch) error

ApplyNetworkRules updates the network rules on the network.

func DelegateToValidator

func DelegateToValidator(
	ctx context.Context,
	client rpc.Client,
	validatorId int,
	stake uint64,
	delegator *ecdsa.PrivateKey,
) error

DelegateToValidator delegates the given stake (in S) from the delegator account to the validator identified by validatorId. The delegator account must already hold enough funds to cover stake + gas.

func FundAccount

func FundAccount(
	ctx context.Context,
	client rpc.Client,
	source *ecdsa.PrivateKey,
	dest common.Address,
	amount uint64,
) error

FundAccount transfers `amount` S from the source account to the destination address using a plain value-transfer transaction.

func GetActiveValidatorIDs

func GetActiveValidatorIDs(client rpc.Client) ([]int, error)

GetActiveValidatorIDs returns the ids of the validators taking part in consensus in the epoch currently being built. SFC validator sets are per-epoch: a validator registered mid-epoch is absent from this set until that epoch is sealed.

func GetCurrentEpoch

func GetCurrentEpoch(client rpc.Client) (hexutil.Uint64, error)

func GetDelegatorStake

func GetDelegatorStake(
	client rpc.Client,
	delegator common.Address,
	validatorId int,
) (uint64, error)

GetDelegatorStake returns the current on-chain stake (in S) held by the given delegator on the given validator.

func RegisterValidatorNode

func RegisterValidatorNode(ctx context.Context, backend ContractBackend, stake uint64) (int, error)

RegisterValidatorNode registers a validator in the SFC contract. If stake is 0, the default stake of 5,000,000 S is used.

func Retry

func Retry(
	ctx context.Context,
	numAttempts int,
	delay time.Duration,
	do func(context.Context) error,
) error

Retry executes the input function until it produces no error. It however executes only the configured number of times with the configured delay between attempts. If the execution is not successful since, the execution returns the last error. The context can be used to abort the retry loop early.

func RetryReturn

func RetryReturn[Out any](
	ctx context.Context,
	numAttempts int,
	delay time.Duration,
	do func(context.Context) (Out, error),
) (Out, error)

RetryReturn executes the input function until it produces no error. It however executes only the configured number of times with the configured delay between attempts. If the execution is not successful since, the execution returns the last error. When execution is successful, the execution result is returned from this method. The context can be used to abort the retry loop early. If the function returns a PermanentError, the retry loop stops immediately.

func UndelegateFromValidator

func UndelegateFromValidator(
	ctx context.Context,
	client rpc.Client,
	validatorId int,
	stake uint64,
	delegator *ecdsa.PrivateKey,
) error

UndelegateFromValidator undelegates the given stake (in S) from the validator, signing the transaction with the delegator's private key. When stake is 0, the current on-chain stake for the delegator on the given validator is queried and fully undelegated.

func UnregisterValidatorNode

func UnregisterValidatorNode(ctx context.Context, client rpc.Client, validatorId int, stake uint64) error

UnregisterValidatorNode undelegates a validator's self-stake from the SFC contract. If stake is 0, the currently staked amount is queried on-chain via GetSelfStake and used as the undelegate amount.

func WaitForEpochChange

func WaitForEpochChange(ctx context.Context, client rpc.Client) error

WaitForEpochChange waits until the current epoch changes. It polls the network until a new epoch is observed or a timeout of 60 seconds is reached.

Types

type AddressPort

type AddressPort string

AddressPort is a string addressing an IP and a port in the format <IP>:<port>.

type ContractBackend

type ContractBackend interface {
	bind.ContractBackend
	// WaitTransactionReceipt waits for the receipt of the given transaction hash to be available.
	// The function returns early if the context is cancelled, and otherwise times out
	// after a fixed period.
	WaitTransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

	// GetNetworkRules returns network rules for the selected block (for example: "latest").
	GetNetworkRules(block string) (opera.Rules, error)
}

ContractBackend is an interface for a client to interact with the network.

type Host

type Host interface {
	// Hostname returns the hostname of the host.
	Hostname() string

	// IsRunning tests whether this host is running or has been stopped.
	IsRunning() bool

	// CheckRunning returns an error if the host process is no longer running,
	// either because it exited on its own or because its state cannot be determined.
	CheckRunning(ctx context.Context) error

	// GetAddressForService returns the address of a service running on this
	// host, or nil if such a service is not offered.
	GetAddressForService(*ServiceDescription) (*AddressPort, error)

	// Stop shuts down the services running on the host gracefully, using
	// their regular shutdown procedure (not killed). After stopping the
	// service, no more interactions are expected to succeed.
	Stop(ctx context.Context) error

	// SaveLogTo transfers the logs of the host to the given file directory.
	SaveLogTo(ctx context.Context, directory string) error

	// StreamLog provides a reader that is continuously providing the host log.
	// The log is tailed via the reader and blocked until next log lines are ready.
	// Before tailing new log lines, the reader can provide certain amount of previous log lines.
	// For instance, the docker host uses a ring memory of 150 lines to buffer previous lines.
	// The reader should reach its end (EOF) only when the host/container is stopped or interrupted.
	// If this method is called many times, it should dispatch the log to all returned
	// readers, i.e. all of them see the same output.
	// It is up to the caller to close the stream.
	StreamLog(ctx context.Context) (io.ReadCloser, error)

	// Cleanup releases all underlying resources. After the cleanup no more
	// operations on this host are expected to succeed.
	Cleanup(ctx context.Context) error
}

Host is an execution environment for Nodes. A host could be an actual physical machine with its dedicated hardware, a virtual machine with shared resources, or a Docker container hosting services. Hosts may be implicitly created by a Networks's CreateNode function.

type MockContractBackend

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

MockContractBackend is a mock of ContractBackend interface.

func NewMockContractBackend

func NewMockContractBackend(ctrl *gomock.Controller) *MockContractBackend

NewMockContractBackend creates a new mock instance.

func (*MockContractBackend) CallContract

func (m *MockContractBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract mocks base method.

func (*MockContractBackend) CodeAt

func (m *MockContractBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt mocks base method.

func (*MockContractBackend) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockContractBackend) EstimateGas

func (m *MockContractBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (uint64, error)

EstimateGas mocks base method.

func (*MockContractBackend) FilterLogs

FilterLogs mocks base method.

func (*MockContractBackend) GetNetworkRules

func (m *MockContractBackend) GetNetworkRules(block string) (opera.Rules, error)

GetNetworkRules mocks base method.

func (*MockContractBackend) HeaderByNumber

func (m *MockContractBackend) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber mocks base method.

func (*MockContractBackend) PendingCodeAt

func (m *MockContractBackend) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt mocks base method.

func (*MockContractBackend) PendingNonceAt

func (m *MockContractBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt mocks base method.

func (*MockContractBackend) SendTransaction

func (m *MockContractBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction mocks base method.

func (*MockContractBackend) SubscribeFilterLogs

func (m *MockContractBackend) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs mocks base method.

func (*MockContractBackend) SuggestGasPrice

func (m *MockContractBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice mocks base method.

func (*MockContractBackend) SuggestGasTipCap

func (m *MockContractBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

SuggestGasTipCap mocks base method.

func (*MockContractBackend) WaitTransactionReceipt

func (m *MockContractBackend) WaitTransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

WaitTransactionReceipt mocks base method.

type MockContractBackendMockRecorder

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

MockContractBackendMockRecorder is the mock recorder for MockContractBackend.

func (*MockContractBackendMockRecorder) CallContract

func (mr *MockContractBackendMockRecorder) CallContract(ctx, call, blockNumber any) *gomock.Call

CallContract indicates an expected call of CallContract.

func (*MockContractBackendMockRecorder) CodeAt

func (mr *MockContractBackendMockRecorder) CodeAt(ctx, contract, blockNumber any) *gomock.Call

CodeAt indicates an expected call of CodeAt.

func (*MockContractBackendMockRecorder) EstimateGas

func (mr *MockContractBackendMockRecorder) EstimateGas(ctx, call any) *gomock.Call

EstimateGas indicates an expected call of EstimateGas.

func (*MockContractBackendMockRecorder) FilterLogs

func (mr *MockContractBackendMockRecorder) FilterLogs(ctx, q any) *gomock.Call

FilterLogs indicates an expected call of FilterLogs.

func (*MockContractBackendMockRecorder) GetNetworkRules

func (mr *MockContractBackendMockRecorder) GetNetworkRules(block any) *gomock.Call

GetNetworkRules indicates an expected call of GetNetworkRules.

func (*MockContractBackendMockRecorder) HeaderByNumber

func (mr *MockContractBackendMockRecorder) HeaderByNumber(ctx, number any) *gomock.Call

HeaderByNumber indicates an expected call of HeaderByNumber.

func (*MockContractBackendMockRecorder) PendingCodeAt

func (mr *MockContractBackendMockRecorder) PendingCodeAt(ctx, account any) *gomock.Call

PendingCodeAt indicates an expected call of PendingCodeAt.

func (*MockContractBackendMockRecorder) PendingNonceAt

func (mr *MockContractBackendMockRecorder) PendingNonceAt(ctx, account any) *gomock.Call

PendingNonceAt indicates an expected call of PendingNonceAt.

func (*MockContractBackendMockRecorder) SendTransaction

func (mr *MockContractBackendMockRecorder) SendTransaction(ctx, tx any) *gomock.Call

SendTransaction indicates an expected call of SendTransaction.

func (*MockContractBackendMockRecorder) SubscribeFilterLogs

func (mr *MockContractBackendMockRecorder) SubscribeFilterLogs(ctx, q, ch any) *gomock.Call

SubscribeFilterLogs indicates an expected call of SubscribeFilterLogs.

func (*MockContractBackendMockRecorder) SuggestGasPrice

func (mr *MockContractBackendMockRecorder) SuggestGasPrice(ctx any) *gomock.Call

SuggestGasPrice indicates an expected call of SuggestGasPrice.

func (*MockContractBackendMockRecorder) SuggestGasTipCap

func (mr *MockContractBackendMockRecorder) SuggestGasTipCap(ctx any) *gomock.Call

SuggestGasTipCap indicates an expected call of SuggestGasTipCap.

func (*MockContractBackendMockRecorder) WaitTransactionReceipt

func (mr *MockContractBackendMockRecorder) WaitTransactionReceipt(ctx, txHash any) *gomock.Call

WaitTransactionReceipt indicates an expected call of WaitTransactionReceipt.

type MockHost

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

MockHost is a mock of Host interface.

func NewMockHost

func NewMockHost(ctrl *gomock.Controller) *MockHost

NewMockHost creates a new mock instance.

func (*MockHost) CheckRunning

func (m *MockHost) CheckRunning(ctx context.Context) error

CheckRunning mocks base method.

func (*MockHost) Cleanup

func (m *MockHost) Cleanup(ctx context.Context) error

Cleanup mocks base method.

func (*MockHost) EXPECT

func (m *MockHost) EXPECT() *MockHostMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockHost) GetAddressForService

func (m *MockHost) GetAddressForService(arg0 *ServiceDescription) (*AddressPort, error)

GetAddressForService mocks base method.

func (*MockHost) Hostname

func (m *MockHost) Hostname() string

Hostname mocks base method.

func (*MockHost) IsRunning

func (m *MockHost) IsRunning() bool

IsRunning mocks base method.

func (*MockHost) SaveLogTo

func (m *MockHost) SaveLogTo(ctx context.Context, directory string) error

SaveLogTo mocks base method.

func (*MockHost) Stop

func (m *MockHost) Stop(ctx context.Context) error

Stop mocks base method.

func (*MockHost) StreamLog

func (m *MockHost) StreamLog(ctx context.Context) (io.ReadCloser, error)

StreamLog mocks base method.

type MockHostMockRecorder

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

MockHostMockRecorder is the mock recorder for MockHost.

func (*MockHostMockRecorder) CheckRunning

func (mr *MockHostMockRecorder) CheckRunning(ctx any) *gomock.Call

CheckRunning indicates an expected call of CheckRunning.

func (*MockHostMockRecorder) Cleanup

func (mr *MockHostMockRecorder) Cleanup(ctx any) *gomock.Call

Cleanup indicates an expected call of Cleanup.

func (*MockHostMockRecorder) GetAddressForService

func (mr *MockHostMockRecorder) GetAddressForService(arg0 any) *gomock.Call

GetAddressForService indicates an expected call of GetAddressForService.

func (*MockHostMockRecorder) Hostname

func (mr *MockHostMockRecorder) Hostname() *gomock.Call

Hostname indicates an expected call of Hostname.

func (*MockHostMockRecorder) IsRunning

func (mr *MockHostMockRecorder) IsRunning() *gomock.Call

IsRunning indicates an expected call of IsRunning.

func (*MockHostMockRecorder) SaveLogTo

func (mr *MockHostMockRecorder) SaveLogTo(ctx, directory any) *gomock.Call

SaveLogTo indicates an expected call of SaveLogTo.

func (*MockHostMockRecorder) Stop

func (mr *MockHostMockRecorder) Stop(ctx any) *gomock.Call

Stop indicates an expected call of Stop.

func (*MockHostMockRecorder) StreamLog

func (mr *MockHostMockRecorder) StreamLog(ctx any) *gomock.Call

StreamLog indicates an expected call of StreamLog.

type MockValidatorRegistrar

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

MockValidatorRegistrar is a mock of ValidatorRegistrar interface.

func NewMockValidatorRegistrar

func NewMockValidatorRegistrar(ctrl *gomock.Controller) *MockValidatorRegistrar

NewMockValidatorRegistrar creates a new mock instance.

func (*MockValidatorRegistrar) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockValidatorRegistrar) RegisterValidatorNode

func (m *MockValidatorRegistrar) RegisterValidatorNode(backend ContractBackend) (int, error)

RegisterValidatorNode mocks base method.

func (*MockValidatorRegistrar) UnregisterValidatorNode

func (m *MockValidatorRegistrar) UnregisterValidatorNode(client rpc.Client, validatorId int) error

UnregisterValidatorNode mocks base method.

type MockValidatorRegistrarMockRecorder

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

MockValidatorRegistrarMockRecorder is the mock recorder for MockValidatorRegistrar.

func (*MockValidatorRegistrarMockRecorder) RegisterValidatorNode

func (mr *MockValidatorRegistrarMockRecorder) RegisterValidatorNode(backend any) *gomock.Call

RegisterValidatorNode indicates an expected call of RegisterValidatorNode.

func (*MockValidatorRegistrarMockRecorder) UnregisterValidatorNode

func (mr *MockValidatorRegistrarMockRecorder) UnregisterValidatorNode(client, validatorId any) *gomock.Call

UnregisterValidatorNode indicates an expected call of UnregisterValidatorNode.

type Port

type Port uint16

Port provides an alias type for a TCP port.

func GetFreePort

func GetFreePort() (Port, error)

GetFreePort obtains a free TCP port on the local system. Note, that after this call the port is not reserved. Thus, consecutive calls may produce the same free port until it is actually bound to some application.

func GetFreePorts

func GetFreePorts(num int) (ports []Port, err error)

GetFreePorts obtains a list of free TCP ports on the local system. Note that after this call the ports are not reserved. Thus, consecutive calls may produce the same free ports until it is actually bound to some application.

type ServiceDescription

type ServiceDescription struct {
	Name     string
	Port     Port
	Protocol string
}

ServiceDescription is

type ServiceGroup

type ServiceGroup map[Port]*ServiceDescription

func (*ServiceGroup) RegisterService

func (s *ServiceGroup) RegisterService(service *ServiceDescription) error

RegisterService installs a supported service in the registry.

func (*ServiceGroup) Services

func (s *ServiceGroup) Services() []*ServiceDescription

Services returns all registered services from the registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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