Skip to content

Commit

Permalink
Rename MaxBacklogSize to NumOfBlocksToReconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Sep 29, 2023
1 parent 283da78 commit e88ac4d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Event Tracker can be used to monitor, track, and analyze events emitted by smart
"pollTime": "2s",
"syncBatchSize": 10,
"numBlockConfirmations": 5,
"maxBacklogSize": 10000,
"numOfBlocksToReconcile": 10000,
"logFilter": [
{
"0xContractAddress": ["EventSig1", "EventSig2"]
Expand All @@ -78,7 +78,7 @@ Event Tracker can be used to monitor, track, and analyze events emitted by smart
Our recommendations are:
- `NumBlockConfirmations` - set this to the number of blocks you feel are enough to consider a block final on the tracked chain (where he will not be replaced in a reorg).
- `SyncBatchSize` - should be connected to the configured NumBlockConfirmations. For example, if the NumBlockConfirmations is 10, batch size should be around 25, meaning that while syncing one batch, you will have at least half of confirmed numbers in it, and tracker can process events from them as he syncs up with the tracked chain.
- `MaxBacklogSize` - should be configured in regards to the business logic for which you are using the tracker. If it is important to sync up and catch events from all confirmed missed blocks in the chain, then just leave this as 0, and tracker will sync up with every block you missed in the chain to get the desired events. If your node or application was down for a longer of period of time (days, months), and if it is not important to sync up all the events from missed blocks, configure MaxBacklogSize to be the number of latest blocks that you consider relevant for you to sync up until the latest chain block.
- `NumOfBlocksToReconcile` - should be configured in regards to the business logic for which you are using the tracker. If it is important to sync up and catch events from all confirmed missed blocks in the chain, then just leave this as 0, and tracker will sync up with every block you missed in the chain to get the desired events. If your node or application was down for a longer of period of time (days, months), and if it is not important to sync up all the events from missed blocks, configure `NumOfBlocksToReconcile` to be the number of latest blocks that you consider relevant for you to sync up until the latest chain block.
- `PollInterval` - should be configured to about the same as the block minting time on the tracked chain.
- `Logger` - you can pass your own logger here, as long as it implements the `Logger` interface from `go-hclog`.
- `Store` - you can pass your own store (as long as it implements the `EventTrackerStore` interface), or use the provided `BoltDBEventTrackerStore` from this repo, that creates and uses a `BoltDB` instance to store tracked blocks and events data.
Expand Down
10 changes: 5 additions & 5 deletions tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type EventTrackerConfig struct {
// logic with them, continuing consensus and relayer stuff.
// In order to not waste too much unnecessary time in syncing all those blocks, with NumOfBlocksToReconcile,
// we tell the tracker to sync only latestBlock.Number - NumOfBlocksToReconcile number of blocks.
NumOfBlocksToReconcile uint64 `json:"maxBacklogSize"`
NumOfBlocksToReconcile uint64 `json:"numOfBlocksToReconcile"`

// PollInterval defines a time interval in which tracker polls json rpc node
// for latest block on the tracked chain.
Expand Down Expand Up @@ -93,7 +93,7 @@ type EventTracker struct {
// StartBlockFromConfig: 100_000,
// NumBlockConfirmations: 10,
// SyncBatchSize: 20,
// MaxBacklogSize: 10_000,
// NumOfBlocksToReconcile:10_000,
// PollInterval: 2 * time.Second,
// Logger: logger,
// Store: store,
Expand Down Expand Up @@ -127,7 +127,7 @@ func NewEventTracker(config *EventTrackerConfig) (*EventTracker, error) {

if latestBlock.Number > config.NumOfBlocksToReconcile {
// if this is a fresh start, then we should start syncing from
// latestBlock.Number - MaxBacklogSize
// latestBlock.Number - NumOfBlocksToReconcile
definiteLastProcessedBlock = latestBlock.Number - config.NumOfBlocksToReconcile
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (e *EventTracker) Close() {
// Start is a method in the EventTracker struct that starts the tracking of blocks
// and retrieval of logs from given blocks from the tracked chain.
// If the tracker was turned off (node was down) for some time, it will sync up all the missed
// blocks and logs from the last start (in regards to MaxBacklogSize field in config).
// blocks and logs from the last start (in regards to NumOfBlocksToReconcile field in config).
//
// Returns:
// - nil if start passes successfully.
Expand All @@ -174,7 +174,7 @@ func (e *EventTracker) Start() error {
"numBlockConfirmations", e.config.NumBlockConfirmations,
"pollInterval", e.config.PollInterval,
"syncBatchSize", e.config.SyncBatchSize,
"maxBacklogSize", e.config.NumOfBlocksToReconcile,
"numOfBlocksToReconcile", e.config.NumOfBlocksToReconcile,
"logFilter", e.config.LogFilter,
)

Expand Down
50 changes: 25 additions & 25 deletions tracker/tracker_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ import (
)

type getNewStateF struct {
Address ethgo.Address
Number uint64
LastProcessed uint64
BatchSize uint64
NumBlockConfirmations uint64
MaxBackLogSize uint64
Address ethgo.Address
Number uint64
LastProcessed uint64
BatchSize uint64
NumBlockConfirmations uint64
NumOfBlocksToReconcile uint64
}

func FuzzGetNewState(f *testing.F) {
seeds := []getNewStateF{
{
Address: ethgo.BytesToAddress([]byte{1}),
Number: 25,
LastProcessed: 9,
BatchSize: 5,
NumBlockConfirmations: 3,
MaxBackLogSize: 1000,
Address: ethgo.BytesToAddress([]byte{1}),
Number: 25,
LastProcessed: 9,
BatchSize: 5,
NumBlockConfirmations: 3,
NumOfBlocksToReconcile: 1000,
},
{
Address: ethgo.BytesToAddress([]byte{1}),
Number: 30,
LastProcessed: 29,
BatchSize: 5,
NumBlockConfirmations: 3,
MaxBackLogSize: 1000,
Address: ethgo.BytesToAddress([]byte{1}),
Number: 30,
LastProcessed: 29,
BatchSize: 5,
NumBlockConfirmations: 3,
NumOfBlocksToReconcile: 1000,
},
{
Address: ethgo.BytesToAddress([]byte{2}),
Number: 100,
LastProcessed: 10,
BatchSize: 10,
NumBlockConfirmations: 3,
MaxBackLogSize: 15,
Address: ethgo.BytesToAddress([]byte{2}),
Number: 100,
LastProcessed: 10,
BatchSize: 10,
NumBlockConfirmations: 3,
NumOfBlocksToReconcile: 15,
},
}

Expand Down Expand Up @@ -75,7 +75,7 @@ func FuzzGetNewState(f *testing.F) {
}
providerMock.On("GetLogs", mock.Anything).Return(logs, nil)

testConfig := createTestTrackerConfig(t, data.NumBlockConfirmations, data.BatchSize, data.MaxBackLogSize)
testConfig := createTestTrackerConfig(t, data.NumBlockConfirmations, data.BatchSize, data.NumOfBlocksToReconcile)
testConfig.BlockProvider = providerMock

eventTracker := &EventTracker{
Expand Down
4 changes: 2 additions & 2 deletions tracker/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ func TestEventTracker_TrackBlock(t *testing.T) {
}

func createTestTrackerConfig(t *testing.T,
numBlockConfirmations, batchSize, maxBacklogSize uint64) *EventTrackerConfig {
numBlockConfirmations, batchSize, numOfBlocksToReconcile uint64) *EventTrackerConfig {
t.Helper()

return &EventTrackerConfig{
RPCEndpoint: "http://some-rpc-url.com",
NumBlockConfirmations: numBlockConfirmations,
SyncBatchSize: batchSize,
NumOfBlocksToReconcile: maxBacklogSize,
NumOfBlocksToReconcile: numOfBlocksToReconcile,
PollInterval: 2 * time.Second,
Logger: hclog.NewNullLogger(),
LogFilter: map[ethgo.Address][]ethgo.Hash{
Expand Down

0 comments on commit e88ac4d

Please sign in to comment.