Documentation
¶
Index ¶
- func BalanceChanges(ctx context.Context, asserter *asserter.Asserter, block *types.Block, ...) ([]*storage.BalanceChange, error)
- func NextSyncableRange(ctx context.Context, s Syncer, endIndex int64) (int64, int64, bool, error)
- func Sync(ctx context.Context, cancel context.CancelFunc, s Syncer, startIndex int64, ...) error
- type BaseHandler
- type Handler
- type StatefulSyncer
- func (s *StatefulSyncer) CurrentIndex(ctx context.Context) (int64, error)
- func (s *StatefulSyncer) Fetcher(ctx context.Context) *fetcher.Fetcher
- func (s *StatefulSyncer) Network(ctx context.Context) *types.NetworkIdentifier
- func (s *StatefulSyncer) SetStartIndex(ctx context.Context, startIndex int64) error
- func (s *StatefulSyncer) SyncRange(ctx context.Context, startIndex int64, endIndex int64) error
- type StatelessSyncer
- func (s *StatelessSyncer) CurrentIndex(ctx context.Context) (int64, error)
- func (s *StatelessSyncer) Fetcher(ctx context.Context) *fetcher.Fetcher
- func (s *StatelessSyncer) Network(ctx context.Context) *types.NetworkIdentifier
- func (s *StatelessSyncer) SetStartIndex(ctx context.Context, startIndex int64) error
- func (s *StatelessSyncer) SyncRange(ctx context.Context, startIndex int64, endIndex int64) error
- type Syncer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BalanceChanges ¶
func BalanceChanges( ctx context.Context, asserter *asserter.Asserter, block *types.Block, orphan bool, ) ([]*storage.BalanceChange, error)
BalanceChanges returns all balance changes for a particular block. All balance changes for a particular account are summed into a single storage.BalanceChanges struct. If a block is being orphaned, the opposite of each balance change is returned.
Types ¶
type BaseHandler ¶
type BaseHandler struct {
// contains filtered or unexported fields
}
BaseHandler logs processed blocks and reconciles modified balances.
func (*BaseHandler) BlockProcessed ¶
func (h *BaseHandler) BlockProcessed( ctx context.Context, block *types.Block, reorg bool, balanceChanges []*storage.BalanceChange, ) error
BlockProcessed is called by the syncer after each block is processed. TODO: refactor to BlockAdded and BlockRemoved
type Handler ¶
type Handler interface {
// TODO: change to BlockAdded and BlockRemoved
BlockProcessed(
ctx context.Context,
block *types.Block,
orphan bool,
changes []*storage.BalanceChange,
) error
}
Handler is called at various times during the sync cycle to handle different events. It is common to write logs or perform reconciliation in the sync handler.
func NewBaseHandler ¶
func NewBaseHandler( logger *logger.Logger, reconciler reconciler.Reconciler, ) Handler
NewBaseHandler constructs a basic Handler.
type StatefulSyncer ¶
type StatefulSyncer struct {
// contains filtered or unexported fields
}
StatefulSyncer contains the logic that orchestrates block fetching, storage, and reconciliation. The stateful syncer is useful for creating an application where durability and consistency of data is important. The stateful syncer supports re-orgs out-of the box.
func NewStateful ¶
func NewStateful( network *types.NetworkIdentifier, storage *storage.BlockStorage, fetcher *fetcher.Fetcher, handler Handler, ) *StatefulSyncer
NewStateful returns a new Syncer.
func (*StatefulSyncer) CurrentIndex ¶
func (s *StatefulSyncer) CurrentIndex( ctx context.Context, ) (int64, error)
CurrentIndex returns the next index to sync.
func (*StatefulSyncer) Fetcher ¶
func (s *StatefulSyncer) Fetcher( ctx context.Context, ) *fetcher.Fetcher
Fetcher returns the syncer fetcher.
func (*StatefulSyncer) Network ¶
func (s *StatefulSyncer) Network( ctx context.Context, ) *types.NetworkIdentifier
Network returns the syncer network.
func (*StatefulSyncer) SetStartIndex ¶
func (s *StatefulSyncer) SetStartIndex( ctx context.Context, startIndex int64, ) error
SetStartIndex initializes the genesisBlock and attempts to set the newHeadIndex.
type StatelessSyncer ¶
type StatelessSyncer struct {
// contains filtered or unexported fields
}
StatelessSyncer contains the logic that orchestrates stateless block fetching and reconciliation. The stateless syncer is useful for performing a quick check over a range of blocks without needed to sync all blocks up to the start of the range (a common pattern when debugging). It is important to note that the stateless syncer does not support reorgs nor does it save where it is on restart.
func NewStateless ¶
func NewStateless( network *types.NetworkIdentifier, fetcher *fetcher.Fetcher, handler Handler, ) *StatelessSyncer
NewStateless returns a new Syncer.
func (*StatelessSyncer) CurrentIndex ¶
func (s *StatelessSyncer) CurrentIndex( ctx context.Context, ) (int64, error)
CurrentIndex returns the next index to sync.
func (*StatelessSyncer) Fetcher ¶
func (s *StatelessSyncer) Fetcher( ctx context.Context, ) *fetcher.Fetcher
Fetcher returns the syncer fetcher.
func (*StatelessSyncer) Network ¶
func (s *StatelessSyncer) Network( ctx context.Context, ) *types.NetworkIdentifier
Network returns the syncer network.
func (*StatelessSyncer) SetStartIndex ¶
func (s *StatelessSyncer) SetStartIndex( ctx context.Context, startIndex int64, ) error
SetStartIndex initializes the current block index with the genesis block index if it is -1.
type Syncer ¶
type Syncer interface {
SetStartIndex(
ctx context.Context,
startIndex int64,
) error
CurrentIndex(
ctx context.Context,
) (int64, error)
SyncRange(
ctx context.Context,
rangeStart int64,
rangeEnd int64,
) error
Network(
ctx context.Context,
) *types.NetworkIdentifier
Fetcher(
ctx context.Context,
) *fetcher.Fetcher
}
Syncer defines an interface for syncing some range of blocks.