monitor/monitor.go
func (m *Monitor) initLastProcessedBlock(role string, initialBlocks uint64) {
	logger := m.logger.Add("method", "initLastProcessedBlock",
		"role", role, "initialBlocks", initialBlocks)

	block, err := m.getLastProcessedBlockNumber()
	if block > 0 || err != nil || role != data.RoleClient ||
		initialBlocks == 0 {
		return
	}

	ctx, cancel := context.WithTimeout(context.Background(),
		m.ethCallTimeout)
	defer cancel()

	lastBlock, err := m.eth.HeaderByNumber(ctx, nil)
	if err != nil {
		logger.Error(err.Error())
		return
	}

	lastEthBlockNum := lastBlock.Number.Uint64()
	logger = logger.Add("lastEthBlockNum", lastEthBlockNum)

	if initialBlocks > lastEthBlockNum {
		logger.Warn("initialBlocks value is very big")
		return
	}

	lastProcessedBlock := lastEthBlockNum - initialBlocks

	_, err = m.db.Exec(`UPDATE settings SET value=$1 WHERE key=$2`,
		lastProcessedBlock, data.SettingLastProcessedBlock)
	if err != nil {
		logger.Error(err.Error())
	}
	logger.Debug(fmt.Sprintf("last processed block: %d",
		lastProcessedBlock))
}
func (m *Monitor) initLastProcessedBlock(role string, initialBlocks uint64) {
	logger := m.logger.Add("method", "initLastProcessedBlock",
		"role", role, "initialBlocks", initialBlocks)

	block, err := m.getLastProcessedBlockNumber()
	if block > 0 || err != nil || role != data.RoleClient ||
		initialBlocks == 0 {
		return
	}

	ctx, cancel := context.WithTimeout(context.Background(),
		m.ethCallTimeout)
	defer cancel()

	lastBlock, err := m.eth.HeaderByNumber(ctx, nil)
	if err != nil {
		logger.Error(err.Error())
		return
	}

	lastEthBlockNum := lastBlock.Number.Uint64()
	logger = logger.Add("lastEthBlockNum", lastEthBlockNum)

	if initialBlocks > lastEthBlockNum {
		logger.Warn("initialBlocks value is very big")
		return
	}

	lastProcessedBlock := lastEthBlockNum - initialBlocks

	_, err = m.db.Exec(`UPDATE settings SET value=$1 WHERE key=$2`,
		lastProcessedBlock, data.SettingLastProcessedBlock)
	if err != nil {
		logger.Error(err.Error())
	}
	logger.Debug(fmt.Sprintf("last processed block: %d",
		lastProcessedBlock))
}
// initLastProcessedBlock calculates last processed block. If user role is
// client and value of "eth.event.lastProcessedBlock" setting is 0, then value
// of "eth.event.lastProcessedBlock" setting is equal the difference between
// the last Ethereum block and a InitialBlocks value. If InitialBlocks
// value is 0, then this parameter is ignored.