Compare commits
No commits in common. "main" and "pallet-slow-clap" have entirely different histories.
main
...
pallet-slo
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1186,7 +1186,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "casper-runtime"
|
||||
version = "3.5.37"
|
||||
version = "3.5.35"
|
||||
dependencies = [
|
||||
"casper-runtime-constants",
|
||||
"frame-benchmarking",
|
||||
@ -3837,7 +3837,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ghost-slow-clap"
|
||||
version = "0.4.10"
|
||||
version = "0.4.5"
|
||||
dependencies = [
|
||||
"frame-benchmarking",
|
||||
"frame-support",
|
||||
|
||||
126
README.md
126
README.md
@ -150,8 +150,28 @@ rustup default stable
|
||||
rustup update
|
||||
```
|
||||
|
||||
Add the nightly release and the nightly WebAssembly (wasm) targets
|
||||
to your development environment by running the following commands:
|
||||
```bash
|
||||
rustup target add wasm32-unknown-unknown --toolchain stable
|
||||
rustup update nightly
|
||||
```
|
||||
|
||||
```bash
|
||||
rustup target add wasm32-unknown-unknown --toolchain nightly
|
||||
```
|
||||
|
||||
```bash
|
||||
rustup target add wasm32-unknown-unknown --toolchain stable-x86_64-unknown-linux-gnu
|
||||
```
|
||||
|
||||
If you are trying to install WebAssembly (wasm) on an ARM-based processor like the ones in Raspberry Pi try this instead:
|
||||
```bash
|
||||
rustup target add wasm32-unknown-unknown --toolchain stable-aarch64-unknown-linux-gnu
|
||||
```
|
||||
|
||||
**_IF error try_**
|
||||
```bash
|
||||
rustup target add wasm32-unknown-unknown --toolchain default
|
||||
```
|
||||
|
||||
Verify the configuration of your development environment by running
|
||||
@ -160,6 +180,10 @@ the following command:
|
||||
rustup show
|
||||
```
|
||||
|
||||
```bash
|
||||
rustup +nightly show
|
||||
```
|
||||
|
||||
You should see something like this:
|
||||
|
||||

|
||||
@ -170,6 +194,13 @@ Now run:
|
||||
rustup component add rust-src --toolchain stable
|
||||
```
|
||||
|
||||
**_IF error try_**
|
||||
```bash
|
||||
rustup component add rust-src --toolchain default
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Install GHOST
|
||||
|
||||
Check if Git is already installed:
|
||||
@ -180,7 +211,7 @@ git --version
|
||||
|
||||
Make a GHOST Directory and go to it:
|
||||
```bash
|
||||
mkdir ~/ghost && cd ~/ghost
|
||||
mkdir ghost && cd ghost
|
||||
```
|
||||
|
||||
Clone GHOST Node Git:
|
||||
@ -195,7 +226,7 @@ cd ghost-node
|
||||
|
||||
Compile the node template by running the following command:
|
||||
```bash
|
||||
./scripts/starter.sh --release
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
The build can take up to 20 minutes depending on the specifications of your machine.
|
||||
@ -203,6 +234,7 @@ The build can take up to 20 minutes depending on the specifications of your mach
|
||||

|
||||
|
||||
|
||||
|
||||
# Boot Node Qualification
|
||||
|
||||
## Boot Node Qualification Test
|
||||
@ -288,7 +320,7 @@ Only `port 30333` should be opened.
|
||||
|
||||
Press _CTRL+C_ to stop the node.
|
||||
|
||||
# Launching GHOST TestNet
|
||||
# Launching GHOST TestNet 3.1
|
||||
|
||||
Switch to main GIT branch:
|
||||
```bash
|
||||
@ -316,7 +348,66 @@ To generate the node key use the following command:
|
||||
./target/release/ghost key generate-node-key --bin --file=/etc/ghost/node-key
|
||||
```
|
||||
|
||||
Feel free to backup the file on a separate storage device.
|
||||
Generate Wallet Key file with the following command:
|
||||
```bash
|
||||
./target/release/ghost key generate | grep "Secret seed" | awk '{$1=$2=""; sub(/^[ \t]+/, ""); print}' > /etc/ghost/wallet-key
|
||||
```
|
||||
|
||||
Display the wallet-key on the screen by using cat command:
|
||||
```bash
|
||||
./target/release/ghost key inspect $(cat /etc/ghost/wallet-key)
|
||||
```
|
||||

|
||||
|
||||
Feel free to back the file on a separate storage device.
|
||||
|
||||
Generate Stash Key file with the following command:
|
||||
```bash
|
||||
./target/release/ghost key generate | grep "Secret seed" | awk '{$1=$2=""; sub(/^[ \t]+/, ""); print}' > /etc/ghost/stash-key
|
||||
```
|
||||
|
||||
Display the stash-key on the screen by using cat command:
|
||||
```bash
|
||||
./target/release/ghost key inspect $(cat /etc/ghost/stash-key)
|
||||
```
|
||||

|
||||
|
||||
Generate Session Key file with the following command:
|
||||
```bash
|
||||
./target/release/ghost key generate | grep "Secret seed" | awk '{$1=$2=""; sub(/^[ \t]+/, ""); print}' > /etc/ghost/session-key
|
||||
```
|
||||
You have generates 4 types of Session Keys:
|
||||
|
||||
1. Session Key – AUDI
|
||||
2. Session Key – BABE
|
||||
3. Session Key – SLOW
|
||||
4. Session Key – GRAN
|
||||
|
||||
Now let's display them!
|
||||
|
||||
Display the session-key//audi on the screen by using cat command:
|
||||
```bash
|
||||
./target/release/ghost key inspect "$(cat /etc/ghost/session-key)//audi"
|
||||
```
|
||||

|
||||
|
||||
Display the session-key//babe on the screen by using cat command:
|
||||
```bash
|
||||
./target/release/ghost key inspect "$(cat /etc/ghost/session-key)//babe"
|
||||
```
|
||||

|
||||
|
||||
Display the session-key//slow on the screen by using cat command:
|
||||
```bash
|
||||
./target/release/ghost key inspect "$(cat /etc/ghost/session-key)//slow"
|
||||
```
|
||||

|
||||
|
||||
Display the session-key//gran on the screen by using cat command:
|
||||
```bash
|
||||
./target/release/ghost key inspect "$(cat /etc/ghost/session-key)//gran" --scheme=ed25519
|
||||
```
|
||||

|
||||
|
||||
## Build and start the ghost-node
|
||||
|
||||
@ -346,7 +437,7 @@ sha256sum /etc/ghost/casper.json
|
||||
|
||||
You should see:
|
||||
```
|
||||
9da6045ed6d4fd844e3939573b31c013d0e564e542029330faa6d978cb4a915a
|
||||
ad653233c978bfd00c5e4525b17628632bc4319c5f5f4b4dcc2f050ef3c3d145
|
||||
```
|
||||
|
||||
Create running `ghost-node` service that starts on system boot using `--unit-file` flag.
|
||||
@ -372,7 +463,10 @@ To choose default options press Enter here:
|
||||
|
||||

|
||||
|
||||
If you want to validate from this node press Enter:
|
||||
Currently, you have to qualify to become a validator node through [GHOST Whales](https://ghostchain.io/whales-apply).
|
||||
If you were NOT included in the [ghosties file](https://git.ghostchain.io/ghostchain/ghost-node/src/branch/main/service/ghosties) then you cannot be a validator node,
|
||||
and you can only be a full node so for `disable validator mode? [y/N]` type `y`.
|
||||
If you were included in the ghosties file you can press Enter:
|
||||
```
|
||||
disable validator mode? [y/N]: y
|
||||
```
|
||||
@ -417,6 +511,17 @@ Type `y` and press _Enter_ for create dedicated user for running `ghost-node`:
|
||||
|
||||

|
||||
|
||||
Now you can check whether or not the keys on your GHOST Node match those
|
||||
in the [ghosties file](https://git.ghostchain.io/ghostchain/ghost-node/src/branch/main/service/ghosties) on GHOST Git.
|
||||
If you are running a **Validator Node** and if you have followed
|
||||
the Generating Keys Part you will see all `[+]`.
|
||||
If you are a running a **Full Node** you will see errors:
|
||||
|
||||
(Press _Enter_ for prompts)
|
||||
```bash
|
||||
./scripts/starter.sh --check-keys
|
||||
```
|
||||
|
||||
Full Node:
|
||||
|
||||

|
||||
@ -430,7 +535,7 @@ Start `ghost-node`:
|
||||
sudo systemctl start ghost-node
|
||||
```
|
||||
|
||||
Wait ~60 seconds!
|
||||
Wait 60 seconds!
|
||||
|
||||
Check node is started:
|
||||
```bash
|
||||
@ -440,6 +545,11 @@ sudo systemctl status ghost-node
|
||||
|
||||
For exit press _CTRL+C_
|
||||
|
||||
In order to insert keys run the following flags `--check-keys` `--insert-keys`:
|
||||
```bash
|
||||
./scripts/starter.sh --check-keys --insert-keys
|
||||
```
|
||||
|
||||
Restart `ghost-node`:
|
||||
```bash
|
||||
sudo systemctl restart ghost-node
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ghost-slow-clap"
|
||||
version = "0.4.10"
|
||||
version = "0.4.5"
|
||||
description = "Applause protocol for the EVM bridge"
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
@ -347,7 +347,6 @@ pub mod pallet {
|
||||
TimeWentBackwards,
|
||||
DisabledAuthority,
|
||||
ExecutedBlockIsHigher,
|
||||
CommitInWrongSession,
|
||||
}
|
||||
|
||||
#[pallet::storage]
|
||||
@ -455,11 +454,13 @@ pub mod pallet {
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn offchain_worker(now: BlockNumberFor<T>) {
|
||||
match Self::start_slow_clapping(now) {
|
||||
Ok(_) => {
|
||||
log::info!(target: LOG_TARGET, "👻 Slow Clap #{:?} finished gracefully", now)
|
||||
}
|
||||
Err(e) => log::info!(target: LOG_TARGET, "👻 Slow Clap #{:?} failed: {:?}", now, e),
|
||||
if let Err(e) = Self::start_slow_clapping(now) {
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"👻 Skipping slow clap at {:?}: {:?}",
|
||||
now,
|
||||
e,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -712,31 +713,19 @@ impl<T: Config> Pallet<T> {
|
||||
fn try_commit_block(new_commitment: &BlockCommitment<NetworkIdOf<T>>) -> DispatchResult {
|
||||
let authority_index = new_commitment.authority_index;
|
||||
let network_id = new_commitment.network_id;
|
||||
let session_index = T::ValidatorSet::session_index();
|
||||
|
||||
ensure!(
|
||||
T::NetworkDataHandler::get(&network_id).is_some(),
|
||||
Error::<T>::UnregistedNetwork
|
||||
);
|
||||
|
||||
ensure!(
|
||||
new_commitment.session_index == session_index,
|
||||
Error::<T>::CommitInWrongSession,
|
||||
);
|
||||
|
||||
let block_commitments = BlockCommitments::<T>::try_mutate(
|
||||
let current_commits = BlockCommitments::<T>::try_mutate(
|
||||
&network_id,
|
||||
|current_commitments| -> Result<BTreeMap<AuthIndex, CommitmentDetails>, DispatchError> {
|
||||
|current_commitments| -> Result<u64, DispatchError> {
|
||||
let mut new_commitment_details = new_commitment.commitment;
|
||||
|
||||
let (current_commits, current_last_updated) = current_commitments
|
||||
.get(&authority_index)
|
||||
.map(|details| {
|
||||
(
|
||||
details.commits.saturating_add(1),
|
||||
details.last_updated.saturating_add(COMMITMENT_DELAY_MILLIS),
|
||||
)
|
||||
})
|
||||
.map(|details| (details.commits + 1, details.last_updated))
|
||||
.unwrap_or((1, 0));
|
||||
|
||||
ensure!(
|
||||
@ -747,21 +736,19 @@ impl<T: Config> Pallet<T> {
|
||||
new_commitment_details.commits = current_commits;
|
||||
current_commitments.insert(authority_index, new_commitment_details);
|
||||
|
||||
Ok(current_commitments.clone())
|
||||
Ok(current_commits)
|
||||
},
|
||||
)?;
|
||||
|
||||
let current_commits = block_commitments
|
||||
.get(&authority_index)
|
||||
.map(|details| details.commits)
|
||||
.unwrap_or(1);
|
||||
|
||||
Self::deposit_event(Event::<T>::BlockCommited {
|
||||
network_id,
|
||||
authority_id: authority_index,
|
||||
});
|
||||
|
||||
let session_index = T::ValidatorSet::session_index();
|
||||
let validators = Validators::<T>::get(&session_index);
|
||||
let block_commitments = BlockCommitments::<T>::get(&network_id);
|
||||
|
||||
let disabled_bitmap = DisabledAuthorityIndexes::<T>::get(&session_index)
|
||||
.unwrap_or(BitMap::new(validators.len() as u32));
|
||||
|
||||
@ -773,7 +760,7 @@ impl<T: Config> Pallet<T> {
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
if current_commits % 3 == 0 && validators.len() > 0 {
|
||||
if current_commits > 2 && validators.len() > 0 {
|
||||
let offence_bitmap = Self::capture_deviation_in_commitments_and_remove(
|
||||
&disabled_bitmap,
|
||||
&block_commitments,
|
||||
@ -796,45 +783,46 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
fn start_slow_clapping(block_number: BlockNumberFor<T>) -> OffchainResult<T, ()> {
|
||||
let session_index = T::ValidatorSet::session_index();
|
||||
let networks = T::NetworkDataHandler::iter().collect::<Vec<_>>();
|
||||
let network_index = block_number
|
||||
.into()
|
||||
.as_usize()
|
||||
.checked_rem(networks.len())
|
||||
.unwrap_or_default();
|
||||
|
||||
let network_in_use = networks
|
||||
.iter()
|
||||
.nth(network_index)
|
||||
let networks_len = T::NetworkDataHandler::iter().count();
|
||||
let network_in_use = T::NetworkDataHandler::iter()
|
||||
.nth(
|
||||
block_number
|
||||
.into()
|
||||
.as_usize()
|
||||
.checked_rem(networks_len)
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.ok_or(OffchainErr::NoStoredNetworks)?;
|
||||
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"👻 Slow Clap #{:?} started for network #{:?}",
|
||||
block_number,
|
||||
network_in_use.0,
|
||||
let network_id_encoded = network_in_use.0.encode();
|
||||
|
||||
let rate_limit_delay_key = Self::create_storage_key(b"rate-limit-", &network_id_encoded);
|
||||
let rate_limit_delay = Self::read_persistent_offchain_storage(
|
||||
&rate_limit_delay_key,
|
||||
network_in_use.1.rate_limit_delay,
|
||||
);
|
||||
|
||||
let network_id_encoded = network_in_use.0.encode();
|
||||
let network_lock_key = Self::create_storage_key(b"network-lock-", &network_id_encoded);
|
||||
let lock_until = rt_offchain::Duration::from_millis(MIN_LOCK_GUARD_PERIOD);
|
||||
let mut network_lock = StorageLock::<Time>::with_deadline(&network_lock_key, lock_until);
|
||||
let block_until =
|
||||
rt_offchain::Duration::from_millis(rate_limit_delay.max(MIN_LOCK_GUARD_PERIOD));
|
||||
let mut network_lock = StorageLock::<Time>::with_deadline(&network_lock_key, block_until);
|
||||
|
||||
let _lock_guard = network_lock
|
||||
.try_lock()
|
||||
.map_err(|_| OffchainErr::OffchainTimeoutPeriod(network_in_use.0))?;
|
||||
|
||||
Self::do_evm_claps_or_save_block(
|
||||
session_index,
|
||||
block_number,
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"👻 Offchain worker started for network #{:?} at block #{:?}",
|
||||
network_in_use.0,
|
||||
&network_in_use.1,
|
||||
)
|
||||
block_number,
|
||||
);
|
||||
|
||||
Self::do_evm_claps_or_save_block(session_index, network_in_use.0, &network_in_use.1)
|
||||
}
|
||||
|
||||
fn do_evm_claps_or_save_block(
|
||||
session_index: SessionIndex,
|
||||
block_number: BlockNumberFor<T>,
|
||||
network_id: NetworkIdOf<T>,
|
||||
network_data: &NetworkData,
|
||||
) -> OffchainResult<T, ()> {
|
||||
@ -911,8 +899,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"👻 Slow Clap #{:?} stored block #{:?} for network {:?}",
|
||||
block_number,
|
||||
"👻 Stored from_block is #{:?} for network {:?}",
|
||||
new_block_range.0,
|
||||
network_id,
|
||||
);
|
||||
@ -1089,7 +1076,7 @@ impl<T: Config> Pallet<T> {
|
||||
debug_assert!(cursor.maybe_cursor.is_none());
|
||||
}
|
||||
|
||||
fn calculate_median_value(values: &mut Vec<(AuthIndex, u64)>) -> u64 {
|
||||
fn calculate_weighted_median(values: &mut Vec<(AuthIndex, u64)>) -> u64 {
|
||||
values.sort_by_key(|data| data.1);
|
||||
|
||||
let length = values.len();
|
||||
@ -1137,8 +1124,8 @@ impl<T: Config> Pallet<T> {
|
||||
time_updates.push((authority_index, data.last_updated));
|
||||
}
|
||||
|
||||
let stored_block_median = Self::calculate_median_value(&mut stored_blocks);
|
||||
let time_update_median = Self::calculate_median_value(&mut time_updates);
|
||||
let stored_block_median = Self::calculate_weighted_median(&mut stored_blocks);
|
||||
let time_update_median = Self::calculate_weighted_median(&mut time_updates);
|
||||
|
||||
Self::apply_median_deviation(
|
||||
&mut delayed,
|
||||
@ -1225,9 +1212,8 @@ impl<T: Config> Pallet<T> {
|
||||
})
|
||||
.collect::<Vec<IdentificationTuple<T>>>();
|
||||
|
||||
let disabled_or_offence_bitmap = disabled_bitmap.bitor(offence_bitmap);
|
||||
let not_enough_validators_left = validator_set_count
|
||||
.saturating_sub(disabled_or_offence_bitmap.count_ones())
|
||||
.saturating_sub(disabled_bitmap.bitor(offence_bitmap).count_ones())
|
||||
.lt(&T::MinAuthoritiesNumber::get());
|
||||
|
||||
if not_enough_validators_left && offenders.len() > 0 {
|
||||
@ -1262,17 +1248,7 @@ impl<T: Config> Pallet<T> {
|
||||
offence_type,
|
||||
};
|
||||
|
||||
let reporters = validators
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, _)| {
|
||||
(!disabled_or_offence_bitmap.exists(&(index as AuthIndex)))
|
||||
.then(|| T::ExposureListener::get_account_by_index(index))
|
||||
.flatten()
|
||||
})
|
||||
.collect();
|
||||
|
||||
if let Err(e) = T::ReportUnresponsiveness::report_offence(reporters, offence) {
|
||||
if let Err(e) = T::ReportUnresponsiveness::report_offence(vec![], offence) {
|
||||
sp_runtime::print(e);
|
||||
}
|
||||
}
|
||||
@ -1398,10 +1374,10 @@ impl<Offender: Clone> Offence<Offender> for SlowClapOffence<Offender> {
|
||||
missed_percent.saturating_mul(Perbill::from_rational(1, offenders_count))
|
||||
}
|
||||
OffenceType::CommitmentOffence => offenders_count
|
||||
.checked_sub(Perbill::from_percent(9).mul_ceil(self.validator_set_count))
|
||||
.checked_sub(self.validator_set_count / 10 + 1)
|
||||
.map(|threshold| {
|
||||
Perbill::from_rational(threshold.saturating_mul(4), self.validator_set_count)
|
||||
.square()
|
||||
Perbill::from_rational(3 * threshold, self.validator_set_count)
|
||||
.saturating_mul(Perbill::from_percent(7))
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ fn should_calculate_throttling_slash_function_correctly() {
|
||||
|
||||
let dummy_offence = SlowClapOffence {
|
||||
session_index: 0,
|
||||
validator_set_count: 100,
|
||||
validator_set_count: 50,
|
||||
offenders: vec![()],
|
||||
offence_type: OffenceType::CommitmentOffence,
|
||||
};
|
||||
@ -39,22 +39,13 @@ fn should_calculate_throttling_slash_function_correctly() {
|
||||
assert_eq!(dummy_offence.slash_fraction(1), Perbill::zero());
|
||||
assert_eq!(dummy_offence.slash_fraction(5), Perbill::zero());
|
||||
assert_eq!(
|
||||
dummy_offence.slash_fraction(15),
|
||||
Perbill::from_parts(57_600_000)
|
||||
dummy_offence.slash_fraction(7),
|
||||
Perbill::from_parts(4_200_000)
|
||||
);
|
||||
assert_eq!(
|
||||
dummy_offence.slash_fraction(20),
|
||||
Perbill::from_parts(193_600_000)
|
||||
dummy_offence.slash_fraction(17),
|
||||
Perbill::from_parts(46_200_000)
|
||||
);
|
||||
assert_eq!(
|
||||
dummy_offence.slash_fraction(25),
|
||||
Perbill::from_parts(409_600_000)
|
||||
);
|
||||
assert_eq!(
|
||||
dummy_offence.slash_fraction(30),
|
||||
Perbill::from_parts(705_600_000)
|
||||
);
|
||||
assert_eq!(dummy_offence.slash_fraction(50), Perbill::one());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1017,8 +1008,8 @@ fn should_disable_on_commitment_inactivity() {
|
||||
};
|
||||
|
||||
// two block commitments
|
||||
for extra_time in 1..=3 {
|
||||
block_commitment.last_updated += COMMITMENT_DELAY_MILLIS + extra_time;
|
||||
for extra_time in 0..=2 {
|
||||
block_commitment.last_updated += extra_time;
|
||||
for i in 0..3 {
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
@ -1075,9 +1066,9 @@ fn should_disable_on_commitment_block_deviation() {
|
||||
};
|
||||
|
||||
// two block commitments
|
||||
for extra_time in 1..=3 {
|
||||
block_commitment.last_updated += COMMITMENT_DELAY_MILLIS + extra_time;
|
||||
bad_block_commitment.last_updated += COMMITMENT_DELAY_MILLIS + extra_time;
|
||||
for extra_time in 0..=2 {
|
||||
block_commitment.last_updated += extra_time;
|
||||
bad_block_commitment.last_updated += extra_time;
|
||||
for i in 0..3 {
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
@ -1102,73 +1093,6 @@ fn should_disable_on_commitment_block_deviation() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_throw_error_on_fast_commitments() {
|
||||
let (network_id, _, _) = generate_unique_hash(None, None, None, None, None);
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let session_index = advance_session_and_get_index();
|
||||
prepare_evm_network(None, None);
|
||||
|
||||
let timestamp = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("Time went backwards")
|
||||
.as_millis() as u64;
|
||||
|
||||
let mut block_commitment = CommitmentDetails {
|
||||
last_stored_block: 9_500_000,
|
||||
commits: 420,
|
||||
last_updated: timestamp,
|
||||
};
|
||||
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
network_id,
|
||||
0,
|
||||
&block_commitment
|
||||
));
|
||||
assert_err!(
|
||||
do_block_commitment(session_index, network_id, 0, &block_commitment),
|
||||
Error::<Runtime>::TimeWentBackwards,
|
||||
);
|
||||
|
||||
block_commitment.last_updated += COMMITMENT_DELAY_MILLIS / 2;
|
||||
assert_err!(
|
||||
do_block_commitment(session_index, network_id, 0, &block_commitment),
|
||||
Error::<Runtime>::TimeWentBackwards,
|
||||
);
|
||||
|
||||
block_commitment.last_updated += COMMITMENT_DELAY_MILLIS / 2;
|
||||
assert_err!(
|
||||
do_block_commitment(session_index, network_id, 0, &block_commitment),
|
||||
Error::<Runtime>::TimeWentBackwards,
|
||||
);
|
||||
|
||||
block_commitment.last_updated += 1;
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
network_id,
|
||||
0,
|
||||
&block_commitment
|
||||
));
|
||||
|
||||
block_commitment.last_updated = timestamp;
|
||||
assert_err!(
|
||||
do_block_commitment(session_index, network_id, 0, &block_commitment),
|
||||
Error::<Runtime>::TimeWentBackwards,
|
||||
);
|
||||
|
||||
for commitment_details in BlockCommitments::<Runtime>::get(network_id).values() {
|
||||
assert_eq!(commitment_details.last_stored_block, 9_500_000);
|
||||
assert_eq!(
|
||||
commitment_details.last_updated,
|
||||
timestamp + COMMITMENT_DELAY_MILLIS + 1
|
||||
);
|
||||
assert_eq!(commitment_details.commits, 2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_offend_disabled_authorities() {
|
||||
let (network_id, _, _) = generate_unique_hash(None, None, None, None, None);
|
||||
@ -1195,8 +1119,8 @@ fn should_not_offend_disabled_authorities() {
|
||||
Session::disable_index(3);
|
||||
|
||||
// two block commitments
|
||||
for extra_time in 1..=3 {
|
||||
block_commitment.last_updated += COMMITMENT_DELAY_MILLIS + extra_time;
|
||||
for extra_time in 0..=2 {
|
||||
block_commitment.last_updated += extra_time;
|
||||
for i in 0..3 {
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
@ -1240,8 +1164,8 @@ fn should_not_slash_by_applause_if_disabled_by_commitment() {
|
||||
Session::disable_index(3);
|
||||
|
||||
// two block commitments
|
||||
for extra_time in 1..=3 {
|
||||
block_commitment.last_updated += COMMITMENT_DELAY_MILLIS + extra_time;
|
||||
for extra_time in 0..=2 {
|
||||
block_commitment.last_updated += extra_time;
|
||||
for i in 0..3 {
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
@ -1279,18 +1203,20 @@ fn should_not_nullify_on_incorrect_block_commitment() {
|
||||
|
||||
for i in 0..4 {
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
network_id,
|
||||
i,
|
||||
&block_commitment
|
||||
session_index,
|
||||
network_id,
|
||||
i,
|
||||
&block_commitment
|
||||
));
|
||||
}
|
||||
|
||||
block_commitment.last_updated = 0;
|
||||
assert_err!(
|
||||
do_block_commitment(session_index, network_id, 3, &block_commitment),
|
||||
Error::<Runtime>::TimeWentBackwards
|
||||
);
|
||||
assert_err!(do_block_commitment(
|
||||
session_index,
|
||||
network_id,
|
||||
3,
|
||||
&block_commitment),
|
||||
Error::<Runtime>::TimeWentBackwards);
|
||||
|
||||
for commitment_details in BlockCommitments::<Runtime>::get(network_id).values() {
|
||||
assert_eq!(commitment_details.last_stored_block, 9_500_000);
|
||||
@ -1300,61 +1226,6 @@ fn should_not_nullify_on_incorrect_block_commitment() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_split_commit_slash_between_active_validators() {
|
||||
let (network_id, _, _) = generate_unique_hash(None, None, None, None, None);
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let session_index = advance_session_and_get_index();
|
||||
prepare_evm_network(None, None);
|
||||
|
||||
let timestamp = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.expect("Time went backwards")
|
||||
.as_millis() as u64;
|
||||
|
||||
let mut block_commitment = CommitmentDetails {
|
||||
last_stored_block: 9_500_000,
|
||||
commits: 420,
|
||||
last_updated: timestamp,
|
||||
};
|
||||
|
||||
for extra_time in 1..=3 {
|
||||
if extra_time < 3 {
|
||||
let offences = Offences::get();
|
||||
assert_eq!(offences.len(), 0);
|
||||
}
|
||||
|
||||
block_commitment.last_updated += COMMITMENT_DELAY_MILLIS + extra_time;
|
||||
for i in 0..3 {
|
||||
assert_ok!(do_block_commitment(
|
||||
session_index,
|
||||
network_id,
|
||||
i,
|
||||
&block_commitment
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
System::assert_has_event(RuntimeEvent::SlowClap(
|
||||
crate::Event::SomeAuthoritiesDelayed {
|
||||
delayed: vec![(3, 3)],
|
||||
},
|
||||
));
|
||||
|
||||
let offences = Offences::get();
|
||||
assert_eq!(offences.len(), 3);
|
||||
for offence in offences {
|
||||
assert_eq!(offence.0, vec![0, 1, 2]);
|
||||
assert_eq!(offence.1.session_index, session_index);
|
||||
assert_eq!(offence.1.validator_set_count, 4);
|
||||
assert_eq!(offence.1.offenders, vec![(3, 3)]);
|
||||
assert_eq!(offence.1.validator_set_count, 4);
|
||||
assert_eq!(offence.1.offence_type, OffenceType::CommitmentOffence);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn assert_clapped_amount(
|
||||
session_index: &SessionIndex,
|
||||
unique_hash: &H256,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "casper-runtime"
|
||||
version = "3.5.37"
|
||||
version = "3.5.35"
|
||||
build = "build.rs"
|
||||
description = "Runtime of the Casper Network"
|
||||
edition.workspace = true
|
||||
|
||||
@ -117,8 +117,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("casper"),
|
||||
impl_name: create_runtime_str!("casper-svengali"),
|
||||
authoring_version: 0,
|
||||
spec_version: 4,
|
||||
impl_version: 3,
|
||||
spec_version: 3,
|
||||
impl_version: 1,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 1,
|
||||
|
||||
@ -81,18 +81,20 @@ extract_seed() {
|
||||
}
|
||||
|
||||
downgrade_compiler_if_needed() {
|
||||
echo "[+] fetching the latest ghost-node source code"
|
||||
git switch main
|
||||
git pull origin main
|
||||
# TODO: uncomment later
|
||||
# echo "[+] fetching the latest ghost-node source code"
|
||||
# git switch main
|
||||
# git pull origin main
|
||||
|
||||
# 1.86.0 works fine, tested with:
|
||||
# 1.83.0 works fine, tested with:
|
||||
# ...
|
||||
# 1.87.0 throws errors during compilation
|
||||
# 1.88.0 throws errors during compilation
|
||||
LATEST_TESTED_VERSION=86
|
||||
LATEST_TESTED_VERSION=83
|
||||
cargo_version=$(cargo --version | cut -d'.' -f2)
|
||||
if [ "$cargo_version" -gt "$LATEST_TESTED_VERSION" ]; then
|
||||
echo "[+] downgrading rustc compiler version to 1.86.0"
|
||||
rustup default 1.86.0
|
||||
echo "[+] downgrading rustc compiler version to 1.83.0"
|
||||
rustup default 1.83.0
|
||||
toolchain_name=$(rustup show | grep default | head -n 1 | cut -d' ' -f1)
|
||||
rustup target add wasm32-unknown-unknown --toolchain $toolchain_name
|
||||
rustup component add rust-src --toolchain $toolchain_name
|
||||
@ -226,11 +228,11 @@ if [[ $HARD_RESET = true ]]; then
|
||||
echo "[+] trying to remove locally stored ledger"
|
||||
sudo rm -rf "$BASE_PATH/chains/casper_staging_testnet"
|
||||
|
||||
cd $PROJECT_FOLDER
|
||||
git switch main
|
||||
git pull origin main
|
||||
echo "[+] starting build in 3 seconds..."
|
||||
sleep 3
|
||||
# TODO: remove before merging to main
|
||||
#cd $PROJECT_FOLDER
|
||||
#git pull origin main
|
||||
#echo "[+] starting build in 3 seconds..."
|
||||
#sleep 3
|
||||
cargo build --release
|
||||
|
||||
printf "[?] are you ready to continue?"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user