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

Set Latest Recorded Height on startup #2603

Merged
merged 22 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
83bf21a
Use Url apis to build the full url path
MitchTurner Jan 18, 2025
b9977d4
Remove unused import
MitchTurner Jan 18, 2025
e8d72c8
Update CHANGELOG
MitchTurner Jan 18, 2025
968fd69
Make comment more inclusive
MitchTurner Jan 18, 2025
b331fe2
Add test to show the latest recorded height is set on init
MitchTurner Jan 20, 2025
b3da4da
Update CHANGELOG
MitchTurner Jan 20, 2025
cdfec32
Apply fix to shared sequencer service
MitchTurner Jan 20, 2025
b3540ce
Avoid creating extra storage tx
MitchTurner Jan 20, 2025
2f021af
Add missed commit
MitchTurner Jan 20, 2025
c57b645
Add missing api endpoints
MitchTurner Jan 20, 2025
575c28f
Appease Clippy-sama
MitchTurner Jan 20, 2025
6be00a7
Merge branch 'fix-url-scheme' into set-latest-recorded-height-on-startup
MitchTurner Jan 20, 2025
449bd41
Merge branch 'master' into set-latest-recorded-height-on-startup
MitchTurner Jan 21, 2025
25bca69
Merge branch 'master' into set-latest-recorded-height-on-startup
MitchTurner Jan 21, 2025
dc13c4e
Fix failing test
MitchTurner Jan 21, 2025
76f5b43
Include `--starting-recorded-height` in `cli` flags
MitchTurner Jan 21, 2025
6a44c23
Remove unused imports
MitchTurner Jan 21, 2025
fd0b38e
Remove unused imports
MitchTurner Jan 21, 2025
21edb4f
Merge branch 'master' into set-latest-recorded-height-on-startup
MitchTurner Jan 21, 2025
ab55e3f
Rename cli arg
MitchTurner Jan 22, 2025
3316f76
Merge branch 'master' into set-latest-recorded-height-on-startup
MitchTurner Jan 22, 2025
e18acd0
Merge branch 'master' into set-latest-recorded-height-on-startup
MitchTurner Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- [2551](https://github.com/FuelLabs/fuel-core/pull/2551): Enhanced the DA compressed block header to include block id.

### Changed
- [2603](https://github.com/FuelLabs/fuel-core/pull/2603): Sets the latest recorded height on initialization, not just when DA costs are received

## [Version 0.41.0]

### Added
Expand Down
59 changes: 56 additions & 3 deletions crates/services/gas_price_service/src/v1/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ impl GetLatestRecordedHeight for UnimplementedStorageTx {
}

impl AsUnrecordedBlocks for UnimplementedStorageTx {
type Wrapper<'a> = UnimplementedStorageTx
where
Self: 'a;
type Wrapper<'a>
= UnimplementedStorageTx
where
Self: 'a;

fn as_unrecorded_blocks(&mut self) -> Self::Wrapper<'_> {
UnimplementedStorageTx
Expand Down Expand Up @@ -973,3 +974,55 @@ async fn uninitialized_task__init__if_metadata_behind_l2_height_then_sync() {

assert_eq!(on_chain_height, algo_updater_height);
}

#[tokio::test]
async fn uninitialized_task__init__sets_latest_recorded_height_to_l2_height_if_none() {
// given
let metadata_height = 100;
let l2_height = 200;
let config = zero_threshold_arbitrary_config();

let metadata = V1Metadata {
new_scaled_exec_price: 100,
l2_block_height: metadata_height,
new_scaled_da_gas_price: 0,
gas_price_factor: NonZeroU64::new(100).unwrap(),
total_da_rewards: 0,
latest_known_total_da_cost: 0,
last_profit: 0,
second_to_last_profit: 0,
latest_da_cost_per_byte: 0,
unrecorded_block_bytes: 0,
};
let gas_price_db = gas_price_database_with_metadata(&metadata, None);
let mut onchain_db = FakeOnChainDb::new(l2_height);
for height in 1..=l2_height {
let block = arb_block();
onchain_db.blocks.insert(BlockHeight::from(height), block);
}

let service = UninitializedTask::new(
config,
Some(metadata_height.into()),
0.into(),
FakeSettings::default(),
empty_block_stream(),
gas_price_db,
FakeDABlockCost::never_returns(),
onchain_db.clone(),
)
.unwrap();

// when
let gas_price_service = service.init(&StateWatcher::started()).await.unwrap();

// then
// sleep to allow the service to sync
tokio::time::sleep(std::time::Duration::from_millis(100)).await;

let recorded_height = gas_price_service
.storage_tx_provider()
.get_recorded_height()
.unwrap();
assert_eq!(recorded_height, Some(l2_height.into()));
}
13 changes: 9 additions & 4 deletions crates/services/gas_price_service/src/v1/uninitialized_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ where
self.block_stream,
);

let starting_recorded_height = self
.gas_price_db
.get_recorded_height()?
.unwrap_or(BlockHeight::from(latest_block_height));
let starting_recorded_height = match self.gas_price_db.get_recorded_height()? {
Some(height) => height,
None => {
let mut storage_tx = self.gas_price_db.begin_transaction()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where do you commit this transaction? Also, maybe it makes sense to allow customization of the gas price height from CLI? For example: you want to sync with the network from genesis block, but you only want to calculate the gas price starting the latest block height, to avoid huge debt because data was not posted during previous blocks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Where do you commit this transaction?

Hmm. I'll double check that it makes sense. I got the test to pass so I assumed it was okay but you're right. Might be able to move this to the sync section.

Also, maybe it makes sense to allow customization of the gas price height from CLI?

Yeah. I think that's a good idea.

storage_tx.set_recorded_height(BlockHeight::from(latest_block_height))?;
AtomicStorage::commit_transaction(storage_tx)?;
BlockHeight::from(latest_block_height)
}
};

let poll_duration = self.config.da_poll_interval;
let latest_l2_height = Arc::new(AtomicU32::new(latest_block_height));
Expand Down
Loading