Skip to content

Commit

Permalink
Implement interchange format v2
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Aug 31, 2020
1 parent 7784a78 commit 6d77a3a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions validator_client/slashing_protection/src/interchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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"
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions validator_client/slashing_protection/src/interchange_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -78,7 +78,7 @@ fn import_minimal_test(data: Vec<MinimalInterchangeData>) {
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()),
Expand Down Expand Up @@ -161,7 +161,7 @@ fn double_import_minimal(data: Vec<MinimalInterchangeData>) {
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()),
Expand Down
2 changes: 1 addition & 1 deletion validator_client/slashing_protection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions validator_client/slashing_protection/src/slashing_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -735,7 +735,7 @@ impl SlashingDatabase {

#[derive(Debug)]
pub enum InterchangeError {
UnsupportedVersion(u16),
UnsupportedVersion(u64),
GenesisValidatorsMismatch {
interchange_file: Hash256,
client: Hash256,
Expand Down

0 comments on commit 6d77a3a

Please sign in to comment.