zapavm

package
v0.0.0-...-78b1b1e Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: BSD-3-Clause Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodecVersion is the current default codec version
	CodecVersion = 0
)
View Source
const (
	Name = "zapavm"
)

Variables

View Source
var (
	Version = version.NewDefaultVersion(1, 2, 0)

	// Whether or not we're on fuji. Controls whether or not certain
	// debug features were enabled (e.g. faucet, mining empty blocks)
	TestNet = true

	// If a chain is here, it's disabled. If the disabled flag is present
	// in the chain config, the chain will also be disabled. A chain cannot
	// be removed from this list via config.
	DisabledChains = map[string]bool{
		"HydwMTPrYBWHrGVmWfG8k4Po2eTPEqe7y7Z4jZaUr2Me6rin7":  true,
		"2LedqoeDb3zZQSqPBczemzrofepr6SzSHXxHXANrfzeFKGGNVd": true,
	}
)
View Source
var (
	Codec codec.Manager
)

Codecs do serialization and deserialization

Functions

func DeleteDb

func DeleteDb(db database.Database) error

func SubnetEVMFormat

func SubnetEVMFormat(prefix string) log.Format

Types

type Block

type Block struct {
	PrntID        ids.ID                `serialize:"true" json:"parentID"` // parent's ID
	Hght          uint64                `serialize:"true" json:"height"`   // This block's height. The genesis block is at height 0.
	ZBlk          nativejson.RawMessage `serialize:"true" json:"zblock"`   // zcash block
	CreationTime  int64                 `serialize:"true" json:"creationTime"`
	ProducingNode string                `serialize:"true" json:"producingNode"`
	// contains filtered or unexported fields
}

Block is a block on the chain. Each block contains: 1) ParentID 2) Height 3) ZBlk -- the serialized zcash block

func (*Block) Accept

func (b *Block) Accept() error

Accept sets this block's status to Accepted and sets lastAccepted to this block's ID and saves this info to b.vm.DB

func (*Block) Bytes

func (b *Block) Bytes() []byte

Bytes returns the byte repr. of this block

func (*Block) Height

func (b *Block) Height() uint64

Height returns this block's height. The genesis block has height 0.

func (*Block) ID

func (b *Block) ID() ids.ID

ID returns the ID of this block

func (*Block) Initialize

func (b *Block) Initialize(bytes []byte, status choices.Status, vm *VM)

Initialize sets [b.bytes] to bytes, [b.id] to hash([b.bytes]), [b.status] to [status] and [b.vm] to [vm]

func (*Block) LogInfo

func (b *Block) LogInfo() []interface{}

func (*Block) Parent

func (b *Block) Parent() ids.ID

ParentID returns [b]'s parent's ID

func (*Block) Reject

func (b *Block) Reject() error

Reject sets this block's status to Rejected and saves the status in state Recall that b.vm.DB.Commit() must be called to persist to the DB

func (*Block) SetStatus

func (b *Block) SetStatus(status choices.Status)

SetStatus sets the status of this block

func (*Block) Status

func (b *Block) Status() choices.Status

Status returns the status of this block

func (*Block) Timestamp

func (b *Block) Timestamp() time.Time

Timestamp returns this block's time. The genesis block has time 0. For now, return the root timesamp (2022-01-01) for genesis plus one second for each additional block

func (*Block) Verify

func (b *Block) Verify() error

Verify returns nil iff this block is valid.

func (*Block) ZBlock

func (b *Block) ZBlock() nativejson.RawMessage

type BlockCountReply

type BlockCountReply struct {
	Blocks int
}

type BlockState

type BlockState interface {
	GetBlock(blkID ids.ID) (*Block, error)
	PutBlock(blk *Block) error
	GetLastAcceptedBlock() (*Block, error)

	GetLastAccepted() (ids.ID, error)
	SetLastAccepted(ids.ID) error
}

BlockState defines methods to manage state with Blocks and LastAcceptedIDs.

func NewBlockState

func NewBlockState(db database.Database, vm *VM) BlockState

NewBlockState returns BlockState with a new cache and given db

type ChainConfig

type ChainConfig struct {
	Enabled       bool   `json:"enabled"`
	MockZcash     bool   `json:"mockZcash"`
	AvaSim        bool   `json:"avasim"`
	ZcashHost     string `json:"zcashHost"`
	ZcashPort     int    `json:"zcashPort"`
	ZcashUser     string `json:"zcashUser"`
	ZcashPassword string `json:"zcashPassword"`
	ClearDatabase bool   `json:"clearDatabase"`
	LogLevel      string `json:"logLevel"`
}

func NewChainConfig

func NewChainConfig(conf []byte) ChainConfig

func (*ChainConfig) ZcashClient

func (c *ChainConfig) ZcashClient(nodeID string) (zclient.ZcashClient, error)

type DecodeArgs

type DecodeArgs struct {
	Bytes    string              `json:"bytes"`
	Encoding formatting.Encoding `json:"encoding"`
}

DecodeArgs are arguments for Decode

type DecodeReply

type DecodeReply struct {
	Data     string              `json:"data"`
	Encoding formatting.Encoding `json:"encoding"`
}

DecodeReply is the reply from Decode

type EmptyArgs

type EmptyArgs struct {
}

type EnabledReply

type EnabledReply struct {
	Enabled bool
}

type EncodeArgs

type EncodeArgs struct {
	Data     string              `json:"data"`
	Encoding formatting.Encoding `json:"encoding"`
	Length   int32               `json:"length"`
}

EncodeArgs are arguments for Encode

type EncodeReply

type EncodeReply struct {
	Bytes    string              `json:"bytes"`
	Encoding formatting.Encoding `json:"encoding"`
}

EncodeReply is the reply from Encode

type Factory

type Factory struct{}

Factory ...

func (*Factory) New

func (f *Factory) New(*snow.Context) (interface{}, error)

New ...

type GetBlockArgs

type GetBlockArgs struct {
	// ID of the block we're getting.
	// If left blank, gets the latest block
	ID *ids.ID `json:"id"`

	Height *int `json:"height"`
}

GetBlockArgs are the arguments to GetBlock

type GetBlockReply

type GetBlockReply struct {
	Timestamp     json.Uint64 `json:"timestamp"` // Timestamp of most recent block
	Data          string      `json:"data"`      // Data in the most recent block. Base 58 repr. of 5 bytes.
	ID            ids.ID      `json:"id"`        // String repr. of ID of the most recent block
	ParentID      ids.ID      `json:"parentID"`  // String repr. of ID of the most recent block's parent
	ProducingNode string      `json:"producingNode"`
}

GetBlockReply is the reply from GetBlock

type GetBlockRequest

type GetBlockRequest struct {
	Height int `json:"height"`
}

type GetMempoolReply

type GetMempoolReply struct {
	Mempool     [][]byte
	SubmittedTx []uint8
}

type NodeBlockCountReply

type NodeBlockCountReply struct {
	NodeBlockCounts map[string]int
}

type NodeBlockCountRequest

type NodeBlockCountRequest struct {
	FromHeight *int `json:"fromHeight,omitempty"` // inclusive
	ToHeight   *int `json:"toHeight,omitempty"`   // exclusive
}

type ProposeBlockArgs

type ProposeBlockArgs struct {
	// Data in the block. Must be base 58 encoding of 32 bytes.
	Data string `json:"data"`
}

ProposeBlockArgs are the arguments to function ProposeValue

type ProposeBlockReply

type ProposeBlockReply struct{ Success bool }

ProposeBlockReply is the reply from function ProposeBlock

type Service

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

Service is the API service for this VM

func (*Service) AssociateZcashHostPort

func (s *Service) AssociateZcashHostPort(_ *http.Request, args *ZcashHostInfo, reply *SuccessReply) error

associate with new zcash host and port

func (*Service) GetBlock

func (s *Service) GetBlock(_ *http.Request, args *GetBlockArgs, reply *GetBlockReply) error

GetBlock gets the block whose ID is [args.ID] If [args.ID] is empty, get the latest block

func (*Service) GetBlockCount

func (s *Service) GetBlockCount(_ *http.Request, args *EmptyArgs, reply *BlockCountReply) error

func (*Service) IsChainEnabled

func (s *Service) IsChainEnabled(_ *http.Request, args *EmptyArgs, reply *EnabledReply) error

func (*Service) MineBlock

func (s *Service) MineBlock(_ *http.Request, args *EmptyArgs, reply *SuccessReply) error

tells the vm to mine a new block. will usually (but not 100%) cause this node to mine

func (*Service) NodeBlockCounts

func (s *Service) NodeBlockCounts(_ *http.Request, args *NodeBlockCountRequest, reply *NodeBlockCountReply) error

func (*Service) SubmitTx

func (s *Service) SubmitTx(_ *http.Request, args *SubmitTxArgs, reply *GetMempoolReply) error

func (*Service) Zcashrpc

func (s *Service) Zcashrpc(_ *http.Request, args *zclient.ZCashRequest, reply *zclient.ZCashResponse) error

type State

type State interface {
	// SingletonState is defined in avalanchego,
	// it is used to understand if db is initialized already.
	avax.SingletonState
	BlockState
	pstate.HeightIndex

	Commit() error
	Close() error
	ClearState() error
}

State is a wrapper around avax.SingleTonState and BlockState State also exposes a few methods needed for managing database commits and close.

func NewState

func NewState(db database.Database, vm *VM) State

type StaticService

type StaticService struct{}

StaticService defines the base service for the timestamp vm

func CreateStaticService

func CreateStaticService() *StaticService

CreateStaticService ...

func (*StaticService) Decode

func (ss *StaticService) Decode(_ *http.Request, args *DecodeArgs, reply *DecodeReply) error

Decode returns the Decoded data

func (*StaticService) Encode

func (ss *StaticService) Encode(_ *http.Request, args *EncodeArgs, reply *EncodeReply) error

Encode returns the encoded data

type SubmitTxArgs

type SubmitTxArgs struct {
	From   string  `json:"from"`
	To     string  `json:"to"`
	Amount float32 `json:"amount"`
}

type SuccessReply

type SuccessReply struct {
	Success bool
}

type VM

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

VM implements the snowman.VM interface Each block in this chain contains a Unix timestamp and a piece of data (a string)

func (*VM) AppGossip

func (vm *VM) AppGossip(nodeID ids.ShortID, msg []byte) error

Receive transaction

func (*VM) AppRequest

func (vm *VM) AppRequest(nodeID ids.ShortID, requestID uint32, time time.Time, request []byte) error

This VM doesn't (currently) have any app-specific messages

func (*VM) AppRequestFailed

func (vm *VM) AppRequestFailed(nodeID ids.ShortID, requestID uint32) error

This VM doesn't (currently) have any app-specific messages

func (*VM) AppResponse

func (vm *VM) AppResponse(nodeID ids.ShortID, requestID uint32, response []byte) error

This VM doesn't (currently) have any app-specific messages

func (*VM) BlockGenerator

func (vm *VM) BlockGenerator(min *int, max *int) chan Block

min is inclusive, max is exclusive

func (*VM) BuildBlock

func (vm *VM) BuildBlock() (snowman.Block, error)

BuildBlock returns a block that this vm wants to add to consensus

func (*VM) Commit

func (vm *VM) Commit() error

func (*VM) Connected

func (vm *VM) Connected(id ids.ShortID, v version.Application) error

func (*VM) CreateHandlers

func (vm *VM) CreateHandlers() (map[string]*common.HTTPHandler, error)

CreateHandlers returns a map where: Keys: The path extension for this VM's API (empty in this case) Values: The handler for the API

func (*VM) CreateStaticHandlers

func (vm *VM) CreateStaticHandlers() (map[string]*common.HTTPHandler, error)

CreateStaticHandlers returns a map where: Keys: The path extension for this VM's static API Values: The handler for that static API

func (*VM) Disconnected

func (vm *VM) Disconnected(id ids.ShortID) error

func (*VM) GetBlock

func (vm *VM) GetBlock(blkID ids.ID) (snowman.Block, error)

GetBlock implements the snowman.ChainVM interface

func (*VM) GetBlockAtHeight

func (vm *VM) GetBlockAtHeight(height uint64) (*Block, error)

func (*VM) GetBlockIDAtHeight

func (vm *VM) GetBlockIDAtHeight(height uint64) (ids.ID, error)

GetBlockIDAtHeight returns the ID of the block that was accepted with [height].

func (*VM) HealthCheck

func (vm *VM) HealthCheck() (interface{}, error)

Health implements the common.VM interface

func (*VM) Initialize

func (vm *VM) Initialize(
	ctx *snow.Context,
	dbManager manager.Manager,
	genesisData []byte,
	upgradeData []byte,
	configData []byte,
	toEngine chan<- common.Message,
	_ []*common.Fx,
	as common.AppSender,
) error

Initialize this vm [ctx] is this vm's context [dbManager] is the manager of this vm's database [toEngine] is used to notify the consensus engine that new blocks are

ready to be added to consensus

The data in the genesis block is [genesisData]

func (*VM) LastAccepted

func (vm *VM) LastAccepted() (ids.ID, error)

LastAccepted returns the block most recently accepted

func (*VM) LastAcceptedBlock

func (vm *VM) LastAcceptedBlock() (*Block, error)

LastAccepted returns the block most recently accepted

func (*VM) NewBlock

func (vm *VM) NewBlock(parentID ids.ID, height uint64, zblock nativejson.RawMessage, timestamp int64) (*Block, error)

NewBlock returns a new Block where: - the block's parent is [parentID] - the block's data is [data] - the block's timestamp is [timestamp]

func (*VM) NotifyBlockReady

func (vm *VM) NotifyBlockReady()

NotifyBlockReady tells the consensus engine that a new block is ready to be created

func (*VM) ParseBlock

func (vm *VM) ParseBlock(bytes []byte) (snowman.Block, error)

ParseBlock parses bytes to a Block This function is used by the vm's state to unmarshal blocks saved in state and by the consensus layer when it receives the byte representation of a block from another node

func (*VM) SetPreference

func (vm *VM) SetPreference(id ids.ID) error

SetPreference sets the block with ID [ID] as the preferred block

func (*VM) SetState

func (vm *VM) SetState(state snow.State) error

SetState sets this VM state according to given snow.State

func (*VM) Shutdown

func (vm *VM) Shutdown() error

Shutdown this vm

func (*VM) VerifyHeightIndex

func (vm *VM) VerifyHeightIndex() error

VerifyHeightIndex should return:

  • nil if the height index is available.
  • ErrHeightIndexedVMNotImplemented if the height index is not supported.
  • ErrIndexIncomplete if the height index is not currently available.
  • Any other non-standard error that may have occurred when verifying the index.

func (*VM) Version

func (vm *VM) Version() (string, error)

Returns this VM's version

type ZcashHostInfo

type ZcashHostInfo struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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