Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into shuffle-shard-id
Browse files Browse the repository at this point in the history
  • Loading branch information
mooori committed Dec 6, 2023
2 parents cf1c18b + 8985a96 commit 8f2487f
Show file tree
Hide file tree
Showing 21 changed files with 328 additions and 220 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master_fuzzer_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
build_fuzzers:
name: Build Fuzzers
runs-on: "ubuntu-22.04-32core"
runs-on: "ubuntu-20.04-32core"

permissions:
contents: "read"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ondemand_fuzzer_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
jobs:
build_fuzzers:
name: Build Fuzzers
runs-on: "ubuntu-22.04-32core"
runs-on: "ubuntu-20.04-32core"

permissions:
contents: "read"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Protocol Changes

* Resharding v2 - new implementation for resharding and a new shard layout for production networks. [#10303](https://github.com/near/nearcore/pull/10303), [NEP-0508](https://github.com/near/NEPs/pull/508)
* Restrict the creation of non-implicit top-level account that are longer than 32 bytes. Only the registrar account can create them. [#9589](https://github.com/near/nearcore/pull/9589)
* Adjust the number of block producers and chunk producers on testnet to facilitate testing of chunk-only producers [#9563](https://github.com/near/nearcore/pull/9563)

Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bencher = "0.1.5"
bitflags = "1.2"
blake2 = "0.9.1"
bn = { package = "zeropool-bn", version = "0.5.11", default-features = false }
bolero = { version = "0.10.0", git = "https://github.com/Ekleog-NEAR/bolero", rev = "8f4e49d65c702a2f9858ed3c217b1cb52ce91243", features = ["arbitrary"] }
bolero = { version = "0.10.0", git = "https://github.com/Ekleog-NEAR/bolero", rev = "56da8e6d1d018519a30b36d85d3a53fe35a42eaf", features = ["arbitrary"] }
borsh = { version = "1.0.0", features = ["derive", "rc"] }
bs58 = "0.4"
bytes = "1"
Expand Down
76 changes: 45 additions & 31 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ pub fn check_header_known(
chain: &Chain,
header: &BlockHeader,
) -> Result<Result<(), BlockKnownError>, Error> {
// TODO: Change the return type to Result<BlockKnownStatusEnum, Error>.
let header_head = chain.store().header_head()?;
if header.hash() == &header_head.last_block_hash
|| header.hash() == &header_head.prev_block_hash
Expand All @@ -411,6 +412,7 @@ fn check_known_store(
chain: &Chain,
block_hash: &CryptoHash,
) -> Result<Result<(), BlockKnownError>, Error> {
// TODO: Change the return type to Result<BlockKnownStatusEnum, Error>.
if chain.store().block_exists(block_hash)? {
Ok(Err(BlockKnownError::KnownInStore))
} else {
Expand All @@ -427,6 +429,7 @@ pub fn check_known(
chain: &Chain,
block_hash: &CryptoHash,
) -> Result<Result<(), BlockKnownError>, Error> {
// TODO: Change the return type to Result<BlockKnownStatusEnum, Error>.
let head = chain.store().head()?;
// Quick in-memory check for fast-reject any block handled recently.
if block_hash == &head.last_block_hash || block_hash == &head.prev_block_hash {
Expand Down Expand Up @@ -1890,59 +1893,70 @@ impl Chain {
mut headers: Vec<BlockHeader>,
challenges: &mut Vec<ChallengeBody>,
) -> Result<(), Error> {
// Sort headers by heights if they are out of order.
// Sort headers by heights.
headers.sort_by_key(|left| left.height());

if let Some(header) = headers.first() {
debug!(target: "chain", "Sync block headers: {} headers from {} at {}", headers.len(), header.hash(), header.height());
if let (Some(first_header), Some(last_header)) = (headers.first(), headers.last()) {
info!(
target: "chain",
num_headers = headers.len(),
first_hash = ?first_header.hash(),
first_height = first_header.height(),
last_hash = ?last_header.hash(),
last_height = ?last_header.height(),
"Sync block headers");
} else {
// No headers.
return Ok(());
};

// Performance optimization to skip looking up every header in the store.
let all_known = if let Some(last_header) = headers.last() {
// If the last header is known, then the other headers are known too.
self.store.get_block_header(last_header.hash()).is_ok()
} else {
false
// Empty set of headers, therefore all received headers are known.
true
};

if !all_known {
// Validate header and then add to the chain.
for header in headers.iter() {
match check_header_known(self, header)? {
Ok(_) => {}
Err(_) => continue,
}
if all_known {
return Ok(());
}

self.validate_header(header, &Provenance::SYNC, challenges)?;
let mut chain_update = self.chain_update();
chain_update.chain_store_update.save_block_header(header.clone())?;
// Validate header and then add to the chain.
for header in headers.iter() {
match check_header_known(self, header)? {
Ok(_) => {}
Err(_) => continue,
}

// Add validator proposals for given header.
let last_finalized_height =
chain_update.chain_store_update.get_block_height(header.last_final_block())?;
let epoch_manager_update = chain_update
.epoch_manager
.add_validator_proposals(BlockHeaderInfo::new(header, last_finalized_height))?;
chain_update.chain_store_update.merge(epoch_manager_update);
chain_update.commit()?;
self.validate_header(header, &Provenance::SYNC, challenges)?;
let mut chain_update = self.chain_update();
chain_update.chain_store_update.save_block_header(header.clone())?;

#[cfg(feature = "new_epoch_sync")]
{
// At this point BlockInfo for this header should be in DB and in `epoch_manager`s cache because of `add_validator_proposals` call.
let mut chain_update = self.chain_update();
chain_update.save_epoch_sync_info_if_finalised(header)?;
chain_update.commit()?;
}
// Add validator proposals for given header.
let last_finalized_height =
chain_update.chain_store_update.get_block_height(header.last_final_block())?;
let epoch_manager_update = chain_update
.epoch_manager
.add_validator_proposals(BlockHeaderInfo::new(header, last_finalized_height))?;
chain_update.chain_store_update.merge(epoch_manager_update);
chain_update.commit()?;

#[cfg(feature = "new_epoch_sync")]
{
// At this point BlockInfo for this header should be in DB and in `epoch_manager`s cache because of `add_validator_proposals` call.
let mut chain_update = self.chain_update();
chain_update.save_epoch_sync_info_if_finalised(header)?;
chain_update.commit()?;
}
}

let mut chain_update = self.chain_update();

if let Some(header) = headers.last() {
// Update header_head if it's the new tip
chain_update.update_header_head_if_not_challenged(header)?;
}

chain_update.commit()
}

Expand Down
10 changes: 4 additions & 6 deletions chain/chain/src/resharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ impl Chain {
config,
..
} = state_split_request;
let config = config.get();

tracing::debug!(target: "resharding", ?config, ?shard_uid, "build_state_for_split_shards_impl starting");
tracing::debug!(target: "resharding", config=?config.get(), ?shard_uid, "build_state_for_split_shards_impl starting");

let shard_id = shard_uid.shard_id();
let new_shards = next_epoch_shard_layout
Expand Down Expand Up @@ -361,7 +359,7 @@ impl Chain {
let batch = {
let histogram = RESHARDING_BATCH_PREPARE_TIME.with_label_values(&metrics_labels);
let _timer = histogram.start_timer();
let batch = get_trie_update_batch(&config, &mut iter);
let batch = get_trie_update_batch(&config.get(), &mut iter);
let batch = batch.map_err(Into::<StorageError>::into)?;
let Some(batch) = batch else { break };
batch
Expand Down Expand Up @@ -395,11 +393,11 @@ impl Chain {

// sleep between batches in order to throttle resharding and leave
// some resource for the regular node operation
std::thread::sleep(config.batch_delay);
std::thread::sleep(config.get().batch_delay);
}

state_roots = apply_delayed_receipts(
&config,
&config.get(),
&tries,
shard_uid,
state_root,
Expand Down
20 changes: 12 additions & 8 deletions chain/client-primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ pub enum SyncStatus {
StateSync(StateSyncStatus),
/// Sync state across all shards is done.
StateSyncDone,
/// Catch up on blocks.
BodySync { start_height: BlockHeight, current_height: BlockHeight, highest_height: BlockHeight },
/// Download and process blocks until the head reaches the head of the network.
BlockSync {
start_height: BlockHeight,
current_height: BlockHeight,
highest_height: BlockHeight,
},
}

impl SyncStatus {
Expand All @@ -311,18 +315,18 @@ impl SyncStatus {
// Represent NoSync as 0 because it is the state of a normal well-behaving node.
SyncStatus::NoSync => 0,
SyncStatus::AwaitingPeers => 1,
SyncStatus::EpochSync { epoch_ord: _ } => 2,
SyncStatus::HeaderSync { start_height: _, current_height: _, highest_height: _ } => 3,
SyncStatus::EpochSync { .. } => 2,
SyncStatus::HeaderSync { .. } => 3,
SyncStatus::StateSync(_) => 4,
SyncStatus::StateSyncDone => 5,
SyncStatus::BodySync { start_height: _, current_height: _, highest_height: _ } => 6,
SyncStatus::BlockSync { .. } => 6,
}
}

pub fn start_height(&self) -> Option<BlockHeight> {
match self {
SyncStatus::HeaderSync { start_height, .. } => Some(*start_height),
SyncStatus::BodySync { start_height, .. } => Some(*start_height),
SyncStatus::BlockSync { start_height, .. } => Some(*start_height),
_ => None,
}
}
Expand Down Expand Up @@ -353,8 +357,8 @@ impl From<SyncStatus> for SyncStatusView {
.collect(),
),
SyncStatus::StateSyncDone => SyncStatusView::StateSyncDone,
SyncStatus::BodySync { start_height, current_height, highest_height } => {
SyncStatusView::BodySync { start_height, current_height, highest_height }
SyncStatus::BlockSync { start_height, current_height, highest_height } => {
SyncStatusView::BlockSync { start_height, current_height, highest_height }
}
}
}
Expand Down
1 change: 1 addition & 0 deletions chain/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ pub struct Client {
impl Client {
pub(crate) fn update_client_config(&self, update_client_config: UpdateableClientConfig) {
self.config.expected_shutdown.update(update_client_config.expected_shutdown);
self.config.state_split_config.update(update_client_config.state_split_config);
}
}

Expand Down
Loading

0 comments on commit 8f2487f

Please sign in to comment.