claimsync

package
v0.10.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0, MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DebugTraceTxEndpoint is the name of the debug method used to trace a transaction.
	DebugTraceTxEndpoint = "debug_traceTransaction"
	// GetTransactionByHashEndpoint is the name of the method used to get transaction details by hash.
	GetTransactionByHashEndpoint = "eth_getTransactionByHash"
)

Variables

This section is empty.

Functions

func NewClaimStorage

func NewClaimStorage(
	database *sql.DB,
	logger aggkitcommon.Logger,
	syncerID claimsynctypes.ClaimSyncerID,
	dbQueryTimeout time.Duration,
) (claimsynctypes.ClaimStorager, error)

NewClaimStorage creates a claim storage instance for embedded mode, using the provided database connection.

func NewPreferDetailedClaimLogsHook

func NewPreferDetailedClaimLogsHook(logger aggkitcommon.Logger) sync.LogsHookFunc

NewPreferDetailedClaimLogsHook returns a LogsHookFunc that removes ClaimEvent logs when a DetailedClaimEvent log exists for the same transaction, so only the richer event is processed.

Types

type AgglayerBridgeL2Reader

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

AgglayerBridgeL2Reader provides functionality to read and interact with the AggLayer Bridge L2 contract. It encapsulates the contract instance and provides methods to query bridge-related data from the L2 chain.

func NewAgglayerBridgeL2Reader

func NewAgglayerBridgeL2Reader(
	bridgeAddr common.Address,
	l2Client aggkittypes.BaseEthereumClienter,
) (*AgglayerBridgeL2Reader, error)

NewAgglayerBridgeL2Reader creates a new instance of AgglayerBridgeL2Reader. It initializes the contract instance using the provided bridge address and L2 client.

Parameters:

  • bridgeAddr: The Ethereum address of the AggLayer Bridge L2 contract
  • l2Client: The Ethereum client for interacting with the L2 chain

Returns:

  • *AgglayerBridgeL2Reader: A new reader instance
  • error: Any error that occurred during contract initialization

func NewAgglayerBridgeL2ReaderWithMaxLogBlockRange

func NewAgglayerBridgeL2ReaderWithMaxLogBlockRange(
	bridgeAddr common.Address,
	l2Client aggkittypes.BaseEthereumClienter,
	unsetClaimsMaxLogBlockRange uint64,
) (*AgglayerBridgeL2Reader, error)

NewAgglayerBridgeL2ReaderWithMaxLogBlockRange creates a new instance of AgglayerBridgeL2Reader with an optional proactive max block range for unset claims eth_getLogs queries.

func (*AgglayerBridgeL2Reader) GetUnsetClaimsForBlockRange

func (r *AgglayerBridgeL2Reader) GetUnsetClaimsForBlockRange(ctx context.Context,
	fromBlock, toBlock uint64) ([]claimsynctypes.Unclaim, error)

GetUnsetClaimsForBlockRange retrieves all unset claims (unclaims) within a specified block range. It filters the UpdatedUnsetGlobalIndexHashChain events from the bridge contract and converts them into Unclaim objects for further processing. If the block range is too large, it automatically splits the request into smaller chunks.

Parameters:

  • ctx: Context for cancellation and timeout control
  • fromBlock: The starting block number for the search range (inclusive)
  • toBlock: The ending block number for the search range (inclusive)

Returns:

  • []types.Unclaim: A slice of Unclaim objects containing global index, block number, and block index
  • error: Any error that occurred during the event filtering or iteration

type BridgeDeployment

type BridgeDeployment byte

BridgeDeployment represents the type of bridge contract deployment (sovereign vs non-sovereign).

const (
	Unknown BridgeDeployment = iota
	NonSovereignChain
	SovereignChain
)

func (BridgeDeployment) String

func (b BridgeDeployment) String() string

type Call

type Call struct {
	From  common.Address    `json:"from"`
	To    common.Address    `json:"to"`
	Value *rpctypes.ArgBig  `json:"value"`
	Err   *string           `json:"error"`
	Input rpctypes.ArgBytes `json:"input"`
	Calls []Call            `json:"calls"`
}

type Claim

type Claim = claimsynctypes.Claim

Claim is an alias for claimsynctypes.Claim

type ClaimSync

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

ClaimSync is the standalone implementation that independently processes claim events.

func NewClaimSync

func NewClaimSync(
	ctx context.Context,
	cfg ConfigStandalone,
	rd sync.ReorgDetector,
	ethClient aggkittypes.EthClienter,
	originNetwork uint32,
	syncerID claimsynctypes.ClaimSyncerID,
	logger aggkitcommon.Logger,
) (*ClaimSync, error)

NewClaimSync creates a standalone ClaimSync that indexes claim events from the bridge contract directly.

func NewStandaloneClaimSync

func NewStandaloneClaimSync(
	ctx context.Context,
	cfg ConfigStandalone,
	rd sync.ReorgDetector,
	ethClient aggkittypes.EthClienter,
	syncerID claimsynctypes.ClaimSyncerID,
	originNetwork uint32,
) (*ClaimSync, error)

NewStandaloneClaimSync creates a standalone ClaimSync that indexes claim events from the bridge contract directly.

func (*ClaimSync) GetClaims

func (c *ClaimSync) GetClaims(ctx context.Context, fromBlock, toBlock uint64) ([]claimsynctypes.Claim, error)

func (*ClaimSync) GetClaimsByGER

func (c *ClaimSync) GetClaimsByGER(ctx context.Context, globalExitRoot common.Hash) ([]*Claim, error)

func (*ClaimSync) GetClaimsByGlobalIndex

func (c *ClaimSync) GetClaimsByGlobalIndex(ctx context.Context, globalIndex *big.Int) ([]claimsynctypes.Claim, error)

func (*ClaimSync) GetClaimsPaged

func (c *ClaimSync) GetClaimsPaged(ctx context.Context, page, pageSize uint32,
	networkIDs []uint32, globalIndex *big.Int) ([]*Claim, int, error)

func (*ClaimSync) GetFirstProcessedBlock

func (c *ClaimSync) GetFirstProcessedBlock(ctx context.Context) (uint64, bool, error)

func (*ClaimSync) GetLastProcessedBlock

func (c *ClaimSync) GetLastProcessedBlock(ctx context.Context) (uint64, bool, error)

func (*ClaimSync) GetLatestBlockNumByGlobalIndexFromRPC

func (c *ClaimSync) GetLatestBlockNumByGlobalIndexFromRPC(
	ctx context.Context, globalIndex *big.Int, toBlock *aggkittypes.BlockNumberFinality) (uint64, bool, error)

GetLatestBlockNumByGlobalIndexFromRPC scans claim event logs on-chain backwards from toBlock to 0 and returns the block number of the most recent log whose GlobalIndex matches. If toBlock is nil, the finality from the configuration (cfg.BlockFinality) is used. The scan is split into chunks if the RPC reports a max-range limit; the chunk size is taken from the error message the first time a full-range call fails. The bool return value is false when no matching log is found (no error in that case).

func (*ClaimSync) GetRPCServices

func (c *ClaimSync) GetRPCServices() []jRPC.Service

GetRPCServices returns the RPC services exposed by ClaimSync.

func (*ClaimSync) GetSetClaimsPaged

func (c *ClaimSync) GetSetClaimsPaged(ctx context.Context, page, pageSize uint32,
	globalIndex *big.Int) ([]*SetClaim, int, error)

func (*ClaimSync) GetUnsetClaimsPaged

func (c *ClaimSync) GetUnsetClaimsPaged(ctx context.Context, page, pageSize uint32,
	globalIndex *big.Int) ([]*UnsetClaim, int, error)

func (*ClaimSync) OriginNetwork

func (c *ClaimSync) OriginNetwork() uint32

OriginNetwork returns the network ID of the origin chain.

func (*ClaimSync) SetNextRequiredBlock

func (c *ClaimSync) SetNextRequiredBlock(ctx context.Context, blockNumber uint64) error

func (*ClaimSync) Start

func (c *ClaimSync) Start(ctx context.Context)

Start starts the synchronization process.

func (*ClaimSync) SyncNextBlock

func (c *ClaimSync) SyncNextBlock(ctx context.Context, blockNum uint64) error

SyncNextBlock downloads and processes blockNum as a bootstrap step.

type ClaimSyncRPC

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

ClaimSyncRPC is the RPC interface for the ClaimSync component.

func NewClaimSyncRPC

func NewClaimSyncRPC(logger aggkitcommon.Logger, claimSync ClaimSyncer) *ClaimSyncRPC

NewClaimSyncRPC creates a new ClaimSyncRPC.

func (*ClaimSyncRPC) GetClaims

func (r *ClaimSyncRPC) GetClaims(fromBlock, toBlock uint64) (interface{}, jRPC.Error)

GetClaims returns claims indexed between fromBlock and toBlock. curl -X POST http://localhost:5576/ -H "Content-Type: application/json" \ -d '{"method":"l2claimsync_getClaims", "params":[0, 1000], "id":1}'

func (*ClaimSyncRPC) GetClaimsByGlobalIndex

func (r *ClaimSyncRPC) GetClaimsByGlobalIndex(globalIndexStr string) (interface{}, jRPC.Error)

GetClaimsByGlobalIndex returns claims for the given global index. curl -X POST http://localhost:5576/ -H "Content-Type: application/json" \ -d '{"method":"l2claimsync_getClaimsByGlobalIndex", "params":["123"], "id":1}'

func (*ClaimSyncRPC) SetNextRequiredBlock

func (r *ClaimSyncRPC) SetNextRequiredBlock(blockNum uint64) (interface{}, jRPC.Error)

SetNextRequiredBlock sets the next block number that the synchronizer must process. curl -X POST http://localhost:5576/ -H "Content-Type: application/json" \ -d '{"method":"l2claimsync_setNextRequiredBlock", "params":[1000], "id":1}'

func (*ClaimSyncRPC) Status

func (r *ClaimSyncRPC) Status() (interface{}, jRPC.Error)

Status returns the sync status of the ClaimSync component. curl -X POST http://localhost:5576/ -H "Content-Type: application/json" \ -d '{"method":"l2claimsync_status", "params":[], "id":1}'

type ClaimSyncer

type ClaimSyncer interface {
	GetLastProcessedBlock(ctx context.Context) (uint64, bool, error)
	GetFirstProcessedBlock(ctx context.Context) (uint64, bool, error)
	GetClaims(ctx context.Context, fromBlock, toBlock uint64) ([]claimsynctypes.Claim, error)
	GetClaimsByGlobalIndex(ctx context.Context, globalIndex *big.Int) ([]claimsynctypes.Claim, error)
	SetNextRequiredBlock(ctx context.Context, blockNum uint64) error
}

ClaimSyncer is the interface required by ClaimSyncRPC.

type ClaimType

type ClaimType = claimsynctypes.ClaimType

ClaimType is an alias for claimsynctypes.ClaimType

const (
	ClaimEvent         ClaimType = claimsynctypes.ClaimEvent
	DetailedClaimEvent ClaimType = claimsynctypes.DetailedClaimEvent
)

type ConfigEmbedded

type ConfigEmbedded struct {
	// DBQueryTimeout is the timeout for database operations (queries, transactions)
	// This is separate from HTTP timeouts to allow database operations more time when needed
	DBQueryTimeout types.Duration `mapstructure:"DBQueryTimeout"`
	// BridgeAddr is the address of the bridge smart contract
	BridgeAddr common.Address `mapstructure:"BridgeAddr"`
}

func (ConfigEmbedded) Validate

func (c ConfigEmbedded) Validate() error

type ConfigStandalone

type ConfigStandalone struct {
	ConfigEmbedded `mapstructure:",squash"`
	// DBPath path of the DB
	DBPath string `mapstructure:"DBPath"`
	// BlockFinality indicates the status of the blocks that will be queried in order to sync
	BlockFinality aggkittypes.BlockNumberFinality `` //nolint:lll
	/* 134-byte string literal not displayed */
	// InitialBlockNum is the first block that will be queried when starting the synchronization from scratch.
	// It should be a number equal or below the creation of the bridge contract
	InitialBlockNum uint64 `mapstructure:"InitialBlockNum"`
	// SyncBlockChunkSize is the amount of blocks that will be queried to the client on each request
	SyncBlockChunkSize uint64 `mapstructure:"SyncBlockChunkSize"`
	// RetryAfterErrorPeriod is the time that will be waited when an unexpected error happens before retry
	RetryAfterErrorPeriod types.Duration `mapstructure:"RetryAfterErrorPeriod"`
	// MaxRetryAttemptsAfterError is the maximum number of consecutive attempts that will happen before panicking.
	// Any number smaller than zero will be considered as unlimited retries
	MaxRetryAttemptsAfterError int `mapstructure:"MaxRetryAttemptsAfterError"`

	// WaitForNewBlocksPeriod time that will be waited when the synchronizer has reached the latest block
	WaitForNewBlocksPeriod types.Duration `mapstructure:"WaitForNewBlocksPeriod"`
	// RequireStorageContentCompatibility is true it's mandatory that data stored in the database
	// is compatible with the running environment
	RequireStorageContentCompatibility bool `mapstructure:"RequireStorageContentCompatibility"`
	// AutoStart controls whether the synchronizer should start automatically after initialization.
	// Possible values:
	//   - "true": automatically starts after initialization using InitialBlockNum
	//   - "false": does not start automatically; requires manual start
	//   - "auto": automatically decides based on which component is active
	AutoStart types.TrueFalseAutoMode `jsonschema:"enum=true, enum=false, enum=auto" mapstructure:"AutoStart"`
}

func (ConfigStandalone) Validate

func (c ConfigStandalone) Validate() error

type EmbeddedClaimSync

type EmbeddedClaimSync struct {
	Appender  sync.LogAppenderMap
	Processor claimsynctypes.EmbeddedProcessor
	Reader    claimsynctypes.ClaimsReader
}

EmbeddedClaimSync is passed to bridgesync as a ClaimEventsProcessor. It has no own EVMDriver; bridgesync drives event download and calls ProcessClaimEvents from its own ProcessBlock, reusing bridgesync's transaction for atomicity.

func NewEmbedded

func NewEmbedded(
	ctx context.Context,
	storage claimsynctypes.ClaimStorager,
	bridgeAddr common.Address,
	ethClient aggkittypes.EthClienter,
	syncerID claimsynctypes.ClaimSyncerID,
	dbQueryTimeout time.Duration,
	logger aggkitcommon.Logger,
) (*EmbeddedClaimSync, error)

NewEmbedded creates a ClaimEventsProcessor for embedding inside bridgesync. It provides claimsync's claim event handlers (for appender merging) and processes claim events using bridgesync's own transaction — no separate DB or EVMDriver is created.

type Event

type Event struct {
	Claim      *Claim
	UnsetClaim *UnsetClaim
	SetClaim   *SetClaim
}

Event combination claim events

func (Event) String

func (e Event) String() string

type SetClaim

type SetClaim = claimsynctypes.SetClaim

SetClaim is an alias for claimsynctypes.SetClaim

type UnsetClaim

type UnsetClaim = claimsynctypes.UnsetClaim

UnsetClaim is an alias for claimsynctypes.UnsetClaim

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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