-
Notifications
You must be signed in to change notification settings - Fork 44
Prune cardano transactions in signer after block range roots computation #1685
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
Conversation
72360bf
to
14be502
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.
LGTM 👍
/// Extension trait for the [SqliteConnection] type. | ||
pub trait ConnectionExtensions { | ||
/// Execute the given sql query and return the value of the first cell read. | ||
fn query_single_cell<Q: Into<String>, T: ReadableWithIndex>( |
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.
Is the use of the generic data type Q: Into<String>
necessary here? The function is always called with &str
parameters. Would it be simpler to directly use &str
instead?
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.
Since it's a low level api that may be used in different kind of scenario I would like to have some flexibility with the input parameters, hence the generic.
That said after re-challenging it I don't need a owned string here but only a ref to a str, so I'm thinking of changing the generics to AsRef<str>
, this avoid an allocation and simplify a bit the implementation:
impl ConnectionExtensions for SqliteConnection {
- fn query_single_cell<Q: Into<String>, T: ReadableWithIndex>(
+ fn query_single_cell<Q: AsRef<str>, T: ReadableWithIndex>(
&self,
sql: Q,
params: &[Value],
) -> StdResult<T> {
- let sql = sql.into();
let mut statement = self.prepare(&sql).with_context(|| {
format!(
"Prepare query error: SQL=`{}`",
- &sql.replace('\n', " ").trim()
+ sql.as_ref().replace('\n', " ").trim()
)
})?;
statement.bind(params)?;
By using a local function to avoid repeating the namespace and simplify the conversion into a `config::Value`.
By using `new_sample()` everywhere it make sense instead of building the whole struct each time.
For now it define one method, `query_single_cell`, that allow to read a single value from the database. The two cases in the ctx repository where a simple query were needed instead of the SQliteEntity system has been simplified using this method.
A first request obtains the highest `block_range_root.start` and a second use it, and a given number of block to keep, as the prune threshold. We do that this instead of using a join to make it simple to test (else the tests would need data on the two tables, our test framework doesn't allow yet to do that without a lot of boilerplate).
…igs to signer Also set a default value to them of `2160` (mainnet value) and `true` (enable pruning by default).
It would happen if the number of block to keep is greater than the highest stored block range root start.
By using a `AsRef<str>` instead of a `Into<String>`. This remove the need to locally allocate the string while keeping flexibility for the caller.
898f444
to
4164aca
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.
LGTM 👍
I left few comments and suggestions below.
.../mithril-persistence/src/database/provider/cardano_transaction/delete_cardano_transaction.rs
Outdated
Show resolved
Hide resolved
.../mithril-persistence/src/database/provider/cardano_transaction/delete_cardano_transaction.rs
Outdated
Show resolved
Hide resolved
mithril-signer/src/transactions_importer_with_prune_decorator.rs
Outdated
Show resolved
Hide resolved
mithril-signer/src/transactions_importer_with_prune_decorator.rs
Outdated
Show resolved
Hide resolved
mithril-signer/src/transactions_importer_with_prune_decorator.rs
Outdated
Show resolved
Hide resolved
* more explicit parameter name for `DeleteCardanoTransactionProvider` method * Simplify `TransactionPruner` doc * Remove 'decorator' from the transaction pruner name * Simplify some generics declaration
* Mithril-aggregator from `0.5.7` to `0.5.8` * Mithril-signer from `0.2.135` to `0.2.136` * Mithril-persistence from `0.1.11` to `0.1.12`
Content
This PR add, to the signer only, a pruning of the cardano transactions after the computation of block ranges roots.
This is done using a decorator wrapping the existing
CardanoTransactionsImporter
.Two new configuration parameters have been added to signer
Configuration
structure:network_security_parameter
, default to2160
(mainnet value).enable_transaction_pruning
, default totrue
.Since both have a default value our signer won't have to update their configurations.
Pre-submit checklist
Comments
new_sample(party_id)
, mithril-signer).Issue(s)
Closes #1645