query

package
v0.0.0-...-7be3494 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestTimeout indicates how long before a request is considered to have timed out.
	RequestTimeout = 1 * time.Minute

	// RetryInterval specifies how long we will wait between retry intervals. This is the interval of our ticker.
	RetryInterval = 10 * time.Second

	// SignedQueryRequestChannelSize is the buffer size of the incoming query request channel.
	SignedQueryRequestChannelSize = 50

	// QueryRequestBufferSize is the buffer size of the per-network query request channel.
	QueryRequestBufferSize = 25
)
View Source
const EvmContractAddressLength = 20
View Source
const MSG_VERSION uint8 = 1

MSG_VERSION is the current version of the CCQ message protocol.

Variables

View Source
var (
	TotalWatcherTime = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "ccq_phylax_total_watcher_query_time_in_ms",
			Help:    "Time from time spent in the watcher per query in ms by chain",
			Buckets: []float64{1.0, 5.0, 10.0, 100.0, 250.0, 500.0, 1000.0, 5000.0, 10000.0, 30000.0},
		}, []string{"chain_name"})
)

Functions

func GetQueryResponseDigestFromBytes

func GetQueryResponseDigestFromBytes(b []byte) common.Hash

GetQueryResponseDigestFromBytes computes the digest bytes for a query response byte array.

func PostSignedQueryRequest

func PostSignedQueryRequest(signedQueryReqSendC chan<- *gossipv1.SignedQueryRequest, req *gossipv1.SignedQueryRequest) error

PostSignedQueryRequest posts a signed query request to the specified channel.

func QueryRequestDigest

func QueryRequestDigest(env common.Environment, b []byte) ethCommon.Hash

QueryRequestDigest returns the query signing prefix based on the environment.

func SignedQueryRequestEqual

func SignedQueryRequestEqual(left *gossipv1.SignedQueryRequest, right *gossipv1.SignedQueryRequest) bool

func SupportsTimestampCaching

func SupportsTimestampCaching(chainID vaa.ChainID) bool

func ValidatePerChainQueryRequestType

func ValidatePerChainQueryRequestType(qt ChainSpecificQueryType) error

Types

type ChainSpecificQuery

type ChainSpecificQuery interface {
	Type() ChainSpecificQueryType
	Marshal() ([]byte, error)
	Unmarshal(data []byte) error
	UnmarshalFromReader(reader *bytes.Reader) error
	Validate() error
}

ChainSpecificQuery is the interface that must be implemented by a chain specific query.

type ChainSpecificQueryType

type ChainSpecificQueryType uint8

ChainSpecificQueryType is used to interpret the data in a per chain query request.

const EthCallByTimestampQueryRequestType ChainSpecificQueryType = 2

EthCallByTimestampQueryRequestType is the type of an EVM eth_call_by_timestamp query request.

const EthCallQueryRequestType ChainSpecificQueryType = 1

EthCallQueryRequestType is the type of an EVM eth_call query request.

const EthCallWithFinalityQueryRequestType ChainSpecificQueryType = 3

EthCallWithFinalityQueryRequestType is the type of an EVM eth_call_with_finality query request.

type ChainSpecificResponse

type ChainSpecificResponse interface {
	Type() ChainSpecificQueryType
	Marshal() ([]byte, error)
	Unmarshal(data []byte) error
	UnmarshalFromReader(reader *bytes.Reader) error
	Validate() error
}

ChainSpecificResponse is the interface that must be implemented by a chain specific response.

type EthCallByTimestampQueryRequest

type EthCallByTimestampQueryRequest struct {
	// TargetTimeInUs specifies the desired timestamp in microseconds.
	TargetTimestamp uint64

	// TargetBlockIdHint is optional. If specified, it identifies the block prior to the desired timestamp. It must be a hex string starting with 0x. It may be a block number or a block hash.
	TargetBlockIdHint string

	// FollowingBlockIdHint is optional. If specified, it identifies the block immediately following the desired timestamp. It must be a hex string starting with 0x. It may be a block number or a block hash.
	FollowingBlockIdHint string

	// CallData is an array of specific queries to be performed on the specified block, in a single RPC call.
	CallData []*EthCallData
}

EthCallByTimestampQueryRequest implements ChainSpecificQuery for an EVM eth_call_by_timestamp query request.

func (*EthCallByTimestampQueryRequest) CallDataList

func (ecr *EthCallByTimestampQueryRequest) CallDataList() []*EthCallData

func (*EthCallByTimestampQueryRequest) Equal

Equal verifies that two EVM eth_call_by_timestamp queries are equal.

func (*EthCallByTimestampQueryRequest) Marshal

func (ecd *EthCallByTimestampQueryRequest) Marshal() ([]byte, error)

Marshal serializes the binary representation of an EVM eth_call_by_timestamp request. This method calls Validate() and relies on it to range checks lengths, etc.

func (*EthCallByTimestampQueryRequest) Type

func (*EthCallByTimestampQueryRequest) Unmarshal

func (ecd *EthCallByTimestampQueryRequest) Unmarshal(data []byte) error

Unmarshal deserializes an EVM eth_call_by_timestamp query from a byte array

func (*EthCallByTimestampQueryRequest) UnmarshalFromReader

func (ecd *EthCallByTimestampQueryRequest) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes an EVM eth_call_by_timestamp query from a byte array

func (*EthCallByTimestampQueryRequest) Validate

func (ecd *EthCallByTimestampQueryRequest) Validate() error

Validate does basic validation on an EVM eth_call_by_timestamp query.

type EthCallByTimestampQueryResponse

type EthCallByTimestampQueryResponse struct {
	TargetBlockNumber    uint64
	TargetBlockHash      common.Hash
	TargetBlockTime      time.Time
	FollowingBlockNumber uint64
	FollowingBlockHash   common.Hash
	FollowingBlockTime   time.Time

	// Results is the array of responses matching CallData in EthCallByTimestampQueryRequest
	Results [][]byte
}

EthCallByTimestampQueryResponse implements ChainSpecificResponse for an EVM eth_call_by_timestamp query response.

func (*EthCallByTimestampQueryResponse) Equal

Equal verifies that two EVM eth_call responses are equal.

func (*EthCallByTimestampQueryResponse) Marshal

func (ecr *EthCallByTimestampQueryResponse) Marshal() ([]byte, error)

Marshal serializes the binary representation of an EVM eth_call response. This method calls Validate() and relies on it to range checks lengths, etc.

func (*EthCallByTimestampQueryResponse) Type

func (*EthCallByTimestampQueryResponse) Unmarshal

func (ecr *EthCallByTimestampQueryResponse) Unmarshal(data []byte) error

Unmarshal deserializes an EVM eth_call response from a byte array

func (*EthCallByTimestampQueryResponse) UnmarshalFromReader

func (ecr *EthCallByTimestampQueryResponse) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes an EVM eth_call response from a byte array

func (*EthCallByTimestampQueryResponse) Validate

func (ecr *EthCallByTimestampQueryResponse) Validate() error

Validate does basic validation on an EVM eth_call response.

type EthCallData

type EthCallData struct {
	// To specifies the contract address to be queried.
	To []byte

	// Data is the ABI encoded parameters to the query.
	Data []byte
}

EthCallData specifies the parameters to a single EVM eth_call request.

type EthCallQueryRequest

type EthCallQueryRequest struct {
	// BlockId identifies the block to be queried. It must be a hex string starting with 0x. It may be a block number or a block hash.
	BlockId string

	// CallData is an array of specific queries to be performed on the specified block, in a single RPC call.
	CallData []*EthCallData
}

EthCallQueryRequest implements ChainSpecificQuery for an EVM eth_call query request.

func (*EthCallQueryRequest) CallDataList

func (ecr *EthCallQueryRequest) CallDataList() []*EthCallData

func (*EthCallQueryRequest) Equal

func (left *EthCallQueryRequest) Equal(right *EthCallQueryRequest) bool

Equal verifies that two EVM eth_call queries are equal.

func (*EthCallQueryRequest) Marshal

func (ecd *EthCallQueryRequest) Marshal() ([]byte, error)

Marshal serializes the binary representation of an EVM eth_call request. This method calls Validate() and relies on it to range checks lengths, etc.

func (*EthCallQueryRequest) Type

func (*EthCallQueryRequest) Unmarshal

func (ecd *EthCallQueryRequest) Unmarshal(data []byte) error

Unmarshal deserializes an EVM eth_call query from a byte array

func (*EthCallQueryRequest) UnmarshalFromReader

func (ecd *EthCallQueryRequest) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes an EVM eth_call query from a byte array

func (*EthCallQueryRequest) Validate

func (ecd *EthCallQueryRequest) Validate() error

Validate does basic validation on an EVM eth_call query.

type EthCallQueryResponse

type EthCallQueryResponse struct {
	BlockNumber uint64
	Hash        common.Hash
	Time        time.Time

	// Results is the array of responses matching CallData in EthCallQueryRequest
	Results [][]byte
}

EthCallQueryResponse implements ChainSpecificResponse for an EVM eth_call query response.

func (*EthCallQueryResponse) Equal

func (left *EthCallQueryResponse) Equal(right *EthCallQueryResponse) bool

Equal verifies that two EVM eth_call responses are equal.

func (*EthCallQueryResponse) Marshal

func (ecr *EthCallQueryResponse) Marshal() ([]byte, error)

Marshal serializes the binary representation of an EVM eth_call response. This method calls Validate() and relies on it to range checks lengths, etc.

func (*EthCallQueryResponse) Type

func (*EthCallQueryResponse) Unmarshal

func (ecr *EthCallQueryResponse) Unmarshal(data []byte) error

Unmarshal deserializes an EVM eth_call response from a byte array

func (*EthCallQueryResponse) UnmarshalFromReader

func (ecr *EthCallQueryResponse) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes an EVM eth_call response from a byte array

func (*EthCallQueryResponse) Validate

func (ecr *EthCallQueryResponse) Validate() error

Validate does basic validation on an EVM eth_call response.

type EthCallWithFinalityQueryRequest

type EthCallWithFinalityQueryRequest struct {
	// BlockId identifies the block to be queried. It must be a hex string starting with 0x. It may be a block number or a block hash.
	BlockId string

	// Finality is required. It identifies the level of finality the block must reach before the query is performed. Valid values are "finalized" and "safe".
	Finality string

	// CallData is an array of specific queries to be performed on the specified block, in a single RPC call.
	CallData []*EthCallData
}

EthCallWithFinalityQueryRequest implements ChainSpecificQuery for an EVM eth_call_with_finality query request.

func (*EthCallWithFinalityQueryRequest) CallDataList

func (ecr *EthCallWithFinalityQueryRequest) CallDataList() []*EthCallData

func (*EthCallWithFinalityQueryRequest) Equal

Equal verifies that two EVM eth_call_with_finality queries are equal.

func (*EthCallWithFinalityQueryRequest) Marshal

func (ecd *EthCallWithFinalityQueryRequest) Marshal() ([]byte, error)

Marshal serializes the binary representation of an EVM eth_call_with_finality request. This method calls Validate() and relies on it to range checks lengths, etc.

func (*EthCallWithFinalityQueryRequest) Type

func (*EthCallWithFinalityQueryRequest) Unmarshal

func (ecd *EthCallWithFinalityQueryRequest) Unmarshal(data []byte) error

Unmarshal deserializes an EVM eth_call_with_finality query from a byte array

func (*EthCallWithFinalityQueryRequest) UnmarshalFromReader

func (ecd *EthCallWithFinalityQueryRequest) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes an EVM eth_call_with_finality query from a byte array

func (*EthCallWithFinalityQueryRequest) Validate

func (ecd *EthCallWithFinalityQueryRequest) Validate() error

Validate does basic validation on an EVM eth_call_with_finality query.

type EthCallWithFinalityQueryResponse

type EthCallWithFinalityQueryResponse struct {
	BlockNumber uint64
	Hash        common.Hash
	Time        time.Time

	// Results is the array of responses matching CallData in EthCallQueryRequest
	Results [][]byte
}

EthCallWithFinalityQueryResponse implements ChainSpecificResponse for an EVM eth_call_with_finality query response.

func (*EthCallWithFinalityQueryResponse) Equal

Equal verifies that two EVM eth_call responses are equal.

func (*EthCallWithFinalityQueryResponse) Marshal

func (ecr *EthCallWithFinalityQueryResponse) Marshal() ([]byte, error)

Marshal serializes the binary representation of an EVM eth_call response. This method calls Validate() and relies on it to range checks lengths, etc.

func (*EthCallWithFinalityQueryResponse) Type

func (*EthCallWithFinalityQueryResponse) Unmarshal

func (ecr *EthCallWithFinalityQueryResponse) Unmarshal(data []byte) error

Unmarshal deserializes an EVM eth_call response from a byte array

func (*EthCallWithFinalityQueryResponse) UnmarshalFromReader

func (ecr *EthCallWithFinalityQueryResponse) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes an EVM eth_call response from a byte array

func (*EthCallWithFinalityQueryResponse) Validate

func (ecr *EthCallWithFinalityQueryResponse) Validate() error

Validate does basic validation on an EVM eth_call response.

type PerChainQueryInternal

type PerChainQueryInternal struct {
	RequestID  string
	RequestIdx int
	Request    *PerChainQueryRequest
}

PerChainQueryInternal is an internal representation of a query request that is passed to the watcher.

type PerChainQueryRequest

type PerChainQueryRequest struct {
	// ChainId indicates which chain this query is destine for.
	ChainId vaa.ChainID

	// Query is the chain specific query data.
	Query ChainSpecificQuery
}

PerChainQueryRequest represents a query request for a single chain.

func (*PerChainQueryRequest) Equal

func (left *PerChainQueryRequest) Equal(right *PerChainQueryRequest) bool

Equal verifies that two query requests are equal.

func (*PerChainQueryRequest) Marshal

func (perChainQuery *PerChainQueryRequest) Marshal() ([]byte, error)

Marshal serializes the binary representation of a per chain query request. This method calls Validate() and relies on it to range checks lengths, etc.

func (*PerChainQueryRequest) Unmarshal

func (perChainQuery *PerChainQueryRequest) Unmarshal(data []byte) error

Unmarshal deserializes the binary representation of a per chain query request from a byte array

func (*PerChainQueryRequest) UnmarshalFromReader

func (perChainQuery *PerChainQueryRequest) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes the binary representation of a per chain query request from an existing reader

func (*PerChainQueryRequest) Validate

func (perChainQuery *PerChainQueryRequest) Validate() error

Validate does basic validation on a per chain query request.

type PerChainQueryResponse

type PerChainQueryResponse struct {
	// ChainId indicates which chain this query was destine for.
	ChainId vaa.ChainID

	// Response is the chain specific query data.
	Response ChainSpecificResponse
}

PerChainQueryResponse represents a query response for a single chain.

func (*PerChainQueryResponse) Equal

func (left *PerChainQueryResponse) Equal(right *PerChainQueryResponse) bool

Equal checks for equality on two per chain query responses.

func (*PerChainQueryResponse) Marshal

func (perChainResponse *PerChainQueryResponse) Marshal() ([]byte, error)

Marshal marshalls a per chain query response.

func (*PerChainQueryResponse) Unmarshal

func (perChainResponse *PerChainQueryResponse) Unmarshal(data []byte) error

Unmarshal deserializes the binary representation of a per chain query response from a byte array

func (*PerChainQueryResponse) UnmarshalFromReader

func (perChainResponse *PerChainQueryResponse) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes the binary representation of a per chain query response from an existing reader

func (*PerChainQueryResponse) Validate

func (perChainResponse *PerChainQueryResponse) Validate() error

ValidatePerChainResponse performs basic validation on a per chain query response.

type PerChainQueryResponseInternal

type PerChainQueryResponseInternal struct {
	RequestID  string
	RequestIdx int
	ChainId    vaa.ChainID
	Status     QueryStatus
	Response   ChainSpecificResponse
}

This is the query response returned from the watcher to the query handler.

func CreatePerChainQueryResponseInternal

func CreatePerChainQueryResponseInternal(reqId string, reqIdx int, chainId vaa.ChainID, status QueryStatus, response ChainSpecificResponse) *PerChainQueryResponseInternal

CreatePerChainQueryResponseInternal creates a PerChainQueryResponseInternal and returns a pointer to it.

type QueryHandler

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

QueryHandler defines the cross chain query handler.

func NewQueryHandler

func NewQueryHandler(
	logger *zap.Logger,
	env common.Environment,
	allowedRequestorsStr string,
	signedQueryReqC <-chan *gossipv1.SignedQueryRequest,
	chainQueryReqC map[vaa.ChainID]chan *PerChainQueryInternal,
	queryResponseReadC <-chan *PerChainQueryResponseInternal,
	queryResponseWriteC chan<- *QueryResponsePublication,
) *QueryHandler

func (*QueryHandler) Start

func (qh *QueryHandler) Start(ctx context.Context) error

Start initializes the query handler and starts the runnable.

type QueryRequest

type QueryRequest struct {
	Nonce           uint32
	PerChainQueries []*PerChainQueryRequest
}

QueryRequest defines a cross chain query request to be submitted to the phylaxs. It is the payload of the SignedQueryRequest gossip message.

func (*QueryRequest) Equal

func (left *QueryRequest) Equal(right *QueryRequest) bool

Equal verifies that two query requests are equal.

func (*QueryRequest) Marshal

func (queryRequest *QueryRequest) Marshal() ([]byte, error)

Marshal serializes the binary representation of a query request. This method calls Validate() and relies on it to range checks lengths, etc.

func (*QueryRequest) Unmarshal

func (queryRequest *QueryRequest) Unmarshal(data []byte) error

Unmarshal deserializes the binary representation of a query request from a byte array

func (*QueryRequest) UnmarshalFromReader

func (queryRequest *QueryRequest) UnmarshalFromReader(reader *bytes.Reader) error

UnmarshalFromReader deserializes the binary representation of a query request from an existing reader

func (*QueryRequest) Validate

func (queryRequest *QueryRequest) Validate() error

Validate does basic validation on a received query request.

type QueryResponsePublication

type QueryResponsePublication struct {
	Request           *gossipv1.SignedQueryRequest
	PerChainResponses []*PerChainQueryResponse
}

QueryResponsePublication is the response to a QueryRequest.

func (*QueryResponsePublication) Equal

Equal checks for equality on two query response publications.

func (*QueryResponsePublication) Marshal

func (msg *QueryResponsePublication) Marshal() ([]byte, error)

Marshal serializes the binary representation of a query response. This method calls Validate() and relies on it to range checks lengths, etc.

func (*QueryResponsePublication) RequestID

func (resp *QueryResponsePublication) RequestID() string

func (*QueryResponsePublication) SigningDigest

func (msg *QueryResponsePublication) SigningDigest() (common.Hash, error)

Similar to sdk/vaa/structs.go, In order to save space in the solana signature verification instruction, we hash twice so we only need to pass in the first hash (32 bytes) vs the full body data.

func (*QueryResponsePublication) Unmarshal

func (msg *QueryResponsePublication) Unmarshal(data []byte) error

Unmarshal deserializes the binary representation of a query response

func (*QueryResponsePublication) Validate

func (msg *QueryResponsePublication) Validate() error

Validate does basic validation on a received query request.

type QueryStatus

type QueryStatus int

QueryStatus is the status returned from the watcher to the query handler.

const (
	// QuerySuccess means the query was successful and the response should be returned to the requester.
	QuerySuccess QueryStatus = 1

	// QueryRetryNeeded means the query failed, but a retry may be helpful.
	QueryRetryNeeded QueryStatus = 0

	// QueryFatalError means the query failed, and there is no point in retrying it.
	QueryFatalError QueryStatus = -1
)

Jump to

Keyboard shortcuts

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