renvm

package
v0.0.0-...-61e8f65 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SyncWithChainFn is an intrinsic function that is generated by block
	// proposers when updating the state for a contract.
	SyncWithChainFn = "syncWithChain"

	// ChangeFeesFn is an intrinsic function that is generated by block
	// proposers when updating the mint or burn fees for a host chain.
	ChangeFeesFn = "changeFees"

	// EpochFn is an intrinsic function that is generated by block proposers
	// upon detecting a new epoch.
	EpochFn = "epoch"

	// ReturnStateAndOutputsFn is an extrinsic function that is generated by a
	// shard once it has finished processing transactions in a block.
	ReturnStateAndOutputsFn = "returnStateAndOutputs"

	// ClaimFeesFn is an extrinsic function that is used by Darknode operators
	// to request unclaimed fees earned by their Darknode.
	ClaimFeesFn = "claimFees"
)

Variables

View Source
var (
	DefaultHome     = "/home/darknode/.darknode"
	DefaultHost     = "0.0.0.0"
	DefaultPort     = uint16(18514)
	DefaultSimulate = Simulate{
		SimulateOutOfMemory: SimulateOutOfMemory{
			Enable: false,
		},
	}
	DefaultProfile = false
)

Default options.

View Source
var (
	// RegExToDestinationFromSource captures chains from selectors that
	// explicitly define their destination and source chains. This regex must be
	// matched before attempting to match RegExToDestination or
	// RegExToFromSource.
	RegExToDestinationFromSource = regexp.MustCompile(`/to(.*)From(.*)`)
	// RegExToDestination captures the destination chain from selectors that
	// explicitly define their destination chain. This regex does not work, but
	// will not error, if the selector also explicitly defines a source chain.
	// To prevent this, always try and match RegExToDestinationFromSource first.
	RegExToDestination = regexp.MustCompile(`/to(.*)`)
	// RegExFromSource captures the source chain from selectors that explicitly
	// define their source chain. This regex does not work, but will not error,
	// if the selector also explicitly defines a destination chain. To prevent
	// this, always try and match RegExToDestinationFromSource first.
	RegExFromSource = regexp.MustCompile(`/from(.*)`)
)
View Source
var (
	// IntrinsicSelectors is a list of selector functions for intrinsic
	// transactions.
	IntrinsicSelectors []string = []string{
		ChangeFeesFn,
		SyncWithChainFn,
		EpochFn,
	}
)

Functions

func OptionsToFile

func OptionsToFile(options Options, path string) error

OptionsToFile writes the Options to the target file in json format.

Types

type ChainOptions

type ChainOptions struct {
	RPC              pack.String                 `json:"rpc"`
	Confirmations    pack.U64                    `json:"confirmations"`
	MaxConfirmations pack.U64                    `json:"maxConfirmations"`
	GasLimit         pack.U256                   `json:"gasLimit"`
	Registry         pack.String                 `json:"registry"`
	Fees             map[multichain.Chain]Fees   `json:"fees"`
	Extras           map[pack.String]pack.String `json:"extras"`

	// TokenAssets are the supported tokens that originate on this chain, e.g.
	// USDC, REN for Ethereum.
	TokenAssets []multichain.Asset `json:"tokenAssets"`
}

ChainOptions used to parameterise chain-specific behaviour for chains that are supported by the transaction engine bindings. It is expected that these options will be marshalled to/from JSON as part of configuring the overall system.

type Contract

type Contract struct {
	Address pack.String `json:"address"`
	State   pack.Typed  `json:"state"`
}

type Fees

type Fees struct {
	MintFee        pack.U64 `json:"mintFee"`
	BurnFee        pack.U64 `json:"burnFee"`
	BurnAndMintFee pack.U64 `json:"burnAndMintFee"`
}

type Options

type Options struct {

	// Home directory for the database and configuration files.
	Home string `json:"home"`

	// PrivKey that defines the identity of the node.
	PrivKey *id.PrivKey `json:"privKey"`

	// Peers that the node will use to bootstrap into the network (in addition
	// to peers that have been saved to the database).
	Peers []wire.Address `json:"peers"`

	// Host that will be used to listen for incoming connections.
	Host string `json:"host"`
	// Port that will be used to listen for incoming connections.
	Port uint16 `json:"port"`

	// Simulate enables/disables different simulation options. These options
	// should only be used during development and testing.
	Simulate Simulate `json:"simulate"`

	// Profile enables/disables the exposure of profiling information at
	// http://localhost:8080.
	Profile bool `json:"profile"`

	// Network environment. Must be one of "localnet", "testnet", or "mainnet".
	Network multichain.Network `json:"net"`

	// Chains along with their options.
	Chains map[multichain.Chain]ChainOptions `json:"chains"`

	// Selectors is a whitelist containing the supported selectors.
	Selectors []Selector `json:"selectors"`

	// Whitelist contains the pubkeys used in various withdraws
	Whitelist Whitelist `json:"whitelist"`
}

Options parameterise the behaviour of a node. During testing, options are usually defined in-memory, however these options can also be marshalled/unmarshalled to/from the disk. This allows the node to keep the exact same configuration between boots, and allows the operator to modify its behaviour at runtime (by modifying the configuration file, and then rebooting the node).

func NewOptions

func NewOptions(network multichain.Network) Options

NewOptions creates a new Options using the default values.

func NewOptionsFromFile

func NewOptionsFromFile(path string) (Options, error)

NewOptionsFromFile parses a file to Options.

func OptionTemplate

func OptionTemplate(url string) (Options, error)

OptionTemplate fetches and returns the Options template from remote server.

type Selector

type Selector string

A Selector identifies a specific function from a specific contract. The contract comes first, and the function comes second, separated by "/". For example, sending BTC to Ethereum is done by sending a cross-chain transactions to the "BTC/toEthereum" selector.

func (Selector) Asset

func (selector Selector) Asset() multichain.Asset

Asset moving from the source chain to the destination chain.

func (Selector) Contract

func (selector Selector) Contract() string

Contract returns the contract component of the selector.

func (Selector) Destination

func (selector Selector) Destination() multichain.Chain

Destination returns the chain to which assets are moving. For example, "BTC/toEthereum" selector has "Ethereum" as its destination chain, and "BTC/fromEthereum" selector has "Bitcoin" as its destination chain.

func (Selector) Fn

func (selector Selector) Fn() string

Fn returns the function component of the selector.

func (Selector) Generate

func (Selector) Generate(r *rand.Rand, size int) reflect.Value

Generate allows us to quickly generate random transaction selectors. This is mostly used for writing tests.

func (Selector) IsBurn

func (selector Selector) IsBurn() bool

IsBurn returns true if the asset is being burned from a host chain. This is true for burn-and-release and burn-and-mint transactions.

func (Selector) IsClaimFees

func (selector Selector) IsClaimFees() bool

IsClaimFees returns true if the selector is for a claim fees tx.

func (Selector) IsCrossChain

func (selector Selector) IsCrossChain() bool

IsCrossChain returns true if the selector is for a cross-chain tx.

func (Selector) IsIntrinsic

func (selector Selector) IsIntrinsic() bool

IsIntrinsic returns true if the selector is for an intrinsic tx.

func (Selector) IsLock

func (selector Selector) IsLock() bool

IsLock returns true if the asset is being locked into RenVM on its origin chain. This is true for lock-and-mint transactions.

func (Selector) IsMint

func (selector Selector) IsMint() bool

IsMint returns true if the asset is being minted to a host chain. This is true for lock-and-mint and burn-and-mint transactions.

func (Selector) IsRelease

func (selector Selector) IsRelease() bool

IsRelease returns true if the asset is being released from RenVM back to its origin chain. This is true for burn-and-release transactions.

func (Selector) IsReturnStateAndOutputs

func (selector Selector) IsReturnStateAndOutputs() bool

IsReturnStateAndOutputs returns true if the selector is for a return-state-and-outputs tx.

func (Selector) Marshal

func (selector Selector) Marshal(buf []byte, rem int) ([]byte, int, error)

Marshal the selector into binary.

func (Selector) MarshalJSON

func (selector Selector) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshaler interface.

func (Selector) SizeHint

func (selector Selector) SizeHint() int

SizeHint returns the number of bytes required to represent the selector in binary.

func (Selector) Source

func (selector Selector) Source() multichain.Chain

Source returns the chain from which assets are moving. For example, "BTC/toEthereum" selector has "Bitcoin" as its source chain, and "BTC/fromEthereum" selector has "Ethereum" as its source chain.

func (Selector) String

func (selector Selector) String() string

func (*Selector) Unmarshal

func (selector *Selector) Unmarshal(buf []byte, rem int) ([]byte, int, error)

Unmarshal the selector from binary.

func (*Selector) UnmarshalJSON

func (selector *Selector) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshaler interface.

type Simulate

type Simulate struct {
	SimulateOutOfMemory `json:"oom"`
}

Simulate defines options for enabling/configuring the simulation of test scenarios that are difficult to force externally.

type SimulateOutOfMemory

type SimulateOutOfMemory struct {
	Enable bool `json:"enable"`
	Min    int  `json:"min"`
	Max    int  `json:"max"`
}

SimulateOutOfMemory defines options for enabling/configuring the simulation of out-of-memory errors.

type State

type State []Contract

type SystemState

type SystemState struct {
	Epoch  SystemStateEpoch  `json:"epoch"`
	Nodes  []SystemStateNode `json:"nodes"`
	Shards SystemStateShards `json:"shards"`
}

SystemState defines the state of the "System" contract. It records information about RenVM itself, including shards, epochs, and so on.

type SystemStateEpoch

type SystemStateEpoch struct {
	Hash      pack.Bytes32 `json:"hash"`
	Number    pack.U64     `json:"number"`
	NumNodes  pack.U64     `json:"numNodes"`
	Timestamp pack.U64     `json:"timestamp"`
}

SystemStateEpoch defines the record of the current epoch. It includes the epoch hash and number.

type SystemStateNode

type SystemStateNode struct {
	ID        pack.Bytes32 `json:"id"`
	EnteredAt pack.U64     `json:"enteredAt"`
}

SystemStateNode defines the record of a single node. Currently, it includes the public key of the node.

type SystemStateShards

type SystemStateShards struct {
	// Primary shards are used by all new cross-chain transactions.
	Primary []SystemStateShardsShard `json:"primary"`
	// Secondary shards finish processing the remaining cross-chain transactions
	// that are left over from when these shards were primary shards. This
	// overlap protects against cross-chain transactions getting lost between
	// epochs.
	Secondary []SystemStateShardsShard `json:"secondary"`
	// Tertiary shards do nothing. They exist to allow time for malicious nodes
	// in the shards to be punished for malicious behaviour that may have
	// occurred when these shards where primary/secondary shards.
	Tertiary []SystemStateShardsShard `json:"tertiary"`
}

SystemStateShards defines the record of shards kept by the "System" contract. At the beginning of every epoch, new primary shards are selected, primary shards become secondary shards, secondary shards become tertiary shards, and tertiary shards are dropped.

type SystemStateShardsShard

type SystemStateShardsShard struct {
	Shard  pack.Bytes32 `json:"shard"`
	PubKey pack.Bytes   `json:"pubKey"`
}

SystemStateShardsShard defines the record of one shard. It includes the identify of the shard, and the ECDSA public key of the shard (encoded using the 33-byte compressed format).

type Whitelist

type Whitelist struct {
	Fund pack.Bytes `json:"fund"`
}

Jump to

Keyboard shortcuts

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