Skip to content

Commit

Permalink
No versioning for ChunkValidatorStats
Browse files Browse the repository at this point in the history
  • Loading branch information
birchmd committed Apr 23, 2024
1 parent 66a8124 commit b1053a8
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 155 deletions.
8 changes: 4 additions & 4 deletions chain/epoch-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,10 @@ impl EpochManager {
.get(info.account_id())
.unwrap_or(&BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 0, expected: 0 },
chunk_stats: ChunkValidatorStats::V1(ValidatorStats {
produced: 0,
expected: 0,
}),
chunk_stats: ChunkValidatorStats {
production: ValidatorStats { produced: 0, expected: 0 },
endorsement: ValidatorStats { produced: 0, expected: 0 },
},
});
let mut shards = validator_to_shard[validator_id]
.iter()
Expand Down
12 changes: 6 additions & 6 deletions chain/epoch-manager/src/reward_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ mod tests {
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 0, expected: 1 },
chunk_stats: ChunkValidatorStats::v1(0, 1),
chunk_stats: ChunkValidatorStats::new_with_production(0, 1),
},
),
]);
Expand Down Expand Up @@ -293,21 +293,21 @@ mod tests {
"test1".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 945, expected: 1000 },
chunk_stats: ChunkValidatorStats::v1(945, 1000),
chunk_stats: ChunkValidatorStats::new_with_production(945, 1000),
},
),
(
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 999, expected: 1000 },
chunk_stats: ChunkValidatorStats::v1(999, 1000),
chunk_stats: ChunkValidatorStats::new_with_production(999, 1000),
},
),
(
"test3".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 850, expected: 1000 },
chunk_stats: ChunkValidatorStats::v1(850, 1000),
chunk_stats: ChunkValidatorStats::new_with_production(850, 1000),
},
),
]);
Expand Down Expand Up @@ -358,15 +358,15 @@ mod tests {
"test1".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 945, expected: 1000 },
chunk_stats: ChunkValidatorStats::v1(945, 1000),
chunk_stats: ChunkValidatorStats::new_with_production(945, 1000),
},
),
// chunk only producer
(
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 0, expected: 0 },
chunk_stats: ChunkValidatorStats::v1(999, 1000),
chunk_stats: ChunkValidatorStats::new_with_production(999, 1000),
},
),
// block only producer (not implemented right now, just for testing)
Expand Down
48 changes: 24 additions & 24 deletions chain/epoch-manager/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ fn test_validator_reward_one_validator() {
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 1, expected: 1 },
chunk_stats: ChunkValidatorStats::v1(1, 1),
chunk_stats: ChunkValidatorStats::new_with_production(1, 1),
},
);
let mut validator_stakes = HashMap::new();
Expand Down Expand Up @@ -819,14 +819,14 @@ fn test_validator_reward_weight_by_stake() {
"test1".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 1, expected: 1 },
chunk_stats: ChunkValidatorStats::v1(1, 1),
chunk_stats: ChunkValidatorStats::new_with_production(1, 1),
},
);
validator_online_ratio.insert(
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 1, expected: 1 },
chunk_stats: ChunkValidatorStats::v1(1, 1),
chunk_stats: ChunkValidatorStats::new_with_production(1, 1),
},
);
let mut validators_stakes = HashMap::new();
Expand Down Expand Up @@ -942,7 +942,7 @@ fn test_reward_multiple_shards() {
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 1, expected: 1 },
chunk_stats: ChunkValidatorStats::v1(1, 1),
chunk_stats: ChunkValidatorStats::new_with_production(1, 1),
},
);
let mut validators_stakes = HashMap::new();
Expand Down Expand Up @@ -2591,18 +2591,18 @@ fn test_validator_kickout_sanity() {
(
0,
HashMap::from([
(0, ChunkValidatorStats::v1(100, 100)),
(1, ChunkValidatorStats::v1(80, 100)),
(2, ChunkValidatorStats::v1(70, 100)),
(0, ChunkValidatorStats::new_with_production(100, 100)),
(1, ChunkValidatorStats::new_with_production(80, 100)),
(2, ChunkValidatorStats::new_with_production(70, 100)),
]),
),
(
1,
HashMap::from([
(0, ChunkValidatorStats::v1(70, 100)),
(1, ChunkValidatorStats::v1(79, 100)),
(3, ChunkValidatorStats::v1(100, 100)),
(4, ChunkValidatorStats::v1(100, 100)),
(0, ChunkValidatorStats::new_with_production(70, 100)),
(1, ChunkValidatorStats::new_with_production(79, 100)),
(3, ChunkValidatorStats::new_with_production(100, 100)),
(4, ChunkValidatorStats::new_with_production(100, 100)),
]),
),
]),
Expand All @@ -2624,35 +2624,35 @@ fn test_validator_kickout_sanity() {
"test0".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 100, expected: 100 },
chunk_stats: ChunkValidatorStats::v1(170, 200),
chunk_stats: ChunkValidatorStats::new_with_production(170, 200),
}
),
(
"test1".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 90, expected: 100 },
chunk_stats: ChunkValidatorStats::v1(159, 200),
chunk_stats: ChunkValidatorStats::new_with_production(159, 200),
}
),
(
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 100, expected: 100 },
chunk_stats: ChunkValidatorStats::v1(70, 100),
chunk_stats: ChunkValidatorStats::new_with_production(70, 100),
}
),
(
"test3".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 89, expected: 100 },
chunk_stats: ChunkValidatorStats::v1(100, 100),
chunk_stats: ChunkValidatorStats::new_with_production(100, 100),
}
),
(
"test4".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 0, expected: 0 },
chunk_stats: ChunkValidatorStats::v1(100, 100),
chunk_stats: ChunkValidatorStats::new_with_production(100, 100),
}
),
])
Expand Down Expand Up @@ -2696,15 +2696,15 @@ fn test_max_kickout_stake_ratio() {
(
0,
HashMap::from([
(0, ChunkValidatorStats::v1(0, 100)),
(1, ChunkValidatorStats::v1(0, 100)),
(0, ChunkValidatorStats::new_with_production(0, 100)),
(1, ChunkValidatorStats::new_with_production(0, 100)),
]),
),
(
1,
HashMap::from([
(2, ChunkValidatorStats::v1(100, 100)),
(4, ChunkValidatorStats::v1(50, 100)),
(2, ChunkValidatorStats::new_with_production(100, 100)),
(4, ChunkValidatorStats::new_with_production(50, 100)),
]),
),
]);
Expand Down Expand Up @@ -2735,21 +2735,21 @@ fn test_max_kickout_stake_ratio() {
"test0".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 50, expected: 100 },
chunk_stats: ChunkValidatorStats::v1(0, 100),
chunk_stats: ChunkValidatorStats::new_with_production(0, 100),
},
),
(
"test1".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 70, expected: 100 },
chunk_stats: ChunkValidatorStats::v1(0, 100),
chunk_stats: ChunkValidatorStats::new_with_production(0, 100),
},
),
(
"test2".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 70, expected: 100 },
chunk_stats: ChunkValidatorStats::v1(100, 100),
chunk_stats: ChunkValidatorStats::new_with_production(100, 100),
},
),
(
Expand All @@ -2763,7 +2763,7 @@ fn test_max_kickout_stake_ratio() {
"test4".parse().unwrap(),
BlockChunkValidatorStats {
block_stats: ValidatorStats { produced: 0, expected: 0 },
chunk_stats: ChunkValidatorStats::v1(50, 100),
chunk_stats: ChunkValidatorStats::new_with_production(50, 100),
},
),
]);
Expand Down
2 changes: 1 addition & 1 deletion core/primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::sync::Arc;

mod chunk_validator_stats;

pub use chunk_validator_stats::{ChunkValidatorStats, ChunkValidatorStatsV2};
pub use chunk_validator_stats::ChunkValidatorStats;

/// Hash used by to store state root.
pub type StateRoot = CryptoHash;
Expand Down
Loading

0 comments on commit b1053a8

Please sign in to comment.