bridgesync

package
v0.2.0-beta7-bridge-tmp Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: Apache-2.0, MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WrappedToken = iota
	SovereignToken
)

Variables

View Source
var (
	// ErrInvalidPageSize indicates that the page size is invalid
	ErrInvalidPageSize = errors.New("page size must be greater than 0")

	// ErrInvalidPageNumber indicates that the page number is invalid
	ErrInvalidPageNumber = errors.New("page number must be greater than 0")
)

Functions

func DecodeGlobalIndex

func DecodeGlobalIndex(globalIndex *big.Int) (mainnetFlag bool,
	rollupIndex uint32, localExitRootIndex uint32, err error)

Decodes global index to its three parts: 1. mainnetFlag - first byte 2. rollupIndex - next 4 bytes 3. localExitRootIndex - last 4 bytes NOTE - mainnet flag is not in the global index bytes if it is false NOTE - rollup index is 0 if mainnet flag is true NOTE - rollup index is not in the global index bytes if mainnet flag is false and rollup index is 0

func GenerateGlobalIndex

func GenerateGlobalIndex(mainnetFlag bool, rollupIndex uint32, localExitRootIndex uint32) *big.Int

Types

type Bridge

type Bridge struct {
	BlockNum           uint64         `meddler:"block_num" json:"block_num"`
	BlockPos           uint64         `meddler:"block_pos" json:"block_pos"`
	FromAddress        common.Address `meddler:"from_address,address" json:"from_address"`
	TxHash             common.Hash    `meddler:"tx_hash,hash" json:"tx_hash"`
	Calldata           []byte         `meddler:"calldata" json:"calldata"`
	BlockTimestamp     uint64         `meddler:"block_timestamp" json:"block_timestamp"`
	LeafType           uint8          `meddler:"leaf_type" json:"leaf_type"`
	OriginNetwork      uint32         `meddler:"origin_network" json:"origin_network"`
	OriginAddress      common.Address `meddler:"origin_address" json:"origin_address"`
	DestinationNetwork uint32         `meddler:"destination_network" json:"destination_network"`
	DestinationAddress common.Address `meddler:"destination_address" json:"destination_address"`
	Amount             *big.Int       `meddler:"amount,bigint" json:"amount"`
	Metadata           []byte         `meddler:"metadata" json:"metadata"`
	DepositCount       uint32         `meddler:"deposit_count" json:"deposit_count"`
	IsNativeToken      bool           `meddler:"is_native_token" json:"is_native_token"`
}

Bridge is the representation of a bridge event

func (*Bridge) Hash

func (b *Bridge) Hash() common.Hash

Hash returns the hash of the bridge event as expected by the exit tree Note: can't change the Hash() here after adding BlockTimestamp and TxHash. Might affect previous versions

type BridgeResponse

type BridgeResponse struct {
	BridgeHash common.Hash `json:"bridge_hash"`
	Bridge
}

BridgeResponse is the representation of a bridge event with additional fields

func NewBridgeResponse

func NewBridgeResponse(bridge *Bridge) *BridgeResponse

NewBridgeResponse creates a new BridgeResponse instance out of the provided Bridge instance

func (*BridgeResponse) MarshalJSON

func (b *BridgeResponse) MarshalJSON() ([]byte, error)

MarshalJSON for hex-encoding Metadata field

type BridgeSync

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

BridgeSync manages the state of the exit tree for the bridge contract by processing Ethereum blockchain events.

func NewL1

func NewL1(
	ctx context.Context,
	dbPath string,
	bridge common.Address,
	syncBlockChunkSize uint64,
	blockFinalityType etherman.BlockNumberFinality,
	rd ReorgDetector,
	ethClient aggkittypes.EthClienter,
	initialBlock uint64,
	waitForNewBlocksPeriod time.Duration,
	retryAfterErrorPeriod time.Duration,
	maxRetryAttemptsAfterError int,
	originNetwork uint32,
	syncFullClaims bool,
	requireStorageContentCompatibility bool,
) (*BridgeSync, error)

NewL1 creates a bridge syncer that synchronizes the mainnet exit tree

func NewL2

func NewL2(
	ctx context.Context,
	dbPath string,
	bridge common.Address,
	syncBlockChunkSize uint64,
	blockFinalityType etherman.BlockNumberFinality,
	rd ReorgDetector,
	ethClient aggkittypes.EthClienter,
	initialBlock uint64,
	waitForNewBlocksPeriod time.Duration,
	retryAfterErrorPeriod time.Duration,
	maxRetryAttemptsAfterError int,
	originNetwork uint32,
	syncFullClaims bool,
	requireStorageContentCompatibility bool,
) (*BridgeSync, error)

NewL2 creates a bridge syncer that synchronizes the local exit tree

func (*BridgeSync) BlockFinality

func (s *BridgeSync) BlockFinality() etherman.BlockNumberFinality

BlockFinality returns the block finality type

func (*BridgeSync) GetBlockByLER

func (s *BridgeSync) GetBlockByLER(ctx context.Context, ler common.Hash) (uint64, error)

func (*BridgeSync) GetBridgeRootByHash

func (s *BridgeSync) GetBridgeRootByHash(ctx context.Context, root common.Hash) (*tree.Root, error)

func (*BridgeSync) GetBridges

func (s *BridgeSync) GetBridges(ctx context.Context, fromBlock, toBlock uint64) ([]Bridge, error)

func (*BridgeSync) GetBridgesPaged added in v0.5.1

func (s *BridgeSync) GetBridgesPaged(
	ctx context.Context,
	page, pageSize uint32,
	depositCount *uint64, networkIDs []uint32) ([]*BridgeResponse, int, error)

func (*BridgeSync) GetClaims

func (s *BridgeSync) GetClaims(ctx context.Context, fromBlock, toBlock uint64) ([]Claim, error)

func (*BridgeSync) GetClaimsPaged added in v0.5.1

func (s *BridgeSync) GetClaimsPaged(
	ctx context.Context,
	page, pageSize uint32, networkIDs []uint32) ([]*ClaimResponse, int, error)

func (*BridgeSync) GetExitRootByIndex

func (s *BridgeSync) GetExitRootByIndex(ctx context.Context, index uint32) (tree.Root, error)

GetExitRootByIndex returns the root of the exit tree at the moment the leaf with the given index was added

func (*BridgeSync) GetLastProcessedBlock

func (s *BridgeSync) GetLastProcessedBlock(ctx context.Context) (uint64, error)

func (*BridgeSync) GetLastReorgEvent added in v0.5.1

func (s *BridgeSync) GetLastReorgEvent(ctx context.Context) (*LastReorg, error)

func (*BridgeSync) GetLegacyTokenMigrations added in v0.5.1

func (s *BridgeSync) GetLegacyTokenMigrations(
	ctx context.Context, pageNumber, pageSize uint32) ([]*LegacyTokenMigration, int, error)

func (*BridgeSync) GetProof

func (s *BridgeSync) GetProof(ctx context.Context, depositCount uint32, localExitRoot common.Hash) (tree.Proof, error)

func (*BridgeSync) GetRootByLER

func (s *BridgeSync) GetRootByLER(ctx context.Context, ler common.Hash) (*tree.Root, error)

func (*BridgeSync) GetTokenMappings added in v0.5.1

func (s *BridgeSync) GetTokenMappings(ctx context.Context, pageNumber, pageSize uint32) ([]*TokenMapping, int, error)

func (*BridgeSync) OriginNetwork

func (s *BridgeSync) OriginNetwork() uint32

OriginNetwork returns the network ID of the origin chain

func (*BridgeSync) Start

func (s *BridgeSync) Start(ctx context.Context)

Start starts the synchronization process

type BridgeSyncerType added in v0.5.1

type BridgeSyncerType int

BridgeSyncerType represents the type of bridge syncer

const (
	L1BridgeSyncer BridgeSyncerType = iota
	L2BridgeSyncer
)

func (BridgeSyncerType) String added in v0.5.1

func (b BridgeSyncerType) String() string

type Claim

type Claim struct {
	BlockNum            uint64         `meddler:"block_num"`
	BlockPos            uint64         `meddler:"block_pos"`
	FromAddress         common.Address `meddler:"from_address,address"`
	TxHash              common.Hash    `meddler:"tx_hash,hash"`
	GlobalIndex         *big.Int       `meddler:"global_index,bigint"`
	OriginNetwork       uint32         `meddler:"origin_network"`
	OriginAddress       common.Address `meddler:"origin_address"`
	DestinationAddress  common.Address `meddler:"destination_address"`
	Amount              *big.Int       `meddler:"amount,bigint"`
	ProofLocalExitRoot  types.Proof    `meddler:"proof_local_exit_root,merkleproof"`
	ProofRollupExitRoot types.Proof    `meddler:"proof_rollup_exit_root,merkleproof"`
	MainnetExitRoot     common.Hash    `meddler:"mainnet_exit_root,hash"`
	RollupExitRoot      common.Hash    `meddler:"rollup_exit_root,hash"`
	GlobalExitRoot      common.Hash    `meddler:"global_exit_root,hash"`
	DestinationNetwork  uint32         `meddler:"destination_network"`
	Metadata            []byte         `meddler:"metadata"`
	IsMessage           bool           `meddler:"is_message"`
	BlockTimestamp      uint64         `meddler:"block_timestamp"`
}

Claim representation of a claim event

type ClaimResponse

type ClaimResponse struct {
	BlockNum           uint64         `json:"block_num"`
	BlockTimestamp     uint64         `json:"block_timestamp"`
	TxHash             common.Hash    `json:"tx_hash"`
	GlobalIndex        *big.Int       `json:"global_index"`
	OriginAddress      common.Address `json:"origin_address"`
	OriginNetwork      uint32         `json:"origin_network"`
	DestinationAddress common.Address `json:"destination_address"`
	DestinationNetwork uint32         `json:"destination_network"`
	Amount             *big.Int       `json:"amount"`
	FromAddress        common.Address `json:"from_address"`
}

ClaimResponse is the representation of a claim event with trimmed fields

func NewClaimResponse

func NewClaimResponse(claim *Claim) *ClaimResponse

NewClaimResponse creates ClaimResponse instance out of the provided Claim

type Config

type Config struct {
	// 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 string `` //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 bellow the creation of the bridge contract
	InitialBlockNum uint64 `mapstructure:"InitialBlockNum"`
	// BridgeAddr is the address of the bridge smart contract
	BridgeAddr common.Address `mapstructure:"BridgeAddr"`
	// 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 panicing.
	// 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"`
}

type Event

type Event struct {
	Pos                  uint64
	Bridge               *Bridge
	Claim                *Claim
	TokenMapping         *TokenMapping
	LegacyTokenMigration *LegacyTokenMigration
	RemoveLegacyToken    *RemoveLegacyToken
}

Event combination of bridge, claim, token mapping and legacy token migration events

type LastReorg added in v0.5.1

type LastReorg struct {
	DetectedAt int64  `json:"detected_at"`
	FromBlock  uint64 `json:"from_block"`
	ToBlock    uint64 `json:"to_block"`
}

type LegacyTokenMigration added in v0.5.1

type LegacyTokenMigration struct {
	BlockNum            uint64         `meddler:"block_num" json:"block_num"`
	BlockPos            uint64         `meddler:"block_pos" json:"block_pos"`
	BlockTimestamp      uint64         `meddler:"block_timestamp" json:"block_timestamp"`
	TxHash              common.Hash    `meddler:"tx_hash,hash" json:"tx_hash"`
	Sender              common.Address `meddler:"sender,address" json:"sender"`
	LegacyTokenAddress  common.Address `meddler:"legacy_token_address,address" json:"legacy_token_address"`
	UpdatedTokenAddress common.Address `meddler:"updated_token_address,address" json:"updated_token_address"`
	Amount              *big.Int       `meddler:"amount,bigint" json:"amount"`
	Calldata            []byte         `meddler:"calldata" json:"calldata"`
}

LegacyTokenMigration representation of a MigrateLegacyToken event, that is emitted by the sovereign chain bridge contract.

type RemoveLegacyToken added in v0.5.1

type RemoveLegacyToken struct {
	BlockNum           uint64         `meddler:"block_num" json:"block_num"`
	BlockPos           uint64         `meddler:"block_pos" json:"block_pos"`
	BlockTimestamp     uint64         `meddler:"block_timestamp" json:"block_timestamp"`
	TxHash             common.Hash    `meddler:"tx_hash,hash" json:"tx_hash"`
	LegacyTokenAddress common.Address `meddler:"legacy_token_address,address" json:"legacy_token_address"`
}

RemoveLegacyToken representation of a RemoveLegacySovereignTokenAddress event, that is emitted by the sovereign chain bridge contract.

type ReorgDetector

type ReorgDetector interface {
	sync.ReorgDetector
	GetLastReorgEvent(ctx context.Context) (reorgdetector.ReorgEvent, error)
}

type TokenMapping added in v0.5.1

type TokenMapping struct {
	BlockNum            uint64           `meddler:"block_num" json:"block_num"`
	BlockPos            uint64           `meddler:"block_pos" json:"block_pos"`
	BlockTimestamp      uint64           `meddler:"block_timestamp" json:"block_timestamp"`
	TxHash              common.Hash      `meddler:"tx_hash,hash" json:"tx_hash"`
	OriginNetwork       uint32           `meddler:"origin_network" json:"origin_network"`
	OriginTokenAddress  common.Address   `meddler:"origin_token_address,address" json:"origin_token_address"`
	WrappedTokenAddress common.Address   `meddler:"wrapped_token_address,address" json:"wrapped_token_address"`
	Metadata            []byte           `meddler:"metadata" json:"metadata"`
	IsNotMintable       bool             `meddler:"is_not_mintable" json:"is_not_mintable"`
	Calldata            []byte           `meddler:"calldata" json:"calldata"`
	Type                TokenMappingType `meddler:"token_type" json:"token_type"`
}

TokenMapping representation of a NewWrappedToken event, that is emitted by the bridge contract

func (*TokenMapping) MarshalJSON

func (t *TokenMapping) MarshalJSON() ([]byte, error)

MarshalJSON for hex-encoding Metadata and Calldata fields

type TokenMappingType

type TokenMappingType uint8

func (TokenMappingType) String

func (l TokenMappingType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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