Skip to content

Commit

Permalink
Make genesis block timestamp hardcoded. (#2476)
Browse files Browse the repository at this point in the history
Genesis block need to always have the same timestamp. We updated
`formats` that changed the leap seconds and changed the timestamp of
genesis. This PR hardcode it forever.

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [x] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself
- [x] I have created follow-up issues caused by this PR and linked them
here

---------

Co-authored-by: Green Baneling <[email protected]>
  • Loading branch information
AurelienFT and xgreenx authored Dec 6, 2024
1 parent f9f719a commit 96a16cc
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Fixed

- [2476](https://github.com/FuelLabs/fuel-core/pull/2476): Hardcode the timestamp of the genesis block.

## [Version 0.40.1]

- [2450](https://github.com/FuelLabs/fuel-core/pull/2450): Added support for posting blocks to the shared sequencer.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bin/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ fuel-core-shared-sequencer = { workspace = true, optional = true }
fuel-core-types = { workspace = true, features = ["std"] }
hex = { workspace = true }
humantime = "2.1"
pyroscope = "0.5"
pyroscope_pprofrs = "0.2"
pyroscope = "=0.5.7"
pyroscope_pprofrs = "=0.2.7"
serde_json = { workspace = true }
tikv-jemallocator = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Expand Down
3 changes: 2 additions & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ reqwest = { version = "0.11.16", default-features = false, features = [
] }
serde = { workspace = true, features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
tai64 = { version = "4.0", features = ["serde"] }
# We force the version because 4.1.0 update leap seconds that breaks our timestamps
tai64 = { version = "=4.0.0", features = ["serde"] }
thiserror = "1.0"
tracing = "0.1"

Expand Down
3 changes: 2 additions & 1 deletion crates/fuel-core/src/service/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ pub fn create_genesis_block(config: &Config) -> Block {
consensus: ConsensusHeader::<Empty> {
prev_root,
height,
time: fuel_core_types::tai64::Tai64::UNIX_EPOCH,
// The time is set to UNIX_EPOCH + 10 leap seconds to make backward compatibility
time: fuel_core_types::tai64::Tai64(4611686018427387914),
generated: Empty,
},
},
Expand Down
3 changes: 2 additions & 1 deletion crates/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ k256 = { version = "0.13", default-features = false, features = ["ecdsa"] }
rand = { workspace = true, optional = true }
secrecy = "0.8"
serde = { workspace = true, features = ["derive"], optional = true }
tai64 = { version = "4.0", features = ["serde"] }
# We force the version because 4.1.0 update leap seconds that breaks our timestamps
tai64 = { version = "=4.0.0", features = ["serde"] }
zeroize = "1.5"

[dev-dependencies]
Expand Down
47 changes: 47 additions & 0 deletions version-compatibility/forkless-upgrade/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#![allow(non_snake_case)]
use crate::tests_helper::{
LatestFuelCoreDriver,
IGNITION_TESTNET_SNAPSHOT,
};
use latest_fuel_core_type::fuel_tx::Bytes32;
use std::str::FromStr;

#[tokio::test(flavor = "multi_thread")]
async fn test__genesis_block__hash() {
// Given
let latest_node = LatestFuelCoreDriver::spawn(&[
"--debug",
"--poa-instant",
"true",
"--snapshot",
IGNITION_TESTNET_SNAPSHOT,
"--enable-relayer",
"--relayer",
"https://google.com",
"--relayer-da-deploy-height",
"5791365",
"--relayer-v2-listening-contracts",
"0x768f9459E3339A1F7d59CcF24C80Eb4A711a01FB",
])
.await
.unwrap();

// When
let original_block = latest_node
.client
.block_by_height(0u32.into())
.await
.expect("Failed to get blocks")
.expect("Genesis block should exists");
// Then
// The hash of the genesis block should always be
// `0x19ac99bf59711aca047b28443e599e26f733291c2fa45f5f309b2c5c9712b215`
// regardless of the changes that we made.
assert_eq!(
original_block.id,
Bytes32::from_str(
"0x19ac99bf59711aca047b28443e599e26f733291c2fa45f5f309b2c5c9712b215"
)
.unwrap()
)
}
2 changes: 2 additions & 0 deletions version-compatibility/forkless-upgrade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod backward_compatibility;
#[cfg(test)]
mod forward_compatibility;
#[cfg(test)]
mod genesis;
#[cfg(test)]
pub(crate) mod tests_helper;

#[cfg(test)]
Expand Down

0 comments on commit 96a16cc

Please sign in to comment.