timestampvm

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: BSD-3-Clause Imports: 28 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DataLen        = 32
	Name           = "timestampvm"
	MaxMempoolSize = 4096
)
View Source
const (
	// CodecVersion is the current default codec version
	CodecVersion = 0
)
View Source
const (
	IsInitializedKey byte = iota
)

Variables

View Source
var (
	Codec codec.Manager
)

Codecs do serialization and deserialization

View Source
var (
	Version = &version.Semantic{
		Major: 1,
		Minor: 3,
		Patch: 3,
	}
)

Functions

func BytesToData added in v1.2.9

func BytesToData(input []byte) [DataLen]byte

BytesToData converts a byte slice to an array. If the byte slice input is larger than DataLen, it will be truncated.

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.
	Tmstmp int64         `serialize:"true" json:"timestamp"` // Time this block was proposed at
	Dt     [DataLen]byte `serialize:"true" json:"data"`      // Arbitrary data
	// contains filtered or unexported fields
}

Block is a block on the chain. Each block contains: 1) ParentID 2) Height 3) Timestamp 4) A piece of data (a string)

func (*Block) Accept added in v1.2.0

func (b *Block) Accept(_ context.Context) 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 added in v1.2.0

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

Bytes returns the byte repr. of this block

func (*Block) Data

func (b *Block) Data() [DataLen]byte

Data returns the data of this block

func (*Block) Height added in v1.2.0

func (b *Block) Height() uint64

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

func (*Block) ID added in v1.2.0

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

ID returns the ID of this block

func (*Block) Initialize added in v1.2.0

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) Parent added in v1.2.0

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

ParentID returns [b]'s parent's ID

func (*Block) Reject added in v1.2.0

func (b *Block) Reject(_ context.Context) 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 added in v1.2.0

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

SetStatus sets the status of this block

func (*Block) Status added in v1.2.0

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.

func (*Block) Verify

func (b *Block) Verify(_ context.Context) error

Verify returns nil iff this block is valid. To be valid, it must be that: b.parent.Timestamp < b.Timestamp <= [local time] + 1 hour

type BlockState added in v1.2.0

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

BlockState defines methods to manage state with Blocks and LastAcceptedIDs.

func NewBlockState added in v1.2.0

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

NewBlockState returns BlockState with a new cache and given db

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 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 (*Factory) New(logging.Logger) (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"`
}

GetBlockArgs are the arguments to GetBlock

type GetBlockReply

type GetBlockReply struct {
	Timestamp json.Uint64 `json:"timestamp"` // Timestamp of block
	Data      string      `json:"data"`      // Data (hex-encoded) in block
	Height    json.Uint64 `json:"height"`    // Height of block
	ID        ids.ID      `json:"id"`        // String repr. of ID of block
	ParentID  ids.ID      `json:"parentID"`  // String repr. of ID of block's parent
}

GetBlockReply is the reply from GetBlock

type ProposeBlockArgs

type ProposeBlockArgs struct {
	// Data in the block. Must be hex 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) 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) ProposeBlock

func (s *Service) ProposeBlock(_ *http.Request, args *ProposeBlockArgs, reply *ProposeBlockReply) error

ProposeBlock is an API method to propose a new block whose data is [args].Data. [args].Data must be a string repr. of a 32 byte array

type SingletonState added in v1.3.2

type SingletonState interface {
	IsInitialized() (bool, error)
	SetInitialized() error
}

SingletonState is a thin wrapper around a database to provide, caching, serialization, and deserialization of singletons.

func NewSingletonState added in v1.3.2

func NewSingletonState(db database.Database) SingletonState

type State added in v1.2.0

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

	Commit() error
	Close() 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 added in v1.2.0

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 (*StaticService) Decode(_ *http.Request, args *DecodeArgs, reply *DecodeReply) error

Decode returns the Decoded data

func (*StaticService) Encode

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

Encode returns the encoded data

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 added in v1.1.0

func (*VM) AppGossip(_ context.Context, _ ids.NodeID, _ []byte) error

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

func (*VM) AppRequest added in v1.1.0

func (*VM) AppRequest(_ context.Context, _ ids.NodeID, _ uint32, _ time.Time, _ []byte) error

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

func (*VM) AppRequestFailed added in v1.1.0

func (*VM) AppRequestFailed(_ context.Context, _ ids.NodeID, _ uint32) error

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

func (*VM) AppResponse added in v1.1.0

func (*VM) AppResponse(_ context.Context, _ ids.NodeID, _ uint32, _ []byte) error

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

func (*VM) BuildBlock

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

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

func (*VM) Connected

func (*VM) Connected(_ context.Context, _ ids.NodeID, _ *version.Application) error

func (*VM) CreateHandlers

func (vm *VM) CreateHandlers(_ context.Context) (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) CreateStaticHandlers(_ context.Context) (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) CrossChainAppRequest added in v1.2.8

func (*VM) CrossChainAppRequest(_ context.Context, _ ids.ID, _ uint32, _ time.Time, _ []byte) error

func (*VM) CrossChainAppRequestFailed added in v1.2.8

func (*VM) CrossChainAppRequestFailed(_ context.Context, _ ids.ID, _ uint32) error

func (*VM) CrossChainAppResponse added in v1.2.8

func (*VM) CrossChainAppResponse(_ context.Context, _ ids.ID, _ uint32, _ []byte) error

func (*VM) Disconnected

func (*VM) Disconnected(_ context.Context, _ ids.NodeID) error

func (*VM) GetBlock added in v1.2.0

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

GetBlock implements the snowman.ChainVM interface

func (*VM) HealthCheck

func (*VM) HealthCheck(_ context.Context) (interface{}, error)

Health implements the common.VM interface

func (*VM) Initialize

func (vm *VM) Initialize(
	ctx context.Context,
	snowCtx *snow.Context,
	dbManager manager.Manager,
	genesisData []byte,
	_ []byte,
	_ []byte,
	toEngine chan<- common.Message,
	_ []*common.Fx,
	_ 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 added in v1.2.0

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

LastAccepted returns the block most recently accepted

func (*VM) NewBlock

func (vm *VM) NewBlock(parentID ids.ID, height uint64, data [DataLen]byte, timestamp time.Time) (*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 added in v1.2.0

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(_ context.Context, bytes []byte) (snowman.Block, error)

ParseBlock parses bytes to a snowman.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 added in v1.2.0

func (vm *VM) SetPreference(_ context.Context, id ids.ID) error

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

func (*VM) SetState added in v1.2.2

func (vm *VM) SetState(_ context.Context, state snow.State) error

SetState sets this VM state according to given snow.State

func (*VM) Shutdown added in v1.2.0

func (vm *VM) Shutdown(_ context.Context) error

Shutdown this vm

func (*VM) Version

func (*VM) Version(_ context.Context) (string, error)

Returns this VM's version

Jump to

Keyboard shortcuts

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