From 6d77a3a8a569bdaeb452ecdb58ec79299a240097 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 31 Aug 2020 12:01:51 +1000 Subject: [PATCH] Implement interchange format v2 --- .../slashing_protection/src/interchange.rs | 11 ++++++----- .../slashing_protection/src/interchange_tests.rs | 6 +++--- validator_client/slashing_protection/src/lib.rs | 2 +- .../slashing_protection/src/slashing_database.rs | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/validator_client/slashing_protection/src/interchange.rs b/validator_client/slashing_protection/src/interchange.rs index 21fab12e963..4ee9475a934 100644 --- a/validator_client/slashing_protection/src/interchange.rs +++ b/validator_client/slashing_protection/src/interchange.rs @@ -12,7 +12,8 @@ pub enum InterchangeFormat { #[serde(deny_unknown_fields)] pub struct InterchangeMetadata { pub interchange_format: InterchangeFormat, - pub interchange_format_version: u16, + #[serde(with = "types::serde_utils::quoted")] + pub interchange_format_version: u64, pub genesis_validators_root: Hash256, } @@ -97,15 +98,15 @@ mod test { { "metadata": { "interchange_format": "minimal", - "interchange_format_version": 1, + "interchange_format_version": "2", "genesis_validators_root": "0x04700007fabc8282644aed6d1c7c9e21d38a03a0c4ba193f3afe428824b3a673" }, "data": [ { "pubkey": "0xb845089a1457f811bfc000588fbb4e713669be8ce060ea6be3c6ece09afc3794106c91ca73acda5e5457122d58723bed", - "last_signed_block_slot": 89765, - "last_signed_attestation_source_epoch": 2990, - "last_signed_attestation_target_epoch": 3007 + "last_signed_block_slot": "89765", + "last_signed_attestation_source_epoch": "2990", + "last_signed_attestation_target_epoch": "3007" } ] } diff --git a/validator_client/slashing_protection/src/interchange_tests.rs b/validator_client/slashing_protection/src/interchange_tests.rs index 6df652be8d9..10b86bfd2b8 100644 --- a/validator_client/slashing_protection/src/interchange_tests.rs +++ b/validator_client/slashing_protection/src/interchange_tests.rs @@ -4,7 +4,7 @@ use crate::interchange::{ Interchange, InterchangeData, InterchangeFormat, InterchangeMetadata, MinimalInterchangeData, }; use crate::test_utils::pubkey; -use crate::{InvalidBlock, NotSafe, SlashingDatabase}; +use crate::{InvalidBlock, NotSafe, SlashingDatabase, SUPPORTED_INTERCHANGE_FORMAT_VERSION}; use tempfile::tempdir; use types::{Epoch, Hash256, Slot}; @@ -78,7 +78,7 @@ fn import_minimal_test(data: Vec) { let interchange = Interchange { metadata: InterchangeMetadata { interchange_format: InterchangeFormat::Minimal, - interchange_format_version: 1, + interchange_format_version: SUPPORTED_INTERCHANGE_FORMAT_VERSION, genesis_validators_root, }, data: InterchangeData::Minimal(data.clone()), @@ -161,7 +161,7 @@ fn double_import_minimal(data: Vec) { let interchange = Interchange { metadata: InterchangeMetadata { interchange_format: InterchangeFormat::Minimal, - interchange_format_version: 1, + interchange_format_version: SUPPORTED_INTERCHANGE_FORMAT_VERSION, genesis_validators_root, }, data: InterchangeData::Minimal(data.clone()), diff --git a/validator_client/slashing_protection/src/lib.rs b/validator_client/slashing_protection/src/lib.rs index 8fc3318546f..5adb1fe2cef 100644 --- a/validator_client/slashing_protection/src/lib.rs +++ b/validator_client/slashing_protection/src/lib.rs @@ -12,7 +12,7 @@ mod test_utils; pub use crate::signed_attestation::{InvalidAttestation, SignedAttestation}; pub use crate::signed_block::{InvalidBlock, SignedBlock}; -pub use crate::slashing_database::SlashingDatabase; +pub use crate::slashing_database::{SlashingDatabase, SUPPORTED_INTERCHANGE_FORMAT_VERSION}; use rusqlite::Error as SQLError; use std::io::{Error as IOError, ErrorKind}; use std::string::ToString; diff --git a/validator_client/slashing_protection/src/slashing_database.rs b/validator_client/slashing_protection/src/slashing_database.rs index f6f843de761..9eb6fae6a1b 100644 --- a/validator_client/slashing_protection/src/slashing_database.rs +++ b/validator_client/slashing_protection/src/slashing_database.rs @@ -26,7 +26,7 @@ pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(5); pub const CONNECTION_TIMEOUT: Duration = Duration::from_millis(100); /// Supported version of the interchange format. -pub const SUPPORTED_INTERCHANGE_FORMAT_VERSION: u16 = 1; +pub const SUPPORTED_INTERCHANGE_FORMAT_VERSION: u64 = 2; #[derive(Debug, Clone)] pub struct SlashingDatabase { @@ -735,7 +735,7 @@ impl SlashingDatabase { #[derive(Debug)] pub enum InterchangeError { - UnsupportedVersion(u16), + UnsupportedVersion(u64), GenesisValidatorsMismatch { interchange_file: Hash256, client: Hash256,