layer1

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 7 Imported by: 0

README

Layer1 package

The layer 1 package contains all the logic for interacting with all the layer1 blockchains that AliceNet supports.

The package is mainly composed of 3 services:

  • Monitor: responsible for monitoring and reacting to layer 1 events.
  • Executor: responsible for scheduling and executing tasks and actions (e.g snapshots, ethdkg, accusations) against the layer 1 blockchains.
  • Transaction: responsible for watching for layer 1 transactions done by the AliceNet node and retrieve its receipts.

Creating new Tasks

The main way to interact with the layer 1 blockchains is via Tasks. So, if you have a service that needs to send a transaction to the layer 1 blockchains or need to check data from time to time in a smart contract create a new task.

The new task should be a new file in its own folder inside the tasks folder (layer1/executor/tasks). Check the example task to get more information on how to create a new task. Once the task file is created, its type need to be registered into the GetTaskRegistry() function in the task scheduler file. Once all these requirements all fulfilled, use the task scheduler to schedule the task when needed.

Registering new layer 1 events

The main way to react to changes in the layer1 blockchains is via events. The layer1 smart contracts will emit events based on the actions performed by the users and the Alicenet node can listen to these events and react accordingly. For instance, the node will create deposits UTXO when someone deposits tokens in the layer1 smart contracts, it will commit the snapshot to the consensus database when someone commits a snapshot that was validated by the smart contracts, etc. For more examples, check the monitor/events/ folder.

If you have an event in which the alicenet node should be listening and reacting to, you will need to create a callback function. Some, examples of callback functions can be seen in the folder ./monitor/events. Before creating a new file, check if the callback function cannot be grouped with the files that currently exists.

Once the callback is created, it needs to be registered in jointly with the event ABI data into the EventMap. Although the parameters of the callback function are not fixed (anything can be passed as long we have access to the data at registration), the callback function will need to be wrapped on the type EventProcessor which has fixed inputs. Check the events/setup for examples on how to get the event ABI data for a layer1 smart contract and how to properly register a callback function.

Finally, with all requirements fulfilled, Alicenet will be watching for the specified event and it will be calling the callback function once the event is observed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllSmartContracts

type AllSmartContracts interface {
	EthereumContracts() EthereumContracts
}

type BasicContracts

type BasicContracts interface {
	GetAllAddresses() []common.Address
}

type Client

type Client interface {
	Close()
	IsAccessible() bool
	EndpointInSync(ctx context.Context) (bool, uint32, error)
	GetPeerCount(ctx context.Context) (uint64, error)
	GetChainID() *big.Int
	GetTxNotFoundMaxBlocks() uint64
	GetTxMaxStaleBlocks() uint64
	GetTransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error)
	GetTransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	GetHeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
	GetBlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	GetBlockBaseFeeAndSuggestedGasTip(ctx context.Context) (*big.Int, *big.Int, error)
	GetCallOpts(context.Context, accounts.Account) (*bind.CallOpts, error)
	GetCallOptsLatestBlock(ctx context.Context, account accounts.Account) *bind.CallOpts
	GetTransactionOpts(context.Context, accounts.Account) (*bind.TransactOpts, error)
	GetAccount(common.Address) (accounts.Account, error)
	GetBalance(common.Address) (*big.Int, error)
	GetCurrentHeight(context.Context) (uint64, error)
	GetFinalizedHeight(context.Context) (uint64, error)
	GetEndpoint() string
	GetDefaultAccount() accounts.Account
	GetKnownAccounts() []accounts.Account
	GetTimeoutContext() (context.Context, context.CancelFunc)
	GetEvents(ctx context.Context, firstBlock, lastBlock uint64, addresses []common.Address) ([]types.Log, error)
	GetFinalityDelay() uint64
	GetTxMaxGasFeeAllowed() *big.Int
	GetPendingNonce(ctx context.Context, account common.Address) (uint64, error)
	SignTransaction(tx types.TxData, signerAddress common.Address) (*types.Transaction, error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	ExtractTransactionSender(tx *types.Transaction) (common.Address, error)
	RetryTransaction(ctx context.Context, tx *types.Transaction, baseFee, gasTipCap *big.Int) (*types.Transaction, error)
}

Client contains state information about a connection to the Ethereum node.

type EthereumContracts

type EthereumContracts interface {
	BasicContracts
	Ethdkg() bindings.IETHDKG
	EthdkgAddress() common.Address
	ALCA() bindings.IALCA
	ALCAAddress() common.Address
	ALCB() bindings.IALCB
	ALCBAddress() common.Address
	PublicStaking() bindings.IPublicStaking
	PublicStakingAddress() common.Address
	ValidatorStaking() bindings.IValidatorStaking
	ValidatorStakingAddress() common.Address
	ContractFactory() bindings.IAliceNetFactory
	ContractFactoryAddress() common.Address
	SnapshotsAddress() common.Address
	Snapshots() bindings.ISnapshots
	ValidatorPool() bindings.IValidatorPool
	ValidatorPoolAddress() common.Address
	Governance() bindings.IGovernance
	GovernanceAddress() common.Address
	Dynamics() bindings.IDynamics
	DynamicsAddress() common.Address
}

Jump to

Keyboard shortcuts

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