fx

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package fx is used to effect changes on the outside world, i.e. the shuttermint node and the main chain node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRetriable

func IsRetriable(err error) bool

IsRetriable checks if we should retry an action that resulted in the given error.

Types

type Accuse

type Accuse struct {
	HalfStep    uint64
	KeyperIndex uint64 // index of the accuser, not the executor
}

Accuse is an action accusing the executor of a given half step at the keyper slasher.

func (Accuse) IsExpired

func (a Accuse) IsExpired(world observe.World) bool

func (Accuse) SendTX

func (a Accuse) SendTX(caller *contract.Caller, auth *bind.TransactOpts) (*types.Transaction, error)

func (Accuse) String

func (a Accuse) String() string

type ActionID

type ActionID uint64

ActionID identifies an action.

type ActionWithID

type ActionWithID struct {
	Action IAction
	ID     ActionID
}

type Appeal

type Appeal struct {
	Authorization contract.Authorization
}

Appeal is an action countering an earlier invalid accusation.

func (Appeal) IsExpired

func (a Appeal) IsExpired(world observe.World) bool

func (Appeal) SendTX

func (a Appeal) SendTX(caller *contract.Caller, auth *bind.TransactOpts) (*types.Transaction, error)

func (Appeal) String

func (a Appeal) String() string

type EonKeyBroadcast

type EonKeyBroadcast struct {
	KeyperIndex     uint64
	StartBatchIndex uint64
	EonPublicKey    *shcrypto.EonPublicKey
}

EonKeyBroadcast is an action sending a vote for an eon public key to the key broadcast contract.

func (EonKeyBroadcast) IsExpired

func (a EonKeyBroadcast) IsExpired(world observe.World) bool

func (EonKeyBroadcast) SendTX

func (a EonKeyBroadcast) SendTX(caller *contract.Caller, auth *bind.TransactOpts) (*types.Transaction, error)

func (EonKeyBroadcast) String

func (a EonKeyBroadcast) String() string

type ExecuteCipherBatch

type ExecuteCipherBatch struct {
	BatchIndex          uint64
	CipherBatchHash     [32]byte
	Transactions        [][]byte
	KeyperIndex         uint64
	TransactionGasLimit uint64
}

ExecuteCipherBatch is an Action that instructs the executor contract to execute a cipher batch.

func (ExecuteCipherBatch) IsExpired

func (a ExecuteCipherBatch) IsExpired(world observe.World) bool

func (ExecuteCipherBatch) SendTX

func (ExecuteCipherBatch) String

func (a ExecuteCipherBatch) String() string

type ExecutePlainBatch

type ExecutePlainBatch struct {
	BatchIndex          uint64
	Transactions        [][]byte
	TransactionGasLimit uint64
}

ExecutePlainBatch is an Action that instructs the executor contract to execute a plain batch.

func (ExecutePlainBatch) IsExpired

func (a ExecutePlainBatch) IsExpired(world observe.World) bool

func (ExecutePlainBatch) SendTX

func (ExecutePlainBatch) String

func (a ExecutePlainBatch) String() string

type IAction

type IAction interface {
	// IsExpired checks if the action expired because some time limit is reached or because the
	// result of the action has been achieved (we or someone else may have performed the same
	// action). We could think about having a dedicated IsDone method.
	IsExpired(world observe.World) bool
}

IAction describes an action to run as determined by the Decider's Decide method.

type IRetriable

type IRetriable interface {
	error
	IsRetriable() bool
}

IRetriable is an error that knows if it makes sense to retry an action.

type MainChainTX

type MainChainTX interface {
	IAction
	SendTX(caller *contract.Caller, auth *bind.TransactOpts) (*types.Transaction, error)
}

MainChainTX is an action that sends a transaction to the main chain.

type MessageSender

type MessageSender interface {
	SendMessage(context.Context, *shmsg.Message) error
}

MessageSender defines the interface of sending messages to shuttermint.

type MockMessageSender

type MockMessageSender struct {
	Msgs chan *shmsg.Message
}

MockMessageSender sends all messages to a channel so that they can be checked for testing.

func NewMockMessageSender

func NewMockMessageSender() MockMessageSender

NewMockMessageSender creates a new MockMessageSender. We use a buffered channel with a rather large size in order to simplify writing our tests.

func (*MockMessageSender) SendMessage

func (ms *MockMessageSender) SendMessage(_ context.Context, msg *shmsg.Message) error

type NonRetriableError

type NonRetriableError struct {
	Err error
}

func (*NonRetriableError) Error

func (e *NonRetriableError) Error() string

func (*NonRetriableError) IsRetriable

func (*NonRetriableError) IsRetriable() bool

func (*NonRetriableError) Unwrap

func (e *NonRetriableError) Unwrap() error

type PendingActions

type PendingActions struct {
	ActionMap         map[ActionID]IAction
	MainChainTXHashes map[ActionID]common.Hash
	CurrentID         ActionID
	// contains filtered or unexported fields
}

PendingActions contains information about the actions, which are currently running or are scheduled to be run. This struct is stored on disk with gob. We enumerate the actions the decider gives us.

func NewPendingActions

func NewPendingActions(path string) *PendingActions

NewPendingActions creates a empty PendingActions struct.

func (*PendingActions) AddActions

func (pending *PendingActions) AddActions(id ActionID, actions []IAction) (ActionID, ActionID)

AddActions adds the given actions unless they have already been added. id is the ActionID of the first action. It returns a startID, endID tuple of actions to be scheduled.

func (*PendingActions) GetAction

func (pending *PendingActions) GetAction(id ActionID) IAction

GetAction returns the action with the given id.

func (*PendingActions) GetMainChainTXHash

func (pending *PendingActions) GetMainChainTXHash(id ActionID) common.Hash

GetMainChainTXHash returns the transaction hash for the given main chain action.

func (*PendingActions) Load

func (pending *PendingActions) Load() error

Load loads pending actions from disk.

func (*PendingActions) RemoveAction

func (pending *PendingActions) RemoveAction(id ActionID)

RemoveAction removes the action with the given id.

func (*PendingActions) SetMainChainTXHash

func (pending *PendingActions) SetMainChainTXHash(id ActionID, hash common.Hash)

SetMainChainTXHash sets the transaction hash for the given main chain action.

func (*PendingActions) ShortInfo

func (pending *PendingActions) ShortInfo() string

func (*PendingActions) SortedIDs

func (pending *PendingActions) SortedIDs() []ActionID

SortedIDs returns the sorted pending action ids.

type RPCMessageSender

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

RPCMessageSender signs messages and sends them via RPC to shuttermint.

func NewRPCMessageSender

func NewRPCMessageSender(cl client.Client, signingKey *ecdsa.PrivateKey) RPCMessageSender

NewRPCMessageSender creates a new RPCMessageSender.

func (*RPCMessageSender) SendMessage

func (ms *RPCMessageSender) SendMessage(ctx context.Context, msg *shmsg.Message) error

SendMessage signs the given shmsg.Message and sends the message to shuttermint.

type RemoteError

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

RemoteError is raised for shuttermint messages that return with a result code != 0, i.e. where the shuttermint app generated an error.

func (*RemoteError) Error

func (remoteError *RemoteError) Error() string

func (*RemoteError) IsRetriable

func (remoteError *RemoteError) IsRetriable() bool

type RunEnv

type RunEnv struct {
	PendingActions     *PendingActions
	PendingActionsPath string
	MessageSender      MessageSender
	ContractCaller     *contract.Caller
	// contains filtered or unexported fields
}

func NewRunEnv

func NewRunEnv(messageSender MessageSender, contractCaller *contract.Caller, currentWorld func() observe.World, path string) *RunEnv

func (*RunEnv) CurrentWorld

func (runenv *RunEnv) CurrentWorld() observe.World

func (*RunEnv) Load

func (runenv *RunEnv) Load(ctx context.Context) (bool, error)

Load loads the pending actions from disk and schedules the actions to be run.

func (*RunEnv) RunActions

func (runenv *RunEnv) RunActions(ctx context.Context, actionCounter uint64, actions []IAction) error

func (*RunEnv) ShortInfo

func (runenv *RunEnv) ShortInfo() string

func (*RunEnv) StartBackgroundTasks

func (runenv *RunEnv) StartBackgroundTasks(ctx context.Context, g *errgroup.Group)

type SendShuttermintMessage

type SendShuttermintMessage struct {
	Description string
	Msg         *shmsg.Message
}

SendShuttermintMessage is an Action that sends a message to shuttermint.

func (SendShuttermintMessage) IsExpired

func (a SendShuttermintMessage) IsExpired(world observe.World) bool

func (SendShuttermintMessage) String

func (a SendShuttermintMessage) String() string

type SkipCipherBatch

type SkipCipherBatch struct {
	BatchIndex uint64
}

SkipCipherBatch is an Action that instructs the executor contract to skip a cipher batch.

func (SkipCipherBatch) IsExpired

func (a SkipCipherBatch) IsExpired(world observe.World) bool

func (SkipCipherBatch) SendTX

func (a SkipCipherBatch) SendTX(caller *contract.Caller, auth *bind.TransactOpts) (*types.Transaction, error)

func (SkipCipherBatch) String

func (a SkipCipherBatch) String() string

Jump to

Keyboard shortcuts

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