Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fast sync #8884

Merged
38 commits merged into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c7d1ad8
State sync
arkpar May 18, 2021
224ec1f
Importing state fixes
arkpar May 19, 2021
eeda74e
Bugfixes
arkpar May 21, 2021
1722f9b
Sync with proof
arkpar May 21, 2021
c3e378c
Status reporting
arkpar May 21, 2021
e755467
Unsafe sync mode
arkpar May 21, 2021
e610196
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar May 21, 2021
783e794
Sync test
arkpar May 22, 2021
b02b515
Cleanup
arkpar May 22, 2021
d22f27e
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar May 26, 2021
4895459
Apply suggestions from code review
arkpar May 26, 2021
4d4a05a
Merge branch 'a-storage-sync' of github.com:paritytech/substrate into…
arkpar May 26, 2021
753d412
set_genesis_storage
arkpar May 26, 2021
22462f3
Extract keys from range proof
arkpar May 27, 2021
0e99e07
Detect iter completion
arkpar May 27, 2021
dff08a4
Download and import bodies with fast sync
arkpar May 27, 2021
c6a263a
Replaced meta updates tuple with a struct
arkpar May 27, 2021
2eb647b
Fixed reverting finalized state
arkpar May 27, 2021
5f97da2
Reverted timeout
arkpar May 27, 2021
fb4926f
Typo
arkpar May 27, 2021
c287be3
Doc
arkpar May 27, 2021
e8df4ac
Doc
arkpar May 27, 2021
bad1124
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar May 27, 2021
730d619
Fixed light client test
arkpar May 27, 2021
7a8e682
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar May 31, 2021
4d665f3
Fixed error handling
arkpar Jun 3, 2021
4b34885
Tweaks
arkpar Jun 3, 2021
bf21352
More UpdateMeta changes
arkpar Jun 3, 2021
2f07284
Rename convert_transaction
arkpar Jun 4, 2021
5a99ef1
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar Jun 4, 2021
13a68e4
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar Jun 5, 2021
08079f4
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar Jun 16, 2021
fb882d4
Apply suggestions from code review
arkpar Jun 17, 2021
21c8c35
Apply suggestions from code review
arkpar Jun 17, 2021
6e5b91c
Code review suggestions
arkpar Jun 17, 2021
47583d9
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar Jun 17, 2021
7ff27dd
Fixed count handling
arkpar Jun 17, 2021
fe1d210
Merge branch 'master' of github.com:paritytech/substrate into a-stora…
arkpar Jun 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use sp_consensus::BlockOrigin;
use parking_lot::RwLock;

pub use sp_state_machine::Backend as StateBackend;
pub use sp_consensus::ImportedState;
use std::marker::PhantomData;

/// Extracts the state backend type for the given backend.
Expand Down Expand Up @@ -162,7 +163,7 @@ pub trait BlockImportOperation<Block: BlockT> {
) -> sp_blockchain::Result<()>;

/// Inject storage data into the database replacing any existing data.
cheme marked this conversation as resolved.
Show resolved Hide resolved
fn reset_storage(&mut self, storage: Storage) -> sp_blockchain::Result<Block::Hash>;
fn reset_storage(&mut self, storage: Storage, commit: bool) -> sp_blockchain::Result<Block::Hash>;

/// Set storage changes.
fn update_storage(
Expand Down
11 changes: 9 additions & 2 deletions client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
genesis_hash: storage.genesis_hash,
finalized_hash: storage.finalized_hash,
finalized_number: storage.finalized_number,
finalized_state: if storage.finalized_hash != Default::default() {
cheme marked this conversation as resolved.
Show resolved Hide resolved
Some((storage.finalized_hash.clone(), storage.finalized_number))
} else {
None
},
number_leaves: storage.leaves.count()
}
}
Expand Down Expand Up @@ -562,7 +567,7 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
Ok(())
}

fn reset_storage(&mut self, storage: Storage) -> sp_blockchain::Result<Block::Hash> {
fn reset_storage(&mut self, storage: Storage, commit: bool) -> sp_blockchain::Result<Block::Hash> {
check_genesis_storage(&storage)?;

let child_delta = storage.children_default.iter()
Expand All @@ -578,7 +583,9 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio
child_delta,
);

self.new_state = Some(transaction);
if commit {
self.new_state = Some(transaction);
}
Ok(root)
}

Expand Down
1 change: 1 addition & 0 deletions client/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub use notifications::*;
pub use proof_provider::*;

pub use sp_state_machine::{StorageProof, ExecutionStrategy};
pub use sp_storage::{StorageData, StorageKey, PrefixedStorageKey, ChildInfo};

/// Usage Information Provider interface
///
Expand Down
27 changes: 27 additions & 0 deletions client/api/src/proof_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Proof utilities
use std::collections::HashMap;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT},
Expand Down Expand Up @@ -70,4 +71,30 @@ pub trait ProofProvider<Block: BlockT> {
storage_key: Option<&PrefixedStorageKey>,
key: &StorageKey,
) -> sp_blockchain::Result<ChangesProof<Block::Header>>;

cheme marked this conversation as resolved.
Show resolved Hide resolved
/// Given a `BlockId` iterate over all storage values starting at `start_key`,
/// building proofs until size limit is reached. Returns collected keys and a combined proof.
fn read_proof_collection(
&self,
id: &BlockId<Block>,
start_key: &StorageKey,
size_limit: usize,
) -> sp_blockchain::Result<(Vec<Vec<u8>>, StorageProof)>;

/// Given a `BlockId` iterate over all storage values starting at `start_key`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we now start with start_key or the first key after it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First after. I'll update the comment.

/// Returns collected keys and values.
fn storage_collection(
&self,
id: &BlockId<Block>,
start_key: &StorageKey,
size_limit: usize,
) -> sp_blockchain::Result<Vec<(Vec<u8>, Vec<u8>)>>;

/// Verify read storage proof for a set of keys.
fn verify_read_proof(
&self,
keys: &[Vec<u8>],
root: Block::Hash,
proof: StorageProof,
) -> sp_blockchain::Result<HashMap<Vec<u8>, Option<Vec<u8>>>>;
}
1 change: 1 addition & 0 deletions client/authority-discovery/src/worker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl<Block: BlockT> HeaderBackend<Block> for TestApi {
finalized_number: Zero::zero(),
genesis_hash: Default::default(),
number_leaves: Default::default(),
finalized_state: None,
}
}

Expand Down
21 changes: 21 additions & 0 deletions client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ arg_enum! {
}
}

arg_enum! {
/// Syncing mode.
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy)]
pub enum SyncMode {
Full,
Fast,
FastUnsafe,
cheme marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it doesn't support doc comments, you can just add some code comment explaining what this does.

}
}

impl Into<sc_network::config::SyncMode> for SyncMode {
fn into(self) -> sc_network::config::SyncMode {
match self {
SyncMode::Full => sc_network::config::SyncMode::Full,
SyncMode::Fast => sc_network::config::SyncMode::Fast { skip_proofs: false },
SyncMode::FastUnsafe => sc_network::config::SyncMode::Fast { skip_proofs: true },
}
}
}

/// Default value for the `--execution-syncing` parameter.
pub const DEFAULT_EXECUTION_SYNCING: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
/// Default value for the `--execution-import-block` parameter.
Expand Down
6 changes: 6 additions & 0 deletions client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::params::node_key_params::NodeKeyParams;
use crate::arg_enums::SyncMode;
use sc_network::{
config::{NetworkConfiguration, NodeKeyConfig, NonReservedPeerMode, SetConfig, TransportConfig},
multiaddr::Protocol,
Expand Down Expand Up @@ -125,6 +126,10 @@ pub struct NetworkParams {
/// Join the IPFS network and serve transactions over bitswap protocol.
#[structopt(long)]
pub ipfs_server: bool,

/// Blockchain syncing mode.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or add some docs here about the variants. So, that the user can understand them

#[structopt(long, default_value = "Full")]
pub sync: SyncMode,
}

impl NetworkParams {
Expand Down Expand Up @@ -218,6 +223,7 @@ impl NetworkParams {
kademlia_disjoint_query_paths: self.kademlia_disjoint_query_paths,
yamux_window_size: None,
ipfs_server: self.ipfs_server,
sync_mode: self.sync.into(),
}
}
}
2 changes: 1 addition & 1 deletion client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ where
let mut import_block = BlockImportParams::new(BlockOrigin::Own, header);
import_block.post_digests.push(signature_digest_item);
import_block.body = Some(body);
import_block.storage_changes = Some(storage_changes);
import_block.storage_changes = Some(sp_consensus::StorageChanges::Raw(storage_changes));
import_block.fork_choice = Some(ForkChoiceStrategy::LongestChain);

Ok(import_block)
Expand Down
9 changes: 7 additions & 2 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ where
let mut import_block = BlockImportParams::new(BlockOrigin::Own, header);
import_block.post_digests.push(digest_item);
import_block.body = Some(body);
import_block.storage_changes = Some(storage_changes);
import_block.storage_changes = Some(sp_consensus::StorageChanges::Raw(storage_changes));
import_block.intermediates.insert(
Cow::from(INTERMEDIATE_KEY),
Box::new(BabeIntermediate::<B> { epoch_descriptor }) as Box<_>,
Expand Down Expand Up @@ -1275,7 +1275,12 @@ impl<Block, Client, Inner> BlockImport<Block> for BabeBlockImport<Block, Client,
// early exit if block already in chain, otherwise the check for
// epoch changes will error when trying to re-import an epoch change
match self.client.status(BlockId::Hash(hash)) {
Ok(sp_blockchain::BlockStatus::InChain) => return Ok(ImportResult::AlreadyInChain),
Ok(sp_blockchain::BlockStatus::InChain) => {
// When re-importing existing block strip away finality information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finality information?

let _ = block.take_intermediate::<BabeIntermediate<Block>>(INTERMEDIATE_KEY)?;
block.fork_choice = Some(ForkChoiceStrategy::Custom(false));
return self.inner.import_block(block, new_cache).await.map_err(Into::into)
}
arkpar marked this conversation as resolved.
Show resolved Hide resolved
Ok(sp_blockchain::BlockStatus::Unknown) => {},
Err(e) => return Err(ConsensusError::ClientImport(e.to_string())),
}
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/manual-seal/src/seal_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub async fn seal_block<B, BI, SC, C, E, P, CIDP>(
params.body = Some(body);
params.finalized = finalize;
params.fork_choice = Some(ForkChoiceStrategy::LongestChain);
params.storage_changes = Some(proposal.storage_changes);
params.storage_changes = Some(sp_consensus::StorageChanges::Raw(proposal.storage_changes));

if let Some(digest_provider) = digest_provider {
digest_provider.append_block_import(&parent, &mut params, &inherent_data)?;
Expand Down
4 changes: 2 additions & 2 deletions client/consensus/pow/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use std::{pin::Pin, time::Duration, collections::HashMap, borrow::Cow};
use sc_client_api::ImportNotifications;
use sp_runtime::{DigestItem, traits::Block as BlockT, generic::BlockId};
use sp_consensus::{Proposal, BlockOrigin, BlockImportParams, import_queue::BoxBlockImport};
use sp_consensus::{Proposal, BlockOrigin, BlockImportParams, StorageChanges, import_queue::BoxBlockImport};
use futures::{prelude::*, task::{Context, Poll}};
use futures_timer::Delay;
use log::*;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl<Block, Algorithm, C, Proof> MiningWorker<Block, Algorithm, C, Proof> where
let mut import_block = BlockImportParams::new(BlockOrigin::Own, header);
import_block.post_digests.push(seal);
import_block.body = Some(body);
import_block.storage_changes = Some(build.proposal.storage_changes);
import_block.storage_changes = Some(StorageChanges::Raw(build.proposal.storage_changes));

let intermediate = PowIntermediate::<Algorithm::Difficulty> {
difficulty: Some(build.metadata.difficulty),
Expand Down
Loading