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 EventsFromViewResult(viewResult dict.Dict) (ret []*isc.Event, err error)
- func GetEventsByBlockIndex(partition kv.KVStoreReader, blockIndex uint32, totalRequests uint16) [][]byte
- func GetOutputID(stateR kv.KVStoreReader, stateIndex uint32, outputIndex uint16) (iotago.OutputID, bool)
- func GetRequestIDsForBlock(stateReader kv.KVStoreReader, blockIndex uint32) ([]isc.RequestID, error)
- func GetUnprocessable(state kv.KVStoreReader, reqID isc.RequestID) (req isc.Request, outputID iotago.OutputID, err error)
- func HasUnprocessable(state kv.KVStoreReader, reqID isc.RequestID) bool
- func HasUnprocessableRequestBeenRemovedInBlock(block state.Block, requestID isc.RequestID) bool
- func IsRequestProcessed(stateReader kv.KVStoreReader, requestID isc.RequestID) (bool, error)
- func MustIsRequestProcessed(stateReader kv.KVStoreReader, reqid isc.RequestID) bool
- func Prune(partition kv.KVStore, latestBlockIndex uint32, blockKeepAmount int32)
- func RemoveUnprocessable(state kv.KVStore, reqID isc.RequestID)
- func RequestReceiptKey(rkey RequestLookupKey) []byte
- func SaveEvent(partition kv.KVStore, eventKey []byte, event *isc.Event)
- func SaveNextBlockInfo(partition kv.KVStore, blockInfo *BlockInfo)
- func SaveRequestReceipt(partition kv.KVStore, rec *RequestReceipt, key RequestLookupKey) error
- func SaveUnprocessable(state kv.KVStore, req isc.OnLedgerRequest, blockIndex uint32, ...)
- func SetInitialState(s kv.KVStore)
- func UnprocessableRequestsAddedInBlock(block state.Block) ([]isc.Request, error)
- func UpdateLatestBlockInfo(partition kv.KVStore, anchorTxID iotago.TransactionID, ...)
- type BlockInfo
- func (bi *BlockInfo) BlockIndex() uint32
- func (bi *BlockInfo) Bytes() []byte
- func (bi *BlockInfo) PreviousL1Commitment() *state.L1Commitment
- func (bi *BlockInfo) Read(r io.Reader) error
- func (bi *BlockInfo) RequestTimestamp(requestIndex uint16) time.Time
- func (bi *BlockInfo) String() string
- func (bi *BlockInfo) Write(w io.Writer) error
- type EventLookupKey
- type GetRequestReceiptResult
- type RequestLookupKey
- type RequestLookupKeyList
- type RequestReceipt
- func GetRequestReceipt(stateReader kv.KVStoreReader, requestID isc.RequestID) (*RequestReceipt, error)
- func ReceiptsFromViewCallResult(res dict.Dict) ([]*RequestReceipt, error)
- func RequestReceiptFromBytes(data []byte, blockIndex uint32, reqIndex uint16) (*RequestReceipt, error)
- func RequestReceiptsFromBlock(block state.Block) ([]*RequestReceipt, error)
- func (rec *RequestReceipt) Bytes() []byte
- func (rec *RequestReceipt) LookupKey() RequestLookupKey
- func (rec *RequestReceipt) Read(r io.Reader) error
- func (rec *RequestReceipt) Short() string
- func (rec *RequestReceipt) String() string
- func (rec *RequestReceipt) ToISCReceipt(resolvedError *isc.VMError) *isc.Receipt
- func (rec *RequestReceipt) Write(w io.Writer) error
- type StateAccess
Constants ¶
const ( ParamBlockIndex = "n" ParamBlockInfo = "i" ParamContractHname = "h" ParamFromBlock = "f" ParamToBlock = "t" ParamRequestID = "u" ParamRequestIndex = "r" ParamRequestProcessed = "p" ParamRequestRecord = "d" ParamEvent = "e" ParamStateControllerAddress = "s" ParamUnprocessableRequestExists = "x" )
request parameters
const (
BlockInfoLatestSchemaVersion = 0
)
const EventLookupKeyLength = 8
const ( // Array of blockIndex => BlockInfo (pruned) // Covered in: TestGetEvents PrefixBlockRegistry = "a" )
Variables ¶
var ( // Funcs FuncRetryUnprocessable = coreutil.Func("retryUnprocessable") // Views 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") ViewHasUnprocessable = coreutil.ViewFunc("hasUnprocessable") )
var ( ErrUnprocessableAlreadyExist = coreerrors.Register("request does not exist on the unprocessable list").Create() ErrUnprocessableUnexpected = coreerrors.Register("unexpected error getting unprocessable request from the state").Create() ErrUnprocessableWrongSender = coreerrors.Register("unprocessable request sender does not match the retry sender").Create() )
var Contract = coreutil.NewContract(coreutil.CoreContractBlocklog)
var ErrBlockNotFound = coreerrors.Register("Block not found").Create()
var Processor = Contract.Processor(nil, ViewGetBlockInfo.WithHandler(viewGetBlockInfo), ViewGetEventsForBlock.WithHandler(viewGetEventsForBlock), ViewGetEventsForContract.WithHandler(viewGetEventsForContract), ViewGetEventsForRequest.WithHandler(viewGetEventsForRequest), ViewGetRequestIDsForBlock.WithHandler(viewGetRequestIDsForBlock), ViewGetRequestReceipt.WithHandler(viewGetRequestReceipt), ViewGetRequestReceiptsForBlock.WithHandler(viewGetRequestReceiptsForBlock), ViewIsRequestProcessed.WithHandler(viewIsRequestProcessed), ViewHasUnprocessable.WithHandler(viewHasUnprocessable), FuncRetryUnprocessable.WithHandler(retryUnprocessable), )
Functions ¶
func BlockInfoKey ¶ added in v0.3.0
BlockInfoKey a key to access block info record inside SC state
func EventsFromViewResult ¶ added in v1.0.3
func GetEventsByBlockIndex ¶ added in v1.0.3
func GetEventsByBlockIndex(partition kv.KVStoreReader, blockIndex uint32, totalRequests uint16) [][]byte
func GetOutputID ¶ added in v1.0.3
func GetRequestIDsForBlock ¶
func GetRequestIDsForBlock(stateReader kv.KVStoreReader, blockIndex uint32) ([]isc.RequestID, error)
GetRequestIDsForBlock reads blocklog from chain state and returns request IDs settled in specific block Can only panic on DB error of internal error
func GetUnprocessable ¶ added in v1.0.3
func HasUnprocessable ¶ added in v1.0.3
func HasUnprocessable(state kv.KVStoreReader, reqID isc.RequestID) bool
func HasUnprocessableRequestBeenRemovedInBlock ¶ added in v1.0.3
func IsRequestProcessed ¶
IsRequestProcessed check if requestID 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 RemoveUnprocessable ¶ added in v1.0.3
func RequestReceiptKey ¶ added in v0.3.0
func RequestReceiptKey(rkey RequestLookupKey) []byte
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 SaveUnprocessable ¶ added in v1.0.3
func SaveUnprocessable(state kv.KVStore, req isc.OnLedgerRequest, blockIndex uint32, outputIndex uint16)
save request reference / address of the sender
func SetInitialState ¶ added in v1.0.3
func UnprocessableRequestsAddedInBlock ¶ added in v1.0.3
func UpdateLatestBlockInfo ¶ added in v0.3.0
func UpdateLatestBlockInfo(partition kv.KVStore, anchorTxID iotago.TransactionID, aliasOutput *isc.AliasOutputWithID, 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 { SchemaVersion uint8 Timestamp time.Time TotalRequests uint16 NumSuccessfulRequests uint16 // which didn't panic NumOffLedgerRequests uint16 PreviousAliasOutput *isc.AliasOutputWithID // nil for block #0 GasBurned uint64 GasFeeCharged uint64 }
func BlockInfoFromBytes ¶
func GetBlockInfo ¶ added in v1.0.3
func GetBlockInfo(partition kv.KVStoreReader, blockIndex uint32) (*BlockInfo, bool)
func GetRequestsInBlock ¶ added in v1.0.3
func (*BlockInfo) BlockIndex ¶
func (*BlockInfo) PreviousL1Commitment ¶ added in v0.3.0
func (bi *BlockInfo) PreviousL1Commitment() *state.L1Commitment
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 EventLookupKey ¶
type EventLookupKey [EventLookupKeyLength]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 NewEventLookupKey ¶
func NewEventLookupKey(blockIndex uint32, requestIndex, eventIndex uint16) (ret 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) (ret RequestLookupKeyList, err error)
func (RequestLookupKeyList) Bytes ¶
func (ll RequestLookupKeyList) Bytes() []byte
type RequestReceipt ¶
type RequestReceipt struct { Request isc.Request `json:"request"` Error *isc.UnresolvedVMError `json:"error"` GasBudget uint64 `json:"gasBudget"` GasBurned uint64 `json:"gasBurned"` GasFeeCharged uint64 `json:"gasFeeCharged"` SDCharged uint64 `json:"storageDepositCharged"` // 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 GetRequestReceipt ¶ added in v1.0.3
func GetRequestReceipt(stateReader kv.KVStoreReader, requestID isc.RequestID) (*RequestReceipt, error)
GetRequestReceipt returns the receipt for the given request, or nil if not found
func ReceiptsFromViewCallResult ¶ added in v1.0.3
func ReceiptsFromViewCallResult(res dict.Dict) ([]*RequestReceipt, error)
func RequestReceiptFromBytes ¶
func RequestReceiptFromBytes(data []byte, blockIndex uint32, reqIndex uint16) (*RequestReceipt, error)
func RequestReceiptsFromBlock ¶ added in v1.0.3
func RequestReceiptsFromBlock(block state.Block) ([]*RequestReceipt, error)
func (*RequestReceipt) Bytes ¶
func (rec *RequestReceipt) Bytes() []byte
func (*RequestReceipt) LookupKey ¶ added in v0.3.0
func (rec *RequestReceipt) LookupKey() RequestLookupKey
func (*RequestReceipt) Short ¶
func (rec *RequestReceipt) Short() string
func (*RequestReceipt) String ¶
func (rec *RequestReceipt) String() string
func (*RequestReceipt) ToISCReceipt ¶ added in v0.3.0
func (rec *RequestReceipt) ToISCReceipt(resolvedError *isc.VMError) *isc.Receipt
type StateAccess ¶ added in v1.0.3
type StateAccess struct {
// contains filtered or unexported fields
}
func NewStateAccess ¶ added in v1.0.3
func NewStateAccess(store kv.KVStoreReader) *StateAccess