-
Notifications
You must be signed in to change notification settings - Fork 41
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
Get rid of store adapter in aggregator #2143
base: main
Are you sure you want to change the base?
Conversation
…le and use `projection_with_table`
…ingStore` that use the `StoreAdapter`
Test Results 4 files ± 0 51 suites ±0 11m 54s ⏱️ +10s Results for commit e450847. ± Comparison against base commit 67d7501. This pull request removes 61 and adds 16 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
7363c3c
to
dae2e96
Compare
|
||
impl CertificatePendingRecord { | ||
/// Construct a [Projection] that will allow to hydrate this `CertificatePendingRecord`. | ||
pub fn get_projection_with_table(table: &str) -> Projection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a proposition to have a function that produce projection with that final table name instead of using an alias.
Tell me if we put it in this PR or if you prefer to keep the standard way
The alias mechanism is not really necessary because we always calling it just after creating the projection. There is no reuse of the projection.
With this function, the caller knows which table name(s) need to be map instead of using an alias key string without any constraints and used in different files (we may use a constant).
Callers of projection function are requests that know record type and can use specific function of this record.
// it is important to alias the fields with the same name as the table | ||
// since the table cannot be aliased in a RETURNING statement in SQLite. | ||
|
||
// let projection = Self::Entity::get_projection().expand(SourceAlias::new(&[( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment will be remove if we keep get_projection_with_table
otherwise it will be uncommented and the code below will be removed.
See PR comment on get_projection_with_table
in CertificatePendingRecord
to have explanation about this function.
&mut self, | ||
) -> Result<Arc<dyn CertificatePendingStorer>> { | ||
Ok(Arc::new(CertificatePendingRepository::new( | ||
self.get_sqlite_connection().await?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The building of certificate_pending_store
is know the same in production and in test environment.
There is no really need to make a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it's better like this 👍
dae2e96
to
d0ba1ee
Compare
mod stake_store; | ||
mod store_pruner; | ||
|
||
pub use stake_store::StakeStorer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We keep StakeStore that contain the trait.
Maybe it's could be better to move this trait from persistence
to aggregator
and signer
What do you think ?
d0ba1ee
to
20c0332
Compare
20c0332
to
e450847
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good 👍
I left few questions and suggestions.
} | ||
|
||
fn get_definition(&self, condition: &str) -> String { | ||
// let aliases = SourceAlias::new(&[("{:pending_certificate:}", "new_pending_certificate")]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to remove this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rework it using the new function expand_projection
let projection = Self::Entity::get_projection_with_table("pending_certificate") | ||
.expand(SourceAlias::new(&[])); | ||
format!( | ||
// TODO check the order to keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this order (rowid desc
). You can remove this comment.
|
||
use crate::database::record::CertificatePendingRecord; | ||
|
||
/// Query to update [CertificatePendingRecord] in the sqlite database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Query to update [CertificatePendingRecord] in the sqlite database | |
/// Query to save [CertificatePendingRecord] in the sqlite database |
r#" | ||
create table new_pending_certificate ( | ||
epoch integer not null, | ||
certificate text not null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
certificate
is a bit misleading here as this does not represent a certificate.
But let's keep it like that if it requires too many modifications as we will remove it completely in the near future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a better name, we can change it. It's not a lot of work.
} | ||
} | ||
|
||
impl From<CertificatePending> for CertificatePendingRecord { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be better to implement TryFrom
here to avoid panics.
|
||
use super::*; | ||
|
||
fn build_signers( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have used a helper to create a SignerWithStake
from a party_id
and a verification_key
.
Also the code could probably be a bit more functional.
@@ -456,3 +458,52 @@ pub fn insert_stake_pool( | |||
|
|||
Ok(()) | |||
} | |||
|
|||
/// A simple struct that help to initialize database with the old adapter behavior for testing purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// A simple struct that help to initialize database with the old adapter behavior for testing purposes. | |
/// A simple struct that helps initialize a database with the old adapter behavior for testing purposes. |
self.connection.execute(sql).unwrap(); | ||
} | ||
|
||
pub fn is_key_hash_exist(&self, key_hash: &str) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn is_key_hash_exist(&self, key_hash: &str) -> bool { | |
pub fn ihas_key_hash(&self, key_hash: &str) -> bool { |
&mut self, | ||
) -> Result<Arc<dyn CertificatePendingStorer>> { | ||
Ok(Arc::new(CertificatePendingRepository::new( | ||
self.get_sqlite_connection().await?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it's better like this 👍
.unwrap(), | ||
)); | ||
|
||
let vkey_store = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let vkey_store = { | |
let verification_key_store = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
migrations | ||
.clone() | ||
.into_iter() | ||
.filter(|m| m.version < 32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a reminder if you want to update the version number after rebasing on the main branch.
/// Get a configured [CertificatePendingStore]. | ||
pub async fn get_certificate_pending_store(&mut self) -> Result<Arc<CertificatePendingStore>> { | ||
/// Get a configured [CertificatePendingStorer]. | ||
pub async fn get_certificate_pending_store( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename the function as well?
pub async fn get_certificate_pending_store( | |
pub async fn get_certificate_pending_storer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also rename build_certificate_pending_store
to build_certificate_pending_storer
d78085f
to
61fd2ee
Compare
Content
Replace the store using the legacy store adapter and replace them with a repository implementation in the
Aggregator
.This PR includes:
StoreAdapter
frompersistence
StoreAdapter
forsigner_registration
andCertificatePending
inAggregator
AdapterError
Note
If pruning is unit tested, there is no test that verify that it's really plugged and worked in production.
It's just a configuration in
build_upkeep_service
function in thebuilder.rs
file that activate it.Pre-submit checklist
Comments
Issue(s)
Relates to #2118