blocklog

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0, BSD-2-Clause Imports: 22 Imported by: 1

Documentation

Overview

in the blocklog core contract the VM keeps indices of blocks and requests in an optimized way for fast checking and timestamp access.

Index

Constants

View Source
const (
	// state variables
	StateVarBlockRegistry             = "b"
	StateVarControlAddresses          = "c"
	StateVarRequestLookupIndex        = "l"
	StateVarRequestReceipts           = "r"
	StateVarRequestEvents             = "e"
	StateVarSmartContractEventsLookup = "e"
)
View Source
const (
	// parameters
	ParamBlockIndex             = "n"
	ParamBlockInfo              = "i"
	ParamGoverningAddress       = "g"
	ParamContractHname          = "h"
	ParamFromBlock              = "f"
	ParamToBlock                = "t"
	ParamRequestID              = "u"
	ParamRequestIndex           = "r"
	ParamRequestProcessed       = "p"
	ParamRequestRecord          = "d"
	ParamEvent                  = "e"
	ParamStateControllerAddress = "s"
)

Variables

View Source
var (
	FuncControlAddresses           = coreutil.ViewFunc("controlAddresses")
	FuncGetBlockInfo               = coreutil.ViewFunc("getBlockInfo")
	FuncGetLatestBlockInfo         = coreutil.ViewFunc("getLatestBlockInfo")
	FuncGetRequestIDsForBlock      = coreutil.ViewFunc("getRequestIDsForBlock")
	FuncGetRequestReceipt          = coreutil.ViewFunc("getRequestReceipt")
	FuncGetRequestReceiptsForBlock = coreutil.ViewFunc("getRequestReceiptsForBlock")
	FuncIsRequestProcessed         = coreutil.ViewFunc("isRequestProcessed")
	FuncGetEventsForRequest        = coreutil.ViewFunc("getEventsForRequest")
	FuncGetEventsForBlock          = coreutil.ViewFunc("getEventsForBlock")
	FuncGetEventsForContract       = coreutil.ViewFunc("getEventsForContract")
)
View Source
var Contract = coreutil.NewContract(coreutil.CoreContractBlocklog, "Block log contract")
View Source
var Processor = Contract.Processor(initialize,
	FuncGetBlockInfo.WithHandler(viewGetBlockInfo),
	FuncGetLatestBlockInfo.WithHandler(viewGetLatestBlockInfo),
	FuncGetRequestReceipt.WithHandler(viewGetRequestReceipt),
	FuncGetRequestReceiptsForBlock.WithHandler(viewGetRequestReceiptsForBlock),
	FuncGetRequestIDsForBlock.WithHandler(viewGetRequestIDsForBlock),
	FuncIsRequestProcessed.WithHandler(viewIsRequestProcessed),
	FuncControlAddresses.WithHandler(viewControlAddresses),
	FuncGetEventsForRequest.WithHandler(viewGetEventsForRequest),
	FuncGetEventsForBlock.WithHandler(viewGetEventsForBlock),
	FuncGetEventsForContract.WithHandler(viewGetEventsForContract),
)

Functions

func GetBlockEventsInternal

func GetBlockEventsInternal(partition kv.KVStoreReader, blockIndex uint32) ([]string, error)

func GetRequestIDsForBlock

func GetRequestIDsForBlock(stateReader state.OptimisticStateReader, blockIndex uint32) ([]iscp.RequestID, error)

GetRequestIDsForLastBlock reads blocklog from chain state and returns request IDs settled in specific block Can only panic on DB error of internal error

func IsRequestProcessed

func IsRequestProcessed(stateReader kv.KVStoreReader, reqid *iscp.RequestID) (bool, error)

IsRequestProcessed check if reqid is stored in the chain state as processed

func SaveControlAddressesIfNecessary

func SaveControlAddressesIfNecessary(partition kv.KVStore, stateAddress, governingAddress ledgerstate.Address, blockIndex uint32)

SaveControlAddressesIfNecessary saves new information about state address in the blocklog partition If state address does not change, it does nothing

func SaveEvent

func SaveEvent(partition kv.KVStore, msg string, key EventLookupKey, contract iscp.Hname) error

func SaveNextBlockInfo

func SaveNextBlockInfo(partition kv.KVStore, blockInfo *BlockInfo) uint32

SaveNextBlockInfo appends block info and returns its index

func SaveRequestLogRecord

func SaveRequestLogRecord(partition kv.KVStore, rec *RequestReceipt, key RequestLookupKey) error

SaveRequestLogRecord appends request record to the record log and creates records for fast lookup

Types

type BlockInfo

type BlockInfo struct {
	BlockIndex            uint32 // not persistent. Set from key
	Timestamp             time.Time
	TotalRequests         uint16
	NumSuccessfulRequests uint16
	NumOffLedgerRequests  uint16
	PreviousStateHash     hashing.HashValue
}

func BlockInfoFromBytes

func BlockInfoFromBytes(blockIndex uint32, data []byte) (*BlockInfo, error)

func (*BlockInfo) Bytes

func (bi *BlockInfo) Bytes() []byte

func (*BlockInfo) Read

func (bi *BlockInfo) Read(r io.Reader) error

func (*BlockInfo) RequestTimestamp

func (bi *BlockInfo) RequestTimestamp(requestIndex uint16) time.Time

RequestTimestamp returns timestamp which corresponds to the request with the given index Timestamps of requests are incremented by 1 nanosecond in the block. The timestamp of the last one is equal to the timestamp pof the block

func (*BlockInfo) String

func (bi *BlockInfo) String() string

func (*BlockInfo) Write

func (bi *BlockInfo) Write(w io.Writer) error

type ControlAddresses

type ControlAddresses struct {
	StateAddress     ledgerstate.Address
	GoverningAddress ledgerstate.Address
	SinceBlockIndex  uint32
}

func ControlAddressesFromBytes

func ControlAddressesFromBytes(data []byte) (*ControlAddresses, error)

func ControlAddressesFromMarshalUtil

func ControlAddressesFromMarshalUtil(mu *marshalutil.MarshalUtil) (*ControlAddresses, error)

func (*ControlAddresses) Bytes

func (ca *ControlAddresses) Bytes() []byte

func (*ControlAddresses) String

func (ca *ControlAddresses) String() string

type EventLookupKey

type EventLookupKey [8]byte

EventLookupKey is a globally unique reference to the event: block index + index of the request within block + index of the event within the request

func EventLookupKeyFromBytes

func EventLookupKeyFromBytes(r io.Reader) (*EventLookupKey, error)

func NewEventLookupKey

func NewEventLookupKey(blockIndex uint32, requestIndex, eventIndex uint16) EventLookupKey

func (EventLookupKey) BlockIndex

func (k EventLookupKey) BlockIndex() uint32

func (EventLookupKey) Bytes

func (k EventLookupKey) Bytes() []byte

func (EventLookupKey) RequestEventIndex

func (k EventLookupKey) RequestEventIndex() uint16

func (EventLookupKey) RequestIndex

func (k EventLookupKey) RequestIndex() uint16

func (*EventLookupKey) Write

func (k *EventLookupKey) Write(w io.Writer) error

type RequestLookupKey

type RequestLookupKey [6]byte

RequestLookupReference globally unique reference to the request: block index and index of the request within block

func NewRequestLookupKey

func NewRequestLookupKey(blockIndex uint32, requestIndex uint16) RequestLookupKey

func (RequestLookupKey) BlockIndex

func (k RequestLookupKey) BlockIndex() uint32

func (RequestLookupKey) Bytes

func (k RequestLookupKey) Bytes() []byte

func (*RequestLookupKey) Read

func (k *RequestLookupKey) Read(r io.Reader) error

func (RequestLookupKey) RequestIndex

func (k RequestLookupKey) RequestIndex() uint16

func (*RequestLookupKey) Write

func (k *RequestLookupKey) Write(w io.Writer) error

type RequestLookupKeyList

type RequestLookupKeyList []RequestLookupKey

RequestLookupKeyList a list of RequestLookupReference of requests with colliding iscp.RequestLookupDigest

func RequestLookupKeyListFromBytes

func RequestLookupKeyListFromBytes(data []byte) (RequestLookupKeyList, error)

func (RequestLookupKeyList) Bytes

func (ll RequestLookupKeyList) Bytes() []byte

type RequestReceipt

type RequestReceipt struct {
	Request iscp.Request
	Error   string
	// not persistent
	BlockIndex   uint32
	RequestIndex uint16
}

RequestReceipt represents log record of processed request on the chain

func RequestReceiptFromBytes

func RequestReceiptFromBytes(data []byte) (*RequestReceipt, error)

func RequestReceiptFromMarshalutil

func RequestReceiptFromMarshalutil(mu *marshalutil.MarshalUtil) (*RequestReceipt, error)

func (*RequestReceipt) Bytes

func (r *RequestReceipt) Bytes() []byte

func (*RequestReceipt) Short

func (r *RequestReceipt) Short() string

func (*RequestReceipt) String

func (r *RequestReceipt) String() string

func (*RequestReceipt) WithBlockData

func (r *RequestReceipt) WithBlockData(blockIndex uint32, requestIndex uint16) *RequestReceipt

Jump to

Keyboard shortcuts

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