diff --git a/command/server/config/config.go b/command/server/config/config.go index 072184c0eb..f502a8000b 100644 --- a/command/server/config/config.go +++ b/command/server/config/config.go @@ -33,13 +33,17 @@ type Config struct { CorsAllowedOrigins []string `json:"cors_allowed_origins" yaml:"cors_allowed_origins"` Relayer bool `json:"relayer" yaml:"relayer"` - NumBlockConfirmations uint64 `json:"num_block_confirmations" yaml:"num_block_confirmations"` RelayerTrackerPollInterval time.Duration `json:"relayer_tracker_poll_interval" yaml:"relayer_tracker_poll_interval"` ConcurrentRequestsDebug uint64 `json:"concurrent_requests_debug" yaml:"concurrent_requests_debug"` WebSocketReadLimit uint64 `json:"web_socket_read_limit" yaml:"web_socket_read_limit"` MetricsInterval time.Duration `json:"metrics_interval" yaml:"metrics_interval"` + + // event tracker + NumBlockConfirmations uint64 `json:"num_block_confirmations" yaml:"num_block_confirmations"` + TrackerSyncBatchSize uint64 `json:"tracker_sync_batch_size" yaml:"tracker_sync_batch_size"` + TrackerBlocksToReconcile uint64 `json:"tracker_blocks_to_reconcile" yaml:"tracker_blocks_to_reconcile"` } // Telemetry holds the config details for metric services. @@ -82,10 +86,6 @@ const ( // requests with fromBlock/toBlock values (e.g. eth_getLogs) DefaultJSONRPCBlockRangeLimit uint64 = 1000 - // DefaultNumBlockConfirmations minimal number of child blocks required for the parent block to be considered final - // on ethereum epoch lasts for 32 blocks. more details: https://www.alchemy.com/overviews/ethereum-commitment-levels - DefaultNumBlockConfirmations uint64 = 64 - // DefaultConcurrentRequestsDebug specifies max number of allowed concurrent requests for debug endpoints DefaultConcurrentRequestsDebug uint64 = 32 @@ -101,6 +101,25 @@ const ( // DefaultMetricsInterval specifies the time interval after which Prometheus metrics will be generated. // A value of 0 means the metrics are disabled. DefaultMetricsInterval time.Duration = time.Second * 8 + + // event tracker + + // DefaultNumBlockConfirmations minimal number of child blocks required for the parent block to be considered final + // on ethereum epoch lasts for 32 blocks. more details: https://www.alchemy.com/overviews/ethereum-commitment-levels + DefaultNumBlockConfirmations uint64 = 64 + + // DefaultTrackerSyncBatchSize defines a default batch size of blocks that will be gotten from tracked chain, + // when tracker is out of sync and needs to sync a number of blocks. + DefaultTrackerSyncBatchSize uint64 = 10 + + // DefaultTrackerBlocksToReconcile defines how default number blocks that tracker + // will sync up from the latest block on tracked chain. + // If a node that has tracker, was offline for days, months, a year, it will miss a lot of blocks. + // In the meantime, we expect the rest of nodes to have collected the desired events and did their + // 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. + DefaultTrackerBlocksToReconcile uint64 = 10000 ) // DefaultConfig returns the default server configuration @@ -136,11 +155,14 @@ func DefaultConfig() *Config { JSONRPCBatchRequestLimit: DefaultJSONRPCBatchRequestLimit, JSONRPCBlockRangeLimit: DefaultJSONRPCBlockRangeLimit, Relayer: false, - NumBlockConfirmations: DefaultNumBlockConfirmations, ConcurrentRequestsDebug: DefaultConcurrentRequestsDebug, WebSocketReadLimit: DefaultWebSocketReadLimit, RelayerTrackerPollInterval: DefaultRelayerTrackerPollInterval, MetricsInterval: DefaultMetricsInterval, + // event tracker + NumBlockConfirmations: DefaultNumBlockConfirmations, + TrackerSyncBatchSize: DefaultTrackerSyncBatchSize, + TrackerBlocksToReconcile: DefaultTrackerBlocksToReconcile, } } diff --git a/command/server/params.go b/command/server/params.go index 43f39f76f5..abaa2cb5f0 100644 --- a/command/server/params.go +++ b/command/server/params.go @@ -37,8 +37,7 @@ const ( corsOriginFlag = "access-control-allow-origins" logFileLocationFlag = "log-to" - relayerFlag = "relayer" - numBlockConfirmationsFlag = "num-block-confirmations" + relayerFlag = "relayer" concurrentRequestsDebugFlag = "concurrent-requests-debug" webSocketReadLimitFlag = "websocket-read-limit" @@ -46,6 +45,11 @@ const ( relayerTrackerPollIntervalFlag = "relayer-poll-interval" metricsIntervalFlag = "metrics-interval" + + // event tracker + numBlockConfirmationsFlag = "num-block-confirmations" + trackerSyncBatchSizeFlag = "tracker-sync-batch-size" + trackerBlocksToReconcileFlag = "tracker-blocks-to-reconcile" ) // Flags that are deprecated, but need to be preserved for @@ -188,8 +192,11 @@ func (p *serverParams) generateConfig() *server.Config { LogFilePath: p.logFileLocation, Relayer: p.relayer, - NumBlockConfirmations: p.rawConfig.NumBlockConfirmations, RelayerTrackerPollInterval: p.rawConfig.RelayerTrackerPollInterval, MetricsInterval: p.rawConfig.MetricsInterval, + // event tracker + NumBlockConfirmations: p.rawConfig.NumBlockConfirmations, + TrackerSyncBatchSize: p.rawConfig.TrackerSyncBatchSize, + TrackerBlocksToReconcile: p.rawConfig.TrackerBlocksToReconcile, } } diff --git a/command/server/server.go b/command/server/server.go index aa64d2b248..ba2c3b64d2 100644 --- a/command/server/server.go +++ b/command/server/server.go @@ -214,13 +214,6 @@ func setFlags(cmd *cobra.Command) { "start the state sync relayer service (PolyBFT only)", ) - cmd.Flags().Uint64Var( - ¶ms.rawConfig.NumBlockConfirmations, - numBlockConfirmationsFlag, - defaultConfig.NumBlockConfirmations, - "minimal number of child blocks required for the parent block to be considered final", - ) - cmd.Flags().Uint64Var( ¶ms.rawConfig.ConcurrentRequestsDebug, concurrentRequestsDebugFlag, @@ -249,6 +242,38 @@ func setFlags(cmd *cobra.Command) { "the interval (in seconds) at which special metrics are generated. a value of zero means the metrics are disabled", ) + // event tracker config + cmd.Flags().Uint64Var( + ¶ms.rawConfig.NumBlockConfirmations, + numBlockConfirmationsFlag, + defaultConfig.NumBlockConfirmations, + "minimal number of child blocks required for the parent block to be considered final", + ) + + cmd.Flags().Uint64Var( + ¶ms.rawConfig.TrackerSyncBatchSize, + trackerSyncBatchSizeFlag, + defaultConfig.TrackerSyncBatchSize, + `defines a batch size of blocks that will be gotten from tracked chain, + when tracker is out of sync and needs to sync a number of blocks. + (e.g., SyncBatchSize = 10, trackers last processed block is 10, latest block on tracked chain is 100, + it will get blocks 11-20, get logs from confirmed blocks of given batch, remove processed confirm logs + from memory, and continue to the next batch)`, + ) + + cmd.Flags().Uint64Var( + ¶ms.rawConfig.TrackerBlocksToReconcile, + trackerBlocksToReconcileFlag, + defaultConfig.TrackerBlocksToReconcile, + `defines how many blocks we will sync up from the latest block on tracked chain. + If a node that has tracker, was offline for days, months, a year, it will miss a lot of blocks. + In the meantime, we expect the rest of nodes to have collected the desired events and did their + 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. + If 0 is set to this flag, event tracker will sync all the blocks from tracked chain`, + ) + setLegacyFlags(cmd) setDevFlags(cmd) diff --git a/consensus/consensus.go b/consensus/consensus.go index 878ad76655..4545f901d7 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -78,8 +78,11 @@ type Params struct { SecretsManager secrets.SecretsManager BlockTime uint64 - NumBlockConfirmations uint64 - MetricsInterval time.Duration + MetricsInterval time.Duration + // event tracker + NumBlockConfirmations uint64 + TrackerSyncBatchSize uint64 + TrackerBlocksToReconcile uint64 } // Factory is the factory function to create a discovery consensus diff --git a/consensus/polybft/consensus_runtime.go b/consensus/polybft/consensus_runtime.go index 7b9bb31879..8be65bc748 100644 --- a/consensus/polybft/consensus_runtime.go +++ b/consensus/polybft/consensus_runtime.go @@ -73,15 +73,18 @@ type guardedDataDTO struct { // runtimeConfig is a struct that holds configuration data for given consensus runtime type runtimeConfig struct { - PolyBFTConfig *PolyBFTConfig - DataDir string - Key *wallet.Key - State *State - blockchain blockchainBackend - polybftBackend polybftBackend - txPool txPoolInterface - bridgeTopic topic - numBlockConfirmations uint64 + PolyBFTConfig *PolyBFTConfig + DataDir string + Key *wallet.Key + State *State + blockchain blockchainBackend + polybftBackend polybftBackend + txPool txPoolInterface + bridgeTopic topic + // event tracker + numBlockConfirmations uint64 + trackerSyncBatchSize uint64 + trackerBlocksToReconcile uint64 } // consensusRuntime is a struct that provides consensus runtime features like epoch, state and event management @@ -187,15 +190,18 @@ func (c *consensusRuntime) initStateSyncManager(logger hcf.Logger) error { logger.Named("state-sync-manager"), c.config.State, &stateSyncConfig{ - key: c.config.Key, - stateSenderAddr: stateSenderAddr, - stateSenderStartBlock: c.config.PolyBFTConfig.Bridge.EventTrackerStartBlocks[stateSenderAddr], - jsonrpcAddr: c.config.PolyBFTConfig.Bridge.JSONRPCEndpoint, - dataDir: c.config.DataDir, - topic: c.config.bridgeTopic, - maxCommitmentSize: maxCommitmentSize, + key: c.config.Key, + stateSenderAddr: stateSenderAddr, + stateSenderStartBlock: c.config.PolyBFTConfig.Bridge.EventTrackerStartBlocks[stateSenderAddr], + jsonrpcAddr: c.config.PolyBFTConfig.Bridge.JSONRPCEndpoint, + dataDir: c.config.DataDir, + topic: c.config.bridgeTopic, + maxCommitmentSize: maxCommitmentSize, + // event tracker numBlockConfirmations: c.config.numBlockConfirmations, blockTrackerPollInterval: c.config.PolyBFTConfig.BlockTrackerPollInterval.Duration, + trackerSyncBatchSize: c.config.trackerSyncBatchSize, + trackerBlocksToReconcile: c.config.trackerBlocksToReconcile, }, c, ) diff --git a/consensus/polybft/eventtracker/event_tracker.go b/consensus/polybft/eventtracker/event_tracker.go index 5901f2cee0..effaa95a6f 100644 --- a/consensus/polybft/eventtracker/event_tracker.go +++ b/consensus/polybft/eventtracker/event_tracker.go @@ -87,7 +87,7 @@ type EventTracker struct { // // Example Usage: // -// config := &EventTracker{ +// config := &EventTrackerConfig{ // RpcEndpoint: "http://some-json-rpc-url.com", // StartBlockFromConfig: 100_000, // NumBlockConfirmations: 10, @@ -110,24 +110,28 @@ type EventTracker struct { // // Outputs: // - A new instance of the EventTracker struct. -func NewEventTracker(config *EventTrackerConfig) (*EventTracker, error) { +func NewEventTracker(config *EventTrackerConfig, startBlockFromGenesis uint64) (*EventTracker, error) { lastProcessedBlock, err := config.Store.GetLastProcessedBlock() if err != nil { return nil, err } - definiteLastProcessedBlock := lastProcessedBlock + if lastProcessedBlock == 0 { + lastProcessedBlock = startBlockFromGenesis - if lastProcessedBlock == 0 && config.NumOfBlocksToReconcile > 0 { - latestBlock, err := config.BlockProvider.GetBlockByNumber(ethgo.Latest, false) - if err != nil { - return nil, err - } + if config.NumOfBlocksToReconcile > 0 { + latestBlock, err := config.BlockProvider.GetBlockByNumber(ethgo.Latest, false) + if err != nil { + return nil, err + } - if latestBlock.Number > config.NumOfBlocksToReconcile { - // if this is a fresh start, then we should start syncing from - // latestBlock.Number - NumOfBlocksToReconcile - definiteLastProcessedBlock = latestBlock.Number - config.NumOfBlocksToReconcile + if latestBlock.Number > config.NumOfBlocksToReconcile && + startBlockFromGenesis < latestBlock.Number-config.NumOfBlocksToReconcile { + // if this is a fresh start, and we missed too much blocks, + // then we should start syncing from + // latestBlock.Number - NumOfBlocksToReconcile + lastProcessedBlock = latestBlock.Number - config.NumOfBlocksToReconcile + } } } @@ -135,7 +139,7 @@ func NewEventTracker(config *EventTrackerConfig) (*EventTracker, error) { config: config, closeCh: make(chan struct{}), blockTracker: blocktracker.NewJSONBlockTracker(config.BlockProvider), - blockContainer: NewTrackerBlockContainer(definiteLastProcessedBlock), + blockContainer: NewTrackerBlockContainer(lastProcessedBlock), }, nil } @@ -175,6 +179,7 @@ func (e *EventTracker) Start() error { "syncBatchSize", e.config.SyncBatchSize, "numOfBlocksToReconcile", e.config.NumOfBlocksToReconcile, "logFilter", e.config.LogFilter, + "lastBlockProcessed", e.blockContainer.LastProcessedBlock(), ) ctx, cancelFn := context.WithCancel(context.Background()) diff --git a/consensus/polybft/eventtracker/event_tracker_test.go b/consensus/polybft/eventtracker/event_tracker_test.go index be7b0d1dd8..619a8d4a9c 100644 --- a/consensus/polybft/eventtracker/event_tracker_test.go +++ b/consensus/polybft/eventtracker/event_tracker_test.go @@ -89,7 +89,7 @@ func TestEventTracker_TrackBlock(t *testing.T) { t.Run("Add block by block - no confirmed blocks", func(t *testing.T) { t.Parallel() - tracker, err := NewEventTracker(createTestTrackerConfig(t, 10, 10, 0)) + tracker, err := NewEventTracker(createTestTrackerConfig(t, 10, 10, 0), 0) require.NoError(t, err) @@ -131,7 +131,7 @@ func TestEventTracker_TrackBlock(t *testing.T) { blockProviderMock := new(mockProvider) blockProviderMock.On("GetLogs", mock.Anything).Return([]*ethgo.Log{}, nil).Once() - tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, 10, 0)) + tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, 10, 0), 0) require.NoError(t, err) tracker.config.BlockProvider = blockProviderMock @@ -197,7 +197,7 @@ func TestEventTracker_TrackBlock(t *testing.T) { blockProviderMock := new(mockProvider) blockProviderMock.On("GetLogs", mock.Anything).Return(logs, nil).Once() - tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, 10, 0)) + tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, 10, 0), 0) require.NoError(t, err) tracker.config.BlockProvider = blockProviderMock @@ -265,7 +265,7 @@ func TestEventTracker_TrackBlock(t *testing.T) { blockProviderMock := new(mockProvider) blockProviderMock.On("GetLogs", mock.Anything).Return(nil, errors.New("some error occurred")).Once() - tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, 10, 0)) + tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, 10, 0), 0) require.NoError(t, err) tracker.config.BlockProvider = blockProviderMock @@ -335,7 +335,7 @@ func TestEventTracker_TrackBlock(t *testing.T) { // just mock the call, it will use the provider.blocks map to handle proper returns blockProviderMock.On("GetBlockByNumber", mock.Anything, mock.Anything).Return(nil, nil).Times(int(numOfMissedBlocks)) - tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, batchSize, 0)) + tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, batchSize, 0), 0) require.NoError(t, err) tracker.config.BlockProvider = blockProviderMock @@ -420,7 +420,7 @@ func TestEventTracker_TrackBlock(t *testing.T) { // just mock the call, it will use the provider.blocks map to handle proper returns blockProviderMock.On("GetBlockByNumber", mock.Anything, mock.Anything).Return(nil, nil).Times(int(numOfMissedBlocks + numOfCachedBlocks)) - tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, batchSize, 0)) + tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, batchSize, 0), 0) require.NoError(t, err) tracker.config.BlockProvider = blockProviderMock @@ -515,7 +515,7 @@ func TestEventTracker_TrackBlock(t *testing.T) { // just mock the call, it will use the provider.blocks map to handle proper returns blockProviderMock.On("GetBlockByNumber", mock.Anything, mock.Anything).Return(nil, nil).Times(int(numOfCachedBlocks)) - tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, batchSize, 0)) + tracker, err := NewEventTracker(createTestTrackerConfig(t, numBlockConfirmations, batchSize, 0), 0) require.NoError(t, err) tracker.config.BlockProvider = blockProviderMock diff --git a/consensus/polybft/polybft.go b/consensus/polybft/polybft.go index 421625956b..3f8a692fff 100644 --- a/consensus/polybft/polybft.go +++ b/consensus/polybft/polybft.go @@ -543,15 +543,18 @@ func (p *Polybft) Start() error { // initRuntime creates consensus runtime func (p *Polybft) initRuntime() error { runtimeConfig := &runtimeConfig{ - PolyBFTConfig: p.consensusConfig, - Key: p.key, - DataDir: p.dataDir, - State: p.state, - blockchain: p.blockchain, - polybftBackend: p, - txPool: p.txPool, - bridgeTopic: p.bridgeTopic, - numBlockConfirmations: p.config.NumBlockConfirmations, + PolyBFTConfig: p.consensusConfig, + Key: p.key, + DataDir: p.dataDir, + State: p.state, + blockchain: p.blockchain, + polybftBackend: p, + txPool: p.txPool, + bridgeTopic: p.bridgeTopic, + // event tracker + numBlockConfirmations: p.config.NumBlockConfirmations, + trackerSyncBatchSize: p.config.TrackerSyncBatchSize, + trackerBlocksToReconcile: p.config.TrackerBlocksToReconcile, } runtime, err := newConsensusRuntime(p.logger, runtimeConfig) diff --git a/consensus/polybft/state_sync_manager.go b/consensus/polybft/state_sync_manager.go index 085544c3bb..805b65e14d 100644 --- a/consensus/polybft/state_sync_manager.go +++ b/consensus/polybft/state_sync_manager.go @@ -1,7 +1,6 @@ package polybft import ( - "context" "encoding/hex" "encoding/json" "errors" @@ -18,7 +17,6 @@ import ( "github.com/0xPolygon/polygon-edge/consensus/polybft/validator" "github.com/0xPolygon/polygon-edge/consensus/polybft/wallet" "github.com/0xPolygon/polygon-edge/contracts" - "github.com/0xPolygon/polygon-edge/tracker" "github.com/0xPolygon/polygon-edge/types" "github.com/hashicorp/go-hclog" "github.com/libp2p/go-libp2p/core/peer" @@ -75,14 +73,17 @@ func (d *dummyStateSyncManager) ProcessLog(header *types.Header, // stateSyncConfig holds the configuration data of state sync manager type stateSyncConfig struct { - stateSenderAddr types.Address - stateSenderStartBlock uint64 - jsonrpcAddr string - dataDir string - topic topic - key *wallet.Key - maxCommitmentSize uint64 + stateSenderAddr types.Address + stateSenderStartBlock uint64 + jsonrpcAddr string + dataDir string + topic topic + key *wallet.Key + maxCommitmentSize uint64 + // event tracker numBlockConfirmations uint64 + trackerSyncBatchSize uint64 + trackerBlocksToReconcile uint64 blockTrackerPollInterval time.Duration } @@ -127,7 +128,7 @@ func newStateSyncManager(logger hclog.Logger, state *State, config *stateSyncCon // Init subscribes to bridge topics (getting votes) and start the event tracker routine func (s *stateSyncManager) Init() error { - if err := s.setupNewTracker(); err != nil { + if err := s.initTracker(); err != nil { return fmt.Errorf("failed to init event tracker. Error: %w", err) } @@ -142,8 +143,8 @@ func (s *stateSyncManager) Close() { close(s.closeCh) } -// setupNewTracker sets up and starts the new tracker implementation -func (s *stateSyncManager) setupNewTracker() error { +// initTracker sets up and starts the event tracker implementation +func (s *stateSyncManager) initTracker() error { store, err := eventtracker.NewBoltDBEventTrackerStore(path.Join(s.config.dataDir, "/deposit.db")) if err != nil { return err @@ -159,8 +160,8 @@ func (s *stateSyncManager) setupNewTracker() error { tracker, err := eventtracker.NewEventTracker(&eventtracker.EventTrackerConfig{ RPCEndpoint: s.config.jsonrpcAddr, NumBlockConfirmations: s.config.numBlockConfirmations, - SyncBatchSize: 5, // this should be configurable - NumOfBlocksToReconcile: 0, // this should be configurable + SyncBatchSize: s.config.trackerSyncBatchSize, + NumOfBlocksToReconcile: s.config.trackerBlocksToReconcile, PollInterval: s.config.blockTrackerPollInterval, Logger: s.logger, Store: store, @@ -169,7 +170,7 @@ func (s *stateSyncManager) setupNewTracker() error { LogFilter: map[ethgo.Address][]ethgo.Hash{ ethgo.Address(s.config.stateSenderAddr): {stateSyncEvent.Sig()}, }, - }) + }, s.config.stateSenderStartBlock) if err != nil { return err } @@ -177,28 +178,6 @@ func (s *stateSyncManager) setupNewTracker() error { return tracker.Start() } -// initTracker starts a new event tracker (to receive new state sync events) -func (s *stateSyncManager) initTracker() error { - ctx, cancelFn := context.WithCancel(context.Background()) - - evtTracker := tracker.NewEventTracker( - path.Join(s.config.dataDir, "/deposit.db"), - s.config.jsonrpcAddr, - ethgo.Address(s.config.stateSenderAddr), - s, - s.config.numBlockConfirmations, - s.config.stateSenderStartBlock, - s.logger, - s.config.blockTrackerPollInterval) - - go func() { - <-s.closeCh - cancelFn() - }() - - return evtTracker.Start(ctx) -} - // initTransport subscribes to bridge topics (getting votes for commitments) func (s *stateSyncManager) initTransport() error { return s.config.topic.Subscribe(func(obj interface{}, _ peer.ID) { diff --git a/consensus/polybft/state_sync_manager_test.go b/consensus/polybft/state_sync_manager_test.go index 4748f074ac..0088b324f7 100644 --- a/consensus/polybft/state_sync_manager_test.go +++ b/consensus/polybft/state_sync_manager_test.go @@ -5,14 +5,12 @@ import ( "math/rand" "os" "testing" - "time" "github.com/hashicorp/go-hclog" "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" "github.com/umbracle/ethgo" "github.com/umbracle/ethgo/abi" - "github.com/umbracle/ethgo/testutil" "google.golang.org/protobuf/proto" "github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi" @@ -476,49 +474,6 @@ func TestStateSyncerManager_AddLog_BuildCommitments(t *testing.T) { }) } -func TestStateSyncerManager_EventTracker_Sync(t *testing.T) { - t.Parallel() - - vals := validator.NewTestValidators(t, 5) - s := newTestStateSyncManager(t, vals.GetValidator("0"), &mockRuntime{isActiveValidator: true}) - - server := testutil.DeployTestServer(t, nil) - - // Deploy contract - contractReceipt, err := server.SendTxn(ðgo.Transaction{ - Input: contractsapi.StateSender.Bytecode, - }) - require.NoError(t, err) - - // Create contract function call payload - encodedSyncStateData, err := (&contractsapi.SyncStateStateSenderFn{ - Receiver: types.BytesToAddress(server.Account(0).Bytes()), - Data: []byte{}, - }).EncodeAbi() - require.NoError(t, err) - - // prefill with 10 events - for i := 0; i < 10; i++ { - receipt, err := server.SendTxn(ðgo.Transaction{ - To: &contractReceipt.ContractAddress, - Input: encodedSyncStateData, - }) - require.NoError(t, err) - require.Equal(t, uint64(types.ReceiptSuccess), receipt.Status) - } - - s.config.stateSenderAddr = types.Address(contractReceipt.ContractAddress) - s.config.jsonrpcAddr = server.HTTPAddr() - - require.NoError(t, s.initTracker()) - - time.Sleep(2 * time.Second) - - events, err := s.state.StateSyncStore.getStateSyncEventsForCommitment(1, 10, nil) - require.NoError(t, err) - require.Len(t, events, 10) -} - func TestStateSyncManager_Close(t *testing.T) { t.Parallel() diff --git a/server/config.go b/server/config.go index ff725973b0..7a51ee5e6d 100644 --- a/server/config.go +++ b/server/config.go @@ -44,9 +44,13 @@ type Config struct { Relayer bool - NumBlockConfirmations uint64 RelayerTrackerPollInterval time.Duration MetricsInterval time.Duration + + // event tracker + NumBlockConfirmations uint64 + TrackerSyncBatchSize uint64 + TrackerBlocksToReconcile uint64 } // Telemetry holds the config details for metric services diff --git a/server/server.go b/server/server.go index 394ed93226..eed7530b62 100644 --- a/server/server.go +++ b/server/server.go @@ -574,18 +574,21 @@ func (s *Server) setupConsensus() error { consensus, err := engine( &consensus.Params{ - Context: context.Background(), - Config: config, - TxPool: s.txpool, - Network: s.network, - Blockchain: s.blockchain, - Executor: s.executor, - Grpc: s.grpcServer, - Logger: s.logger, - SecretsManager: s.secretsManager, - BlockTime: uint64(blockTime.Seconds()), - NumBlockConfirmations: s.config.NumBlockConfirmations, - MetricsInterval: s.config.MetricsInterval, + Context: context.Background(), + Config: config, + TxPool: s.txpool, + Network: s.network, + Blockchain: s.blockchain, + Executor: s.executor, + Grpc: s.grpcServer, + Logger: s.logger, + SecretsManager: s.secretsManager, + BlockTime: uint64(blockTime.Seconds()), + MetricsInterval: s.config.MetricsInterval, + // event tracker + NumBlockConfirmations: s.config.NumBlockConfirmations, + TrackerSyncBatchSize: s.config.TrackerSyncBatchSize, + TrackerBlocksToReconcile: s.config.TrackerBlocksToReconcile, }, )