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
- Variables
- func BlockInfoKey(index uint32) []byte
- func GetAnchorTransactionIDByBlockIndex(partition kv.KVStore, blockIndex uint32) iotago.TransactionID
- func GetBlockEventsInternal(partition kv.KVStoreReader, blockIndex uint32) ([]string, error)
- func GetRequestIDsForBlock(stateReader state.OptimisticStateReader, blockIndex uint32) ([]isc.RequestID, error)
- func GetUTXOInput(stateR kv.KVStoreReader, stateIndex uint32, outputIndex uint16) *iotago.UTXOInput
- func IsRequestProcessed(stateReader kv.KVStoreReader, reqid *isc.RequestID) (bool, error)
- func MustIsRequestProcessed(stateReader kv.KVStoreReader, reqid *isc.RequestID) bool
- func ReadTransactionSubEssenceHash(r io.Reader, h *TransactionEssenceHash) error
- func RequestReceiptKey(rkey RequestLookupKey) []byte
- func SaveControlAddressesIfNecessary(partition kv.KVStore, stateAddress, governingAddress iotago.Address, ...)
- func SaveEvent(partition kv.KVStore, msg string, key EventLookupKey, contract isc.Hname) error
- func SaveNextBlockInfo(partition kv.KVStore, blockInfo *BlockInfo) uint32
- func SaveRequestReceipt(partition kv.KVStore, rec *RequestReceipt, key RequestLookupKey) error
- func UpdateLatestBlockInfo(partition kv.KVStore, anchorTxID iotago.TransactionID, ...)
- type BlockInfo
- type ControlAddresses
- type EventLookupKey
- type GetRequestReceiptResult
- type RequestLookupKey
- type RequestLookupKeyList
- type RequestReceipt
- func (r *RequestReceipt) Bytes() []byte
- func (r *RequestReceipt) LookupKey() RequestLookupKey
- func (r *RequestReceipt) Short() string
- func (r *RequestReceipt) String() string
- func (r *RequestReceipt) ToISCReceipt(resolvedError *isc.VMError) *isc.Receipt
- func (r *RequestReceipt) WithBlockData(blockIndex uint32, requestIndex uint16) *RequestReceipt
- type TransactionEssenceHash
Constants ¶
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" )
const TransactionEssenceHashLength = 32
Variables ¶
var ( ViewControlAddresses = coreutil.ViewFunc("controlAddresses") ViewGetBlockInfo = coreutil.ViewFunc("getBlockInfo") ViewGetRequestIDsForBlock = coreutil.ViewFunc("getRequestIDsForBlock") ViewGetRequestReceipt = coreutil.ViewFunc("getRequestReceipt") ViewGetRequestReceiptsForBlock = coreutil.ViewFunc("getRequestReceiptsForBlock") ViewIsRequestProcessed = coreutil.ViewFunc("isRequestProcessed") ViewGetEventsForRequest = coreutil.ViewFunc("getEventsForRequest") ViewGetEventsForBlock = coreutil.ViewFunc("getEventsForBlock") ViewGetEventsForContract = coreutil.ViewFunc("getEventsForContract") )
var Contract = coreutil.NewContract(coreutil.CoreContractBlocklog, "Block log contract")
var Processor = Contract.Processor(initialize, ViewControlAddresses.WithHandler(viewControlAddresses), ViewGetBlockInfo.WithHandler(viewGetBlockInfo), ViewGetEventsForBlock.WithHandler(viewGetEventsForBlock), ViewGetEventsForContract.WithHandler(viewGetEventsForContract), ViewGetEventsForRequest.WithHandler(viewGetEventsForRequest), ViewGetRequestIDsForBlock.WithHandler(viewGetRequestIDsForBlock), ViewGetRequestReceipt.WithHandler(viewGetRequestReceipt), ViewGetRequestReceiptsForBlock.WithHandler(viewGetRequestReceiptsForBlock), ViewIsRequestProcessed.WithHandler(viewIsRequestProcessed), )
Functions ¶
func BlockInfoKey ¶ added in v0.3.0
BlockInfoKey a key to access block info record inside SC state
func GetAnchorTransactionIDByBlockIndex ¶ added in v0.3.0
func GetAnchorTransactionIDByBlockIndex(partition kv.KVStore, blockIndex uint32) iotago.TransactionID
func GetBlockEventsInternal ¶
func GetBlockEventsInternal(partition kv.KVStoreReader, blockIndex uint32) ([]string, error)
func GetRequestIDsForBlock ¶
func GetRequestIDsForBlock(stateReader state.OptimisticStateReader, blockIndex uint32) ([]isc.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 GetUTXOInput ¶ added in v0.3.0
func IsRequestProcessed ¶
IsRequestProcessed check if reqid is stored in the chain state as processed
func MustIsRequestProcessed ¶ added in v0.3.0
func MustIsRequestProcessed(stateReader kv.KVStoreReader, reqid *isc.RequestID) bool
func ReadTransactionSubEssenceHash ¶ added in v0.3.0
func ReadTransactionSubEssenceHash(r io.Reader, h *TransactionEssenceHash) error
func RequestReceiptKey ¶ added in v0.3.0
func RequestReceiptKey(rkey RequestLookupKey) []byte
func SaveControlAddressesIfNecessary ¶
func SaveControlAddressesIfNecessary(partition kv.KVStore, stateAddress, governingAddress iotago.Address, blockIndex uint32)
SaveControlAddressesIfNecessary saves new information about state address in the blocklog partition If state address does not change, it does nothing
func SaveNextBlockInfo ¶
SaveNextBlockInfo appends block info and returns its index
func SaveRequestReceipt ¶ added in v0.3.0
func SaveRequestReceipt(partition kv.KVStore, rec *RequestReceipt, key RequestLookupKey) error
SaveRequestReceipt appends request record to the record log and creates records for fast lookup
func UpdateLatestBlockInfo ¶ added in v0.3.0
func UpdateLatestBlockInfo(partition kv.KVStore, anchorTxID iotago.TransactionID, l1Commitment *state.L1Commitment)
UpdateLatestBlockInfo is called before producing the next block to save anchor tx id and commitment data of the previous one
Types ¶
type BlockInfo ¶
type BlockInfo struct { BlockIndex uint32 // not persistent. Set from key Timestamp time.Time TotalRequests uint16 NumSuccessfulRequests uint16 // which didn't panic NumOffLedgerRequests uint16 PreviousL1Commitment state.L1Commitment // always known L1Commitment *state.L1Commitment // nil when not known yet for the current state AnchorTransactionID iotago.TransactionID // of the input state TransactionSubEssenceHash TransactionEssenceHash // always known even without state commitment. Needed for fraud proofs TotalBaseTokensInL2Accounts uint64 TotalStorageDeposit uint64 GasBurned uint64 GasFeeCharged uint64 }
func BlockInfoFromBytes ¶
func (*BlockInfo) RequestTimestamp ¶
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
type ControlAddresses ¶
type ControlAddresses struct { StateAddress iotago.Address GoverningAddress iotago.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
type GetRequestReceiptResult ¶ added in v0.3.0
func GetRequestRecordDataByRequestID ¶ added in v0.3.0
func GetRequestRecordDataByRequestID(stateReader kv.KVStoreReader, reqID isc.RequestID) (*GetRequestReceiptResult, error)
GetRequestRecordDataByRequestID tries to obtain the receipt data for a given request returns nil if receipt was not found
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) RequestIndex ¶
func (k RequestLookupKey) RequestIndex() uint16
type RequestLookupKeyList ¶
type RequestLookupKeyList []RequestLookupKey
RequestLookupKeyList a list of RequestLookupReference of requests with colliding isc.RequestLookupDigest
func RequestLookupKeyListFromBytes ¶
func RequestLookupKeyListFromBytes(data []byte) (RequestLookupKeyList, error)
func (RequestLookupKeyList) Bytes ¶
func (ll RequestLookupKeyList) Bytes() []byte
type RequestReceipt ¶
type RequestReceipt struct { // TODO request may be big (blobs). Do we want to store it all? Request isc.Request `json:"request"` Error *isc.UnresolvedVMError `json:"error"` GasBudget uint64 `json:"gasBudget"` GasBurned uint64 `json:"gasBurned"` GasFeeCharged uint64 `json:"gasFeeCharged"` // not persistent BlockIndex uint32 `json:"blockIndex"` RequestIndex uint16 `json:"requestIndex"` GasBurnLog *gas.BurnLog `json:"-"` }
RequestReceipt represents log record of processed request on the chain
func RequestReceiptFromBytes ¶
func RequestReceiptFromBytes(data []byte) (*RequestReceipt, error)
func RequestReceiptFromMarshalUtil ¶ added in v0.3.0
func RequestReceiptFromMarshalUtil(mu *marshalutil.MarshalUtil) (*RequestReceipt, error)
func (*RequestReceipt) Bytes ¶
func (r *RequestReceipt) Bytes() []byte
func (*RequestReceipt) LookupKey ¶ added in v0.3.0
func (r *RequestReceipt) LookupKey() RequestLookupKey
func (*RequestReceipt) Short ¶
func (r *RequestReceipt) Short() string
func (*RequestReceipt) String ¶
func (r *RequestReceipt) String() string
func (*RequestReceipt) ToISCReceipt ¶ added in v0.3.0
func (r *RequestReceipt) ToISCReceipt(resolvedError *isc.VMError) *isc.Receipt
func (*RequestReceipt) WithBlockData ¶
func (r *RequestReceipt) WithBlockData(blockIndex uint32, requestIndex uint16) *RequestReceipt
type TransactionEssenceHash ¶ added in v0.3.0
type TransactionEssenceHash [TransactionEssenceHashLength]byte
TransactionEssenceHash is a blake2b 256 bit hash of the essence of the transaction Used to calculate sub-essence hash
func CalcTransactionEssenceHash ¶ added in v0.3.0
func CalcTransactionEssenceHash(essence *iotago.TransactionEssence) (ret TransactionEssenceHash)