bridge

package
v1.9.7-0...-ba03429 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: LGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APIVersion = &typesproto.VersionReply{Major: 1, Minor: 0, Patch: 0}

Functions

func NewStateSyncEventMessages

func NewStateSyncEventMessages(stateSyncEvents []rlp.RawValue, stateReceiverContract *libcommon.Address, gasLimit uint64) []*types.Message

NewStateSyncEventMessages creates a corresponding message that can be passed to EVM for multiple state sync events

func NewTxStore

func NewTxStore(tx kv.Tx) txStore

func UnwindBlockNumToEventID

func UnwindBlockNumToEventID(tx kv.RwTx, blockNum uint64) error

UnwindBlockNumToEventID deletes data in kv.BorEventProcessedBlocks. The blockNum parameter is exclusive, i.e. only data in the range (blockNum, last] is deleted.

func UnwindEventProcessedBlocks

func UnwindEventProcessedBlocks(tx kv.RwTx, blockNum uint64) error

UnwindEventProcessedBlocks deletes data in kv.BorEventProcessedBlocks. The blockNum parameter is exclusive, i.e. only data in the range (blockNum, last] is deleted.

func UnwindEventTxnToBlockNum

func UnwindEventTxnToBlockNum(tx kv.RwTx, blockNum uint64) error

UnwindEventTxnToBlockNum deletes data in kv.BorTxLookup. The blockNum parameter is exclusive, i.e. only data in the range (blockNum, last] is deleted.

func UnwindEvents

func UnwindEvents(tx kv.RwTx, unwindPoint uint64) error

Types

type BackendServer

type BackendServer struct {
	remoteproto.UnimplementedBridgeBackendServer // must be embedded to have forward compatible implementations.
	// contains filtered or unexported fields
}

func NewBackendServer

func NewBackendServer(ctx context.Context, bridgeReader bridgeReader) *BackendServer

func (*BackendServer) BorEvents

func (*BackendServer) BorTxnLookup

func (*BackendServer) Version

type MdbxStore

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

func NewDbStore

func NewDbStore(db kv.RoDB) *MdbxStore

func NewMdbxStore

func NewMdbxStore(dataDir string, logger log.Logger, accede bool, roTxLimit int64) *MdbxStore

func (*MdbxStore) BlockEventIdsRange

func (s *MdbxStore) BlockEventIdsRange(ctx context.Context, blockNum uint64) (uint64, uint64, bool, error)

BlockEventIdsRange returns the [start, end] event Id for the given block number If the given block number is the first in the database, then the first uint64 (representing start Id) is 0.

func (*MdbxStore) BorStartEventId

func (s *MdbxStore) BorStartEventId(ctx context.Context, hash libcommon.Hash, blockHeight uint64) (uint64, error)

func (*MdbxStore) Close

func (s *MdbxStore) Close()

func (*MdbxStore) EventTxnToBlockNum

func (s *MdbxStore) EventTxnToBlockNum(ctx context.Context, borTxHash libcommon.Hash) (uint64, bool, error)

func (*MdbxStore) Events

func (s *MdbxStore) Events(ctx context.Context, start, end uint64) ([][]byte, error)

Events gets raw events, start inclusive, end exclusive

func (*MdbxStore) EventsByBlock

func (s *MdbxStore) EventsByBlock(ctx context.Context, hash libcommon.Hash, blockHeight uint64) ([]rlp.RawValue, error)

func (*MdbxStore) EventsByIdFromSnapshot

func (s *MdbxStore) EventsByIdFromSnapshot(from uint64, to time.Time, limit int) ([]*heimdall.EventRecordWithTime, bool, error)

func (*MdbxStore) LastEventId

func (s *MdbxStore) LastEventId(ctx context.Context) (uint64, error)

LastEventId the latest state sync event Id in given DB, 0 if DB is empty NOTE: Polygon sync events start at index 1

func (*MdbxStore) LastEventIdWithinWindow

func (s *MdbxStore) LastEventIdWithinWindow(ctx context.Context, fromId uint64, toTime time.Time) (uint64, error)

LastEventIdWithinWindow gets the last event id where event.Id >= fromId and event.Time < toTime.

func (*MdbxStore) LastFrozenEventBlockNum

func (s *MdbxStore) LastFrozenEventBlockNum() uint64

func (*MdbxStore) LastFrozenEventId

func (s *MdbxStore) LastFrozenEventId() uint64

func (*MdbxStore) LastProcessedBlockInfo

func (s *MdbxStore) LastProcessedBlockInfo(ctx context.Context) (ProcessedBlockInfo, bool, error)

func (*MdbxStore) LastProcessedEventId

func (s *MdbxStore) LastProcessedEventId(ctx context.Context) (uint64, error)

LastProcessedEventId gets the last seen event Id in the BorEventNums table

func (*MdbxStore) Prepare

func (s *MdbxStore) Prepare(ctx context.Context) error

func (*MdbxStore) PruneEvents

func (s *MdbxStore) PruneEvents(ctx context.Context, blocksTo uint64, blocksDeleteLimit int) (deleted int, err error)

func (*MdbxStore) PutBlockNumToEventId

func (s *MdbxStore) PutBlockNumToEventId(ctx context.Context, blockNumToEventId map[uint64]uint64) error

func (*MdbxStore) PutEventTxnToBlockNum

func (s *MdbxStore) PutEventTxnToBlockNum(ctx context.Context, eventTxnToBlockNum map[libcommon.Hash]uint64) error

func (*MdbxStore) PutEvents

func (s *MdbxStore) PutEvents(ctx context.Context, events []*heimdall.EventRecordWithTime) error

func (*MdbxStore) PutProcessedBlockInfo

func (s *MdbxStore) PutProcessedBlockInfo(ctx context.Context, info []ProcessedBlockInfo) error

func (*MdbxStore) RangeExtractor

func (s *MdbxStore) RangeExtractor() snaptype.RangeExtractor

func (*MdbxStore) Unwind

func (s *MdbxStore) Unwind(ctx context.Context, blockNum uint64) error

func (*MdbxStore) WithTx

func (s *MdbxStore) WithTx(tx kv.Tx) Store

type ProcessedBlockInfo

type ProcessedBlockInfo struct {
	BlockNum  uint64
	BlockTime uint64
}

func (*ProcessedBlockInfo) MarshallBytes

func (info *ProcessedBlockInfo) MarshallBytes() (key []byte, value []byte)

func (*ProcessedBlockInfo) UnmarshallBytes

func (info *ProcessedBlockInfo) UnmarshallBytes(key []byte, value []byte)

type Reader

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

func AssembleReader

func AssembleReader(ctx context.Context, config ReaderConfig) (*Reader, error)

func NewReader

func NewReader(store Store, logger log.Logger, stateReceiverContractAddress libcommon.Address) *Reader

func (*Reader) Close

func (r *Reader) Close()

func (*Reader) EventTxnLookup

func (r *Reader) EventTxnLookup(ctx context.Context, borTxHash libcommon.Hash) (uint64, bool, error)

func (*Reader) Events

func (r *Reader) Events(ctx context.Context, blockNum uint64) ([]*types.Message, error)

Events returns all sync events at blockNum

func (*Reader) Prepare

func (r *Reader) Prepare(ctx context.Context) error

type ReaderConfig

type ReaderConfig struct {
	Store                        Store
	Logger                       log.Logger
	StateReceiverContractAddress libcommon.Address
	RoTxLimit                    int64
}

type RemoteReader

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

func NewRemoteReader

func NewRemoteReader(client remote.BridgeBackendClient) *RemoteReader

func (*RemoteReader) Close

func (r *RemoteReader) Close()

func (*RemoteReader) EnsureVersionCompatibility

func (r *RemoteReader) EnsureVersionCompatibility() bool

func (*RemoteReader) EventTxnLookup

func (r *RemoteReader) EventTxnLookup(ctx context.Context, borTxHash libcommon.Hash) (uint64, bool, error)

func (*RemoteReader) Events

func (r *RemoteReader) Events(ctx context.Context, blockNum uint64) ([]*types.Message, error)

type Service

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

func NewService

func NewService(config ServiceConfig) *Service

func (*Service) Close

func (s *Service) Close()

func (*Service) EventTxnLookup

func (s *Service) EventTxnLookup(ctx context.Context, borTxHash libcommon.Hash) (uint64, bool, error)

func (*Service) Events

func (s *Service) Events(ctx context.Context, blockNum uint64) ([]*types.Message, error)

Events returns all sync events at blockNum

func (*Service) InitialBlockReplayNeeded

func (s *Service) InitialBlockReplayNeeded(ctx context.Context) (uint64, bool, error)

func (*Service) ProcessNewBlocks

func (s *Service) ProcessNewBlocks(ctx context.Context, blocks []*types.Block) error

ProcessNewBlocks iterates through all blocks and constructs a map from block number to sync events

func (*Service) Ready

func (s *Service) Ready(ctx context.Context) <-chan error

func (*Service) ReplayInitialBlock

func (s *Service) ReplayInitialBlock(ctx context.Context, block *types.Block) error

func (*Service) Run

func (s *Service) Run(ctx context.Context) error

func (*Service) Synchronize

func (s *Service) Synchronize(ctx context.Context, blockNum uint64) error

Synchronize blocks until events up to a given block are processed.

func (*Service) Unwind

func (s *Service) Unwind(ctx context.Context, blockNum uint64) error

Unwind delete unwindable bridge data. The blockNum parameter is exclusive, i.e. only data in the range (blockNum, last] is deleted.

type ServiceConfig

type ServiceConfig struct {
	Store        Store
	Logger       log.Logger
	BorConfig    *borcfg.BorConfig
	EventFetcher eventFetcher
}

type SnapshotStore

type SnapshotStore struct {
	Store
	// contains filtered or unexported fields
}

func NewSnapshotStore

func NewSnapshotStore(base Store, snapshots *heimdall.RoSnapshots, sprintLengthCalculator sprintLengthCalculator) *SnapshotStore

func (*SnapshotStore) BlockEventIdsRange

func (s *SnapshotStore) BlockEventIdsRange(ctx context.Context, blockNum uint64) (uint64, uint64, bool, error)

func (*SnapshotStore) BorStartEventId

func (s *SnapshotStore) BorStartEventId(ctx context.Context, hash libcommon.Hash, blockHeight uint64) (uint64, error)

func (*SnapshotStore) EventTxnToBlockNum

func (s *SnapshotStore) EventTxnToBlockNum(ctx context.Context, txnHash libcommon.Hash) (uint64, bool, error)

func (*SnapshotStore) Events

func (s *SnapshotStore) Events(ctx context.Context, start, end uint64) ([][]byte, error)

func (*SnapshotStore) EventsByBlock

func (s *SnapshotStore) EventsByBlock(ctx context.Context, hash libcommon.Hash, blockHeight uint64) ([]rlp.RawValue, error)

func (*SnapshotStore) EventsByIdFromSnapshot

func (s *SnapshotStore) EventsByIdFromSnapshot(from uint64, to time.Time, limit int) ([]*heimdall.EventRecordWithTime, bool, error)

EventsByIdFromSnapshot returns the list of records limited by time, or the number of records along with a bool value to signify if the records were limited by time

func (*SnapshotStore) LastEventId

func (s *SnapshotStore) LastEventId(ctx context.Context) (uint64, error)

func (*SnapshotStore) LastFrozenEventBlockNum

func (s *SnapshotStore) LastFrozenEventBlockNum() uint64

func (*SnapshotStore) LastFrozenEventId

func (s *SnapshotStore) LastFrozenEventId() uint64

func (*SnapshotStore) LastProcessedBlockInfo

func (s *SnapshotStore) LastProcessedBlockInfo(ctx context.Context) (ProcessedBlockInfo, bool, error)

func (*SnapshotStore) LastProcessedEventId

func (s *SnapshotStore) LastProcessedEventId(ctx context.Context) (uint64, error)

func (*SnapshotStore) Prepare

func (s *SnapshotStore) Prepare(ctx context.Context) error

func (*SnapshotStore) RangeExtractor

func (s *SnapshotStore) RangeExtractor() snaptype.RangeExtractor

func (*SnapshotStore) WithTx

func (s *SnapshotStore) WithTx(tx kv.Tx) Store

type Store

type Store interface {
	Prepare(ctx context.Context) error
	Close()

	LastEventId(ctx context.Context) (uint64, error)
	LastEventIdWithinWindow(ctx context.Context, fromID uint64, toTime time.Time) (uint64, error)
	LastProcessedEventId(ctx context.Context) (uint64, error)
	LastProcessedBlockInfo(ctx context.Context) (ProcessedBlockInfo, bool, error)
	LastFrozenEventId() uint64
	LastFrozenEventBlockNum() uint64

	EventTxnToBlockNum(ctx context.Context, borTxHash libcommon.Hash) (uint64, bool, error)
	Events(ctx context.Context, start, end uint64) ([][]byte, error)
	BlockEventIdsRange(ctx context.Context, blockNum uint64) (start uint64, end uint64, ok bool, err error) // [start,end)

	PutEventTxnToBlockNum(ctx context.Context, eventTxnToBlockNum map[libcommon.Hash]uint64) error
	PutEvents(ctx context.Context, events []*heimdall.EventRecordWithTime) error
	PutBlockNumToEventId(ctx context.Context, blockNumToEventId map[uint64]uint64) error
	PutProcessedBlockInfo(ctx context.Context, info []ProcessedBlockInfo) error

	Unwind(ctx context.Context, blockNum uint64) error

	// block reader compatibility
	BorStartEventId(ctx context.Context, hash libcommon.Hash, blockHeight uint64) (uint64, error)
	EventsByBlock(ctx context.Context, hash libcommon.Hash, blockNum uint64) ([]rlp.RawValue, error)
	EventsByIdFromSnapshot(from uint64, to time.Time, limit int) ([]*heimdall.EventRecordWithTime, bool, error)
	PruneEvents(ctx context.Context, blocksTo uint64, blocksDeleteLimit int) (deleted int, err error)
}

Jump to

Keyboard shortcuts

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