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

Refactor sync out of block_store.rs #2089

Merged
merged 122 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
9a9370a
feat: added new ExternalMessage::RequestFromHeight and ExternalMessag…
shawn-zil Dec 24, 2024
ef104fe
feat: initial blockstore.rs skeleton.
shawn-zil Dec 25, 2024
2422561
feat: added request/response skeleton.
shawn-zil Dec 26, 2024
f811b77
feat: hook up initial wiring of blockstore with consensus.
shawn-zil Dec 26, 2024
87c12f9
feat: added blockstore.rs.
shawn-zil Dec 26, 2024
4b7097a
feat: added in-flight check.
shawn-zil Dec 27, 2024
58f2290
feat: added debug/warn/trace messages.
shawn-zil Dec 27, 2024
b6959ad
feat: initial requests firing.
shawn-zil Dec 27, 2024
8bd7214
feat: convert config value to usize for simplicity.
shawn-zil Dec 27, 2024
7edca1c
feat: added blockstore::handle_response_from_height().
shawn-zil Dec 27, 2024
b5b7c35
feat: checkpoint, successful RequestFromHeight-ResponseFromHeight.
shawn-zil Dec 27, 2024
3fa4840
feat: direct insert into DB, without receipts/touched/state.
shawn-zil Dec 27, 2024
dcfeed1
feat: successfully injecting blocks/state_trie
shawn-zil Dec 27, 2024
b3fb999
feat: small refactor blockstore.rs
shawn-zil Dec 28, 2024
ef3a8fb
sec: make RequestId random, to mitigate response injections.
shawn-zil Dec 28, 2024
36449fa
feat: minor reorg.
shawn-zil Dec 28, 2024
a8abeac
feat: disable speculative requests for now, until we have a better wa…
shawn-zil Dec 28, 2024
1f65f75
feat: re-enabled speculative fetch.
shawn-zil Dec 28, 2024
0930540
feat: use InjectedProposals instead of ProcessProposals.
shawn-zil Dec 30, 2024
45c202e
chore: minor cleanups.
shawn-zil Dec 30, 2024
3f379b7
feat: avoid single source of truth.
shawn-zil Dec 30, 2024
7a522d9
fix: insufficient peers in GCP.
shawn-zil Dec 30, 2024
85a7975
feat: only inject blocks sourced from two peers - impossible to sync,…
shawn-zil Dec 30, 2024
486056d
feat: sort-of working sync with multiple sources of truth.
shawn-zil Dec 30, 2024
de60034
feat: pre-allocate enough capacity; corrected block_gap check.
shawn-zil Dec 30, 2024
247c504
feat: replace non-corroborated blocks in cache.
shawn-zil Dec 30, 2024
d87d09e
chore: clippy. checkpoint. [corroborate proposals]
shawn-zil Dec 30, 2024
eed2ee6
feat: [speculative fetch]
shawn-zil Dec 30, 2024
66abff8
feat: remove peer check, which allows it to proceed under circumstanc…
shawn-zil Dec 30, 2024
27ae3ea
chore: clippy.
shawn-zil Dec 30, 2024
20ccc46
feat: added handle_metadata_request/response().
shawn-zil Jan 2, 2025
7580b39
feat: [checkpoint - retrieve chain metadata].
shawn-zil Jan 3, 2025
abfa6d4
feat: added handle_multiblock_request/response().
shawn-zil Jan 3, 2025
936b0a4
feat: [checkpoint - multi_block_request/response; never quite catchin…
shawn-zil Jan 3, 2025
9ea6e41
chore: clippy.
shawn-zil Jan 3, 2025
c4c89fe
feat: sync phase#3 - zip it up. works for syncing new nodes.
shawn-zil Jan 4, 2025
39d2cd4
feat: rename blockstore.rs to sync.rs - makes clear that its job is t…
shawn-zil Jan 6, 2025
6ccc7ca
nit: minor refactor - removing previous strategy.
shawn-zil Jan 6, 2025
1ee9685
feat: request multi-blocks from original meta-data peer.
shawn-zil Jan 6, 2025
d016c05
feat: validates the chain metadata as it is retrieved.
shawn-zil Jan 6, 2025
d777a8a
chore: minor cleanup.
shawn-zil Jan 6, 2025
5c339e9
feat: perform checks to ensure multi-block response matches multi-blo…
shawn-zil Jan 6, 2025
b7bc13b
feat: allow retries of request_missing_blocks().
shawn-zil Jan 6, 2025
2c35504
feat: added ability to retry phase 1, during phase 2 error.
shawn-zil Jan 7, 2025
3fae169
feat: combined p1_cursor/p2_cursor into a self.state value.
shawn-zil Jan 7, 2025
4c0a274
feat: restructure sync_proposal() to make it legible.
shawn-zil Jan 7, 2025
2d1b044
checkpoint: working sync with state machine.
shawn-zil Jan 7, 2025
b583758
Revert "sec: make RequestId random, to mitigate response injections."
shawn-zil Jan 8, 2025
bbfaf53
feat: make fixed-sized queue size, configurable.
shawn-zil Jan 8, 2025
179cb4d
feat: v1 sync compatibility.
shawn-zil Jan 9, 2025
c930283
feat: use ChainMetaData as the main state variable structure.
shawn-zil Jan 9, 2025
b643541
feat: make sync compatible with older nodes.
shawn-zil Jan 9, 2025
feecd20
feat: default to V1 peer; upgrade to V2 peer upon getting invalid res…
shawn-zil Jan 9, 2025
ad4cc3b
feat: filter V1 responses for gaps and forks.
shawn-zil Jan 10, 2025
ee3e322
feat: working phase 1 with protomainnet.
shawn-zil Jan 10, 2025
2e779e9
feat: removed sending BlockRequest from block_store.rs
shawn-zil Jan 10, 2025
d213e26
chore: comments, cleanup.
shawn-zil Jan 10, 2025
3f44c0a
fix: correct Phase 2 range, the stored value is accurate.
shawn-zil Jan 10, 2025
866794c
feat: ensure unique peers.
shawn-zil Jan 11, 2025
b05f098
feat: output rate stats in block/s
shawn-zil Jan 11, 2025
84900bf
feat: minor reorg, logging.
shawn-zil Jan 11, 2025
805313e
feat: added saving of metadata/segments to DB - allows continuation.
shawn-zil Jan 12, 2025
f23e71b
feat: added stateful sync algorithm feature - can continue after rest…
shawn-zil Jan 12, 2025
f2f5799
feat: rebuilt the algorithm to use DB for state, instead of in-memory.
shawn-zil Jan 13, 2025
d95dd98
feat: added PeerVer info to DB.
shawn-zil Jan 13, 2025
f6b4095
chore: post-rebase.
shawn-zil Jan 14, 2025
8aae098
feat: removed block_store.rs
shawn-zil Jan 16, 2025
0af7bf1
feat: added sync from timeout, not just proposals.
shawn-zil Jan 16, 2025
0795f0e
feat: made the batch_size dynamic, so that it can get past a larger r…
shawn-zil Jan 16, 2025
3b7ffcf
feat: added dynamic_batch_sizing() which is reactive, not pro-active.
shawn-zil Jan 17, 2025
49ad23c
feat: make dynamic_batch_sizing() work per-peer, not per sync.
shawn-zil Jan 17, 2025
f12793e
fix: wire up peers in test Network.
shawn-zil Jan 17, 2025
b58d7f7
fix: handle when V2 BlockResponse is late.
shawn-zil Jan 17, 2025
cf2b9c7
feat: sync batch_size should depend on the current request_range, not…
shawn-zil Jan 17, 2025
8b40988
feat: simplified the request_missing_metadata() match selector.
shawn-zil Jan 17, 2025
2146f84
fix: improve test sync, added Network::run_until_synced();
shawn-zil Jan 20, 2025
e0b2914
fix: fixed unreliable::blocks_are_produced_while_a_node_restarts() test.
shawn-zil Jan 20, 2025
2e1a111
fix: staking::validators_can_join_and_become_proposer() test.
shawn-zil Jan 20, 2025
25102c5
fix: tests.
shawn-zil Jan 20, 2025
cab93f3
nit: use Db::contains_block() instead of Db::get_block_by_hash().
shawn-zil Jan 21, 2025
497e807
fix: tests.
shawn-zil Jan 21, 2025
37fb852
feat: retry sync against upgraded Peer, immediately.
shawn-zil Jan 21, 2025
dd1b9f8
fix: checkpoints_test(), randomized add_peers() for tests.
shawn-zil Jan 21, 2025
df7fc94
fix: handle_forking(), validators_can_join() test.
shawn-zil Jan 22, 2025
a57ed20
fix: experiment.
shawn-zil Jan 22, 2025
d720cd5
fix: checkpoints_test().
shawn-zil Jan 23, 2025
902e38b
feat: check for checkpoint block, not just history.
shawn-zil Jan 23, 2025
626e49d
fix: undoing some test timeouts.
shawn-zil Jan 23, 2025
b6509d4
feat: replace ChainMetaData with BlockHeader.
shawn-zil Jan 23, 2025
e0007e3
feat: changed BlockRequestV2 from 'hash'-based to 'height'-based.
shawn-zil Jan 23, 2025
7c4d40b
feat: simplify checkpointed check.
shawn-zil Jan 24, 2025
75ab04b
nit: make sync_data temporary.
shawn-zil Jan 24, 2025
1c8c412
fix: better error handling for committee_for_hash().
shawn-zil Jan 24, 2025
6036668
feat: sets starting_block during Sync::new().
shawn-zil Jan 24, 2025
deec0fa
feat: store gas_used as a proxy for block size.
shawn-zil Jan 24, 2025
4d68b82
feat: reordered handle_metadata_response() to allow for micro-segment…
shawn-zil Jan 24, 2025
a00851a
fix: removed dynamic_batch_sizing() as it should be unnecessary until…
shawn-zil Jan 24, 2025
4ed1f38
feat: shifts txn verification from server side to client side.
shawn-zil Jan 24, 2025
3da126f
fix: validators_can_join..()
shawn-zil Jan 24, 2025
4449e64
fix PR comments:
shawn-zil Jan 27, 2025
108887c
feat: moved sync db layer from sync.rs to db.rs
shawn-zil Jan 27, 2025
40c84ce
feat: moved internal sync-peers to SyncPeers shared-state.
shawn-zil Jan 27, 2025
3ede631
fix: tests with shared-state SyncPeers.
shawn-zil Jan 27, 2025
d4f6d26
fix: issue of upgraded node, encountered in protomainnet where a node…
shawn-zil Jan 27, 2025
7cd3221
nit: increase deposit_v3 boundary to 24.
shawn-zil Jan 28, 2025
19da848
feat: use libp2p timeout instead of internal sync timeout.
shawn-zil Jan 28, 2025
5bbfe26
nit: change sync_data to sync_metadata table name; misc nits.
shawn-zil Jan 28, 2025
9b28c95
feat: added place-holder for active/passive sync.
shawn-zil Jan 28, 2025
c5d9b92
fix #2227; and remove txn.verify() during Phase 2 - it is checked dur…
shawn-zil Jan 28, 2025
dae52d5
feat: place-holder to store old ZIL txn blocks.
shawn-zil Jan 28, 2025
0c3614a
nit: simplify run_until_synced();
shawn-zil Jan 28, 2025
d0d3f00
fix: flaw in get_next_peer().
shawn-zil Jan 28, 2025
dba0235
feat: early prototype for issue #1878.
shawn-zil Jan 28, 2025
5dce6ae
Delete all non-finalized blocks from database at startup
JamesHinshelwood Jan 29, 2025
a845a55
Merge remote-tracking branch 'origin/main' into 2039-refactor-blockstore
JamesHinshelwood Jan 29, 2025
516fc63
Don't fail benchmark workflows on alert
JamesHinshelwood Jan 29, 2025
770465f
Remove redundant config
JamesHinshelwood Jan 29, 2025
eb42fbb
Hide listen addrs
JamesHinshelwood Jan 30, 2025
c34accb
Merge remote-tracking branch 'origin/main' into 2039-refactor-blockstore
JamesHinshelwood Jan 30, 2025
b10602e
feat: store raw header blob in sync_metadata().
shawn-zil Jan 31, 2025
e262091
Merge branch 'main' into 2039-refactor-blockstore
shawn-zil Feb 3, 2025
071d40b
feat: minor log changes; remove redundant check in handle_metadata_re…
shawn-zil Feb 3, 2025
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: 0 additions & 1 deletion .github/workflows/base_benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
--threshold-max-sample-size 64 \
--threshold-upper-boundary 0.99 \
--thresholds-reset \
--err \
--adapter rust_criterion \
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
cargo bench
1 change: 0 additions & 1 deletion .github/workflows/pr_benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
--start-point-clone-thresholds \
--start-point-reset \
--testbed self-hosted \
--err \
--adapter rust_criterion \
--github-actions '${{ secrets.GITHUB_TOKEN }}' \
cargo bench
22 changes: 3 additions & 19 deletions z2/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ use bitvec::{bitarr, order::Msb0};
use eth_trie::{EthTrie, MemoryDB, Trie};
use indicatif::{ProgressBar, ProgressFinish, ProgressIterator, ProgressStyle};
use itertools::Itertools;
use libp2p::PeerId;
use sha2::{Digest, Sha256};
use tokio::sync::mpsc;
use tracing::{debug, trace, warn};
use zilliqa::{
block_store::BlockStore,
cfg::{scilla_ext_libs_path_default, Amount, Config, NodeConfig},
crypto::{Hash, SecretKey},
db::Db,
exec::store_external_libraries,
message::{Block, QuorumCertificate, Vote, MAX_COMMITTEE_SIZE},
node::{MessageSender, RequestId},
schnorr,
scilla::{storage_key, CheckOutput, ParamValue, Transition},
state::{Account, Code, ContractInit, State},
Expand Down Expand Up @@ -346,27 +342,15 @@ pub async fn convert_persistence(
"{msg} {wide_bar} [{per_sec}] {human_pos}/~{human_len} ({elapsed}/~{duration})",
)?;

let (outbound_message_sender, _a) = mpsc::unbounded_channel();
let (local_message_sender, _b) = mpsc::unbounded_channel();
let message_sender = MessageSender {
our_shard: 0,
our_peer_id: PeerId::random(),
outbound_channel: outbound_message_sender,
local_channel: local_message_sender,
request_id: RequestId::default(),
};
// let (outbound_message_sender, _a) = mpsc::unbounded_channel();
// let (local_message_sender, _b) = mpsc::unbounded_channel();

let zq2_db = Arc::new(zq2_db);
let node_config = &zq2_config.nodes[0];
let block_store = Arc::new(BlockStore::new(
node_config,
zq2_db.clone(),
message_sender.clone(),
)?);
let mut state = State::new_with_genesis(
zq2_db.clone().state_trie()?,
node_config.clone(),
block_store,
zq2_db.clone(),
)?;

let mut scilla_docker = run_scilla_docker()?;
Expand Down
16 changes: 13 additions & 3 deletions z2/src/docgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use regex::Regex;
use serde::{Deserialize, Serialize};
use tera::Tera;
use tokio::fs;
use zilliqa::{cfg::NodeConfig, crypto::SecretKey};
use zilliqa::{cfg::NodeConfig, crypto::SecretKey, sync::SyncPeers};

const SUPPORTED_APIS_PATH_NAME: &str = "index";

Expand Down Expand Up @@ -352,10 +352,20 @@ pub fn get_implemented_jsonrpc_methods() -> Result<HashMap<ApiMethod, PageStatus
let (s2, _) = tokio::sync::mpsc::unbounded_channel();
let (s3, _) = tokio::sync::mpsc::unbounded_channel();
let (s4, _) = tokio::sync::mpsc::unbounded_channel();
let peers = Arc::new(AtomicUsize::new(0));
let peers_count = Arc::new(AtomicUsize::new(0));

let peer_id = secret_key.to_libp2p_keypair().public().to_peer_id();
let peers = Arc::new(SyncPeers::new(peer_id));

let my_node = Arc::new(Mutex::new(zilliqa::node::Node::new(
config, secret_key, s1, s2, s3, s4, peers,
config,
secret_key,
s1,
s2,
s3,
s4,
peers_count,
peers,
)?));
let module = zilliqa::api::rpc_module(my_node.clone(), &[]);
for m in module.method_names() {
Expand Down
7 changes: 6 additions & 1 deletion zilliqa/benches/it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use zilliqa::{
message::{Block, ExternalMessage, Proposal, QuorumCertificate, Vote, MAX_COMMITTEE_SIZE},
node::{MessageSender, RequestId},
schnorr,
sync::SyncPeers,
test_util::compile_contract,
time::{self, SystemTime},
transaction::{
Expand All @@ -46,12 +47,13 @@ fn process_empty(c: &mut Criterion) {
.measurement_time(Duration::from_secs(10));

let secret_key = SecretKey::new().unwrap();
let peer_id = secret_key.to_libp2p_keypair().public().to_peer_id();
let (outbound_message_sender, _a) = mpsc::unbounded_channel();
let (local_message_sender, _b) = mpsc::unbounded_channel();
let (reset_timeout_sender, _c) = mpsc::unbounded_channel();
let message_sender = MessageSender {
our_shard: 0,
our_peer_id: PeerId::random(),
our_peer_id: peer_id,
outbound_channel: outbound_message_sender,
local_channel: local_message_sender,
request_id: RequestId::default(),
Expand Down Expand Up @@ -88,6 +90,7 @@ fn process_empty(c: &mut Criterion) {
message_sender,
reset_timeout_sender,
Arc::new(db),
Arc::new(SyncPeers::new(peer_id)),
)
.unwrap();

Expand Down Expand Up @@ -163,6 +166,7 @@ fn consensus(
index: usize,
) -> Consensus {
let secret_key = genesis_deposits[index].0;
let peer_id = secret_key.to_libp2p_keypair().public().to_peer_id();
let (outbound_message_sender, a) = mpsc::unbounded_channel();
let (local_message_sender, b) = mpsc::unbounded_channel();
let (reset_timeout_sender, c) = mpsc::unbounded_channel();
Expand Down Expand Up @@ -208,6 +212,7 @@ fn consensus(
message_sender,
reset_timeout_sender,
Arc::new(db),
Arc::new(SyncPeers::new(peer_id)),
)
.unwrap()
}
Expand Down
14 changes: 3 additions & 11 deletions zilliqa/src/api/zilliqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ fn get_blockchain_info(_: Params, node: &Arc<Mutex<Node>>) -> Result<BlockchainI
let num_peers = node.get_peer_num();
let num_tx_blocks = node.get_chain_tip();
let num_ds_blocks = (num_tx_blocks / TX_BLOCKS_PER_DS_BLOCK) + 1;
let num_transactions = node.consensus.block_store.get_num_transactions()?;
let num_transactions = node.consensus.get_num_transactions()?;
let ds_block_rate = tx_block_rate / TX_BLOCKS_PER_DS_BLOCK as f64;

// num_txns_ds_epoch
Expand All @@ -518,7 +518,6 @@ fn get_blockchain_info(_: Params, node: &Arc<Mutex<Node>>) -> Result<BlockchainI
for i in current_epoch_first..node.get_chain_tip() {
let block = node
.consensus
.block_store
.get_canonical_block_by_number(i)?
.ok_or_else(|| anyhow!("Block not found"))?;
num_txns_ds_epoch += block.transactions.len();
Expand All @@ -527,7 +526,6 @@ fn get_blockchain_info(_: Params, node: &Arc<Mutex<Node>>) -> Result<BlockchainI
// num_txns_tx_epoch
let latest_block = node
.consensus
.block_store
.get_canonical_block_by_number(node.get_chain_tip())?;
let num_txns_tx_epoch = match latest_block {
Some(block) => block.transactions.len(),
Expand Down Expand Up @@ -1247,11 +1245,7 @@ fn get_recent_transactions(
let mut txns = Vec::new();
let mut blocks_searched = 0;
while block_number > 0 && txns.len() < 100 && blocks_searched < 100 {
let block = match node
.consensus
.block_store
.get_canonical_block_by_number(block_number)?
{
let block = match node.consensus.get_canonical_block_by_number(block_number)? {
Some(block) => block,
None => continue,
};
Expand All @@ -1274,7 +1268,7 @@ fn get_recent_transactions(
// GetNumTransactions
fn get_num_transactions(_params: Params, node: &Arc<Mutex<Node>>) -> Result<String> {
let node = node.lock().unwrap();
let num_transactions = node.consensus.block_store.get_num_transactions()?;
let num_transactions = node.consensus.get_num_transactions()?;
Ok(num_transactions.to_string())
}

Expand All @@ -1283,7 +1277,6 @@ fn get_num_txns_tx_epoch(_params: Params, node: &Arc<Mutex<Node>>) -> Result<Str
let node = node.lock().unwrap();
let latest_block = node
.consensus
.block_store
.get_canonical_block_by_number(node.get_chain_tip())?;
let num_transactions = match latest_block {
Some(block) => block.transactions.len(),
Expand All @@ -1302,7 +1295,6 @@ fn get_num_txns_ds_epoch(_params: Params, node: &Arc<Mutex<Node>>) -> Result<Str
for i in current_epoch_first..node.get_chain_tip() {
let block = node
.consensus
.block_store
.get_canonical_block_by_number(i)?
.ok_or_else(|| anyhow!("Block not found"))?;
num_txns_epoch += block.transactions.len();
Expand Down
Loading