Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent million-proposal attack by introducing minimum stake req… #2805

Merged
merged 10 commits into from
Jun 15, 2020
11 changes: 1 addition & 10 deletions chain/chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use near_primitives::transaction::{
};
use near_primitives::types::{
AccountId, ApprovalStake, Balance, BlockHeight, EpochId, Gas, Nonce, NumBlocks, NumShards,
ShardId, StateRoot, StateRootNode, ValidatorStake, ValidatorStats,
ShardId, StateRoot, StateRootNode, ValidatorStake,
};
use near_primitives::validator_signer::InMemoryValidatorSigner;
use near_primitives::version::{ProtocolVersion, PROTOCOL_VERSION};
Expand Down Expand Up @@ -383,15 +383,6 @@ impl RuntimeAdapter for KeyValueRuntime {
Ok(validators[offset + delta].account_id.clone())
}

fn get_num_validator_blocks(
&self,
_epoch_id: &EpochId,
_last_known_block_hash: &CryptoHash,
_account_id: &AccountId,
) -> Result<ValidatorStats, Error> {
Ok(ValidatorStats { produced: 0, expected: 0 })
}

fn num_shards(&self) -> ShardId {
self.num_shards
}
Expand Down
12 changes: 3 additions & 9 deletions chain/chain/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use near_primitives::sharding::{ReceiptProof, ShardChunk, ShardChunkHeader};
use near_primitives::transaction::{ExecutionOutcomeWithId, SignedTransaction};
use near_primitives::types::{
AccountId, ApprovalStake, Balance, BlockHeight, EpochId, Gas, MerkleHash, ShardId, StateRoot,
StateRootNode, ValidatorStake, ValidatorStats,
StateRootNode, ValidatorStake,
};
use near_primitives::version::ProtocolVersion;
use near_primitives::views::{EpochValidatorInfo, QueryRequest, QueryResponse};
Expand Down Expand Up @@ -113,6 +113,7 @@ pub struct BlockHeaderInfo {
pub height: BlockHeight,
pub random_value: CryptoHash,
pub last_finalized_height: BlockHeight,
pub last_finalized_block_hash: CryptoHash,
pub proposals: Vec<ValidatorStake>,
pub slashed_validators: Vec<SlashedValidator>,
pub chunk_mask: Vec<bool>,
Expand All @@ -128,6 +129,7 @@ impl BlockHeaderInfo {
height: header.height(),
random_value: *header.random_value(),
last_finalized_height,
last_finalized_block_hash: *header.last_final_block(),
proposals: header.validator_proposals().to_vec(),
slashed_validators: vec![],
chunk_mask: header.chunk_mask().to_vec(),
Expand Down Expand Up @@ -271,14 +273,6 @@ pub trait RuntimeAdapter: Send + Sync {
account_id: &AccountId,
) -> Result<(ValidatorStake, bool), Error>;

/// Number of missed blocks for given block producer.
fn get_num_validator_blocks(
&self,
epoch_id: &EpochId,
last_known_block_hash: &CryptoHash,
account_id: &AccountId,
) -> Result<ValidatorStats, Error>;

/// Get current number of shards.
fn num_shards(&self) -> ShardId;

Expand Down
Loading