Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sidecar query server #6953

Merged
merged 6 commits into from
Nov 30, 2023
Merged

feat: sidecar query server #6953

merged 6 commits into from
Nov 30, 2023

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Nov 30, 2023

Closes: #XXX

What is the purpose of the change

Core implementation of the sidecar query server with the router

Separated from: #6785

SQS is not wired into the app yet. I suggest review being only cursory. Please check go.mod, that there is no state-machine affecting logic.

Testing and Verifying

This change is a trivial rework / code cleanup without any test coverage.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@github-actions github-actions bot removed the T:build label Nov 30, 2023
@p0mvn p0mvn marked this pull request as ready for review November 30, 2023 03:30
Base automatically changed from roman/sqs-ingest-manager to main November 30, 2023 03:42
@p0mvn p0mvn added V:state/compatible/no_backport State machine compatible PR, depends on prior breaks V:state/compatible/backport State machine compatible PR, should be backported A:no-changelog A:backport/v20.x backport patches to v20.x branch A:backport/v21.x backport patches to v21.x branch and removed V:state/compatible/no_backport State machine compatible PR, depends on prior breaks labels Nov 30, 2023
Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK on skim, noting that I did not look at tests. Full feature will need proper review

Comment on lines +98 to +99
- How to handle atomicity between ticks and pools? E.g. let's say a block is written between the time initial pools are read
and the time the ticks are read. Now, we have data that is partially up-to-date.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should we just operate on data from the previous block?

Comment on lines +20 to +26
// NewChainInfoIngester returns a new chain information ingester.
func NewChainInfoIngester(chainInfoRepo mvc.ChainInfoRepository, repositoryManager mvc.TxManager) mvc.AtomicIngester {
return &chainInfoIngester{
chainInfoRepo: chainInfoRepo,
repositoryManager: repositoryManager,
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we don't just set the logger directly here?

func (ci *chainInfoIngester) ProcessBlock(ctx sdk.Context, tx mvc.Tx) error {
height := ctx.BlockHeight()

ci.logger.Info("ingesting latest blockchain height", zap.Int64("height", height))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be an info log, we should keep info logs as bare as needed, especially for something that will happen on a per block basis.

Comment on lines +119 to +123
// GetTotalValueLockedUOSMO implements domain.PoolI.
func (mp *MockRoutablePool) GetTotalValueLockedUOSMO() math.Int {
return mp.TotalValueLockedUSDC
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method is UOSMO be returns USDC

newDenoms := make([]string, len(mp.Denoms))
copy(newDenoms, mp.Denoms)

newTotalValueLocker := osmomath.NewIntFromBigInt(mp.TotalValueLockedUSDC.BigInt())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locker instead of Locked

Comment on lines +15 to +30
func retrieveTakerFeeToMapIfNotExists(ctx sdk.Context, denoms []string, denomPairToTakerFeeMap domain.TakerFeeMap, poolManagerKeeper common.PoolManagerKeeper) error {
for i, denomI := range denoms {
for j := i + 1; j < len(denoms); j++ {
if !denomPairToTakerFeeMap.Has(denomI, denoms[j]) {
takerFee, err := poolManagerKeeper.GetTradingPairTakerFee(ctx, denomI, denoms[j])
if err != nil {
// This error should not happen. As a result, we do not skip it
return err
}

denomPairToTakerFeeMap.SetTakerFee(denomI, denoms[j], takerFee)
}
}
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, we set it here. Can probably save on storage by making it so that if no store exists we use default rather than storing default for ever non-overriden pair.

Comment on lines +23 to +30
// NewPoolsUsecase will create a new pools use case object
func NewPoolsUsecase(timeout time.Duration, poolsRepository mvc.PoolsRepository, redisRepositoryManager mvc.TxManager) mvc.PoolsUsecase {
return &poolsUseCase{
contextTimeout: timeout,
poolsRepository: poolsRepository,
redisRepositoryManager: redisRepositoryManager,
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better name for usecase? I am still struggling to understand how usecase applies here

return nil, err
}

// TODO: refactor get these directl from the pools repository.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: refactor get these directl from the pools repository.
// TODO: refactor get these directly from the pools repository.

Comment on lines +31 to +35
// Define a regular expression pattern to match sdk.Coin where the first part is the amount and second is the denom name
// Patterns tested:
// 500ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2
// 100uion
var coinPattern = regexp.MustCompile(`([0-9]+)(([a-z]+)(\/([A-Z0-9]+))*)`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regex will prob need to consider multiple slash for token factory, it might already do this but I am skimming

}

const (
keySeparator = "-"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am skimming but is it possible for a denom to have "-" now in sdk 47 so this would maybe mess up the key

@p0mvn
Copy link
Member Author

p0mvn commented Nov 30, 2023

Thanks for the review. I reviewed all comments, and all are non-blocking. I will come back to addressing after the v1 release.

Tracking that here: https://app.clickup.com/t/86a1j92hy

@p0mvn p0mvn merged commit 4edf2cb into main Nov 30, 2023
1 check passed
@p0mvn p0mvn deleted the roman/sqs-main branch November 30, 2023 21:35
mergify bot pushed a commit that referenced this pull request Nov 30, 2023
* feat(SQS): IngestManager abstraction and wiring

* comment

* comment

* lint

* feat: sidecar query server

---------

Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
(cherry picked from commit 4edf2cb)

# Conflicts:
#	go.mod
#	go.sum
mergify bot pushed a commit that referenced this pull request Nov 30, 2023
* feat(SQS): IngestManager abstraction and wiring

* comment

* comment

* lint

* feat: sidecar query server

---------

Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
(cherry picked from commit 4edf2cb)
p0mvn added a commit that referenced this pull request Nov 30, 2023
p0mvn added a commit that referenced this pull request Nov 30, 2023
* feat(SQS): IngestManager abstraction and wiring

* comment

* comment

* lint

* feat: sidecar query server

---------

Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
(cherry picked from commit 4edf2cb)

Co-authored-by: Roman <roman@osmosis.team>
p0mvn added a commit that referenced this pull request Nov 30, 2023
Co-authored-by: roman <roman@osmosis.team>
}

// SetTokenOutDenom implements domain.RoutablePool.
func (*MockRoutablePool) SetTokenOutDenom(tokenOutDenom string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason we're not implementing this for mock?

@@ -0,0 +1,3 @@
// Encapsulates the Model-View-Controller abstraction domain.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what was the original intention of this file:?


// AtomicIngester is an interface that defines the methods for the atomic ingester.
// It processes a block by writing data into a transaction.
// The caller must call Exec on the transaction to flush data to sink.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean?

MaxRoutes int
MaxSplitRoutes int
MaxSplitIterations int
// Denominated in OSMO (not uosmo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why do we want this in osmo not uosmo?

Debug(msg string, fields ...zap.Field)
}

type NoOpLogger struct{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want no op logger?

return nil, err
}

core = zapcore.NewTee(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing, I found a bug that logger wouldnt correctly pipe it to std out besides in the ingester. Needs investigation

sqsModel := p.GetSQSPoolModel()
poolDenoms := p.GetPoolDenoms()

if len(poolDenoms) < 2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this?

// updateRoutes updates the routes for all denom pairs in the taker fee map. The taker fee map value is unused.
// It returns a channel that is closed when all routes are updated.
// TODO: test
func (pi *poolIngester) updateRoutes(ctx context.Context, tx mvc.Tx, pools []domain.PoolI, denomPairToTakerFeeMap map[domain.DenomPair]osmomath.Dec) chan domain.DenomPair {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why are we using channels here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v20.x backport patches to v20.x branch A:backport/v21.x backport patches to v21.x branch A:no-changelog V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants