Documentation
¶
Index ¶
- func NewBroadcaster(orm ORM, ethClient eth.Client, config Config, highestSavedHead *models.Head) *broadcaster
- func NewORM(db *gorm.DB) *orm
- type Broadcast
- type Broadcaster
- type Config
- type JobIdSelect
- type Listener
- type ListenerOpts
- type LogBroadcast
- type LogBroadcastAsKey
- type NullBroadcaster
- func (n *NullBroadcaster) AddDependents(int)
- func (n *NullBroadcaster) AwaitDependents() <-chan struct{}
- func (n *NullBroadcaster) Close() error
- func (n *NullBroadcaster) Connect(*models.Head) error
- func (n *NullBroadcaster) DependentReady()
- func (n *NullBroadcaster) Healthy() error
- func (n *NullBroadcaster) IsConnected() bool
- func (n *NullBroadcaster) LatestHead() *models.Head
- func (n *NullBroadcaster) MarkConsumed(db *gorm.DB, lb Broadcast) error
- func (n *NullBroadcaster) OnNewLongestChain(context.Context, models.Head)
- func (n *NullBroadcaster) Ready() error
- func (n *NullBroadcaster) Register(listener Listener, opts ListenerOpts) (unsubscribe func())
- func (n *NullBroadcaster) Start() error
- func (n *NullBroadcaster) TrackedAddressesCount() uint32
- func (n *NullBroadcaster) WasAlreadyConsumed(db *gorm.DB, lb Broadcast) (bool, error)
- type ORM
- type ParseLogFunc
- type Topic
- type Uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Broadcast ¶
type Broadcast interface {
DecodedLog() interface{}
RawLog() types.Log
SetDecodedLog(interface{})
String() string
LatestBlockNumber() uint64
LatestBlockHash() common.Hash
JobID() JobIdSelect
}
The Broadcast type wraps a types.Log but provides additional functionality for determining whether or not the log has been consumed and for marking the log as consumed
func NewLogBroadcast ¶ added in v0.10.8
type Broadcaster ¶
type Broadcaster interface {
utils.DependentAwaiter
service.Service
httypes.HeadTrackable
IsConnected() bool
Register(listener Listener, opts ListenerOpts) (unsubscribe func())
LatestHead() *models.Head
TrackedAddressesCount() uint32
// DB interactions
WasAlreadyConsumed(db *gorm.DB, lb Broadcast) (bool, error)
MarkConsumed(db *gorm.DB, lb Broadcast) error
}
The Broadcaster manages log subscription requests for the Chainlink node. Instead of creating a new subscription for each request, it multiplexes all subscriptions to all of the relevant contracts over a single connection and forwards the logs to the relevant subscribers.
In case of node crash and/or restart, the logs will be backfilled from the latest head from DB, for subscribers that are added before all dependents of LogBroadcaster are done.
If a subscriber is added after the LogBroadcaster does the initial backfill, then it's possible/likely that the backfill fill only have depth: 1 (from latest head)
Of course, these backfilled logs + any new logs will only be sent after the NumConfirmations for given subscriber.
type JobIdSelect ¶ added in v0.10.10
func NewJobIdFromListener ¶ added in v0.10.10
func NewJobIdFromListener(listener Listener) JobIdSelect
func NewJobIdV1 ¶ added in v0.10.10
func NewJobIdV1(id models.JobID) JobIdSelect
func NewJobIdV2 ¶ added in v0.10.10
func NewJobIdV2(id int32) JobIdSelect
func (JobIdSelect) String ¶ added in v0.10.10
func (j JobIdSelect) String() string
type Listener ¶
type Listener interface {
HandleLog(b Broadcast)
JobID() models.JobID
JobIDV2() int32
IsV2Job() bool
}
The Listener responds to log events through HandleLog.
type ListenerOpts ¶ added in v0.10.3
type ListenerOpts struct {
Contract common.Address
// Event types to receive, with value filter for each field in the event
// No filter or an empty filter for a given field position mean: all values allowed
// the key should be a result of AbigenLog.Topic() call
LogsWithTopics map[common.Hash][][]Topic
ParseLog ParseLogFunc
// Minimum number of block confirmations before the log is received
NumConfirmations uint64
}
type LogBroadcast ¶ added in v0.10.10
type LogBroadcast struct {
BlockHash common.Hash
LogIndex uint
JobId models.JobID
JobIdV2 null.Int64
}
LogBroadcast - gorm-compatible receive data from log_broadcasts table columns
func (LogBroadcast) AsKey ¶ added in v0.10.10
func (b LogBroadcast) AsKey() LogBroadcastAsKey
func (LogBroadcast) JobID ¶ added in v0.10.10
func (b LogBroadcast) JobID() JobIdSelect
type LogBroadcastAsKey ¶ added in v0.10.10
LogBroadcastAsKey - used as key in a map to filter out already consumed logs
func NewLogBroadcastAsKey ¶ added in v0.10.10
func NewLogBroadcastAsKey(log types.Log, listener Listener) LogBroadcastAsKey
type NullBroadcaster ¶ added in v0.10.8
type NullBroadcaster struct{ ErrMsg string }
func (*NullBroadcaster) AddDependents ¶ added in v0.10.8
func (n *NullBroadcaster) AddDependents(int)
func (*NullBroadcaster) AwaitDependents ¶ added in v0.10.8
func (n *NullBroadcaster) AwaitDependents() <-chan struct{}
func (*NullBroadcaster) Close ¶ added in v0.10.8
func (n *NullBroadcaster) Close() error
func (*NullBroadcaster) Connect ¶ added in v0.10.8
func (n *NullBroadcaster) Connect(*models.Head) error
func (*NullBroadcaster) DependentReady ¶ added in v0.10.8
func (n *NullBroadcaster) DependentReady()
func (*NullBroadcaster) Healthy ¶ added in v0.10.8
func (n *NullBroadcaster) Healthy() error
func (*NullBroadcaster) IsConnected ¶ added in v0.10.8
func (n *NullBroadcaster) IsConnected() bool
func (*NullBroadcaster) LatestHead ¶ added in v0.10.8
func (n *NullBroadcaster) LatestHead() *models.Head
func (*NullBroadcaster) MarkConsumed ¶ added in v0.10.8
func (n *NullBroadcaster) MarkConsumed(db *gorm.DB, lb Broadcast) error
func (*NullBroadcaster) OnNewLongestChain ¶ added in v0.10.8
func (n *NullBroadcaster) OnNewLongestChain(context.Context, models.Head)
func (*NullBroadcaster) Ready ¶ added in v0.10.8
func (n *NullBroadcaster) Ready() error
func (*NullBroadcaster) Register ¶ added in v0.10.8
func (n *NullBroadcaster) Register(listener Listener, opts ListenerOpts) (unsubscribe func())
func (*NullBroadcaster) Start ¶ added in v0.10.8
func (n *NullBroadcaster) Start() error
func (*NullBroadcaster) TrackedAddressesCount ¶ added in v0.10.8
func (n *NullBroadcaster) TrackedAddressesCount() uint32
func (*NullBroadcaster) WasAlreadyConsumed ¶ added in v0.10.8
type ORM ¶ added in v0.10.3
type ORM interface {
FindConsumedLogs(fromBlockNum int64, toBlockNum int64) ([]LogBroadcast, error)
WasBroadcastConsumed(tx *gorm.DB, blockHash common.Hash, logIndex uint, jobID JobIdSelect) (bool, error)
MarkBroadcastConsumed(tx *gorm.DB, blockHash common.Hash, blockNumber uint64, logIndex uint, jobID JobIdSelect) error
}