common

package
v0.0.41 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainClient

type ChainClient interface {
	// Start initializes and starts the chain client
	Start(ctx context.Context) error

	// Stop gracefully shuts down the chain client
	Stop() error

	// IsHealthy checks if the chain client is operational
	IsHealthy() bool

	// GetTxBuilder returns the TxBuilder for this chain
	// Returns an error if txBuilder is not supported for this chain (e.g., Push chain)
	GetTxBuilder() (TxBuilder, error)
}

ChainClient defines the interface for chain-specific implementations

type ChainStore added in v0.0.13

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

ChainStore provides database operations for chain state and events

func NewChainStore added in v0.0.13

func NewChainStore(database *db.DB) *ChainStore

NewChainStore creates a new chain store

func (*ChainStore) DeleteTerminalEvents added in v0.0.13

func (cs *ChainStore) DeleteTerminalEvents(updatedBefore any) (int64, error)

DeleteTerminalEvents deletes events in terminal states (COMPLETED, REVERTED, EXPIRED) that were updated before the given time

func (*ChainStore) GetChainHeight added in v0.0.13

func (cs *ChainStore) GetChainHeight() (uint64, error)

GetChainHeight returns the last processed block height for the chain. Creates a new entry with height 0 if one doesn't exist (atomic via FirstOrCreate).

func (*ChainStore) GetConfirmedEvents added in v0.0.13

func (cs *ChainStore) GetConfirmedEvents(limit int) ([]store.Event, error)

GetConfirmedEvents fetches confirmed events ordered by creation time

func (*ChainStore) GetPendingEvents added in v0.0.13

func (cs *ChainStore) GetPendingEvents(limit int) ([]store.Event, error)

GetPendingEvents fetches pending events ordered by creation time

func (*ChainStore) InsertEventIfNotExists added in v0.0.13

func (cs *ChainStore) InsertEventIfNotExists(event *store.Event) (bool, error)

InsertEventIfNotExists inserts an event if it doesn't already exist (by EventID) Returns (true, nil) if a new event was inserted, (false, nil) if it already existed, or (false, error) if insertion failed

func (*ChainStore) UpdateChainHeight added in v0.0.13

func (cs *ChainStore) UpdateChainHeight(blockHeight uint64) error

UpdateChainHeight updates the last processed block height for the chain. Creates a new entry if one doesn't exist (atomic via FirstOrCreate). Only updates if the new height is greater than the current one.

func (*ChainStore) UpdateEventStatus added in v0.0.13

func (cs *ChainStore) UpdateEventStatus(eventID string, oldStatus, newStatus string) (int64, error)

UpdateEventStatus updates the status of an event by event ID

func (*ChainStore) UpdateStatusAndEventData added in v0.0.19

func (cs *ChainStore) UpdateStatusAndEventData(eventID, oldStatus, newStatus string, eventData []byte) (int64, error)

UpdateStatusAndEventData atomically flips the event status and updates the event data in one DB write. The update is conditional on the event currently having oldStatus (compare-and-swap semantics). Returns the number of rows affected (0 means the event was already in a different status).

func (*ChainStore) UpdateStatusAndVoteTxHash added in v0.0.16

func (cs *ChainStore) UpdateStatusAndVoteTxHash(eventID, oldStatus, newStatus, voteTxHash string) (int64, error)

UpdateStatusAndVoteTxHash atomically flips the event status and records the vote tx hash in one DB write. The update is conditional on the event currently having oldStatus (compare-and-swap semantics). Returns the number of rows affected (0 means the event was already in a different status).

func (*ChainStore) UpdateVoteTxHash added in v0.0.13

func (cs *ChainStore) UpdateVoteTxHash(eventID string, voteTxHash string) error

UpdateVoteTxHash updates the vote_tx_hash field for an event

type EventCleaner added in v0.0.13

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

EventCleaner handles periodic cleanup of old confirmed events for a chain

func NewEventCleaner added in v0.0.13

func NewEventCleaner(
	database *db.DB,
	cleanupIntervalSeconds *int,
	retentionPeriodSeconds *int,
	chainID string,
	logger zerolog.Logger,
) *EventCleaner

NewEventCleaner creates a new event cleaner for a chain

func (*EventCleaner) Start added in v0.0.13

func (ec *EventCleaner) Start(ctx context.Context) error

Start begins the periodic cleanup process

func (*EventCleaner) Stop added in v0.0.13

func (ec *EventCleaner) Stop()

Stop gracefully stops the event cleaner. No-op if not running.

type EventProcessor added in v0.0.13

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

EventProcessor processes events from the chain's database and votes on them

func NewEventProcessor added in v0.0.13

func NewEventProcessor(
	signer *pushsigner.Signer,
	database *db.DB,
	chainID string,
	inboundEnabled bool,
	outboundEnabled bool,
	logger zerolog.Logger,
) *EventProcessor

NewEventProcessor creates a new event processor

func (*EventProcessor) IsRunning added in v0.0.13

func (ep *EventProcessor) IsRunning() bool

IsRunning returns whether the processor is currently running

func (*EventProcessor) Start added in v0.0.13

func (ep *EventProcessor) Start(ctx context.Context) error

Start begins processing events

func (*EventProcessor) Stop added in v0.0.13

func (ep *EventProcessor) Stop() error

Stop gracefully stops the event processor

type FundMigrationData added in v0.0.28

type FundMigrationData struct {
	From     string   // Old TSS address (derived from old pubkey)
	To       string   // New TSS address (derived from current pubkey)
	GasPrice *big.Int // Gas price from the migration event
	GasLimit uint64   // Gas limit from the migration event
	L1GasFee *big.Int // Extra L1 data-availability fee (wei); 0 for non-L2 chains

	Balance *big.Int // if nil, builder queries chain
}

FundMigrationData contains the data needed to build a fund migration transaction. Populated by the coordinator from the migration event + derived addresses.

type OutboundEvent added in v0.0.13

type OutboundEvent struct {
	TxID          string `json:"tx_id"`                  // bytes32 hex-encoded (0x...)
	UniversalTxID string `json:"universal_tx_id"`        // bytes32 hex-encoded (0x...)
	GasFeeUsed    string `json:"gas_fee_used,omitempty"` // gas fee used in wei (decimal string)
}

OutboundEvent represents an outbound observation event from the gateway contract Event structure: - txID at 1st indexed position (bytes32) - universalTxID at 2nd indexed position (bytes32)

type TxBuilder added in v0.0.28

type TxBuilder interface {
	// GetOutboundSigningRequest creates a signing request from outbound event data
	GetOutboundSigningRequest(ctx context.Context, data *uetypes.OutboundCreatedEvent, nonce uint64) (*UnsignedSigningReq, error)

	// GetNextNonce returns the next nonce for the given signer on this chain (for seeding local nonce).
	// useFinalized: for EVM, if true use finalized block nonce (aggressive/replace stuck); if false use pending. SVM ignores this.
	GetNextNonce(ctx context.Context, signerAddress string, useFinalized bool) (uint64, error)

	// BroadcastOutboundSigningRequest assembles and broadcasts a signed transaction from the signing request, event data, and signature
	BroadcastOutboundSigningRequest(ctx context.Context, req *UnsignedSigningReq, data *uetypes.OutboundCreatedEvent, signature []byte) (string, error)

	// VerifyBroadcastedTx checks the status of a broadcasted transaction on the destination chain.
	// Returns (found, blockHeight, confirmations, status, error):
	// - found=false: tx not found or not yet mined
	// - found=true: tx exists on-chain
	//   - blockHeight: the block in which the tx was mined
	//   - confirmations: number of blocks since the tx was mined (0 = just mined)
	//   - status: 0 = failed/reverted, 1 = success
	VerifyBroadcastedTx(ctx context.Context, txHash string) (found bool, blockHeight uint64, confirmations uint64, status uint8, err error)

	// IsAlreadyExecuted checks whether a transaction with the given txID has already been
	// executed on the destination chain (e.g., by another relayer).
	// For SVM: checks if the ExecutedTx PDA exists on-chain, AND returns the
	//   unix timestamp of the latest finalized block. Callers use this as the
	//   cluster's "now" to gate deadline-based give-up/REVERT decisions and to
	//   detect cluster halt or finalization stall (queryBlockTime far behind
	//   wall-clock). 0 means freshness couldn't be determined.
	// For EVM: returns (false, 0, nil). EVM uses nonce-based replay protection.
	IsAlreadyExecuted(ctx context.Context, txID string) (executed bool, queryBlockTime int64, err error)

	// GetGasFeeUsed returns the gas fee used by a transaction on the destination chain.
	// EVM: fetches receipt and returns gasUsed * effectiveGasPrice as decimal string.
	// SVM: returns "0" (gas accounting is handled via vault gasFee reimbursement).
	// Returns "0" if the transaction is not found.
	GetGasFeeUsed(ctx context.Context, txHash string) (string, error)

	// GetFundMigrationSigningRequest builds a native token transfer for fund migration,
	// transferring the maximum possible balance (balance minus gas cost).
	GetFundMigrationSigningRequest(ctx context.Context, data *FundMigrationData, nonce uint64) (*UnsignedSigningReq, error)

	// BroadcastFundMigrationTx assembles and broadcasts a signed fund migration transaction.
	BroadcastFundMigrationTx(ctx context.Context, req *UnsignedSigningReq, data *FundMigrationData, signature []byte) (string, error)
}

TxBuilder builds and broadcasts transactions for outbound transfers

type UniversalTx

type UniversalTx struct {
	SourceChain         string `json:"sourceChain"`
	LogIndex            uint   `json:"logIndex"`
	Sender              string `json:"sender"`
	Recipient           string `json:"recipient"`
	Token               string `json:"bridgeToken"`
	Amount              string `json:"bridgeAmount"`         // uint256 as decimal string
	RawPayload          string `json:"rawPayload,omitempty"` // hex-encoded raw payload bytes from source chain
	VerificationData    string `json:"verificationData"`
	RevertFundRecipient string `json:"revertFundRecipient,omitempty"`
	TxType              uint   `json:"txType"`  // enum backing uint as decimal string
	FromCEA             bool   `json:"fromCEA"` // true if inbound is initiated by a CEA
}

UniversalTx Payload

type UnsignedSigningReq added in v0.0.28

type UnsignedSigningReq struct {
	SigningHash []byte // Hash to be signed by TSS
	Nonce       uint64 // evm - TSS Address nonce | svm - PDA nonce

	// TSSFundMigrationAmount is the native value swept for a fund-migration tx, fixed at
	// signing time. Nil for outbound. Must be reused verbatim at broadcast — re-querying
	// balance there races with a successful sweep from another validator.
	TSSFundMigrationAmount *big.Int `json:"TSSFundMigrationAmount,omitempty"`
}

UnsignedSigningReq contains the request for signing an outbound or fund-migration transaction.

Jump to

Keyboard shortcuts

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