-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
chore(gas_price_service): define port for GasPriceDatabase #2226
Closed
Closed
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5702371
chore(gas_price_service): define port for gas price db lookups
rymnc ac699b9
fix: pass metadata by ref
rymnc 1c296b4
Merge branch 'master' into chore/gas-price-service-ports-p2
MitchTurner 100b5b8
chore: use structured storage strat
rymnc 9575a21
chore: rollback centrally
rymnc e5f5d92
fix: dont sync if nothing in onchain db
rymnc b2aa337
test: swallow error for soft rollback
rymnc 2953019
fix: log warning if rollback failed
rymnc 62343d7
fix: retain test
rymnc d51d494
chore: add comment
rymnc 417459d
fix: remove impl for Database
rymnc 2e6a9d3
fix: docstring
rymnc 64818a6
fix: improved comment for GasPriceData
rymnc 986ef13
Merge branch 'master' into chore/gas-price-service-ports-p2
xgreenx b439c8d
Merge branch 'master' into chore/gas-price-service-ports-p2
MitchTurner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,29 @@ use crate::{ | |
use fuel_core_gas_price_service::{ | ||
fuel_gas_price_updater::{ | ||
fuel_core_storage_adapter::{ | ||
storage::GasPriceMetadata, | ||
GasPriceSettings, | ||
GasPriceSettingsProvider, | ||
}, | ||
Error as GasPriceError, | ||
Result as GasPriceResult, | ||
UpdaterMetadata, | ||
}, | ||
ports::L2Data, | ||
ports::{ | ||
GasPriceData, | ||
L2Data, | ||
MetadataStorage, | ||
}, | ||
}; | ||
use fuel_core_storage::{ | ||
transactional::{ | ||
HistoricalView, | ||
WriteTransaction, | ||
}, | ||
Result as StorageResult, | ||
StorageAsMut, | ||
StorageAsRef, | ||
}; | ||
use fuel_core_storage::Result as StorageResult; | ||
use fuel_core_types::{ | ||
blockchain::{ | ||
block::Block, | ||
|
@@ -23,6 +37,11 @@ use fuel_core_types::{ | |
fuel_types::BlockHeight, | ||
}; | ||
|
||
use crate::database::{ | ||
database_description::gas_price::GasPriceDatabase, | ||
Database, | ||
}; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
|
@@ -39,6 +58,44 @@ impl L2Data for OnChainIterableKeyValueView { | |
} | ||
} | ||
|
||
impl GasPriceData for Database<GasPriceDatabase> { | ||
fn latest_height(&self) -> Option<BlockHeight> { | ||
HistoricalView::latest_height(self) | ||
} | ||
} | ||
|
||
impl MetadataStorage for Database<GasPriceDatabase> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we want to duplicate the implementation here instead of deriving the blanket implementation from gas price service crate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed in 417459d |
||
fn get_metadata( | ||
&self, | ||
block_height: &BlockHeight, | ||
) -> GasPriceResult<Option<UpdaterMetadata>> { | ||
let metadata = self | ||
.storage::<GasPriceMetadata>() | ||
.get(block_height) | ||
.map_err(|err| GasPriceError::CouldNotFetchMetadata { | ||
source_error: err.into(), | ||
})?; | ||
Ok(metadata.map(|inner| inner.into_owned())) | ||
} | ||
|
||
fn set_metadata(&mut self, metadata: &UpdaterMetadata) -> GasPriceResult<()> { | ||
let block_height = metadata.l2_block_height(); | ||
let mut tx = self.write_transaction(); | ||
tx.storage_as_mut::<GasPriceMetadata>() | ||
.insert(&block_height, metadata) | ||
.map_err(|err| GasPriceError::CouldNotSetMetadata { | ||
block_height, | ||
source_error: err.into(), | ||
})?; | ||
tx.commit() | ||
.map_err(|err| GasPriceError::CouldNotSetMetadata { | ||
block_height, | ||
source_error: err.into(), | ||
})?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl GasPriceSettingsProvider for ConsensusParametersProvider { | ||
fn settings( | ||
&self, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Yeah. We definitely want to throw an error if this fails.